|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.iperg.part.core.IpObjectPattern
public class IpObjectPattern
The IpObjectPattern
class is used to create object
patterns that can be matched against instances of any PART object
class.
Patterns can be used to express requirements concerning the
class to which a PART object instance belongs or inherits from. The
setClass
method takes a class name and a match
parameter that determines how the class name will be matched
against the class of a PART object. For example, the following
pattern will match objects that are instances of the class
SomeClass
:
IpObjectPattern pattern = new IpObjectPattern(); pattern.setClass("SomeClass", IpObjectPattern.EQUALS);Patterns can also be used to express requirements concerning the state of an object's properties. For instance, the following pattern will match any object that has a property named
speed
, whose value is "23.0"
:
IpObjectPattern pattern = new IpObjectPattern(); pattern.addProperty("speed", "23.0");If more than one property requirement is added to a pattern, objects must fulfill all of these in order to match the pattern.
The class and property pattern requirements can of course be used in combination:
IpObjectPattern pattern = new IpObjectPattern(); pattern.setClass("SomeClass", IpObjectPattern.EQUALS); pattern.addProperty("speed", "23.0"); pattern.addProperty("name", "Player1");
Apart from the class and property requirements, patterns can be also be used to search for objects using their identifiers. However, since every synchronised object has an unique identifier, a pattern that carries an identifier requirement can match one and only one object.
IpObjectPattern pattern = new IpObjectPattern(); pattern.setId(...);
Field Summary | |
---|---|
static int |
EQUALS
A class requirement match type that specifies that the class of an object must equal the given class in order for the object to match the pattern. |
static int |
INSTANCEOF
A class requirement match type that specifies that the class of an object must be an instance of the given class or interface in order for the object to match the pattern. |
Constructor Summary | |
---|---|
IpObjectPattern()
Constructs a empty pattern (the pattern contains no id, class or property requirements). |
Method Summary | |
---|---|
void |
addProperty(java.lang.String name,
java.lang.String value)
Add a property requirement. |
void |
addProperty(java.lang.String group,
java.lang.String name,
java.lang.String value)
Add a property requirement. |
void |
addPropertyExists(java.lang.String name)
Add a property requirement. |
void |
addPropertyExists(java.lang.String group,
java.lang.String name)
Add a property requirement. |
void |
read(IpInputStream stream)
Read the patterns's state from an input stream. |
void |
setClass(java.lang.String className,
int matchType)
Set class requirement. |
void |
setId(IpIdentifier id)
Set id requirement. |
void |
write(IpOutputStream stream)
Write the state of the pattern into an output stream. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int EQUALS
public static final int INSTANCEOF
Constructor Detail |
---|
public IpObjectPattern()
Method Detail |
---|
public void setId(IpIdentifier id)
id
- The identifier that must equal the identifier of a
synchronised object for the object to match the pattern.public void setClass(java.lang.String className, int matchType)
className
- A class name. The match type parameter
determines how the name should be interpreted when matching the
pattern against an object.matchType
- The class match typepublic void addProperty(java.lang.String name, java.lang.String value)
Many property requirements can be added to the same pattern.
name
- The name of the propertyvalue
- The required value of the propertypublic void addProperty(java.lang.String group, java.lang.String name, java.lang.String value)
null
, the default group is assumed.Many property requirements can be added to the same pattern.
group
- The name of the group that the property belongs toname
- The name of the propertyvalue
- The required value of the propertypublic void addPropertyExists(java.lang.String name)
name
parameter. The property must belong to the
default group. The property can have any value.
Many property requirements can be added to the same pattern.
name
- The name of the propertypublic void addPropertyExists(java.lang.String group, java.lang.String name)
name
parameter. The property must also belong to
the group specified by the groupnull, the default group is
assumed. The property can have any value.
Many property requirements can be added to the same pattern.
- Parameters:
group
- The name of the group that the property belongs toname
- The name of the property
public void write(IpOutputStream stream) throws java.io.IOException
write
in interface IpSerializable
stream
- The output stream into which the patterns's state
should be written
java.io.IOException
- if an io exception occured while writing
the pattern to the streampublic void read(IpInputStream stream) throws java.io.IOException
read
in interface IpSerializable
stream
- The input stream from which the patterns's state
should be read
java.io.IOException
- if the read failed
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |