1
package org.hibernate.test.hql;
3
import java.io.Serializable;
4
import java.util.HashMap;
9
* @author Steve Ebersole
11
public class Classification implements Serializable, Comparable {
13
public static final Classification COOL = new Classification( "COOL", 0 );
14
public static final Classification LAME = new Classification( "LAME", 1 );
16
private static final HashMap INSTANCES = new HashMap();
18
INSTANCES.put( COOL.name, COOL );
19
INSTANCES.put( LAME.name, LAME );
22
private final String name;
23
private final int ordinal;
24
private final int hashCode;
26
private Classification(String name, int ordinal) {
28
this.ordinal = ordinal;
30
int hashCode = name.hashCode();
31
hashCode = 29 * hashCode + ordinal;
32
this.hashCode = hashCode;
35
public String name() {
39
public int ordinal() {
43
public boolean equals(Object obj) {
44
return compareTo( obj ) == 0;
47
public int compareTo(Object o) {
48
int otherOrdinal = ( ( Classification ) o ).ordinal;
49
if ( ordinal == otherOrdinal ) {
52
else if ( ordinal > otherOrdinal ) {
60
public int hashCode() {
64
public static Classification valueOf(String name) {
65
return ( Classification ) INSTANCES.get( name );
68
public static Classification valueOf(Integer ordinal) {
69
if ( ordinal == null ) {
72
switch ( ordinal.intValue() ) {
75
default: throw new IllegalArgumentException( "unknown classification ordinal [" + ordinal + "]" );