Class AttributeList

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList
          extended by AttributeList
All Implemented Interfaces:
java.io.Serializable, java.lang.Iterable, java.util.Collection, java.util.List
 class AttributeList
extends java.util.AbstractList
implements java.util.List, java.io.Serializable

AttributeList represents legal JDOM Attribute content. This class is NOT PUBLIC; users should see it as a simple List implementation.

See Also:
CDATA, Comment, Element, EntityRef, ProcessingInstruction, Text

Field Summary
private static java.lang.StringCVS_ID
           
private  Attribute[]elementData
          The backing list
private static intINITIAL_ARRAY_SIZE
           
private  Elementparent
          The parent Element
private  intsize
           
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
private AttributeList()
          Force an Element parent
(package private)AttributeList(Element parent)
          Create a new instance of the AttributeList representing Element content
 
Method Summary
(package private)  voidadd(int index, Attribute attribute)
          Check and add the Attribute to this list at the given index.
 voidadd(int index, java.lang.Object obj)
          Inserts the specified attribute at the specified position in this list.
 booleanadd(java.lang.Object obj)
          Add a attribute to the end of the list or replace a existing attribute with the same name and Namespace.
 booleanaddAll(java.util.Collection collection)
          Add all the objects in the specified collection.
 booleanaddAll(int index, java.util.Collection collection)
          Inserts the specified collecton at the specified position in this list.
 voidclear()
          Clear the current list.
(package private)  voidclearAndSet(java.util.Collection collection)
          Clear the current list and set it to the contents of the Collection.
private  voidensureCapacity(int minCapacity)
          Increases the capacity of this AttributeList instance, if necessary, to ensure that it can hold at least the number of items specified by the minimum capacity argument.
 java.lang.Objectget(int index)
          Return the object at the specified offset.
(package private)  java.lang.Objectget(java.lang.String name, Namespace namespace)
          Return the Attribute with the given name and Namespace.
(package private)  intindexOf(java.lang.String name, Namespace namespace)
          Return index of the Attribute with the given name and uri.
private  intindexOfDuplicate(Attribute attribute)
          Return index of attribute with same name and Namespace, or -1 if one doesn't exist
 java.lang.Objectremove(int index)
          Remove the object at the specified offset.
(package private)  booleanremove(java.lang.String name, Namespace namespace)
          Remove the Attribute with the given name and Namespace.
(package private)  java.lang.Objectset(int index, Attribute attribute)
          Set the object at the specified location to the supplied object.
 java.lang.Objectset(int index, java.lang.Object obj)
          Set the object at the specified location to the supplied object.
 intsize()
          Return the number of items in this list
 java.lang.StringtoString()
          Return this list as a String
(package private)  voiduncheckedAddAttribute(Attribute a)
          Package internal method to support building from sources that are 100% trusted.
 
Methods inherited from class java.util.AbstractList
equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, removeRange, subList
 
Methods inherited from class java.util.AbstractCollection
contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
contains, containsAll, equals, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, removeAll, retainAll, subList, toArray, toArray
 

Field Detail

CVS_ID

private static final java.lang.String CVS_ID
See Also:
Constant Field Values

INITIAL_ARRAY_SIZE

private static final int INITIAL_ARRAY_SIZE
See Also:
Constant Field Values

elementData

private Attribute[] elementData
The backing list

size

private int size

parent

private Element parent
The parent Element

Constructor Detail

AttributeList

private AttributeList()
Force an Element parent

AttributeList

AttributeList(Element parent)
Create a new instance of the AttributeList representing Element content

Parameters:
parent - element whose attributes are to be held
Method Detail

uncheckedAddAttribute

final void uncheckedAddAttribute(Attribute a)
Package internal method to support building from sources that are 100% trusted.

Parameters:
a - attribute to add without any checks

add

public boolean add(java.lang.Object obj)
Add a attribute to the end of the list or replace a existing attribute with the same name and Namespace.

Specified by:
add in interface java.util.Collection
Specified by:
add in interface java.util.List
Overrides:
add in class java.util.AbstractList
Parameters:
obj - The object to insert into the list.
Returns:
true (as per the general contract of Collection.add).
Throws:
java.lang.IndexOutOfBoundsException - if index < 0 || index > size()

add

public void add(int index,
                java.lang.Object obj)
