I
- symbol class.public final class WordBuilder<I> extends AbstractList<I>
Word
s.
As Word
s are - like strings - immutable objects, constructing them by subsequent
invocations of Word.concat(Word...)
etc. is highly inefficient. This class provides an
efficient means of construction by operating on an internal storage during construction,
only creating a Word
(and thus requiring to ensure immutability) when the method toWord()
(or toWord(int, int)
is invoked.
Note that due to the specifics of the underlying word implementation, even after an invocation
of toWord()
the storage does not have to be duplicated unless it either is required
due to capacity adjustment or a non-appending change (such as setSymbol(int, Object)
or truncate(int)
) is made.
Nearly all modification methods of this class return a this-reference, allowing constructs
such as
builder.append(foo).append(bar).append(baz);
modCount
Constructor and Description |
---|
WordBuilder()
Constructor.
|
WordBuilder(I initSym,
int count)
Constructor.
|
WordBuilder(int initialCapacity)
Constructor.
|
WordBuilder(int capacity,
I initSym,
int count)
Constructor.
|
WordBuilder(int capacity,
Word<I> init)
Constructor.
|
WordBuilder(Word<I> init)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(I e) |
WordBuilder<I> |
append(I... symbols)
Appends several symbols to the contents of the internal storage.
|
WordBuilder<I> |
append(I symbol)
Appends a symbol to the contents of the internal storage.
|
WordBuilder<I> |
append(List<? extends I> symList) |
WordBuilder<I> |
append(Word<? extends I>... words)
Appends several words to the contents of the internal storage.
|
WordBuilder<I> |
append(Word<? extends I> word)
Appends a word to the contents of the internal storage.
|
void |
clear() |
void |
ensureAdditionalCapacity(int add)
Ensures that the internal storage has additionally the given
capacity.
|
void |
ensureCapacity(int cap)
Ensures that the internal storage has in total the given capacity
|
I |
get(int index) |
I |
getSymbol(int index)
Retrieves the symbol at the given index
|
WordBuilder<I> |
repeatAppend(int num,
I symbol)
Appends num copies of a symbol to the contents of the
internal storage.
|
WordBuilder<I> |
repeatAppend(int num,
Word<I> word)
Appends num copies of the given word to the contents
of the initial storage.
|
WordBuilder<I> |
reverse() |
I |
set(int index,
I element) |
WordBuilder<I> |
setSymbol(int index,
I symbol)
Sets the symbol at the given index.
|
int |
size() |
Word<I> |
toWord()
Creates a word from the contents of the internal storage.
|
Word<I> |
toWord(int fromIndex,
int toIndex)
Creates a word from the given range of the contents of the internal storage.
|
WordBuilder<I> |
truncate(int truncLen)
Truncates the contents of the initial storage to the given length.
|
add, addAll, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, removeRange, subList
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
addAll, contains, containsAll, isEmpty, remove, removeAll, replaceAll, retainAll, sort, spliterator, toArray, toArray
parallelStream, removeIf, stream
public WordBuilder()
public WordBuilder(int initialCapacity)
initialCapacity
- the initial capacity of the internal storage.public WordBuilder(I initSym, int count)
initSym
- the initial symbolcount
- the initial symbol countpublic WordBuilder(int capacity, I initSym, int count)
capacity
- the initial capacity of the internal storage.initSym
- the initial symbolcount
- the initial symbol countpublic WordBuilder(Word<I> init)
init
- the word to initialize the builder with.public WordBuilder<I> append(List<? extends I> symList)
public WordBuilder<I> append(Word<? extends I> word)
word
- the word to append.@SafeVarargs public final WordBuilder<I> append(Word<? extends I>... words)
words
- the words to appendpublic WordBuilder<I> repeatAppend(int num, Word<I> word)
num
- the number of copiesword
- the wordpublic WordBuilder<I> append(I symbol)
symbol
- the symbol to appendpublic WordBuilder<I> repeatAppend(int num, I symbol)
num
- the number of copiessymbol
- the symbol@SafeVarargs public final WordBuilder<I> append(I... symbols)
symbols
- the symbols to appendpublic void ensureCapacity(int cap)
cap
- the minimum capacity to ensurepublic void ensureAdditionalCapacity(int add)
add
- the additional capacity to ensurepublic I getSymbol(int index)
index
- the index to retrievepublic WordBuilder<I> setSymbol(int index, I symbol)
index
- the index to manipulatesymbol
- the symbol to setpublic WordBuilder<I> truncate(int truncLen)
truncLen
- the length to truncate topublic Word<I> toWord(int fromIndex, int toIndex)
WordBuilder
.fromIndex
- the starting indextoIndex
- the end indexpublic Word<I> toWord()
WordBuilder
.public boolean add(I e)
add
in interface Collection<I>
add
in interface List<I>
add
in class AbstractList<I>
public I get(int index)
public void clear()
clear
in interface Collection<I>
clear
in interface List<I>
clear
in class AbstractList<I>
public int size()
size
in interface Collection<I>
size
in interface List<I>
size
in class AbstractCollection<I>
public WordBuilder<I> reverse()
Copyright © 2015. All rights reserved.