Class CharHashBag
- java.lang.Object
-
- org.eclipse.collections.impl.primitive.AbstractCharIterable
-
- org.eclipse.collections.impl.bag.mutable.primitive.CharHashBag
-
- All Implemented Interfaces:
java.io.Externalizable
,java.io.Serializable
,CharBag
,MutableCharBag
,CharIterable
,MutableCharCollection
,PrimitiveIterable
public class CharHashBag extends AbstractCharIterable implements MutableCharBag, java.io.Externalizable
CharHashBag is similar toHashBag
, and is memory-optimized for char primitives. This file was automatically generated from template file primitiveHashBag.stg.- Since:
- 3.0.
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
CharHashBag.InternalIterator
-
Field Summary
Fields Modifier and Type Field Description private CharIntHashMap
items
private static long
serialVersionUID
private int
size
-
Constructor Summary
Constructors Constructor Description CharHashBag()
CharHashBag(char... elements)
CharHashBag(int size)
CharHashBag(CharIterable iterable)
CharHashBag(CharHashBag bag)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(char item)
boolean
addAll(char... source)
boolean
addAll(CharIterable source)
void
addOccurrences(char item, int occurrences)
boolean
allSatisfy(CharPredicate predicate)
Returns true if all of the elements in the CharIterable return true for the specified predicate, otherwise returns false.boolean
anySatisfy(CharPredicate predicate)
Returns true if any of the elements in the CharIterable return true for the specified predicate, otherwise returns false.void
appendString(java.lang.Appendable appendable, java.lang.String start, java.lang.String separator, java.lang.String end)
Prints a string representation of this collection onto the givenAppendable
.MutableCharBag
asSynchronized()
MutableCharBag
asUnmodifiable()
MutableList<CharIntPair>
bottomOccurrences(int count)
Returns thecount
least frequently occurring items.MutableCharIterator
charIterator()
Returns a primitive iterator that can be used to iterate over the CharIterable in an imperative style.RichIterable<CharIterable>
chunk(int size)
Partitions elements in fixed size chunks.void
clear()
<V> MutableBag<V>
collect(CharToObjectFunction<? extends V> function)
Returns a new collection with the results of applying the specified function on each element of the source collection.boolean
contains(char value)
Returns true if the value is contained in the CharIterable, and false if it is not.int
count(CharPredicate predicate)
Returns a count of the number of elements in the CharIterable that return true for the specified predicate.char
detectIfNone(CharPredicate predicate, char ifNone)
void
each(CharProcedure procedure)
A synonym for forEach.boolean
equals(java.lang.Object otherBag)
Follows the same general contract asBag.equals(Object)
.void
forEachWithOccurrences(CharIntProcedure procedure)
For each distinct item, with the number of occurrences, execute the specified procedure.int
hashCode()
Follows the same general contract asBag.hashCode()
.<T> T
injectInto(T injectedValue, ObjectCharToObjectFunction<? super T,? extends T> function)
boolean
isEmpty()
Returns true if this iterable has zero items.char
max()
char
min()
static CharHashBag
newBag(int size)
static CharHashBag
newBag(CharBag source)
static CharHashBag
newBag(CharIterable source)
static CharHashBag
newBagWith(char... source)
CharHashBag
newEmpty()
Creates a new empty CharHashBag.boolean
noneSatisfy(CharPredicate predicate)
Returns true if none of the elements in the CharIterable return true for the specified predicate, otherwise returns false.boolean
notEmpty()
The English equivalent of !this.isEmpty()int
occurrencesOf(char item)
The occurrences of a distinct item in the bag.protected MutableList<CharIntPair>
occurrencesSortingBy(int n, IntFunction<CharIntPair> function, MutableList<CharIntPair> returnWhenEmpty)
void
readExternal(java.io.ObjectInput in)
CharHashBag
reject(CharPredicate predicate)
Returns a new CharIterable with all of the elements in the CharIterable that return false for the specified predicate.boolean
remove(char item)
boolean
removeAll(char... source)
boolean
removeAll(CharIterable source)
boolean
removeIf(CharPredicate predicate)
boolean
removeOccurrences(char item, int occurrences)
boolean
retainAll(char... source)
boolean
retainAll(CharIterable source)
CharHashBag
select(CharPredicate predicate)
Returns a new CharIterable with all of the elements in the CharIterable that return true for the specified predicate.CharHashBag
selectByOccurrences(IntPredicate predicate)
Returns all elements of the bag that have a number of occurrences that satisfy the predicate.MutableCharSet
selectUnique()
Returns all elements of the bag that have exactly one occurrence.int
size()
Returns the number of items in this iterable.int
sizeDistinct()
The size of the Bag when counting only distinct elements.long
sum()
char[]
toArray()
Converts the CharIterable to a primitive char array.char[]
toArray(char[] array)
Converts the CharIterable to a primitive char array.ImmutableCharBag
toImmutable()
Returns an immutable copy of this bag.protected MutableList<CharIntPair>
toListWithOccurrences()
MutableList<CharIntPair>
topOccurrences(int count)
Returns thecount
most frequently occurring items.CharHashBag
with(char element)
CharHashBag
with(char element1, char element2)
CharHashBag
with(char element1, char element2, char element3)
CharHashBag
withAll(CharIterable iterable)
CharHashBag
without(char element)
CharHashBag
withoutAll(CharIterable iterable)
void
writeExternal(java.io.ObjectOutput out)
-
Methods inherited from class org.eclipse.collections.impl.primitive.AbstractCharIterable
asLazy, average, maxIfEmpty, median, minIfEmpty, toBag, toList, toSet, toSortedArray, toSortedList, toString
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.eclipse.collections.api.bag.primitive.CharBag
toStringOfItemToCount
-
Methods inherited from interface org.eclipse.collections.api.CharIterable
asLazy, average, averageIfEmpty, collect, collectBoolean, collectByte, collectChar, collectDouble, collectFloat, collectInt, collectLong, collectShort, containsAll, containsAll, containsAny, containsAny, containsNone, containsNone, flatCollect, forEach, injectIntoBoolean, injectIntoByte, injectIntoChar, injectIntoDouble, injectIntoFloat, injectIntoInt, injectIntoLong, injectIntoShort, maxIfEmpty, median, medianIfEmpty, minIfEmpty, reduce, reduceIfEmpty, reject, select, summaryStatistics, toBag, toList, toSet, toSortedArray, toSortedList, toSortedList, toSortedListBy, toSortedListBy
-
Methods inherited from interface org.eclipse.collections.api.bag.primitive.MutableCharBag
selectDuplicates, tap
-
Methods inherited from interface org.eclipse.collections.api.PrimitiveIterable
appendString, appendString, makeString, makeString, makeString, toString
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
items
private CharIntHashMap items
-
size
private int size
-
-
Constructor Detail
-
CharHashBag
public CharHashBag()
-
CharHashBag
public CharHashBag(int size)
-
CharHashBag
public CharHashBag(CharIterable iterable)
-
CharHashBag
public CharHashBag(char... elements)
-
CharHashBag
public CharHashBag(CharHashBag bag)
-
-
Method Detail
-
newBag
public static CharHashBag newBag(int size)
-
newBagWith
public static CharHashBag newBagWith(char... source)
-
newBag
public static CharHashBag newBag(CharIterable source)
-
newBag
public static CharHashBag newBag(CharBag source)
-
isEmpty
public boolean isEmpty()
Description copied from interface:PrimitiveIterable
Returns true if this iterable has zero items.- Specified by:
isEmpty
in interfacePrimitiveIterable
-
notEmpty
public boolean notEmpty()
Description copied from interface:PrimitiveIterable
The English equivalent of !this.isEmpty()- Specified by:
notEmpty
in interfacePrimitiveIterable
-
size
public int size()
Description copied from interface:PrimitiveIterable
Returns the number of items in this iterable.- Specified by:
size
in interfacePrimitiveIterable
-
sizeDistinct
public int sizeDistinct()
Description copied from interface:CharBag
The size of the Bag when counting only distinct elements.- Specified by:
sizeDistinct
in interfaceCharBag
-
clear
public void clear()
- Specified by:
clear
in interfaceMutableCharCollection
-
with
public CharHashBag with(char element)
- Specified by:
with
in interfaceMutableCharBag
- Specified by:
with
in interfaceMutableCharCollection
-
with
public CharHashBag with(char element1, char element2)
-
with
public CharHashBag with(char element1, char element2, char element3)
-
withAll
public CharHashBag withAll(CharIterable iterable)
- Specified by:
withAll
in interfaceMutableCharBag
- Specified by:
withAll
in interfaceMutableCharCollection
-
without
public CharHashBag without(char element)
- Specified by:
without
in interfaceMutableCharBag
- Specified by:
without
in interfaceMutableCharCollection
-
withoutAll
public CharHashBag withoutAll(CharIterable iterable)
- Specified by:
withoutAll
in interfaceMutableCharBag
- Specified by:
withoutAll
in interfaceMutableCharCollection
-
contains
public boolean contains(char value)
Description copied from interface:CharIterable
Returns true if the value is contained in the CharIterable, and false if it is not.- Specified by:
contains
in interfaceCharIterable
-
occurrencesOf
public int occurrencesOf(char item)
Description copied from interface:CharBag
The occurrences of a distinct item in the bag.- Specified by:
occurrencesOf
in interfaceCharBag
-
forEachWithOccurrences
public void forEachWithOccurrences(CharIntProcedure procedure)
Description copied from interface:CharBag
For each distinct item, with the number of occurrences, execute the specified procedure.- Specified by:
forEachWithOccurrences
in interfaceCharBag
-
selectByOccurrences
public CharHashBag selectByOccurrences(IntPredicate predicate)
Description copied from interface:MutableCharBag
Returns all elements of the bag that have a number of occurrences that satisfy the predicate.- Specified by:
selectByOccurrences
in interfaceCharBag
- Specified by:
selectByOccurrences
in interfaceMutableCharBag
-
selectUnique
public MutableCharSet selectUnique()
Description copied from interface:MutableCharBag
Returns all elements of the bag that have exactly one occurrence.- Specified by:
selectUnique
in interfaceCharBag
- Specified by:
selectUnique
in interfaceMutableCharBag
-
topOccurrences
public MutableList<CharIntPair> topOccurrences(int count)
Description copied from interface:MutableCharBag
Returns thecount
most frequently occurring items. In the event of a tie, all of the items with the number of occurrences that match the occurrences of the last item will be returned.- Specified by:
topOccurrences
in interfaceCharBag
- Specified by:
topOccurrences
in interfaceMutableCharBag
-
bottomOccurrences
public MutableList<CharIntPair> bottomOccurrences(int count)
Description copied from interface:MutableCharBag
Returns thecount
least frequently occurring items. In the event of a tie, all of the items with the number of occurrences that match the occurrences of the last item will be returned.- Specified by:
bottomOccurrences
in interfaceCharBag
- Specified by:
bottomOccurrences
in interfaceMutableCharBag
-
occurrencesSortingBy
protected MutableList<CharIntPair> occurrencesSortingBy(int n, IntFunction<CharIntPair> function, MutableList<CharIntPair> returnWhenEmpty)
-
toListWithOccurrences
protected MutableList<CharIntPair> toListWithOccurrences()
-
add
public boolean add(char item)
- Specified by:
add
in interfaceMutableCharCollection
-
remove
public boolean remove(char item)
- Specified by:
remove
in interfaceMutableCharCollection
-
removeIf
public boolean removeIf(CharPredicate predicate)
- Specified by:
removeIf
in interfaceMutableCharCollection
-
addAll
public boolean addAll(char... source)
- Specified by:
addAll
in interfaceMutableCharCollection
-
addAll
public boolean addAll(CharIterable source)
- Specified by:
addAll
in interfaceMutableCharCollection
-
removeAll
public boolean removeAll(char... source)
- Specified by:
removeAll
in interfaceMutableCharCollection
-
removeAll
public boolean removeAll(CharIterable source)
- Specified by:
removeAll
in interfaceMutableCharCollection
-
retainAll
public boolean retainAll(CharIterable source)
- Specified by:
retainAll
in interfaceMutableCharCollection
- See Also:
Collection.retainAll(Collection)
-
retainAll
public boolean retainAll(char... source)
- Specified by:
retainAll
in interfaceMutableCharCollection
- See Also:
Collection.retainAll(Collection)
-
addOccurrences
public void addOccurrences(char item, int occurrences)
- Specified by:
addOccurrences
in interfaceMutableCharBag
-
removeOccurrences
public boolean removeOccurrences(char item, int occurrences)
- Specified by:
removeOccurrences
in interfaceMutableCharBag
-
each
public void each(CharProcedure procedure)
Description copied from interface:CharIterable
A synonym for forEach.- Specified by:
each
in interfaceCharIterable
- Since:
- 7.0.
-
select
public CharHashBag select(CharPredicate predicate)
Description copied from interface:CharIterable
Returns a new CharIterable with all of the elements in the CharIterable that return true for the specified predicate.- Specified by:
select
in interfaceCharBag
- Specified by:
select
in interfaceCharIterable
- Specified by:
select
in interfaceMutableCharBag
- Specified by:
select
in interfaceMutableCharCollection
-
reject
public CharHashBag reject(CharPredicate predicate)
Description copied from interface:CharIterable
Returns a new CharIterable with all of the elements in the CharIterable that return false for the specified predicate.- Specified by:
reject
in interfaceCharBag
- Specified by:
reject
in interfaceCharIterable
- Specified by:
reject
in interfaceMutableCharBag
- Specified by:
reject
in interfaceMutableCharCollection
-
injectInto
public <T> T injectInto(T injectedValue, ObjectCharToObjectFunction<? super T,? extends T> function)
- Specified by:
injectInto
in interfaceCharIterable
-
chunk
public RichIterable<CharIterable> chunk(int size)
Description copied from interface:CharIterable
Partitions elements in fixed size chunks.- Specified by:
chunk
in interfaceCharIterable
- Parameters:
size
- the number of elements per chunk- Returns:
- A
RichIterable
containingCharIterable
s of sizesize
, except the last will be truncated if the elements don't divide evenly.
-
equals
public boolean equals(java.lang.Object otherBag)
Description copied from interface:CharBag
Follows the same general contract asBag.equals(Object)
.
-
hashCode
public int hashCode()
Description copied from interface:CharBag
Follows the same general contract asBag.hashCode()
.
-
appendString
public void appendString(java.lang.Appendable appendable, java.lang.String start, java.lang.String separator, java.lang.String end)
Description copied from interface:PrimitiveIterable
Prints a string representation of this collection onto the givenAppendable
. Prints the string returned byPrimitiveIterable.makeString(String, String, String)
.- Specified by:
appendString
in interfacePrimitiveIterable
-
count
public int count(CharPredicate predicate)
Description copied from interface:CharIterable
Returns a count of the number of elements in the CharIterable that return true for the specified predicate.- Specified by:
count
in interfaceCharIterable
-
anySatisfy
public boolean anySatisfy(CharPredicate predicate)
Description copied from interface:CharIterable
Returns true if any of the elements in the CharIterable return true for the specified predicate, otherwise returns false.- Specified by:
anySatisfy
in interfaceCharIterable
-
allSatisfy
public boolean allSatisfy(CharPredicate predicate)
Description copied from interface:CharIterable
Returns true if all of the elements in the CharIterable return true for the specified predicate, otherwise returns false.- Specified by:
allSatisfy
in interfaceCharIterable
-
noneSatisfy
public boolean noneSatisfy(CharPredicate predicate)
Description copied from interface:CharIterable
Returns true if none of the elements in the CharIterable return true for the specified predicate, otherwise returns false.- Specified by:
noneSatisfy
in interfaceCharIterable
-
detectIfNone
public char detectIfNone(CharPredicate predicate, char ifNone)
- Specified by:
detectIfNone
in interfaceCharIterable
-
collect
public <V> MutableBag<V> collect(CharToObjectFunction<? extends V> function)
Description copied from interface:CharIterable
Returns a new collection with the results of applying the specified function on each element of the source collection. This method is also commonly called transform or map.- Specified by:
collect
in interfaceCharBag
- Specified by:
collect
in interfaceCharIterable
- Specified by:
collect
in interfaceMutableCharBag
- Specified by:
collect
in interfaceMutableCharCollection
-
max
public char max()
- Specified by:
max
in interfaceCharIterable
-
min
public char min()
- Specified by:
min
in interfaceCharIterable
-
sum
public long sum()
- Specified by:
sum
in interfaceCharIterable
-
toArray
public char[] toArray()
Description copied from interface:CharIterable
Converts the CharIterable to a primitive char array.- Specified by:
toArray
in interfaceCharIterable
-
toArray
public char[] toArray(char[] array)
Description copied from interface:CharIterable
Converts the CharIterable to a primitive char array. If the collection fits into the provided array it is used to store its elements and is returned from the method, otherwise a new array of the appropriate size is allocated and returned. If the iterable is empty, the target array is returned unchanged.- Specified by:
toArray
in interfaceCharIterable
-
asUnmodifiable
public MutableCharBag asUnmodifiable()
- Specified by:
asUnmodifiable
in interfaceMutableCharBag
- Specified by:
asUnmodifiable
in interfaceMutableCharCollection
-
asSynchronized
public MutableCharBag asSynchronized()
- Specified by:
asSynchronized
in interfaceMutableCharBag
- Specified by:
asSynchronized
in interfaceMutableCharCollection
-
toImmutable
public ImmutableCharBag toImmutable()
Description copied from interface:MutableCharBag
Returns an immutable copy of this bag.- Specified by:
toImmutable
in interfaceCharBag
- Specified by:
toImmutable
in interfaceMutableCharBag
- Specified by:
toImmutable
in interfaceMutableCharCollection
-
newEmpty
public CharHashBag newEmpty()
Creates a new empty CharHashBag.- Specified by:
newEmpty
in interfaceMutableCharBag
- Specified by:
newEmpty
in interfaceMutableCharCollection
- Since:
- 9.2.
-
charIterator
public MutableCharIterator charIterator()
Description copied from interface:CharIterable
Returns a primitive iterator that can be used to iterate over the CharIterable in an imperative style.- Specified by:
charIterator
in interfaceCharIterable
- Specified by:
charIterator
in interfaceMutableCharCollection
-
writeExternal
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException
- Specified by:
writeExternal
in interfacejava.io.Externalizable
- Throws:
java.io.IOException
-
readExternal
public void readExternal(java.io.ObjectInput in) throws java.io.IOException
- Specified by:
readExternal
in interfacejava.io.Externalizable
- Throws:
java.io.IOException
-
-