Added getFirst/getLast/removeFirst/removeLast to lists
This commit is contained in:
parent
ed9ce60af4
commit
2da4588430
|
@ -1,5 +1,8 @@
|
||||||
# Changelog of versions
|
# Changelog of versions
|
||||||
|
|
||||||
|
### Version 0.8.0
|
||||||
|
- Added: getFirst/getLast/removeFirst/removeLast to Lists
|
||||||
|
|
||||||
### Version 0.8.0
|
### Version 0.8.0
|
||||||
- Added: ISizeProvider interface (Optimization Helper)
|
- Added: ISizeProvider interface (Optimization Helper)
|
||||||
- Added: ISizeProvider into most Iterable implementations (Distinct/Filter/FlatMap/ArrayFlatMap don't support it, for obvious reasons)
|
- Added: ISizeProvider into most Iterable implementations (Distinct/Filter/FlatMap/ArrayFlatMap don't support it, for obvious reasons)
|
||||||
|
|
|
@ -69,7 +69,10 @@ public class ListModule extends BaseModule
|
||||||
protected void loadFunctions()
|
protected void loadFunctions()
|
||||||
{
|
{
|
||||||
addFunctionMapper("GET_KEY", "get");
|
addFunctionMapper("GET_KEY", "get");
|
||||||
addFunctionMapper("REMOVE_LAST", "removeLast");
|
addFunctionMapper("GET_FIRST_KEY", "getFirst");
|
||||||
|
addFunctionMapper("GET_LAST_KEY", "getLast");
|
||||||
|
addFunctionMapper("REMOVE_FIRST_KEY", "removeFirst");
|
||||||
|
addFunctionMapper("REMOVE_LAST_KEY", "removeLast");
|
||||||
addFunctionMapper("REMOVE_SWAP", "swapRemove");
|
addFunctionMapper("REMOVE_SWAP", "swapRemove");
|
||||||
addFunctionMappers("REPLACE", keyType.isObject() ? "replaceObjects" : "replace%ss");
|
addFunctionMappers("REPLACE", keyType.isObject() ? "replaceObjects" : "replace%ss");
|
||||||
addFunctionMappers("SORT", "sort%ss");
|
addFunctionMappers("SORT", "sort%ss");
|
||||||
|
|
|
@ -314,21 +314,43 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||||
#if DEQUEUE_FEATURE
|
#if DEQUEUE_FEATURE
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE first() {
|
public KEY_TYPE first() {
|
||||||
|
return GET_FIRST_KEY();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE last() {
|
||||||
|
return GET_LAST_KEY();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE GET_FIRST_KEY() {
|
||||||
if(first == null) throw new NoSuchElementException();
|
if(first == null) throw new NoSuchElementException();
|
||||||
return first.value;
|
return first.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE last() {
|
public KEY_TYPE GET_LAST_KEY() {
|
||||||
if(last == null) throw new NoSuchElementException();
|
if(last == null) throw new NoSuchElementException();
|
||||||
return last.value;
|
return last.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
@Override
|
||||||
|
public KEY_TYPE REMOVE_FIRST_KEY() {
|
||||||
|
if(first == null) throw new NoSuchElementException();
|
||||||
|
return unlinkFirst(first);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KEY_TYPE REMOVE_LAST_KEY() {
|
||||||
|
return pop();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE peek(int index) {
|
public KEY_TYPE peek(int index) {
|
||||||
return GET_KEY((size() - 1) - index);
|
return GET_KEY((size() - 1) - index);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE GET_KEY(int index) {
|
public KEY_TYPE GET_KEY(int index) {
|
||||||
checkRange(index);
|
checkRange(index);
|
||||||
|
@ -1146,8 +1168,7 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||||
Entry KEY_GENERIC_TYPE prev;
|
Entry KEY_GENERIC_TYPE prev;
|
||||||
Entry KEY_GENERIC_TYPE next;
|
Entry KEY_GENERIC_TYPE next;
|
||||||
|
|
||||||
public Entry(KEY_TYPE value, Entry KEY_GENERIC_TYPE prev, Entry KEY_GENERIC_TYPE next)
|
public Entry(KEY_TYPE value, Entry KEY_GENERIC_TYPE prev, Entry KEY_GENERIC_TYPE next) {
|
||||||
{
|
|
||||||
this.value = value;
|
this.value = value;
|
||||||
this.prev = prev;
|
this.prev = prev;
|
||||||
this.next = next;
|
this.next = next;
|
||||||
|
|
|
@ -98,6 +98,46 @@ public interface LIST KEY_GENERIC_TYPE extends COLLECTION KEY_GENERIC_TYPE, List
|
||||||
*/
|
*/
|
||||||
public boolean addAll(int index, LIST KEY_GENERIC_TYPE c);
|
public boolean addAll(int index, LIST KEY_GENERIC_TYPE c);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper method that returns the first element of a List.
|
||||||
|
* This function was introduced due to how annoying it is to get/remove the last element of a list.
|
||||||
|
* This simplifies this process a bit.
|
||||||
|
* @return first element of the list
|
||||||
|
*/
|
||||||
|
public default KEY_TYPE GET_FIRST_KEY() {
|
||||||
|
return GET_KEY(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper method that returns the last element of a List.
|
||||||
|
* This function was introduced due to how annoying it is to get/remove the last element of a list.
|
||||||
|
* This simplifies this process a bit.
|
||||||
|
* @return last element of the list
|
||||||
|
*/
|
||||||
|
public default KEY_TYPE GET_LAST_KEY() {
|
||||||
|
return GET_KEY(size() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper method that removes and returns the first element of a List.
|
||||||
|
* This function was introduced due to how annoying it is to get/remove the last element of a list.
|
||||||
|
* This simplifies this process a bit.
|
||||||
|
* @return first element of the list and removes it
|
||||||
|
*/
|
||||||
|
public default KEY_TYPE REMOVE_FIRST_KEY() {
|
||||||
|
return REMOVE(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper method that removes and returns the last element of a List.
|
||||||
|
* This function was introduced due to how annoying it is to get/remove the last element of a list.
|
||||||
|
* This simplifies this process a bit.
|
||||||
|
* @return last element of the list and removes it
|
||||||
|
*/
|
||||||
|
public default KEY_TYPE REMOVE_LAST_KEY() {
|
||||||
|
return REMOVE(size() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
#if !TYPE_OBJECT
|
#if !TYPE_OBJECT
|
||||||
/**
|
/**
|
||||||
* A Type-Specific get function to reduce (un)boxing
|
* A Type-Specific get function to reduce (un)boxing
|
||||||
|
|
Loading…
Reference in New Issue