diff --git a/Common/src/main/java/at/petrak/hexcasting/api/utils/TreeList.java b/Common/src/main/java/at/petrak/hexcasting/api/utils/TreeList.java index aed3b14424..074e0626dd 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/utils/TreeList.java +++ b/Common/src/main/java/at/petrak/hexcasting/api/utils/TreeList.java @@ -464,26 +464,48 @@ protected TreeList appendedAll0(Iterable suffix, int k) { } else return new TreeListBuilder().initFrom(this).addAll(suffix).result(); } + /** + * @param n the number of elements to keep + * @return a new TreeList containing only the first {@code n} elements of this TreeList + */ public final TreeList take(int n) { return this.slice(0, n); } + /** + * @param n the number of elements to discard + * @return a new TreeList containing all but the first {@code n} elements of this TreeList + */ public final TreeList drop(int n) { return this.slice(n, this.length()); } + /** + * @param n the number of elements to keep + * @return a new TreeList containing only the last {@code n} elements of this TreeList + */ public final TreeList takeRight(int n) { return this.slice(this.length() - Math.max(n, 0), this.length()); } + /** + * @param n the number of elements to discard + * @return a new TreeList containing all but the last {@code n} elements of this TreeList + */ public final TreeList dropRight(int n) { return this.slice(0, this.length() - Math.max(n, 0)); } + /** + * @return a new TreeList containing all the elements from this TreeList except for the first one + */ public TreeList tail() { return this.slice(1, this.length()); } + /** + * @return a new TreeList containing all the elements from this TreeList except for the last one + */ public TreeList init() { return this.slice(0, this.length() - 1); } @@ -498,11 +520,17 @@ public TreeList init() { /** Length of all slices up to and including index */ abstract int treeListSlicePrefixLength(int idx); + /** + * @return the first element of this TreeList + */ public final A head() { if(this.prefix1.length == 0) throw new NoSuchElementException("empty.head"); else return (A) this.prefix1[0]; } + /** + * @return the last element of this TreeList + */ public A last() { return (A) this.prefix1[this.prefix1.length - 1]; }