lp.struct
Class LpVariable

java.lang.Object
  extended by lp.struct.LpAbstractStructureUnit
      extended by lp.struct.LpVariable
All Implemented Interfaces:
LpStructureUnit, LpTerm

public class LpVariable
extends LpAbstractStructureUnit
implements LpTerm

Represents a variable in logic programming. Variables are, together with function symbols and constants (see LpFunction and LpConstant) building units of terms (see LpTerm). Each variable has a unique non-empty name.

Version:
1.0.0
Author:
Martin Slota
See Also:
LpTerm

Field Summary
private  String name
          This variable's name.
private static Map<String,LpVariable> pool
          A pool of instances of this immutable class.
 
Fields inherited from class lp.struct.LpAbstractStructureUnit
TO_STRING_BUFFER
 
Constructor Summary
protected LpVariable(String name)
          Creates a new instance of LpVariable with the given name.
 
Method Summary
 void accept(LpStructureUnitVisitor visitor)
          Accepts LpStructureUnitVisitor instance, i.e. calls visitor.visit(this).
 boolean equals(Object obj)
          Returns true if and only if obj is a LpVariable instance, its name is equal to this variable's name as defined by String.equals(Object),
static LpVariable getInstance(String name)
          Returns an instance of LpVariable with the given name.
 String getName()
          Returns this variable's name, the same that was given to the constructor.
 int hashCode()
          Overriden in order to maintain the general contract of Object.hashCode().
 
Methods inherited from class lp.struct.LpAbstractStructureUnit
toString, toUnmodifiableList, toUnmodifiableSet
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

pool

private static final Map<String,LpVariable> pool
A pool of instances of this immutable class. The getInstance(String) method first looks here for the requested instances and if it is forced to create a new one, it is added to this pool.


name

private final String name
This variable's name.

Constructor Detail

LpVariable

protected LpVariable(String name)
Creates a new instance of LpVariable with the given name.

Parameters:
name - the new variable's name
Throws:
IllegalArgumentException - if name is null or an empty string
Method Detail

getInstance

public static LpVariable getInstance(String name)
Returns an instance of LpVariable with the given name.

Parameters:
name - the requested variable's name
Throws:
IllegalArgumentException - if name is null or an empty string

getName

public String getName()
Returns this variable's name, the same that was given to the constructor.

Returns:
the name of this variable

accept

public void accept(LpStructureUnitVisitor visitor)
Accepts LpStructureUnitVisitor instance, i.e. calls visitor.visit(this).

Specified by:
accept in interface LpStructureUnit
Parameters:
visitor - the visitor to accept

equals

public boolean equals(Object obj)
Returns true if and only if
  1. obj is a LpVariable instance,
  2. its name is equal to this variable's name as defined by String.equals(Object),

Specified by:
equals in interface LpTerm
Overrides:
equals in class Object
Parameters:
obj - the object to compare with
Returns:
true if this object is equal to obj according to the description above, and false otherwise
See Also:
String.equals(Object), LpTerm.equals(Object)

hashCode

public int hashCode()
Overriden in order to maintain the general contract of Object.hashCode().

Specified by:
hashCode in interface LpTerm
Overrides:
hashCode in class Object
Returns:
the hash of this object
See Also:
String.hashCode(), LpTerm.equals(Object)