Class ContentList

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

A non-public list implementation holding only legal JDOM content, including content for Document or Element nodes. Users see this class as a simple List implementation.

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

Nested Class Summary
(package private)  classContentList.FilterList
          FilterList represents legal JDOM content, including content for Documents or Elements.
(package private)  classContentList.FilterListIterator
           
 
Field Summary
private static intADD
           
private static intCREATE
          Used inner class FilterListIterator to help hasNext and hasPrevious the next index of our cursor (must be here for JDK1.1).
private static java.lang.StringCVS_ID
           
private  Content[]elementData
          Our backing list
private static intHASNEXT
           
private static intHASPREV
           
private static intINITIAL_ARRAY_SIZE
           
private static intNEXT
           
private  Parentparent
          Document or Element this list belongs to
private static intPREV
           
private static intREMOVE
           
private  intsize
           
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
ContentList(Parent parent)
          Force either a Document or Element parent
 
Method Summary
(package private)  voidadd(int index, Content child)
          Check and add the Element to this list at the given index.
 voidadd(int index, java.lang.Object obj)
          Inserts the specified object at the specified position in this list.
 booleanaddAll(java.util.Collection collection)
          Add the specified collecton to the end of this list.
 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  voiddocumentCanContain(int index, Content child)
           
private static voidelementCanContain(int index, Content child)
           
(package private)  voidensureCapacity(int minCapacity)
          Increases the capacity of this ContentList 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.
private  intgetModCount()
          Give access of ContentList.modCount to FilterList
(package private)  java.util.ListgetView(Filter filter)
          Return a view of this list based on the given filter.
(package private)  intindexOfDocType()
          Return the index of the DocType element in the list.
(package private)  intindexOfFirstElement()
          Return the index of the first Element in the list.
 java.lang.Objectremove(int index)
          Remove the object at the specified offset.
private static voidremoveParent(Content c)
          Remove the parent of a 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)  voiduncheckedAddContent(Content c)
          Package internal method to support building from sources that are 100% trusted.
 
Methods inherited from class java.util.AbstractList
add, 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, isEmpty, remove, removeAll, retainAll, 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

CREATE

private static final int CREATE
Used inner class FilterListIterator to help hasNext and hasPrevious the next index of our cursor (must be here for JDK1.1).

See Also:
Constant Field Values

HASPREV

private static final int HASPREV
See Also:
Constant Field Values

HASNEXT

private static final int HASNEXT
See Also:
Constant Field Values

PREV

private static final int PREV
See Also:
Constant Field Values

NEXT

private static final int NEXT
See Also:
Constant Field Values

ADD

private static final int ADD
See Also:
Constant Field Values

REMOVE

private static final int REMOVE
See Also:
Constant Field Values

elementData

private Content[] elementData
Our backing list

size

private int size

parent

private Parent parent
Document or Element this list belongs to

Constructor Detail

ContentList

ContentList(Parent parent)
Force either a Document or Element parent

Method Detail

uncheckedAddContent

final void uncheckedAddContent(Content c)
Package internal method to support building from sources that are 100% trusted.

Parameters:
c - content to add without any checks

add

public void add(int index,
                java.lang.Object obj)
Inserts the specified object at the specified position in this list. Shifts the object currently at that position (if any) and any subsequent objects 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()

documentCanContain

private void documentCanContain(int index,
                                Content child)
                         throws IllegalAddException
Throws:
IllegalAddException
See Also:
ContentList#add(int, org.jdom.Content)

elementCanContain

private static void elementCanContain(int index,
                                      Content child)
                               throws IllegalAddException
Throws:
IllegalAddException

add

void add(int index,
         Content child)
Check and add the Element to this list at the given index.

Parameters:
index - index where to add Element
child - Element to add

addAll

public boolean addAll(java.util.Collection collection)
Add the specified collecton to the end of this list.

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 to add to the list.
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 object currently at that position (if any) and any subsequent objects 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

void ensureCapacity(int minCapacity)
Increases the capacity of this ContentList 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.

getView

java.util.List getView(Filter filter)
Return a view of this list based on the given filter.

Parameters:
filter - Filter for this view.
Returns:
a list representing the rules of the Filter.

indexOfFirstElement

int indexOfFirstElement()
Return the index of the first Element in the list. If the parent is a Document then the element is the root element. If the list contains no Elements, it returns -1.

Returns:
index of first element, or -1 if one doesn't exist

indexOfDocType

int indexOfDocType()
Return the index of the DocType element in the list. If the list contains no DocType, it returns -1.

Returns:
index of the DocType, or -1 if it doesn't exist

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.

removeParent

private static void removeParent(Content c)
Remove the parent of a Object

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()

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
Returns:
The number of items in this list.

getModCount

private int getModCount()
Give access of ContentList.modCount to FilterList