|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectezvcard.util.CaseClasses<T,V>
T - the classV - the value that the class holds (e.g. String)public abstract class CaseClasses<T,V>
Manages objects that are like enums in that they are constant, but unlike enums in that new instances can be created during runtime. This class ensures that all instances of a class are unique, so they can be safely compared using "==" (provided their constructors are private). It mimics the "case class" feature in Scala.
| Field Summary | |
|---|---|
protected Class<T> |
clazz
|
protected Collection<T> |
preDefined
|
protected Collection<T> |
runtimeDefined
|
| Constructor Summary | |
|---|---|
CaseClasses(Class<T> clazz)
Creates a new case class collection. |
|
| Method Summary | |
|---|---|
Collection<T> |
all()
Gets all the static constants of the case class. |
protected abstract T |
create(V value)
Creates a new instance of the case class. |
T |
find(V value)
Searches for a case object by value, only looking at the case class' static constants (does not include runtime-defined objects). |
T |
get(V value)
Searches for a case object by value, creating a new object if one cannot be found. |
protected abstract boolean |
matches(T object,
V value)
Determines if a value is associated with a case object. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected final Class<T> clazz
protected volatile Collection<T> preDefined
protected Collection<T> runtimeDefined
| Constructor Detail |
|---|
public CaseClasses(Class<T> clazz)
clazz - the case class| Method Detail |
|---|
protected abstract T create(V value)
value - the value to give the instance
protected abstract boolean matches(T object,
V value)
object - the objectvalue - the value
public T find(V value)
value - the value
public T get(V value)
value - the value
public Collection<T> all()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||