- java.lang.Object
-
- org.logicng.collections.LNGVector<T>
-
-
Constructor Summary
Constructors Constructor Description LNGVector()Creates a vector with an initial capacity of 5 elements.LNGVector(int size)Creates a vector with a given capacity.LNGVector(int size, T pad)Creates a vector with a given capacity and a given initial element.LNGVector(Collection<T> elems)Creates a vector with the given elementsLNGVector(T... elems)Creates a vector with the given elements.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Tback()Returns the last element of the vector and leaves it on the vector.voidclear()Clears the vector.booleanempty()Returns whether the vector is empty or not.Tget(int position)Returns the element at a given position in the vector.voidgrowTo(int size)Grows the vector to a new size and initializes the new elements withnull.voidgrowTo(int size, T pad)Grows the vector to a new size and initializes the new elements with a given value.Iterator<T>iterator()voidmanualSort(Comparator<T> comparator)Sorts this vector with a given comparator (with manual implemented merge sort).voidpop()Removes the last element of the vector.voidpush(T element)Pushes an element at the end of the vector.voidrelease()Clears the vector and sets all elements tonull.booleanremove(T element)Removes the first occurrence of a given element from the vector (the element is compared byequals).voidremoveElements(int num)Removes a given number of elements from the vector.voidreplaceInplace(LNGVector<? extends T> other)Replaces the contents of this vector with the contents of another vector in-place.voidset(int position, T element)Sets an element at a given position in the vector.voidshrinkTo(int newSize)Shrinks the vector to a given size if the new size is less than the current size.intsize()Returns the size of the vector.voidsort(Comparator<T> comparator)Sorts this vector with a given comparator (with JDK sorting).voidsortReverse(Comparator<T> comparator)Sorts this vector in reverse order.StringtoString()voidunsafePush(T element)Pushes an element and assumes that there is enough space on the vector.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Constructor Detail
-
LNGVector
public LNGVector()
Creates a vector with an initial capacity of 5 elements.
-
LNGVector
public LNGVector(int size)
Creates a vector with a given capacity.- Parameters:
size- the capacity of the vector.
-
LNGVector
public LNGVector(int size, T pad)Creates a vector with a given capacity and a given initial element.- Parameters:
size- the capacity of the vectorpad- the initial element
-
LNGVector
@SafeVarargs public LNGVector(T... elems)
Creates a vector with the given elements.- Parameters:
elems- the elements
-
LNGVector
public LNGVector(Collection<T> elems)
Creates a vector with the given elements- Parameters:
elems- the elements
-
-
Method Detail
-
empty
public boolean empty()
Returns whether the vector is empty or not.- Returns:
trueif the vector is empty,falseotherwise
-
size
public int size()
Returns the size of the vector.- Returns:
- the size of the vector
-
back
public T back()
Returns the last element of the vector and leaves it on the vector.- Returns:
- the last element of the vector
-
push
public void push(T element)
Pushes an element at the end of the vector.- Parameters:
element- the element
-
unsafePush
public void unsafePush(T element)
Pushes an element and assumes that there is enough space on the vector.- Parameters:
element- the element to push- Throws:
ArrayIndexOutOfBoundsException- if there was not enough space on the vector
-
get
public T get(int position)
Returns the element at a given position in the vector.- Parameters:
position- the position- Returns:
- the element at the position
- Throws:
ArrayIndexOutOfBoundsException- if the position is not found in the vector
-
set
public void set(int position, T element)Sets an element at a given position in the vector.- Parameters:
position- the positionelement- the element- Throws:
ArrayIndexOutOfBoundsException- if the position is not found in the vector
-
pop
public void pop()
Removes the last element of the vector.
-
shrinkTo
public void shrinkTo(int newSize)
Shrinks the vector to a given size if the new size is less than the current size. Otherwise, the size remains the same.- Parameters:
newSize- the new size
-
growTo
public void growTo(int size, T pad)Grows the vector to a new size and initializes the new elements with a given value.- Parameters:
size- the new sizepad- the value for new elements
-
growTo
public void growTo(int size)
Grows the vector to a new size and initializes the new elements withnull.- Parameters:
size- the new size
-
removeElements
public void removeElements(int num)
Removes a given number of elements from the vector.- Parameters:
num- the number of elements to remove.- Throws:
ArrayIndexOutOfBoundsException- if the number of elements to remove is larger than the size of the vector
-
remove
public boolean remove(T element)
Removes the first occurrence of a given element from the vector (the element is compared byequals).- Parameters:
element- the element to remove- Returns:
trueif the element was removed,falseif the element was not in the vector
-
replaceInplace
public void replaceInplace(LNGVector<? extends T> other)
Replaces the contents of this vector with the contents of another vector in-place.- Parameters:
other- the other vector- Throws:
IllegalArgumentException- if you try to replace a vector with itself
-
clear
public void clear()
Clears the vector. This method only sets the size to 0. The elements are not nulled out. Userelease()for this purpose.
-
release
public void release()
Clears the vector and sets all elements tonull.
-
sort
public void sort(Comparator<T> comparator)
Sorts this vector with a given comparator (with JDK sorting).- Parameters:
comparator- the comparator
-
manualSort
public void manualSort(Comparator<T> comparator)
Sorts this vector with a given comparator (with manual implemented merge sort). This method is required for sorting clauses based on activity, since not all requirements of the JDK sorting are met.- Parameters:
comparator- the comparator
-
sortReverse
public void sortReverse(Comparator<T> comparator)
Sorts this vector in reverse order.- Parameters:
comparator- the comparator
-
-