Created
October 28, 2015 08:22
-
-
Save mitchwongho/4a8cb9046e2304b1811f to your computer and use it in GitHub Desktop.
A enum replacement
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.google.auto.value.AutoValue; | |
/** | |
* | |
*/ | |
@AutoValue | |
public abstract class PseudoEnum { | |
public static PseudoEnum MONDAY() { | |
return new AutoValue_PseudoEnum(0); | |
} | |
public static PseudoEnum TUESDAY() { | |
return new AutoValue_PseudoEnum(1); | |
} | |
public static PseudoEnum WEDNESDAY() { | |
return new AutoValue_PseudoEnum(2); | |
} | |
public static PseudoEnum THURSDAY() { | |
return new AutoValue_PseudoEnum(3); | |
} | |
public static PseudoEnum FRIDAY() { | |
return new AutoValue_PseudoEnum(4); | |
} | |
public static PseudoEnum SATURDAY() { | |
return new AutoValue_PseudoEnum(5); | |
} | |
public static PseudoEnum SUNDAY() { | |
return new AutoValue_PseudoEnum(6); | |
} | |
public abstract int value(); | |
/** | |
* Compares this instance with the specified object and indicates if they | |
* are equal. In order to be equal, {@code o} must represent the same object | |
* as this instance using a class-specific comparison. The general contract | |
* is that this comparison should be reflexive, symmetric, and transitive. | |
* Also, no object reference other than null is equal to null. | |
* <p> | |
* <p>The default implementation returns {@code true} only if {@code this == | |
* o}. See <a href="{@docRoot}reference/java/lang/Object.html#writing_equals">Writing a correct | |
* {@code equals} method</a> | |
* if you intend implementing your own {@code equals} method. | |
* <p> | |
* <p>The general contract for the {@code equals} and {@link | |
* #hashCode()} methods is that if {@code equals} returns {@code true} for | |
* any two objects, then {@code hashCode()} must return the same value for | |
* these objects. This means that subclasses of {@code Object} usually | |
* override either both methods or neither of them. | |
* | |
* @param o the object to compare this instance with. | |
* @return {@code true} if the specified object is equal to this {@code | |
* Object}; {@code false} otherwise. | |
* @see #hashCode | |
*/ | |
@Override | |
public boolean equals(Object o) { | |
return ((o instanceof PseudoEnum) && | |
( ((PseudoEnum)o).value() == value())); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment