站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > NetBeans API Javadoc (Current Development Version)

GapList (Editor Utilities) - NetBeans API Javadoc (Current Development Version)

org.netbeans.modules.editor.util/1 1.17

org.netbeans.lib.editor.util
Class GapList<E>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by org.netbeans.lib.editor.util.GapList<E>
All Implemented Interfaces:
Serializable, Cloneable, Iterable<E>, Collection<E>, List<E>, RandomAccess
Direct Known Subclasses:
FlyOffsetGapList, OffsetGapList

public class GapList<E>
extends AbstractList<E>
implements List<E>, RandomAccess, Cloneable, Serializable

List implementation that stores items in an array with a gap.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
GapList()
          Constructs an empty list with an initial capacity of ten.
GapList(Collection<? extends E> c)
          Constructs a list containing the elements of the specified collection, in the order they are returned by the collection's iterator.
GapList(int initialCapacity)
          Constructs an empty list with the specified initial capacity.
 
Method Summary
 boolean add(E element)
          Appends the specified element to the end of this list.
 void add(int index, E element)
          Inserts the specified element at the specified position in this list.
 boolean addAll(Collection<? extends E> c)
          Appends all of the elements in the specified Collection to the end of this list, in the order that they are returned by the specified Collection's Iterator.
 boolean addAll(int index, Collection<? extends E> c)
          Inserts all of the elements in the specified Collection into this list, starting at the specified position.
 boolean addArray(int index, Object[] elements)
           
 boolean addArray(int index, Object[] elements, int off, int len)
          Inserts elements from the given array into this list, starting at the given index.
 void clear()
          Removes all of the elements from this list.
 Object clone()
          Returns a shallow copy of this GapList instance.
protected  void consistencyCheck()
          Internal consistency check.
protected  void consistencyError(String s)
           
 boolean contains(Object elem)
          Returns true if this list contains the specified element.
 void copyElements(int startIndex, int endIndex, Collection<E> dest)
          Copy elements of this list between the given index range to the end of the given collection.
 void copyElements(int startIndex, int endIndex, Object[] dest, int destIndex)
          Copy elements of this list between the given index range to the given object array.
 void copyItems(int startIndex, int endIndex, Object[] dest, int destIndex)
          Deprecated. use copyElements(int, int, Object[], int) which performs the same operation
protected  String dumpDetails()
           
static String dumpElements(List l)
           
protected  String dumpInternals()
           
 void ensureCapacity(int minCapacity)
          Increases the capacity of this GapList instance, if necessary, to ensure that it can hold at least the number of elements specified by the minimum capacity argument.
 E get(int index)
          Returns the element at the specified position in this list.
 int indexOf(Object elem)
          Searches for the first occurence of the given argument, testing for equality using the equals method.
 boolean isEmpty()
          Tests if this list has no elements.
 int lastIndexOf(Object elem)
          Returns the index of the last occurrence of the specified object in this list.
 E remove(int index)
          Removes the element at the specified position in this list.
 void remove(int index, int count)
          Removes elements at the given index.
protected  void removeRange(int fromIndex, int toIndex)
          Removes from this List all of the elements whose index is between fromIndex, inclusive and toIndex, exclusive.
 E set(int index, E element)
          Replaces the element at the specified position in this list with the specified element.
 int size()
          Returns the number of elements in this list.
 void swap(int index1, int index2)
          Swap elements at the given indexes.
 Object[] toArray()
          Returns an array containing all of the elements in this list in the correct order.
<T> T[]
toArray(T[] a)
          Returns an array containing all of the elements in this list in the correct order; the runtime type of the returned array is that of the specified array.
 String toString()
           
 void trimToSize()
          Trims the capacity of this GapList instance to be the list's current size.
 
Methods inherited from class java.util.AbstractList
equals, hashCode, iterator, listIterator, listIterator, subList
 
Methods inherited from class java.util.AbstractCollection
containsAll, remove, removeAll, retainAll
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
containsAll, equals, hashCode, iterator, listIterator, listIterator, remove, removeAll, retainAll, subList
 

Constructor Detail

GapList

public GapList(int initialCapacity)
Constructs an empty list with the specified initial capacity.

Parameters:
initialCapacity - the initial capacity of the list.
Throws:
IllegalArgumentException - if the specified initial capacity is negative

GapList

public GapList()
Constructs an empty list with an initial capacity of ten.


GapList

