xtc.tree
Class Attribute

java.lang.Object
  extended by xtc.tree.Node
      extended by xtc.tree.Attribute
All Implemented Interfaces:
java.lang.Iterable<java.lang.Object>, Locatable

public class Attribute
extends Node

A name/value pair.

Version:
$Revision: 1.12 $
Author:
Robert Grimm

Constructor Summary
Attribute(java.lang.String name)
          Create a new attribute with the specified name.
Attribute(java.lang.String name, java.lang.Object value)
          Create a new attribute with the specified name and value.
 
Method Summary
static boolean areEquivalent(java.util.List<Attribute> l1, java.util.List<Attribute> l2)
          Determine whether the specified lists of attributes are equivalent.
 boolean equals(java.lang.Object o)
           
 java.lang.Object get(int index)
          Get the child at the specified index.
static Attribute get(java.lang.String name, java.util.List<Attribute> list)
          Get the attribute with the specified name from the specified list.
 java.lang.String getName()
          Get the name.
 java.lang.Object getValue()
          Get the value.
 int hashCode()
           
 boolean hasTraversal()
          Determine whether this node supports generic traversal of its children.
 java.lang.Object set(int index, java.lang.Object value)
          Set the child at the specified index to the specified value.
 int size()
          Get the number of children.
 void write(java.lang.Appendable out)
          Write a human readable representation to the specified appendable.
 
Methods inherited from class xtc.tree.Node
add, add, addAll, addAll, addAll, addAll, addAllTo, addNode, contains, getBoolean, getBooleanProperty, getGeneric, getList, getLocation, getNode, getProperty, getString, getStringProperty, getTokenText, hasLocation, hasName, hasProperty, hasVariable, indexOf, isAnnotation, isEmpty, isGeneric, isList, isToken, iterator, lastIndexOf, properties, remove, removeProperty, setLocation, setLocation, setProperty, strip, toAnnotation, toList, toString, toToken
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Attribute

public Attribute(java.lang.String name)
Create a new attribute with the specified name. The new attribute's value is null.

Parameters:
name - The name.

Attribute

public Attribute(java.lang.String name,
                 java.lang.Object value)
Create a new attribute with the specified name and value.

Parameters:
name - The name.
value - The value.
Method Detail

hasTraversal

public boolean hasTraversal()
Description copied from class: Node
Determine whether this node supports generic traversal of its children. The default implementation returns false.

Overrides:
hasTraversal in class Node
Returns:
true if this node supports generic traversal of its children.

size

public int size()
Description copied from class: Node
Get the number of children. The default implementation signals an unsupported operation exception.

Overrides:
size in class Node
Returns:
The number of children.

get

public java.lang.Object get(int index)
Description copied from class: Node
Get the child at the specified index. The default implementation signals an unsupported operation exception.

Note that instance tests on the returned object may not behave as expected. Notably, any node may be wrapped in annotations. Furthermore, any string may be wrapped in a token (and, recursively, in annotations).

Overrides:
get in class Node
Parameters:
index - The index.
Returns:
The child at that positioin.
See Also:
Token.test(Object), Token.cast(Object), GNode.test(Object), GNode.cast(Object)

set

public java.lang.Object set(int index,
                            java.lang.Object value)
Description copied from class: Node
Set the child at the specified index to the specified value. The default implementation signals an unsupported operation exception.

Overrides:
set in class Node
Parameters:
index - The index.
value - The new value.
Returns:
The old value.

getName

public java.lang.String getName()
Get the name.

Overrides:
getName in class Node
Returns:
The name.

getValue

public java.lang.Object getValue()
Get the value.

Returns:
The value.

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

write

public void write(java.lang.Appendable out)
           throws java.io.IOException
Description copied from class: Node
Write a human readable representation to the specified appendable. If this node supports generic traversal, the default implementation writes this node in algebraic term-format; otherwise, it writes the string returned by Object.toString().

Overrides:
write in class Node
Parameters:
out - The appendable.
Throws:
java.io.IOException - Signals an I/O error.

get

public static Attribute get(java.lang.String name,
                            java.util.List<Attribute> list)
Get the attribute with the specified name from the specified list.

Parameters:
name - The name.
list - The list.
Returns:
The corresponding attribute or null if the list is null or contains no such attribute.

areEquivalent

public static boolean areEquivalent(java.util.List<Attribute> l1,
                                    java.util.List<Attribute> l2)
Determine whether the specified lists of attributes are equivalent.

Parameters:
l1 - The first list.
l2 - The second list.
Returns:
true if the two lists are equivalent, that is, contain the same attributes in some order.


Copyright © 2012. All Rights Reserved.