@MinDoc(copyright="Copyright 2009, 2016 A. Weinert", author="Albrecht Weinert", version="V.33", lastModified="27.03.2021", usage="a limited set of unsorted texts for frequent use", purpose="collect a (limited) set of texts, then use it as quasi immutable") public final class FastStringSet extends Object implements Set<String>
String
s).
Its intended use is for relatively small sets of texts that are once build
and used quite often afterwards, like e.g. lists of roles, filenames or
of types in the context of authenticated user accounts respectively
file criteria or visitors. null is not allowed as entry but the empty
String is.clear()
;
see the warning hint there
).clear()
a FastStringSet
is immutable in the
sense that texts once added will not be removed and internally keep in
the order of insertion.FileCriteria
Constructor and Description |
---|
FastStringSet(CharSequence[] startContent)
Make a Set with initial content.
|
FastStringSet(FastStringSet startContent)
Make a Set with initial content (copy constructor).
|
FastStringSet(int size)
Make an empty Set.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(String e)
Add the text to the set if not yet there.
|
boolean |
add(String s,
int addShortened)
Add a attribute text in original or shortened version.
|
boolean |
addAll(Collection<? extends String> c)
Add all elements of the Collection supplied.
|
boolean |
addAll(Object[] into)
Add all CharSequence elements.
|
boolean |
addTypes(CharSequence types)
Add file type (criteria) entries.
|
String[] |
asArray()
The texts contained in this FastStringSet as internal array.
|
void |
clear()
Remove all elements from this FastStringSet.
|
boolean |
contains(CharSequence s,
boolean ignoreCase,
boolean wildEqual)
Is the specified sequence contained in this FastStringSet.
|
boolean |
contains(Object o)
Is the specified sequence contained in this FastStringSet.
|
boolean |
containsAll(CharSequence[] cS)
Are all sequences in
c also contained in this
FastStringSet. |
boolean |
containsAll(Collection<?> c)
Are all texts in
cS also contained in this FastStringSet. |
Appendable |
csL(Appendable dest)
The content as comma separated list.
|
boolean |
equals(Object o)
Compares this FastStringSet with the specified object for equality.
|
int |
hashCode()
This FastStringSet's hash code.
|
boolean |
isEmpty()
Is this FastStringSet empty.
|
Iterator<String> |
iterator()
An Iterator over this FastStringSet's elements.
|
ArrayList<String> |
list()
The texts contained in this FastStringSet as ArrayList.
|
boolean |
remove(Object o)
Remove the object supplied from this FastStringSet.
|
boolean |
removeAll(Collection<?> c)
Remove all the Collection's objects from this FastStringSet.
|
boolean |
retainAll(Collection<?> c)
Remove all but the Collection's objects from this FastStringSet.
|
boolean |
setTypes(CharSequence types)
Set file type (criteria) entries.
|
int |
size()
The number of texts / Strings contained in this FastStringSet.
|
Object[] |
toArray()
The texts contained in this FastStringSet as array.
|
<T> T[] |
toArray(T[] a)
The texts contained in this FastStringSet as array.
|
String |
toString()
The state / content as multi-line String.
|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
spliterator
parallelStream, removeIf, stream
public FastStringSet(int size)
size
- initial capacity, outside 4..5000 gets 50public FastStringSet(CharSequence[] startContent)
startContent
- the initial size and contentpublic FastStringSet(FastStringSet startContent)
startContent
- the initial size and content as FastStringSet
public boolean add(String e)
add
in interface Collection<String>
add
in interface Set<String>
e
- the text to add; null always returns false, as null is not
allowed as FastStringSet
's elementpublic boolean addAll(Collection<? extends String> c)
c
supplied are members of this set. If c
is null or empty nothing
happens.c
is asked for its array representation
and addAll(Object[])
is used.public boolean addAll(Object[] into)
into
.into
- elements to addpublic boolean add(String s, int addShortened)
s
is null nothing happens and false is
returned. Otherwise s
and / or a shortened version of s
,
if feasible, is added to the set if not yet there in each case.addShortened
= 1 only a shortened version of s
being
the part between the first equals sign (=) and a comma (,) or the end of
s
. If no equals sign (=) is in s
s is added as is.addShortened
= 2 (both) the long original version and,
if possible, the just described short version are both entered.addShortened
only the long original
version is entered.s
- the value (attribute text) to enteraddShortened
- 1: shortened version only; 2: both long and shortened;
else: only s as is (long)public boolean addTypes(CharSequence types)
FastStringSet
. The entries entered will start with a dot (.) and
be in lower case only or be transformed to that format.types
. An empty sequence will be taken as null and cause no
change (return false). types
may freely have forms like
"typ", "*.typ" or "+.typ"; plus
characters + will be transformed to asterisks *. (A leading *. will bear
no information anyway and a single * will be ignored as type.)FileHelper.isOfType(java.io.File, CharSequence)
public boolean setTypes(CharSequence types)
clears
this set. Then it is like
addTypes(CharSequence)
.public void clear()
toArray()
to return arrays containing null elements
and hence violate its contract.public int hashCode()
Set
is defined to be the sum of the hash
codes of the elements in the set.hashCode
in interface Collection<String>
hashCode
in interface Set<String>
hashCode
in class Object
equals(Object)
,
Set.equals(Object)
,
Set.hashCode()
public boolean equals(Object o)
Set
's this method returns true if the other object#
o
is a FastStringSet
of the same size()
containing the same texts.equals
in interface Collection<String>
equals
in interface Set<String>
equals
in class Object
o
- object to be compared for equality with this FastStringSethashCode()
,
containsAll(CharSequence[])
public String toString()
toString
in class Object
TextHelper.format(Appendable, CharSequence, CharSequence[], int)
public Appendable csL(Appendable dest)
public boolean contains(Object o)
CharSequence
) o
supplied.public boolean contains(CharSequence s, boolean ignoreCase, boolean wildEqual)
s
is null.s
supplied
optionally ignoring case and optionally regarding wildcard rules for
this sets entries (see
TextHelper.wildEqual(...)
).s
- sequence the presence of which in this FastStringSet is testedpublic boolean containsAll(CharSequence[] cS)
c
also contained in this
FastStringSet. c
supplied.c
is null or empty, true is returned as no collected objects
are supplied, for which the condition can fail.c
contains any element that is not of type
CharSequence (including null) false is returned, as a FastStringSet will
never contain such elements.cS
- the text the presence of which in this FastStringSet is testedpublic boolean containsAll(Collection<?> c)
cS
also contained in this FastStringSet. cS
supplied.cS
is null or empty, true is returned as no texts are
supplied, for which the condition can fail.cS
contains null as element false is returned, as a
FastStringSet will never contain null elements.containsAll
in interface Collection<String>
containsAll
in interface Set<String>
c
- the collection the presence of it's contained texts in this
FastStringSet is testedClassCastException
- if o
's type is not CharSequence
(or derived including, of course, String)public boolean isEmpty()
public Iterator<String> iterator()
public boolean remove(Object o)
FastStringSet
.remove
in interface Collection<String>
remove
in interface Set<String>
o
- the Object / text to be removed; if no CharSequence false is
returned as o could not be contained, and hence no
remove orderedUnsupportedOperationException
- always (almost)public boolean removeAll(Collection<?> c)
FastStringSet
.removeAll
in interface Collection<String>
removeAll
in interface Set<String>
c
- the Collection of the texts to be removed; if null false is
returned as no remove is ordered thenUnsupportedOperationException
- always (almost)public boolean retainAll(Collection<?> c)
FastStringSet
.retainAll
in interface Collection<String>
retainAll
in interface Set<String>
UnsupportedOperationException
- alwayspublic int size()
public Object[] toArray()
size()
) elements.toArray
in interface Collection<String>
toArray
in interface Set<String>
toArray(Object[])
,
list()
public final String[] asArray()
size()
non null elements; if it is longer, the elements following
will be null. A null element may be taken as end marker.toArray(Object[])
,
list()
public ArrayList<String> list()
size()
) elements.toArray(Object[])
,
toArray()
public <T> T[] toArray(T[] a)
a
if that is big enough. If it is longer than size()
a[size()
] will be set null as an end marker. a
's elements
beyond, if any, are left unchanged.a
is shorter than size()
a new
array of the same (run time) type and fitting length will be made and
returned instead.toArray
in interface Collection<String>
toArray
in interface Set<String>
a
- the array into which this FastStringSet's Strings are to be
stored, if it is big enough; otherwise, a new array of the same
runtime type is made (and returned) for this purpose.a
itselfArrayStoreException
- ifa
's type is not String or of
a String's supertypeNullPointerException
- if a
is nulltoArray()
,
list()
,
Arrays.copyOf(Object[], int, Class)