+ //
+ // PRIVATE METHODS
+ //
+
+ /**
+ * Returns the {@link FloatControl.Type.VOLUME} control.
+ *
+ * @param dataLine
+ * The data line to search for the control
+ * @return The control, or {@code null} if no volume control could be found
+ */
+ private static FloatControl getVolumeControl(DataLine dataLine) {
+ return getControl(dataLine, VOLUME, FloatControl.class);
+ }
+
+ /**
+ * Returns the {@link BooleanControl.Type.MUTE} control.
+ *
+ * @param dataLine
+ * The data line to search for the control
+ * @return The control, or {@code null} if no mute control could be found
+ */
+ private static BooleanControl getMuteControl(DataLine dataLine) {
+ return getControl(dataLine, MUTE, BooleanControl.class);
+ }
+
+ /**
+ * Searches the given data line for a control of the given type and returns it.
+ * If the given data line is {@code null}, {@code null} is returned.
+ *
+ * @param dataLine
+ * The data line to search for a control
+ * @param controlType
+ * The type of the control to search
+ * @param controlClass
+ * The class of the control
+ * @param <T>
+ * The class of the control
+ * @return The control, or {@code null} if no control could be found
+ */
+ private static <T> T getControl(DataLine dataLine, Control.Type controlType, Class<T> controlClass) {
+ if (dataLine == null) {
+ return null;
+ }
+ Control[] controls = dataLine.getControls();
+ for (Control control : controls) {
+ if (control.getType().equals(controlType)) {
+ return (T) control;
+ }
+ }
+ return null;
+ }
+