remove unnecessary annotations to calculate evalution numbers.
[IRC.git] / Robust / src / Benchmarks / SSJava / MP3Decoder / OutputChannels.java
1 /*
2  * 11/19/04 1.0 moved to LGPL.
3  * 12/12/99 Initial implementation.             mdm@techie.com. 
4  *-----------------------------------------------------------------------
5  *   This program is free software; you can redistribute it and/or modify
6  *   it under the terms of the GNU Library General Public License as published
7  *   by the Free Software Foundation; either version 2 of the License, or
8  *   (at your option) any later version.
9  *
10  *   This program is distributed in the hope that it will be useful,
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *   GNU Library General Public License for more details.
14  *
15  *   You should have received a copy of the GNU Library General Public
16  *   License along with this program; if not, write to the Free Software
17  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  *----------------------------------------------------------------------
19  */
20
21 /**
22  * A Type-safe representation of the the supported output channel constants.
23  * 
24  * This class is immutable and, hence, is thread safe.
25  * 
26  * @author Mat McGowan 12/12/99
27  * @since 0.0.7
28  */
29 @LATTICE("B<T")
30 @METHODDEFAULT("OUT<THIS,THIS<IN,THISLOC=THIS,RETURNLOC=OUT")
31 public class OutputChannels {
32   /**
33    * Flag to indicate output should include both channels.
34    */
35   public static final int BOTH_CHANNELS = 0;
36
37   /**
38    * Flag to indicate output should include the left channel only.
39    */
40   public static final int LEFT_CHANNEL = 1;
41
42   /**
43    * Flag to indicate output should include the right channel only.
44    */
45   public static final int RIGHT_CHANNEL = 2;
46
47   /**
48    * Flag to indicate output is mono.
49    */
50   public static final int DOWNMIX_CHANNELS = 3;
51
52   public static final OutputChannels LEFT = new OutputChannels(LEFT_CHANNEL);
53   public static final OutputChannels RIGHT = new OutputChannels(RIGHT_CHANNEL);
54   public static final OutputChannels BOTH = new OutputChannels(BOTH_CHANNELS);
55   public static final OutputChannels DOWNMIX = new OutputChannels(DOWNMIX_CHANNELS);
56
57   @LOC("T")
58   private/* final */int outputChannels;
59
60   /**
61    * Creates an <code>OutputChannels</code> instance corresponding to the given
62    * channel code.
63    * 
64    * @param code
65    *          one of the OutputChannels channel code constants.
66    * 
67    * @throws IllegalArgumentException
68    *           if code is not a valid channel code.
69    */
70   static public OutputChannels fromInt(int code) {
71     switch (code) {
72     case LEFT_CHANNEL:
73       return LEFT;
74     case RIGHT_CHANNEL:
75       return RIGHT;
76     case BOTH_CHANNELS:
77       return BOTH;
78     case DOWNMIX_CHANNELS:
79       return DOWNMIX;
80     default:
81       throw new IllegalArgumentException("Invalid channel code: " + code);
82     }
83   }
84
85   public OutputChannels(@LOC("IN") int channels) {
86     outputChannels = channels;
87
88     if (channels < 0 || channels > 3)
89       throw new IllegalArgumentException("channels");
90   }
91
92   /**
93    * Retrieves the code representing the desired output channels. Will be one of
94    * LEFT_CHANNEL, RIGHT_CHANNEL, BOTH_CHANNELS or DOWNMIX_CHANNELS.
95    * 
96    * @return the channel code represented by this instance.
97    */
98   public int getChannelsOutputCode() {
99     return outputChannels;
100   }
101
102   /**
103    * Retrieves the number of output channels represented by this channel output
104    * type.
105    * 
106    * @return The number of output channels for this channel output type. This
107    *         will be 2 for BOTH_CHANNELS only, and 1 for all other types.
108    */
109   public int getChannelCount() {
110     int count = (outputChannels == BOTH_CHANNELS) ? 2 : 1;
111     return count;
112   }
113
114   public boolean equals(Object o) {
115     boolean equals = false;
116
117     if (o instanceof OutputChannels) {
118       OutputChannels oc = (OutputChannels) o;
119       equals = (oc.outputChannels == outputChannels);
120     }
121
122     return equals;
123   }
124
125   public int hashCode() {
126     return outputChannels;
127   }
128
129 }