public GapList(Collection<? extends E> c)
Constructs a list containing the elements of the specified collection, in the order they are returned by the collection's iterator. The GapList instance has an initial capacity of 110% the size of the specified collection.

Parameters:
c - the collection whose elements are to be placed into this list.
Throws:
NullPointerException - if the specified collection is null.
Method Detail

trimToSize

public void trimToSize()
Trims the capacity of this GapList instance to be the list's current size. An application can use this operation to minimize the storage of an GapList instance.


ensureCapacity

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

Parameters:
minCapacity - the desired minimum capacity.

size

public int size()
Returns the number of elements in this list.

Specified by:
size in interface Collection<E>
Specified by:
size in interface List<E>
Specified by:
size in class AbstractCollection<E>
Returns:
the number of elements in this list.

isEmpty

public boolean isEmpty()
Tests if this list has no elements.

Specified by:
isEmpty in interface Collection<E>
Specified by:
isEmpty in interface List<E>
Overrides:
isEmpty in class AbstractCollection<E>
Returns:
true if this list has no elements; false otherwise.

contains

public boolean contains(Object elem)
Returns true if this list contains the specified element.

Specified by:
contains in interface Collection<E>
Specified by:
contains in interface List<E>
Overrides:
contains in class AbstractCollection<E>
Parameters:
elem - element whose presence in this List is to be tested.
Returns:
true if the specified element is present; false otherwise.

indexOf

public int indexOf(Object elem)
Searches for the first occurence of the given argument, testing for equality using the equals method.

Specified by:
indexOf in interface List<E>
Overrides:
indexOf in class AbstractList<E>
Parameters:
elem - an object.
Returns:
the index of the first occurrence of the argument in this list; returns -1 if the object is not found.
See Also:
Object.equals(Object)

lastIndexOf

public int lastIndexOf(Object elem)
Returns the index of the last occurrence of the specified object in this list.

Specified by:
lastIndexOf in interface List<E>
Overrides:
lastIndexOf in class AbstractList<E>
Parameters:
elem - the desired element.
Returns:
the index of the last occurrence of the specified object in this list; returns -1 if the object is not found.

clone

public Object clone()
Returns a shallow copy of this GapList instance. (The elements themselves are not copied.)

Overrides:
clone in class Object
Returns:
a clone of this GapList instance.

copyItems

public void copyItems(int startIndex,
                      int endIndex,
                      Object[] dest,
                      int destIndex)
Deprecated. use copyElements(int, int, Object[], int) which performs the same operation


copyElements

public void copyElements(int startIndex,
                         int endIndex,
                         Object[] dest,
                         int destIndex)
Copy elements of this list between the given index range to the given object array.

Parameters:
startIndex - start index of the region of this list to be copied.
endIndex - end index of the region of this list to be copied.
dest - collection to the end of which the items should be copied.

copyElements

public void copyElements(int startIndex,
                         int endIndex,
                         Collection<E> dest)
Copy elements of this list between the given index range to the end of the given collection.

Parameters:
startIndex - start index of the region of this list to be copied.
endIndex - end index of the region of this list to be copied.
dest - collection to the end of which the items should be copied.

toArray

public Object[] toArray()
Returns an array containing all of the elements in this list in the correct order.

Specified by:
toArray in interface Collection<E>
Specified by:
toArray in interface List<E>
Overrides:
toArray in class AbstractCollection<E>
Returns:
an array containing all of the elements in this list in the correct order.

toArray

public <T> T[] toArray(T[] a)
Returns an array containing all of the elements in this list in the correct order; the runtime type of the returned array is that of the specified array. If the list fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this list.

If the list fits in the specified array with room to spare (i.e., the array has more elements than the list), the element in the array immediately following the end of the collection is set to null. This is useful in determining the length of the list only if the caller knows that the list does not contain any null elements.

Specified by:
toArray in interface Collection<E>
Specified by:
toArray in interface List<E>
Overrides:
toArray in class AbstractCollection<E>
Parameters:
a - the array into which the elements of the list are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose.
Returns:
an array containing the elements of the list.
Throws:
ArrayStoreException - if the runtime type of a is not a supertype of the runtime type of every element in this list.

get

public E get(int index)
Returns the element at the specified position in this list.

Specified by:
get in interface List<E>
Specified by:
get in class AbstractList<E>
Parameters:
index - index of element to return.
Returns:
the element at the specified position in this list.
Throws:
IndexOutOfBoundsException - if index is out of range (index < 0 || index >= size()).

set

public E set(int index,
             E element)
