    All Packages  Class Hierarchy  This Package  Previous  Next  Index

# Class collections.Dynarray

    java.lang.Object
       |
       +----collections.UpdatableImpl
               |
               +----collections.UpdatableSeqImpl
                       |
                       +----collections.Dynarray

public class Dynarray
extends UpdatableSeqImpl
implements UpdatableSeq, SortableCollection

Dynamically allocated and resized Arrays. Beyond implementing its interfaces, adds methods to adjust capacities. The default heuristics for resizing usually work fine, but you can adjust them manually when you need to. Dynarrays are generally like java.util.Vectors. But unlike them, Dynarrays do not actually allocate arrays when they are constructed. Among other consequences, you can adjust the capacity `for free' after construction but before adding elements. You can adjust it at other times as well, but this may lead to more expensive resizing. Also, unlike Vectors, they release their internal arrays whenever they are empty.

##

array_
  The elements, or null if no buffer yet allocated.
minCapacity
  The minimum capacity of any non-empty buffer

##

Dynarray()
  Make a new empty Dynarray.
Dynarray(Predicate)
  Make an empty Dynarray with given element screener
Dynarray(Predicate, Object[], int)
  Special version of constructor needed by clone()

##

appendElements(Enumeration)
  Implements collections.UpdatableSeq.appendElements.
at(int)
  Implements collections.Seq.at.
capacity()
  return the current internal buffer capacity (zero if no buffer allocated).
capacity(int)
  Set the internal buffer capacity to max(size(), newCap).
checkImplementation()
  Implements collections.ImplementationCheckable.checkImplementation.
clear()
  Implements collections.UpdatableCollection.clear.
clone()
  Make an independent copy.
elements()
  Implements collections.Collection.elements.
exclude(Object)
  Implements collections.UpdatableCollection.exclude.
first()
  Implements collections.Seq.first.
firstIndexOf(Object)
  Implements collections.Seq.firstIndexOf.
firstIndexOf(Object, int)
  Implements collections.Seq.firstIndexOf.
includes(Object)
  Implements collections.Collection.includes.
insertAt(int, Object)
  Implements collections.UpdatableSeq.insertAt.
insertElementsAt(int, Enumeration)
  Implements collections.UpdatableSeq.insertElementsAt.
insertFirst(Object)
  Implements collections.UpdatableSeq.insertFirst.
insertLast(Object)
  Implements collections.UpdatableSeq.insertLast.
last()
  Implements collections.Seq.last.
lastIndexOf(Object)
  Implements collections.Seq.lastIndexOf.
lastIndexOf(Object, int)
  Implements collections.Seq.lastIndexOf.
occurrencesOf(Object)
  Implements collections.Collection.occurrencesOf.
prependElements(Enumeration)
  Implements collections.UpdatableSeq.prependElements.
quickSort(Object[], int, int, Comparator)
  An implementation of Quicksort using medians of 3 for partitions.
removeAt(int)
  Implements collections.UpdatableSeq.removeAt.
removeFirst()
  Implements collections.UpdatableSeq.removeFirst.
removeFromTo(int, int)
  Implements collections.UpdatableSeq.removeFromTo.
removeLast()
  Implements collections.UpdatableSeq.removeLast.
removeOneOf(Object)
  Implements collections.UpdatableCollection.removeOneOf.
replaceAllOf(Object, Object)
  Implements collections.UpdatableCollection.replaceAllOf.
replaceAt(int, Object)
  Implements collections.UpdatableSeq.replaceAt.
replaceFirst(Object)
  Implements collections.UpdatableSeq.replaceFirst.
replaceLast(Object)
  Implements collections.UpdatableSeq.replaceLast.
replaceOneOf(Object, Object)
  Implements collections.UpdatableCollection.replaceOneOf Time complexity: O(n).
sort(Comparator)
  Implements collections.SortableCollection.sort.
subseq(int, int)
  Implements collections.Seq.subseq.
take()
  Implements collections.UpdatableCollection.take.

##

minCapacity

     public static final int minCapacity

  The minimum capacity of any non-empty buffer

array_

     protected Object array_[]

  The elements, or null if no buffer yet allocated.

##

Dynarray

     public Dynarray()

  Make a new empty Dynarray.

Dynarray

     public Dynarray(Predicate screener)

  Make an empty Dynarray with given element screener

Dynarray

     protected Dynarray(Predicate s,
                        Object b[],
                        int c)

  Special version of constructor needed by clone()

##

clone

     protected Object clone() throws CloneNotSupportedException

  Make an independent copy. The elements themselves are not cloned

  Overrides:
    clone in class Object

capacity

     public synchronized int capacity()

  return the current internal buffer capacity (zero if no buffer allocated).

  Returns:
    capacity (always greater than or equal to size())

capacity

     public synchronized void capacity(int newCap)

  Set the internal buffer capacity to max(size(), newCap). That is, if given an argument less than the current number of elements, the capacity is just set to the current number of elements. Thus, elements are never lost by setting the capacity.

  Parameters:
    newCap - the desired capacity.
  Returns:
    condition:

         capacity() >= size() &&
         version() != PREV(this).version() == (capacity() != PREV(this).capacity())

includes

     public synchronized boolean includes(Object element)

  Implements collections.Collection.includes. Time complexity: O(n).

  Overrides:
    includes in class UpdatableImpl
  See Also:
    includes

occurrencesOf

     public synchronized int occurrencesOf(Object element)

  Implements collections.Collection.occurrencesOf. Time complexity: O(n).

  Overrides:
    occurrencesOf in class UpdatableImpl
  See Also:
    occurrencesOf

elements

     public synchronized CollectionEnumeration elements()

  Implements collections.Collection.elements. Time complexity: O(1).

  Overrides:
    elements in class UpdatableImpl
  See Also:
    elements

first

     public synchronized Object first() throws NoSuchElementException

  Implements collections.Seq.first. Time complexity: O(1).

  Overrides:
    first in class UpdatableSeqImpl
  See Also:
    first

last

     public synchronized Object last() throws NoSuchElementException

  Implements collections.Seq.last. Time complexity: O(1).

  Overrides:
    last in class UpdatableSeqImpl
  See Also:
    last

at

     public synchronized Object at(int index) throws NoSuchElementException

  Implements collections.Seq.at. Time complexity: O(1).

  Overrides:
    at in class UpdatableSeqImpl
  See Also:
    at

firstIndexOf

     public synchronized int firstIndexOf(Object element,
                                          int startingIndex)

  Implements collections.Seq.firstIndexOf. Time complexity: O(n).

  Overrides:
    firstIndexOf in class UpdatableSeqImpl
  See Also:
    firstIndexOf

lastIndexOf

     public synchronized int lastIndexOf(Object element,
                                         int startingIndex)

  Implements collections.Seq.lastIndexOf. Time complexity: O(n).

  Overrides:
    lastIndexOf in class UpdatableSeqImpl
  See Also:
    lastIndexOf

firstIndexOf

     public synchronized int firstIndexOf(Object element)

  Implements collections.Seq.firstIndexOf. Time complexity: O(n).

  Overrides:
    firstIndexOf in class UpdatableSeqImpl
  See Also:
    firstIndexOf

lastIndexOf

     public synchronized int lastIndexOf(Object element)

  Implements collections.Seq.lastIndexOf. Time complexity: O(n).

  Overrides:
    lastIndexOf in class UpdatableSeqImpl
  See Also:
    lastIndexOf

subseq

     public synchronized Seq subseq(int from,
                                    int length) throws NoSuchElementException

  Implements collections.Seq.subseq. Time complexity: O(length).

  Overrides:
    subseq in class UpdatableSeqImpl
  See Also:
    subseq

clear

     public synchronized void clear()

  Implements collections.UpdatableCollection.clear. Time complexity: O(1).

  Overrides:
    clear in class UpdatableImpl
  See Also:
    clear

removeOneOf

     public synchronized void removeOneOf(Object element)

  Implements collections.UpdatableCollection.removeOneOf. Time complexity: O(n).

  Overrides:
    removeOneOf in class UpdatableImpl
  See Also:
    removeOneOf

replaceOneOf

     public synchronized void replaceOneOf(Object oldElement,
                                           Object newElement) throws IllegalElementException

  Implements collections.UpdatableCollection.replaceOneOf Time complexity: O(n).

  Overrides:
    replaceOneOf in class UpdatableImpl
  See Also:
    replaceOneOf

replaceAllOf

     public synchronized void replaceAllOf(Object oldElement,
                                           Object newElement) throws IllegalElementException

  Implements collections.UpdatableCollection.replaceAllOf. Time complexity: O(n * number of replacements).

  Overrides:
    replaceAllOf in class UpdatableImpl
  See Also:
    replaceAllOf

exclude

     public synchronized void exclude(Object element)

  Implements collections.UpdatableCollection.exclude. Time complexity: O(n * occurrencesOf(element)).

  Overrides:
    exclude in class UpdatableImpl
  See Also:
    exclude

take

     public synchronized Object take() throws NoSuchElementException

  Implements collections.UpdatableCollection.take. Time complexity: O(1). Takes the rightmost element of the array.

  Overrides:
    take in class UpdatableImpl
  See Also:
    take

sort

     public void sort(Comparator cmp)

  Implements collections.SortableCollection.sort. Time complexity: O(n log n). Uses a quicksort-based algorithm.

  See Also:
    sort

insertFirst

     public synchronized void insertFirst(Object element) throws IllegalElementException

  Implements collections.UpdatableSeq.insertFirst. Time complexity: O(n)

  Overrides:
    insertFirst in class UpdatableSeqImpl
  See Also:
    insertFirst

replaceFirst

     public synchronized void replaceFirst(Object element) throws IllegalElementException

  Implements collections.UpdatableSeq.replaceFirst. Time complexity: O(1).

  Overrides:
    replaceFirst in class UpdatableSeqImpl
  See Also:
    replaceFirst

removeFirst

     public synchronized void removeFirst() throws NoSuchElementException

  Implements collections.UpdatableSeq.removeFirst. Time complexity: O(n).

  Overrides:
    removeFirst in class UpdatableSeqImpl
  See Also:
    removeFirst

insertLast

     public synchronized void insertLast(Object element) throws IllegalElementException

  Implements collections.UpdatableSeq.insertLast. Time complexity: normally O(1), but O(n) if size() == capacity().

  Overrides:
    insertLast in class UpdatableSeqImpl
  See Also:
    insertLast

replaceLast

     public synchronized void replaceLast(Object element) throws IllegalElementException, NoSuchElementException

  Implements collections.UpdatableSeq.replaceLast. Time complexity: O(1).

  Overrides:
    replaceLast in class UpdatableSeqImpl
  See Also:
    replaceLast

removeLast

     public synchronized void removeLast() throws NoSuchElementException

  Implements collections.UpdatableSeq.removeLast. Time complexity: O(1).

  Overrides:
    removeLast in class UpdatableSeqImpl
  See Also:
    removeLast

insertAt

     public synchronized void insertAt(int index,
                                       Object element) throws IllegalElementException, NoSuchElementException

  Implements collections.UpdatableSeq.insertAt. Time complexity: O(n).

  Overrides:
    insertAt in class UpdatableSeqImpl
  See Also:
    insertAt

removeAt

     public synchronized void removeAt(int index) throws NoSuchElementException

  Implements collections.UpdatableSeq.removeAt. Time complexity: O(n).

  Overrides:
    removeAt in class UpdatableSeqImpl
  See Also:
    removeAt

replaceAt

     public synchronized void replaceAt(int index,
                                        Object element) throws IllegalElementException, NoSuchElementException

  Implements collections.UpdatableSeq.replaceAt. Time complexity: O(1).

  Overrides:
    replaceAt in class UpdatableSeqImpl
  See Also:
    replaceAt

prependElements

     public synchronized void prependElements(Enumeration e) throws IllegalElementException, CorruptedEnumerationException

  Implements collections.UpdatableSeq.prependElements. Time complexity: O(n + number of elements in e) if (e instanceof CollectionEnumeration) else O(n * number of elements in e)

  Overrides:
    prependElements in class UpdatableSeqImpl
  See Also:
    prependElements

appendElements

     public synchronized void appendElements(Enumeration e) throws IllegalElementException, CorruptedEnumerationException

  Implements collections.UpdatableSeq.appendElements. Time complexity: O(number of elements in e)

  Overrides:
    appendElements in class UpdatableSeqImpl
  See Also:
    appendElements

insertElementsAt

     public synchronized void insertElementsAt(int index,
                                               Enumeration e) throws IllegalElementException, CorruptedEnumerationException, NoSuchElementException

  Implements collections.UpdatableSeq.insertElementsAt. Time complexity: O(n + number of elements in e) if (e instanceof CollectionEnumeration) else O(n * number of elements in e)

  Overrides:
    insertElementsAt in class UpdatableSeqImpl
  See Also:
    insertElementsAt

removeFromTo

     public synchronized void removeFromTo(int fromIndex,
                                           int toIndex) throws NoSuchElementException

  Implements collections.UpdatableSeq.removeFromTo. Time complexity: O(n).

  Overrides:
    removeFromTo in class UpdatableSeqImpl
  See Also:
    removeFromTo

quickSort

     public static void quickSort(Object s[],
                                  int lo,
                                  int hi,
                                  Comparator cmp)

  An implementation of Quicksort using medians of 3 for partitions. Used internally by sort. It is public and static so it can be used to sort plain arrays as well.

  Parameters:
    s, - the array to sort
    lo, - the least index to sort from
    hi, - the greatest index
    cmp, - the comparator to use for comparing elements

checkImplementation

     public synchronized void checkImplementation() throws ImplementationError

  Implements collections.ImplementationCheckable.checkImplementation.

  Overrides:
    checkImplementation in class UpdatableImpl
  See Also:
    checkImplementation

    All Packages  Class Hierarchy  This Package  Previous  Next  Index