< prev index next >

src/java.desktop/share/classes/javax/sound/sampled/CompoundControl.java

Print this page
rev 57600 : 8236980: toString() cleanup in JavaSound
Reviewed-by: XXX

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -23,10 +23,12 @@
  * questions.
  */
 
 package javax.sound.sampled;
 
+import java.util.StringJoiner;
+
 /**
  * A {@code CompoundControl}, such as a graphic equalizer, provides control over
  * two or more related properties, each of which is itself represented as a
  * {@code Control}.
  *

@@ -59,29 +61,22 @@
     public Control[] getMemberControls() {
         return controls.clone();
     }
 
     /**
-     * Provides a string representation of the control.
+     * Returns a string representation of the compound control.
      *
-     * @return a string description
+     * @return a string representation of the compound control
      */
     @Override
     public String toString() {
-
-        StringBuilder sb = new StringBuilder();
-        for (int i = 0; i < controls.length; i++) {
-            if (i != 0) {
-                sb.append(", ");
-                if ((i + 1) == controls.length) {
-                    sb.append("and ");
-                }
+        StringJoiner controls = new StringJoiner(", ", "[", "]");
+        for (Control control : getMemberControls()) {
+            controls.add(control.getType().toString());
             }
-            sb.append(controls[i].getType());
-        }
-
-        return new String(getType() + " Control containing " + sb + " Controls.");
+        return String.format("%s containing %s controls", super.toString(),
+                             controls);
     }
 
     /**
      * An instance of the {@code CompoundControl.Type} inner class identifies
      * one kind of compound control.
< prev index next >