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

   1 /*
   2  * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package javax.sound.sampled;
  27 
  28 /**
  29  * Ports are simple lines for input or output of audio to or from audio devices.
  30  * Common examples of ports that act as source lines (mixer inputs) include the
  31  * microphone, line input, and CD-ROM drive. Ports that act as target lines
  32  * (mixer outputs) include the speaker, headphone, and line output. You can
  33  * access port using a {@link Port.Info} object.
  34  *
  35  * @author Kara Kytle
  36  * @since 1.3
  37  */
  38 public interface Port extends Line {
  39 
  40     /**
  41      * The {@code Port.Info} class extends {@code Line.Info} with additional
  42      * information specific to ports, including the port's name and whether it
  43      * is a source or a target for its mixer. By definition, a port acts as
  44      * either a source or a target to its mixer, but not both. (Audio input
  45      * ports are sources; audio output ports are targets.)
  46      * <p>
  47      * To learn what ports are available, you can retrieve port info objects
  48      * through the {@link Mixer#getSourceLineInfo getSourceLineInfo} and
  49      * {@link Mixer#getTargetLineInfo getTargetLineInfo} methods of the
  50      * {@code Mixer} interface. Instances of the {@code Port.Info} class may
  51      * also be constructed and used to obtain lines matching the parameters
  52      * specified in the {@code Port.Info} object.
  53      *
  54      * @author Kara Kytle
  55      * @since 1.3
  56      */
  57     class Info extends Line.Info {
  58 
  59         // AUDIO PORT TYPE DEFINES
  60 
  61         // SOURCE PORTS
  62 
  63         /**
  64          * A type of port that gets audio from a built-in microphone or a
  65          * microphone jack.
  66          */
  67         public static final Info MICROPHONE = new Info(Port.class,"MICROPHONE", true);
  68 
  69         /**
  70          * A type of port that gets audio from a line-level audio input jack.
  71          */
  72         public static final Info LINE_IN = new Info(Port.class,"LINE_IN", true);
  73 
  74         /**
  75          * A type of port that gets audio from a CD-ROM drive.
  76          */
  77         public static final Info COMPACT_DISC = new Info(Port.class,"COMPACT_DISC", true);
  78 
  79         // TARGET PORTS
  80 
  81         /**
  82          * A type of port that sends audio to a built-in speaker or a speaker
  83          * jack.
  84          */
  85         public static final Info SPEAKER = new Info(Port.class,"SPEAKER", false);
  86 
  87         /**
  88          * A type of port that sends audio to a headphone jack.
  89          */
  90         public static final Info HEADPHONE = new Info(Port.class,"HEADPHONE", false);
  91 
  92         /**
  93          * A type of port that sends audio to a line-level audio output jack.
  94          */
  95         public static final Info LINE_OUT = new Info(Port.class,"LINE_OUT", false);
  96 
  97         // FUTURE DIRECTIONS...
  98 
  99         // telephone
 100         // DAT
 101         // DVD
 102 
 103         /**
 104          * The string that names the port.
 105          */
 106         private final String name;
 107 
 108         /**
 109          * Whether this port is source or not.
 110          */
 111         private final boolean isSource;
 112 
 113         /**
 114          * Constructs a port's info object from the information given. This
 115          * constructor is typically used by an implementation of Java Sound to
 116          * describe a supported line.
 117          *
 118          * @param  lineClass the class of the port described by the info object
 119          * @param  name the string that names the port
 120          * @param  isSource {@code true} if the port is a source port (such as a
 121          *         microphone), {@code false} if the port is a target port (such
 122          *         as a speaker)
 123          */
 124         public Info(Class<?> lineClass, String name, boolean isSource) {
 125 
 126             super(lineClass);
 127             this.name = name;
 128             this.isSource = isSource;
 129         }
 130 
 131         /**
 132          * Obtains the name of the port.
 133          *
 134          * @return the string that names the port
 135          */
 136         public String getName() {
 137             return name;
 138         }
 139 
 140         /**
 141          * Indicates whether the port is a source or a target for its mixer.
 142          *
 143          * @return {@code true} if the port is a source port (such as a
 144          *         microphone), {@code false} if the port is a target port (such
 145          *         as a speaker)
 146          */
 147         public boolean isSource() {
 148             return isSource;
 149         }
 150 
 151         /**
 152          * Indicates whether this info object specified matches this one. To
 153          * match, the match requirements of the superclass must be met and the
 154          * types must be equal.
 155          *
 156          * @param  info the info object for which the match is queried
 157          * @return {@code true} if the specified object matches this one,
 158          *         {@code false} otherwise
 159          */
 160         @Override
 161         public boolean matches(Line.Info info) {
 162 
 163             if (! (super.matches(info)) ) {
 164                 return false;
 165             }
 166 
 167             if (!(name.equals(((Info)info).getName())) ) {
 168                 return false;
 169             }
 170 
 171             if (! (isSource == ((Info)info).isSource()) ) {
 172                 return false;
 173             }
 174 
 175             return true;
 176         }
 177 
 178         /**
 179          * Indicates whether the specified object is equal to this info object,
 180          * returning {@code true} if the objects are the same.
 181          *
 182          * @param  obj the reference object with which to compare
 183          * @return {@code true} if the specified object is equal to this info
 184          *         object; {@code false} otherwise
 185          */
 186         @Override
 187         public final boolean equals(Object obj) {
 188             return super.equals(obj);
 189         }
 190 
 191         /**
 192          * Returns a hash code value for this info object.
 193          *
 194          * @return a hash code value for this info object
 195          */
 196         @Override
 197         public final int hashCode() {
 198             return super.hashCode();
 199         }
 200 
 201         /**
 202          * Provides a {@code String} representation of the port.
 203          *
 204          * @return a string that describes the port
 205          */
 206         @Override
 207         public final String toString() {
 208             return (name + ((isSource == true) ? " source" : " target") + " port");

 209         }
 210     }
 211 }
--- EOF ---