Replaces the element at the specified position in this list with the specified element.

Specified by:
set in interface List<E>
Overrides:
set in class AbstractList<E>
Parameters:
index - index of element to replace.
element - element to be stored at the specified position.
Returns:
the element previously at the specified position.
Throws:
IndexOutOfBoundsException - if index out of range (index < 0 || index >= size()).

swap

public void swap(int index1,
                 int index2)
Swap elements at the given indexes.


add

public boolean add(E element)
Appends the specified element to the end of this list.

Specified by:
add in interface Collection<E>
Specified by:
add in interface List<E>
Overrides:
add in class AbstractList<E>
Parameters:
element - non-null element to be appended to this list.
Returns:
true (as per the general contract of Collection.add).

add

public void add(int index,
                E element)
Inserts the specified element at the specified position in this list. Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).

Specified by:
add in interface List<E>
Overrides:
add in class AbstractList<E>
Parameters:
index - index at which the specified element is to be inserted.
element - element to be inserted.
Throws:
IndexOutOfBoundsException - if index is out of range (index < 0 || index > size()).

addAll

public boolean addAll(Collection<? extends E> c)
Appends all of the elements in the specified Collection to the end of this list, in the order that they are returned by the specified Collection's Iterator. The behavior of this operation is undefined if the specified Collection is modified while the operation is in progress. (This implies that the behavior of this call is undefined if the specified Collection is this list, and this list is nonempty.)

Specified by:
addAll in interface Collection<E>
Specified by:
addAll in interface List<E>
Overrides:
addAll in class AbstractCollection<E>
Parameters:
c - the elements to be inserted into this list.
Returns:
true if this list changed as a result of the call.
Throws:
NullPointerException - if the specified collection is null.

addAll

public boolean addAll(int index,
                      Collection<? extends E> c)
Inserts all of the elements in the specified Collection into this list, starting at the specified position. Shifts the element currently at that position (if any) and any subsequent elements to the right (increases their indices). The new elements will appear in the list in the order that they are returned by the specified Collection's iterator.

Specified by:
addAll in interface List<E>
Overrides:
addAll in class AbstractList<E>
Parameters:
index - index at which to insert first element from the specified collection.
c - elements to be inserted into this list.
Returns:
true if this list changed as a result of the call.
Throws:
IndexOutOfBoundsException - if index out of range (index < 0 || index > size()).
NullPointerException - if the specified Collection is null.

addArray

public boolean addArray(int index,
                        Object[] elements)

addArray

public boolean addArray(int index,
                        Object[] elements,
                        int off,
                        int len)
Inserts elements from the given array into this list, starting at the given index.

Parameters:
index - index at which to insert first element.
elements - array of elements from which to insert elements.
off - offset in the elements pointing to first element to copy.
len - number of elements to copy from the elements array.

clear

public void clear()
Removes all of the elements from this list. The list will be empty after this call returns.

Specified by:
clear in interface Collection<E>
Specified by:
clear in interface List<E>
Overrides:
clear in class AbstractList<E>

remove

public E remove(int index)
Removes the element at the specified position in this list. Shifts any subsequent elements to the left (subtracts one from their indices).

Specified by:
remove in interface List<E>
Overrides:
remove in class AbstractList<E>
Parameters:
index - the index of the element to removed.
Returns:
the element that was removed from the list.
Throws:
IndexOutOfBoundsException - if index out of range (index < 0 || index >= size()).

remove

public void remove(int index,
                   int count)
Removes elements at the given index.

Parameters:
index - index of the first element to be removed.
count - number of elements to remove.

removeRange

protected void removeRange(int fromIndex,
                           int toIndex)
Removes from this List all of the elements whose index is between fromIndex, inclusive and toIndex, exclusive. Shifts any succeeding elements to the left (reduces their index). This call shortens the list by (toIndex - fromIndex) elements. (If toIndex==fromIndex, this operation has no effect.)

Overrides:
removeRange in class AbstractList<E>
Parameters:
fromIndex - index of first element to be removed.
toIndex - index after last element to be removed.

consistencyCheck

protected void consistencyCheck()
Internal consistency check.


consistencyError

protected final void consistencyError(String s)

dumpDetails

protected String dumpDetails()

dumpInternals

protected String dumpInternals()

toString

public String toString()
Overrides:
toString in class AbstractCollection<E>

dumpElements

public static String dumpElements(List l)

org.netbeans.modules.editor.util/1 1.17

Built on May 28 2007.  |  Portions Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.