TYPE
- Type of stored elementspublic final class SortedArray<TYPE>
extends java.lang.Object
implements java.lang.Iterable<TYPE>
Comparable
elements) or as indicates by a Comparator
.Modifier and Type | Class and Description |
---|---|
(package private) static class |
SortedArray.ComparatorNatural<ELEMENT>
Comparator for "natural order" of
Comparable |
Modifier and Type | Field and Description |
---|---|
private TYPE[] |
array
Stored elements
|
private java.util.Comparator |
comparator
Comparator to use
|
private int |
size
Actual array size
|
private java.lang.Class<TYPE> |
typeClass
Type of element stored
|
private boolean |
unique
Indicates if we are in unique mode
|
Constructor and Description |
---|
SortedArray(java.lang.Class<TYPE> typeClass)
Create a new instance of SortedArray in not unique mode.
|
SortedArray(java.lang.Class<TYPE> typeClass,
boolean unique)
Create a new instance of SortedArray.
|
SortedArray(java.lang.Class<TYPE> typeClass,
java.util.Comparator<TYPE> comparator)
Create a new instance of SortedArray in not unique mode.
|
SortedArray(java.lang.Class<TYPE> typeClass,
java.util.Comparator<TYPE> comparator,
boolean unique)
Create a new instance of SortedArray.
|
SortedArray(java.lang.Class<TYPE> typeClass,
java.util.Comparator<TYPE> comparator,
int initialSize,
boolean unique)
Create a new instance of SortedArray.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(TYPE element)
Add an element
|
private void |
checkIndex(int index)
Check if an index is out of the array
|
void |
clear()
Clear the array.
|
boolean |
contains(TYPE element)
Indicates if an element is inside the array
|
private void |
expand(int more)
Expand the array (if need) to have more space
|
protected void |
finalize()
Called when garbage collector want free is memory
Parent documentation: |
TYPE |
getElement(int index)
Give an element of the array
|
int |
getSize()
Actual array size
|
int |
indexOf(TYPE element)
Get an element index or -1 if not present
|
private int |
insertIn(TYPE element)
Compute the index where insert an element.
|
Pair<java.lang.Integer,java.lang.Integer> |
intervalOf(TYPE element)
Compute interval index where should be insert a given element.
|
boolean |
isEmpty()
Indicates if array is empty
|
boolean |
isUnique()
Indicates if array is in unique mode
|
java.util.Iterator<TYPE> |
iterator()
Compute iterator over the list
Parent documentation: |
TYPE |
obtainElement(java.lang.Object object)
Search an element similar to the object.
|
int |
obtainIndex(java.lang.Object object)
Search index of similar element.
|
TYPE |
remove(int index)
Remove an element
|
TYPE |
remove(TYPE element)
Remove an element.
|
TYPE[] |
toArray()
Transform the array to a an array with size the same as this array, with same element in same order
|
java.lang.String |
toString()
String representation
Parent documentation: |
private TYPE[] array
private java.util.Comparator comparator
private int size
private java.lang.Class<TYPE> typeClass
private boolean unique
public SortedArray(java.lang.Class<TYPE> typeClass)
Comparable
to use the "natural order"typeClass
- Type of element to storepublic SortedArray(java.lang.Class<TYPE> typeClass, boolean unique)
Comparable
to use the "natural order"typeClass
- Type of element to storeunique
- Indicates if use unique mode or notpublic SortedArray(java.lang.Class<TYPE> typeClass, java.util.Comparator<TYPE> comparator)
null
, the type of class must be a Comparable
to use the "natural order"typeClass
- Type of elementscomparator
- Comparator to usepublic SortedArray(java.lang.Class<TYPE> typeClass, java.util.Comparator<TYPE> comparator, boolean unique)
null
, the type of class must be a Comparable
to use the "natural order"typeClass
- Type of elementcomparator
- Comparator to useunique
- Indicates if the unique mode is activatedpublic SortedArray(java.lang.Class<TYPE> typeClass, java.util.Comparator<TYPE> comparator, int initialSize, boolean unique)
null
, the type of class must be a Comparable
to use the "natural order"typeClass
- Type of elementcomparator
- Comparator to useinitialSize
- Initial array capacityunique
- Indicates if the unique mode is enableprivate void checkIndex(int index)
index
- Index to setjava.lang.IllegalArgumentException
- If the index is out of boundsprivate void expand(int more)
more
- Number space more needprivate int insertIn(TYPE element)
index = insertIn(element); if(index<0) index = -index-1;
element
- Element searchprotected void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable
- On issueObject.finalize()
public boolean add(TYPE element)
element
- element to addtrue
if element added. false
if unique mode and already present, so not addedjava.lang.NullPointerException
- if the element is null
public void clear()
public boolean contains(TYPE element)
element
- Tested elementtrue
if an element is inside the arrayjava.lang.NullPointerException
- if the element is null
public TYPE getElement(int index)
index
- Element indexjava.lang.IllegalArgumentException
- if the index is out of boundspublic int getSize()
public int indexOf(TYPE element)
element
- Element testedjava.lang.NullPointerException
- if element is null
public Pair<java.lang.Integer,java.lang.Integer> intervalOf(TYPE element)
element
- Element searchpublic boolean isEmpty()
true
if array is emptypublic boolean isUnique()
true
if array is in unique modepublic java.util.Iterator<TYPE> iterator()
iterator
in interface java.lang.Iterable<TYPE>
Iterable.iterator()
public TYPE obtainElement(java.lang.Object object)
object
- Object to be similarnull
if no element are similarpublic int obtainIndex(java.lang.Object object)
object
- Object to be similarpublic TYPE remove(int index)
index
- Element indexjava.lang.IllegalArgumentException
- if index is out of boundspublic TYPE remove(TYPE element)
element
- Element to removenull
if element not foundjava.lang.NullPointerException
- if element is null
public TYPE[] toArray()
public java.lang.String toString()
toString
in class java.lang.Object
Object.toString()