Module org.jhotdraw8.fxcollection
Class AbstractIndexedArrayObservableSet<E>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractList<E>
javafx.collections.ObservableListBase<E>
org.jhotdraw8.fxcollection.indexedset.AbstractIndexedArrayObservableSet<E>
- Type Parameters:
E- the element type
- All Implemented Interfaces:
Iterable<E>,Collection<E>,List<E>,SequencedCollection<E>,Set<E>,javafx.beans.Observable,javafx.collections.ObservableList<E>,ReadOnlyCollection<E>,ReadOnlySequencedCollection<E>,ReadOnlySequencedSet<E>,ReadOnlySet<E>
- Direct Known Subclasses:
IndexedArrayObservableSet,IndexedHashObservableSet
public abstract class AbstractIndexedArrayObservableSet<E>
extends javafx.collections.ObservableListBase<E>
implements Set<E>, ReadOnlySequencedSet<E>, ReadOnlySet<E>
Abstract base class for
Sets that provide precise control where each
element is inserted.
The set is backed by an array. Insertion and removal is in O(n)
and contains check is O(n), where n is the number of elements.
This class is useful as a base class for sub-classes that can provide
a faster means of the contains check, typically in O(1).
- Author:
- Werner Randelshofer
-
Field Summary
Fields inherited from class java.util.AbstractList
modCount -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance.AbstractIndexedArrayObservableSet(Collection<? extends E> col) Creates a new instance and adds all elements of the specified collection to it. -
Method Summary
Modifier and TypeMethodDescriptionvoidbooleanbooleanaddAll(int index, Collection<? extends E> c) booleanaddAll(Collection<? extends E> c) booleanprotected booleanbooleanvoidfireItemUpdated(int index) get(int index) final EgetFirst()getLast()booleaninthashCode()intiterator()listIterator(int index) protected abstract booleanmayBeAdded(E e) Returns true if the specified element can be added to this set.voidmove(int oldIndex, int newIndex) Moves an element atoldIndextonewIndex.protected abstract voidThis method is invoked after an element has been added.protected abstract @Nullable BooleanonContains(E e) This method is called, when acontains(Object)check is needed.protected abstract voidThis method is invoked after an element has been removed.remove(int index) booleanbooleanremoveAll(Collection<?> c) voidremoveRange(int fromIndex, int toIndex) booleanretainAll(Collection<?> c) booleansetAll(Collection<? extends E> col) intsize()stream()subList(int fromIndex, int toIndex) Methods inherited from class javafx.collections.ObservableListBase
addAll, addListener, addListener, beginChange, endChange, fireChange, hasListeners, nextAdd, nextPermutation, nextRemove, nextRemove, nextReplace, nextSet, nextUpdate, remove, removeAll, removeListener, removeListener, retainAll, setAllMethods inherited from class java.util.AbstractList
clear, lastIndexOf, listIteratorMethods inherited from class java.util.AbstractCollection
containsAll, isEmpty, toArray, toArray, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, toArrayMethods inherited from interface java.util.List
addFirst, addLast, clear, containsAll, isEmpty, lastIndexOf, listIterator, removeFirst, removeLast, replaceAll, reversed, sort, toArray, toArrayMethods inherited from interface javafx.beans.Observable
subscribeMethods inherited from interface javafx.collections.ObservableList
filtered, sorted, sortedMethods inherited from interface org.jhotdraw8.icollection.readonly.ReadOnlyCollection
containsAll, isEmpty, toArray, toArrayMethods inherited from interface org.jhotdraw8.icollection.readonly.ReadOnlySequencedCollection
asCollectionMethods inherited from interface org.jhotdraw8.icollection.readonly.ReadOnlySequencedSet
asSetMethods inherited from interface org.jhotdraw8.icollection.readonly.ReadOnlySet
characteristics
-
Constructor Details
-
AbstractIndexedArrayObservableSet
public AbstractIndexedArrayObservableSet()Creates a new instance. -
AbstractIndexedArrayObservableSet
Creates a new instance and adds all elements of the specified collection to it.- Parameters:
col- A collection.
-
-
Method Details
-
setAll
-
addAll
-
addAll
-
removeAll
-
retainAll
-
add
-
move
public void move(int oldIndex, int newIndex) Moves an element atoldIndextonewIndex.So that
indexOf(element) == newIndex;- Parameters:
oldIndex- the current index of the elementnewIndex- the desired new index of the element
-
doAdd
-
set
-
contains
- Specified by:
containsin interfaceCollection<E>- Specified by:
containsin interfaceList<E>- Specified by:
containsin interfaceReadOnlyCollection<E>- Specified by:
containsin interfaceSet<E>- Overrides:
containsin classAbstractCollection<E>
-
remove
-
remove
-
removeRange
public void removeRange(int fromIndex, int toIndex) - Overrides:
removeRangein classAbstractList<E>
-
subList
-
get
-
size
public int size()- Specified by:
sizein interfaceCollection<E>- Specified by:
sizein interfaceList<E>- Specified by:
sizein interfaceReadOnlyCollection<E>- Specified by:
sizein interfaceSet<E>- Specified by:
sizein classAbstractCollection<E>
-
add
-
listIterator
- Specified by:
listIteratorin interfaceList<E>- Overrides:
listIteratorin classAbstractList<E>
-
onRemoved
This method is invoked after an element has been removed.Subclasses can implement this method to remove it from a data structure that can answer
onContains(E).- Parameters:
e- the removed element
-
onAdded
This method is invoked after an element has been added.Subclasses can implement this method to add it from a data structure that can answer
onContains(E).- Parameters:
e- the added element
-
onContains
This method is called, when acontains(Object)check is needed.Subclasses can implement this method to provide a fast contains check.
- Parameters:
e- an object- Returns:
- true if the object is a member of this set, false if the object is not a member of this set, null if it is not known whether the object is a member of the set or not
-
indexOf
-
getFirst
- Specified by:
getFirstin interfaceList<E>- Specified by:
getFirstin interfaceReadOnlySequencedCollection<E>- Specified by:
getFirstin interfaceSequencedCollection<E>
-
getLast
- Specified by:
getLastin interfaceList<E>- Specified by:
getLastin interfaceReadOnlySequencedCollection<E>- Specified by:
getLastin interfaceSequencedCollection<E>
-
spliterator
- Specified by:
spliteratorin interfaceCollection<E>- Specified by:
spliteratorin interfaceIterable<E>- Specified by:
spliteratorin interfaceList<E>- Specified by:
spliteratorin interfaceSet<E>
-
stream
- Specified by:
streamin interfaceCollection<E>- Specified by:
streamin interfaceReadOnlyCollection<E>
-
fireItemUpdated
public void fireItemUpdated(int index) -
hasChangeListeners
public boolean hasChangeListeners() -
mayBeAdded
Returns true if the specified element can be added to this set.Subclasses can return false if they only want to include elements based on a predicate check.
- Parameters:
e- an object- Returns:
- true if the object may be added to this set
-
equals
- Specified by:
equalsin interfaceCollection<E>- Specified by:
equalsin interfaceList<E>- Specified by:
equalsin interfaceReadOnlySet<E>- Specified by:
equalsin interfaceSet<E>- Overrides:
equalsin classAbstractList<E>
-
hashCode
public int hashCode()- Specified by:
hashCodein interfaceCollection<E>- Specified by:
hashCodein interfaceList<E>- Specified by:
hashCodein interfaceReadOnlySet<E>- Specified by:
hashCodein interfaceSet<E>- Overrides:
hashCodein classAbstractList<E>
-
iterator
-
readOnlyReversed
- Specified by:
readOnlyReversedin interfaceReadOnlySequencedCollection<E>- Specified by:
readOnlyReversedin interfaceReadOnlySequencedSet<E>
-