Package com.github.tommyettinger.ds
Class BooleanBag
java.lang.Object
com.github.tommyettinger.ds.BooleanList
com.github.tommyettinger.ds.BooleanBag
- All Implemented Interfaces:
Arrangeable,Ordered.OfBoolean,PrimitiveCollection<Boolean>,PrimitiveCollection.OfBoolean
An unordered List of boolean items. This allows efficient iteration via a reused iterator or via index.
This class avoids a memory copy when removing elements (the last element is moved to the removed element's position).
Items are permitted to change position in the ordering when any item is removed or added.
Although this won't keep an order during modifications, you can
BooleanList.sort() the bag to ensure,
if no modifications are made later, that the iteration will happen in sorted order.-
Nested Class Summary
Nested classes/interfaces inherited from class com.github.tommyettinger.ds.BooleanList
BooleanList.BooleanListIteratorNested classes/interfaces inherited from interface com.github.tommyettinger.ds.Arrangeable
Arrangeable.ArrangeableList<T>Nested classes/interfaces inherited from interface com.github.tommyettinger.ds.PrimitiveCollection
PrimitiveCollection.OfBoolean, PrimitiveCollection.OfByte, PrimitiveCollection.OfChar, PrimitiveCollection.OfDouble, PrimitiveCollection.OfFloat, PrimitiveCollection.OfInt, PrimitiveCollection.OfLong, PrimitiveCollection.OfShort -
Field Summary
Fields inherited from class com.github.tommyettinger.ds.BooleanList
items, iterator1, iterator2, size -
Constructor Summary
ConstructorsConstructorDescriptionCreates an ordered bag with a capacity of 10.BooleanBag(boolean[] array) Creates a new bag containing the elements in the specified array.BooleanBag(boolean[] array, int startIndex, int count) Creates a new bag containing the elements in the specified array.BooleanBag(int capacity) Creates an ordered bag with the specified capacity.BooleanBag(BooleanList list) Creates a new bag containing the elements in the specific list or bag.BooleanBag(Ordered.OfBoolean other) Copies the given Ordered.OfBoolean into a new bag.BooleanBag(Ordered.OfBoolean other, int offset, int count) Creates a new bag by copyingcountitems from the given Ordered, starting atoffsetin that Ordered, into this.Creates a new bag containing the items in the specified PrimitiveCollection.OfBoolean.BooleanBag(BooleanIterator coll) Creates a new instance containing the items in the specified iterator. -
Method Summary
Modifier and TypeMethodDescriptioninthashCode()voidinsert(int index, boolean element) This always addselementto the end of this bag's ordering.booleanReturns true if this implementation retains order, which it does not.static BooleanBagCallsparse(String, String, boolean)with brackets set to false.static BooleanBagCreates a new collection and fills it by callingPrimitiveCollection.OfBoolean.addLegible(String, String, int, int)on either all ofstr(ifbracketsis false) orstrwithout its first and last chars (ifbracketsis true).static BooleanBagCreates a new collection and fills it by callingPrimitiveCollection.OfBoolean.addLegible(String, String, int, int)with the given four parameters as-is.booleanremoveAt(int index) Removes and returns the item at the specified index.voidremoveRange(int start, int end) Removes the items between the specified start index, inclusive, and end index, exclusive.static BooleanBagwith()Constructs an empty bag.static BooleanBagwith(boolean item) Creates a new BooleanBag that holds only the given item, but can be resized.static BooleanBagwith(boolean... varargs) Creates a new BooleanBag that holds only the given items, but can be resized.static BooleanBagwith(boolean item0, boolean item1) Creates a new BooleanBag that holds only the given items, but can be resized.static BooleanBagwith(boolean item0, boolean item1, boolean item2) Creates a new BooleanBag that holds only the given items, but can be resized.static BooleanBagwith(boolean item0, boolean item1, boolean item2, boolean item3) Creates a new BooleanBag that holds only the given items, but can be resized.static BooleanBagwith(boolean item0, boolean item1, boolean item2, boolean item3, boolean item4) Creates a new BooleanBag that holds only the given items, but can be resized.static BooleanBagwith(boolean item0, boolean item1, boolean item2, boolean item3, boolean item4, boolean item5) Creates a new BooleanBag that holds only the given items, but can be resized.static BooleanBagwith(boolean item0, boolean item1, boolean item2, boolean item3, boolean item4, boolean item5, boolean item6) Creates a new BooleanBag that holds only the given items, but can be resized.static BooleanBagwith(boolean item0, boolean item1, boolean item2, boolean item3, boolean item4, boolean item5, boolean item6, boolean item7) Creates a new BooleanBag that holds only the given items, but can be resized.Methods inherited from class com.github.tommyettinger.ds.BooleanList
add, add, add, add, addAll, addAll, addAll, addAll, addAll, addAll, and, clear, contains, containsAll, duplicateRange, ensureCapacity, equals, first, get, indexOf, isEmpty, iterator, lastIndexOf, not, notEmpty, or, order, peek, pop, random, remove, removeAll, removeEach, replaceAll, replaceAll, replaceFirst, resize, retainAll, reverse, set, setSize, shrink, shuffle, size, sort, sort, sort, sort, swap, toArray, toArray, toString, trimToSize, truncate, xorMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface com.github.tommyettinger.ds.Arrangeable
rearrange, shuffleMethods inherited from interface com.github.tommyettinger.ds.Ordered.OfBoolean
getOrderType, random, selectRanked, selectRankedIndexMethods inherited from interface com.github.tommyettinger.ds.PrimitiveCollection.OfBoolean
addAll, addAll, addDense, addDense, addLegible, addLegible, addVarargs, appendTo, appendTo, containsAll, containsAll, containsAll, containsAll, containsAny, containsAny, containsAny, containsAny, denseAppendTo, forEach, removeAll, removeAll, removeAll, removeEach, removeEach, removeEach, removeIf, retainAll, retainAll, toDenseString, toDenseString, toString, toString, toString
-
Constructor Details
-
BooleanBag
public BooleanBag()Creates an ordered bag with a capacity of 10. -
BooleanBag
public BooleanBag(int capacity) Creates an ordered bag with the specified capacity.- Parameters:
capacity-
-
BooleanBag
Creates a new bag containing the elements in the specific list or bag. The capacity is set to the number of elements, so any subsequent elements added will cause the backing array to be grown.- Parameters:
list- another BooleanList or BooleanBag
-
BooleanBag
public BooleanBag(boolean[] array) Creates a new bag containing the elements in the specified array. The capacity is set to the number of elements, so any subsequent elements added will cause the backing array to be grown.- Parameters:
array- a non-null boolean array to add to this bag
-
BooleanBag
public BooleanBag(boolean[] array, int startIndex, int count) Creates a new bag containing the elements in the specified array. The capacity is set to the number of elements, so any subsequent elements added will cause the backing array to be grown.- Parameters:
array- a non-null boolean array to add to this bagstartIndex- the first index inarrayto usecount- how many items to use fromarray
-
BooleanBag
Creates a new bag containing the items in the specified PrimitiveCollection.OfBoolean.- Parameters:
coll- a primitive collection that will have its contents added to this
-
BooleanBag
Creates a new instance containing the items in the specified iterator.- Parameters:
coll- an iterator that will have its remaining contents added to this
-
BooleanBag
Copies the given Ordered.OfBoolean into a new bag.- Parameters:
other- another Ordered.OfBoolean
-
BooleanBag
Creates a new bag by copyingcountitems from the given Ordered, starting atoffsetin that Ordered, into this.- Parameters:
other- another Ordered.OfBooleanoffset- the first index in other's ordering to draw an item fromcount- how many items to copy from other
-
-
Method Details
-
keepsOrder
public boolean keepsOrder()Returns true if this implementation retains order, which it does not.- Overrides:
keepsOrderin classBooleanList- Returns:
- false
-
insert
public void insert(int index, boolean element) This always addselementto the end of this bag's ordering.- Overrides:
insertin classBooleanList- Parameters:
index- ignoredelement- element to be inserted
-
removeAt
public boolean removeAt(int index) Removes and returns the item at the specified index. Note that this is equivalent toList.remove(int), but can't have that name because we also haveBooleanList.remove(boolean)that removes a value, rather than an index.- Overrides:
removeAtin classBooleanList- Parameters:
index- the index of the item to remove and return- Returns:
- the removed item
-
removeRange
public void removeRange(int start, int end) Removes the items between the specified start index, inclusive, and end index, exclusive. Note that this takes different arguments than some other range-related methods; this needs a start index and an end index, rather than a count of items. This matches the behavior in the JDK collections.- Specified by:
removeRangein interfaceOrdered.OfBoolean- Overrides:
removeRangein classBooleanList- Parameters:
start- the first index to remove, inclusiveend- the last index (after what should be removed), exclusive
-
hashCode
public int hashCode()- Specified by:
hashCodein interfacePrimitiveCollection<Boolean>- Overrides:
hashCodein classBooleanList
-
with
Constructs an empty bag. This is usually less useful than just using the constructor, but can be handy in some code-generation scenarios when you don't know how many arguments you will have.- Returns:
- a new bag containing nothing
-
with
Creates a new BooleanBag that holds only the given item, but can be resized.- Parameters:
item- a boolean item- Returns:
- a new BooleanBag that holds the given item
-
with
Creates a new BooleanBag that holds only the given items, but can be resized.- Parameters:
item0- a boolean itemitem1- a boolean item- Returns:
- a new BooleanBag that holds the given items
-
with
Creates a new BooleanBag that holds only the given items, but can be resized.- Parameters:
item0- a boolean itemitem1- a boolean itemitem2- a boolean item- Returns:
- a new BooleanBag that holds the given items
-
with
Creates a new BooleanBag that holds only the given items, but can be resized.- Parameters:
item0- a boolean itemitem1- a boolean itemitem2- a boolean itemitem3- a boolean item- Returns:
- a new BooleanBag that holds the given items
-
with
public static BooleanBag with(boolean item0, boolean item1, boolean item2, boolean item3, boolean item4) Creates a new BooleanBag that holds only the given items, but can be resized.- Parameters:
item0- a boolean itemitem1- a boolean itemitem2- a boolean itemitem3- a boolean itemitem4- a boolean item- Returns:
- a new BooleanBag that holds the given items
-
with
public static BooleanBag with(boolean item0, boolean item1, boolean item2, boolean item3, boolean item4, boolean item5) Creates a new BooleanBag that holds only the given items, but can be resized.- Parameters:
item0- a boolean itemitem1- a boolean itemitem2- a boolean itemitem3- a boolean itemitem4- a boolean itemitem5- a boolean item- Returns:
- a new BooleanBag that holds the given items
-
with
public static BooleanBag with(boolean item0, boolean item1, boolean item2, boolean item3, boolean item4, boolean item5, boolean item6) Creates a new BooleanBag that holds only the given items, but can be resized.- Parameters:
item0- a boolean itemitem1- a boolean itemitem2- a boolean itemitem3- a boolean itemitem4- a boolean itemitem5- a boolean itemitem6- a boolean item- Returns:
- a new BooleanBag that holds the given items
-
with
public static BooleanBag with(boolean item0, boolean item1, boolean item2, boolean item3, boolean item4, boolean item5, boolean item6, boolean item7) Creates a new BooleanBag that holds only the given items, but can be resized.- Parameters:
item0- a boolean itemitem1- a boolean itemitem2- a boolean itemitem3- a boolean itemitem4- a boolean itemitem5- a boolean itemitem6- a boolean item- Returns:
- a new BooleanBag that holds the given items
-
with
Creates a new BooleanBag that holds only the given items, but can be resized. This overload will only be used when an array is supplied and the type of the items requested is the component type of the array, or if varargs are used and there are 9 or more arguments.- Parameters:
varargs- a boolean varargs or boolean array; remember that varargs allocate- Returns:
- a new BooleanBag that holds the given items
-
parse
Callsparse(String, String, boolean)with brackets set to false.- Parameters:
str- a String that will be parsed in fulldelimiter- the delimiter between items in str- Returns:
- a new collection parsed from str
-
parse
Creates a new collection and fills it by callingPrimitiveCollection.OfBoolean.addLegible(String, String, int, int)on either all ofstr(ifbracketsis false) orstrwithout its first and last chars (ifbracketsis true). Each item is expected to be separated bydelimiter.- Parameters:
str- a String that will be parsed in full (depending on brackets)delimiter- the delimiter between items in strbrackets- if true, the first and last chars in str will be ignored- Returns:
- a new collection parsed from str
-
parse
Creates a new collection and fills it by callingPrimitiveCollection.OfBoolean.addLegible(String, String, int, int)with the given four parameters as-is.- Parameters:
str- a String that will have the given section parseddelimiter- the delimiter between items in stroffset- the first position to parse in str, inclusivelength- how many chars to parse, starting from offset- Returns:
- a new collection parsed from str
-