public class ShortBag extends Object
Modifier and Type | Field and Description |
---|---|
protected int |
size
The number of values stored by this bag.
|
Constructor and Description |
---|
ShortBag()
Constructs an empty Bag with an initial capacity of 64.
|
ShortBag(int capacity)
Constructs an empty Bag with the specified initial capacity.
|
Modifier and Type | Method and Description |
---|---|
void |
add(short value)
Adds the specified element to the end of this bag.
|
void |
addAll(ShortBag other)
Adds the specified elements to the end of this bag.
|
void |
clear()
Removes all of the elements from this bag.
|
boolean |
contains(short value)
Check if bag contains this element.
|
void |
ensureCapacity(int index)
Check if an item, if added at the given item will fit into the bag.
|
boolean |
equals(Object o) |
short |
get(int index)
Returns the element at the specified position in Bag.
|
int |
getCapacity()
Returns the number of elements the bag can hold without growing.
|
short[] |
getData()
Returns this bag's underlying array.
|
int |
hashCode() |
int |
indexOf(short value)
Find index of element.
|
boolean |
isEmpty()
Returns true if this bag contains no elements.
|
int |
remove(int index)
Removes the element at the specified position in this Bag.
|
boolean |
removeValue(short value)
Removes the first occurrence of the value from this IntBag, if
it is present.
|
void |
set(int index,
short value)
Set element at specified index in the bag.
|
void |
setSize(int size)
Set the size.
|
int |
size()
Returns the number of elements in this bag.
|
String |
toString() |
void |
unsafeSet(int index,
short value) |
public ShortBag()
public ShortBag(int capacity)
capacity
- the initial capacity of Bagpublic boolean removeValue(short value) throws ArrayIndexOutOfBoundsException
value
- the value to be removedArrayIndexOutOfBoundsException
public int remove(int index) throws ArrayIndexOutOfBoundsException
It does this by overwriting it was last element then removing last element
index
- the index of element to be removedArrayIndexOutOfBoundsException
public int indexOf(short value)
value
- element to check-1
if there is no such index.public boolean contains(short value)
value
- element to checktrue
if the bag contains this elementpublic short get(int index) throws ArrayIndexOutOfBoundsException
index
- index of the element to returnArrayIndexOutOfBoundsException
public int size()
public int getCapacity()
public boolean isEmpty()
true
if this bag contains no elementspublic void add(short value)
If required, it also increases the capacity of the bag.
value
- element to be added to this listpublic void addAll(ShortBag other)
If required, it also increases the capacity of the bag.
other
- elements to be added to this listpublic void unsafeSet(int index, short value)
public void set(int index, short value)
index
- position of elementvalue
- the elementpublic void ensureCapacity(int index)
If not, the bag capacity will be increased to hold an item at the index.
index
- index to checkpublic void clear()
The bag will be empty after this call returns.
public short[] getData()
Use with care.
size()
public void setSize(int size)
This will not resize the bag, nor will it clean up contents beyond the given size. Use with caution.
size
- the size to setCopyright © 2019. All rights reserved.