Created
November 11, 2013 15:52
-
-
Save GLitchfield/7415388 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
public abstract class Identifier<T extends Identifier<T>> | |
implements Comparable<T>, Existential { | |
private final String id; | |
private final Class<T> clazz; | |
public Identifier(final String id, final Class<T> clazz) { | |
if(id == null) { | |
throw new IllegalArgumentException("ID cannot be null"); | |
} | |
if(clazz == null) { | |
throw new IllegalArgumentException("Class cannot be null"); | |
} | |
this.id = id; | |
this.clazz = clazz; | |
} | |
@Override | |
public int compareTo(final T o) { | |
return id.compareTo(o.toString()); | |
} | |
@Override | |
public boolean isNull() { | |
return false; | |
} | |
@Override | |
public int hashCode() { | |
return id.hashCode(); | |
} | |
@Override | |
public boolean equals(final Object o) { | |
if(!(clazz.isInstance(o))) { | |
return false; | |
} | |
return id.equals(o.toString()); | |
} | |
@Override | |
public String toString() { | |
return id; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment