|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--gausssoft.util.InstanceChecker
The InstanceChecker
class is an object that can be used to check the runtime
type of an object.
The most usual use of this object would normally to check a group of objects to ensure they are of a certain type. Take this example code:
public ExampleObject (Collection coll) { List args = new ArrayList(3); args[0] = java.lang.String.class; args[1] = java.lang.Integer.class; args[2] = getClass(); InstanceChecker ic = new InstanceChecker (args, false); if (ic.matchesIn(coll)) {throw new IllegalArgumentException();} else {....} }An
InstanceChecker
is created, which uses the Class objects of java.lang.String
,
java.lang.Integer
and the ExampleObject class for comparison. It is set, so that
if an object is compared against it, and the object being compared is not a String, Integer
or ExampleObject, it returns true
.
Each InstanceChecker is immutable after creation. An InstanceChecker is considered to be
inclusive
if the matches
method returns true
if an object
is an instance of at least one of the classes specified. Otherwise, it is exclusive
.
When arguments are passed at construction time to the InstanceChecker
, the only
allowed object types are Class objects.
Class
,
matches(Object)
,
matchesIn(Collection)
,
matchesIn(Object[])
, Serialized FormConstructor Summary | |
InstanceChecker(Class clazz)
Creates an inclusive InstanceChecker from a single class. |
|
InstanceChecker(Class[] classes)
Creates an inclusive InstanceChecker from an array of classes. |
|
InstanceChecker(Class[] classes,
boolean incl)
Creates an InstanceChecker from an array of classes, also specifying if this InstanceChecker is inclusive or not. |
|
InstanceChecker(Class clazz,
boolean incl)
Creates an InstanceChecker from a single class, also specifying if this InstanceChecker is inclusive or not. |
|
InstanceChecker(Collection coll)
Creates an inclusive InstanceChecker from a collection of classes. |
|
InstanceChecker(Collection coll,
boolean incl)
Creates an InstanceChecker from a collection of classes, also specifying if this InstanceChecker is inclusive or not. |
|
InstanceChecker(InstanceChecker ic)
Creates an InstanceChecker using the same data as another InstanceChecker. |
Method Summary | |
Set |
classes()
Returns an immutable set containing all the classes this InstanceChecker represents. |
Object |
clone()
Clones this InstanceChecker. |
boolean |
equals(Object obj)
Compares this InstanceChecker against another object. |
int |
hashCode()
Generates a hash code for this InstanceChecker. |
boolean |
isInclusive()
Return true if this InstanceChecker is inclusive. |
boolean |
matches(Object obj)
Checks to see if the supplied object matches the criteria by this InstanceChecker. |
boolean |
matchesIn(Collection coll)
Checks to see if the supplied collection has an object that matches the criteria set by this InstanceChecker. |
boolean |
matchesIn(Object[] array)
Checks to see if the supplied array has an object that matches the criteria set by this InstanceChecker. |
String |
toString()
Creates a String representation of this object. |
Methods inherited from class java.lang.Object |
finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public InstanceChecker(InstanceChecker ic)
ic
- The InstanceChecker to use.NullPointerException
- If ic
is null
.public InstanceChecker(Class clazz)
clazz
- A class object to use.NullPointerException
- If clazz
is null
.public InstanceChecker(Class clazz, boolean incl)
clazz
- A class object to use.incl
- true
if this object should be inclusive.NullPointerException
- If clazz
is null
.public InstanceChecker(Class[] classes)
classes
- An array of class objects to use.incl
- true
if this object should be inclusive.NullPointerException
- If classes
or an element in classes
is null
.public InstanceChecker(Class[] classes, boolean incl)
classes
- An array of class objects to use.incl
- true
if this object should be inclusive.NullPointerException
- If classes
or an element in classes
is null
.public InstanceChecker(Collection coll)
coll
- A collection of class objects to use.NullPointerException
- If coll
or an element in coll
is null
.ClassCastException
- If an element in coll
is not a Class
object.public InstanceChecker(Collection coll, boolean incl)
coll
- A collection of class objects to use.incl
- true
if this object should be inclusive.NullPointerException
- If coll
or an element in coll
is null
.ClassCastException
- If an element in coll
is not a Class
object.Method Detail |
public final Set classes()
public final boolean isInclusive()
true
if this InstanceChecker is inclusive.true
if this InstanceChecker is inclusive.public String toString()
toString
in class Object
public Object clone()
clone
in interface CloneableObject
clone
in class Object
public int hashCode()
hashCode
in class Object
public final boolean matches(Object obj)
obj
- The object to compare it against.true
if this object matches the criteria set by this InstanceChecker.public final boolean matchesIn(Object[] array)
array
- The supplied array.true
if this array contains an object that matches the
criteria set by this InstanceChecker.NullPointerException
- If array
is null
.public final boolean matchesIn(Collection coll)
coll
- The supplied collection.true
if this collection contains an object that matches the
criteria set by this InstanceChecker.NullPointerException
- If coll
is null
.public boolean equals(Object obj)
This object returns true
if the object provided is an InstanceChecker,
which has the same values as the supplied InstanceChecker.
equals
in class Object
obj
- The object to test for comparison.true
if the object provided matches the criteria of this InstanceChecker.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |