netkit.graph
Class Attributes

java.lang.Object
  extended by netkit.graph.Attributes
All Implemented Interfaces:
java.lang.Iterable<Attribute>

public final class Attributes
extends java.lang.Object
implements java.lang.Iterable<Attribute>

This class is a container for Attribute classes. It keeps an ordered list of Attribute classes as individually typed fields. This container knows which field is the KEY Attribute (if a key exists.) Each Attribute within this container must have a unique field name. Each Attributes container must have a unique container name also. The name of this container class serves as a "type" for Nodes.

Author:
Kaveh R. Ghazi
See Also:
Attribute, AttributeKey, Node, SchemaReader

Constructor Summary
Attributes(java.lang.String name)
          This constructor builds an Attributes container object using the supplied name.
 
Method Summary
 void add(Attribute a)
          Adds an Attribute to this container; the name of the Attribute must be a unique field name within this container.
 int attributeCount()
          Get the number of Attribute fields in this container including the key Attribute (if one exists).
 boolean contains(java.lang.String fieldName)
          Check if the specified field name is already present among the attributes in this container.
 boolean equals(java.lang.Object o)
          Indicates whether some other object is "equal to" this one; note this method assumes that each instance has a unique name and uses the name for equality purposes.
 Attribute getAttribute(int attrIndex)
          Get the Attribute at a particular index; indexes honor the presence of a key Attribute within this container.
 Attribute getAttribute(java.lang.String attribute)
          Get the Attribute with a particular name.
 int getAttributeIndex(java.lang.String attribute)
          Get the index of an attribute within this container; indexes honor the presence of a key Attribute within this container.
 AttributeKey getKey()
          Get the key Attribute from this container.
 int getKeyIndex()
          Get the key index from this container.
 java.lang.String getName()
          Get the name of this object.
 int hashCode()
          Returns a hash code value for this object.
 java.util.Iterator<Attribute> iterator()
          Get an Iterator over the Attribute fields; iteration is performed in the order that each Attribute was added to this container.
 void remove(int index)
          Removes the Attribute at the specified index.
 void remove(java.lang.String fieldName)
          Removes the Attribute specified by the supplied field name.
 java.lang.String toString()
          Returns a String representation for this object.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Attributes

public Attributes(java.lang.String name)
This constructor builds an Attributes container object using the supplied name.

Parameters:
name - a string to uniquely name this container.
Method Detail

add

public void add(Attribute a)
Adds an Attribute to this container; the name of the Attribute must be a unique field name within this container. Note you shouldn't call this method directly after this container has been added to a Graph because Nodes will not carry the same number of values as their Attributes container requires.

Parameters:
a - the attribute to be added.
Throws:
java.lang.RuntimeException - if the attribute name is already present.
java.lang.RuntimeException - if an attempt is made to add a second key.
See Also:
Graph.addAttribute(String,Attribute)

getName

public java.lang.String getName()
Get the name of this object.

Returns:
the name of this object.

getAttributeIndex

public int getAttributeIndex(java.lang.String attribute)
Get the index of an attribute within this container; indexes honor the presence of a key Attribute within this container. This method is reflexive with getAttribute(int).

Parameters:
attribute - the attribute name to lookup.
Returns:
the index of an attribute within this container.
Throws:
java.lang.RuntimeException - if the attribute isn't found.

remove

public void remove(int index)
Removes the Attribute at the specified index. One cannot remove a KEY field if it exists. Note you shouldn't call this method directly after this container has been added to a Graph because Nodes will not carry the same number of values as their Attributes container requires.

Parameters:
index - an integer index specifying which Attribute to remove.
Throws:
java.lang.RuntimeException - if index is out of bounds or if index references the KEY field.
See Also:
Graph.removeAttribute(String,int)

remove

public void remove(java.lang.String fieldName)
Removes the Attribute specified by the supplied field name. One cannot remove a KEY field if it exists. Note you shouldn't call this method directly after this container has been added to a Graph because Nodes will not carry the same number of values as their Attributes container requires.

Parameters:
fieldName - a String representing the name of the Attribute field to be removed.
Throws:
java.lang.RuntimeException - if fieldName references the KEY field or if the Attribute referenced by fieldName does not exist in this container.
See Also:
Graph.removeAttribute(String,int)

iterator

public java.util.Iterator<Attribute> iterator()
Get an Iterator over the Attribute fields; iteration is performed in the order that each Attribute was added to this container. The Iterator is read-only.

Specified by:
iterator in interface java.lang.Iterable<Attribute>
Returns:
an Iterator on the Attribute fields in this container.

contains

public boolean contains(java.lang.String fieldName)
Check if the specified field name is already present among the attributes in this container.

Parameters:
fieldName - the field name to look for in this container.
Returns:
true if the field name exists in this container.

getAttribute

public Attribute getAttribute(java.lang.String attribute)
Get the Attribute with a particular name.

Parameters:
attribute - the attribute name to look for in the container.
Returns:
the Attribute with the matching attribute name or null if it doesn't exist.

getAttribute

public Attribute getAttribute(int attrIndex)
Get the Attribute at a particular index; indexes honor the presence of a key Attribute within this container. This method is reflexive with getAttributeIndex(String).

Parameters:
attrIndex - the attribute index to look for in the container.
Returns:
the Attribute at the matching index name or null if it doesn't exist.

getKey

public AttributeKey getKey()
Get the key Attribute from this container.

Returns:
the key Attribute from this container or null if none exists.

getKeyIndex

public int getKeyIndex()
Get the key index from this container.

Returns:
the key index from this container.

attributeCount

public int attributeCount()
Get the number of Attribute fields in this container including the key Attribute (if one exists).

Returns:
the number of attribute fields in this container.

hashCode

public int hashCode()
Returns a hash code value for this object.

Overrides:
hashCode in class java.lang.Object
Returns:
a hash code value for this object.

equals

public boolean equals(java.lang.Object o)
Indicates whether some other object is "equal to" this one; note this method assumes that each instance has a unique name and uses the name for equality purposes. The constraint on name uniqueness is enforced by the Graph class which holds Attributes.

Overrides:
equals in class java.lang.Object
Parameters:
o - the reference object with which to compare.
Returns:
true if this object is the same as the argument; false otherwise.
See Also:
Graph.addAttributes(Attributes)

toString

public java.lang.String toString()
Returns a String representation for this object.

Overrides:
toString in class java.lang.Object
Returns:
a String representation for this object.