Top Description Inners Fields Constructors Methods
org.jdom2

pack-priv final Class AttributeList

extends AbstractList<Attribute>
implements RandomAccess
Class Inheritance
All Implemented Interfaces
java.util.RandomAccess
Imports
java.util.*, org.jdom2.internal.ArrayCopy

AttributeList represents legal JDOM Attribute content.

This class is NOT PUBLIC; users should see it as a simple List implementation, although it behaves something like a Set because you cannot add duplicate Attributes. An attribute is considered duplicate if it has the same Namespace URI and Attribute name as another existing Attribute.

Authors
Alex Rosen, Philippe Riand, Bradley S. Huffman, Rolf Lear

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
AttributeList.ALIterator

A fast iterator that can beat AbstractList because we can access the data directly.

Field Summary

Modifier and TypeField and Description
private static final Comparator<Attribute>
private Attribute[]
attributeData

The backing array

private static final int
INITIAL_ARRAY_SIZE

The initial size to start the backing array.

private final Element
parent

The parent Element

private int
size

The current size

Inherited from java.util.AbstractList:
modCount

Constructor Summary

AccessConstructor and Description
pack-priv
AttributeList(final Element
Element whose Attributes are to be held
parent
)

Create a new instance of the AttributeList representing parent Element's Attributes

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true as specified by Collection.add().
add
(final Attribute
The Attribute to insert into the list.
attribute
)

Overrides java.util.AbstractList.add.

Implements java.util.List.add, java.util.Collection.add.

Check and add attribute to the end of the list or replace an existing Attribute with the same name and Namespace.
public void
add(final int
where to add/insert the Attribute
index
,
final Attribute
Attribute to add
attribute
)

Overrides java.util.AbstractList.add.

Implements java.util.List.add.

Check and add attribute to this list at index.
public boolean

Returns:

true if the list was modified as a result of the add.
addAll
(final Collection<? extends Attribute>
The Collection of Attributes to add.
collection
)

Overrides java.util.AbstractCollection.addAll.

Implements java.util.List.addAll, java.util.Collection.addAll.

Add all the Attributes in collection.
public boolean

Returns:

true if the list was modified as a result of the add.
addAll
(final int
The offset at which to start adding the Attributes
index
,
final Collection<? extends Attribute>
The Collection containing the Attributes to add.
collection
)

Overrides java.util.AbstractList.addAll.

Implements java.util.List.addAll.

Inserts the Attributes in collection at the specified index in this list.
private final int

Returns:

the insertion point.
binarySearch
(final int[]
The pointers to search within
indexes
,
final int
The number of pointers to search within
len
,
final int
The pointer we are checking for.
val
,
final Comparator<? super Attribute>
The Comparator to compare with
comp
)

Unlike the Arrays.binarySearch, this method never expects an "already exists" condition, we only ever add, thus there will never be a negative insertion-point.

public void
clear()

Overrides java.util.AbstractList.clear.

Implements java.util.List.clear, java.util.Collection.clear.

Clear the current list.
pack-priv void
clearAndSet(final Collection<? extends Attribute>
The Collection to use.
collection
)

Clear the current list and set it to the contents of collection.