Inserts the specified attribute at the specified position in this list. Shifts the attribute currently at that position (if any) and any subsequent attributes to the right (adds one to their indices).

Specified by:
add in interface java.util.List
Overrides:
add in class java.util.AbstractList
Parameters:
index - The location to set the value to.
obj - The object to insert into the list. throws IndexOutOfBoundsException if index < 0 || index > size()

add

void add(int index,
         Attribute attribute)
Check and add the Attribute to this list at the given index. Note: does not check for duplicate attributes.

Parameters:
index - index where to add Attribute
attribute - Attribute to add

addAll

public boolean addAll(java.util.Collection collection)
Add all the objects in the specified collection.

Specified by:
addAll in interface java.util.Collection
Specified by:
addAll in interface java.util.List
Overrides:
addAll in class java.util.AbstractCollection
Parameters:
collection - The collection containing all the objects to add.
Returns:
true if the list was modified as a result of the add.

addAll

public boolean addAll(int index,
                      java.util.Collection collection)
Inserts the specified collecton at the specified position in this list. Shifts the attribute currently at that position (if any) and any subsequent attributes to the right (adds one to their indices).

Specified by:
addAll in interface java.util.List
Overrides:
addAll in class java.util.AbstractList
Parameters:
index - The offset to start adding the data in the collection
collection - The collection to insert into the list.
Returns:
true if the list was modified as a result of the add. throws IndexOutOfBoundsException if index < 0 || index > size()

clear

public void clear()
Clear the current list.

Specified by:
clear in interface java.util.Collection
Specified by:
clear in interface java.util.List
Overrides:
clear in class java.util.AbstractList

clearAndSet

void clearAndSet(java.util.Collection collection)
Clear the current list and set it to the contents of the Collection. object.

Parameters:
collection - The collection to use.

ensureCapacity

private void ensureCapacity(int minCapacity)
Increases the capacity of this AttributeList instance, if necessary, to ensure that it can hold at least the number of items specified by the minimum capacity argument.

Parameters:
minCapacity - the desired minimum capacity.

get

public java.lang.Object get(int index)
Return the object at the specified offset.

Specified by:
get in interface java.util.List
Specified by:
get in class java.util.AbstractList
Parameters:
index - The offset of the object.
Returns:
The Object which was returned.

get

java.lang.Object get(java.lang.String name,
                     Namespace namespace)
Return the Attribute with the given name and Namespace.

Parameters:
name - name of attribute to return
namespace - Namespace to match
Returns:
the Attribute, or null if one doesn't exist.

indexOf

int indexOf(java.lang.String name,
            Namespace namespace)
Return index of the Attribute with the given name and uri.

remove

public java.lang.Object remove(int index)
Remove the object at the specified offset.

Specified by:
remove in interface java.util.List
Overrides:
remove in class java.util.AbstractList
Parameters:
index - The offset of the object.
Returns:
The Object which was removed.

remove

boolean remove(java.lang.String name,
               Namespace namespace)
Remove the Attribute with the given name and Namespace.

Parameters:
namespace - Namespace to match
Returns:
the true if attribute was removed, false otherwise

set

public java.lang.Object set(int index,
                            java.lang.Object obj)
Set the object at the specified location to the supplied object.

Specified by:
set in interface java.util.List
Overrides:
set in class java.util.AbstractList
Parameters:
index - The location to set the value to.
obj - The location to set the value to.
Returns:
The object which was replaced. throws IndexOutOfBoundsException if index < 0 || index >= size()

set

java.lang.Object set(int index,
                     Attribute attribute)
Set the object at the specified location to the supplied object. Note: does not check for duplicate attributes.

Parameters:
index - The location to set the value to.
attribute - The attribute to set.
Returns:
The object which was replaced. throws IndexOutOfBoundsException if index < 0 || index >= size()

indexOfDuplicate

private int indexOfDuplicate(Attribute attribute)
Return index of attribute with same name and Namespace, or -1 if one doesn't exist

size

public int size()
Return the number of items in this list

Specified by:
size in interface java.util.Collection
Specified by:
size in interface java.util.List
Specified by:
size in class java.util.AbstractCollection
Returns:
The number of items in this list.

toString

public java.lang.String toString()
Return this list as a String

Overrides:
toString in class java.util.AbstractCollection