lights.adapters
Class Field

java.lang.Object
  |
  +--lights.adapters.Field
All Implemented Interfaces:
IField, java.io.Serializable

public class Field
extends java.lang.Object
implements IField, java.io.Serializable

Represents a single typed field of a tuple. The type of a field can be any class implementing the Serializable interface. A field can either contain a value, or be characterized just by its type. In Linda jargon, the former is called an actual field, while the latter is called a formal field. Tuples with formals are typically used as a template to query the tuple space by pattern matching.

Formals and actuals are set by using two separate methods, setToFormal and setToActual. null is a legal value for the domain on which the type of the field is defined, thus fields whose value is null are considered to be actuals. Nevertheless, the null value must be specified by using a special method setToNullActual. Had the null value been set using setToActual(null), it would have been impossible to determine the type of the actual. Hence, null fields are not considered as formals.

this.matches(f) returns true if:

  1. this and f are both actuals, they have the same type, and they have the same value;
  2. either this or f is a formal, and both have the same type.
The above definition assumes that:
  1. the type of this and f is the same when their class object (as determined by invoking getClass() on the field objects) is the same.
  2. this and f have the same value when this.equals(f) returns true.
Notably, this matching rule does not allow for matching based on subtypes. Thus, for instance, if this and f both implement Serializable, they are not considered to match according to the rule above. Different matching rules, e.g., taking into account subtyping, can be provided by overriding the method matches.

Version:
1.0
Author:
Gian Pietro Picco
See Also:
Serialized Form

Field Summary
protected  IField adapter
           
 
Constructor Summary
Field()
          Creates an uninitialized field.
 
Method Summary
 java.lang.Class getType()
          Returns the type of this field.
 java.io.Serializable getValue()
          Returns the value of this field.
 boolean isFormal()
          Returns true if the field is a formal, false otherwise.
 boolean matches(IField field)
          Determines the rule used for pattern matching between fields.
 IField set(IField field)
          Substitutes this field with the one passed as a parameter.
 IField setToActual(java.io.Serializable obj)
          Sets the value of this field to the object passed as a parameter.
 IField setToFormal(java.lang.Class classObj)
          Sets this field to be a formal whose type becomes the class passed as a parameter.
 IField setToNullActual(java.lang.Class classObj)
          Sets the value of this field to null.
 java.lang.String toString()
          Returns a string representation of the tuple.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

adapter

protected IField adapter
Constructor Detail

Field

public Field()
Creates an uninitialized field.
Method Detail

set

public IField set(IField field)
Substitutes this field with the one passed as a parameter. If field is a formal, this field becomes a formal with field's type. If field is an actual, this fields becomes an actual with the type and value of field.
Specified by:
set in interface IField
Parameters:
field - the field to be assigned.
Returns:
the resulting field.

getValue

public java.io.Serializable getValue()
Returns the value of this field.
Specified by:
getValue in interface IField
Throws:
java.lang.IllegalArgumentException - if this field is a formal. isFormal() should be used to check whether this field is an actual, before calling this method.

getType

public java.lang.Class getType()
Returns the type of this field.
Specified by:
getType in interface IField

setToActual

public IField setToActual(java.io.Serializable obj)
Sets the value of this field to the object passed as a parameter. The type of the field is set automatically to the one of the object.
Specified by:
setToActual in interface IField
Parameters:
obj - the new value of the field.
Returns:
the resulting field.
Throws:
java.lang.IllegalArgumentException - if obj is null. setToNullActual should be used instead.

setToNullActual

public IField setToNullActual(java.lang.Class classObj)
Sets the value of this field to null. The type of the field is set to the class passed as a parameter.
Specified by:
setToNullActual in interface IField
Parameters:
classObj - the class to be associated to the null actual.
Returns:
the resulting field.

setToFormal

public IField setToFormal(java.lang.Class classObj)
Sets this field to be a formal whose type becomes the class passed as a parameter.
Specified by:
setToFormal in interface IField
Parameters:
classObj - the new type of this field.
Returns:
the resulting field.

isFormal

public boolean isFormal()
Returns true if the field is a formal, false otherwise.
Specified by:
isFormal in interface IField

matches

public boolean matches(IField field)
Determines the rule used for pattern matching between fields.
this.matches(f) returns true if:
  1. this and f are both actuals, they have the same type, and they have the same value;
  2. either this or f is a formal, and both have the same type.
The above definition assumes that:
  1. the type of this and f is the same when their class object (as determined by invoking getClass() on the field objects) is the same.
  2. this and f have the same value when this.equals(f) returns true.
Specified by:
matches in interface IField
Returns:
true if the field passed as a parameter matches this field, false otherwise.

toString

public java.lang.String toString()
Returns a string representation of the tuple.
Overrides:
toString in class java.lang.Object