Skip to content

Commit

Permalink
Updated to 0.9.0 src
Browse files Browse the repository at this point in the history
  • Loading branch information
Speiger committed Jun 29, 2023
1 parent 49ce7fb commit 2a2d9e8
Show file tree
Hide file tree
Showing 825 changed files with 23,895 additions and 25,822 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import speiger.src.collections.booleans.collections.BooleanCollection;
import speiger.src.collections.booleans.collections.BooleanIterator;
import speiger.src.collections.booleans.collections.BooleanSplititerator;
import speiger.src.collections.ints.lists.IntList;
import speiger.src.collections.booleans.utils.BooleanSplititerators;
import speiger.src.collections.utils.SanityChecks;

Expand Down Expand Up @@ -205,13 +206,23 @@ public BooleanIterator iterator() {
public BooleanListIterator listIterator() {
return listIterator(0);
}

@Override
public BooleanListIterator listIterator(int index) {
if(index < 0 || index > size()) throw new IndexOutOfBoundsException();
return new BooleanListIter(index);
}

@Override
public BooleanListIterator indexedIterator(int...indecies) {
return new IndexedIterator(indecies);
}

@Override
public BooleanListIterator indexedIterator(IntList indecies) {
return new ListIndexedIterator(indecies);
}

@Override
public void size(int size) {
while(size > size()) add(false);
Expand Down Expand Up @@ -566,7 +577,153 @@ public int back(int amount) {
}
}
}

private class ListIndexedIterator implements BooleanListIterator {
IntList indecies;
int index;
int lastReturned = -1;

ListIndexedIterator(IntList indecies) {
this.indecies = indecies;
}

@Override
public boolean hasNext() {
return index < indecies.size();
}

@Override
public boolean nextBoolean() {
if(!hasNext()) throw new NoSuchElementException();
int i = index++;
return getBoolean((lastReturned = indecies.getInt(i)));
}

@Override
public boolean hasPrevious() {
return index > 0;
}

@Override
public boolean previousBoolean() {
if(!hasPrevious()) throw new NoSuchElementException();
index--;
return getBoolean((lastReturned = indecies.getInt(index)));
}

@Override
public int nextIndex() {
return index;
}

@Override
public int previousIndex() {
return index-1;
}

@Override
public void remove() { throw new UnsupportedOperationException(); }
@Override
public void add(boolean e) { throw new UnsupportedOperationException(); }

@Override
public void set(boolean e) {
if(lastReturned == -1) throw new IllegalStateException();
AbstractBooleanList.this.set(lastReturned, e);
}

@Override
public int skip(int amount) {
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
int steps = Math.min(amount, indecies.size() - index);
index += steps;
if(steps > 0) lastReturned = Math.min(index-1, indecies.size()-1);
return steps;
}

@Override
public int back(int amount) {
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
int steps = Math.min(amount, index);
index -= steps;
if(steps > 0) lastReturned = Math.max(index, 0);
return steps;
}
}

private class IndexedIterator implements BooleanListIterator {
int[] indecies;
int index;
int lastReturned = -1;

IndexedIterator(int[] indecies) {
this.indecies = indecies;
}

@Override
public boolean hasNext() {
return index < indecies.length;
}

@Override
public boolean nextBoolean() {
if(!hasNext()) throw new NoSuchElementException();
int i = index++;
return getBoolean((lastReturned = indecies[i]));
}

@Override
public boolean hasPrevious() {
return index > 0;
}

@Override
public boolean previousBoolean() {
if(!hasPrevious()) throw new NoSuchElementException();
index--;
return getBoolean((lastReturned = indecies[index]));
}

@Override
public int nextIndex() {
return index;
}

@Override
public int previousIndex() {
return index-1;
}

@Override
public void remove() { throw new UnsupportedOperationException(); }
@Override
public void add(boolean e) { throw new UnsupportedOperationException(); }

@Override
public void set(boolean e) {
if(lastReturned == -1) throw new IllegalStateException();
AbstractBooleanList.this.set(lastReturned, e);
}

@Override
public int skip(int amount) {
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
int steps = Math.min(amount, indecies.length - index);
index += steps;
if(steps > 0) lastReturned = Math.min(index-1, indecies.length-1);
return steps;
}

@Override
public int back(int amount) {
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
int steps = Math.min(amount, index);
index -= steps;
if(steps > 0) lastReturned = Math.max(index, 0);
return steps;
}
}

