diff options
| author | bculkin2442 <bjculkin@mix.wvu.edu> | 2017-02-17 02:19:59 -0500 |
|---|---|---|
| committer | bculkin2442 <bjculkin@mix.wvu.edu> | 2017-02-17 02:19:59 -0500 |
| commit | 699c2890ca50f9b33ee8e228e544105754b0daca (patch) | |
| tree | 22a2463d973814d40e25a3d6a0efb35f662ca6e9 /BJC-Utils2/src/main/java/bjc/utils | |
| parent | f43f4f79e2b90a637b1eaef34cd8d10b69333db6 (diff) | |
IList is now iterable. No more useless toIterable()s :)
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils')
| -rw-r--r-- | BJC-Utils2/src/main/java/bjc/utils/esodata/TapeChanger.java | 8 | ||||
| -rw-r--r-- | BJC-Utils2/src/main/java/bjc/utils/funcdata/IList.java | 18 |
2 files changed, 16 insertions, 10 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/esodata/TapeChanger.java b/BJC-Utils2/src/main/java/bjc/utils/esodata/TapeChanger.java index 1a07cbb..1d132fa 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/esodata/TapeChanger.java +++ b/BJC-Utils2/src/main/java/bjc/utils/esodata/TapeChanger.java @@ -33,7 +33,7 @@ public class TapeChanger<T> implements Tape<T> { tapes.insertBefore(current); for(Tape<T> tp : others) { - tapes.insertAfter(others); + tapes.insertAfter(tp); tapes.right(); } @@ -47,7 +47,7 @@ public class TapeChanger<T> implements Tape<T> { * @return The item the tape is on. */ public T item() { - if(currentTape == null) return false; + if(currentTape == null) return null; return currentTape.item(); } @@ -176,7 +176,7 @@ public class TapeChanger<T> implements Tape<T> { * @return Whether the cursor was moved right. */ public boolean right(int amt) { - if(currentTape == null) return; + if(currentTape == null) return false; return currentTape.right(amt); } @@ -198,7 +198,7 @@ public class TapeChanger<T> implements Tape<T> { @Override public boolean isDoubleSided() { - if(currentTape == null) return; + if(currentTape == null) return false; return currentTape.isDoubleSided(); } diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcdata/IList.java b/BJC-Utils2/src/main/java/bjc/utils/funcdata/IList.java index f920fce..f6b207a 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/IList.java +++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/IList.java @@ -1,6 +1,7 @@ package bjc.utils.funcdata; import java.util.Comparator; +import java.util.Iterator; import java.util.function.BiConsumer; import java.util.function.BiFunction; import java.util.function.Consumer; @@ -18,7 +19,7 @@ import bjc.utils.data.IPair; * @param <ContainedType> * The type in this list */ -public interface IList<ContainedType> { +public interface IList<ContainedType> extends Iterable<ContainedType> { /** * Add an item to this list * @@ -72,7 +73,7 @@ public interface IList<ContainedType> { * The collector to use for reduction * @return The reduced list */ - public default <StateType, ReducedType> ReducedType collect( + default <StateType, ReducedType> ReducedType collect( Collector<ContainedType, StateType, ReducedType> collector) { BiConsumer<StateType, ContainedType> accumulator = collector.accumulator(); @@ -147,7 +148,7 @@ public interface IList<ContainedType> { * @param action * The action to apply to each member of the list. */ - void forEach(Consumer<ContainedType> action); + void forEach(Consumer<? super ContainedType> action); /** * Apply a given function to each element in the list and its index. @@ -334,7 +335,7 @@ public interface IList<ContainedType> { * * @return The list without the first element */ - public IList<ContainedType> tail(); + IList<ContainedType> tail(); /** * Convert this list into an array @@ -343,12 +344,17 @@ public interface IList<ContainedType> { * The type of array to return * @return The list, as an array */ - public ContainedType[] toArray(ContainedType[] type); + ContainedType[] toArray(ContainedType[] type); /** * Convert the list into a Iterable * * @return An iterable view onto the list */ - public Iterable<ContainedType> toIterable(); + Iterable<ContainedType> toIterable(); + + @Override + default Iterator<ContainedType> iterator() { + return toIterable().iterator(); + } } |
