org.syphr.prom
Class Reference

java.lang.Object
  extended by org.syphr.prom.Reference

public class Reference
extends Object

This class encapsulates a reference to another property from within a property's value. For example, using an Ant-like Evaluator, a property may look like some.property = some value ${nested} where ${nested} is the reference.

Author:
Gregory P. Moyer

Constructor Summary
Reference(String name, String value, int startPosition, int endPosition)
          Construct a new reference.
 
Method Summary
 void addReference(Reference ref)
          Add a sub reference to this instance.
 boolean equals(Object obj)
           
 int getEndPosition()
          Retrieve the end index (inclusive) of this reference in the original value in which it was nested.
 String getName()
          Retrieve the name of this reference.
 List<Reference> getReferences()
          Retrieve a list of sub-references contained within the value of this reference.
 int getStartPosition()
          Retrieve the start index (inclusive) of this reference in the original value in which it was nested.
 String getValue()
          Retrieve the value of this reference, which may contain other references.
 int hashCode()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Reference

public Reference(String name,
                 String value,
                 int startPosition,
                 int endPosition)
Construct a new reference.

Parameters:
name - the name of the reference
value - the value of the reference
startPosition - the starting location (inclusive) of the entire reference (not just the name) in its original context
endPosition - the ending location (inclusive) of the entire reference (not just the name) in its original context
Method Detail

getName

public String getName()
Retrieve the name of this reference.

Returns:
the name

getValue

public String getValue()
Retrieve the value of this reference, which may contain other references.

Returns:
the value

getStartPosition

public int getStartPosition()
Retrieve the start index (inclusive) of this reference in the original value in which it was nested. Note that this position is the start of whatever defines this string as a reference, which is not necessarily the beginning of the reference name.

For example, with an Ant-like Evaluator and a reference " ${reference}", the start position would be the '$'.

This means that the following line will replace this reference with its value in the original string:
 
 StringBuilder originalValue = new StringBuilder(original);
 String evaluated = originalValue.replace(ref.getStartPosition(), ref.getEndPostion(), ref.getValue());
 
 

Returns:
the starting index for this reference
See Also:
getEndPosition()

getEndPosition

public int getEndPosition()
Retrieve the end index (inclusive) of this reference in the original value in which it was nested. Note that this position is the end of whatever defines this string as a reference, which is not necessarily the end of the reference name.

For example, with an Ant-like Evaluator and a reference " ${reference}", the end position would be the '}'.

This means that the following line will replace this reference with its value in the original string:
 
 StringBuilder originalValue = new StringBuilder(original);
 String evaluated = originalValue.replace(ref.getStartPosition(), ref.getEndPostion(), ref.getValue());
 
 

Returns:
the starting index for this reference
See Also:
getStartPosition()

addReference

public void addReference(Reference ref)
Add a sub reference to this instance. This method is intended for use by an Evaluator when building a reference.

Parameters:
ref - the reference to add

getReferences

public List<Reference> getReferences()
Retrieve a list of sub-references contained within the value of this reference. The elements in this list should not be modified.

Returns:
an immutable list of sub-references

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object


Copyright © 2010 syphr.org. All Rights Reserved.