public interface Container
Methods ensureCapacity(long)
and shrink()
make sense only for array-based
containers.
Method \ Mutability | Mutable | Updatable | Immutable |
size() | ✓ | ✓ | ✓ |
sizeAsLong() | ✓ | ✓ | ✓ |
isEmpty() | ✓ | ✓ | ✓ |
ensureCapacity(long) | ✓ | ✓ | - |
shrink() | ✓ | ✓ | - |
clear() | ✓ | ✓ | - |
Modifier and Type | Method and Description |
---|---|
void |
clear()
Removes all of the elements (entries) from this container.
|
boolean |
ensureCapacity(long minSize)
Prepares the container for insertion of
minSize - sizeAsLong() new elements
without excessive capacity increases. |
boolean |
isEmpty()
Returns
true if this container contains no elements. |
boolean |
shrink()
Decreases this container's capacity, if there is memory overuse.
|
int |
size()
Returns the number of elements (entries) in this container.
|
long |
sizeAsLong()
Returns the number of elements (entries) in this container.
|
int size()
Integer.MAX_VALUE
elements (entries), returns Integer.MAX_VALUE
.sizeAsLong()
long sizeAsLong()
boolean ensureCapacity(long minSize)
minSize -
sizeAsLong()
new elements
without excessive capacity increases.
If the container is an array-based data structure, increases the capacity of this
container, if necessary, to ensure that it can hold at least minSize
elements.
Returns true
, if the capacity has been increased, false
if it isn't necessary.
If the container is a linked data structure, does nothing and returns false
.
minSize
- the desired minimum size, which the container is expected to reach soontrue
if the capacity has been increased, false
if it isn't necessary
or impossibleUnsupportedOperationException
- if the container doesn't support insertionsboolean shrink()
If the container is array-based data structure, and the memory is overused due to
preventive expansion on elements insertion, decreases the capacity and returns true
,
returns false
if the capacity is already minimum needed to hold the current
number of elements.
If the container is linked data structure, does nothing and returns false
.
true
if the container has been actually shrunk, false
otherwiseUnsupportedOperationException
- if the container is immutablevoid clear()
UnsupportedOperationException
- if the container is immutableboolean isEmpty()
true
if this container contains no elements.true
if this container contains no elements