private void
ensureCapacity(final int
the desired minimum capacity.
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.

public Attribute

Returns:

The Attribute at position index.
get
(final int
The position of the Attribute to retrieve.
index
)

Implements abstract java.util.AbstractList.get.

Implements java.util.List.get.

Retrieve the Attribute at offset.
pack-priv Attribute

Returns:

the Attribute, or null if one doesn't exist.
get
(final String
name of attribute to return
name
,
final Namespace
indicate what Namespace URI to consider
namespace
)

Retrieve the Attribute with the given name and the same Namespace URI as namespace.

pack-priv int

Returns:

the index of the attribute that matches the conditions, or -1 if there is none.
indexOf
(final String
name of Attribute to retrieve
name
,
final Namespace
indicate what Namespace URI to consider
namespace
)

Return index of the Attribute with the given name and the same Namespace URI as namespace.

private int
indexOfDuplicate(final Attribute attribute)

Return index of attribute with same name and Namespace, or -1 if one doesn't exist

public boolean
isEmpty()

Overrides java.util.AbstractCollection.isEmpty.

Implements java.util.List.isEmpty, java.util.Collection.isEmpty.

Returns true if this list contains no elements.
public Iterator<Attribute>

Returns:

an iterator.
iterator
()

Overrides java.util.AbstractList.iterator.

Implements java.util.List.iterator, java.util.Collection.iterator.

Returns an Iterator over the Attributes in this list in the proper sequence.
public Attribute

Returns:

The removed Attribute.
remove
(final int
The offset of the Attribute to remove.
index
)

Overrides java.util.AbstractList.remove.

Implements java.util.List.remove.

Remove the Attribute at index.
pack-priv boolean

Returns:

the true if attribute was removed, false otherwise
remove
(final String
name of Attribute to remove
name
,
final Namespace
indicate what Namespace URI to consider
namespace
)

Remove the Attribute with the specified name and the same URI as namespace.

public Attribute

Returns:

The replaced Attribute.
set
(final int
The location to set the value to.
index
,
final Attribute
The Attribute to set.
attribute
)

Overrides java.util.AbstractList.set.

Implements java.util.List.set.

Set the Attribute at index to be attribute.
public int

Returns:

The number of Attributes in this list.
size
()

Implements abstract java.util.AbstractCollection.size.

Implements java.util.List.size, java.util.Collection.size.

Return the number of Attributes in this list
public void
sort(Comparator<? super Attribute>
The Comparator to use for sorting.
comp
)

Overrides default java.util.List.sort.

Sort the attributes using the supplied comparator.
private void
sortInPlace(final int[] indexes)

public String
toString()

Overrides java.util.AbstractCollection.toString.

Return this list as a String
pack-priv final void
uncheckedAddAttribute(final Attribute
an Attribute to add without any checks
a
)

Package internal method to support building from sources that are 100% trusted.

Inherited from java.util.AbstractList:
equalshashCodeindexOflastIndexOflistIteratorlistIteratorremoveRangesubList

Field Detail

ATTRIBUTE_NATURALback to summary
private static final Comparator<Attribute> ATTRIBUTE_NATURAL
attributeDataback to summary
private Attribute[] attributeData

The backing array

INITIAL_ARRAY_SIZEback to summary
private static final int INITIAL_ARRAY_SIZE

The initial size to start the backing array.

parentback to summary
private final Element parent

The parent Element

sizeback to summary
private int size

The current size

Constructor Detail

AttributeListback to summary
pack-priv AttributeList(final Element parent)

Create a new instance of the AttributeList representing parent Element's Attributes

Parameters
parent:Element

Element whose Attributes are to be held

Method Detail

addback to summary
public boolean add(final Attribute attribute)

Overrides java.util.AbstractList.add.

Implements java.util.List.add, java.util.Collection.add.

Check and add attribute to the end of the list or replace an existing Attribute with the same name and Namespace.

Parameters
attribute:Attribute

The Attribute to insert into the list.

Returns:boolean

true as specified by Collection.add().

Annotations
@Override
Exceptions
IllegalAddException:
if validation rules prevent the add
addback to summary
public void add(final int index, final Attribute attribute)

Overrides java.util.AbstractList.add.

Implements java.util.List.add.

Check and add attribute to this list at index.

Parameters
index:int

where to add/insert the Attribute

attribute:Attribute

Attribute to add

Annotations
@Override
Exceptions
IllegalAddException:
if validation rules prevent the add
addAllback to summary
public boolean addAll(final Collection<? extends Attribute> collection)

Overrides java.util.AbstractCollection.addAll.

Implements java.util.List.addAll, java.util.Collection.addAll.

Add all the Attributes in collection.

Parameters
collection:Collection<? extends Attribute>

The Collection of Attributes to add.

Returns:boolean

true if the list was modified as a result of the add.

Annotations
@Override
Exceptions
IllegalAddException:
if validation rules prevent the addAll
addAllback to summary
public boolean addAll(final int index, final Collection<? extends Attribute> collection)

Overrides java.util.AbstractList.addAll.

Implements java.util.List.addAll.

Inserts the Attributes in collection at the specified index in this list.

Parameters
index:int

The offset at which to start adding the Attributes

collection:Collection<? extends Attribute>

The Collection containing the Attributes to add.

Returns:boolean

true if the list was modified as a result of the add.

Annotations
@Override
Exceptions
IllegalAddException:
if validation rules prevent the addAll
binarySearchback to summary
private final int binarySearch(final int[] indexes, final int len, final int val, final Comparator<? super Attribute> comp)

Unlike the Arrays.binarySearch, this method never expects an "already exists" condition, we only ever add, thus there will never be a negative insertion-point.

Parameters
indexes:int[]

The pointers to search within

len:int

The number of pointers to search within

val:int

The pointer we are checking for.

comp:Comparator<? super Attribute>

The Comparator to compare with

Returns:int

the insertion point.

clearback to summary
public void clear()

Overrides java.util.AbstractList.clear.

Implements java.util.List.clear, java.util.Collection.clear.

Clear the current list.

Annotations
@Override
clearAndSetback to summary
pack-priv void clearAndSet(final Collection<? extends Attribute> collection)

Clear the current list and set it to the contents of collection.

Parameters
collection:Collection<? extends Attribute>

The Collection to use.

Exceptions
IllegalAddException:
if validation rules prevent the addAll
ensureCapacityback to summary
private void ensureCapacity(final 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:int

the desired minimum capacity.

getback to summary
public Attribute get(final int index)

Implements abstract java.util.AbstractList.get.

Implements java.util.List.get.

Retrieve the Attribute at offset.

Parameters
index:int

The position of the Attribute to retrieve.

Returns:Attribute

The Attribute at position index.

Annotations
@Override
getback to summary
pack-priv Attribute get(final String name, final Namespace namespace)

Retrieve the Attribute with the given name and the same Namespace URI as namespace.

Parameters
name:String

name of attribute to return

namespace:Namespace

indicate what Namespace URI to consider

Returns:Attribute

the Attribute, or null if one doesn't exist.

indexOfback to summary
pack-priv int indexOf(final String name, final Namespace namespace)

Return index of the Attribute with the given name and the same Namespace URI as namespace.

Parameters
name:String

name of Attribute to retrieve

namespace:Namespace

indicate what Namespace URI to consider

Returns:int

the index of the attribute that matches the conditions, or -1 if there is none.

indexOfDuplicateback to summary
private int indexOfDuplicate(final Attribute attribute)

Return index of attribute with same name and Namespace, or -1 if one doesn't exist

isEmptyback to summary
public boolean isEmpty()

Overrides java.util.AbstractCollection.isEmpty.

Implements java.util.List.isEmpty, java.util.Collection.isEmpty.

Doc from java.util.List.isEmpty.

Returns true if this list contains no elements.

Returns:boolean

true if this list contains no elements

Annotations
@Override
iteratorback to summary
public Iterator<Attribute> iterator()

Overrides java.util.AbstractList.iterator.

Implements java.util.List.iterator, java.util.Collection.iterator.

Returns an Iterator over the Attributes in this list in the proper sequence.

Returns:Iterator<Attribute>

an iterator.

Annotations
@Override
removeback to summary
public Attribute remove(final int index)

Overrides java.util.AbstractList.remove.

Implements java.util.List.remove.

Remove the Attribute at index.

Parameters
index:int

The offset of the Attribute to remove.

Returns:Attribute

The removed Attribute.

Annotations
@Override
removeback to summary
pack-priv boolean remove(final String name, final Namespace namespace)

Remove the Attribute with the specified name and the same URI as namespace.

Parameters
name:String

name of Attribute to remove

namespace:Namespace

indicate what Namespace URI to consider

Returns:boolean

the true if attribute was removed, false otherwise

setback to summary
public Attribute set(final int index, final Attribute attribute)

Overrides java.util.AbstractList.set.

Implements java.util.List.set.

Set the Attribute at index to be attribute.

Parameters
index:int

The location to set the value to.

attribute:Attribute

The Attribute to set.

Returns:Attribute

The replaced Attribute.

Annotations
@Override
Exceptions
IllegalAddException:
if validation rules prevent the set
sizeback to summary
public int size()

Implements abstract java.util.AbstractCollection.size.

Implements java.util.List.size, java.util.Collection.size.

Return the number of Attributes in this list

Returns:int

The number of Attributes in this list.

Annotations
@Override
sortback to summary
public void sort(Comparator<? super Attribute> comp)

Overrides default java.util.List.sort.

Sort the attributes using the supplied comparator. The attributes are never added using regular mechanisms, so there are never problems with detached or already-attached Attributes. The sort happens 'in place'.

If the comparator identifies two (or more) Attributes to be equal, then the relative order of those attributes will not be changed.

Parameters
comp:Comparator<? super Attribute>

The Comparator to use for sorting.

sortInPlaceback to summary
private void sortInPlace(final int[] indexes)
toStringback to summary
public String toString()

Overrides java.util.AbstractCollection.toString.

Return this list as a String

Returns:String

Doc from java.util.AbstractCollection.toString.

a string representation of this collection

Annotations
@Override
uncheckedAddAttributeback to summary
pack-priv final void uncheckedAddAttribute(final Attribute a)

Package internal method to support building from sources that are 100% trusted.

Parameters
a:Attribute

an Attribute to add without any checks

org.jdom2 back to summary

private final Class AttributeList.ALIterator

extends Object
implements Iterator<Attribute>
Class Inheritance
All Implemented Interfaces
java.util.Iterator

A fast iterator that can beat AbstractList because we can access the data directly. This is important because so much code now uses the for-each type loop for (Attribute a : element.getAttributes()) {...}, and that uses iterator().
Author
Rolf Lear

Field Summary

Modifier and TypeField and Description
private boolean
private int
private int

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public boolean
hasNext()

Implements java.util.Iterator.hasNext.

Returns true if the iteration has more elements.
public Attribute
next()

Implements java.util.Iterator.next.

Returns the next element in the iteration.
public void
remove()

Overrides default java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation).
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

canremoveback to summary
private boolean canremove
cursorback to summary
private int cursor
expectback to summary
private int expect

Constructor Detail

ALIteratorback to summary
private ALIterator()

Method Detail

hasNextback to summary
public boolean hasNext()

Implements java.util.Iterator.hasNext.

Doc from java.util.Iterator.hasNext.

Returns true if the iteration has more elements. (In other words, returns true if next would return an element rather than throwing an exception.)

Returns:boolean

true if the iteration has more elements

Annotations
@Override
nextback to summary
public Attribute next()

Implements java.util.Iterator.next.

Doc from java.util.Iterator.next.

Returns the next element in the iteration.

Returns:Attribute

the next element in the iteration

Annotations
@Override
removeback to summary
public void remove()

Overrides default java.util.Iterator.remove.

Doc from java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation). This method can be called only once per call to next.

The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method, unless an overriding class has specified a concurrent modification policy.

The behavior of an iterator is unspecified if this method is called after a call to the forEachRemaining method.

Annotations
@Override