P
- Type of the (P)arent object containing this collection (e.g., SelectorPart
s have Selector
s as the parent).T
- The (T)ype of units to be grouped with.public final class LinkedSyntaxCollection<P,T extends Groupable<P,T>> extends Object implements SyntaxCollection<P,T>
SyntaxCollection
.
This uses a linked-node approach optimized for random lookups, insertions and removals. Uniqueness is maintained like a set and prevents duplicates. Appending or prepending an existing unit will simply move its position.
Constructor and Description |
---|
LinkedSyntaxCollection(P parent)
Creates a new
LinkedSyntaxCollection with no available Broadcaster . |
Modifier and Type | Method and Description |
---|---|
SyntaxCollection<P,T> |
append(T unit)
Appends the specified unit to the end of this collection.
|
SyntaxCollection<P,T> |
appendAfter(T index,
T unit)
Appends the specified unit after the given index unit.
|
SyntaxCollection<P,T> |
appendAll(Iterable<T> units)
Appends all of the given units to the end of this collection.
|
SyntaxCollection<P,T> |
clear()
Removes all units from this collection.
|
boolean |
contains(T unit)
Gets whether the given unit is contained within this collection.
|
void |
destroyAll()
Calls
Groupable.destroy() on all units. |
<S extends T> |
find(Class<S> klass)
Finds the first item in this collection that is a type of a the given class.
|
Optional<T> |
first()
Gets the first unit in the collection.
|
boolean |
isEmpty()
Gets whether this collection contains any units.
|
boolean |
isEmptyOrNoneWritable()
Gets whether this collection is empty, or all contained elements are not writable.
|
Iterator<T> |
iterator() |
Optional<T> |
last()
Gets the last unit in the collection.
|
Optional<T> |
next(T unit)
Gets the next unit after the given one, if there is one.
|
P |
parent()
Gets the parent
Syntax unit that owns this collection. |
SyntaxCollection<P,T> |
prepend(T unit)
Prepends the specified unit to the beginning of this collection.
|
SyntaxCollection<P,T> |
prependAll(Iterable<T> units)
Prepends all of the given units to the beginning of this collection.
|
SyntaxCollection<P,T> |
prependBefore(T index,
T unit)
Prepends the specified unit before the given index unit.
|
Optional<T> |
previous(T unit)
Gets the previous unit before the given one, if there is one.
|
void |
propagateBroadcast(Broadcaster broadcaster,
Status status)
Calls
Broadcastable#propagateBroadcast(Broadcaster, Status) on all units within this collection using the given
Broadcaster . |
SyntaxCollection<P,T> |
remove(T unit)
Removes a unit from this collection.
|
SyntaxCollection<P,T> |
replaceExistingWith(Iterable<T> units)
Replaces all existing units with the given units.
|
SyntaxCollection<P,T> |
replaceExistingWith(T unit)
Replaces all existing units with the given unit.
|
int |
size()
Gets the number of units in the collection.
|
Stream<T> |
stream()
Returns a
Stream over the contents. |
String |
toString() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
forEach, spliterator
public LinkedSyntaxCollection(P parent)
LinkedSyntaxCollection
with no available Broadcaster
.parent
- The parent that owns this collection. Do not pass null.public int size()
SyntaxCollection
public boolean isEmpty()
SyntaxCollection
public boolean isEmptyOrNoneWritable()
SyntaxCollection
isEmptyOrNoneWritable
in interface SyntaxCollection<P,T extends Groupable<P,T>>
Writable#isWritable()
public boolean contains(T unit)
SyntaxCollection
public Optional<T> first()
SyntaxCollection
public Optional<T> last()
SyntaxCollection
public Optional<T> next(T unit)
SyntaxCollection
public Optional<T> previous(T unit)
SyntaxCollection
public <S extends T> Optional<S> find(Class<S> klass)
SyntaxCollection
public SyntaxCollection<P,T> prepend(T unit)
SyntaxCollection
public SyntaxCollection<P,T> prependAll(Iterable<T> units)
SyntaxCollection
prependAll
in interface SyntaxCollection<P,T extends Groupable<P,T>>
units
- The units to add.public SyntaxCollection<P,T> prependBefore(T index, T unit) throws IllegalArgumentException
SyntaxCollection
The index unit must be present within this collection. If the unit to prepend already exists in this collection it will be moved.
prependBefore
in interface SyntaxCollection<P,T extends Groupable<P,T>>
index
- Prepend before this unit.unit
- Prepend this unit.IllegalArgumentException
- If the index unit is not contained within this collection.public SyntaxCollection<P,T> append(T unit)
SyntaxCollection
public SyntaxCollection<P,T> appendAll(Iterable<T> units)
SyntaxCollection
public SyntaxCollection<P,T> appendAfter(T index, T unit) throws IllegalArgumentException
SyntaxCollection
The index unit must be present within this collection. If the unit to append already exists in this collection it will be moved.
appendAfter
in interface SyntaxCollection<P,T extends Groupable<P,T>>
index
- Append after this unit.unit
- Append this unit.IllegalArgumentException
- If existing is not contained within this collection.public SyntaxCollection<P,T> remove(T unit)
SyntaxCollection
Groupable.destroy()
over this.public SyntaxCollection<P,T> clear()
SyntaxCollection
public SyntaxCollection<P,T> replaceExistingWith(T unit)
SyntaxCollection
replaceExistingWith
in interface SyntaxCollection<P,T extends Groupable<P,T>>
unit
- Replace all existing (if any) units with this one.public SyntaxCollection<P,T> replaceExistingWith(Iterable<T> units)
SyntaxCollection
replaceExistingWith
in interface SyntaxCollection<P,T extends Groupable<P,T>>
units
- Replace all existing (if any) units with these.public void destroyAll()
SyntaxCollection
Groupable.destroy()
on all units.destroyAll
in interface SyntaxCollection<P,T extends Groupable<P,T>>
public P parent()
SyntaxCollection
Syntax
unit that owns this collection.public void propagateBroadcast(Broadcaster broadcaster, Status status)
SyntaxCollection
Broadcastable#propagateBroadcast(Broadcaster, Status)
on all units within this collection using the given
Broadcaster
.propagateBroadcast
in interface SyntaxCollection<P,T extends Groupable<P,T>>
broadcaster
- Propagate using this Broadcaster
.status
- Broadcast units that have this status.public Stream<T> stream()
SyntaxCollection
Stream
over the contents.Copyright (c) 2019, Salesforce.com, Inc. All rights reserved. Licensed under the BSD 3-Clause license. For full license text, see the LICENSE file in the repository.