FileDocCategorySizeDatePackage
StereoVolume.javaAPI DocExample3640Fri Feb 20 21:32:20 GMT 2004com.oreilly.hh

StereoVolume

public class StereoVolume extends Object implements Serializable
A simple structure encapsulating a stereo volume level.

Fields Summary
public static final short
MINIMUM
The minimum legal volume level.
public static final short
MAXIMUM
The maximum legal volume level.
private short
left
Stores the volume of the left channel.
private short
right
Stores the volume of the right channel.
Constructors Summary
public StereoVolume()
Default constructor sets full volume in both channels.


                 
      
        this(MAXIMUM, MAXIMUM);
    
public StereoVolume(short left, short right)
Constructor that establishes specific volume levels.

param
left the volume of the left channel.
param
right the volume of the right channel.
throws
IllegalArgumentException if a volume is out of range.

        setLeft(left);
        setRight(right);
    
Methods Summary
private voidcheckVolume(short volume)
Helper method to make sure a volume value is legal.

param
volume the level that is being set.
throws
IllegalArgumentException if it is out of range.

        if (volume < MINIMUM) {
            throw new IllegalArgumentException("volume cannot be less than " +
                                               MINIMUM);
        }
        if (volume > MAXIMUM) {
            throw new IllegalArgumentException("volume cannot be more than " +
                                               MAXIMUM);
        }
    
public booleanequals(java.lang.Object obj)
Compare whether another object is equal to this one, following the contract established by {@link Object}.

param
obj the object to be compared.
return
true if obj is also a StereoVolume instance, and represents the same volume levels.

        if (obj instanceof StereoVolume) {
            StereoVolume other = (StereoVolume)obj;
            return other.getLeft() == getLeft() &&
                other.getRight() == getRight();
        }
        return false;  // It wasn't a StereoVolume
    
public shortgetLeft()
Get the volume of the left channel

return
the current volume level of the channel.

        return left;
    
public shortgetRight()
Get the volume of the right channel.

return
the current volume level of the channel.

        return right;
    
public inthashCode()
Returns a hash code value for the StereoVolume. This method must be consistent with the {@link #equals} method.

        return (int)getLeft() * MAXIMUM * 10 + getRight();
    
public voidsetLeft(short volume)
Set the volume of the left channel.

param
volume level to which the left channel is being set.
throws
IllegalArgumentException if it is out of range.

        checkVolume(volume);
        left = volume;
    
public voidsetRight(short volume)
Set the volume of the right channel.

param
volume level to which the right channel is being set.
throws
IllegalArgumentException if it is out of range.

        checkVolume(volume);
        right = volume;
    
public java.lang.StringtoString()
Format a readable version of the volume levels, for debugging.

        return "Volume[left=" + left + ", right=" + right + ']";