FileDocCategorySizeDatePackage
SourceMedia.javaAPI DocExample5411Tue Feb 10 11:52:44 GMT 2004com.oreilly.hh

SourceMedia

public class SourceMedia extends Object implements Serializable, net.sf.hibernate.PersistentEnum
This is a typesafe enumeration that identifies the media on which an item in our music database was obtained.

Fields Summary
private final String
name
Stores the external name of this instance, by which it can be retrieved.
private final String
description
Stores the human-readable description of this instance, by which it is identified in the user interface.
private final int
code
Stores the integer value used by Hibernate to persist this instance.
private static final Map
instancesByName
Keeps track of all instances by name, for efficient lookup.
private static final Map
instancesByCode
Keeps track of all instances by code, for efficient lookup.
public static final SourceMedia
CASSETTE
The instance that represents music obtained from cassette tape.
public static final SourceMedia
VINYL
The instance that represents music obtained from vinyl.
public static final SourceMedia
VHS
The instance that represents music obtained from VHS tapes.
public static final SourceMedia
BROADCAST
The instance that represents music obtained from a broadcast.
public static final SourceMedia
CD
The instance that represents music obtained from a compact disc.
public static final SourceMedia
DOWNLOAD
The instance that represents music obtained as an Internet download.
public static final SourceMedia
STREAM
The instance that represents music from a digital audio stream.
Constructors Summary
private SourceMedia(String name, String description, int code)
Constructor is private to prevent instantiation except during class loading.

param
name the external name of the message type.
param
description the human readable description of the message type, by which it is presented in the user interface.
param
code the persistence code by which Hibernate stores the instance.


                                                                  
           
        this.name = name;
        this.description = description;
        this.code = code;

        // Record this instance in the collections that track the enumeration
        instancesByName.put(name, this);
        instancesByCode.put(new Integer(code), this);
    
Methods Summary
public static com.oreilly.hh.SourceMediafromInt(int code)
Look up an instance by code, as specified by the {@link PersistentEnum} interface.

param
code the persistence code of an instance.
return
the corresponding instance.
throws
NoSuchElementException if there is no such instance.

        SourceMedia result =
            (SourceMedia)instancesByCode.get(new Integer(code));
        if (result == null) {
            throw new NoSuchElementException("code=" + code);
        }
        return result;
    
public static java.util.CollectiongetAllValues()
Obtain the collection of all legal enumeration values.

return
all instances of this typesafe enumeration.


                        
        
        return Collections.unmodifiableCollection(instancesByName.values());
    
public java.lang.StringgetDescription()
Return the description associated with this instance.

return
the human-readable description by which this instance is identified in the user interface.

        return description;
    
public static com.oreilly.hh.SourceMediagetInstanceByName(java.lang.String name)
Look up an instance by name.

param
name the external name of an instance.
return
the corresponding instance.
throws
NoSuchElementException if there is no such instance.

        SourceMedia result = (SourceMedia)instancesByName.get(name);
        if (result == null) {
            throw new NoSuchElementException(name);
        }
        return result;
    
public java.lang.StringgetName()
Return the external name associated with this instance.

return
the name by which this instance is identified in code.

        return name;
    
private java.lang.ObjectreadResolve()
Insure that deserialization preserves the signleton property.

        return getInstanceByName(name);
    
public inttoInt()
Return the persistence code associated with this instance, as mandated by the {@link PersistentEnum} interface.

        return code;
    
public java.lang.StringtoString()
Return a string representation of this object.

        return description;