private class BooleanListIter implements BooleanListIterator {
int index;
int lastReturned = -1;
Expand Down Expand Up @@ -644,7 +801,7 @@ public int back(int amount) {
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
int steps = Math.min(amount, index);
index -= steps;
if(steps > 0) lastReturned = Math.min(index, size()-1);
if(steps > 0) lastReturned = Math.max(index, 0);
return steps;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import speiger.src.collections.booleans.functions.BooleanComparator;
import speiger.src.collections.booleans.utils.BooleanArrays;
import speiger.src.collections.booleans.utils.BooleanLists;
import speiger.src.collections.ints.lists.IntList;
import speiger.src.collections.booleans.utils.BooleanSplititerators;

/**
Expand Down Expand Up @@ -320,6 +321,24 @@ public default void forEachIndexed(IntBooleanConsumer action) {
@Override
public BooleanListIterator listIterator(int index);

/**
* Creates a Iterator that follows the indecies provided.<br>
* For example if the Lists Contents is:<br> -1, 0 1 <br>and the indecies are: <br>0, 1, 2, 2, 1, 0<br>
* then the iterator will return the following values: <br>-1, 0, 1, 1, 0, -1
* @param indecies that should be used for the iteration.
* @return a custom indexed iterator
*/
public BooleanListIterator indexedIterator(int...indecies);

/**
* Creates a Iterator that follows the indecies provided.<br>
* For example if the Lists Contents is:<br> -1, 0 1 <br>and the indecies are: <br>0, 1, 2, 2, 1, 0<br>
* then the iterator will return the following values: <br>-1, 0, 1, 1, 0, -1
* @param indecies that should be used for the iteration.
* @return a custom indexed iterator
*/
public BooleanListIterator indexedIterator(IntList indecies);

/**
* A Type-Specific List of subList
* @see java.util.List#subList(int, int)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,15 @@ public boolean peek(int index) {
return index >= array.length ? array[index-array.length] : array[index];
}

@Override
public boolean contains(boolean e) {
if(first == last) return false;
for(int i = 0,m=size();i<m;i++) {
if(e == array[(first + i) % array.length]) return true;
}
return false;
}

@Override
public boolean removeFirst(boolean e) {
if(first == last) return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,13 @@ public boolean peek(int index) {
return array[index];
}

@Override
public boolean contains(boolean e) {
for(int i = 0;i<size;i++)
if(e == array[i]) return true;
return false;
}

@Override
public boolean removeFirst(boolean e) {
for(int i = 0;i<size;i++)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,13 @@ public boolean peek(int index) {
return array[index];
}

@Override
public boolean contains(boolean e) {
for(int i = 0;i<size;i++)
if(e == array[i]) return true;
return false;
}

@Override
public boolean removeFirst(boolean e) {
for(int i = 0;i<size;i++)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ public default void enqueueAll(BooleanCollection c) {
*/
public default boolean first() { return peek(0); }

/**
* Method to find out if a element is part of the queue
* @param e the element that is searched for
* @return true if the element is in the queue
*/
public boolean contains(boolean e);

/**
* Removes the first found element in the queue
* @param e the element that should be removed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
import speiger.src.collections.booleans.lists.BooleanArrayList;
import speiger.src.collections.objects.utils.ObjectAsyncBuilder;
import speiger.src.collections.objects.utils.ObjectAsyncBuilder.BaseObjectTask;
import speiger.src.collections.ints.utils.IntAsyncBuilder;
import speiger.src.collections.ints.utils.IntAsyncBuilder.BaseIntTask;
import speiger.src.collections.ints.utils.IntAsyncBuilder;import speiger.src.collections.ints.utils.IntAsyncBuilder.BaseIntTask;
import speiger.src.collections.utils.ISizeProvider;
import speiger.src.collections.utils.SanityChecks;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,23 @@

import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.function.Consumer;

import speiger.src.collections.booleans.collections.BooleanIterator;
import speiger.src.collections.objects.collections.ObjectIterator;
import speiger.src.collections.objects.utils.ObjectIterators;
import speiger.src.collections.booleans.functions.BooleanConsumer;
import speiger.src.collections.booleans.functions.BooleanComparator;
import speiger.src.collections.booleans.functions.function.BooleanFunction;
import speiger.src.collections.objects.functions.consumer.ObjectBooleanConsumer;
import speiger.src.collections.booleans.functions.function.BooleanPredicate;
import speiger.src.collections.booleans.lists.BooleanList;
import speiger.src.collections.booleans.lists.BooleanArrayList;

import speiger.src.collections.booleans.lists.BooleanListIterator;
import speiger.src.collections.booleans.collections.BooleanBidirectionalIterator;
import speiger.src.collections.booleans.collections.BooleanCollection;
import speiger.src.collections.booleans.utils.BooleanCollections.CollectionWrapper;

/**
* A Helper class for Iterators
Expand Down Expand Up @@ -206,6 +209,24 @@ public static BooleanIterator repeat(Iterator<? extends Boolean> iterator, int r
return new RepeatingIterator(wrap(iterator), repeats);
}

/**
* A Helper function that creates a infinitely looping iterator
* @param iterator that should be looping infinitely
* @return a infinitely looping iterator
*/
public static BooleanIterator infinite(BooleanIterator iterator) {
return new InfiniteIterator(iterator);
}

/**
* A Helper function that creates a infinitely looping iterator from a Java Iterator
* @param iterator that should be looping infinitely
* @return a infinitely looping iterator
*/
public static BooleanIterator infinite(Iterator<? extends Boolean> iterator) {
return new InfiniteIterator(wrap(iterator));
}

/**
* A Helper function that hard limits the Iterator to a specific size
* @param iterator that should be limited
Expand Down Expand Up @@ -841,6 +862,40 @@ public T next() {
}
}

private static class InfiniteIterator implements BooleanIterator
{
BooleanIterator iter;
CollectionWrapper looper = BooleanCollections.wrapper();
int index = 0;

public InfiniteIterator(BooleanIterator iter) {
this.iter = iter;
}

@Override
public boolean hasNext() {
return true;
}

@Override
public boolean nextBoolean() {
if(iter != null) {
if(iter.hasNext()) {
boolean value = iter.nextBoolean();
looper.add(value);
return value;
}
else iter = null;
}
return looper.getBoolean((index++) % looper.size());
}

@Override
public void forEachRemaining(BooleanConsumer action) { throw new UnsupportedOperationException("This is a instant deadlock, so unsupported"); }
public void forEachRemaining(Consumer<? super Boolean> action) { throw new UnsupportedOperationException("This is a instant deadlock, so unsupported"); }
public <E> void forEachRemaining(E input, ObjectBooleanConsumer<E> action) { throw new UnsupportedOperationException("This is a instant deadlock, so unsupported"); }
}

private static class RepeatingIterator implements BooleanIterator
{
final int repeats;
Expand Down
Loading

0 comments on commit 2a2d9e8

Please sign in to comment.