Sync Source Changes :)

This commit is contained in:
Speiger 2026-05-12 13:40:48 +02:00
parent 4c565f2cf3
commit 91aabe2096
928 changed files with 20291 additions and 14236 deletions

View File

@ -198,6 +198,7 @@ public class MapModule extends BaseModule
addBiRequirement("SortedMapNavigationTester");
addBiRequirement("OrderedMapNavigationTester");
addBiRequirement("OrderedMapMoveTester");
addBiRequirement("OrderedMapPutTester");
addBiRequirement("MapConstructorTester");
addRemapper("TestMapGenerator", "Test%sMapGenerator");

View File

@ -713,6 +713,10 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
}
private class MapEntrySet extends AbstractObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> implements ORDERED_MAP.FastOrderedSet KEY_VALUE_GENERIC_TYPE {
@Override
public void addFirst(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
@Override
@ -1004,10 +1008,13 @@ public class LINKED_CUSTOM_HASH_MAP KEY_VALUE_GENERIC_TYPE extends CUSTOM_HASH_M
public boolean add(KEY_TYPE o) {
throw new UnsupportedOperationException();
}
@Override
public void addFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(KEY_TYPE o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToLast(KEY_TYPE o) { throw new UnsupportedOperationException(); }

View File

@ -717,6 +717,10 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
}
private class MapEntrySet extends AbstractObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> implements ORDERED_MAP.FastOrderedSet KEY_VALUE_GENERIC_TYPE {
@Override
public void addFirst(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
@Override
@ -1003,6 +1007,12 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
#endif
@Override
public boolean add(KEY_TYPE o) { throw new UnsupportedOperationException(); }
@Override
public void addFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(KEY_TYPE o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); }

View File

@ -637,6 +637,10 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
}
private class MapEntrySet extends AbstractObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> implements ORDERED_MAP.FastOrderedSet KEY_VALUE_GENERIC_TYPE {
@Override
public void addFirst(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
@Override
@ -894,6 +898,12 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
throw new UnsupportedOperationException();
}
@Override
public void addFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(KEY_TYPE o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); }

View File

@ -868,6 +868,10 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
}
private class MapEntrySet extends AbstractObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> implements ORDERED_MAP.FastOrderedSet KEY_VALUE_GENERIC_TYPE {
@Override
public void addFirst(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
@Override
@ -1126,6 +1130,10 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
@Override
public boolean add(KEY_TYPE o) { throw new UnsupportedOperationException(); }
@Override
public void addFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(KEY_TYPE o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToLast(KEY_TYPE o) { throw new UnsupportedOperationException(); }

View File

@ -473,6 +473,10 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
}
private class MapEntrySet extends AbstractObjectSet<MAP.Entry KEY_VALUE_GENERIC_TYPE> implements ORDERED_MAP.FastOrderedSet KEY_VALUE_GENERIC_TYPE {
@Override
public void addFirst(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
@Override
@ -637,7 +641,10 @@ public class LINKED_ENUM_MAP KEY_ENUM_VALUE_GENERIC_TYPE extends ENUM_MAP KEY_VA
public boolean add(T o) {
throw new UnsupportedOperationException();
}
@Override
public void addFirst(T o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(T o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(T o) { throw new UnsupportedOperationException(); }

View File

@ -73,7 +73,17 @@ public abstract class ABSTRACT_SET KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION
public BI_ITERATOR KEY_GENERIC_TYPE reverseIterator() {
return set.iterator();
}
@Override
public void addFirst(KEY_TYPE o) {
set.addLast(o);
}
@Override
public void addLast(KEY_TYPE o) {
set.addFirst(o);
}
@Override
#if !TYPE_OBJECT
public boolean remove(KEY_TYPE o) {

View File

@ -153,6 +153,25 @@ public class ARRAY_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERIC_TYPE im
}
#endif
@Override
public void addFirst(KEY_TYPE o) {
int index = findIndex(o);
if(index == -1) {
if(data.length == size) data = Arrays.copyOf(data, size == 0 ? 2 : size * 2);
System.arraycopy(data, 0, data, 1, size++);
data[0] = o;
}
}
@Override
public void addLast(KEY_TYPE o) {
int index = findIndex(o);
if(index == -1) {
if(data.length == size) data = Arrays.copyOf(data, size == 0 ? 2 : size * 2);
data[size++] = o;
}
}
@Override
public boolean addAndMoveToFirst(KEY_TYPE o) {
int index = findIndex(o);

View File

@ -264,6 +264,10 @@ public class IMMUTABLE_HASH_SET KEY_GENERIC_TYPE extends ABSTRACT_SET KEY_GENERI
@Override
public boolean addAll(COLLECTION KEY_GENERIC_TYPE c) { throw new UnsupportedOperationException(); }
@Override
public void addFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(KEY_TYPE o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToLast(KEY_TYPE o) { throw new UnsupportedOperationException(); }

View File

@ -241,6 +241,46 @@ public class LINKED_CUSTOM_HASH_SET KEY_GENERIC_TYPE extends CUSTOM_HASH_SET KEY
}
#endif
@Override
public void addFirst(KEY_TYPE o) {
if(strategy.equals(o, EMPTY_KEY_VALUE)) {
if(containsNull) return;
containsNull = true;
onNodeAdded(nullIndex);
moveToFirstIndex(nullIndex);
}
else {
int pos = HashUtil.mix(strategy.hashCode(o)) & mask;
while(!strategy.equals(keys[pos], EMPTY_KEY_VALUE)) {
if(strategy.equals(keys[pos], o)) return;
pos = ++pos & mask;
}
keys[pos] = o;
onNodeAdded(pos);
moveToFirstIndex(pos);
}
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
}
@Override
public void addLast(KEY_TYPE o) {
if(strategy.equals(o, EMPTY_KEY_VALUE)) {
if(containsNull) return;
containsNull = true;
onNodeAdded(nullIndex);
}
else {
int pos = HashUtil.mix(strategy.hashCode(o)) & mask;
while(!strategy.equals(keys[pos], EMPTY_KEY_VALUE)) {
if(strategy.equals(keys[pos], o)) return;
pos = ++pos & mask;
}
keys[pos] = o;
onNodeAdded(pos);
}
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
}
@Override
public boolean addAndMoveToFirst(KEY_TYPE o) {
if(strategy.equals(o, EMPTY_KEY_VALUE)) {

View File

@ -212,6 +212,46 @@ public class LINKED_HASH_SET KEY_GENERIC_TYPE extends HASH_SET KEY_GENERIC_TYPE
}
#endif
@Override
public void addFirst(KEY_TYPE o) {
if(KEY_EQUALS_NULL(o)) {
if(containsNull) return;
containsNull = true;
onNodeAdded(nullIndex);
moveToFirstIndex(nullIndex);
}
else {
int pos = HashUtil.mix(KEY_TO_HASH(o)) & mask;
while(KEY_EQUALS_NOT_NULL(keys[pos])) {
if(KEY_EQUALS(keys[pos], o)) return;
pos = ++pos & mask;
}
keys[pos] = o;
onNodeAdded(pos);
moveToFirstIndex(pos);
}
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
}
@Override
public void addLast(KEY_TYPE o) {
if(KEY_EQUALS_NULL(o)) {
if(containsNull) return;
containsNull = true;
onNodeAdded(nullIndex);
}
else {
int pos = HashUtil.mix(KEY_TO_HASH(o)) & mask;
while(KEY_EQUALS_NOT_NULL(keys[pos])) {
if(KEY_EQUALS(keys[pos], o)) return;
pos = ++pos & mask;
}
keys[pos] = o;
onNodeAdded(pos);
}
if(size++ >= maxFill) rehash(HashUtil.arraySize(size+1, loadFactor));
}
@Override
public boolean addAndMoveToFirst(KEY_TYPE o) {
if(KEY_EQUALS_NULL(o)) {

View File

@ -5,6 +5,7 @@ import java.util.SequencedSet;
#endif
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
import speiger.src.collections.PACKAGE.collections.ORDERED_COLLECTION;
#if SPLIT_ITERATOR_FEATURE
import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR;
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
@ -23,9 +24,9 @@ import speiger.src.collections.PACKAGE.utils.SETS;
* @Type(T)
*/
#if JAVA_VERSION>=21
public interface ORDERED_SET KEY_GENERIC_TYPE extends SET KEY_GENERIC_TYPE, SequencedSet<CLASS_TYPE>
public interface ORDERED_SET KEY_GENERIC_TYPE extends SET KEY_GENERIC_TYPE, ORDERED_COLLECTION KEY_GENERIC_TYPE, SequencedSet<CLASS_TYPE>
#else
public interface ORDERED_SET KEY_GENERIC_TYPE extends SET KEY_GENERIC_TYPE
public interface ORDERED_SET KEY_GENERIC_TYPE extends SET KEY_GENERIC_TYPE, ORDERED_COLLECTION KEY_GENERIC_TYPE
#endif
{
/**

View File

@ -360,6 +360,10 @@ public class SETS
s = c;
}
@Override
public void addFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(KEY_TYPE o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); }
@Override
@ -650,7 +654,11 @@ public class SETS
super(c, mutex);
s = c;
}
@Override
public void addFirst(KEY_TYPE o) { synchronized(mutex) { s.addFirst(o); } }
@Override
public void addLast(KEY_TYPE o) { synchronized(mutex) { s.addLast(o); } }
@Override
public boolean addAndMoveToFirst(KEY_TYPE o) { synchronized(mutex) { return s.addAndMoveToFirst(o); } }
@Override

View File

@ -754,7 +754,11 @@ public class MAPS
super(c);
set = c;
}
@Override
public void addFirst(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
@Override

View File

@ -20,6 +20,7 @@ import speiger.src.testers.PACKAGE.generators.maps.TEST_ORDERED_MAP_GENERATOR;
import speiger.src.testers.PACKAGE.impl.maps.DERIVED_MAP_GENERATORS;
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEOrderedMapMoveTester;
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEOrderedMapNavigationTester;
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEOrderedMapPutTester;
#if !TYPE_OBJECT
import speiger.src.testers.objects.builder.ObjectSetTestSuiteBuilder;
import speiger.src.testers.objects.generators.TestObjectSetGenerator;
@ -41,6 +42,7 @@ public class ORDERED_MAP_TEST_BUILDER KEY_VALUE_GENERIC_TYPE extends MAP_TEST_BU
List<Class<? extends AbstractTester>> testers = super.getTesters();
testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEOrderedMapMoveTester.class);
testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEOrderedMapNavigationTester.class);
testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEOrderedMapPutTester.class);
return testers;
}

View File

@ -27,6 +27,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapContainsTester KEY_VALUE_GENERIC_TY
#ignore
@CollectionSize.Require(absent = ZERO)
@SuppressWarnings("unlikely-arg-type")
#endignore
public void testContainsObject_yes() {
assertTrue("contains(present) should return true", getMap().ENTRY_SET().contains(new AbstractMap.SimpleEntry<>(e0())));
@ -36,6 +37,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapContainsTester KEY_VALUE_GENERIC_TY
assertFalse("contains(notPresent) should return false", getMap().ENTRY_SET().contains(e3()));
}
@SuppressWarnings("unlikely-arg-type")
public void testContainsObject_no() {
assertFalse("contains(notPresent) should return false", getMap().ENTRY_SET().contains(new AbstractMap.SimpleEntry<>(e3())));
}

View File

@ -136,6 +136,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapRemoveEntryTester KEY_VALUE_GENERIC
#ignore
@CollectionSize.Require(ONE)
@MapFeature.Require(SUPPORTS_REMOVE)
@SuppressWarnings("unlikely-arg-type")
#endignore
public void testRemove_supportedObjectEntryPresent() {
assertTrue(getMap().ENTRY_SET().remove(new AbstractMap.SimpleEntry<>(e0())));
@ -154,6 +155,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapRemoveEntryTester KEY_VALUE_GENERIC
#ignore
@CollectionSize.Require(ONE)
@MapFeature.Require(SUPPORTS_REMOVE)
@SuppressWarnings("unlikely-arg-type")
#endignore
public void testRemove_supportedObjectEntryMissing() {
assertFalse(getMap().ENTRY_SET().remove(new AbstractMap.SimpleEntry<>(e3())));

View File

@ -0,0 +1,122 @@
package speiger.src.testers.PACKAGE.tests.maps;
#ignore
import static com.google.common.collect.testing.features.CollectionSize.ZERO;
import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_PUT;
import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_REMOVE;
import static org.junit.Assert.assertNotEquals;
#endignore
import com.google.common.collect.testing.features.CollectionSize;
import com.google.common.collect.testing.features.MapFeature;
import speiger.src.collections.PACKAGE.maps.interfaces.MAP;
import speiger.src.collections.PACKAGE.maps.interfaces.ORDERED_MAP;
import speiger.src.collections.objects.lists.ObjectList;
import speiger.src.testers.PACKAGE.tests.base.maps.ABSTRACT_MAP_TESTER;
import speiger.src.testers.objects.utils.ObjectHelpers;
@SuppressWarnings("javadoc")
public class FILE_KEY_TYPE2FILE_VALUE_TYPEOrderedMapPutTester KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP_TESTER KEY_VALUE_GENERIC_TYPE
{
private ORDERED_MAP KEY_VALUE_GENERIC_TYPE orderedMap;
private ObjectList<MAP.Entry KEY_VALUE_GENERIC_TYPE> values;
private KEY_TYPE a;
private VALUE_TYPE aValue;
private VALUE_TYPE cValue;
@Override
public void setUp() throws Exception {
super.setUp();
orderedMap = (ORDERED_MAP KEY_VALUE_GENERIC_TYPE)getMap();
values = ObjectHelpers.copyToList(getSampleElements(getSubjectGenerator().getCollectionSize().getNumElements()));
if (values.size() >= 1) {
a = values.get(0).ENTRY_KEY();
aValue = values.get(0).ENTRY_VALUE();
if (values.size() >= 3) {
cValue = values.get(2).ENTRY_VALUE();
}
}
}
#ignore
@MapFeature.Require(SUPPORTS_PUT)
@CollectionSize.Require(absent = ZERO)
#endignore
public void testPutFirst() {
assertEquals(aValue, orderedMap.putFirst(a, cValue));
assertNotEquals(cValue, orderedMap.FIRST_ENTRY_VALUE());
assertEquals(orderedMap.getDefaultReturnValue(), orderedMap.putFirst(k4(), v4()));
assertNotEquals(v4(), orderedMap.FIRST_ENTRY_VALUE());
assertEquals(e4(), orderedMap.firstEntry());
}
#ignore
@MapFeature.Require(SUPPORTS_PUT)
@CollectionSize.Require(absent = ZERO)
#endignore
public void testPutLast() {
assertEquals(aValue, orderedMap.putLast(a, cValue));
assertNotEquals(cValue, orderedMap.LAST_ENTRY_VALUE());
assertEquals(orderedMap.getDefaultReturnValue(), orderedMap.putLast(k4(), v4()));
assertNotEquals(v4(), orderedMap.LAST_ENTRY_VALUE());
assertEquals(e4(), orderedMap.lastEntry());
}
#ignore
@MapFeature.Require(SUPPORTS_REMOVE)
@CollectionSize.Require(CollectionSize.ONE)
#endignore
public void testPollFirst() {
assertFalse(orderedMap.isEmpty());
assertEquals(e0(), orderedMap.pollFirstEntry());
assertTrue(orderedMap.isEmpty());
}
#ignore
@MapFeature.Require(SUPPORTS_REMOVE)
@CollectionSize.Require(CollectionSize.ONE)
#endignore
public void testPollLast() {
assertFalse(orderedMap.isEmpty());
assertEquals(e0(), orderedMap.pollLastEntry());
assertTrue(orderedMap.isEmpty());
}
#ignore
@MapFeature.Require(absent = SUPPORTS_PUT)
#endignore
public void testUnsupportedPutFirst() {
try { orderedMap.putFirst(a, aValue); }
catch (UnsupportedOperationException tolerated) {}
expectUnchanged();
}
#ignore
@MapFeature.Require(absent = SUPPORTS_PUT)
#endignore
public void testUnsupportedPutLast() {
try { orderedMap.putLast(a, aValue); }
catch (UnsupportedOperationException tolerated) {}
expectUnchanged();
}
#ignore
@MapFeature.Require(absent = SUPPORTS_REMOVE)
#endignore
public void testUnsupportedPollFirst() {
try { orderedMap.pollFirstEntry(); }
catch (UnsupportedOperationException tolerated) {}
expectUnchanged();
}
#ignore
@MapFeature.Require(absent = SUPPORTS_REMOVE)
#endignore
public void testUnsupportedPollLast() {
try { orderedMap.pollFirstEntry(); }
catch (UnsupportedOperationException tolerated) {}
expectUnchanged();
}
}

View File

@ -2,6 +2,11 @@ package speiger.src.testers.PACKAGE.tests.queue.iterators;
#if TYPE_OBJECT
import java.util.Objects;
#endif
#if JDK_TYPE
import java.util.OPTIONAL;
#else
import speiger.src.collections.PACKAGE.functions.OPTIONAL;
#endif
import org.junit.Ignore;
@ -27,17 +32,17 @@ public class FILE_KEY_TYPEQueueFindFirstTester KEY_GENERIC_TYPE extends ABSTRACT
@CollectionSize.Require(absent = CollectionSize.ZERO)
#endignore
public void testQueueFindFirst_FindFirstElements() {
assertEquals("First Element should be found", e0(), queue.findFirst(T -> KEY_EQUALS(T, e0())));
assertEquals("First Element should be found", e0(), queue.findFirst(T -> KEY_EQUALS(T, e0())).SUPPLY_GET());
}
public void testQueueFindFirst_FindNothing() {
assertEquals("No element should be found", EMPTY_KEY_VALUE, queue.findFirst(T -> KEY_EQUALS(T, e4())));
assertEquals("No element should be found", OPTIONAL.empty(), queue.findFirst(T -> KEY_EQUALS(T, e4())));
}
#ignore
@CollectionSize.Require(CollectionSize.SEVERAL)
#endignore
public void testQueueFindFirst_FindLastElement() {
assertEquals("Last Element should be found", e2(), queue.findFirst(T -> KEY_EQUALS(T, e2())));
assertEquals("Last Element should be found", e2(), queue.findFirst(T -> KEY_EQUALS(T, e2())).SUPPLY_GET());
}
}

View File

@ -3,10 +3,16 @@ package speiger.src.testers.PACKAGE.tests.queue.iterators;
#if TYPE_OBJECT
import java.util.Objects;
#endif
#if JDK_TYPE
import java.util.OPTIONAL;
#else
import speiger.src.collections.PACKAGE.functions.OPTIONAL;
#endif
import org.junit.Ignore;
import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_QUEUE_TESTER;
import com.google.common.collect.testing.features.CollectionSize;
@Ignore
@SuppressWarnings("javadoc")
@ -29,7 +35,7 @@ public class FILE_KEY_TYPEQueueReduceTester KEY_GENERIC_TYPE extends ABSTRACT_QU
}
public void testQueueReduce() {
assertEquals("The sum of the queue should match", getSum(), queue.reduce(this::sum));
assertEquals("The sum of the queue should match", size == CollectionSize.ZERO ? OPTIONAL.empty() : OPTIONAL.GET_OPTIONAL(getSum()), queue.reduce(this::sum));
}
public void testQueueExtraReduce() {

View File

@ -7,6 +7,7 @@ import java.util.function.Consumer;
import speiger.src.collections.booleans.functions.BooleanConsumer;
import speiger.src.collections.booleans.functions.BooleanComparator;
import speiger.src.collections.objects.collections.ObjectIterable;
import speiger.src.collections.booleans.functions.OptionalBoolean;
import speiger.src.collections.booleans.functions.function.BooleanFunction;
import speiger.src.collections.ints.functions.consumer.IntBooleanConsumer;
import speiger.src.collections.objects.functions.consumer.ObjectBooleanConsumer;
@ -271,13 +272,13 @@ public interface BooleanIterable extends Iterable<Boolean>
* @param filter that should be applied
* @return the found value or the null equivalent variant.
*/
default boolean findFirst(BooleanPredicate filter) {
default OptionalBoolean findFirst(BooleanPredicate filter) {
Objects.requireNonNull(filter);
for(BooleanIterator iter = iterator();iter.hasNext();) {
boolean entry = iter.nextBoolean();
if(filter.test(entry)) return entry;
if(filter.test(entry)) return OptionalBoolean.of(entry);
}
return false;
return OptionalBoolean.empty();
}
/**
@ -302,7 +303,7 @@ public interface BooleanIterable extends Iterable<Boolean>
* @param operator the operation that should be applied
* @return the reduction result, returns null value if nothing was found
*/
default boolean reduce(BooleanBooleanUnaryOperator operator) {
default OptionalBoolean reduce(BooleanBooleanUnaryOperator operator) {
Objects.requireNonNull(operator);
boolean state = false;
boolean empty = true;
@ -314,7 +315,7 @@ public interface BooleanIterable extends Iterable<Boolean>
}
state = operator.applyAsBoolean(state, iter.nextBoolean());
}
return state;
return empty ? OptionalBoolean.empty() : OptionalBoolean.of(state);
}
/**

View File

@ -10,6 +10,7 @@ import java.util.function.UnaryOperator;
import speiger.src.collections.booleans.collections.BooleanCollection;
import speiger.src.collections.booleans.collections.BooleanStack;
import speiger.src.collections.booleans.collections.BooleanIterator;
import speiger.src.collections.booleans.functions.OptionalBoolean;
import speiger.src.collections.booleans.functions.BooleanComparator;
import speiger.src.collections.booleans.functions.BooleanConsumer;
import speiger.src.collections.objects.functions.consumer.ObjectBooleanConsumer;
@ -510,12 +511,12 @@ public class BooleanArrayList extends AbstractBooleanList implements IBooleanArr
}
@Override
public boolean findFirst(BooleanPredicate filter) {
public OptionalBoolean findFirst(BooleanPredicate filter) {
Objects.requireNonNull(filter);
for(int i = 0;i<size;i++) {
if(filter.test(data[i])) return data[i];
if(filter.test(data[i])) return OptionalBoolean.of(data[i]);
}
return false;
return OptionalBoolean.empty();
}
@Override
@ -529,7 +530,7 @@ public class BooleanArrayList extends AbstractBooleanList implements IBooleanArr
}
@Override
public boolean reduce(BooleanBooleanUnaryOperator operator) {
public OptionalBoolean reduce(BooleanBooleanUnaryOperator operator) {
Objects.requireNonNull(operator);
boolean state = false;
boolean empty = true;
@ -541,7 +542,7 @@ public class BooleanArrayList extends AbstractBooleanList implements IBooleanArr
}
state = operator.applyAsBoolean(state, data[i]);
}
return state;
return empty ? OptionalBoolean.empty() : OptionalBoolean.of(state);
}
@Override

View File

@ -8,6 +8,7 @@ import java.util.Spliterator;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.function.UnaryOperator;
import speiger.src.collections.booleans.functions.OptionalBoolean;
import speiger.src.collections.ints.functions.consumer.IntBooleanConsumer;
import speiger.src.collections.objects.functions.consumer.ObjectBooleanConsumer;
import speiger.src.collections.booleans.functions.function.BooleanPredicate;
@ -415,12 +416,12 @@ public class BooleanLinkedList extends AbstractBooleanList implements BooleanPri
}
@Override
public boolean findFirst(BooleanPredicate filter) {
public OptionalBoolean findFirst(BooleanPredicate filter) {
Objects.requireNonNull(filter);
for(Entry entry = first;entry != null;entry = entry.next) {
if(filter.test(entry.value)) return entry.value;
if(filter.test(entry.value)) return OptionalBoolean.of(entry.value);
}
return false;
return OptionalBoolean.empty();
}
@Override
@ -434,7 +435,7 @@ public class BooleanLinkedList extends AbstractBooleanList implements BooleanPri
}
@Override
public boolean reduce(BooleanBooleanUnaryOperator operator) {
public OptionalBoolean reduce(BooleanBooleanUnaryOperator operator) {
Objects.requireNonNull(operator);
boolean state = false;
boolean empty = true;
@ -446,7 +447,7 @@ public class BooleanLinkedList extends AbstractBooleanList implements BooleanPri
}
state = operator.applyAsBoolean(state, entry.value);
}
return state;
return empty ? OptionalBoolean.empty() : OptionalBoolean.of(state);
}
@Override

View File

@ -14,6 +14,7 @@ import java.util.function.UnaryOperator;
import speiger.src.collections.booleans.collections.BooleanCollection;
import speiger.src.collections.booleans.collections.BooleanStack;
import speiger.src.collections.booleans.collections.BooleanIterator;
import speiger.src.collections.booleans.functions.OptionalBoolean;
import speiger.src.collections.booleans.functions.BooleanComparator;
import speiger.src.collections.booleans.functions.BooleanConsumer;
import speiger.src.collections.objects.functions.consumer.ObjectBooleanConsumer;
@ -645,13 +646,13 @@ public class CopyOnWriteBooleanArrayList extends AbstractBooleanList implements
}
@Override
public boolean findFirst(BooleanPredicate filter) {
public OptionalBoolean findFirst(BooleanPredicate filter) {
Objects.requireNonNull(filter);
boolean[] data = this.data;
for(int i = 0,m=data.length;i<m;i++) {
if(filter.test(data[i])) return data[i];
if(filter.test(data[i])) return OptionalBoolean.of(data[i]);
}
return false;
return OptionalBoolean.empty();
}
@Override
@ -666,7 +667,7 @@ public class CopyOnWriteBooleanArrayList extends AbstractBooleanList implements
}
@Override
public boolean reduce(BooleanBooleanUnaryOperator operator) {
public OptionalBoolean reduce(BooleanBooleanUnaryOperator operator) {
Objects.requireNonNull(operator);
boolean[] data = this.data;
boolean state = false;
@ -679,7 +680,7 @@ public class CopyOnWriteBooleanArrayList extends AbstractBooleanList implements
}
state = operator.applyAsBoolean(state, data[i]);
}
return state;
return empty ? OptionalBoolean.empty() : OptionalBoolean.of(state);
}
@Override

View File

@ -10,6 +10,7 @@ import java.util.function.UnaryOperator;
import speiger.src.collections.booleans.collections.BooleanCollection;
import speiger.src.collections.booleans.functions.BooleanComparator;
import speiger.src.collections.booleans.functions.BooleanConsumer;
import speiger.src.collections.booleans.functions.OptionalBoolean;
import speiger.src.collections.booleans.utils.BooleanArrays;
import speiger.src.collections.objects.functions.consumer.ObjectBooleanConsumer;
import speiger.src.collections.booleans.functions.function.BooleanPredicate;
@ -270,12 +271,12 @@ public class ImmutableBooleanList extends AbstractBooleanList
}
@Override
public boolean findFirst(BooleanPredicate filter) {
public OptionalBoolean findFirst(BooleanPredicate filter) {
Objects.requireNonNull(filter);
for(int i = 0,m=data.length;i<m;i++) {
if(filter.test(data[i])) return data[i];
if(filter.test(data[i])) return OptionalBoolean.of(data[i]);
}
return false;
return OptionalBoolean.empty();
}
@Override
@ -289,7 +290,7 @@ public class ImmutableBooleanList extends AbstractBooleanList
}
@Override
public boolean reduce(BooleanBooleanUnaryOperator operator) {
public OptionalBoolean reduce(BooleanBooleanUnaryOperator operator) {
Objects.requireNonNull(operator);
boolean state = false;
boolean empty = true;
@ -301,7 +302,7 @@ public class ImmutableBooleanList extends AbstractBooleanList
}
state = operator.applyAsBoolean(state, data[i]);
}
return state;
return empty ? OptionalBoolean.empty() : OptionalBoolean.of(state);
}
@Override

View File

@ -5,6 +5,7 @@ import java.util.Objects;
import java.util.NoSuchElementException;
import speiger.src.collections.booleans.collections.BooleanIterator;
import speiger.src.collections.booleans.functions.OptionalBoolean;
import speiger.src.collections.booleans.functions.BooleanComparator;
import speiger.src.collections.booleans.functions.BooleanConsumer;
import speiger.src.collections.ints.functions.consumer.IntBooleanConsumer;
@ -278,17 +279,17 @@ public class BooleanArrayFIFOQueue extends AbstractBooleanPriorityQueue implemen
}
@Override
public boolean findFirst(BooleanPredicate filter) {
public OptionalBoolean findFirst(BooleanPredicate filter) {
Objects.requireNonNull(filter);
for(int i = 0,m=size();i<m;i++) {
int index = (first + i) % array.length;
if(filter.test(array[index])) {
boolean data = array[index];
removeIndex(index);
return data;
return OptionalBoolean.of(data);
}
}
return false;
return OptionalBoolean.empty();
}
@Override
@ -302,7 +303,7 @@ public class BooleanArrayFIFOQueue extends AbstractBooleanPriorityQueue implemen
}
@Override
public boolean reduce(BooleanBooleanUnaryOperator operator) {
public OptionalBoolean reduce(BooleanBooleanUnaryOperator operator) {
Objects.requireNonNull(operator);
boolean state = false;
boolean empty = true;
@ -314,7 +315,7 @@ public class BooleanArrayFIFOQueue extends AbstractBooleanPriorityQueue implemen
}
state = operator.applyAsBoolean(state, array[(first + i) % array.length]);
}
return state;
return empty ? OptionalBoolean.empty() : OptionalBoolean.of(state);
}
@Override

View File

@ -6,6 +6,7 @@ import java.util.Objects;
import speiger.src.collections.booleans.collections.BooleanCollection;
import speiger.src.collections.booleans.collections.BooleanIterator;
import speiger.src.collections.booleans.functions.OptionalBoolean;
import speiger.src.collections.booleans.functions.BooleanComparator;
import speiger.src.collections.booleans.functions.BooleanConsumer;
import speiger.src.collections.ints.functions.consumer.IntBooleanConsumer;
@ -307,7 +308,7 @@ public class BooleanArrayPriorityQueue extends AbstractBooleanPriorityQueue
}
@Override
public boolean reduce(BooleanBooleanUnaryOperator operator) {
public OptionalBoolean reduce(BooleanBooleanUnaryOperator operator) {
Objects.requireNonNull(operator);
boolean state = false;
boolean empty = true;
@ -319,20 +320,20 @@ public class BooleanArrayPriorityQueue extends AbstractBooleanPriorityQueue
}
state = operator.applyAsBoolean(state, array[i]);
}
return state;
return empty ? OptionalBoolean.empty() : OptionalBoolean.of(state);
}
@Override
public boolean findFirst(BooleanPredicate filter) {
public OptionalBoolean findFirst(BooleanPredicate filter) {
Objects.requireNonNull(filter);
for(int i = 0;i<size;i++) {
if(filter.test(array[i])) {
boolean data = array[i];
removeIndex(i);
return data;
return OptionalBoolean.of(data);
}
}
return false;
return OptionalBoolean.empty();
}
@Override

View File

@ -6,6 +6,7 @@ import java.util.Objects;
import speiger.src.collections.booleans.collections.BooleanCollection;
import speiger.src.collections.booleans.collections.BooleanIterator;
import speiger.src.collections.booleans.functions.OptionalBoolean;
import speiger.src.collections.booleans.functions.BooleanComparator;
import speiger.src.collections.booleans.functions.BooleanConsumer;
import speiger.src.collections.ints.functions.consumer.IntBooleanConsumer;
@ -290,7 +291,7 @@ public class BooleanHeapPriorityQueue extends AbstractBooleanPriorityQueue
}
@Override
public boolean reduce(BooleanBooleanUnaryOperator operator) {
public OptionalBoolean reduce(BooleanBooleanUnaryOperator operator) {
Objects.requireNonNull(operator);
boolean state = false;
boolean empty = true;
@ -302,20 +303,20 @@ public class BooleanHeapPriorityQueue extends AbstractBooleanPriorityQueue
}
state = operator.applyAsBoolean(state, array[i]);
}
return state;
return empty ? OptionalBoolean.empty() : OptionalBoolean.of(state);
}
@Override
public boolean findFirst(BooleanPredicate filter) {
public OptionalBoolean findFirst(BooleanPredicate filter) {
Objects.requireNonNull(filter);
for(int i = 0;i<size;i++) {
if(filter.test(array[i])) {
boolean data = array[i];
removeIndex(i);
return data;
return OptionalBoolean.of(data);
}
}
return false;
return OptionalBoolean.empty();
}
@Override

View File

@ -13,6 +13,7 @@ import speiger.src.collections.booleans.collections.BooleanCollection;
import speiger.src.collections.booleans.collections.BooleanOrderedCollection;
import speiger.src.collections.booleans.collections.BooleanIterator;
import speiger.src.collections.booleans.functions.BooleanComparator;
import speiger.src.collections.booleans.functions.OptionalBoolean;
import speiger.src.collections.objects.utils.ObjectArrays;
import speiger.src.collections.booleans.functions.BooleanConsumer;
import speiger.src.collections.booleans.functions.function.BooleanPredicate;
@ -460,9 +461,9 @@ public class BooleanCollections
@Override
public boolean reduce(boolean identity, BooleanBooleanUnaryOperator operator) { synchronized(mutex) { return c.reduce(identity, operator); } }
@Override
public boolean reduce(BooleanBooleanUnaryOperator operator) { synchronized(mutex) { return c.reduce(operator); } }
public OptionalBoolean reduce(BooleanBooleanUnaryOperator operator) { synchronized(mutex) { return c.reduce(operator); } }
@Override
public boolean findFirst(BooleanPredicate filter) { synchronized(mutex) { return c.findFirst(filter); } }
public OptionalBoolean findFirst(BooleanPredicate filter) { synchronized(mutex) { return c.findFirst(filter); } }
@Override
public int count(BooleanPredicate filter) { synchronized(mutex) { return c.count(filter); } }
}
@ -588,9 +589,9 @@ public class BooleanCollections
@Override
public boolean reduce(boolean identity, BooleanBooleanUnaryOperator operator) { return c.reduce(identity, operator); }
@Override
public boolean reduce(BooleanBooleanUnaryOperator operator) { return c.reduce(operator); }
public OptionalBoolean reduce(BooleanBooleanUnaryOperator operator) { return c.reduce(operator); }
@Override
public boolean findFirst(BooleanPredicate filter) { return c.findFirst(filter); }
public OptionalBoolean findFirst(BooleanPredicate filter) { return c.findFirst(filter); }
@Override
public int count(BooleanPredicate filter) { return c.count(filter); }
}

View File

@ -1,13 +1,14 @@
package speiger.src.collections.booleans.utils;
import speiger.src.collections.booleans.collections.BooleanIterator;
import speiger.src.collections.booleans.collections.BooleanCollection;
import speiger.src.collections.booleans.functions.BooleanComparator;
import speiger.src.collections.booleans.functions.OptionalBoolean;
import speiger.src.collections.booleans.queues.BooleanPriorityDequeue;
import speiger.src.collections.booleans.queues.BooleanPriorityQueue;
import speiger.src.collections.booleans.functions.BooleanConsumer;
import speiger.src.collections.booleans.functions.function.BooleanPredicate;
import speiger.src.collections.booleans.functions.function.BooleanBooleanUnaryOperator;
import speiger.src.collections.objects.functions.consumer.ObjectBooleanConsumer;
/**
@ -113,7 +114,11 @@ public class BooleanPriorityQueues
@Override
public boolean matchesAll(BooleanPredicate filter) { synchronized(mutex) { return queue.matchesAll(filter); } }
@Override
public boolean findFirst(BooleanPredicate filter) { synchronized(mutex) { return queue.findFirst(filter); } }
public OptionalBoolean findFirst(BooleanPredicate filter) { synchronized(mutex) { return queue.findFirst(filter); } }
@Override
public boolean reduce(boolean identity, BooleanBooleanUnaryOperator operator) { synchronized(mutex) { return queue.reduce(identity, operator); } }
@Override
public OptionalBoolean reduce(BooleanBooleanUnaryOperator operator) { synchronized(mutex) { return queue.reduce(operator); } }
@Override
public int count(BooleanPredicate filter) { synchronized(mutex) { return queue.count(filter); } }
}

View File

@ -7,6 +7,7 @@ import java.util.function.Consumer;
import speiger.src.collections.bytes.functions.ByteConsumer;
import speiger.src.collections.bytes.functions.ByteComparator;
import speiger.src.collections.objects.collections.ObjectIterable;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.functions.function.ByteFunction;
import speiger.src.collections.ints.functions.consumer.IntByteConsumer;
import speiger.src.collections.objects.functions.consumer.ObjectByteConsumer;
@ -281,13 +282,13 @@ public interface ByteIterable extends Iterable<Byte>
* @param filter that should be applied
* @return the found value or the null equivalent variant.
*/
default byte findFirst(BytePredicate filter) {
default OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
for(ByteIterator iter = iterator();iter.hasNext();) {
byte entry = iter.nextByte();
if(filter.test(entry)) return entry;
if(filter.test(entry)) return OptionalByte.of(entry);
}
return (byte)0;
return OptionalByte.empty();
}
/**
@ -312,7 +313,7 @@ public interface ByteIterable extends Iterable<Byte>
* @param operator the operation that should be applied
* @return the reduction result, returns null value if nothing was found
*/
default byte reduce(ByteByteUnaryOperator operator) {
default OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -324,7 +325,7 @@ public interface ByteIterable extends Iterable<Byte>
}
state = operator.applyAsByte(state, iter.nextByte());
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
/**

View File

@ -12,6 +12,7 @@ import java.nio.ByteBuffer;
import speiger.src.collections.bytes.collections.ByteCollection;
import speiger.src.collections.bytes.collections.ByteStack;
import speiger.src.collections.bytes.collections.ByteIterator;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.functions.ByteComparator;
import speiger.src.collections.bytes.functions.ByteConsumer;
import speiger.src.collections.objects.functions.consumer.ObjectByteConsumer;
@ -519,12 +520,12 @@ public class ByteArrayList extends AbstractByteList implements IByteArray, ByteS
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
for(int i = 0;i<size;i++) {
if(filter.test(data[i])) return data[i];
if(filter.test(data[i])) return OptionalByte.of(data[i]);
}
return (byte)0;
return OptionalByte.empty();
}
@Override
@ -538,7 +539,7 @@ public class ByteArrayList extends AbstractByteList implements IByteArray, ByteS
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -550,7 +551,7 @@ public class ByteArrayList extends AbstractByteList implements IByteArray, ByteS
}
state = operator.applyAsByte(state, data[i]);
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override

View File

@ -11,6 +11,7 @@ import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.function.UnaryOperator;
import java.util.function.IntPredicate;import java.util.function.IntUnaryOperator;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.ints.functions.consumer.IntByteConsumer;
import speiger.src.collections.objects.functions.consumer.ObjectByteConsumer;
import speiger.src.collections.bytes.functions.function.BytePredicate;
@ -429,12 +430,12 @@ public class ByteLinkedList extends AbstractByteList implements BytePriorityDequ
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
for(Entry entry = first;entry != null;entry = entry.next) {
if(filter.test(entry.value)) return entry.value;
if(filter.test(entry.value)) return OptionalByte.of(entry.value);
}
return (byte)0;
return OptionalByte.empty();
}
@Override
@ -448,7 +449,7 @@ public class ByteLinkedList extends AbstractByteList implements BytePriorityDequ
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -460,7 +461,7 @@ public class ByteLinkedList extends AbstractByteList implements BytePriorityDequ
}
state = operator.applyAsByte(state, entry.value);
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override

View File

@ -16,6 +16,7 @@ import java.nio.ByteBuffer;
import speiger.src.collections.bytes.collections.ByteCollection;
import speiger.src.collections.bytes.collections.ByteStack;
import speiger.src.collections.bytes.collections.ByteIterator;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.functions.ByteComparator;
import speiger.src.collections.bytes.functions.ByteConsumer;
import speiger.src.collections.objects.functions.consumer.ObjectByteConsumer;
@ -654,13 +655,13 @@ public class CopyOnWriteByteArrayList extends AbstractByteList implements ITrimm
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
byte[] data = this.data;
for(int i = 0,m=data.length;i<m;i++) {
if(filter.test(data[i])) return data[i];
if(filter.test(data[i])) return OptionalByte.of(data[i]);
}
return (byte)0;
return OptionalByte.empty();
}
@Override
@ -675,7 +676,7 @@ public class CopyOnWriteByteArrayList extends AbstractByteList implements ITrimm
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte[] data = this.data;
byte state = (byte)0;
@ -688,7 +689,7 @@ public class CopyOnWriteByteArrayList extends AbstractByteList implements ITrimm
}
state = operator.applyAsByte(state, data[i]);
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override

View File

@ -11,6 +11,7 @@ import java.util.function.IntPredicate;import java.util.function.IntUnaryOperato
import speiger.src.collections.bytes.collections.ByteCollection;
import speiger.src.collections.bytes.functions.ByteComparator;
import speiger.src.collections.bytes.functions.ByteConsumer;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.utils.ByteArrays;
import speiger.src.collections.objects.functions.consumer.ObjectByteConsumer;
import speiger.src.collections.bytes.functions.function.BytePredicate;
@ -273,12 +274,12 @@ public class ImmutableByteList extends AbstractByteList
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
for(int i = 0,m=data.length;i<m;i++) {
if(filter.test(data[i])) return data[i];
if(filter.test(data[i])) return OptionalByte.of(data[i]);
}
return (byte)0;
return OptionalByte.empty();
}
@Override
@ -292,7 +293,7 @@ public class ImmutableByteList extends AbstractByteList
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -304,7 +305,7 @@ public class ImmutableByteList extends AbstractByteList
}
state = operator.applyAsByte(state, data[i]);
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override

View File

@ -4,6 +4,7 @@ import java.util.Arrays;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.locks.StampedLock;
import java.util.function.Consumer;
import java.util.function.Predicate;
@ -19,6 +20,7 @@ import speiger.src.collections.bytes.functions.consumer.ByteBooleanConsumer;
import speiger.src.collections.bytes.functions.function.BytePredicate;
import speiger.src.collections.bytes.functions.function.ByteBooleanUnaryOperator;
import speiger.src.collections.bytes.functions.function.ByteByteUnaryOperator;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.maps.abstracts.AbstractByte2BooleanMap;
import speiger.src.collections.bytes.maps.interfaces.Byte2BooleanMap;
import speiger.src.collections.bytes.maps.interfaces.Byte2BooleanConcurrentMap;
@ -36,6 +38,7 @@ import speiger.src.collections.booleans.functions.BooleanConsumer;
import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer;
import speiger.src.collections.objects.functions.consumer.ObjectBooleanConsumer;
import speiger.src.collections.booleans.functions.function.BooleanPredicate;
import speiger.src.collections.booleans.functions.OptionalBoolean;
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
import speiger.src.collections.objects.sets.AbstractObjectSet;
import speiger.src.collections.objects.sets.ObjectSet;
@ -755,7 +758,7 @@ public class Byte2BooleanConcurrentOpenHashMap extends AbstractByte2BooleanMap i
}
@Override
public Byte2BooleanMap.Entry reduce(ObjectObjectUnaryOperator<Byte2BooleanMap.Entry, Byte2BooleanMap.Entry> operator) {
public Optional<Byte2BooleanMap.Entry> reduce(ObjectObjectUnaryOperator<Byte2BooleanMap.Entry, Byte2BooleanMap.Entry> operator) {
Objects.requireNonNull(operator);
Byte2BooleanMap.Entry state = null;
boolean empty = true;
@ -779,11 +782,11 @@ public class Byte2BooleanConcurrentOpenHashMap extends AbstractByte2BooleanMap i
seg.unlockRead(stamp);
}
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public Byte2BooleanMap.Entry findFirst(Predicate<Byte2BooleanMap.Entry> filter) {
public Optional<Byte2BooleanMap.Entry> findFirst(Predicate<Byte2BooleanMap.Entry> filter) {
Objects.requireNonNull(filter);
MapEntry entry = new MapEntry();
for(int i = 0,m=segments.length;i<m;i++) {
@ -793,7 +796,7 @@ public class Byte2BooleanConcurrentOpenHashMap extends AbstractByte2BooleanMap i
try {
while(index != -1) {
entry.set(index, i);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
index = (int)seg.links[index];
}
}
@ -801,7 +804,7 @@ public class Byte2BooleanConcurrentOpenHashMap extends AbstractByte2BooleanMap i
seg.unlockRead(stamp);
}
}
return null;
return Optional.empty();
}
@Override
@ -1062,7 +1065,7 @@ public class Byte2BooleanConcurrentOpenHashMap extends AbstractByte2BooleanMap i
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -1086,11 +1089,11 @@ public class Byte2BooleanConcurrentOpenHashMap extends AbstractByte2BooleanMap i
seg.unlockRead(stamp);
}
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
for(int i = 0,m=segments.length;i<m;i++) {
Segment seg = segments[i];
@ -1098,7 +1101,7 @@ public class Byte2BooleanConcurrentOpenHashMap extends AbstractByte2BooleanMap i
try {
int index = seg.firstIndex;
while(index != -1){
if(filter.test(seg.keys[index])) return seg.keys[index];
if(filter.test(seg.keys[index])) return OptionalByte.of(seg.keys[index]);
index = (int)seg.links[index];
}
}
@ -1106,7 +1109,7 @@ public class Byte2BooleanConcurrentOpenHashMap extends AbstractByte2BooleanMap i
seg.unlockRead(stamp);
}
}
return (byte)0;
return OptionalByte.empty();
}
@Override
@ -1297,7 +1300,7 @@ public class Byte2BooleanConcurrentOpenHashMap extends AbstractByte2BooleanMap i
}
@Override
public boolean reduce(BooleanBooleanUnaryOperator operator) {
public OptionalBoolean reduce(BooleanBooleanUnaryOperator operator) {
Objects.requireNonNull(operator);
boolean state = false;
boolean empty = true;
@ -1321,20 +1324,20 @@ public class Byte2BooleanConcurrentOpenHashMap extends AbstractByte2BooleanMap i
seg.unlockRead(stamp);
}
}
return state;
return empty ? OptionalBoolean.empty() : OptionalBoolean.of(state);
}
@Override
public boolean findFirst(BooleanPredicate filter) {
public OptionalBoolean findFirst(BooleanPredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return false;
if(size() <= 0) return OptionalBoolean.empty();
for(int i = 0,m=segments.length;i<m;i++) {
Segment seg = segments[i];
long stamp = seg.readLock();
try {
int index = seg.firstIndex;
while(index != -1){
if(filter.test(seg.values[index])) return seg.values[index];
if(filter.test(seg.values[index])) return OptionalBoolean.of(seg.values[index]);
index = (int)seg.links[index];
}
}
@ -1342,7 +1345,7 @@ public class Byte2BooleanConcurrentOpenHashMap extends AbstractByte2BooleanMap i
seg.unlockRead(stamp);
}
}
return false;
return OptionalBoolean.empty();
}
@Override

View File

@ -4,6 +4,7 @@ import java.util.Arrays;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.locks.StampedLock;
import java.util.function.Consumer;
import java.util.function.Predicate;
@ -18,6 +19,7 @@ import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
import speiger.src.collections.bytes.functions.consumer.ByteByteConsumer;
import speiger.src.collections.bytes.functions.function.ByteUnaryOperator;
import speiger.src.collections.bytes.functions.function.ByteByteUnaryOperator;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.functions.function.BytePredicate;
import speiger.src.collections.bytes.maps.abstracts.AbstractByte2ByteMap;
import speiger.src.collections.bytes.maps.interfaces.Byte2ByteMap;
@ -761,7 +763,7 @@ public class Byte2ByteConcurrentOpenHashMap extends AbstractByte2ByteMap impleme
}
@Override
public Byte2ByteMap.Entry reduce(ObjectObjectUnaryOperator<Byte2ByteMap.Entry, Byte2ByteMap.Entry> operator) {
public Optional<Byte2ByteMap.Entry> reduce(ObjectObjectUnaryOperator<Byte2ByteMap.Entry, Byte2ByteMap.Entry> operator) {
Objects.requireNonNull(operator);
Byte2ByteMap.Entry state = null;
boolean empty = true;
@ -785,11 +787,11 @@ public class Byte2ByteConcurrentOpenHashMap extends AbstractByte2ByteMap impleme
seg.unlockRead(stamp);
}
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public Byte2ByteMap.Entry findFirst(Predicate<Byte2ByteMap.Entry> filter) {
public Optional<Byte2ByteMap.Entry> findFirst(Predicate<Byte2ByteMap.Entry> filter) {
Objects.requireNonNull(filter);
MapEntry entry = new MapEntry();
for(int i = 0,m=segments.length;i<m;i++) {
@ -799,7 +801,7 @@ public class Byte2ByteConcurrentOpenHashMap extends AbstractByte2ByteMap impleme
try {
while(index != -1) {
entry.set(index, i);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
index = (int)seg.links[index];
}
}
@ -807,7 +809,7 @@ public class Byte2ByteConcurrentOpenHashMap extends AbstractByte2ByteMap impleme
seg.unlockRead(stamp);
}
}
return null;
return Optional.empty();
}
@Override
@ -1068,7 +1070,7 @@ public class Byte2ByteConcurrentOpenHashMap extends AbstractByte2ByteMap impleme
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -1092,11 +1094,11 @@ public class Byte2ByteConcurrentOpenHashMap extends AbstractByte2ByteMap impleme
seg.unlockRead(stamp);
}
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
for(int i = 0,m=segments.length;i<m;i++) {
Segment seg = segments[i];
@ -1104,7 +1106,7 @@ public class Byte2ByteConcurrentOpenHashMap extends AbstractByte2ByteMap impleme
try {
int index = seg.firstIndex;
while(index != -1){
if(filter.test(seg.keys[index])) return seg.keys[index];
if(filter.test(seg.keys[index])) return OptionalByte.of(seg.keys[index]);
index = (int)seg.links[index];
}
}
@ -1112,7 +1114,7 @@ public class Byte2ByteConcurrentOpenHashMap extends AbstractByte2ByteMap impleme
seg.unlockRead(stamp);
}
}
return (byte)0;
return OptionalByte.empty();
}
@Override
@ -1303,7 +1305,7 @@ public class Byte2ByteConcurrentOpenHashMap extends AbstractByte2ByteMap impleme
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -1327,20 +1329,20 @@ public class Byte2ByteConcurrentOpenHashMap extends AbstractByte2ByteMap impleme
seg.unlockRead(stamp);
}
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return (byte)0;
if(size() <= 0) return OptionalByte.empty();
for(int i = 0,m=segments.length;i<m;i++) {
Segment seg = segments[i];
long stamp = seg.readLock();
try {
int index = seg.firstIndex;
while(index != -1){
if(filter.test(seg.values[index])) return seg.values[index];
if(filter.test(seg.values[index])) return OptionalByte.of(seg.values[index]);
index = (int)seg.links[index];
}
}
@ -1348,7 +1350,7 @@ public class Byte2ByteConcurrentOpenHashMap extends AbstractByte2ByteMap impleme
seg.unlockRead(stamp);
}
}
return (byte)0;
return OptionalByte.empty();
}
@Override

View File

@ -4,6 +4,7 @@ import java.util.Arrays;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.locks.StampedLock;
import java.util.function.Consumer;
import java.util.function.Predicate;
@ -19,6 +20,7 @@ import speiger.src.collections.bytes.functions.consumer.ByteCharConsumer;
import speiger.src.collections.bytes.functions.function.Byte2CharFunction;
import speiger.src.collections.bytes.functions.function.ByteCharUnaryOperator;
import speiger.src.collections.bytes.functions.function.ByteByteUnaryOperator;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.functions.function.BytePredicate;
import speiger.src.collections.bytes.maps.abstracts.AbstractByte2CharMap;
import speiger.src.collections.bytes.maps.interfaces.Byte2CharMap;
@ -37,6 +39,7 @@ import speiger.src.collections.chars.functions.CharConsumer;
import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer;
import speiger.src.collections.objects.functions.consumer.ObjectCharConsumer;
import speiger.src.collections.chars.functions.function.CharPredicate;
import speiger.src.collections.chars.functions.OptionalChar;
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
import speiger.src.collections.objects.sets.AbstractObjectSet;
import speiger.src.collections.objects.sets.ObjectSet;
@ -768,7 +771,7 @@ public class Byte2CharConcurrentOpenHashMap extends AbstractByte2CharMap impleme
}
@Override
public Byte2CharMap.Entry reduce(ObjectObjectUnaryOperator<Byte2CharMap.Entry, Byte2CharMap.Entry> operator) {
public Optional<Byte2CharMap.Entry> reduce(ObjectObjectUnaryOperator<Byte2CharMap.Entry, Byte2CharMap.Entry> operator) {
Objects.requireNonNull(operator);
Byte2CharMap.Entry state = null;
boolean empty = true;
@ -792,11 +795,11 @@ public class Byte2CharConcurrentOpenHashMap extends AbstractByte2CharMap impleme
seg.unlockRead(stamp);
}
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public Byte2CharMap.Entry findFirst(Predicate<Byte2CharMap.Entry> filter) {
public Optional<Byte2CharMap.Entry> findFirst(Predicate<Byte2CharMap.Entry> filter) {
Objects.requireNonNull(filter);
MapEntry entry = new MapEntry();
for(int i = 0,m=segments.length;i<m;i++) {
@ -806,7 +809,7 @@ public class Byte2CharConcurrentOpenHashMap extends AbstractByte2CharMap impleme
try {
while(index != -1) {
entry.set(index, i);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
index = (int)seg.links[index];
}
}
@ -814,7 +817,7 @@ public class Byte2CharConcurrentOpenHashMap extends AbstractByte2CharMap impleme
seg.unlockRead(stamp);
}
}
return null;
return Optional.empty();
}
@Override
@ -1075,7 +1078,7 @@ public class Byte2CharConcurrentOpenHashMap extends AbstractByte2CharMap impleme
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -1099,11 +1102,11 @@ public class Byte2CharConcurrentOpenHashMap extends AbstractByte2CharMap impleme
seg.unlockRead(stamp);
}
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
for(int i = 0,m=segments.length;i<m;i++) {
Segment seg = segments[i];
@ -1111,7 +1114,7 @@ public class Byte2CharConcurrentOpenHashMap extends AbstractByte2CharMap impleme
try {
int index = seg.firstIndex;
while(index != -1){
if(filter.test(seg.keys[index])) return seg.keys[index];
if(filter.test(seg.keys[index])) return OptionalByte.of(seg.keys[index]);
index = (int)seg.links[index];
}
}
@ -1119,7 +1122,7 @@ public class Byte2CharConcurrentOpenHashMap extends AbstractByte2CharMap impleme
seg.unlockRead(stamp);
}
}
return (byte)0;
return OptionalByte.empty();
}
@Override
@ -1310,7 +1313,7 @@ public class Byte2CharConcurrentOpenHashMap extends AbstractByte2CharMap impleme
}
@Override
public char reduce(CharCharUnaryOperator operator) {
public OptionalChar reduce(CharCharUnaryOperator operator) {
Objects.requireNonNull(operator);
char state = (char)0;
boolean empty = true;
@ -1334,20 +1337,20 @@ public class Byte2CharConcurrentOpenHashMap extends AbstractByte2CharMap impleme
seg.unlockRead(stamp);
}
}
return state;
return empty ? OptionalChar.empty() : OptionalChar.of(state);
}
@Override
public char findFirst(CharPredicate filter) {
public OptionalChar findFirst(CharPredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return (char)0;
if(size() <= 0) return OptionalChar.empty();
for(int i = 0,m=segments.length;i<m;i++) {
Segment seg = segments[i];
long stamp = seg.readLock();
try {
int index = seg.firstIndex;
while(index != -1){
if(filter.test(seg.values[index])) return seg.values[index];
if(filter.test(seg.values[index])) return OptionalChar.of(seg.values[index]);
index = (int)seg.links[index];
}
}
@ -1355,7 +1358,7 @@ public class Byte2CharConcurrentOpenHashMap extends AbstractByte2CharMap impleme
seg.unlockRead(stamp);
}
}
return (char)0;
return OptionalChar.empty();
}
@Override

View File

@ -4,11 +4,13 @@ import java.util.Arrays;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.locks.StampedLock;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.function.BiFunction;
import java.util.function.DoublePredicate;
import java.util.OptionalDouble;
import speiger.src.collections.bytes.collections.ByteBidirectionalIterator;
import speiger.src.collections.bytes.functions.ByteConsumer;
@ -20,6 +22,7 @@ import speiger.src.collections.bytes.functions.consumer.ByteDoubleConsumer;
import speiger.src.collections.bytes.functions.function.Byte2DoubleFunction;
import speiger.src.collections.bytes.functions.function.ByteDoubleUnaryOperator;
import speiger.src.collections.bytes.functions.function.ByteByteUnaryOperator;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.functions.function.BytePredicate;
import speiger.src.collections.bytes.maps.abstracts.AbstractByte2DoubleMap;
import speiger.src.collections.bytes.maps.interfaces.Byte2DoubleMap;
@ -768,7 +771,7 @@ public class Byte2DoubleConcurrentOpenHashMap extends AbstractByte2DoubleMap imp
}
@Override
public Byte2DoubleMap.Entry reduce(ObjectObjectUnaryOperator<Byte2DoubleMap.Entry, Byte2DoubleMap.Entry> operator) {
public Optional<Byte2DoubleMap.Entry> reduce(ObjectObjectUnaryOperator<Byte2DoubleMap.Entry, Byte2DoubleMap.Entry> operator) {
Objects.requireNonNull(operator);
Byte2DoubleMap.Entry state = null;
boolean empty = true;
@ -792,11 +795,11 @@ public class Byte2DoubleConcurrentOpenHashMap extends AbstractByte2DoubleMap imp
seg.unlockRead(stamp);
}
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public Byte2DoubleMap.Entry findFirst(Predicate<Byte2DoubleMap.Entry> filter) {
public Optional<Byte2DoubleMap.Entry> findFirst(Predicate<Byte2DoubleMap.Entry> filter) {
Objects.requireNonNull(filter);
MapEntry entry = new MapEntry();
for(int i = 0,m=segments.length;i<m;i++) {
@ -806,7 +809,7 @@ public class Byte2DoubleConcurrentOpenHashMap extends AbstractByte2DoubleMap imp
try {
while(index != -1) {
entry.set(index, i);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
index = (int)seg.links[index];
}
}
@ -814,7 +817,7 @@ public class Byte2DoubleConcurrentOpenHashMap extends AbstractByte2DoubleMap imp
seg.unlockRead(stamp);
}
}
return null;
return Optional.empty();
}
@Override
@ -1075,7 +1078,7 @@ public class Byte2DoubleConcurrentOpenHashMap extends AbstractByte2DoubleMap imp
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -1099,11 +1102,11 @@ public class Byte2DoubleConcurrentOpenHashMap extends AbstractByte2DoubleMap imp
seg.unlockRead(stamp);
}
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
for(int i = 0,m=segments.length;i<m;i++) {
Segment seg = segments[i];
@ -1111,7 +1114,7 @@ public class Byte2DoubleConcurrentOpenHashMap extends AbstractByte2DoubleMap imp
try {
int index = seg.firstIndex;
while(index != -1){
if(filter.test(seg.keys[index])) return seg.keys[index];
if(filter.test(seg.keys[index])) return OptionalByte.of(seg.keys[index]);
index = (int)seg.links[index];
}
}
@ -1119,7 +1122,7 @@ public class Byte2DoubleConcurrentOpenHashMap extends AbstractByte2DoubleMap imp
seg.unlockRead(stamp);
}
}
return (byte)0;
return OptionalByte.empty();
}
@Override
@ -1310,7 +1313,7 @@ public class Byte2DoubleConcurrentOpenHashMap extends AbstractByte2DoubleMap imp
}
@Override
public double reduce(DoubleDoubleUnaryOperator operator) {
public OptionalDouble reduce(DoubleDoubleUnaryOperator operator) {
Objects.requireNonNull(operator);
double state = 0D;
boolean empty = true;
@ -1334,20 +1337,20 @@ public class Byte2DoubleConcurrentOpenHashMap extends AbstractByte2DoubleMap imp
seg.unlockRead(stamp);
}
}
return state;
return empty ? OptionalDouble.empty() : OptionalDouble.of(state);
}
@Override
public double findFirst(DoublePredicate filter) {
public OptionalDouble findFirst(DoublePredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return 0D;
if(size() <= 0) return OptionalDouble.empty();
for(int i = 0,m=segments.length;i<m;i++) {
Segment seg = segments[i];
long stamp = seg.readLock();
try {
int index = seg.firstIndex;
while(index != -1){
if(filter.test(seg.values[index])) return seg.values[index];
if(filter.test(seg.values[index])) return OptionalDouble.of(seg.values[index]);
index = (int)seg.links[index];
}
}
@ -1355,7 +1358,7 @@ public class Byte2DoubleConcurrentOpenHashMap extends AbstractByte2DoubleMap imp
seg.unlockRead(stamp);
}
}
return 0D;
return OptionalDouble.empty();
}
@Override

View File

@ -4,6 +4,7 @@ import java.util.Arrays;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.locks.StampedLock;
import java.util.function.Consumer;
import java.util.function.Predicate;
@ -19,6 +20,7 @@ import speiger.src.collections.bytes.functions.consumer.ByteFloatConsumer;
import speiger.src.collections.bytes.functions.function.Byte2FloatFunction;
import speiger.src.collections.bytes.functions.function.ByteFloatUnaryOperator;
import speiger.src.collections.bytes.functions.function.ByteByteUnaryOperator;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.functions.function.BytePredicate;
import speiger.src.collections.bytes.maps.abstracts.AbstractByte2FloatMap;
import speiger.src.collections.bytes.maps.interfaces.Byte2FloatMap;
@ -37,6 +39,7 @@ import speiger.src.collections.floats.functions.FloatConsumer;
import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer;
import speiger.src.collections.objects.functions.consumer.ObjectFloatConsumer;
import speiger.src.collections.floats.functions.function.FloatPredicate;
import speiger.src.collections.floats.functions.OptionalFloat;
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
import speiger.src.collections.objects.sets.AbstractObjectSet;
import speiger.src.collections.objects.sets.ObjectSet;
@ -768,7 +771,7 @@ public class Byte2FloatConcurrentOpenHashMap extends AbstractByte2FloatMap imple
}
@Override
public Byte2FloatMap.Entry reduce(ObjectObjectUnaryOperator<Byte2FloatMap.Entry, Byte2FloatMap.Entry> operator) {
public Optional<Byte2FloatMap.Entry> reduce(ObjectObjectUnaryOperator<Byte2FloatMap.Entry, Byte2FloatMap.Entry> operator) {
Objects.requireNonNull(operator);
Byte2FloatMap.Entry state = null;
boolean empty = true;
@ -792,11 +795,11 @@ public class Byte2FloatConcurrentOpenHashMap extends AbstractByte2FloatMap imple
seg.unlockRead(stamp);
}
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public Byte2FloatMap.Entry findFirst(Predicate<Byte2FloatMap.Entry> filter) {
public Optional<Byte2FloatMap.Entry> findFirst(Predicate<Byte2FloatMap.Entry> filter) {
Objects.requireNonNull(filter);
MapEntry entry = new MapEntry();
for(int i = 0,m=segments.length;i<m;i++) {
@ -806,7 +809,7 @@ public class Byte2FloatConcurrentOpenHashMap extends AbstractByte2FloatMap imple
try {
while(index != -1) {
entry.set(index, i);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
index = (int)seg.links[index];
}
}
@ -814,7 +817,7 @@ public class Byte2FloatConcurrentOpenHashMap extends AbstractByte2FloatMap imple
seg.unlockRead(stamp);
}
}
return null;
return Optional.empty();
}
@Override
@ -1075,7 +1078,7 @@ public class Byte2FloatConcurrentOpenHashMap extends AbstractByte2FloatMap imple
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -1099,11 +1102,11 @@ public class Byte2FloatConcurrentOpenHashMap extends AbstractByte2FloatMap imple
seg.unlockRead(stamp);
}
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
for(int i = 0,m=segments.length;i<m;i++) {
Segment seg = segments[i];
@ -1111,7 +1114,7 @@ public class Byte2FloatConcurrentOpenHashMap extends AbstractByte2FloatMap imple
try {
int index = seg.firstIndex;
while(index != -1){
if(filter.test(seg.keys[index])) return seg.keys[index];
if(filter.test(seg.keys[index])) return OptionalByte.of(seg.keys[index]);
index = (int)seg.links[index];
}
}
@ -1119,7 +1122,7 @@ public class Byte2FloatConcurrentOpenHashMap extends AbstractByte2FloatMap imple
seg.unlockRead(stamp);
}
}
return (byte)0;
return OptionalByte.empty();
}
@Override
@ -1310,7 +1313,7 @@ public class Byte2FloatConcurrentOpenHashMap extends AbstractByte2FloatMap imple
}
@Override
public float reduce(FloatFloatUnaryOperator operator) {
public OptionalFloat reduce(FloatFloatUnaryOperator operator) {
Objects.requireNonNull(operator);
float state = 0F;
boolean empty = true;
@ -1334,20 +1337,20 @@ public class Byte2FloatConcurrentOpenHashMap extends AbstractByte2FloatMap imple
seg.unlockRead(stamp);
}
}
return state;
return empty ? OptionalFloat.empty() : OptionalFloat.of(state);
}
@Override
public float findFirst(FloatPredicate filter) {
public OptionalFloat findFirst(FloatPredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return 0F;
if(size() <= 0) return OptionalFloat.empty();
for(int i = 0,m=segments.length;i<m;i++) {
Segment seg = segments[i];
long stamp = seg.readLock();
try {
int index = seg.firstIndex;
while(index != -1){
if(filter.test(seg.values[index])) return seg.values[index];
if(filter.test(seg.values[index])) return OptionalFloat.of(seg.values[index]);
index = (int)seg.links[index];
}
}
@ -1355,7 +1358,7 @@ public class Byte2FloatConcurrentOpenHashMap extends AbstractByte2FloatMap imple
seg.unlockRead(stamp);
}
}
return 0F;
return OptionalFloat.empty();
}
@Override

View File

@ -4,11 +4,13 @@ import java.util.Arrays;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.locks.StampedLock;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.function.BiFunction;
import java.util.function.IntPredicate;
import java.util.OptionalInt;
import speiger.src.collections.bytes.collections.ByteBidirectionalIterator;
import speiger.src.collections.bytes.functions.ByteConsumer;
@ -20,6 +22,7 @@ import speiger.src.collections.bytes.functions.consumer.ByteIntConsumer;
import speiger.src.collections.bytes.functions.function.Byte2IntFunction;
import speiger.src.collections.bytes.functions.function.ByteIntUnaryOperator;
import speiger.src.collections.bytes.functions.function.ByteByteUnaryOperator;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.functions.function.BytePredicate;
import speiger.src.collections.bytes.maps.abstracts.AbstractByte2IntMap;
import speiger.src.collections.bytes.maps.interfaces.Byte2IntMap;
@ -768,7 +771,7 @@ public class Byte2IntConcurrentOpenHashMap extends AbstractByte2IntMap implement
}
@Override
public Byte2IntMap.Entry reduce(ObjectObjectUnaryOperator<Byte2IntMap.Entry, Byte2IntMap.Entry> operator) {
public Optional<Byte2IntMap.Entry> reduce(ObjectObjectUnaryOperator<Byte2IntMap.Entry, Byte2IntMap.Entry> operator) {
Objects.requireNonNull(operator);
Byte2IntMap.Entry state = null;
boolean empty = true;
@ -792,11 +795,11 @@ public class Byte2IntConcurrentOpenHashMap extends AbstractByte2IntMap implement
seg.unlockRead(stamp);
}
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public Byte2IntMap.Entry findFirst(Predicate<Byte2IntMap.Entry> filter) {
public Optional<Byte2IntMap.Entry> findFirst(Predicate<Byte2IntMap.Entry> filter) {
Objects.requireNonNull(filter);
MapEntry entry = new MapEntry();
for(int i = 0,m=segments.length;i<m;i++) {
@ -806,7 +809,7 @@ public class Byte2IntConcurrentOpenHashMap extends AbstractByte2IntMap implement
try {
while(index != -1) {
entry.set(index, i);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
index = (int)seg.links[index];
}
}
@ -814,7 +817,7 @@ public class Byte2IntConcurrentOpenHashMap extends AbstractByte2IntMap implement
seg.unlockRead(stamp);
}
}
return null;
return Optional.empty();
}
@Override
@ -1075,7 +1078,7 @@ public class Byte2IntConcurrentOpenHashMap extends AbstractByte2IntMap implement
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -1099,11 +1102,11 @@ public class Byte2IntConcurrentOpenHashMap extends AbstractByte2IntMap implement
seg.unlockRead(stamp);
}
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
for(int i = 0,m=segments.length;i<m;i++) {
Segment seg = segments[i];
@ -1111,7 +1114,7 @@ public class Byte2IntConcurrentOpenHashMap extends AbstractByte2IntMap implement
try {
int index = seg.firstIndex;
while(index != -1){
if(filter.test(seg.keys[index])) return seg.keys[index];
if(filter.test(seg.keys[index])) return OptionalByte.of(seg.keys[index]);
index = (int)seg.links[index];
}
}
@ -1119,7 +1122,7 @@ public class Byte2IntConcurrentOpenHashMap extends AbstractByte2IntMap implement
seg.unlockRead(stamp);
}
}
return (byte)0;
return OptionalByte.empty();
}
@Override
@ -1310,7 +1313,7 @@ public class Byte2IntConcurrentOpenHashMap extends AbstractByte2IntMap implement
}
@Override
public int reduce(IntIntUnaryOperator operator) {
public OptionalInt reduce(IntIntUnaryOperator operator) {
Objects.requireNonNull(operator);
int state = 0;
boolean empty = true;
@ -1334,20 +1337,20 @@ public class Byte2IntConcurrentOpenHashMap extends AbstractByte2IntMap implement
seg.unlockRead(stamp);
}
}
return state;
return empty ? OptionalInt.empty() : OptionalInt.of(state);
}
@Override
public int findFirst(IntPredicate filter) {
public OptionalInt findFirst(IntPredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return 0;
if(size() <= 0) return OptionalInt.empty();
for(int i = 0,m=segments.length;i<m;i++) {
Segment seg = segments[i];
long stamp = seg.readLock();
try {
int index = seg.firstIndex;
while(index != -1){
if(filter.test(seg.values[index])) return seg.values[index];
if(filter.test(seg.values[index])) return OptionalInt.of(seg.values[index]);
index = (int)seg.links[index];
}
}
@ -1355,7 +1358,7 @@ public class Byte2IntConcurrentOpenHashMap extends AbstractByte2IntMap implement
seg.unlockRead(stamp);
}
}
return 0;
return OptionalInt.empty();
}
@Override

View File

@ -4,11 +4,13 @@ import java.util.Arrays;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.locks.StampedLock;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.function.BiFunction;
import java.util.function.LongPredicate;
import java.util.OptionalLong;
import speiger.src.collections.bytes.collections.ByteBidirectionalIterator;
import speiger.src.collections.bytes.functions.ByteConsumer;
@ -20,6 +22,7 @@ import speiger.src.collections.bytes.functions.consumer.ByteLongConsumer;
import speiger.src.collections.bytes.functions.function.Byte2LongFunction;
import speiger.src.collections.bytes.functions.function.ByteLongUnaryOperator;
import speiger.src.collections.bytes.functions.function.ByteByteUnaryOperator;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.functions.function.BytePredicate;
import speiger.src.collections.bytes.maps.abstracts.AbstractByte2LongMap;
import speiger.src.collections.bytes.maps.interfaces.Byte2LongMap;
@ -768,7 +771,7 @@ public class Byte2LongConcurrentOpenHashMap extends AbstractByte2LongMap impleme
}
@Override
public Byte2LongMap.Entry reduce(ObjectObjectUnaryOperator<Byte2LongMap.Entry, Byte2LongMap.Entry> operator) {
public Optional<Byte2LongMap.Entry> reduce(ObjectObjectUnaryOperator<Byte2LongMap.Entry, Byte2LongMap.Entry> operator) {
Objects.requireNonNull(operator);
Byte2LongMap.Entry state = null;
boolean empty = true;
@ -792,11 +795,11 @@ public class Byte2LongConcurrentOpenHashMap extends AbstractByte2LongMap impleme
seg.unlockRead(stamp);
}
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public Byte2LongMap.Entry findFirst(Predicate<Byte2LongMap.Entry> filter) {
public Optional<Byte2LongMap.Entry> findFirst(Predicate<Byte2LongMap.Entry> filter) {
Objects.requireNonNull(filter);
MapEntry entry = new MapEntry();
for(int i = 0,m=segments.length;i<m;i++) {
@ -806,7 +809,7 @@ public class Byte2LongConcurrentOpenHashMap extends AbstractByte2LongMap impleme
try {
while(index != -1) {
entry.set(index, i);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
index = (int)seg.links[index];
}
}
@ -814,7 +817,7 @@ public class Byte2LongConcurrentOpenHashMap extends AbstractByte2LongMap impleme
seg.unlockRead(stamp);
}
}
return null;
return Optional.empty();
}
@Override
@ -1075,7 +1078,7 @@ public class Byte2LongConcurrentOpenHashMap extends AbstractByte2LongMap impleme
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -1099,11 +1102,11 @@ public class Byte2LongConcurrentOpenHashMap extends AbstractByte2LongMap impleme
seg.unlockRead(stamp);
}
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
for(int i = 0,m=segments.length;i<m;i++) {
Segment seg = segments[i];
@ -1111,7 +1114,7 @@ public class Byte2LongConcurrentOpenHashMap extends AbstractByte2LongMap impleme
try {
int index = seg.firstIndex;
while(index != -1){
if(filter.test(seg.keys[index])) return seg.keys[index];
if(filter.test(seg.keys[index])) return OptionalByte.of(seg.keys[index]);
index = (int)seg.links[index];
}
}
@ -1119,7 +1122,7 @@ public class Byte2LongConcurrentOpenHashMap extends AbstractByte2LongMap impleme
seg.unlockRead(stamp);
}
}
return (byte)0;
return OptionalByte.empty();
}
@Override
@ -1310,7 +1313,7 @@ public class Byte2LongConcurrentOpenHashMap extends AbstractByte2LongMap impleme
}
@Override
public long reduce(LongLongUnaryOperator operator) {
public OptionalLong reduce(LongLongUnaryOperator operator) {
Objects.requireNonNull(operator);
long state = 0L;
boolean empty = true;
@ -1334,20 +1337,20 @@ public class Byte2LongConcurrentOpenHashMap extends AbstractByte2LongMap impleme
seg.unlockRead(stamp);
}
}
return state;
return empty ? OptionalLong.empty() : OptionalLong.of(state);
}
@Override
public long findFirst(LongPredicate filter) {
public OptionalLong findFirst(LongPredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return 0L;
if(size() <= 0) return OptionalLong.empty();
for(int i = 0,m=segments.length;i<m;i++) {
Segment seg = segments[i];
long stamp = seg.readLock();
try {
int index = seg.firstIndex;
while(index != -1){
if(filter.test(seg.values[index])) return seg.values[index];
if(filter.test(seg.values[index])) return OptionalLong.of(seg.values[index]);
index = (int)seg.links[index];
}
}
@ -1355,7 +1358,7 @@ public class Byte2LongConcurrentOpenHashMap extends AbstractByte2LongMap impleme
seg.unlockRead(stamp);
}
}
return 0L;
return OptionalLong.empty();
}
@Override

View File

@ -4,6 +4,7 @@ import java.util.Arrays;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.locks.StampedLock;
import java.util.function.Consumer;
import java.util.function.Predicate;
@ -18,6 +19,7 @@ import speiger.src.collections.bytes.functions.consumer.ByteObjectConsumer;
import speiger.src.collections.bytes.functions.function.ByteFunction;
import speiger.src.collections.bytes.functions.function.ByteObjectUnaryOperator;
import speiger.src.collections.bytes.functions.function.ByteByteUnaryOperator;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.functions.function.BytePredicate;
import speiger.src.collections.bytes.maps.abstracts.AbstractByte2ObjectMap;
import speiger.src.collections.bytes.maps.interfaces.Byte2ObjectMap;
@ -715,7 +717,7 @@ public class Byte2ObjectConcurrentOpenHashMap<V> extends AbstractByte2ObjectMap<
}
@Override
public Byte2ObjectMap.Entry<V> reduce(ObjectObjectUnaryOperator<Byte2ObjectMap.Entry<V>, Byte2ObjectMap.Entry<V>> operator) {
public Optional<Byte2ObjectMap.Entry<V>> reduce(ObjectObjectUnaryOperator<Byte2ObjectMap.Entry<V>, Byte2ObjectMap.Entry<V>> operator) {
Objects.requireNonNull(operator);
Byte2ObjectMap.Entry<V> state = null;
boolean empty = true;
@ -739,11 +741,11 @@ public class Byte2ObjectConcurrentOpenHashMap<V> extends AbstractByte2ObjectMap<
seg.unlockRead(stamp);
}
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public Byte2ObjectMap.Entry<V> findFirst(Predicate<Byte2ObjectMap.Entry<V>> filter) {
public Optional<Byte2ObjectMap.Entry<V>> findFirst(Predicate<Byte2ObjectMap.Entry<V>> filter) {
Objects.requireNonNull(filter);
MapEntry entry = new MapEntry();
for(int i = 0,m=segments.length;i<m;i++) {
@ -753,7 +755,7 @@ public class Byte2ObjectConcurrentOpenHashMap<V> extends AbstractByte2ObjectMap<
try {
while(index != -1) {
entry.set(index, i);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
index = (int)seg.links[index];
}
}
@ -761,7 +763,7 @@ public class Byte2ObjectConcurrentOpenHashMap<V> extends AbstractByte2ObjectMap<
seg.unlockRead(stamp);
}
}
return null;
return Optional.empty();
}
@Override
@ -1022,7 +1024,7 @@ public class Byte2ObjectConcurrentOpenHashMap<V> extends AbstractByte2ObjectMap<
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -1046,11 +1048,11 @@ public class Byte2ObjectConcurrentOpenHashMap<V> extends AbstractByte2ObjectMap<
seg.unlockRead(stamp);
}
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
for(int i = 0,m=segments.length;i<m;i++) {
Segment<V> seg = segments[i];
@ -1058,7 +1060,7 @@ public class Byte2ObjectConcurrentOpenHashMap<V> extends AbstractByte2ObjectMap<
try {
int index = seg.firstIndex;
while(index != -1){
if(filter.test(seg.keys[index])) return seg.keys[index];
if(filter.test(seg.keys[index])) return OptionalByte.of(seg.keys[index]);
index = (int)seg.links[index];
}
}
@ -1066,7 +1068,7 @@ public class Byte2ObjectConcurrentOpenHashMap<V> extends AbstractByte2ObjectMap<
seg.unlockRead(stamp);
}
}
return (byte)0;
return OptionalByte.empty();
}
@Override
@ -1258,7 +1260,7 @@ public class Byte2ObjectConcurrentOpenHashMap<V> extends AbstractByte2ObjectMap<
}
@Override
public V reduce(ObjectObjectUnaryOperator<V, V> operator) {
public Optional<V> reduce(ObjectObjectUnaryOperator<V, V> operator) {
Objects.requireNonNull(operator);
V state = null;
boolean empty = true;
@ -1282,20 +1284,20 @@ public class Byte2ObjectConcurrentOpenHashMap<V> extends AbstractByte2ObjectMap<
seg.unlockRead(stamp);
}
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public V findFirst(Predicate<V> filter) {
public Optional<V> findFirst(Predicate<V> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return null;
if(size() <= 0) return Optional.empty();
for(int i = 0,m=segments.length;i<m;i++) {
Segment<V> seg = segments[i];
long stamp = seg.readLock();
try {
int index = seg.firstIndex;
while(index != -1){
if(filter.test(seg.values[index])) return seg.values[index];
if(filter.test(seg.values[index])) return Optional.ofNullable(seg.values[index]);
index = (int)seg.links[index];
}
}
@ -1303,7 +1305,7 @@ public class Byte2ObjectConcurrentOpenHashMap<V> extends AbstractByte2ObjectMap<
seg.unlockRead(stamp);
}
}
return null;
return Optional.empty();
}
@Override

View File

@ -4,6 +4,7 @@ import java.util.Arrays;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.locks.StampedLock;
import java.util.function.Consumer;
import java.util.function.Predicate;
@ -19,6 +20,7 @@ import speiger.src.collections.bytes.functions.consumer.ByteShortConsumer;
import speiger.src.collections.bytes.functions.function.Byte2ShortFunction;
import speiger.src.collections.bytes.functions.function.ByteShortUnaryOperator;
import speiger.src.collections.bytes.functions.function.ByteByteUnaryOperator;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.functions.function.BytePredicate;
import speiger.src.collections.bytes.maps.abstracts.AbstractByte2ShortMap;
import speiger.src.collections.bytes.maps.interfaces.Byte2ShortMap;
@ -37,6 +39,7 @@ import speiger.src.collections.shorts.functions.ShortConsumer;
import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer;
import speiger.src.collections.objects.functions.consumer.ObjectShortConsumer;
import speiger.src.collections.shorts.functions.function.ShortPredicate;
import speiger.src.collections.shorts.functions.OptionalShort;
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
import speiger.src.collections.objects.sets.AbstractObjectSet;
import speiger.src.collections.objects.sets.ObjectSet;
@ -768,7 +771,7 @@ public class Byte2ShortConcurrentOpenHashMap extends AbstractByte2ShortMap imple
}
@Override
public Byte2ShortMap.Entry reduce(ObjectObjectUnaryOperator<Byte2ShortMap.Entry, Byte2ShortMap.Entry> operator) {
public Optional<Byte2ShortMap.Entry> reduce(ObjectObjectUnaryOperator<Byte2ShortMap.Entry, Byte2ShortMap.Entry> operator) {
Objects.requireNonNull(operator);
Byte2ShortMap.Entry state = null;
boolean empty = true;
@ -792,11 +795,11 @@ public class Byte2ShortConcurrentOpenHashMap extends AbstractByte2ShortMap imple
seg.unlockRead(stamp);
}
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public Byte2ShortMap.Entry findFirst(Predicate<Byte2ShortMap.Entry> filter) {
public Optional<Byte2ShortMap.Entry> findFirst(Predicate<Byte2ShortMap.Entry> filter) {
Objects.requireNonNull(filter);
MapEntry entry = new MapEntry();
for(int i = 0,m=segments.length;i<m;i++) {
@ -806,7 +809,7 @@ public class Byte2ShortConcurrentOpenHashMap extends AbstractByte2ShortMap imple
try {
while(index != -1) {
entry.set(index, i);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
index = (int)seg.links[index];
}
}
@ -814,7 +817,7 @@ public class Byte2ShortConcurrentOpenHashMap extends AbstractByte2ShortMap imple
seg.unlockRead(stamp);
}
}
return null;
return Optional.empty();
}
@Override
@ -1075,7 +1078,7 @@ public class Byte2ShortConcurrentOpenHashMap extends AbstractByte2ShortMap imple
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -1099,11 +1102,11 @@ public class Byte2ShortConcurrentOpenHashMap extends AbstractByte2ShortMap imple
seg.unlockRead(stamp);
}
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
for(int i = 0,m=segments.length;i<m;i++) {
Segment seg = segments[i];
@ -1111,7 +1114,7 @@ public class Byte2ShortConcurrentOpenHashMap extends AbstractByte2ShortMap imple
try {
int index = seg.firstIndex;
while(index != -1){
if(filter.test(seg.keys[index])) return seg.keys[index];
if(filter.test(seg.keys[index])) return OptionalByte.of(seg.keys[index]);
index = (int)seg.links[index];
}
}
@ -1119,7 +1122,7 @@ public class Byte2ShortConcurrentOpenHashMap extends AbstractByte2ShortMap imple
seg.unlockRead(stamp);
}
}
return (byte)0;
return OptionalByte.empty();
}
@Override
@ -1310,7 +1313,7 @@ public class Byte2ShortConcurrentOpenHashMap extends AbstractByte2ShortMap imple
}
@Override
public short reduce(ShortShortUnaryOperator operator) {
public OptionalShort reduce(ShortShortUnaryOperator operator) {
Objects.requireNonNull(operator);
short state = (short)0;
boolean empty = true;
@ -1334,20 +1337,20 @@ public class Byte2ShortConcurrentOpenHashMap extends AbstractByte2ShortMap imple
seg.unlockRead(stamp);
}
}
return state;
return empty ? OptionalShort.empty() : OptionalShort.of(state);
}
@Override
public short findFirst(ShortPredicate filter) {
public OptionalShort findFirst(ShortPredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return (short)0;
if(size() <= 0) return OptionalShort.empty();
for(int i = 0,m=segments.length;i<m;i++) {
Segment seg = segments[i];
long stamp = seg.readLock();
try {
int index = seg.firstIndex;
while(index != -1){
if(filter.test(seg.values[index])) return seg.values[index];
if(filter.test(seg.values[index])) return OptionalShort.of(seg.values[index]);
index = (int)seg.links[index];
}
}
@ -1355,7 +1358,7 @@ public class Byte2ShortConcurrentOpenHashMap extends AbstractByte2ShortMap imple
seg.unlockRead(stamp);
}
}
return (short)0;
return OptionalShort.empty();
}
@Override

View File

@ -4,6 +4,7 @@ import java.util.Arrays;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.BiFunction;
import java.util.function.Predicate;
@ -14,6 +15,7 @@ import speiger.src.collections.objects.functions.consumer.ObjectByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
import speiger.src.collections.ints.functions.consumer.IntBooleanConsumer;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.functions.function.BytePredicate;
import speiger.src.collections.bytes.functions.consumer.ByteBooleanConsumer;
import speiger.src.collections.bytes.functions.function.ByteByteUnaryOperator;
@ -33,6 +35,7 @@ import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer;
import speiger.src.collections.objects.functions.consumer.ObjectBooleanConsumer;
import speiger.src.collections.booleans.functions.function.BooleanPredicate;
import speiger.src.collections.booleans.functions.OptionalBoolean;
import speiger.src.collections.objects.functions.function.ObjectObjectUnaryOperator;
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
import speiger.src.collections.objects.lists.ObjectListIterator;
@ -671,6 +674,10 @@ public class Byte2BooleanLinkedOpenCustomHashMap extends Byte2BooleanOpenCustomH
}
private class MapEntrySet extends AbstractObjectSet<Byte2BooleanMap.Entry> implements Byte2BooleanOrderedMap.FastOrderedSet {
@Override
public void addFirst(Byte2BooleanMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(Byte2BooleanMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(Byte2BooleanMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
@ -836,7 +843,7 @@ public class Byte2BooleanLinkedOpenCustomHashMap extends Byte2BooleanOpenCustomH
}
@Override
public Byte2BooleanMap.Entry reduce(ObjectObjectUnaryOperator<Byte2BooleanMap.Entry, Byte2BooleanMap.Entry> operator) {
public Optional<Byte2BooleanMap.Entry> reduce(ObjectObjectUnaryOperator<Byte2BooleanMap.Entry, Byte2BooleanMap.Entry> operator) {
Objects.requireNonNull(operator);
Byte2BooleanMap.Entry state = null;
boolean empty = true;
@ -851,21 +858,21 @@ public class Byte2BooleanLinkedOpenCustomHashMap extends Byte2BooleanOpenCustomH
state = operator.apply(state, new ValueMapEntry(index));
index = (int)links[index];
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public Byte2BooleanMap.Entry findFirst(Predicate<Byte2BooleanMap.Entry> filter) {
public Optional<Byte2BooleanMap.Entry> findFirst(Predicate<Byte2BooleanMap.Entry> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return null;
if(size() <= 0) return Optional.empty();
MapEntry entry = new MapEntry();
int index = firstIndex;
while(index != -1) {
entry.set(index);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
index = (int)links[index];
}
return null;
return Optional.empty();
}
@Override
@ -944,10 +951,13 @@ public class Byte2BooleanLinkedOpenCustomHashMap extends Byte2BooleanOpenCustomH
public boolean add(byte o) {
throw new UnsupportedOperationException();
}
@Override
public void addFirst(byte o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(byte o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(byte o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToLast(byte o) { throw new UnsupportedOperationException(); }
@ -1090,7 +1100,7 @@ public class Byte2BooleanLinkedOpenCustomHashMap extends Byte2BooleanOpenCustomH
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -1105,19 +1115,19 @@ public class Byte2BooleanLinkedOpenCustomHashMap extends Byte2BooleanOpenCustomH
state = operator.applyAsByte(state, keys[index]);
index = (int)links[index];
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return (byte)0;
if(size() <= 0) return OptionalByte.empty();
int index = firstIndex;
while(index != -1){
if(filter.test(keys[index])) return keys[index];
if(filter.test(keys[index])) return OptionalByte.of(keys[index]);
index = (int)links[index];
}
return (byte)0;
return OptionalByte.empty();
}
@Override
@ -1252,7 +1262,7 @@ public class Byte2BooleanLinkedOpenCustomHashMap extends Byte2BooleanOpenCustomH
}
@Override
public boolean reduce(BooleanBooleanUnaryOperator operator) {
public OptionalBoolean reduce(BooleanBooleanUnaryOperator operator) {
Objects.requireNonNull(operator);
boolean state = false;
boolean empty = true;
@ -1267,19 +1277,19 @@ public class Byte2BooleanLinkedOpenCustomHashMap extends Byte2BooleanOpenCustomH
state = operator.applyAsBoolean(state, values[index]);
index = (int)links[index];
}
return state;
return empty ? OptionalBoolean.empty() : OptionalBoolean.of(state);
}
@Override
public boolean findFirst(BooleanPredicate filter) {
public OptionalBoolean findFirst(BooleanPredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return false;
if(size() <= 0) return OptionalBoolean.empty();
int index = firstIndex;
while(index != -1){
if(filter.test(values[index])) return values[index];
if(filter.test(values[index])) return OptionalBoolean.of(values[index]);
index = (int)links[index];
}
return false;
return OptionalBoolean.empty();
}
@Override

View File

@ -5,6 +5,7 @@ import java.util.ConcurrentModificationException;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.BiFunction;
import java.util.function.Predicate;
@ -19,6 +20,7 @@ import speiger.src.collections.bytes.functions.consumer.ByteBooleanConsumer;
import speiger.src.collections.bytes.functions.function.BytePredicate;
import speiger.src.collections.bytes.functions.function.ByteBooleanUnaryOperator;
import speiger.src.collections.bytes.functions.function.ByteByteUnaryOperator;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.maps.abstracts.AbstractByte2BooleanMap;
import speiger.src.collections.bytes.maps.interfaces.Byte2BooleanMap;
import speiger.src.collections.bytes.sets.AbstractByteSet;
@ -36,6 +38,7 @@ import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer;
import speiger.src.collections.objects.functions.consumer.ObjectBooleanConsumer;
import speiger.src.collections.booleans.functions.function.BooleanPredicate;
import speiger.src.collections.booleans.functions.OptionalBoolean;
import speiger.src.collections.objects.collections.ObjectIterator;
import speiger.src.collections.objects.sets.AbstractObjectSet;
import speiger.src.collections.objects.sets.ObjectSet;
@ -930,7 +933,7 @@ public class Byte2BooleanOpenCustomHashMap extends AbstractByte2BooleanMap imple
}
@Override
public Byte2BooleanMap.Entry reduce(ObjectObjectUnaryOperator<Byte2BooleanMap.Entry, Byte2BooleanMap.Entry> operator) {
public Optional<Byte2BooleanMap.Entry> reduce(ObjectObjectUnaryOperator<Byte2BooleanMap.Entry, Byte2BooleanMap.Entry> operator) {
Objects.requireNonNull(operator);
Byte2BooleanMap.Entry state = null;
boolean empty = true;
@ -947,25 +950,25 @@ public class Byte2BooleanOpenCustomHashMap extends AbstractByte2BooleanMap imple
}
state = operator.apply(state, new ValueMapEntry(i));
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public Byte2BooleanMap.Entry findFirst(Predicate<Byte2BooleanMap.Entry> filter) {
public Optional<Byte2BooleanMap.Entry> findFirst(Predicate<Byte2BooleanMap.Entry> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return null;
if(size() <= 0) return Optional.empty();
MapEntry entry = new MapEntry();
if(containsNull) {
entry.set(nullIndex);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
}
for(int i = nullIndex-1;i>=0;i--) {
if(!strategy.equals(keys[i], (byte)0)) {
entry.set(i);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
}
}
return null;
return Optional.empty();
}
@Override
@ -1139,7 +1142,7 @@ public class Byte2BooleanOpenCustomHashMap extends AbstractByte2BooleanMap imple
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -1156,18 +1159,18 @@ public class Byte2BooleanOpenCustomHashMap extends AbstractByte2BooleanMap imple
}
state = operator.applyAsByte(state, keys[i]);
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return (byte)0;
if(containsNull && filter.test(keys[nullIndex])) return keys[nullIndex];
if(size() <= 0) return OptionalByte.empty();
if(containsNull && filter.test(keys[nullIndex])) return OptionalByte.of(keys[nullIndex]);
for(int i = nullIndex-1;i>=0;i--) {
if(!strategy.equals(keys[i], (byte)0) && filter.test(keys[i])) return keys[i];
if(!strategy.equals(keys[i], (byte)0) && filter.test(keys[i])) return OptionalByte.of(keys[i]);
}
return (byte)0;
return OptionalByte.empty();
}
@Override
@ -1282,7 +1285,7 @@ public class Byte2BooleanOpenCustomHashMap extends AbstractByte2BooleanMap imple
}
@Override
public boolean reduce(BooleanBooleanUnaryOperator operator) {
public OptionalBoolean reduce(BooleanBooleanUnaryOperator operator) {
Objects.requireNonNull(operator);
boolean state = false;
boolean empty = true;
@ -1299,18 +1302,18 @@ public class Byte2BooleanOpenCustomHashMap extends AbstractByte2BooleanMap imple
}
state = operator.applyAsBoolean(state, values[i]);
}
return state;
return empty ? OptionalBoolean.empty() : OptionalBoolean.of(state);
}
@Override
public boolean findFirst(BooleanPredicate filter) {
public OptionalBoolean findFirst(BooleanPredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return false;
if(containsNull && filter.test(values[nullIndex])) return values[nullIndex];
if(size() <= 0) return OptionalBoolean.empty();
if(containsNull && filter.test(values[nullIndex])) return OptionalBoolean.of(values[nullIndex]);
for(int i = nullIndex-1;i>=0;i--) {
if(!strategy.equals(keys[i], (byte)0) && filter.test(values[i])) return values[i];
if(!strategy.equals(keys[i], (byte)0) && filter.test(values[i])) return OptionalBoolean.of(values[i]);
}
return false;
return OptionalBoolean.empty();
}
@Override

View File

@ -4,6 +4,7 @@ import java.util.Arrays;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.BiFunction;
import java.util.function.Predicate;
@ -13,6 +14,7 @@ import speiger.src.collections.bytes.functions.ByteConsumer;
import speiger.src.collections.objects.functions.consumer.ObjectByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.functions.function.BytePredicate;
import speiger.src.collections.bytes.functions.consumer.ByteByteConsumer;
import speiger.src.collections.bytes.functions.function.ByteByteUnaryOperator;
@ -664,6 +666,10 @@ public class Byte2ByteLinkedOpenCustomHashMap extends Byte2ByteOpenCustomHashMap
}
private class MapEntrySet extends AbstractObjectSet<Byte2ByteMap.Entry> implements Byte2ByteOrderedMap.FastOrderedSet {
@Override
public void addFirst(Byte2ByteMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(Byte2ByteMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(Byte2ByteMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
@ -829,7 +835,7 @@ public class Byte2ByteLinkedOpenCustomHashMap extends Byte2ByteOpenCustomHashMap
}
@Override
public Byte2ByteMap.Entry reduce(ObjectObjectUnaryOperator<Byte2ByteMap.Entry, Byte2ByteMap.Entry> operator) {
public Optional<Byte2ByteMap.Entry> reduce(ObjectObjectUnaryOperator<Byte2ByteMap.Entry, Byte2ByteMap.Entry> operator) {
Objects.requireNonNull(operator);
Byte2ByteMap.Entry state = null;
boolean empty = true;
@ -844,21 +850,21 @@ public class Byte2ByteLinkedOpenCustomHashMap extends Byte2ByteOpenCustomHashMap
state = operator.apply(state, new ValueMapEntry(index));
index = (int)links[index];
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public Byte2ByteMap.Entry findFirst(Predicate<Byte2ByteMap.Entry> filter) {
public Optional<Byte2ByteMap.Entry> findFirst(Predicate<Byte2ByteMap.Entry> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return null;
if(size() <= 0) return Optional.empty();
MapEntry entry = new MapEntry();
int index = firstIndex;
while(index != -1) {
entry.set(index);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
index = (int)links[index];
}
return null;
return Optional.empty();
}
@Override
@ -937,10 +943,13 @@ public class Byte2ByteLinkedOpenCustomHashMap extends Byte2ByteOpenCustomHashMap
public boolean add(byte o) {
throw new UnsupportedOperationException();
}
@Override
public void addFirst(byte o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(byte o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(byte o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToLast(byte o) { throw new UnsupportedOperationException(); }
@ -1083,7 +1092,7 @@ public class Byte2ByteLinkedOpenCustomHashMap extends Byte2ByteOpenCustomHashMap
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -1098,19 +1107,19 @@ public class Byte2ByteLinkedOpenCustomHashMap extends Byte2ByteOpenCustomHashMap
state = operator.applyAsByte(state, keys[index]);
index = (int)links[index];
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return (byte)0;
if(size() <= 0) return OptionalByte.empty();
int index = firstIndex;
while(index != -1){
if(filter.test(keys[index])) return keys[index];
if(filter.test(keys[index])) return OptionalByte.of(keys[index]);
index = (int)links[index];
}
return (byte)0;
return OptionalByte.empty();
}
@Override
@ -1245,7 +1254,7 @@ public class Byte2ByteLinkedOpenCustomHashMap extends Byte2ByteOpenCustomHashMap
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -1260,19 +1269,19 @@ public class Byte2ByteLinkedOpenCustomHashMap extends Byte2ByteOpenCustomHashMap
state = operator.applyAsByte(state, values[index]);
index = (int)links[index];
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return (byte)0;
if(size() <= 0) return OptionalByte.empty();
int index = firstIndex;
while(index != -1){
if(filter.test(values[index])) return values[index];
if(filter.test(values[index])) return OptionalByte.of(values[index]);
index = (int)links[index];
}
return (byte)0;
return OptionalByte.empty();
}
@Override

View File

@ -5,6 +5,7 @@ import java.util.ConcurrentModificationException;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.BiFunction;
import java.util.function.Predicate;
@ -17,6 +18,7 @@ import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
import speiger.src.collections.bytes.functions.consumer.ByteByteConsumer;
import speiger.src.collections.bytes.functions.function.ByteUnaryOperator;
import speiger.src.collections.bytes.functions.function.ByteByteUnaryOperator;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.functions.function.BytePredicate;
import speiger.src.collections.bytes.maps.abstracts.AbstractByte2ByteMap;
import speiger.src.collections.bytes.maps.interfaces.Byte2ByteMap;
@ -944,7 +946,7 @@ public class Byte2ByteOpenCustomHashMap extends AbstractByte2ByteMap implements
}
@Override
public Byte2ByteMap.Entry reduce(ObjectObjectUnaryOperator<Byte2ByteMap.Entry, Byte2ByteMap.Entry> operator) {
public Optional<Byte2ByteMap.Entry> reduce(ObjectObjectUnaryOperator<Byte2ByteMap.Entry, Byte2ByteMap.Entry> operator) {
Objects.requireNonNull(operator);
Byte2ByteMap.Entry state = null;
boolean empty = true;
@ -961,25 +963,25 @@ public class Byte2ByteOpenCustomHashMap extends AbstractByte2ByteMap implements
}
state = operator.apply(state, new ValueMapEntry(i));
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public Byte2ByteMap.Entry findFirst(Predicate<Byte2ByteMap.Entry> filter) {
public Optional<Byte2ByteMap.Entry> findFirst(Predicate<Byte2ByteMap.Entry> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return null;
if(size() <= 0) return Optional.empty();
MapEntry entry = new MapEntry();
if(containsNull) {
entry.set(nullIndex);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
}
for(int i = nullIndex-1;i>=0;i--) {
if(!strategy.equals(keys[i], (byte)0)) {
entry.set(i);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
}
}
return null;
return Optional.empty();
}
@Override
@ -1153,7 +1155,7 @@ public class Byte2ByteOpenCustomHashMap extends AbstractByte2ByteMap implements
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -1170,18 +1172,18 @@ public class Byte2ByteOpenCustomHashMap extends AbstractByte2ByteMap implements
}
state = operator.applyAsByte(state, keys[i]);
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return (byte)0;
if(containsNull && filter.test(keys[nullIndex])) return keys[nullIndex];
if(size() <= 0) return OptionalByte.empty();
if(containsNull && filter.test(keys[nullIndex])) return OptionalByte.of(keys[nullIndex]);
for(int i = nullIndex-1;i>=0;i--) {
if(!strategy.equals(keys[i], (byte)0) && filter.test(keys[i])) return keys[i];
if(!strategy.equals(keys[i], (byte)0) && filter.test(keys[i])) return OptionalByte.of(keys[i]);
}
return (byte)0;
return OptionalByte.empty();
}
@Override
@ -1296,7 +1298,7 @@ public class Byte2ByteOpenCustomHashMap extends AbstractByte2ByteMap implements
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -1313,18 +1315,18 @@ public class Byte2ByteOpenCustomHashMap extends AbstractByte2ByteMap implements
}
state = operator.applyAsByte(state, values[i]);
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return (byte)0;
if(containsNull && filter.test(values[nullIndex])) return values[nullIndex];
if(size() <= 0) return OptionalByte.empty();
if(containsNull && filter.test(values[nullIndex])) return OptionalByte.of(values[nullIndex]);
for(int i = nullIndex-1;i>=0;i--) {
if(!strategy.equals(keys[i], (byte)0) && filter.test(values[i])) return values[i];
if(!strategy.equals(keys[i], (byte)0) && filter.test(values[i])) return OptionalByte.of(values[i]);
}
return (byte)0;
return OptionalByte.empty();
}
@Override

View File

@ -4,6 +4,7 @@ import java.util.Arrays;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.BiFunction;
import java.util.function.Predicate;
@ -14,6 +15,7 @@ import speiger.src.collections.objects.functions.consumer.ObjectByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
import speiger.src.collections.ints.functions.consumer.IntCharConsumer;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.functions.function.BytePredicate;
import speiger.src.collections.bytes.functions.consumer.ByteCharConsumer;
import speiger.src.collections.bytes.functions.function.ByteByteUnaryOperator;
@ -33,6 +35,7 @@ import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer;
import speiger.src.collections.objects.functions.consumer.ObjectCharConsumer;
import speiger.src.collections.chars.functions.function.CharPredicate;
import speiger.src.collections.chars.functions.OptionalChar;
import speiger.src.collections.objects.functions.function.ObjectObjectUnaryOperator;
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
import speiger.src.collections.objects.lists.ObjectListIterator;
@ -671,6 +674,10 @@ public class Byte2CharLinkedOpenCustomHashMap extends Byte2CharOpenCustomHashMap
}
private class MapEntrySet extends AbstractObjectSet<Byte2CharMap.Entry> implements Byte2CharOrderedMap.FastOrderedSet {
@Override
public void addFirst(Byte2CharMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(Byte2CharMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(Byte2CharMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
@ -836,7 +843,7 @@ public class Byte2CharLinkedOpenCustomHashMap extends Byte2CharOpenCustomHashMap
}
@Override
public Byte2CharMap.Entry reduce(ObjectObjectUnaryOperator<Byte2CharMap.Entry, Byte2CharMap.Entry> operator) {
public Optional<Byte2CharMap.Entry> reduce(ObjectObjectUnaryOperator<Byte2CharMap.Entry, Byte2CharMap.Entry> operator) {
Objects.requireNonNull(operator);
Byte2CharMap.Entry state = null;
boolean empty = true;
@ -851,21 +858,21 @@ public class Byte2CharLinkedOpenCustomHashMap extends Byte2CharOpenCustomHashMap
state = operator.apply(state, new ValueMapEntry(index));
index = (int)links[index];
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public Byte2CharMap.Entry findFirst(Predicate<Byte2CharMap.Entry> filter) {
public Optional<Byte2CharMap.Entry> findFirst(Predicate<Byte2CharMap.Entry> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return null;
if(size() <= 0) return Optional.empty();
MapEntry entry = new MapEntry();
int index = firstIndex;
while(index != -1) {
entry.set(index);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
index = (int)links[index];
}
return null;
return Optional.empty();
}
@Override
@ -944,10 +951,13 @@ public class Byte2CharLinkedOpenCustomHashMap extends Byte2CharOpenCustomHashMap
public boolean add(byte o) {
throw new UnsupportedOperationException();
}
@Override
public void addFirst(byte o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(byte o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(byte o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToLast(byte o) { throw new UnsupportedOperationException(); }
@ -1090,7 +1100,7 @@ public class Byte2CharLinkedOpenCustomHashMap extends Byte2CharOpenCustomHashMap
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -1105,19 +1115,19 @@ public class Byte2CharLinkedOpenCustomHashMap extends Byte2CharOpenCustomHashMap
state = operator.applyAsByte(state, keys[index]);
index = (int)links[index];
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return (byte)0;
if(size() <= 0) return OptionalByte.empty();
int index = firstIndex;
while(index != -1){
if(filter.test(keys[index])) return keys[index];
if(filter.test(keys[index])) return OptionalByte.of(keys[index]);
index = (int)links[index];
}
return (byte)0;
return OptionalByte.empty();
}
@Override
@ -1252,7 +1262,7 @@ public class Byte2CharLinkedOpenCustomHashMap extends Byte2CharOpenCustomHashMap
}
@Override
public char reduce(CharCharUnaryOperator operator) {
public OptionalChar reduce(CharCharUnaryOperator operator) {
Objects.requireNonNull(operator);
char state = (char)0;
boolean empty = true;
@ -1267,19 +1277,19 @@ public class Byte2CharLinkedOpenCustomHashMap extends Byte2CharOpenCustomHashMap
state = operator.applyAsChar(state, values[index]);
index = (int)links[index];
}
return state;
return empty ? OptionalChar.empty() : OptionalChar.of(state);
}
@Override
public char findFirst(CharPredicate filter) {
public OptionalChar findFirst(CharPredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return (char)0;
if(size() <= 0) return OptionalChar.empty();
int index = firstIndex;
while(index != -1){
if(filter.test(values[index])) return values[index];
if(filter.test(values[index])) return OptionalChar.of(values[index]);
index = (int)links[index];
}
return (char)0;
return OptionalChar.empty();
}
@Override

View File

@ -5,6 +5,7 @@ import java.util.ConcurrentModificationException;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.BiFunction;
import java.util.function.Predicate;
@ -19,6 +20,7 @@ import speiger.src.collections.bytes.functions.consumer.ByteCharConsumer;
import speiger.src.collections.bytes.functions.function.Byte2CharFunction;
import speiger.src.collections.bytes.functions.function.ByteCharUnaryOperator;
import speiger.src.collections.bytes.functions.function.ByteByteUnaryOperator;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.functions.function.BytePredicate;
import speiger.src.collections.bytes.maps.abstracts.AbstractByte2CharMap;
import speiger.src.collections.bytes.maps.interfaces.Byte2CharMap;
@ -37,6 +39,7 @@ import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer;
import speiger.src.collections.objects.functions.consumer.ObjectCharConsumer;
import speiger.src.collections.chars.functions.function.CharPredicate;
import speiger.src.collections.chars.functions.OptionalChar;
import speiger.src.collections.objects.collections.ObjectIterator;
import speiger.src.collections.objects.sets.AbstractObjectSet;
import speiger.src.collections.objects.sets.ObjectSet;
@ -952,7 +955,7 @@ public class Byte2CharOpenCustomHashMap extends AbstractByte2CharMap implements
}
@Override
public Byte2CharMap.Entry reduce(ObjectObjectUnaryOperator<Byte2CharMap.Entry, Byte2CharMap.Entry> operator) {
public Optional<Byte2CharMap.Entry> reduce(ObjectObjectUnaryOperator<Byte2CharMap.Entry, Byte2CharMap.Entry> operator) {
Objects.requireNonNull(operator);
Byte2CharMap.Entry state = null;
boolean empty = true;
@ -969,25 +972,25 @@ public class Byte2CharOpenCustomHashMap extends AbstractByte2CharMap implements
}
state = operator.apply(state, new ValueMapEntry(i));
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public Byte2CharMap.Entry findFirst(Predicate<Byte2CharMap.Entry> filter) {
public Optional<Byte2CharMap.Entry> findFirst(Predicate<Byte2CharMap.Entry> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return null;
if(size() <= 0) return Optional.empty();
MapEntry entry = new MapEntry();
if(containsNull) {
entry.set(nullIndex);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
}
for(int i = nullIndex-1;i>=0;i--) {
if(!strategy.equals(keys[i], (byte)0)) {
entry.set(i);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
}
}
return null;
return Optional.empty();
}
@Override
@ -1161,7 +1164,7 @@ public class Byte2CharOpenCustomHashMap extends AbstractByte2CharMap implements
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -1178,18 +1181,18 @@ public class Byte2CharOpenCustomHashMap extends AbstractByte2CharMap implements
}
state = operator.applyAsByte(state, keys[i]);
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return (byte)0;
if(containsNull && filter.test(keys[nullIndex])) return keys[nullIndex];
if(size() <= 0) return OptionalByte.empty();
if(containsNull && filter.test(keys[nullIndex])) return OptionalByte.of(keys[nullIndex]);
for(int i = nullIndex-1;i>=0;i--) {
if(!strategy.equals(keys[i], (byte)0) && filter.test(keys[i])) return keys[i];
if(!strategy.equals(keys[i], (byte)0) && filter.test(keys[i])) return OptionalByte.of(keys[i]);
}
return (byte)0;
return OptionalByte.empty();
}
@Override
@ -1304,7 +1307,7 @@ public class Byte2CharOpenCustomHashMap extends AbstractByte2CharMap implements
}
@Override
public char reduce(CharCharUnaryOperator operator) {
public OptionalChar reduce(CharCharUnaryOperator operator) {
Objects.requireNonNull(operator);
char state = (char)0;
boolean empty = true;
@ -1321,18 +1324,18 @@ public class Byte2CharOpenCustomHashMap extends AbstractByte2CharMap implements
}
state = operator.applyAsChar(state, values[i]);
}
return state;
return empty ? OptionalChar.empty() : OptionalChar.of(state);
}
@Override
public char findFirst(CharPredicate filter) {
public OptionalChar findFirst(CharPredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return (char)0;
if(containsNull && filter.test(values[nullIndex])) return values[nullIndex];
if(size() <= 0) return OptionalChar.empty();
if(containsNull && filter.test(values[nullIndex])) return OptionalChar.of(values[nullIndex]);
for(int i = nullIndex-1;i>=0;i--) {
if(!strategy.equals(keys[i], (byte)0) && filter.test(values[i])) return values[i];
if(!strategy.equals(keys[i], (byte)0) && filter.test(values[i])) return OptionalChar.of(values[i]);
}
return (char)0;
return OptionalChar.empty();
}
@Override

View File

@ -4,10 +4,12 @@ import java.util.Arrays;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.BiFunction;
import java.util.function.Predicate;
import java.util.function.DoublePredicate;
import java.util.OptionalDouble;
import speiger.src.collections.bytes.collections.ByteBidirectionalIterator;
import speiger.src.collections.bytes.functions.ByteConsumer;
@ -15,6 +17,7 @@ import speiger.src.collections.objects.functions.consumer.ObjectByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
import speiger.src.collections.ints.functions.consumer.IntDoubleConsumer;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.functions.function.BytePredicate;
import speiger.src.collections.bytes.functions.consumer.ByteDoubleConsumer;
import speiger.src.collections.bytes.functions.function.ByteByteUnaryOperator;
@ -671,6 +674,10 @@ public class Byte2DoubleLinkedOpenCustomHashMap extends Byte2DoubleOpenCustomHas
}
private class MapEntrySet extends AbstractObjectSet<Byte2DoubleMap.Entry> implements Byte2DoubleOrderedMap.FastOrderedSet {
@Override
public void addFirst(Byte2DoubleMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(Byte2DoubleMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(Byte2DoubleMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
@ -836,7 +843,7 @@ public class Byte2DoubleLinkedOpenCustomHashMap extends Byte2DoubleOpenCustomHas
}
@Override
public Byte2DoubleMap.Entry reduce(ObjectObjectUnaryOperator<Byte2DoubleMap.Entry, Byte2DoubleMap.Entry> operator) {
public Optional<Byte2DoubleMap.Entry> reduce(ObjectObjectUnaryOperator<Byte2DoubleMap.Entry, Byte2DoubleMap.Entry> operator) {
Objects.requireNonNull(operator);
Byte2DoubleMap.Entry state = null;
boolean empty = true;
@ -851,21 +858,21 @@ public class Byte2DoubleLinkedOpenCustomHashMap extends Byte2DoubleOpenCustomHas
state = operator.apply(state, new ValueMapEntry(index));
index = (int)links[index];
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public Byte2DoubleMap.Entry findFirst(Predicate<Byte2DoubleMap.Entry> filter) {
public Optional<Byte2DoubleMap.Entry> findFirst(Predicate<Byte2DoubleMap.Entry> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return null;
if(size() <= 0) return Optional.empty();
MapEntry entry = new MapEntry();
int index = firstIndex;
while(index != -1) {
entry.set(index);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
index = (int)links[index];
}
return null;
return Optional.empty();
}
@Override
@ -944,10 +951,13 @@ public class Byte2DoubleLinkedOpenCustomHashMap extends Byte2DoubleOpenCustomHas
public boolean add(byte o) {
throw new UnsupportedOperationException();
}
@Override
public void addFirst(byte o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(byte o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(byte o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToLast(byte o) { throw new UnsupportedOperationException(); }
@ -1090,7 +1100,7 @@ public class Byte2DoubleLinkedOpenCustomHashMap extends Byte2DoubleOpenCustomHas
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -1105,19 +1115,19 @@ public class Byte2DoubleLinkedOpenCustomHashMap extends Byte2DoubleOpenCustomHas
state = operator.applyAsByte(state, keys[index]);
index = (int)links[index];
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return (byte)0;
if(size() <= 0) return OptionalByte.empty();
int index = firstIndex;
while(index != -1){
if(filter.test(keys[index])) return keys[index];
if(filter.test(keys[index])) return OptionalByte.of(keys[index]);
index = (int)links[index];
}
return (byte)0;
return OptionalByte.empty();
}
@Override
@ -1252,7 +1262,7 @@ public class Byte2DoubleLinkedOpenCustomHashMap extends Byte2DoubleOpenCustomHas
}
@Override
public double reduce(DoubleDoubleUnaryOperator operator) {
public OptionalDouble reduce(DoubleDoubleUnaryOperator operator) {
Objects.requireNonNull(operator);
double state = 0D;
boolean empty = true;
@ -1267,19 +1277,19 @@ public class Byte2DoubleLinkedOpenCustomHashMap extends Byte2DoubleOpenCustomHas
state = operator.applyAsDouble(state, values[index]);
index = (int)links[index];
}
return state;
return empty ? OptionalDouble.empty() : OptionalDouble.of(state);
}
@Override
public double findFirst(DoublePredicate filter) {
public OptionalDouble findFirst(DoublePredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return 0D;
if(size() <= 0) return OptionalDouble.empty();
int index = firstIndex;
while(index != -1){
if(filter.test(values[index])) return values[index];
if(filter.test(values[index])) return OptionalDouble.of(values[index]);
index = (int)links[index];
}
return 0D;
return OptionalDouble.empty();
}
@Override

View File

@ -5,10 +5,12 @@ import java.util.ConcurrentModificationException;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.BiFunction;
import java.util.function.Predicate;
import java.util.function.DoublePredicate;
import java.util.OptionalDouble;
import speiger.src.collections.bytes.collections.ByteIterator;
import speiger.src.collections.bytes.functions.ByteConsumer;
@ -20,6 +22,7 @@ import speiger.src.collections.bytes.functions.consumer.ByteDoubleConsumer;
import speiger.src.collections.bytes.functions.function.Byte2DoubleFunction;
import speiger.src.collections.bytes.functions.function.ByteDoubleUnaryOperator;
import speiger.src.collections.bytes.functions.function.ByteByteUnaryOperator;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.functions.function.BytePredicate;
import speiger.src.collections.bytes.maps.abstracts.AbstractByte2DoubleMap;
import speiger.src.collections.bytes.maps.interfaces.Byte2DoubleMap;
@ -952,7 +955,7 @@ public class Byte2DoubleOpenCustomHashMap extends AbstractByte2DoubleMap impleme
}
@Override
public Byte2DoubleMap.Entry reduce(ObjectObjectUnaryOperator<Byte2DoubleMap.Entry, Byte2DoubleMap.Entry> operator) {
public Optional<Byte2DoubleMap.Entry> reduce(ObjectObjectUnaryOperator<Byte2DoubleMap.Entry, Byte2DoubleMap.Entry> operator) {
Objects.requireNonNull(operator);
Byte2DoubleMap.Entry state = null;
boolean empty = true;
@ -969,25 +972,25 @@ public class Byte2DoubleOpenCustomHashMap extends AbstractByte2DoubleMap impleme
}
state = operator.apply(state, new ValueMapEntry(i));
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public Byte2DoubleMap.Entry findFirst(Predicate<Byte2DoubleMap.Entry> filter) {
public Optional<Byte2DoubleMap.Entry> findFirst(Predicate<Byte2DoubleMap.Entry> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return null;
if(size() <= 0) return Optional.empty();
MapEntry entry = new MapEntry();
if(containsNull) {
entry.set(nullIndex);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
}
for(int i = nullIndex-1;i>=0;i--) {
if(!strategy.equals(keys[i], (byte)0)) {
entry.set(i);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
}
}
return null;
return Optional.empty();
}
@Override
@ -1161,7 +1164,7 @@ public class Byte2DoubleOpenCustomHashMap extends AbstractByte2DoubleMap impleme
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -1178,18 +1181,18 @@ public class Byte2DoubleOpenCustomHashMap extends AbstractByte2DoubleMap impleme
}
state = operator.applyAsByte(state, keys[i]);
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return (byte)0;
if(containsNull && filter.test(keys[nullIndex])) return keys[nullIndex];
if(size() <= 0) return OptionalByte.empty();
if(containsNull && filter.test(keys[nullIndex])) return OptionalByte.of(keys[nullIndex]);
for(int i = nullIndex-1;i>=0;i--) {
if(!strategy.equals(keys[i], (byte)0) && filter.test(keys[i])) return keys[i];
if(!strategy.equals(keys[i], (byte)0) && filter.test(keys[i])) return OptionalByte.of(keys[i]);
}
return (byte)0;
return OptionalByte.empty();
}
@Override
@ -1304,7 +1307,7 @@ public class Byte2DoubleOpenCustomHashMap extends AbstractByte2DoubleMap impleme
}
@Override
public double reduce(DoubleDoubleUnaryOperator operator) {
public OptionalDouble reduce(DoubleDoubleUnaryOperator operator) {
Objects.requireNonNull(operator);
double state = 0D;
boolean empty = true;
@ -1321,18 +1324,18 @@ public class Byte2DoubleOpenCustomHashMap extends AbstractByte2DoubleMap impleme
}
state = operator.applyAsDouble(state, values[i]);
}
return state;
return empty ? OptionalDouble.empty() : OptionalDouble.of(state);
}
@Override
public double findFirst(DoublePredicate filter) {
public OptionalDouble findFirst(DoublePredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return 0D;
if(containsNull && filter.test(values[nullIndex])) return values[nullIndex];
if(size() <= 0) return OptionalDouble.empty();
if(containsNull && filter.test(values[nullIndex])) return OptionalDouble.of(values[nullIndex]);
for(int i = nullIndex-1;i>=0;i--) {
if(!strategy.equals(keys[i], (byte)0) && filter.test(values[i])) return values[i];
if(!strategy.equals(keys[i], (byte)0) && filter.test(values[i])) return OptionalDouble.of(values[i]);
}
return 0D;
return OptionalDouble.empty();
}
@Override

View File

@ -4,6 +4,7 @@ import java.util.Arrays;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.BiFunction;
import java.util.function.Predicate;
@ -14,6 +15,7 @@ import speiger.src.collections.objects.functions.consumer.ObjectByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
import speiger.src.collections.ints.functions.consumer.IntFloatConsumer;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.functions.function.BytePredicate;
import speiger.src.collections.bytes.functions.consumer.ByteFloatConsumer;
import speiger.src.collections.bytes.functions.function.ByteByteUnaryOperator;
@ -33,6 +35,7 @@ import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer;
import speiger.src.collections.objects.functions.consumer.ObjectFloatConsumer;
import speiger.src.collections.floats.functions.function.FloatPredicate;
import speiger.src.collections.floats.functions.OptionalFloat;
import speiger.src.collections.objects.functions.function.ObjectObjectUnaryOperator;
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
import speiger.src.collections.objects.lists.ObjectListIterator;
@ -671,6 +674,10 @@ public class Byte2FloatLinkedOpenCustomHashMap extends Byte2FloatOpenCustomHashM
}
private class MapEntrySet extends AbstractObjectSet<Byte2FloatMap.Entry> implements Byte2FloatOrderedMap.FastOrderedSet {
@Override
public void addFirst(Byte2FloatMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(Byte2FloatMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(Byte2FloatMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
@ -836,7 +843,7 @@ public class Byte2FloatLinkedOpenCustomHashMap extends Byte2FloatOpenCustomHashM
}
@Override
public Byte2FloatMap.Entry reduce(ObjectObjectUnaryOperator<Byte2FloatMap.Entry, Byte2FloatMap.Entry> operator) {
public Optional<Byte2FloatMap.Entry> reduce(ObjectObjectUnaryOperator<Byte2FloatMap.Entry, Byte2FloatMap.Entry> operator) {
Objects.requireNonNull(operator);
Byte2FloatMap.Entry state = null;
boolean empty = true;
@ -851,21 +858,21 @@ public class Byte2FloatLinkedOpenCustomHashMap extends Byte2FloatOpenCustomHashM
state = operator.apply(state, new ValueMapEntry(index));
index = (int)links[index];
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public Byte2FloatMap.Entry findFirst(Predicate<Byte2FloatMap.Entry> filter) {
public Optional<Byte2FloatMap.Entry> findFirst(Predicate<Byte2FloatMap.Entry> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return null;
if(size() <= 0) return Optional.empty();
MapEntry entry = new MapEntry();
int index = firstIndex;
while(index != -1) {
entry.set(index);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
index = (int)links[index];
}
return null;
return Optional.empty();
}
@Override
@ -944,10 +951,13 @@ public class Byte2FloatLinkedOpenCustomHashMap extends Byte2FloatOpenCustomHashM
public boolean add(byte o) {
throw new UnsupportedOperationException();
}
@Override
public void addFirst(byte o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(byte o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(byte o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToLast(byte o) { throw new UnsupportedOperationException(); }
@ -1090,7 +1100,7 @@ public class Byte2FloatLinkedOpenCustomHashMap extends Byte2FloatOpenCustomHashM
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -1105,19 +1115,19 @@ public class Byte2FloatLinkedOpenCustomHashMap extends Byte2FloatOpenCustomHashM
state = operator.applyAsByte(state, keys[index]);
index = (int)links[index];
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return (byte)0;
if(size() <= 0) return OptionalByte.empty();
int index = firstIndex;
while(index != -1){
if(filter.test(keys[index])) return keys[index];
if(filter.test(keys[index])) return OptionalByte.of(keys[index]);
index = (int)links[index];
}
return (byte)0;
return OptionalByte.empty();
}
@Override
@ -1252,7 +1262,7 @@ public class Byte2FloatLinkedOpenCustomHashMap extends Byte2FloatOpenCustomHashM
}
@Override
public float reduce(FloatFloatUnaryOperator operator) {
public OptionalFloat reduce(FloatFloatUnaryOperator operator) {
Objects.requireNonNull(operator);
float state = 0F;
boolean empty = true;
@ -1267,19 +1277,19 @@ public class Byte2FloatLinkedOpenCustomHashMap extends Byte2FloatOpenCustomHashM
state = operator.applyAsFloat(state, values[index]);
index = (int)links[index];
}
return state;
return empty ? OptionalFloat.empty() : OptionalFloat.of(state);
}
@Override
public float findFirst(FloatPredicate filter) {
public OptionalFloat findFirst(FloatPredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return 0F;
if(size() <= 0) return OptionalFloat.empty();
int index = firstIndex;
while(index != -1){
if(filter.test(values[index])) return values[index];
if(filter.test(values[index])) return OptionalFloat.of(values[index]);
index = (int)links[index];
}
return 0F;
return OptionalFloat.empty();
}
@Override

View File

@ -5,6 +5,7 @@ import java.util.ConcurrentModificationException;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.BiFunction;
import java.util.function.Predicate;
@ -19,6 +20,7 @@ import speiger.src.collections.bytes.functions.consumer.ByteFloatConsumer;
import speiger.src.collections.bytes.functions.function.Byte2FloatFunction;
import speiger.src.collections.bytes.functions.function.ByteFloatUnaryOperator;
import speiger.src.collections.bytes.functions.function.ByteByteUnaryOperator;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.functions.function.BytePredicate;
import speiger.src.collections.bytes.maps.abstracts.AbstractByte2FloatMap;
import speiger.src.collections.bytes.maps.interfaces.Byte2FloatMap;
@ -37,6 +39,7 @@ import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer;
import speiger.src.collections.objects.functions.consumer.ObjectFloatConsumer;
import speiger.src.collections.floats.functions.function.FloatPredicate;
import speiger.src.collections.floats.functions.OptionalFloat;
import speiger.src.collections.objects.collections.ObjectIterator;
import speiger.src.collections.objects.sets.AbstractObjectSet;
import speiger.src.collections.objects.sets.ObjectSet;
@ -952,7 +955,7 @@ public class Byte2FloatOpenCustomHashMap extends AbstractByte2FloatMap implement
}
@Override
public Byte2FloatMap.Entry reduce(ObjectObjectUnaryOperator<Byte2FloatMap.Entry, Byte2FloatMap.Entry> operator) {
public Optional<Byte2FloatMap.Entry> reduce(ObjectObjectUnaryOperator<Byte2FloatMap.Entry, Byte2FloatMap.Entry> operator) {
Objects.requireNonNull(operator);
Byte2FloatMap.Entry state = null;
boolean empty = true;
@ -969,25 +972,25 @@ public class Byte2FloatOpenCustomHashMap extends AbstractByte2FloatMap implement
}
state = operator.apply(state, new ValueMapEntry(i));
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public Byte2FloatMap.Entry findFirst(Predicate<Byte2FloatMap.Entry> filter) {
public Optional<Byte2FloatMap.Entry> findFirst(Predicate<Byte2FloatMap.Entry> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return null;
if(size() <= 0) return Optional.empty();
MapEntry entry = new MapEntry();
if(containsNull) {
entry.set(nullIndex);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
}
for(int i = nullIndex-1;i>=0;i--) {
if(!strategy.equals(keys[i], (byte)0)) {
entry.set(i);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
}
}
return null;
return Optional.empty();
}
@Override
@ -1161,7 +1164,7 @@ public class Byte2FloatOpenCustomHashMap extends AbstractByte2FloatMap implement
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -1178,18 +1181,18 @@ public class Byte2FloatOpenCustomHashMap extends AbstractByte2FloatMap implement
}
state = operator.applyAsByte(state, keys[i]);
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return (byte)0;
if(containsNull && filter.test(keys[nullIndex])) return keys[nullIndex];
if(size() <= 0) return OptionalByte.empty();
if(containsNull && filter.test(keys[nullIndex])) return OptionalByte.of(keys[nullIndex]);
for(int i = nullIndex-1;i>=0;i--) {
if(!strategy.equals(keys[i], (byte)0) && filter.test(keys[i])) return keys[i];
if(!strategy.equals(keys[i], (byte)0) && filter.test(keys[i])) return OptionalByte.of(keys[i]);
}
return (byte)0;
return OptionalByte.empty();
}
@Override
@ -1304,7 +1307,7 @@ public class Byte2FloatOpenCustomHashMap extends AbstractByte2FloatMap implement
}
@Override
public float reduce(FloatFloatUnaryOperator operator) {
public OptionalFloat reduce(FloatFloatUnaryOperator operator) {
Objects.requireNonNull(operator);
float state = 0F;
boolean empty = true;
@ -1321,18 +1324,18 @@ public class Byte2FloatOpenCustomHashMap extends AbstractByte2FloatMap implement
}
state = operator.applyAsFloat(state, values[i]);
}
return state;
return empty ? OptionalFloat.empty() : OptionalFloat.of(state);
}
@Override
public float findFirst(FloatPredicate filter) {
public OptionalFloat findFirst(FloatPredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return 0F;
if(containsNull && filter.test(values[nullIndex])) return values[nullIndex];
if(size() <= 0) return OptionalFloat.empty();
if(containsNull && filter.test(values[nullIndex])) return OptionalFloat.of(values[nullIndex]);
for(int i = nullIndex-1;i>=0;i--) {
if(!strategy.equals(keys[i], (byte)0) && filter.test(values[i])) return values[i];
if(!strategy.equals(keys[i], (byte)0) && filter.test(values[i])) return OptionalFloat.of(values[i]);
}
return 0F;
return OptionalFloat.empty();
}
@Override

View File

@ -4,10 +4,12 @@ import java.util.Arrays;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.BiFunction;
import java.util.function.Predicate;
import java.util.function.IntPredicate;
import java.util.OptionalInt;
import speiger.src.collections.bytes.collections.ByteBidirectionalIterator;
import speiger.src.collections.bytes.functions.ByteConsumer;
@ -15,6 +17,7 @@ import speiger.src.collections.objects.functions.consumer.ObjectByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
import speiger.src.collections.ints.functions.consumer.IntIntConsumer;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.functions.function.BytePredicate;
import speiger.src.collections.bytes.functions.consumer.ByteIntConsumer;
import speiger.src.collections.bytes.functions.function.ByteByteUnaryOperator;
@ -671,6 +674,10 @@ public class Byte2IntLinkedOpenCustomHashMap extends Byte2IntOpenCustomHashMap i
}
private class MapEntrySet extends AbstractObjectSet<Byte2IntMap.Entry> implements Byte2IntOrderedMap.FastOrderedSet {
@Override
public void addFirst(Byte2IntMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(Byte2IntMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(Byte2IntMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
@ -836,7 +843,7 @@ public class Byte2IntLinkedOpenCustomHashMap extends Byte2IntOpenCustomHashMap i
}
@Override
public Byte2IntMap.Entry reduce(ObjectObjectUnaryOperator<Byte2IntMap.Entry, Byte2IntMap.Entry> operator) {
public Optional<Byte2IntMap.Entry> reduce(ObjectObjectUnaryOperator<Byte2IntMap.Entry, Byte2IntMap.Entry> operator) {
Objects.requireNonNull(operator);
Byte2IntMap.Entry state = null;
boolean empty = true;
@ -851,21 +858,21 @@ public class Byte2IntLinkedOpenCustomHashMap extends Byte2IntOpenCustomHashMap i
state = operator.apply(state, new ValueMapEntry(index));
index = (int)links[index];
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public Byte2IntMap.Entry findFirst(Predicate<Byte2IntMap.Entry> filter) {
public Optional<Byte2IntMap.Entry> findFirst(Predicate<Byte2IntMap.Entry> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return null;
if(size() <= 0) return Optional.empty();
MapEntry entry = new MapEntry();
int index = firstIndex;
while(index != -1) {
entry.set(index);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
index = (int)links[index];
}
return null;
return Optional.empty();
}
@Override
@ -944,10 +951,13 @@ public class Byte2IntLinkedOpenCustomHashMap extends Byte2IntOpenCustomHashMap i
public boolean add(byte o) {
throw new UnsupportedOperationException();
}
@Override
public void addFirst(byte o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(byte o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(byte o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToLast(byte o) { throw new UnsupportedOperationException(); }
@ -1090,7 +1100,7 @@ public class Byte2IntLinkedOpenCustomHashMap extends Byte2IntOpenCustomHashMap i
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -1105,19 +1115,19 @@ public class Byte2IntLinkedOpenCustomHashMap extends Byte2IntOpenCustomHashMap i
state = operator.applyAsByte(state, keys[index]);
index = (int)links[index];
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return (byte)0;
if(size() <= 0) return OptionalByte.empty();
int index = firstIndex;
while(index != -1){
if(filter.test(keys[index])) return keys[index];
if(filter.test(keys[index])) return OptionalByte.of(keys[index]);
index = (int)links[index];
}
return (byte)0;
return OptionalByte.empty();
}
@Override
@ -1252,7 +1262,7 @@ public class Byte2IntLinkedOpenCustomHashMap extends Byte2IntOpenCustomHashMap i
}
@Override
public int reduce(IntIntUnaryOperator operator) {
public OptionalInt reduce(IntIntUnaryOperator operator) {
Objects.requireNonNull(operator);
int state = 0;
boolean empty = true;
@ -1267,19 +1277,19 @@ public class Byte2IntLinkedOpenCustomHashMap extends Byte2IntOpenCustomHashMap i
state = operator.applyAsInt(state, values[index]);
index = (int)links[index];
}
return state;
return empty ? OptionalInt.empty() : OptionalInt.of(state);
}
@Override
public int findFirst(IntPredicate filter) {
public OptionalInt findFirst(IntPredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return 0;
if(size() <= 0) return OptionalInt.empty();
int index = firstIndex;
while(index != -1){
if(filter.test(values[index])) return values[index];
if(filter.test(values[index])) return OptionalInt.of(values[index]);
index = (int)links[index];
}
return 0;
return OptionalInt.empty();
}
@Override

View File

@ -5,10 +5,12 @@ import java.util.ConcurrentModificationException;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.BiFunction;
import java.util.function.Predicate;
import java.util.function.IntPredicate;
import java.util.OptionalInt;
import speiger.src.collections.bytes.collections.ByteIterator;
import speiger.src.collections.bytes.functions.ByteConsumer;
@ -20,6 +22,7 @@ import speiger.src.collections.bytes.functions.consumer.ByteIntConsumer;
import speiger.src.collections.bytes.functions.function.Byte2IntFunction;
import speiger.src.collections.bytes.functions.function.ByteIntUnaryOperator;
import speiger.src.collections.bytes.functions.function.ByteByteUnaryOperator;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.functions.function.BytePredicate;
import speiger.src.collections.bytes.maps.abstracts.AbstractByte2IntMap;
import speiger.src.collections.bytes.maps.interfaces.Byte2IntMap;
@ -952,7 +955,7 @@ public class Byte2IntOpenCustomHashMap extends AbstractByte2IntMap implements IT
}
@Override
public Byte2IntMap.Entry reduce(ObjectObjectUnaryOperator<Byte2IntMap.Entry, Byte2IntMap.Entry> operator) {
public Optional<Byte2IntMap.Entry> reduce(ObjectObjectUnaryOperator<Byte2IntMap.Entry, Byte2IntMap.Entry> operator) {
Objects.requireNonNull(operator);
Byte2IntMap.Entry state = null;
boolean empty = true;
@ -969,25 +972,25 @@ public class Byte2IntOpenCustomHashMap extends AbstractByte2IntMap implements IT
}
state = operator.apply(state, new ValueMapEntry(i));
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public Byte2IntMap.Entry findFirst(Predicate<Byte2IntMap.Entry> filter) {
public Optional<Byte2IntMap.Entry> findFirst(Predicate<Byte2IntMap.Entry> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return null;
if(size() <= 0) return Optional.empty();
MapEntry entry = new MapEntry();
if(containsNull) {
entry.set(nullIndex);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
}
for(int i = nullIndex-1;i>=0;i--) {
if(!strategy.equals(keys[i], (byte)0)) {
entry.set(i);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
}
}
return null;
return Optional.empty();
}
@Override
@ -1161,7 +1164,7 @@ public class Byte2IntOpenCustomHashMap extends AbstractByte2IntMap implements IT
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -1178,18 +1181,18 @@ public class Byte2IntOpenCustomHashMap extends AbstractByte2IntMap implements IT
}
state = operator.applyAsByte(state, keys[i]);
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return (byte)0;
if(containsNull && filter.test(keys[nullIndex])) return keys[nullIndex];
if(size() <= 0) return OptionalByte.empty();
if(containsNull && filter.test(keys[nullIndex])) return OptionalByte.of(keys[nullIndex]);
for(int i = nullIndex-1;i>=0;i--) {
if(!strategy.equals(keys[i], (byte)0) && filter.test(keys[i])) return keys[i];
if(!strategy.equals(keys[i], (byte)0) && filter.test(keys[i])) return OptionalByte.of(keys[i]);
}
return (byte)0;
return OptionalByte.empty();
}
@Override
@ -1304,7 +1307,7 @@ public class Byte2IntOpenCustomHashMap extends AbstractByte2IntMap implements IT
}
@Override
public int reduce(IntIntUnaryOperator operator) {
public OptionalInt reduce(IntIntUnaryOperator operator) {
Objects.requireNonNull(operator);
int state = 0;
boolean empty = true;
@ -1321,18 +1324,18 @@ public class Byte2IntOpenCustomHashMap extends AbstractByte2IntMap implements IT
}
state = operator.applyAsInt(state, values[i]);
}
return state;
return empty ? OptionalInt.empty() : OptionalInt.of(state);
}
@Override
public int findFirst(IntPredicate filter) {
public OptionalInt findFirst(IntPredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return 0;
if(containsNull && filter.test(values[nullIndex])) return values[nullIndex];
if(size() <= 0) return OptionalInt.empty();
if(containsNull && filter.test(values[nullIndex])) return OptionalInt.of(values[nullIndex]);
for(int i = nullIndex-1;i>=0;i--) {
if(!strategy.equals(keys[i], (byte)0) && filter.test(values[i])) return values[i];
if(!strategy.equals(keys[i], (byte)0) && filter.test(values[i])) return OptionalInt.of(values[i]);
}
return 0;
return OptionalInt.empty();
}
@Override

View File

@ -4,10 +4,12 @@ import java.util.Arrays;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.BiFunction;
import java.util.function.Predicate;
import java.util.function.LongPredicate;
import java.util.OptionalLong;
import speiger.src.collections.bytes.collections.ByteBidirectionalIterator;
import speiger.src.collections.bytes.functions.ByteConsumer;
@ -15,6 +17,7 @@ import speiger.src.collections.objects.functions.consumer.ObjectByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
import speiger.src.collections.ints.functions.consumer.IntLongConsumer;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.functions.function.BytePredicate;
import speiger.src.collections.bytes.functions.consumer.ByteLongConsumer;
import speiger.src.collections.bytes.functions.function.ByteByteUnaryOperator;
@ -671,6 +674,10 @@ public class Byte2LongLinkedOpenCustomHashMap extends Byte2LongOpenCustomHashMap
}
private class MapEntrySet extends AbstractObjectSet<Byte2LongMap.Entry> implements Byte2LongOrderedMap.FastOrderedSet {
@Override
public void addFirst(Byte2LongMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(Byte2LongMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(Byte2LongMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
@ -836,7 +843,7 @@ public class Byte2LongLinkedOpenCustomHashMap extends Byte2LongOpenCustomHashMap
}
@Override
public Byte2LongMap.Entry reduce(ObjectObjectUnaryOperator<Byte2LongMap.Entry, Byte2LongMap.Entry> operator) {
public Optional<Byte2LongMap.Entry> reduce(ObjectObjectUnaryOperator<Byte2LongMap.Entry, Byte2LongMap.Entry> operator) {
Objects.requireNonNull(operator);
Byte2LongMap.Entry state = null;
boolean empty = true;
@ -851,21 +858,21 @@ public class Byte2LongLinkedOpenCustomHashMap extends Byte2LongOpenCustomHashMap
state = operator.apply(state, new ValueMapEntry(index));
index = (int)links[index];
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public Byte2LongMap.Entry findFirst(Predicate<Byte2LongMap.Entry> filter) {
public Optional<Byte2LongMap.Entry> findFirst(Predicate<Byte2LongMap.Entry> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return null;
if(size() <= 0) return Optional.empty();
MapEntry entry = new MapEntry();
int index = firstIndex;
while(index != -1) {
entry.set(index);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
index = (int)links[index];
}
return null;
return Optional.empty();
}
@Override
@ -944,10 +951,13 @@ public class Byte2LongLinkedOpenCustomHashMap extends Byte2LongOpenCustomHashMap
public boolean add(byte o) {
throw new UnsupportedOperationException();
}
@Override
public void addFirst(byte o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(byte o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(byte o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToLast(byte o) { throw new UnsupportedOperationException(); }
@ -1090,7 +1100,7 @@ public class Byte2LongLinkedOpenCustomHashMap extends Byte2LongOpenCustomHashMap
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -1105,19 +1115,19 @@ public class Byte2LongLinkedOpenCustomHashMap extends Byte2LongOpenCustomHashMap
state = operator.applyAsByte(state, keys[index]);
index = (int)links[index];
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return (byte)0;
if(size() <= 0) return OptionalByte.empty();
int index = firstIndex;
while(index != -1){
if(filter.test(keys[index])) return keys[index];
if(filter.test(keys[index])) return OptionalByte.of(keys[index]);
index = (int)links[index];
}
return (byte)0;
return OptionalByte.empty();
}
@Override
@ -1252,7 +1262,7 @@ public class Byte2LongLinkedOpenCustomHashMap extends Byte2LongOpenCustomHashMap
}
@Override
public long reduce(LongLongUnaryOperator operator) {
public OptionalLong reduce(LongLongUnaryOperator operator) {
Objects.requireNonNull(operator);
long state = 0L;
boolean empty = true;
@ -1267,19 +1277,19 @@ public class Byte2LongLinkedOpenCustomHashMap extends Byte2LongOpenCustomHashMap
state = operator.applyAsLong(state, values[index]);
index = (int)links[index];
}
return state;
return empty ? OptionalLong.empty() : OptionalLong.of(state);
}
@Override
public long findFirst(LongPredicate filter) {
public OptionalLong findFirst(LongPredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return 0L;
if(size() <= 0) return OptionalLong.empty();
int index = firstIndex;
while(index != -1){
if(filter.test(values[index])) return values[index];
if(filter.test(values[index])) return OptionalLong.of(values[index]);
index = (int)links[index];
}
return 0L;
return OptionalLong.empty();
}
@Override

View File

@ -5,10 +5,12 @@ import java.util.ConcurrentModificationException;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.BiFunction;
import java.util.function.Predicate;
import java.util.function.LongPredicate;
import java.util.OptionalLong;
import speiger.src.collections.bytes.collections.ByteIterator;
import speiger.src.collections.bytes.functions.ByteConsumer;
@ -20,6 +22,7 @@ import speiger.src.collections.bytes.functions.consumer.ByteLongConsumer;
import speiger.src.collections.bytes.functions.function.Byte2LongFunction;
import speiger.src.collections.bytes.functions.function.ByteLongUnaryOperator;
import speiger.src.collections.bytes.functions.function.ByteByteUnaryOperator;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.functions.function.BytePredicate;
import speiger.src.collections.bytes.maps.abstracts.AbstractByte2LongMap;
import speiger.src.collections.bytes.maps.interfaces.Byte2LongMap;
@ -952,7 +955,7 @@ public class Byte2LongOpenCustomHashMap extends AbstractByte2LongMap implements
}
@Override
public Byte2LongMap.Entry reduce(ObjectObjectUnaryOperator<Byte2LongMap.Entry, Byte2LongMap.Entry> operator) {
public Optional<Byte2LongMap.Entry> reduce(ObjectObjectUnaryOperator<Byte2LongMap.Entry, Byte2LongMap.Entry> operator) {
Objects.requireNonNull(operator);
Byte2LongMap.Entry state = null;
boolean empty = true;
@ -969,25 +972,25 @@ public class Byte2LongOpenCustomHashMap extends AbstractByte2LongMap implements
}
state = operator.apply(state, new ValueMapEntry(i));
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public Byte2LongMap.Entry findFirst(Predicate<Byte2LongMap.Entry> filter) {
public Optional<Byte2LongMap.Entry> findFirst(Predicate<Byte2LongMap.Entry> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return null;
if(size() <= 0) return Optional.empty();
MapEntry entry = new MapEntry();
if(containsNull) {
entry.set(nullIndex);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
}
for(int i = nullIndex-1;i>=0;i--) {
if(!strategy.equals(keys[i], (byte)0)) {
entry.set(i);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
}
}
return null;
return Optional.empty();
}
@Override
@ -1161,7 +1164,7 @@ public class Byte2LongOpenCustomHashMap extends AbstractByte2LongMap implements
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -1178,18 +1181,18 @@ public class Byte2LongOpenCustomHashMap extends AbstractByte2LongMap implements
}
state = operator.applyAsByte(state, keys[i]);
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return (byte)0;
if(containsNull && filter.test(keys[nullIndex])) return keys[nullIndex];
if(size() <= 0) return OptionalByte.empty();
if(containsNull && filter.test(keys[nullIndex])) return OptionalByte.of(keys[nullIndex]);
for(int i = nullIndex-1;i>=0;i--) {
if(!strategy.equals(keys[i], (byte)0) && filter.test(keys[i])) return keys[i];
if(!strategy.equals(keys[i], (byte)0) && filter.test(keys[i])) return OptionalByte.of(keys[i]);
}
return (byte)0;
return OptionalByte.empty();
}
@Override
@ -1304,7 +1307,7 @@ public class Byte2LongOpenCustomHashMap extends AbstractByte2LongMap implements
}
@Override
public long reduce(LongLongUnaryOperator operator) {
public OptionalLong reduce(LongLongUnaryOperator operator) {
Objects.requireNonNull(operator);
long state = 0L;
boolean empty = true;
@ -1321,18 +1324,18 @@ public class Byte2LongOpenCustomHashMap extends AbstractByte2LongMap implements
}
state = operator.applyAsLong(state, values[i]);
}
return state;
return empty ? OptionalLong.empty() : OptionalLong.of(state);
}
@Override
public long findFirst(LongPredicate filter) {
public OptionalLong findFirst(LongPredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return 0L;
if(containsNull && filter.test(values[nullIndex])) return values[nullIndex];
if(size() <= 0) return OptionalLong.empty();
if(containsNull && filter.test(values[nullIndex])) return OptionalLong.of(values[nullIndex]);
for(int i = nullIndex-1;i>=0;i--) {
if(!strategy.equals(keys[i], (byte)0) && filter.test(values[i])) return values[i];
if(!strategy.equals(keys[i], (byte)0) && filter.test(values[i])) return OptionalLong.of(values[i]);
}
return 0L;
return OptionalLong.empty();
}
@Override

View File

@ -4,6 +4,7 @@ import java.util.Arrays;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.BiFunction;
import java.util.function.Predicate;
@ -13,6 +14,7 @@ import speiger.src.collections.bytes.functions.ByteConsumer;
import speiger.src.collections.objects.functions.consumer.ObjectByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.functions.function.BytePredicate;
import speiger.src.collections.bytes.functions.consumer.ByteObjectConsumer;
import speiger.src.collections.bytes.functions.function.ByteByteUnaryOperator;
@ -666,6 +668,10 @@ public class Byte2ObjectLinkedOpenCustomHashMap<V> extends Byte2ObjectOpenCustom
}
private class MapEntrySet extends AbstractObjectSet<Byte2ObjectMap.Entry<V>> implements Byte2ObjectOrderedMap.FastOrderedSet<V> {
@Override
public void addFirst(Byte2ObjectMap.Entry<V> o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(Byte2ObjectMap.Entry<V> o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(Byte2ObjectMap.Entry<V> o) { throw new UnsupportedOperationException(); }
@Override
@ -831,7 +837,7 @@ public class Byte2ObjectLinkedOpenCustomHashMap<V> extends Byte2ObjectOpenCustom
}
@Override
public Byte2ObjectMap.Entry<V> reduce(ObjectObjectUnaryOperator<Byte2ObjectMap.Entry<V>, Byte2ObjectMap.Entry<V>> operator) {
public Optional<Byte2ObjectMap.Entry<V>> reduce(ObjectObjectUnaryOperator<Byte2ObjectMap.Entry<V>, Byte2ObjectMap.Entry<V>> operator) {
Objects.requireNonNull(operator);
Byte2ObjectMap.Entry<V> state = null;
boolean empty = true;
@ -846,21 +852,21 @@ public class Byte2ObjectLinkedOpenCustomHashMap<V> extends Byte2ObjectOpenCustom
state = operator.apply(state, new ValueMapEntry(index));
index = (int)links[index];
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public Byte2ObjectMap.Entry<V> findFirst(Predicate<Byte2ObjectMap.Entry<V>> filter) {
public Optional<Byte2ObjectMap.Entry<V>> findFirst(Predicate<Byte2ObjectMap.Entry<V>> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return null;
if(size() <= 0) return Optional.empty();
MapEntry entry = new MapEntry();
int index = firstIndex;
while(index != -1) {
entry.set(index);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
index = (int)links[index];
}
return null;
return Optional.empty();
}
@Override
@ -939,10 +945,13 @@ public class Byte2ObjectLinkedOpenCustomHashMap<V> extends Byte2ObjectOpenCustom
public boolean add(byte o) {
throw new UnsupportedOperationException();
}
@Override
public void addFirst(byte o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(byte o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(byte o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToLast(byte o) { throw new UnsupportedOperationException(); }
@ -1085,7 +1094,7 @@ public class Byte2ObjectLinkedOpenCustomHashMap<V> extends Byte2ObjectOpenCustom
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -1100,19 +1109,19 @@ public class Byte2ObjectLinkedOpenCustomHashMap<V> extends Byte2ObjectOpenCustom
state = operator.applyAsByte(state, keys[index]);
index = (int)links[index];
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return (byte)0;
if(size() <= 0) return OptionalByte.empty();
int index = firstIndex;
while(index != -1){
if(filter.test(keys[index])) return keys[index];
if(filter.test(keys[index])) return OptionalByte.of(keys[index]);
index = (int)links[index];
}
return (byte)0;
return OptionalByte.empty();
}
@Override
@ -1248,7 +1257,7 @@ public class Byte2ObjectLinkedOpenCustomHashMap<V> extends Byte2ObjectOpenCustom
}
@Override
public V reduce(ObjectObjectUnaryOperator<V, V> operator) {
public Optional<V> reduce(ObjectObjectUnaryOperator<V, V> operator) {
Objects.requireNonNull(operator);
V state = null;
boolean empty = true;
@ -1263,19 +1272,19 @@ public class Byte2ObjectLinkedOpenCustomHashMap<V> extends Byte2ObjectOpenCustom
state = operator.apply(state, values[index]);
index = (int)links[index];
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public V findFirst(Predicate<V> filter) {
public Optional<V> findFirst(Predicate<V> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return null;
if(size() <= 0) return Optional.empty();
int index = firstIndex;
while(index != -1){
if(filter.test(values[index])) return values[index];
if(filter.test(values[index])) return Optional.ofNullable(values[index]);
index = (int)links[index];
}
return null;
return Optional.empty();
}
@Override

View File

@ -5,6 +5,7 @@ import java.util.ConcurrentModificationException;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.BiFunction;
import java.util.function.Predicate;
@ -18,6 +19,7 @@ import speiger.src.collections.bytes.functions.consumer.ByteObjectConsumer;
import speiger.src.collections.bytes.functions.function.ByteFunction;
import speiger.src.collections.bytes.functions.function.ByteObjectUnaryOperator;
import speiger.src.collections.bytes.functions.function.ByteByteUnaryOperator;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.functions.function.BytePredicate;
import speiger.src.collections.bytes.maps.abstracts.AbstractByte2ObjectMap;
import speiger.src.collections.bytes.maps.interfaces.Byte2ObjectMap;
@ -868,7 +870,7 @@ public class Byte2ObjectOpenCustomHashMap<V> extends AbstractByte2ObjectMap<V> i
}
@Override
public Byte2ObjectMap.Entry<V> reduce(ObjectObjectUnaryOperator<Byte2ObjectMap.Entry<V>, Byte2ObjectMap.Entry<V>> operator) {
public Optional<Byte2ObjectMap.Entry<V>> reduce(ObjectObjectUnaryOperator<Byte2ObjectMap.Entry<V>, Byte2ObjectMap.Entry<V>> operator) {
Objects.requireNonNull(operator);
Byte2ObjectMap.Entry<V> state = null;
boolean empty = true;
@ -885,25 +887,25 @@ public class Byte2ObjectOpenCustomHashMap<V> extends AbstractByte2ObjectMap<V> i
}
state = operator.apply(state, new ValueMapEntry(i));
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public Byte2ObjectMap.Entry<V> findFirst(Predicate<Byte2ObjectMap.Entry<V>> filter) {
public Optional<Byte2ObjectMap.Entry<V>> findFirst(Predicate<Byte2ObjectMap.Entry<V>> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return null;
if(size() <= 0) return Optional.empty();
MapEntry entry = new MapEntry();
if(containsNull) {
entry.set(nullIndex);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
}
for(int i = nullIndex-1;i>=0;i--) {
if(!strategy.equals(keys[i], (byte)0)) {
entry.set(i);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
}
}
return null;
return Optional.empty();
}
@Override
@ -1077,7 +1079,7 @@ public class Byte2ObjectOpenCustomHashMap<V> extends AbstractByte2ObjectMap<V> i
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -1094,18 +1096,18 @@ public class Byte2ObjectOpenCustomHashMap<V> extends AbstractByte2ObjectMap<V> i
}
state = operator.applyAsByte(state, keys[i]);
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return (byte)0;
if(containsNull && filter.test(keys[nullIndex])) return keys[nullIndex];
if(size() <= 0) return OptionalByte.empty();
if(containsNull && filter.test(keys[nullIndex])) return OptionalByte.of(keys[nullIndex]);
for(int i = nullIndex-1;i>=0;i--) {
if(!strategy.equals(keys[i], (byte)0) && filter.test(keys[i])) return keys[i];
if(!strategy.equals(keys[i], (byte)0) && filter.test(keys[i])) return OptionalByte.of(keys[i]);
}
return (byte)0;
return OptionalByte.empty();
}
@Override
@ -1220,7 +1222,7 @@ public class Byte2ObjectOpenCustomHashMap<V> extends AbstractByte2ObjectMap<V> i
}
@Override
public V reduce(ObjectObjectUnaryOperator<V, V> operator) {
public Optional<V> reduce(ObjectObjectUnaryOperator<V, V> operator) {
Objects.requireNonNull(operator);
V state = null;
boolean empty = true;
@ -1237,18 +1239,18 @@ public class Byte2ObjectOpenCustomHashMap<V> extends AbstractByte2ObjectMap<V> i
}
state = operator.apply(state, values[i]);
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public V findFirst(Predicate<V> filter) {
public Optional<V> findFirst(Predicate<V> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return null;
if(containsNull && filter.test(values[nullIndex])) return values[nullIndex];
if(size() <= 0) return Optional.empty();
if(containsNull && filter.test(values[nullIndex])) return Optional.ofNullable(values[nullIndex]);
for(int i = nullIndex-1;i>=0;i--) {
if(!strategy.equals(keys[i], (byte)0) && filter.test(values[i])) return values[i];
if(!strategy.equals(keys[i], (byte)0) && filter.test(values[i])) return Optional.ofNullable(values[i]);
}
return null;
return Optional.empty();
}
@Override

View File

@ -4,6 +4,7 @@ import java.util.Arrays;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.BiFunction;
import java.util.function.Predicate;
@ -14,6 +15,7 @@ import speiger.src.collections.objects.functions.consumer.ObjectByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
import speiger.src.collections.ints.functions.consumer.IntShortConsumer;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.functions.function.BytePredicate;
import speiger.src.collections.bytes.functions.consumer.ByteShortConsumer;
import speiger.src.collections.bytes.functions.function.ByteByteUnaryOperator;
@ -33,6 +35,7 @@ import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer;
import speiger.src.collections.objects.functions.consumer.ObjectShortConsumer;
import speiger.src.collections.shorts.functions.function.ShortPredicate;
import speiger.src.collections.shorts.functions.OptionalShort;
import speiger.src.collections.objects.functions.function.ObjectObjectUnaryOperator;
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
import speiger.src.collections.objects.lists.ObjectListIterator;
@ -671,6 +674,10 @@ public class Byte2ShortLinkedOpenCustomHashMap extends Byte2ShortOpenCustomHashM
}
private class MapEntrySet extends AbstractObjectSet<Byte2ShortMap.Entry> implements Byte2ShortOrderedMap.FastOrderedSet {
@Override
public void addFirst(Byte2ShortMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(Byte2ShortMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(Byte2ShortMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
@ -836,7 +843,7 @@ public class Byte2ShortLinkedOpenCustomHashMap extends Byte2ShortOpenCustomHashM
}
@Override
public Byte2ShortMap.Entry reduce(ObjectObjectUnaryOperator<Byte2ShortMap.Entry, Byte2ShortMap.Entry> operator) {
public Optional<Byte2ShortMap.Entry> reduce(ObjectObjectUnaryOperator<Byte2ShortMap.Entry, Byte2ShortMap.Entry> operator) {
Objects.requireNonNull(operator);
Byte2ShortMap.Entry state = null;
boolean empty = true;
@ -851,21 +858,21 @@ public class Byte2ShortLinkedOpenCustomHashMap extends Byte2ShortOpenCustomHashM
state = operator.apply(state, new ValueMapEntry(index));
index = (int)links[index];
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public Byte2ShortMap.Entry findFirst(Predicate<Byte2ShortMap.Entry> filter) {
public Optional<Byte2ShortMap.Entry> findFirst(Predicate<Byte2ShortMap.Entry> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return null;
if(size() <= 0) return Optional.empty();
MapEntry entry = new MapEntry();
int index = firstIndex;
while(index != -1) {
entry.set(index);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
index = (int)links[index];
}
return null;
return Optional.empty();
}
@Override
@ -944,10 +951,13 @@ public class Byte2ShortLinkedOpenCustomHashMap extends Byte2ShortOpenCustomHashM
public boolean add(byte o) {
throw new UnsupportedOperationException();
}
@Override
public void addFirst(byte o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(byte o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(byte o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToLast(byte o) { throw new UnsupportedOperationException(); }
@ -1090,7 +1100,7 @@ public class Byte2ShortLinkedOpenCustomHashMap extends Byte2ShortOpenCustomHashM
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -1105,19 +1115,19 @@ public class Byte2ShortLinkedOpenCustomHashMap extends Byte2ShortOpenCustomHashM
state = operator.applyAsByte(state, keys[index]);
index = (int)links[index];
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return (byte)0;
if(size() <= 0) return OptionalByte.empty();
int index = firstIndex;
while(index != -1){
if(filter.test(keys[index])) return keys[index];
if(filter.test(keys[index])) return OptionalByte.of(keys[index]);
index = (int)links[index];
}
return (byte)0;
return OptionalByte.empty();
}
@Override
@ -1252,7 +1262,7 @@ public class Byte2ShortLinkedOpenCustomHashMap extends Byte2ShortOpenCustomHashM
}
@Override
public short reduce(ShortShortUnaryOperator operator) {
public OptionalShort reduce(ShortShortUnaryOperator operator) {
Objects.requireNonNull(operator);
short state = (short)0;
boolean empty = true;
@ -1267,19 +1277,19 @@ public class Byte2ShortLinkedOpenCustomHashMap extends Byte2ShortOpenCustomHashM
state = operator.applyAsShort(state, values[index]);
index = (int)links[index];
}
return state;
return empty ? OptionalShort.empty() : OptionalShort.of(state);
}
@Override
public short findFirst(ShortPredicate filter) {
public OptionalShort findFirst(ShortPredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return (short)0;
if(size() <= 0) return OptionalShort.empty();
int index = firstIndex;
while(index != -1){
if(filter.test(values[index])) return values[index];
if(filter.test(values[index])) return OptionalShort.of(values[index]);
index = (int)links[index];
}
return (short)0;
return OptionalShort.empty();
}
@Override

View File

@ -5,6 +5,7 @@ import java.util.ConcurrentModificationException;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.BiFunction;
import java.util.function.Predicate;
@ -19,6 +20,7 @@ import speiger.src.collections.bytes.functions.consumer.ByteShortConsumer;
import speiger.src.collections.bytes.functions.function.Byte2ShortFunction;
import speiger.src.collections.bytes.functions.function.ByteShortUnaryOperator;
import speiger.src.collections.bytes.functions.function.ByteByteUnaryOperator;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.functions.function.BytePredicate;
import speiger.src.collections.bytes.maps.abstracts.AbstractByte2ShortMap;
import speiger.src.collections.bytes.maps.interfaces.Byte2ShortMap;
@ -37,6 +39,7 @@ import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer;
import speiger.src.collections.objects.functions.consumer.ObjectShortConsumer;
import speiger.src.collections.shorts.functions.function.ShortPredicate;
import speiger.src.collections.shorts.functions.OptionalShort;
import speiger.src.collections.objects.collections.ObjectIterator;
import speiger.src.collections.objects.sets.AbstractObjectSet;
import speiger.src.collections.objects.sets.ObjectSet;
@ -952,7 +955,7 @@ public class Byte2ShortOpenCustomHashMap extends AbstractByte2ShortMap implement
}
@Override
public Byte2ShortMap.Entry reduce(ObjectObjectUnaryOperator<Byte2ShortMap.Entry, Byte2ShortMap.Entry> operator) {
public Optional<Byte2ShortMap.Entry> reduce(ObjectObjectUnaryOperator<Byte2ShortMap.Entry, Byte2ShortMap.Entry> operator) {
Objects.requireNonNull(operator);
Byte2ShortMap.Entry state = null;
boolean empty = true;
@ -969,25 +972,25 @@ public class Byte2ShortOpenCustomHashMap extends AbstractByte2ShortMap implement
}
state = operator.apply(state, new ValueMapEntry(i));
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public Byte2ShortMap.Entry findFirst(Predicate<Byte2ShortMap.Entry> filter) {
public Optional<Byte2ShortMap.Entry> findFirst(Predicate<Byte2ShortMap.Entry> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return null;
if(size() <= 0) return Optional.empty();
MapEntry entry = new MapEntry();
if(containsNull) {
entry.set(nullIndex);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
}
for(int i = nullIndex-1;i>=0;i--) {
if(!strategy.equals(keys[i], (byte)0)) {
entry.set(i);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
}
}
return null;
return Optional.empty();
}
@Override
@ -1161,7 +1164,7 @@ public class Byte2ShortOpenCustomHashMap extends AbstractByte2ShortMap implement
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -1178,18 +1181,18 @@ public class Byte2ShortOpenCustomHashMap extends AbstractByte2ShortMap implement
}
state = operator.applyAsByte(state, keys[i]);
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return (byte)0;
if(containsNull && filter.test(keys[nullIndex])) return keys[nullIndex];
if(size() <= 0) return OptionalByte.empty();
if(containsNull && filter.test(keys[nullIndex])) return OptionalByte.of(keys[nullIndex]);
for(int i = nullIndex-1;i>=0;i--) {
if(!strategy.equals(keys[i], (byte)0) && filter.test(keys[i])) return keys[i];
if(!strategy.equals(keys[i], (byte)0) && filter.test(keys[i])) return OptionalByte.of(keys[i]);
}
return (byte)0;
return OptionalByte.empty();
}
@Override
@ -1304,7 +1307,7 @@ public class Byte2ShortOpenCustomHashMap extends AbstractByte2ShortMap implement
}
@Override
public short reduce(ShortShortUnaryOperator operator) {
public OptionalShort reduce(ShortShortUnaryOperator operator) {
Objects.requireNonNull(operator);
short state = (short)0;
boolean empty = true;
@ -1321,18 +1324,18 @@ public class Byte2ShortOpenCustomHashMap extends AbstractByte2ShortMap implement
}
state = operator.applyAsShort(state, values[i]);
}
return state;
return empty ? OptionalShort.empty() : OptionalShort.of(state);
}
@Override
public short findFirst(ShortPredicate filter) {
public OptionalShort findFirst(ShortPredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return (short)0;
if(containsNull && filter.test(values[nullIndex])) return values[nullIndex];
if(size() <= 0) return OptionalShort.empty();
if(containsNull && filter.test(values[nullIndex])) return OptionalShort.of(values[nullIndex]);
for(int i = nullIndex-1;i>=0;i--) {
if(!strategy.equals(keys[i], (byte)0) && filter.test(values[i])) return values[i];
if(!strategy.equals(keys[i], (byte)0) && filter.test(values[i])) return OptionalShort.of(values[i]);
}
return (short)0;
return OptionalShort.empty();
}
@Override

View File

@ -4,6 +4,7 @@ import java.util.Arrays;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.BiFunction;
import java.util.function.Predicate;
@ -14,6 +15,7 @@ import speiger.src.collections.objects.functions.consumer.ObjectByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
import speiger.src.collections.ints.functions.consumer.IntBooleanConsumer;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.functions.function.BytePredicate;
import speiger.src.collections.bytes.functions.consumer.ByteBooleanConsumer;
import speiger.src.collections.bytes.functions.function.ByteByteUnaryOperator;
@ -32,6 +34,7 @@ import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer;
import speiger.src.collections.objects.functions.consumer.ObjectBooleanConsumer;
import speiger.src.collections.booleans.functions.function.BooleanPredicate;
import speiger.src.collections.booleans.functions.OptionalBoolean;
import speiger.src.collections.objects.functions.function.ObjectObjectUnaryOperator;
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
import speiger.src.collections.objects.lists.ObjectListIterator;
@ -669,6 +672,10 @@ public class Byte2BooleanLinkedOpenHashMap extends Byte2BooleanOpenHashMap imple
}
private class MapEntrySet extends AbstractObjectSet<Byte2BooleanMap.Entry> implements Byte2BooleanOrderedMap.FastOrderedSet {
@Override
public void addFirst(Byte2BooleanMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(Byte2BooleanMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(Byte2BooleanMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
@ -834,7 +841,7 @@ public class Byte2BooleanLinkedOpenHashMap extends Byte2BooleanOpenHashMap imple
}
@Override
public Byte2BooleanMap.Entry reduce(ObjectObjectUnaryOperator<Byte2BooleanMap.Entry, Byte2BooleanMap.Entry> operator) {
public Optional<Byte2BooleanMap.Entry> reduce(ObjectObjectUnaryOperator<Byte2BooleanMap.Entry, Byte2BooleanMap.Entry> operator) {
Objects.requireNonNull(operator);
Byte2BooleanMap.Entry state = null;
boolean empty = true;
@ -849,21 +856,21 @@ public class Byte2BooleanLinkedOpenHashMap extends Byte2BooleanOpenHashMap imple
state = operator.apply(state, new ValueMapEntry(index));
index = (int)links[index];
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public Byte2BooleanMap.Entry findFirst(Predicate<Byte2BooleanMap.Entry> filter) {
public Optional<Byte2BooleanMap.Entry> findFirst(Predicate<Byte2BooleanMap.Entry> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return null;
if(size() <= 0) return Optional.empty();
MapEntry entry = new MapEntry();
int index = firstIndex;
while(index != -1) {
entry.set(index);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
index = (int)links[index];
}
return null;
return Optional.empty();
}
@Override
@ -939,6 +946,12 @@ public class Byte2BooleanLinkedOpenHashMap extends Byte2BooleanOpenHashMap imple
@Override
public boolean add(byte o) { throw new UnsupportedOperationException(); }
@Override
public void addFirst(byte o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(byte o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(byte o) { throw new UnsupportedOperationException(); }
@ -1085,7 +1098,7 @@ public class Byte2BooleanLinkedOpenHashMap extends Byte2BooleanOpenHashMap imple
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -1100,19 +1113,19 @@ public class Byte2BooleanLinkedOpenHashMap extends Byte2BooleanOpenHashMap imple
state = operator.applyAsByte(state, keys[index]);
index = (int)links[index];
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return (byte)0;
if(size() <= 0) return OptionalByte.empty();
int index = firstIndex;
while(index != -1){
if(filter.test(keys[index])) return keys[index];
if(filter.test(keys[index])) return OptionalByte.of(keys[index]);
index = (int)links[index];
}
return (byte)0;
return OptionalByte.empty();
}
@Override
@ -1248,7 +1261,7 @@ public class Byte2BooleanLinkedOpenHashMap extends Byte2BooleanOpenHashMap imple
}
@Override
public boolean reduce(BooleanBooleanUnaryOperator operator) {
public OptionalBoolean reduce(BooleanBooleanUnaryOperator operator) {
Objects.requireNonNull(operator);
boolean state = false;
boolean empty = true;
@ -1263,19 +1276,19 @@ public class Byte2BooleanLinkedOpenHashMap extends Byte2BooleanOpenHashMap imple
state = operator.applyAsBoolean(state, values[index]);
index = (int)links[index];
}
return state;
return empty ? OptionalBoolean.empty() : OptionalBoolean.of(state);
}
@Override
public boolean findFirst(BooleanPredicate filter) {
public OptionalBoolean findFirst(BooleanPredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return false;
if(size() <= 0) return OptionalBoolean.empty();
int index = firstIndex;
while(index != -1){
if(filter.test(values[index])) return values[index];
if(filter.test(values[index])) return OptionalBoolean.of(values[index]);
index = (int)links[index];
}
return false;
return OptionalBoolean.empty();
}
@Override

View File

@ -5,6 +5,7 @@ import java.util.ConcurrentModificationException;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.BiFunction;
import java.util.function.Predicate;
@ -19,6 +20,7 @@ import speiger.src.collections.bytes.functions.consumer.ByteBooleanConsumer;
import speiger.src.collections.bytes.functions.function.BytePredicate;
import speiger.src.collections.bytes.functions.function.ByteBooleanUnaryOperator;
import speiger.src.collections.bytes.functions.function.ByteByteUnaryOperator;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.maps.abstracts.AbstractByte2BooleanMap;
import speiger.src.collections.bytes.maps.interfaces.Byte2BooleanMap;
import speiger.src.collections.bytes.sets.AbstractByteSet;
@ -33,6 +35,7 @@ import speiger.src.collections.booleans.functions.BooleanConsumer;
import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer;
import speiger.src.collections.objects.functions.consumer.ObjectBooleanConsumer;
import speiger.src.collections.booleans.functions.function.BooleanPredicate;
import speiger.src.collections.booleans.functions.OptionalBoolean;
import speiger.src.collections.objects.collections.ObjectIterator;
import speiger.src.collections.objects.sets.AbstractObjectSet;
import speiger.src.collections.objects.sets.ObjectSet;
@ -898,7 +901,7 @@ public class Byte2BooleanOpenHashMap extends AbstractByte2BooleanMap implements
}
@Override
public Byte2BooleanMap.Entry reduce(ObjectObjectUnaryOperator<Byte2BooleanMap.Entry, Byte2BooleanMap.Entry> operator) {
public Optional<Byte2BooleanMap.Entry> reduce(ObjectObjectUnaryOperator<Byte2BooleanMap.Entry, Byte2BooleanMap.Entry> operator) {
Objects.requireNonNull(operator);
Byte2BooleanMap.Entry state = null;
boolean empty = true;
@ -915,25 +918,25 @@ public class Byte2BooleanOpenHashMap extends AbstractByte2BooleanMap implements
}
state = operator.apply(state, new ValueMapEntry(i));
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public Byte2BooleanMap.Entry findFirst(Predicate<Byte2BooleanMap.Entry> filter) {
public Optional<Byte2BooleanMap.Entry> findFirst(Predicate<Byte2BooleanMap.Entry> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return null;
if(size() <= 0) return Optional.empty();
MapEntry entry = new MapEntry();
if(containsNull) {
entry.set(nullIndex);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
}
for(int i = nullIndex-1;i>=0;i--) {
if(keys[i] != (byte)0) {
entry.set(i);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
}
}
return null;
return Optional.empty();
}
@Override
@ -1105,7 +1108,7 @@ public class Byte2BooleanOpenHashMap extends AbstractByte2BooleanMap implements
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -1122,18 +1125,18 @@ public class Byte2BooleanOpenHashMap extends AbstractByte2BooleanMap implements
}
state = operator.applyAsByte(state, keys[i]);
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return (byte)0;
if(containsNull && filter.test(keys[nullIndex])) return keys[nullIndex];
if(size() <= 0) return OptionalByte.empty();
if(containsNull && filter.test(keys[nullIndex])) return OptionalByte.of(keys[nullIndex]);
for(int i = nullIndex-1;i>=0;i--) {
if(keys[i] != (byte)0 && filter.test(keys[i])) return keys[i];
if(keys[i] != (byte)0 && filter.test(keys[i])) return OptionalByte.of(keys[i]);
}
return (byte)0;
return OptionalByte.empty();
}
@Override
@ -1248,7 +1251,7 @@ public class Byte2BooleanOpenHashMap extends AbstractByte2BooleanMap implements
}
@Override
public boolean reduce(BooleanBooleanUnaryOperator operator) {
public OptionalBoolean reduce(BooleanBooleanUnaryOperator operator) {
Objects.requireNonNull(operator);
boolean state = false;
boolean empty = true;
@ -1265,18 +1268,18 @@ public class Byte2BooleanOpenHashMap extends AbstractByte2BooleanMap implements
}
state = operator.applyAsBoolean(state, values[i]);
}
return state;
return empty ? OptionalBoolean.empty() : OptionalBoolean.of(state);
}
@Override
public boolean findFirst(BooleanPredicate filter) {
public OptionalBoolean findFirst(BooleanPredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return false;
if(containsNull && filter.test(values[nullIndex])) return values[nullIndex];
if(size() <= 0) return OptionalBoolean.empty();
if(containsNull && filter.test(values[nullIndex])) return OptionalBoolean.of(values[nullIndex]);
for(int i = nullIndex-1;i>=0;i--) {
if(keys[i] != (byte)0 && filter.test(values[i])) return values[i];
if(keys[i] != (byte)0 && filter.test(values[i])) return OptionalBoolean.of(values[i]);
}
return false;
return OptionalBoolean.empty();
}
@Override

View File

@ -4,6 +4,7 @@ import java.util.Arrays;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.BiFunction;
import java.util.function.Predicate;
@ -13,6 +14,7 @@ import speiger.src.collections.bytes.functions.ByteConsumer;
import speiger.src.collections.objects.functions.consumer.ObjectByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.functions.function.BytePredicate;
import speiger.src.collections.bytes.functions.consumer.ByteByteConsumer;
import speiger.src.collections.bytes.functions.function.ByteByteUnaryOperator;
@ -662,6 +664,10 @@ public class Byte2ByteLinkedOpenHashMap extends Byte2ByteOpenHashMap implements
}
private class MapEntrySet extends AbstractObjectSet<Byte2ByteMap.Entry> implements Byte2ByteOrderedMap.FastOrderedSet {
@Override
public void addFirst(Byte2ByteMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(Byte2ByteMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(Byte2ByteMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
@ -827,7 +833,7 @@ public class Byte2ByteLinkedOpenHashMap extends Byte2ByteOpenHashMap implements
}
@Override
public Byte2ByteMap.Entry reduce(ObjectObjectUnaryOperator<Byte2ByteMap.Entry, Byte2ByteMap.Entry> operator) {
public Optional<Byte2ByteMap.Entry> reduce(ObjectObjectUnaryOperator<Byte2ByteMap.Entry, Byte2ByteMap.Entry> operator) {
Objects.requireNonNull(operator);
Byte2ByteMap.Entry state = null;
boolean empty = true;
@ -842,21 +848,21 @@ public class Byte2ByteLinkedOpenHashMap extends Byte2ByteOpenHashMap implements
state = operator.apply(state, new ValueMapEntry(index));
index = (int)links[index];
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public Byte2ByteMap.Entry findFirst(Predicate<Byte2ByteMap.Entry> filter) {
public Optional<Byte2ByteMap.Entry> findFirst(Predicate<Byte2ByteMap.Entry> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return null;
if(size() <= 0) return Optional.empty();
MapEntry entry = new MapEntry();
int index = firstIndex;
while(index != -1) {
entry.set(index);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
index = (int)links[index];
}
return null;
return Optional.empty();
}
@Override
@ -932,6 +938,12 @@ public class Byte2ByteLinkedOpenHashMap extends Byte2ByteOpenHashMap implements
@Override
public boolean add(byte o) { throw new UnsupportedOperationException(); }
@Override
public void addFirst(byte o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(byte o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(byte o) { throw new UnsupportedOperationException(); }
@ -1078,7 +1090,7 @@ public class Byte2ByteLinkedOpenHashMap extends Byte2ByteOpenHashMap implements
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -1093,19 +1105,19 @@ public class Byte2ByteLinkedOpenHashMap extends Byte2ByteOpenHashMap implements
state = operator.applyAsByte(state, keys[index]);
index = (int)links[index];
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return (byte)0;
if(size() <= 0) return OptionalByte.empty();
int index = firstIndex;
while(index != -1){
if(filter.test(keys[index])) return keys[index];
if(filter.test(keys[index])) return OptionalByte.of(keys[index]);
index = (int)links[index];
}
return (byte)0;
return OptionalByte.empty();
}
@Override
@ -1241,7 +1253,7 @@ public class Byte2ByteLinkedOpenHashMap extends Byte2ByteOpenHashMap implements
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -1256,19 +1268,19 @@ public class Byte2ByteLinkedOpenHashMap extends Byte2ByteOpenHashMap implements
state = operator.applyAsByte(state, values[index]);
index = (int)links[index];
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return (byte)0;
if(size() <= 0) return OptionalByte.empty();
int index = firstIndex;
while(index != -1){
if(filter.test(values[index])) return values[index];
if(filter.test(values[index])) return OptionalByte.of(values[index]);
index = (int)links[index];
}
return (byte)0;
return OptionalByte.empty();
}
@Override

View File

@ -5,6 +5,7 @@ import java.util.ConcurrentModificationException;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.BiFunction;
import java.util.function.Predicate;
@ -17,6 +18,7 @@ import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
import speiger.src.collections.bytes.functions.consumer.ByteByteConsumer;
import speiger.src.collections.bytes.functions.function.ByteUnaryOperator;
import speiger.src.collections.bytes.functions.function.ByteByteUnaryOperator;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.functions.function.BytePredicate;
import speiger.src.collections.bytes.maps.abstracts.AbstractByte2ByteMap;
import speiger.src.collections.bytes.maps.interfaces.Byte2ByteMap;
@ -914,7 +916,7 @@ public class Byte2ByteOpenHashMap extends AbstractByte2ByteMap implements ITrimm
}
@Override
public Byte2ByteMap.Entry reduce(ObjectObjectUnaryOperator<Byte2ByteMap.Entry, Byte2ByteMap.Entry> operator) {
public Optional<Byte2ByteMap.Entry> reduce(ObjectObjectUnaryOperator<Byte2ByteMap.Entry, Byte2ByteMap.Entry> operator) {
Objects.requireNonNull(operator);
Byte2ByteMap.Entry state = null;
boolean empty = true;
@ -931,25 +933,25 @@ public class Byte2ByteOpenHashMap extends AbstractByte2ByteMap implements ITrimm
}
state = operator.apply(state, new ValueMapEntry(i));
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public Byte2ByteMap.Entry findFirst(Predicate<Byte2ByteMap.Entry> filter) {
public Optional<Byte2ByteMap.Entry> findFirst(Predicate<Byte2ByteMap.Entry> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return null;
if(size() <= 0) return Optional.empty();
MapEntry entry = new MapEntry();
if(containsNull) {
entry.set(nullIndex);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
}
for(int i = nullIndex-1;i>=0;i--) {
if(keys[i] != (byte)0) {
entry.set(i);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
}
}
return null;
return Optional.empty();
}
@Override
@ -1121,7 +1123,7 @@ public class Byte2ByteOpenHashMap extends AbstractByte2ByteMap implements ITrimm
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -1138,18 +1140,18 @@ public class Byte2ByteOpenHashMap extends AbstractByte2ByteMap implements ITrimm
}
state = operator.applyAsByte(state, keys[i]);
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return (byte)0;
if(containsNull && filter.test(keys[nullIndex])) return keys[nullIndex];
if(size() <= 0) return OptionalByte.empty();
if(containsNull && filter.test(keys[nullIndex])) return OptionalByte.of(keys[nullIndex]);
for(int i = nullIndex-1;i>=0;i--) {
if(keys[i] != (byte)0 && filter.test(keys[i])) return keys[i];
if(keys[i] != (byte)0 && filter.test(keys[i])) return OptionalByte.of(keys[i]);
}
return (byte)0;
return OptionalByte.empty();
}
@Override
@ -1264,7 +1266,7 @@ public class Byte2ByteOpenHashMap extends AbstractByte2ByteMap implements ITrimm
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -1281,18 +1283,18 @@ public class Byte2ByteOpenHashMap extends AbstractByte2ByteMap implements ITrimm
}
state = operator.applyAsByte(state, values[i]);
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return (byte)0;
if(containsNull && filter.test(values[nullIndex])) return values[nullIndex];
if(size() <= 0) return OptionalByte.empty();
if(containsNull && filter.test(values[nullIndex])) return OptionalByte.of(values[nullIndex]);
for(int i = nullIndex-1;i>=0;i--) {
if(keys[i] != (byte)0 && filter.test(values[i])) return values[i];
if(keys[i] != (byte)0 && filter.test(values[i])) return OptionalByte.of(values[i]);
}
return (byte)0;
return OptionalByte.empty();
}
@Override

View File

@ -4,6 +4,7 @@ import java.util.Arrays;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.BiFunction;
import java.util.function.Predicate;
@ -14,6 +15,7 @@ import speiger.src.collections.objects.functions.consumer.ObjectByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
import speiger.src.collections.ints.functions.consumer.IntCharConsumer;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.functions.function.BytePredicate;
import speiger.src.collections.bytes.functions.consumer.ByteCharConsumer;
import speiger.src.collections.bytes.functions.function.ByteByteUnaryOperator;
@ -32,6 +34,7 @@ import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer;
import speiger.src.collections.objects.functions.consumer.ObjectCharConsumer;
import speiger.src.collections.chars.functions.function.CharPredicate;
import speiger.src.collections.chars.functions.OptionalChar;
import speiger.src.collections.objects.functions.function.ObjectObjectUnaryOperator;
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
import speiger.src.collections.objects.lists.ObjectListIterator;
@ -669,6 +672,10 @@ public class Byte2CharLinkedOpenHashMap extends Byte2CharOpenHashMap implements
}
private class MapEntrySet extends AbstractObjectSet<Byte2CharMap.Entry> implements Byte2CharOrderedMap.FastOrderedSet {
@Override
public void addFirst(Byte2CharMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(Byte2CharMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(Byte2CharMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
@ -834,7 +841,7 @@ public class Byte2CharLinkedOpenHashMap extends Byte2CharOpenHashMap implements
}
@Override
public Byte2CharMap.Entry reduce(ObjectObjectUnaryOperator<Byte2CharMap.Entry, Byte2CharMap.Entry> operator) {
public Optional<Byte2CharMap.Entry> reduce(ObjectObjectUnaryOperator<Byte2CharMap.Entry, Byte2CharMap.Entry> operator) {
Objects.requireNonNull(operator);
Byte2CharMap.Entry state = null;
boolean empty = true;
@ -849,21 +856,21 @@ public class Byte2CharLinkedOpenHashMap extends Byte2CharOpenHashMap implements
state = operator.apply(state, new ValueMapEntry(index));
index = (int)links[index];
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public Byte2CharMap.Entry findFirst(Predicate<Byte2CharMap.Entry> filter) {
public Optional<Byte2CharMap.Entry> findFirst(Predicate<Byte2CharMap.Entry> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return null;
if(size() <= 0) return Optional.empty();
MapEntry entry = new MapEntry();
int index = firstIndex;
while(index != -1) {
entry.set(index);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
index = (int)links[index];
}
return null;
return Optional.empty();
}
@Override
@ -939,6 +946,12 @@ public class Byte2CharLinkedOpenHashMap extends Byte2CharOpenHashMap implements
@Override
public boolean add(byte o) { throw new UnsupportedOperationException(); }
@Override
public void addFirst(byte o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(byte o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(byte o) { throw new UnsupportedOperationException(); }
@ -1085,7 +1098,7 @@ public class Byte2CharLinkedOpenHashMap extends Byte2CharOpenHashMap implements
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -1100,19 +1113,19 @@ public class Byte2CharLinkedOpenHashMap extends Byte2CharOpenHashMap implements
state = operator.applyAsByte(state, keys[index]);
index = (int)links[index];
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return (byte)0;
if(size() <= 0) return OptionalByte.empty();
int index = firstIndex;
while(index != -1){
if(filter.test(keys[index])) return keys[index];
if(filter.test(keys[index])) return OptionalByte.of(keys[index]);
index = (int)links[index];
}
return (byte)0;
return OptionalByte.empty();
}
@Override
@ -1248,7 +1261,7 @@ public class Byte2CharLinkedOpenHashMap extends Byte2CharOpenHashMap implements
}
@Override
public char reduce(CharCharUnaryOperator operator) {
public OptionalChar reduce(CharCharUnaryOperator operator) {
Objects.requireNonNull(operator);
char state = (char)0;
boolean empty = true;
@ -1263,19 +1276,19 @@ public class Byte2CharLinkedOpenHashMap extends Byte2CharOpenHashMap implements
state = operator.applyAsChar(state, values[index]);
index = (int)links[index];
}
return state;
return empty ? OptionalChar.empty() : OptionalChar.of(state);
}
@Override
public char findFirst(CharPredicate filter) {
public OptionalChar findFirst(CharPredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return (char)0;
if(size() <= 0) return OptionalChar.empty();
int index = firstIndex;
while(index != -1){
if(filter.test(values[index])) return values[index];
if(filter.test(values[index])) return OptionalChar.of(values[index]);
index = (int)links[index];
}
return (char)0;
return OptionalChar.empty();
}
@Override

View File

@ -5,6 +5,7 @@ import java.util.ConcurrentModificationException;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.BiFunction;
import java.util.function.Predicate;
@ -19,6 +20,7 @@ import speiger.src.collections.bytes.functions.consumer.ByteCharConsumer;
import speiger.src.collections.bytes.functions.function.Byte2CharFunction;
import speiger.src.collections.bytes.functions.function.ByteCharUnaryOperator;
import speiger.src.collections.bytes.functions.function.ByteByteUnaryOperator;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.functions.function.BytePredicate;
import speiger.src.collections.bytes.maps.abstracts.AbstractByte2CharMap;
import speiger.src.collections.bytes.maps.interfaces.Byte2CharMap;
@ -34,6 +36,7 @@ import speiger.src.collections.chars.functions.CharConsumer;
import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer;
import speiger.src.collections.objects.functions.consumer.ObjectCharConsumer;
import speiger.src.collections.chars.functions.function.CharPredicate;
import speiger.src.collections.chars.functions.OptionalChar;
import speiger.src.collections.objects.collections.ObjectIterator;
import speiger.src.collections.objects.sets.AbstractObjectSet;
import speiger.src.collections.objects.sets.ObjectSet;
@ -920,7 +923,7 @@ public class Byte2CharOpenHashMap extends AbstractByte2CharMap implements ITrimm
}
@Override
public Byte2CharMap.Entry reduce(ObjectObjectUnaryOperator<Byte2CharMap.Entry, Byte2CharMap.Entry> operator) {
public Optional<Byte2CharMap.Entry> reduce(ObjectObjectUnaryOperator<Byte2CharMap.Entry, Byte2CharMap.Entry> operator) {
Objects.requireNonNull(operator);
Byte2CharMap.Entry state = null;
boolean empty = true;
@ -937,25 +940,25 @@ public class Byte2CharOpenHashMap extends AbstractByte2CharMap implements ITrimm
}
state = operator.apply(state, new ValueMapEntry(i));
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public Byte2CharMap.Entry findFirst(Predicate<Byte2CharMap.Entry> filter) {
public Optional<Byte2CharMap.Entry> findFirst(Predicate<Byte2CharMap.Entry> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return null;
if(size() <= 0) return Optional.empty();
MapEntry entry = new MapEntry();
if(containsNull) {
entry.set(nullIndex);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
}
for(int i = nullIndex-1;i>=0;i--) {
if(keys[i] != (byte)0) {
entry.set(i);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
}
}
return null;
return Optional.empty();
}
@Override
@ -1127,7 +1130,7 @@ public class Byte2CharOpenHashMap extends AbstractByte2CharMap implements ITrimm
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -1144,18 +1147,18 @@ public class Byte2CharOpenHashMap extends AbstractByte2CharMap implements ITrimm
}
state = operator.applyAsByte(state, keys[i]);
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return (byte)0;
if(containsNull && filter.test(keys[nullIndex])) return keys[nullIndex];
if(size() <= 0) return OptionalByte.empty();
if(containsNull && filter.test(keys[nullIndex])) return OptionalByte.of(keys[nullIndex]);
for(int i = nullIndex-1;i>=0;i--) {
if(keys[i] != (byte)0 && filter.test(keys[i])) return keys[i];
if(keys[i] != (byte)0 && filter.test(keys[i])) return OptionalByte.of(keys[i]);
}
return (byte)0;
return OptionalByte.empty();
}
@Override
@ -1270,7 +1273,7 @@ public class Byte2CharOpenHashMap extends AbstractByte2CharMap implements ITrimm
}
@Override
public char reduce(CharCharUnaryOperator operator) {
public OptionalChar reduce(CharCharUnaryOperator operator) {
Objects.requireNonNull(operator);
char state = (char)0;
boolean empty = true;
@ -1287,18 +1290,18 @@ public class Byte2CharOpenHashMap extends AbstractByte2CharMap implements ITrimm
}
state = operator.applyAsChar(state, values[i]);
}
return state;
return empty ? OptionalChar.empty() : OptionalChar.of(state);
}
@Override
public char findFirst(CharPredicate filter) {
public OptionalChar findFirst(CharPredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return (char)0;
if(containsNull && filter.test(values[nullIndex])) return values[nullIndex];
if(size() <= 0) return OptionalChar.empty();
if(containsNull && filter.test(values[nullIndex])) return OptionalChar.of(values[nullIndex]);
for(int i = nullIndex-1;i>=0;i--) {
if(keys[i] != (byte)0 && filter.test(values[i])) return values[i];
if(keys[i] != (byte)0 && filter.test(values[i])) return OptionalChar.of(values[i]);
}
return (char)0;
return OptionalChar.empty();
}
@Override

View File

@ -4,10 +4,12 @@ import java.util.Arrays;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.BiFunction;
import java.util.function.Predicate;
import java.util.function.DoublePredicate;
import java.util.OptionalDouble;
import speiger.src.collections.bytes.collections.ByteBidirectionalIterator;
import speiger.src.collections.bytes.functions.ByteConsumer;
@ -15,6 +17,7 @@ import speiger.src.collections.objects.functions.consumer.ObjectByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
import speiger.src.collections.ints.functions.consumer.IntDoubleConsumer;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.functions.function.BytePredicate;
import speiger.src.collections.bytes.functions.consumer.ByteDoubleConsumer;
import speiger.src.collections.bytes.functions.function.ByteByteUnaryOperator;
@ -669,6 +672,10 @@ public class Byte2DoubleLinkedOpenHashMap extends Byte2DoubleOpenHashMap impleme
}
private class MapEntrySet extends AbstractObjectSet<Byte2DoubleMap.Entry> implements Byte2DoubleOrderedMap.FastOrderedSet {
@Override
public void addFirst(Byte2DoubleMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(Byte2DoubleMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(Byte2DoubleMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
@ -834,7 +841,7 @@ public class Byte2DoubleLinkedOpenHashMap extends Byte2DoubleOpenHashMap impleme
}
@Override
public Byte2DoubleMap.Entry reduce(ObjectObjectUnaryOperator<Byte2DoubleMap.Entry, Byte2DoubleMap.Entry> operator) {
public Optional<Byte2DoubleMap.Entry> reduce(ObjectObjectUnaryOperator<Byte2DoubleMap.Entry, Byte2DoubleMap.Entry> operator) {
Objects.requireNonNull(operator);
Byte2DoubleMap.Entry state = null;
boolean empty = true;
@ -849,21 +856,21 @@ public class Byte2DoubleLinkedOpenHashMap extends Byte2DoubleOpenHashMap impleme
state = operator.apply(state, new ValueMapEntry(index));
index = (int)links[index];
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public Byte2DoubleMap.Entry findFirst(Predicate<Byte2DoubleMap.Entry> filter) {
public Optional<Byte2DoubleMap.Entry> findFirst(Predicate<Byte2DoubleMap.Entry> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return null;
if(size() <= 0) return Optional.empty();
MapEntry entry = new MapEntry();
int index = firstIndex;
while(index != -1) {
entry.set(index);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
index = (int)links[index];
}
return null;
return Optional.empty();
}
@Override
@ -939,6 +946,12 @@ public class Byte2DoubleLinkedOpenHashMap extends Byte2DoubleOpenHashMap impleme
@Override
public boolean add(byte o) { throw new UnsupportedOperationException(); }
@Override
public void addFirst(byte o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(byte o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(byte o) { throw new UnsupportedOperationException(); }
@ -1085,7 +1098,7 @@ public class Byte2DoubleLinkedOpenHashMap extends Byte2DoubleOpenHashMap impleme
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -1100,19 +1113,19 @@ public class Byte2DoubleLinkedOpenHashMap extends Byte2DoubleOpenHashMap impleme
state = operator.applyAsByte(state, keys[index]);
index = (int)links[index];
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return (byte)0;
if(size() <= 0) return OptionalByte.empty();
int index = firstIndex;
while(index != -1){
if(filter.test(keys[index])) return keys[index];
if(filter.test(keys[index])) return OptionalByte.of(keys[index]);
index = (int)links[index];
}
return (byte)0;
return OptionalByte.empty();
}
@Override
@ -1248,7 +1261,7 @@ public class Byte2DoubleLinkedOpenHashMap extends Byte2DoubleOpenHashMap impleme
}
@Override
public double reduce(DoubleDoubleUnaryOperator operator) {
public OptionalDouble reduce(DoubleDoubleUnaryOperator operator) {
Objects.requireNonNull(operator);
double state = 0D;
boolean empty = true;
@ -1263,19 +1276,19 @@ public class Byte2DoubleLinkedOpenHashMap extends Byte2DoubleOpenHashMap impleme
state = operator.applyAsDouble(state, values[index]);
index = (int)links[index];
}
return state;
return empty ? OptionalDouble.empty() : OptionalDouble.of(state);
}
@Override
public double findFirst(DoublePredicate filter) {
public OptionalDouble findFirst(DoublePredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return 0D;
if(size() <= 0) return OptionalDouble.empty();
int index = firstIndex;
while(index != -1){
if(filter.test(values[index])) return values[index];
if(filter.test(values[index])) return OptionalDouble.of(values[index]);
index = (int)links[index];
}
return 0D;
return OptionalDouble.empty();
}
@Override

View File

@ -5,10 +5,12 @@ import java.util.ConcurrentModificationException;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.BiFunction;
import java.util.function.Predicate;
import java.util.function.DoublePredicate;
import java.util.OptionalDouble;
import speiger.src.collections.bytes.collections.ByteIterator;
import speiger.src.collections.bytes.functions.ByteConsumer;
@ -20,6 +22,7 @@ import speiger.src.collections.bytes.functions.consumer.ByteDoubleConsumer;
import speiger.src.collections.bytes.functions.function.Byte2DoubleFunction;
import speiger.src.collections.bytes.functions.function.ByteDoubleUnaryOperator;
import speiger.src.collections.bytes.functions.function.ByteByteUnaryOperator;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.functions.function.BytePredicate;
import speiger.src.collections.bytes.maps.abstracts.AbstractByte2DoubleMap;
import speiger.src.collections.bytes.maps.interfaces.Byte2DoubleMap;
@ -920,7 +923,7 @@ public class Byte2DoubleOpenHashMap extends AbstractByte2DoubleMap implements IT
}
@Override
public Byte2DoubleMap.Entry reduce(ObjectObjectUnaryOperator<Byte2DoubleMap.Entry, Byte2DoubleMap.Entry> operator) {
public Optional<Byte2DoubleMap.Entry> reduce(ObjectObjectUnaryOperator<Byte2DoubleMap.Entry, Byte2DoubleMap.Entry> operator) {
Objects.requireNonNull(operator);
Byte2DoubleMap.Entry state = null;
boolean empty = true;
@ -937,25 +940,25 @@ public class Byte2DoubleOpenHashMap extends AbstractByte2DoubleMap implements IT
}
state = operator.apply(state, new ValueMapEntry(i));
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public Byte2DoubleMap.Entry findFirst(Predicate<Byte2DoubleMap.Entry> filter) {
public Optional<Byte2DoubleMap.Entry> findFirst(Predicate<Byte2DoubleMap.Entry> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return null;
if(size() <= 0) return Optional.empty();
MapEntry entry = new MapEntry();
if(containsNull) {
entry.set(nullIndex);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
}
for(int i = nullIndex-1;i>=0;i--) {
if(keys[i] != (byte)0) {
entry.set(i);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
}
}
return null;
return Optional.empty();
}
@Override
@ -1127,7 +1130,7 @@ public class Byte2DoubleOpenHashMap extends AbstractByte2DoubleMap implements IT
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -1144,18 +1147,18 @@ public class Byte2DoubleOpenHashMap extends AbstractByte2DoubleMap implements IT
}
state = operator.applyAsByte(state, keys[i]);
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return (byte)0;
if(containsNull && filter.test(keys[nullIndex])) return keys[nullIndex];
if(size() <= 0) return OptionalByte.empty();
if(containsNull && filter.test(keys[nullIndex])) return OptionalByte.of(keys[nullIndex]);
for(int i = nullIndex-1;i>=0;i--) {
if(keys[i] != (byte)0 && filter.test(keys[i])) return keys[i];
if(keys[i] != (byte)0 && filter.test(keys[i])) return OptionalByte.of(keys[i]);
}
return (byte)0;
return OptionalByte.empty();
}
@Override
@ -1270,7 +1273,7 @@ public class Byte2DoubleOpenHashMap extends AbstractByte2DoubleMap implements IT
}
@Override
public double reduce(DoubleDoubleUnaryOperator operator) {
public OptionalDouble reduce(DoubleDoubleUnaryOperator operator) {
Objects.requireNonNull(operator);
double state = 0D;
boolean empty = true;
@ -1287,18 +1290,18 @@ public class Byte2DoubleOpenHashMap extends AbstractByte2DoubleMap implements IT
}
state = operator.applyAsDouble(state, values[i]);
}
return state;
return empty ? OptionalDouble.empty() : OptionalDouble.of(state);
}
@Override
public double findFirst(DoublePredicate filter) {
public OptionalDouble findFirst(DoublePredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return 0D;
if(containsNull && filter.test(values[nullIndex])) return values[nullIndex];
if(size() <= 0) return OptionalDouble.empty();
if(containsNull && filter.test(values[nullIndex])) return OptionalDouble.of(values[nullIndex]);
for(int i = nullIndex-1;i>=0;i--) {
if(keys[i] != (byte)0 && filter.test(values[i])) return values[i];
if(keys[i] != (byte)0 && filter.test(values[i])) return OptionalDouble.of(values[i]);
}
return 0D;
return OptionalDouble.empty();
}
@Override

View File

@ -4,6 +4,7 @@ import java.util.Arrays;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.BiFunction;
import java.util.function.Predicate;
@ -14,6 +15,7 @@ import speiger.src.collections.objects.functions.consumer.ObjectByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
import speiger.src.collections.ints.functions.consumer.IntFloatConsumer;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.functions.function.BytePredicate;
import speiger.src.collections.bytes.functions.consumer.ByteFloatConsumer;
import speiger.src.collections.bytes.functions.function.ByteByteUnaryOperator;
@ -32,6 +34,7 @@ import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer;
import speiger.src.collections.objects.functions.consumer.ObjectFloatConsumer;
import speiger.src.collections.floats.functions.function.FloatPredicate;
import speiger.src.collections.floats.functions.OptionalFloat;
import speiger.src.collections.objects.functions.function.ObjectObjectUnaryOperator;
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
import speiger.src.collections.objects.lists.ObjectListIterator;
@ -669,6 +672,10 @@ public class Byte2FloatLinkedOpenHashMap extends Byte2FloatOpenHashMap implement
}
private class MapEntrySet extends AbstractObjectSet<Byte2FloatMap.Entry> implements Byte2FloatOrderedMap.FastOrderedSet {
@Override
public void addFirst(Byte2FloatMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(Byte2FloatMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(Byte2FloatMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
@ -834,7 +841,7 @@ public class Byte2FloatLinkedOpenHashMap extends Byte2FloatOpenHashMap implement
}
@Override
public Byte2FloatMap.Entry reduce(ObjectObjectUnaryOperator<Byte2FloatMap.Entry, Byte2FloatMap.Entry> operator) {
public Optional<Byte2FloatMap.Entry> reduce(ObjectObjectUnaryOperator<Byte2FloatMap.Entry, Byte2FloatMap.Entry> operator) {
Objects.requireNonNull(operator);
Byte2FloatMap.Entry state = null;
boolean empty = true;
@ -849,21 +856,21 @@ public class Byte2FloatLinkedOpenHashMap extends Byte2FloatOpenHashMap implement
state = operator.apply(state, new ValueMapEntry(index));
index = (int)links[index];
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public Byte2FloatMap.Entry findFirst(Predicate<Byte2FloatMap.Entry> filter) {
public Optional<Byte2FloatMap.Entry> findFirst(Predicate<Byte2FloatMap.Entry> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return null;
if(size() <= 0) return Optional.empty();
MapEntry entry = new MapEntry();
int index = firstIndex;
while(index != -1) {
entry.set(index);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
index = (int)links[index];
}
return null;
return Optional.empty();
}
@Override
@ -939,6 +946,12 @@ public class Byte2FloatLinkedOpenHashMap extends Byte2FloatOpenHashMap implement
@Override
public boolean add(byte o) { throw new UnsupportedOperationException(); }
@Override
public void addFirst(byte o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(byte o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(byte o) { throw new UnsupportedOperationException(); }
@ -1085,7 +1098,7 @@ public class Byte2FloatLinkedOpenHashMap extends Byte2FloatOpenHashMap implement
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -1100,19 +1113,19 @@ public class Byte2FloatLinkedOpenHashMap extends Byte2FloatOpenHashMap implement
state = operator.applyAsByte(state, keys[index]);
index = (int)links[index];
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return (byte)0;
if(size() <= 0) return OptionalByte.empty();
int index = firstIndex;
while(index != -1){
if(filter.test(keys[index])) return keys[index];
if(filter.test(keys[index])) return OptionalByte.of(keys[index]);
index = (int)links[index];
}
return (byte)0;
return OptionalByte.empty();
}
@Override
@ -1248,7 +1261,7 @@ public class Byte2FloatLinkedOpenHashMap extends Byte2FloatOpenHashMap implement
}
@Override
public float reduce(FloatFloatUnaryOperator operator) {
public OptionalFloat reduce(FloatFloatUnaryOperator operator) {
Objects.requireNonNull(operator);
float state = 0F;
boolean empty = true;
@ -1263,19 +1276,19 @@ public class Byte2FloatLinkedOpenHashMap extends Byte2FloatOpenHashMap implement
state = operator.applyAsFloat(state, values[index]);
index = (int)links[index];
}
return state;
return empty ? OptionalFloat.empty() : OptionalFloat.of(state);
}
@Override
public float findFirst(FloatPredicate filter) {
public OptionalFloat findFirst(FloatPredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return 0F;
if(size() <= 0) return OptionalFloat.empty();
int index = firstIndex;
while(index != -1){
if(filter.test(values[index])) return values[index];
if(filter.test(values[index])) return OptionalFloat.of(values[index]);
index = (int)links[index];
}
return 0F;
return OptionalFloat.empty();
}
@Override

View File

@ -5,6 +5,7 @@ import java.util.ConcurrentModificationException;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.BiFunction;
import java.util.function.Predicate;
@ -19,6 +20,7 @@ import speiger.src.collections.bytes.functions.consumer.ByteFloatConsumer;
import speiger.src.collections.bytes.functions.function.Byte2FloatFunction;
import speiger.src.collections.bytes.functions.function.ByteFloatUnaryOperator;
import speiger.src.collections.bytes.functions.function.ByteByteUnaryOperator;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.functions.function.BytePredicate;
import speiger.src.collections.bytes.maps.abstracts.AbstractByte2FloatMap;
import speiger.src.collections.bytes.maps.interfaces.Byte2FloatMap;
@ -34,6 +36,7 @@ import speiger.src.collections.floats.functions.FloatConsumer;
import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer;
import speiger.src.collections.objects.functions.consumer.ObjectFloatConsumer;
import speiger.src.collections.floats.functions.function.FloatPredicate;
import speiger.src.collections.floats.functions.OptionalFloat;
import speiger.src.collections.objects.collections.ObjectIterator;
import speiger.src.collections.objects.sets.AbstractObjectSet;
import speiger.src.collections.objects.sets.ObjectSet;
@ -920,7 +923,7 @@ public class Byte2FloatOpenHashMap extends AbstractByte2FloatMap implements ITri
}
@Override
public Byte2FloatMap.Entry reduce(ObjectObjectUnaryOperator<Byte2FloatMap.Entry, Byte2FloatMap.Entry> operator) {
public Optional<Byte2FloatMap.Entry> reduce(ObjectObjectUnaryOperator<Byte2FloatMap.Entry, Byte2FloatMap.Entry> operator) {
Objects.requireNonNull(operator);
Byte2FloatMap.Entry state = null;
boolean empty = true;
@ -937,25 +940,25 @@ public class Byte2FloatOpenHashMap extends AbstractByte2FloatMap implements ITri
}
state = operator.apply(state, new ValueMapEntry(i));
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public Byte2FloatMap.Entry findFirst(Predicate<Byte2FloatMap.Entry> filter) {
public Optional<Byte2FloatMap.Entry> findFirst(Predicate<Byte2FloatMap.Entry> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return null;
if(size() <= 0) return Optional.empty();
MapEntry entry = new MapEntry();
if(containsNull) {
entry.set(nullIndex);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
}
for(int i = nullIndex-1;i>=0;i--) {
if(keys[i] != (byte)0) {
entry.set(i);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
}
}
return null;
return Optional.empty();
}
@Override
@ -1127,7 +1130,7 @@ public class Byte2FloatOpenHashMap extends AbstractByte2FloatMap implements ITri
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -1144,18 +1147,18 @@ public class Byte2FloatOpenHashMap extends AbstractByte2FloatMap implements ITri
}
state = operator.applyAsByte(state, keys[i]);
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return (byte)0;
if(containsNull && filter.test(keys[nullIndex])) return keys[nullIndex];
if(size() <= 0) return OptionalByte.empty();
if(containsNull && filter.test(keys[nullIndex])) return OptionalByte.of(keys[nullIndex]);
for(int i = nullIndex-1;i>=0;i--) {
if(keys[i] != (byte)0 && filter.test(keys[i])) return keys[i];
if(keys[i] != (byte)0 && filter.test(keys[i])) return OptionalByte.of(keys[i]);
}
return (byte)0;
return OptionalByte.empty();
}
@Override
@ -1270,7 +1273,7 @@ public class Byte2FloatOpenHashMap extends AbstractByte2FloatMap implements ITri
}
@Override
public float reduce(FloatFloatUnaryOperator operator) {
public OptionalFloat reduce(FloatFloatUnaryOperator operator) {
Objects.requireNonNull(operator);
float state = 0F;
boolean empty = true;
@ -1287,18 +1290,18 @@ public class Byte2FloatOpenHashMap extends AbstractByte2FloatMap implements ITri
}
state = operator.applyAsFloat(state, values[i]);
}
return state;
return empty ? OptionalFloat.empty() : OptionalFloat.of(state);
}
@Override
public float findFirst(FloatPredicate filter) {
public OptionalFloat findFirst(FloatPredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return 0F;
if(containsNull && filter.test(values[nullIndex])) return values[nullIndex];
if(size() <= 0) return OptionalFloat.empty();
if(containsNull && filter.test(values[nullIndex])) return OptionalFloat.of(values[nullIndex]);
for(int i = nullIndex-1;i>=0;i--) {
if(keys[i] != (byte)0 && filter.test(values[i])) return values[i];
if(keys[i] != (byte)0 && filter.test(values[i])) return OptionalFloat.of(values[i]);
}
return 0F;
return OptionalFloat.empty();
}
@Override

View File

@ -4,10 +4,12 @@ import java.util.Arrays;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.BiFunction;
import java.util.function.Predicate;
import java.util.function.IntPredicate;
import java.util.OptionalInt;
import speiger.src.collections.bytes.collections.ByteBidirectionalIterator;
import speiger.src.collections.bytes.functions.ByteConsumer;
@ -15,6 +17,7 @@ import speiger.src.collections.objects.functions.consumer.ObjectByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
import speiger.src.collections.ints.functions.consumer.IntIntConsumer;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.functions.function.BytePredicate;
import speiger.src.collections.bytes.functions.consumer.ByteIntConsumer;
import speiger.src.collections.bytes.functions.function.ByteByteUnaryOperator;
@ -669,6 +672,10 @@ public class Byte2IntLinkedOpenHashMap extends Byte2IntOpenHashMap implements By
}
private class MapEntrySet extends AbstractObjectSet<Byte2IntMap.Entry> implements Byte2IntOrderedMap.FastOrderedSet {
@Override
public void addFirst(Byte2IntMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(Byte2IntMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(Byte2IntMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
@ -834,7 +841,7 @@ public class Byte2IntLinkedOpenHashMap extends Byte2IntOpenHashMap implements By
}
@Override
public Byte2IntMap.Entry reduce(ObjectObjectUnaryOperator<Byte2IntMap.Entry, Byte2IntMap.Entry> operator) {
public Optional<Byte2IntMap.Entry> reduce(ObjectObjectUnaryOperator<Byte2IntMap.Entry, Byte2IntMap.Entry> operator) {
Objects.requireNonNull(operator);
Byte2IntMap.Entry state = null;
boolean empty = true;
@ -849,21 +856,21 @@ public class Byte2IntLinkedOpenHashMap extends Byte2IntOpenHashMap implements By
state = operator.apply(state, new ValueMapEntry(index));
index = (int)links[index];
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public Byte2IntMap.Entry findFirst(Predicate<Byte2IntMap.Entry> filter) {
public Optional<Byte2IntMap.Entry> findFirst(Predicate<Byte2IntMap.Entry> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return null;
if(size() <= 0) return Optional.empty();
MapEntry entry = new MapEntry();
int index = firstIndex;
while(index != -1) {
entry.set(index);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
index = (int)links[index];
}
return null;
return Optional.empty();
}
@Override
@ -939,6 +946,12 @@ public class Byte2IntLinkedOpenHashMap extends Byte2IntOpenHashMap implements By
@Override
public boolean add(byte o) { throw new UnsupportedOperationException(); }
@Override
public void addFirst(byte o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(byte o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(byte o) { throw new UnsupportedOperationException(); }
@ -1085,7 +1098,7 @@ public class Byte2IntLinkedOpenHashMap extends Byte2IntOpenHashMap implements By
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -1100,19 +1113,19 @@ public class Byte2IntLinkedOpenHashMap extends Byte2IntOpenHashMap implements By
state = operator.applyAsByte(state, keys[index]);
index = (int)links[index];
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return (byte)0;
if(size() <= 0) return OptionalByte.empty();
int index = firstIndex;
while(index != -1){
if(filter.test(keys[index])) return keys[index];
if(filter.test(keys[index])) return OptionalByte.of(keys[index]);
index = (int)links[index];
}
return (byte)0;
return OptionalByte.empty();
}
@Override
@ -1248,7 +1261,7 @@ public class Byte2IntLinkedOpenHashMap extends Byte2IntOpenHashMap implements By
}
@Override
public int reduce(IntIntUnaryOperator operator) {
public OptionalInt reduce(IntIntUnaryOperator operator) {
Objects.requireNonNull(operator);
int state = 0;
boolean empty = true;
@ -1263,19 +1276,19 @@ public class Byte2IntLinkedOpenHashMap extends Byte2IntOpenHashMap implements By
state = operator.applyAsInt(state, values[index]);
index = (int)links[index];
}
return state;
return empty ? OptionalInt.empty() : OptionalInt.of(state);
}
@Override
public int findFirst(IntPredicate filter) {
public OptionalInt findFirst(IntPredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return 0;
if(size() <= 0) return OptionalInt.empty();
int index = firstIndex;
while(index != -1){
if(filter.test(values[index])) return values[index];
if(filter.test(values[index])) return OptionalInt.of(values[index]);
index = (int)links[index];
}
return 0;
return OptionalInt.empty();
}
@Override

View File

@ -5,10 +5,12 @@ import java.util.ConcurrentModificationException;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.BiFunction;
import java.util.function.Predicate;
import java.util.function.IntPredicate;
import java.util.OptionalInt;
import speiger.src.collections.bytes.collections.ByteIterator;
import speiger.src.collections.bytes.functions.ByteConsumer;
@ -20,6 +22,7 @@ import speiger.src.collections.bytes.functions.consumer.ByteIntConsumer;
import speiger.src.collections.bytes.functions.function.Byte2IntFunction;
import speiger.src.collections.bytes.functions.function.ByteIntUnaryOperator;
import speiger.src.collections.bytes.functions.function.ByteByteUnaryOperator;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.functions.function.BytePredicate;
import speiger.src.collections.bytes.maps.abstracts.AbstractByte2IntMap;
import speiger.src.collections.bytes.maps.interfaces.Byte2IntMap;
@ -920,7 +923,7 @@ public class Byte2IntOpenHashMap extends AbstractByte2IntMap implements ITrimmab
}
@Override
public Byte2IntMap.Entry reduce(ObjectObjectUnaryOperator<Byte2IntMap.Entry, Byte2IntMap.Entry> operator) {
public Optional<Byte2IntMap.Entry> reduce(ObjectObjectUnaryOperator<Byte2IntMap.Entry, Byte2IntMap.Entry> operator) {
Objects.requireNonNull(operator);
Byte2IntMap.Entry state = null;
boolean empty = true;
@ -937,25 +940,25 @@ public class Byte2IntOpenHashMap extends AbstractByte2IntMap implements ITrimmab
}
state = operator.apply(state, new ValueMapEntry(i));
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public Byte2IntMap.Entry findFirst(Predicate<Byte2IntMap.Entry> filter) {
public Optional<Byte2IntMap.Entry> findFirst(Predicate<Byte2IntMap.Entry> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return null;
if(size() <= 0) return Optional.empty();
MapEntry entry = new MapEntry();
if(containsNull) {
entry.set(nullIndex);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
}
for(int i = nullIndex-1;i>=0;i--) {
if(keys[i] != (byte)0) {
entry.set(i);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
}
}
return null;
return Optional.empty();
}
@Override
@ -1127,7 +1130,7 @@ public class Byte2IntOpenHashMap extends AbstractByte2IntMap implements ITrimmab
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -1144,18 +1147,18 @@ public class Byte2IntOpenHashMap extends AbstractByte2IntMap implements ITrimmab
}
state = operator.applyAsByte(state, keys[i]);
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return (byte)0;
if(containsNull && filter.test(keys[nullIndex])) return keys[nullIndex];
if(size() <= 0) return OptionalByte.empty();
if(containsNull && filter.test(keys[nullIndex])) return OptionalByte.of(keys[nullIndex]);
for(int i = nullIndex-1;i>=0;i--) {
if(keys[i] != (byte)0 && filter.test(keys[i])) return keys[i];
if(keys[i] != (byte)0 && filter.test(keys[i])) return OptionalByte.of(keys[i]);
}
return (byte)0;
return OptionalByte.empty();
}
@Override
@ -1270,7 +1273,7 @@ public class Byte2IntOpenHashMap extends AbstractByte2IntMap implements ITrimmab
}
@Override
public int reduce(IntIntUnaryOperator operator) {
public OptionalInt reduce(IntIntUnaryOperator operator) {
Objects.requireNonNull(operator);
int state = 0;
boolean empty = true;
@ -1287,18 +1290,18 @@ public class Byte2IntOpenHashMap extends AbstractByte2IntMap implements ITrimmab
}
state = operator.applyAsInt(state, values[i]);
}
return state;
return empty ? OptionalInt.empty() : OptionalInt.of(state);
}
@Override
public int findFirst(IntPredicate filter) {
public OptionalInt findFirst(IntPredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return 0;
if(containsNull && filter.test(values[nullIndex])) return values[nullIndex];
if(size() <= 0) return OptionalInt.empty();
if(containsNull && filter.test(values[nullIndex])) return OptionalInt.of(values[nullIndex]);
for(int i = nullIndex-1;i>=0;i--) {
if(keys[i] != (byte)0 && filter.test(values[i])) return values[i];
if(keys[i] != (byte)0 && filter.test(values[i])) return OptionalInt.of(values[i]);
}
return 0;
return OptionalInt.empty();
}
@Override

View File

@ -4,10 +4,12 @@ import java.util.Arrays;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.BiFunction;
import java.util.function.Predicate;
import java.util.function.LongPredicate;
import java.util.OptionalLong;
import speiger.src.collections.bytes.collections.ByteBidirectionalIterator;
import speiger.src.collections.bytes.functions.ByteConsumer;
@ -15,6 +17,7 @@ import speiger.src.collections.objects.functions.consumer.ObjectByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
import speiger.src.collections.ints.functions.consumer.IntLongConsumer;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.functions.function.BytePredicate;
import speiger.src.collections.bytes.functions.consumer.ByteLongConsumer;
import speiger.src.collections.bytes.functions.function.ByteByteUnaryOperator;
@ -669,6 +672,10 @@ public class Byte2LongLinkedOpenHashMap extends Byte2LongOpenHashMap implements
}
private class MapEntrySet extends AbstractObjectSet<Byte2LongMap.Entry> implements Byte2LongOrderedMap.FastOrderedSet {
@Override
public void addFirst(Byte2LongMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(Byte2LongMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(Byte2LongMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
@ -834,7 +841,7 @@ public class Byte2LongLinkedOpenHashMap extends Byte2LongOpenHashMap implements
}
@Override
public Byte2LongMap.Entry reduce(ObjectObjectUnaryOperator<Byte2LongMap.Entry, Byte2LongMap.Entry> operator) {
public Optional<Byte2LongMap.Entry> reduce(ObjectObjectUnaryOperator<Byte2LongMap.Entry, Byte2LongMap.Entry> operator) {
Objects.requireNonNull(operator);
Byte2LongMap.Entry state = null;
boolean empty = true;
@ -849,21 +856,21 @@ public class Byte2LongLinkedOpenHashMap extends Byte2LongOpenHashMap implements
state = operator.apply(state, new ValueMapEntry(index));
index = (int)links[index];
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public Byte2LongMap.Entry findFirst(Predicate<Byte2LongMap.Entry> filter) {
public Optional<Byte2LongMap.Entry> findFirst(Predicate<Byte2LongMap.Entry> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return null;
if(size() <= 0) return Optional.empty();
MapEntry entry = new MapEntry();
int index = firstIndex;
while(index != -1) {
entry.set(index);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
index = (int)links[index];
}
return null;
return Optional.empty();
}
@Override
@ -939,6 +946,12 @@ public class Byte2LongLinkedOpenHashMap extends Byte2LongOpenHashMap implements
@Override
public boolean add(byte o) { throw new UnsupportedOperationException(); }
@Override
public void addFirst(byte o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(byte o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(byte o) { throw new UnsupportedOperationException(); }
@ -1085,7 +1098,7 @@ public class Byte2LongLinkedOpenHashMap extends Byte2LongOpenHashMap implements
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -1100,19 +1113,19 @@ public class Byte2LongLinkedOpenHashMap extends Byte2LongOpenHashMap implements
state = operator.applyAsByte(state, keys[index]);
index = (int)links[index];
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return (byte)0;
if(size() <= 0) return OptionalByte.empty();
int index = firstIndex;
while(index != -1){
if(filter.test(keys[index])) return keys[index];
if(filter.test(keys[index])) return OptionalByte.of(keys[index]);
index = (int)links[index];
}
return (byte)0;
return OptionalByte.empty();
}
@Override
@ -1248,7 +1261,7 @@ public class Byte2LongLinkedOpenHashMap extends Byte2LongOpenHashMap implements
}
@Override
public long reduce(LongLongUnaryOperator operator) {
public OptionalLong reduce(LongLongUnaryOperator operator) {
Objects.requireNonNull(operator);
long state = 0L;
boolean empty = true;
@ -1263,19 +1276,19 @@ public class Byte2LongLinkedOpenHashMap extends Byte2LongOpenHashMap implements
state = operator.applyAsLong(state, values[index]);
index = (int)links[index];
}
return state;
return empty ? OptionalLong.empty() : OptionalLong.of(state);
}
@Override
public long findFirst(LongPredicate filter) {
public OptionalLong findFirst(LongPredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return 0L;
if(size() <= 0) return OptionalLong.empty();
int index = firstIndex;
while(index != -1){
if(filter.test(values[index])) return values[index];
if(filter.test(values[index])) return OptionalLong.of(values[index]);
index = (int)links[index];
}
return 0L;
return OptionalLong.empty();
}
@Override

View File

@ -5,10 +5,12 @@ import java.util.ConcurrentModificationException;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.BiFunction;
import java.util.function.Predicate;
import java.util.function.LongPredicate;
import java.util.OptionalLong;
import speiger.src.collections.bytes.collections.ByteIterator;
import speiger.src.collections.bytes.functions.ByteConsumer;
@ -20,6 +22,7 @@ import speiger.src.collections.bytes.functions.consumer.ByteLongConsumer;
import speiger.src.collections.bytes.functions.function.Byte2LongFunction;
import speiger.src.collections.bytes.functions.function.ByteLongUnaryOperator;
import speiger.src.collections.bytes.functions.function.ByteByteUnaryOperator;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.functions.function.BytePredicate;
import speiger.src.collections.bytes.maps.abstracts.AbstractByte2LongMap;
import speiger.src.collections.bytes.maps.interfaces.Byte2LongMap;
@ -920,7 +923,7 @@ public class Byte2LongOpenHashMap extends AbstractByte2LongMap implements ITrimm
}
@Override
public Byte2LongMap.Entry reduce(ObjectObjectUnaryOperator<Byte2LongMap.Entry, Byte2LongMap.Entry> operator) {
public Optional<Byte2LongMap.Entry> reduce(ObjectObjectUnaryOperator<Byte2LongMap.Entry, Byte2LongMap.Entry> operator) {
Objects.requireNonNull(operator);
Byte2LongMap.Entry state = null;
boolean empty = true;
@ -937,25 +940,25 @@ public class Byte2LongOpenHashMap extends AbstractByte2LongMap implements ITrimm
}
state = operator.apply(state, new ValueMapEntry(i));
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public Byte2LongMap.Entry findFirst(Predicate<Byte2LongMap.Entry> filter) {
public Optional<Byte2LongMap.Entry> findFirst(Predicate<Byte2LongMap.Entry> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return null;
if(size() <= 0) return Optional.empty();
MapEntry entry = new MapEntry();
if(containsNull) {
entry.set(nullIndex);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
}
for(int i = nullIndex-1;i>=0;i--) {
if(keys[i] != (byte)0) {
entry.set(i);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
}
}
return null;
return Optional.empty();
}
@Override
@ -1127,7 +1130,7 @@ public class Byte2LongOpenHashMap extends AbstractByte2LongMap implements ITrimm
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -1144,18 +1147,18 @@ public class Byte2LongOpenHashMap extends AbstractByte2LongMap implements ITrimm
}
state = operator.applyAsByte(state, keys[i]);
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return (byte)0;
if(containsNull && filter.test(keys[nullIndex])) return keys[nullIndex];
if(size() <= 0) return OptionalByte.empty();
if(containsNull && filter.test(keys[nullIndex])) return OptionalByte.of(keys[nullIndex]);
for(int i = nullIndex-1;i>=0;i--) {
if(keys[i] != (byte)0 && filter.test(keys[i])) return keys[i];
if(keys[i] != (byte)0 && filter.test(keys[i])) return OptionalByte.of(keys[i]);
}
return (byte)0;
return OptionalByte.empty();
}
@Override
@ -1270,7 +1273,7 @@ public class Byte2LongOpenHashMap extends AbstractByte2LongMap implements ITrimm
}
@Override
public long reduce(LongLongUnaryOperator operator) {
public OptionalLong reduce(LongLongUnaryOperator operator) {
Objects.requireNonNull(operator);
long state = 0L;
boolean empty = true;
@ -1287,18 +1290,18 @@ public class Byte2LongOpenHashMap extends AbstractByte2LongMap implements ITrimm
}
state = operator.applyAsLong(state, values[i]);
}
return state;
return empty ? OptionalLong.empty() : OptionalLong.of(state);
}
@Override
public long findFirst(LongPredicate filter) {
public OptionalLong findFirst(LongPredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return 0L;
if(containsNull && filter.test(values[nullIndex])) return values[nullIndex];
if(size() <= 0) return OptionalLong.empty();
if(containsNull && filter.test(values[nullIndex])) return OptionalLong.of(values[nullIndex]);
for(int i = nullIndex-1;i>=0;i--) {
if(keys[i] != (byte)0 && filter.test(values[i])) return values[i];
if(keys[i] != (byte)0 && filter.test(values[i])) return OptionalLong.of(values[i]);
}
return 0L;
return OptionalLong.empty();
}
@Override

View File

@ -4,6 +4,7 @@ import java.util.Arrays;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.BiFunction;
import java.util.function.Predicate;
@ -13,6 +14,7 @@ import speiger.src.collections.bytes.functions.ByteConsumer;
import speiger.src.collections.objects.functions.consumer.ObjectByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.functions.function.BytePredicate;
import speiger.src.collections.bytes.functions.consumer.ByteObjectConsumer;
import speiger.src.collections.bytes.functions.function.ByteByteUnaryOperator;
@ -653,6 +655,10 @@ public class Byte2ObjectLinkedOpenHashMap<V> extends Byte2ObjectOpenHashMap<V> i
}
private class MapEntrySet extends AbstractObjectSet<Byte2ObjectMap.Entry<V>> implements Byte2ObjectOrderedMap.FastOrderedSet<V> {
@Override
public void addFirst(Byte2ObjectMap.Entry<V> o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(Byte2ObjectMap.Entry<V> o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(Byte2ObjectMap.Entry<V> o) { throw new UnsupportedOperationException(); }
@Override
@ -818,7 +824,7 @@ public class Byte2ObjectLinkedOpenHashMap<V> extends Byte2ObjectOpenHashMap<V> i
}
@Override
public Byte2ObjectMap.Entry<V> reduce(ObjectObjectUnaryOperator<Byte2ObjectMap.Entry<V>, Byte2ObjectMap.Entry<V>> operator) {
public Optional<Byte2ObjectMap.Entry<V>> reduce(ObjectObjectUnaryOperator<Byte2ObjectMap.Entry<V>, Byte2ObjectMap.Entry<V>> operator) {
Objects.requireNonNull(operator);
Byte2ObjectMap.Entry<V> state = null;
boolean empty = true;
@ -833,21 +839,21 @@ public class Byte2ObjectLinkedOpenHashMap<V> extends Byte2ObjectOpenHashMap<V> i
state = operator.apply(state, new ValueMapEntry(index));
index = (int)links[index];
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public Byte2ObjectMap.Entry<V> findFirst(Predicate<Byte2ObjectMap.Entry<V>> filter) {
public Optional<Byte2ObjectMap.Entry<V>> findFirst(Predicate<Byte2ObjectMap.Entry<V>> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return null;
if(size() <= 0) return Optional.empty();
MapEntry entry = new MapEntry();
int index = firstIndex;
while(index != -1) {
entry.set(index);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
index = (int)links[index];
}
return null;
return Optional.empty();
}
@Override
@ -923,6 +929,12 @@ public class Byte2ObjectLinkedOpenHashMap<V> extends Byte2ObjectOpenHashMap<V> i
@Override
public boolean add(byte o) { throw new UnsupportedOperationException(); }
@Override
public void addFirst(byte o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(byte o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(byte o) { throw new UnsupportedOperationException(); }
@ -1069,7 +1081,7 @@ public class Byte2ObjectLinkedOpenHashMap<V> extends Byte2ObjectOpenHashMap<V> i
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -1084,19 +1096,19 @@ public class Byte2ObjectLinkedOpenHashMap<V> extends Byte2ObjectOpenHashMap<V> i
state = operator.applyAsByte(state, keys[index]);
index = (int)links[index];
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return (byte)0;
if(size() <= 0) return OptionalByte.empty();
int index = firstIndex;
while(index != -1){
if(filter.test(keys[index])) return keys[index];
if(filter.test(keys[index])) return OptionalByte.of(keys[index]);
index = (int)links[index];
}
return (byte)0;
return OptionalByte.empty();
}
@Override
@ -1233,7 +1245,7 @@ public class Byte2ObjectLinkedOpenHashMap<V> extends Byte2ObjectOpenHashMap<V> i
}
@Override
public V reduce(ObjectObjectUnaryOperator<V, V> operator) {
public Optional<V> reduce(ObjectObjectUnaryOperator<V, V> operator) {
Objects.requireNonNull(operator);
V state = null;
boolean empty = true;
@ -1248,19 +1260,19 @@ public class Byte2ObjectLinkedOpenHashMap<V> extends Byte2ObjectOpenHashMap<V> i
state = operator.apply(state, values[index]);
index = (int)links[index];
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public V findFirst(Predicate<V> filter) {
public Optional<V> findFirst(Predicate<V> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return null;
if(size() <= 0) return Optional.empty();
int index = firstIndex;
while(index != -1){
if(filter.test(values[index])) return values[index];
if(filter.test(values[index])) return Optional.ofNullable(values[index]);
index = (int)links[index];
}
return null;
return Optional.empty();
}
@Override

View File

@ -5,6 +5,7 @@ import java.util.ConcurrentModificationException;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.BiFunction;
import java.util.function.Predicate;
@ -18,6 +19,7 @@ import speiger.src.collections.bytes.functions.consumer.ByteObjectConsumer;
import speiger.src.collections.bytes.functions.function.ByteFunction;
import speiger.src.collections.bytes.functions.function.ByteObjectUnaryOperator;
import speiger.src.collections.bytes.functions.function.ByteByteUnaryOperator;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.functions.function.BytePredicate;
import speiger.src.collections.bytes.maps.abstracts.AbstractByte2ObjectMap;
import speiger.src.collections.bytes.maps.interfaces.Byte2ObjectMap;
@ -837,7 +839,7 @@ public class Byte2ObjectOpenHashMap<V> extends AbstractByte2ObjectMap<V> impleme
}
@Override
public Byte2ObjectMap.Entry<V> reduce(ObjectObjectUnaryOperator<Byte2ObjectMap.Entry<V>, Byte2ObjectMap.Entry<V>> operator) {
public Optional<Byte2ObjectMap.Entry<V>> reduce(ObjectObjectUnaryOperator<Byte2ObjectMap.Entry<V>, Byte2ObjectMap.Entry<V>> operator) {
Objects.requireNonNull(operator);
Byte2ObjectMap.Entry<V> state = null;
boolean empty = true;
@ -854,25 +856,25 @@ public class Byte2ObjectOpenHashMap<V> extends AbstractByte2ObjectMap<V> impleme
}
state = operator.apply(state, new ValueMapEntry(i));
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public Byte2ObjectMap.Entry<V> findFirst(Predicate<Byte2ObjectMap.Entry<V>> filter) {
public Optional<Byte2ObjectMap.Entry<V>> findFirst(Predicate<Byte2ObjectMap.Entry<V>> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return null;
if(size() <= 0) return Optional.empty();
MapEntry entry = new MapEntry();
if(containsNull) {
entry.set(nullIndex);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
}
for(int i = nullIndex-1;i>=0;i--) {
if(keys[i] != (byte)0) {
entry.set(i);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
}
}
return null;
return Optional.empty();
}
@Override
@ -1044,7 +1046,7 @@ public class Byte2ObjectOpenHashMap<V> extends AbstractByte2ObjectMap<V> impleme
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -1061,18 +1063,18 @@ public class Byte2ObjectOpenHashMap<V> extends AbstractByte2ObjectMap<V> impleme
}
state = operator.applyAsByte(state, keys[i]);
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return (byte)0;
if(containsNull && filter.test(keys[nullIndex])) return keys[nullIndex];
if(size() <= 0) return OptionalByte.empty();
if(containsNull && filter.test(keys[nullIndex])) return OptionalByte.of(keys[nullIndex]);
for(int i = nullIndex-1;i>=0;i--) {
if(keys[i] != (byte)0 && filter.test(keys[i])) return keys[i];
if(keys[i] != (byte)0 && filter.test(keys[i])) return OptionalByte.of(keys[i]);
}
return (byte)0;
return OptionalByte.empty();
}
@Override
@ -1187,7 +1189,7 @@ public class Byte2ObjectOpenHashMap<V> extends AbstractByte2ObjectMap<V> impleme
}
@Override
public V reduce(ObjectObjectUnaryOperator<V, V> operator) {
public Optional<V> reduce(ObjectObjectUnaryOperator<V, V> operator) {
Objects.requireNonNull(operator);
V state = null;
boolean empty = true;
@ -1204,18 +1206,18 @@ public class Byte2ObjectOpenHashMap<V> extends AbstractByte2ObjectMap<V> impleme
}
state = operator.apply(state, values[i]);
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public V findFirst(Predicate<V> filter) {
public Optional<V> findFirst(Predicate<V> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return null;
if(containsNull && filter.test(values[nullIndex])) return values[nullIndex];
if(size() <= 0) return Optional.empty();
if(containsNull && filter.test(values[nullIndex])) return Optional.ofNullable(values[nullIndex]);
for(int i = nullIndex-1;i>=0;i--) {
if(keys[i] != (byte)0 && filter.test(values[i])) return values[i];
if(keys[i] != (byte)0 && filter.test(values[i])) return Optional.ofNullable(values[i]);
}
return null;
return Optional.empty();
}
@Override

View File

@ -4,6 +4,7 @@ import java.util.Arrays;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.BiFunction;
import java.util.function.Predicate;
@ -14,6 +15,7 @@ import speiger.src.collections.objects.functions.consumer.ObjectByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
import speiger.src.collections.ints.functions.consumer.IntShortConsumer;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.functions.function.BytePredicate;
import speiger.src.collections.bytes.functions.consumer.ByteShortConsumer;
import speiger.src.collections.bytes.functions.function.ByteByteUnaryOperator;
@ -32,6 +34,7 @@ import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer;
import speiger.src.collections.objects.functions.consumer.ObjectShortConsumer;
import speiger.src.collections.shorts.functions.function.ShortPredicate;
import speiger.src.collections.shorts.functions.OptionalShort;
import speiger.src.collections.objects.functions.function.ObjectObjectUnaryOperator;
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
import speiger.src.collections.objects.lists.ObjectListIterator;
@ -669,6 +672,10 @@ public class Byte2ShortLinkedOpenHashMap extends Byte2ShortOpenHashMap implement
}
private class MapEntrySet extends AbstractObjectSet<Byte2ShortMap.Entry> implements Byte2ShortOrderedMap.FastOrderedSet {
@Override
public void addFirst(Byte2ShortMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(Byte2ShortMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(Byte2ShortMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
@ -834,7 +841,7 @@ public class Byte2ShortLinkedOpenHashMap extends Byte2ShortOpenHashMap implement
}
@Override
public Byte2ShortMap.Entry reduce(ObjectObjectUnaryOperator<Byte2ShortMap.Entry, Byte2ShortMap.Entry> operator) {
public Optional<Byte2ShortMap.Entry> reduce(ObjectObjectUnaryOperator<Byte2ShortMap.Entry, Byte2ShortMap.Entry> operator) {
Objects.requireNonNull(operator);
Byte2ShortMap.Entry state = null;
boolean empty = true;
@ -849,21 +856,21 @@ public class Byte2ShortLinkedOpenHashMap extends Byte2ShortOpenHashMap implement
state = operator.apply(state, new ValueMapEntry(index));
index = (int)links[index];
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public Byte2ShortMap.Entry findFirst(Predicate<Byte2ShortMap.Entry> filter) {
public Optional<Byte2ShortMap.Entry> findFirst(Predicate<Byte2ShortMap.Entry> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return null;
if(size() <= 0) return Optional.empty();
MapEntry entry = new MapEntry();
int index = firstIndex;
while(index != -1) {
entry.set(index);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
index = (int)links[index];
}
return null;
return Optional.empty();
}
@Override
@ -939,6 +946,12 @@ public class Byte2ShortLinkedOpenHashMap extends Byte2ShortOpenHashMap implement
@Override
public boolean add(byte o) { throw new UnsupportedOperationException(); }
@Override
public void addFirst(byte o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(byte o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(byte o) { throw new UnsupportedOperationException(); }
@ -1085,7 +1098,7 @@ public class Byte2ShortLinkedOpenHashMap extends Byte2ShortOpenHashMap implement
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -1100,19 +1113,19 @@ public class Byte2ShortLinkedOpenHashMap extends Byte2ShortOpenHashMap implement
state = operator.applyAsByte(state, keys[index]);
index = (int)links[index];
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return (byte)0;
if(size() <= 0) return OptionalByte.empty();
int index = firstIndex;
while(index != -1){
if(filter.test(keys[index])) return keys[index];
if(filter.test(keys[index])) return OptionalByte.of(keys[index]);
index = (int)links[index];
}
return (byte)0;
return OptionalByte.empty();
}
@Override
@ -1248,7 +1261,7 @@ public class Byte2ShortLinkedOpenHashMap extends Byte2ShortOpenHashMap implement
}
@Override
public short reduce(ShortShortUnaryOperator operator) {
public OptionalShort reduce(ShortShortUnaryOperator operator) {
Objects.requireNonNull(operator);
short state = (short)0;
boolean empty = true;
@ -1263,19 +1276,19 @@ public class Byte2ShortLinkedOpenHashMap extends Byte2ShortOpenHashMap implement
state = operator.applyAsShort(state, values[index]);
index = (int)links[index];
}
return state;
return empty ? OptionalShort.empty() : OptionalShort.of(state);
}
@Override
public short findFirst(ShortPredicate filter) {
public OptionalShort findFirst(ShortPredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return (short)0;
if(size() <= 0) return OptionalShort.empty();
int index = firstIndex;
while(index != -1){
if(filter.test(values[index])) return values[index];
if(filter.test(values[index])) return OptionalShort.of(values[index]);
index = (int)links[index];
}
return (short)0;
return OptionalShort.empty();
}
@Override

View File

@ -5,6 +5,7 @@ import java.util.ConcurrentModificationException;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.BiFunction;
import java.util.function.Predicate;
@ -19,6 +20,7 @@ import speiger.src.collections.bytes.functions.consumer.ByteShortConsumer;
import speiger.src.collections.bytes.functions.function.Byte2ShortFunction;
import speiger.src.collections.bytes.functions.function.ByteShortUnaryOperator;
import speiger.src.collections.bytes.functions.function.ByteByteUnaryOperator;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.functions.function.BytePredicate;
import speiger.src.collections.bytes.maps.abstracts.AbstractByte2ShortMap;
import speiger.src.collections.bytes.maps.interfaces.Byte2ShortMap;
@ -34,6 +36,7 @@ import speiger.src.collections.shorts.functions.ShortConsumer;
import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer;
import speiger.src.collections.objects.functions.consumer.ObjectShortConsumer;
import speiger.src.collections.shorts.functions.function.ShortPredicate;
import speiger.src.collections.shorts.functions.OptionalShort;
import speiger.src.collections.objects.collections.ObjectIterator;
import speiger.src.collections.objects.sets.AbstractObjectSet;
import speiger.src.collections.objects.sets.ObjectSet;
@ -920,7 +923,7 @@ public class Byte2ShortOpenHashMap extends AbstractByte2ShortMap implements ITri
}
@Override
public Byte2ShortMap.Entry reduce(ObjectObjectUnaryOperator<Byte2ShortMap.Entry, Byte2ShortMap.Entry> operator) {
public Optional<Byte2ShortMap.Entry> reduce(ObjectObjectUnaryOperator<Byte2ShortMap.Entry, Byte2ShortMap.Entry> operator) {
Objects.requireNonNull(operator);
Byte2ShortMap.Entry state = null;
boolean empty = true;
@ -937,25 +940,25 @@ public class Byte2ShortOpenHashMap extends AbstractByte2ShortMap implements ITri
}
state = operator.apply(state, new ValueMapEntry(i));
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public Byte2ShortMap.Entry findFirst(Predicate<Byte2ShortMap.Entry> filter) {
public Optional<Byte2ShortMap.Entry> findFirst(Predicate<Byte2ShortMap.Entry> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return null;
if(size() <= 0) return Optional.empty();
MapEntry entry = new MapEntry();
if(containsNull) {
entry.set(nullIndex);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
}
for(int i = nullIndex-1;i>=0;i--) {
if(keys[i] != (byte)0) {
entry.set(i);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
}
}
return null;
return Optional.empty();
}
@Override
@ -1127,7 +1130,7 @@ public class Byte2ShortOpenHashMap extends AbstractByte2ShortMap implements ITri
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -1144,18 +1147,18 @@ public class Byte2ShortOpenHashMap extends AbstractByte2ShortMap implements ITri
}
state = operator.applyAsByte(state, keys[i]);
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return (byte)0;
if(containsNull && filter.test(keys[nullIndex])) return keys[nullIndex];
if(size() <= 0) return OptionalByte.empty();
if(containsNull && filter.test(keys[nullIndex])) return OptionalByte.of(keys[nullIndex]);
for(int i = nullIndex-1;i>=0;i--) {
if(keys[i] != (byte)0 && filter.test(keys[i])) return keys[i];
if(keys[i] != (byte)0 && filter.test(keys[i])) return OptionalByte.of(keys[i]);
}
return (byte)0;
return OptionalByte.empty();
}
@Override
@ -1270,7 +1273,7 @@ public class Byte2ShortOpenHashMap extends AbstractByte2ShortMap implements ITri
}
@Override
public short reduce(ShortShortUnaryOperator operator) {
public OptionalShort reduce(ShortShortUnaryOperator operator) {
Objects.requireNonNull(operator);
short state = (short)0;
boolean empty = true;
@ -1287,18 +1290,18 @@ public class Byte2ShortOpenHashMap extends AbstractByte2ShortMap implements ITri
}
state = operator.applyAsShort(state, values[i]);
}
return state;
return empty ? OptionalShort.empty() : OptionalShort.of(state);
}
@Override
public short findFirst(ShortPredicate filter) {
public OptionalShort findFirst(ShortPredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return (short)0;
if(containsNull && filter.test(values[nullIndex])) return values[nullIndex];
if(size() <= 0) return OptionalShort.empty();
if(containsNull && filter.test(values[nullIndex])) return OptionalShort.of(values[nullIndex]);
for(int i = nullIndex-1;i>=0;i--) {
if(keys[i] != (byte)0 && filter.test(values[i])) return values[i];
if(keys[i] != (byte)0 && filter.test(values[i])) return OptionalShort.of(values[i]);
}
return (short)0;
return OptionalShort.empty();
}
@Override

View File

@ -4,6 +4,7 @@ import java.util.Arrays;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.BiFunction;
import java.util.function.Predicate;
@ -14,6 +15,7 @@ import speiger.src.collections.objects.functions.consumer.ObjectByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
import speiger.src.collections.ints.functions.consumer.IntBooleanConsumer;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.functions.consumer.ByteBooleanConsumer;
import speiger.src.collections.bytes.functions.function.BytePredicate;
import speiger.src.collections.bytes.functions.function.ByteBooleanUnaryOperator;
@ -28,6 +30,7 @@ import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer;
import speiger.src.collections.objects.functions.consumer.ObjectBooleanConsumer;
import speiger.src.collections.booleans.functions.function.BooleanPredicate;
import speiger.src.collections.booleans.functions.OptionalBoolean;
import speiger.src.collections.bytes.sets.AbstractByteSet;
import speiger.src.collections.booleans.collections.AbstractBooleanCollection;
import speiger.src.collections.booleans.collections.BooleanOrderedCollection;
@ -533,6 +536,10 @@ public class ImmutableByte2BooleanOpenHashMap extends AbstractByte2BooleanMap im
}
private class MapEntrySet extends AbstractObjectSet<Byte2BooleanMap.Entry> implements Byte2BooleanOrderedMap.FastOrderedSet {
@Override
public void addFirst(Byte2BooleanMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(Byte2BooleanMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(Byte2BooleanMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
@ -686,7 +693,7 @@ public class ImmutableByte2BooleanOpenHashMap extends AbstractByte2BooleanMap im
}
@Override
public Byte2BooleanMap.Entry reduce(ObjectObjectUnaryOperator<Byte2BooleanMap.Entry, Byte2BooleanMap.Entry> operator) {
public Optional<Byte2BooleanMap.Entry> reduce(ObjectObjectUnaryOperator<Byte2BooleanMap.Entry, Byte2BooleanMap.Entry> operator) {
Objects.requireNonNull(operator);
Byte2BooleanMap.Entry state = null;
boolean empty = true;
@ -701,21 +708,21 @@ public class ImmutableByte2BooleanOpenHashMap extends AbstractByte2BooleanMap im
state = operator.apply(state, new BasicEntry(keys[index], values[index]));
index = (int)links[index];
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public Byte2BooleanMap.Entry findFirst(Predicate<Byte2BooleanMap.Entry> filter) {
public Optional<Byte2BooleanMap.Entry> findFirst(Predicate<Byte2BooleanMap.Entry> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return null;
if(size() <= 0) return Optional.empty();
BasicEntry entry = new BasicEntry();
int index = firstIndex;
while(index != -1) {
entry.set(keys[index], values[index]);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
index = (int)links[index];
}
return null;
return Optional.empty();
}
@Override
@ -778,6 +785,12 @@ public class ImmutableByte2BooleanOpenHashMap extends AbstractByte2BooleanMap im
throw new UnsupportedOperationException();
}
@Override
public void addFirst(byte o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(byte o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(byte o) { throw new UnsupportedOperationException(); }
@ -913,7 +926,7 @@ public class ImmutableByte2BooleanOpenHashMap extends AbstractByte2BooleanMap im
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -928,19 +941,19 @@ public class ImmutableByte2BooleanOpenHashMap extends AbstractByte2BooleanMap im
state = operator.applyAsByte(state, keys[index]);
index = (int)links[index];
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return (byte)0;
if(size() <= 0) return OptionalByte.empty();
int index = firstIndex;
while(index != -1){
if(filter.test(keys[index])) return keys[index];
if(filter.test(keys[index])) return OptionalByte.of(keys[index]);
index = (int)links[index];
}
return (byte)0;
return OptionalByte.empty();
}
@Override
@ -1067,7 +1080,7 @@ public class ImmutableByte2BooleanOpenHashMap extends AbstractByte2BooleanMap im
}
@Override
public boolean reduce(BooleanBooleanUnaryOperator operator) {
public OptionalBoolean reduce(BooleanBooleanUnaryOperator operator) {
Objects.requireNonNull(operator);
boolean state = false;
boolean empty = true;
@ -1082,19 +1095,19 @@ public class ImmutableByte2BooleanOpenHashMap extends AbstractByte2BooleanMap im
state = operator.applyAsBoolean(state, values[index]);
index = (int)links[index];
}
return state;
return empty ? OptionalBoolean.empty() : OptionalBoolean.of(state);
}
@Override
public boolean findFirst(BooleanPredicate filter) {
public OptionalBoolean findFirst(BooleanPredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return false;
if(size() <= 0) return OptionalBoolean.empty();
int index = firstIndex;
while(index != -1){
if(filter.test(values[index])) return values[index];
if(filter.test(values[index])) return OptionalBoolean.of(values[index]);
index = (int)links[index];
}
return false;
return OptionalBoolean.empty();
}
@Override

View File

@ -4,6 +4,7 @@ import java.util.Arrays;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.BiFunction;
import java.util.function.Predicate;
@ -13,6 +14,7 @@ import speiger.src.collections.bytes.functions.ByteConsumer;
import speiger.src.collections.objects.functions.consumer.ObjectByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.functions.function.BytePredicate;
import speiger.src.collections.bytes.functions.consumer.ByteByteConsumer;
import speiger.src.collections.bytes.functions.function.ByteUnaryOperator;
@ -529,6 +531,10 @@ public class ImmutableByte2ByteOpenHashMap extends AbstractByte2ByteMap implemen
}
private class MapEntrySet extends AbstractObjectSet<Byte2ByteMap.Entry> implements Byte2ByteOrderedMap.FastOrderedSet {
@Override
public void addFirst(Byte2ByteMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(Byte2ByteMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(Byte2ByteMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
@ -682,7 +688,7 @@ public class ImmutableByte2ByteOpenHashMap extends AbstractByte2ByteMap implemen
}
@Override
public Byte2ByteMap.Entry reduce(ObjectObjectUnaryOperator<Byte2ByteMap.Entry, Byte2ByteMap.Entry> operator) {
public Optional<Byte2ByteMap.Entry> reduce(ObjectObjectUnaryOperator<Byte2ByteMap.Entry, Byte2ByteMap.Entry> operator) {
Objects.requireNonNull(operator);
Byte2ByteMap.Entry state = null;
boolean empty = true;
@ -697,21 +703,21 @@ public class ImmutableByte2ByteOpenHashMap extends AbstractByte2ByteMap implemen
state = operator.apply(state, new BasicEntry(keys[index], values[index]));
index = (int)links[index];
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public Byte2ByteMap.Entry findFirst(Predicate<Byte2ByteMap.Entry> filter) {
public Optional<Byte2ByteMap.Entry> findFirst(Predicate<Byte2ByteMap.Entry> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return null;
if(size() <= 0) return Optional.empty();
BasicEntry entry = new BasicEntry();
int index = firstIndex;
while(index != -1) {
entry.set(keys[index], values[index]);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
index = (int)links[index];
}
return null;
return Optional.empty();
}
@Override
@ -774,6 +780,12 @@ public class ImmutableByte2ByteOpenHashMap extends AbstractByte2ByteMap implemen
throw new UnsupportedOperationException();
}
@Override
public void addFirst(byte o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(byte o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(byte o) { throw new UnsupportedOperationException(); }
@ -909,7 +921,7 @@ public class ImmutableByte2ByteOpenHashMap extends AbstractByte2ByteMap implemen
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -924,19 +936,19 @@ public class ImmutableByte2ByteOpenHashMap extends AbstractByte2ByteMap implemen
state = operator.applyAsByte(state, keys[index]);
index = (int)links[index];
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return (byte)0;
if(size() <= 0) return OptionalByte.empty();
int index = firstIndex;
while(index != -1){
if(filter.test(keys[index])) return keys[index];
if(filter.test(keys[index])) return OptionalByte.of(keys[index]);
index = (int)links[index];
}
return (byte)0;
return OptionalByte.empty();
}
@Override
@ -1063,7 +1075,7 @@ public class ImmutableByte2ByteOpenHashMap extends AbstractByte2ByteMap implemen
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -1078,19 +1090,19 @@ public class ImmutableByte2ByteOpenHashMap extends AbstractByte2ByteMap implemen
state = operator.applyAsByte(state, values[index]);
index = (int)links[index];
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return (byte)0;
if(size() <= 0) return OptionalByte.empty();
int index = firstIndex;
while(index != -1){
if(filter.test(values[index])) return values[index];
if(filter.test(values[index])) return OptionalByte.of(values[index]);
index = (int)links[index];
}
return (byte)0;
return OptionalByte.empty();
}
@Override

View File

@ -4,6 +4,7 @@ import java.util.Arrays;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.BiFunction;
import java.util.function.Predicate;
@ -14,6 +15,7 @@ import speiger.src.collections.objects.functions.consumer.ObjectByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
import speiger.src.collections.ints.functions.consumer.IntCharConsumer;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.functions.function.BytePredicate;
import speiger.src.collections.bytes.functions.consumer.ByteCharConsumer;
import speiger.src.collections.bytes.functions.function.Byte2CharFunction;
@ -29,6 +31,7 @@ import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer;
import speiger.src.collections.objects.functions.consumer.ObjectCharConsumer;
import speiger.src.collections.chars.functions.function.CharPredicate;
import speiger.src.collections.chars.functions.OptionalChar;
import speiger.src.collections.bytes.sets.AbstractByteSet;
import speiger.src.collections.chars.collections.AbstractCharCollection;
import speiger.src.collections.chars.collections.CharOrderedCollection;
@ -538,6 +541,10 @@ public class ImmutableByte2CharOpenHashMap extends AbstractByte2CharMap implemen
}
private class MapEntrySet extends AbstractObjectSet<Byte2CharMap.Entry> implements Byte2CharOrderedMap.FastOrderedSet {
@Override
public void addFirst(Byte2CharMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(Byte2CharMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(Byte2CharMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
@ -691,7 +698,7 @@ public class ImmutableByte2CharOpenHashMap extends AbstractByte2CharMap implemen
}
@Override
public Byte2CharMap.Entry reduce(ObjectObjectUnaryOperator<Byte2CharMap.Entry, Byte2CharMap.Entry> operator) {
public Optional<Byte2CharMap.Entry> reduce(ObjectObjectUnaryOperator<Byte2CharMap.Entry, Byte2CharMap.Entry> operator) {
Objects.requireNonNull(operator);
Byte2CharMap.Entry state = null;
boolean empty = true;
@ -706,21 +713,21 @@ public class ImmutableByte2CharOpenHashMap extends AbstractByte2CharMap implemen
state = operator.apply(state, new BasicEntry(keys[index], values[index]));
index = (int)links[index];
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public Byte2CharMap.Entry findFirst(Predicate<Byte2CharMap.Entry> filter) {
public Optional<Byte2CharMap.Entry> findFirst(Predicate<Byte2CharMap.Entry> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return null;
if(size() <= 0) return Optional.empty();
BasicEntry entry = new BasicEntry();
int index = firstIndex;
while(index != -1) {
entry.set(keys[index], values[index]);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
index = (int)links[index];
}
return null;
return Optional.empty();
}
@Override
@ -783,6 +790,12 @@ public class ImmutableByte2CharOpenHashMap extends AbstractByte2CharMap implemen
throw new UnsupportedOperationException();
}
@Override
public void addFirst(byte o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(byte o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(byte o) { throw new UnsupportedOperationException(); }
@ -918,7 +931,7 @@ public class ImmutableByte2CharOpenHashMap extends AbstractByte2CharMap implemen
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -933,19 +946,19 @@ public class ImmutableByte2CharOpenHashMap extends AbstractByte2CharMap implemen
state = operator.applyAsByte(state, keys[index]);
index = (int)links[index];
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return (byte)0;
if(size() <= 0) return OptionalByte.empty();
int index = firstIndex;
while(index != -1){
if(filter.test(keys[index])) return keys[index];
if(filter.test(keys[index])) return OptionalByte.of(keys[index]);
index = (int)links[index];
}
return (byte)0;
return OptionalByte.empty();
}
@Override
@ -1072,7 +1085,7 @@ public class ImmutableByte2CharOpenHashMap extends AbstractByte2CharMap implemen
}
@Override
public char reduce(CharCharUnaryOperator operator) {
public OptionalChar reduce(CharCharUnaryOperator operator) {
Objects.requireNonNull(operator);
char state = (char)0;
boolean empty = true;
@ -1087,19 +1100,19 @@ public class ImmutableByte2CharOpenHashMap extends AbstractByte2CharMap implemen
state = operator.applyAsChar(state, values[index]);
index = (int)links[index];
}
return state;
return empty ? OptionalChar.empty() : OptionalChar.of(state);
}
@Override
public char findFirst(CharPredicate filter) {
public OptionalChar findFirst(CharPredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return (char)0;
if(size() <= 0) return OptionalChar.empty();
int index = firstIndex;
while(index != -1){
if(filter.test(values[index])) return values[index];
if(filter.test(values[index])) return OptionalChar.of(values[index]);
index = (int)links[index];
}
return (char)0;
return OptionalChar.empty();
}
@Override

View File

@ -4,10 +4,12 @@ import java.util.Arrays;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.BiFunction;
import java.util.function.Predicate;
import java.util.function.DoublePredicate;
import java.util.OptionalDouble;
import speiger.src.collections.bytes.collections.ByteBidirectionalIterator;
import speiger.src.collections.bytes.functions.ByteConsumer;
@ -15,6 +17,7 @@ import speiger.src.collections.objects.functions.consumer.ObjectByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
import speiger.src.collections.ints.functions.consumer.IntDoubleConsumer;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.functions.function.BytePredicate;
import speiger.src.collections.bytes.functions.consumer.ByteDoubleConsumer;
import speiger.src.collections.bytes.functions.function.Byte2DoubleFunction;
@ -538,6 +541,10 @@ public class ImmutableByte2DoubleOpenHashMap extends AbstractByte2DoubleMap impl
}
private class MapEntrySet extends AbstractObjectSet<Byte2DoubleMap.Entry> implements Byte2DoubleOrderedMap.FastOrderedSet {
@Override
public void addFirst(Byte2DoubleMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(Byte2DoubleMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(Byte2DoubleMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
@ -691,7 +698,7 @@ public class ImmutableByte2DoubleOpenHashMap extends AbstractByte2DoubleMap impl
}
@Override
public Byte2DoubleMap.Entry reduce(ObjectObjectUnaryOperator<Byte2DoubleMap.Entry, Byte2DoubleMap.Entry> operator) {
public Optional<Byte2DoubleMap.Entry> reduce(ObjectObjectUnaryOperator<Byte2DoubleMap.Entry, Byte2DoubleMap.Entry> operator) {
Objects.requireNonNull(operator);
Byte2DoubleMap.Entry state = null;
boolean empty = true;
@ -706,21 +713,21 @@ public class ImmutableByte2DoubleOpenHashMap extends AbstractByte2DoubleMap impl
state = operator.apply(state, new BasicEntry(keys[index], values[index]));
index = (int)links[index];
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public Byte2DoubleMap.Entry findFirst(Predicate<Byte2DoubleMap.Entry> filter) {
public Optional<Byte2DoubleMap.Entry> findFirst(Predicate<Byte2DoubleMap.Entry> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return null;
if(size() <= 0) return Optional.empty();
BasicEntry entry = new BasicEntry();
int index = firstIndex;
while(index != -1) {
entry.set(keys[index], values[index]);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
index = (int)links[index];
}
return null;
return Optional.empty();
}
@Override
@ -783,6 +790,12 @@ public class ImmutableByte2DoubleOpenHashMap extends AbstractByte2DoubleMap impl
throw new UnsupportedOperationException();
}
@Override
public void addFirst(byte o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(byte o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(byte o) { throw new UnsupportedOperationException(); }
@ -918,7 +931,7 @@ public class ImmutableByte2DoubleOpenHashMap extends AbstractByte2DoubleMap impl
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -933,19 +946,19 @@ public class ImmutableByte2DoubleOpenHashMap extends AbstractByte2DoubleMap impl
state = operator.applyAsByte(state, keys[index]);
index = (int)links[index];
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return (byte)0;
if(size() <= 0) return OptionalByte.empty();
int index = firstIndex;
while(index != -1){
if(filter.test(keys[index])) return keys[index];
if(filter.test(keys[index])) return OptionalByte.of(keys[index]);
index = (int)links[index];
}
return (byte)0;
return OptionalByte.empty();
}
@Override
@ -1072,7 +1085,7 @@ public class ImmutableByte2DoubleOpenHashMap extends AbstractByte2DoubleMap impl
}
@Override
public double reduce(DoubleDoubleUnaryOperator operator) {
public OptionalDouble reduce(DoubleDoubleUnaryOperator operator) {
Objects.requireNonNull(operator);
double state = 0D;
boolean empty = true;
@ -1087,19 +1100,19 @@ public class ImmutableByte2DoubleOpenHashMap extends AbstractByte2DoubleMap impl
state = operator.applyAsDouble(state, values[index]);
index = (int)links[index];
}
return state;
return empty ? OptionalDouble.empty() : OptionalDouble.of(state);
}
@Override
public double findFirst(DoublePredicate filter) {
public OptionalDouble findFirst(DoublePredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return 0D;
if(size() <= 0) return OptionalDouble.empty();
int index = firstIndex;
while(index != -1){
if(filter.test(values[index])) return values[index];
if(filter.test(values[index])) return OptionalDouble.of(values[index]);
index = (int)links[index];
}
return 0D;
return OptionalDouble.empty();
}
@Override

View File

@ -4,6 +4,7 @@ import java.util.Arrays;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.BiFunction;
import java.util.function.Predicate;
@ -14,6 +15,7 @@ import speiger.src.collections.objects.functions.consumer.ObjectByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
import speiger.src.collections.ints.functions.consumer.IntFloatConsumer;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.functions.function.BytePredicate;
import speiger.src.collections.bytes.functions.consumer.ByteFloatConsumer;
import speiger.src.collections.bytes.functions.function.Byte2FloatFunction;
@ -29,6 +31,7 @@ import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer;
import speiger.src.collections.objects.functions.consumer.ObjectFloatConsumer;
import speiger.src.collections.floats.functions.function.FloatPredicate;
import speiger.src.collections.floats.functions.OptionalFloat;
import speiger.src.collections.bytes.sets.AbstractByteSet;
import speiger.src.collections.floats.collections.AbstractFloatCollection;
import speiger.src.collections.floats.collections.FloatOrderedCollection;
@ -538,6 +541,10 @@ public class ImmutableByte2FloatOpenHashMap extends AbstractByte2FloatMap implem
}
private class MapEntrySet extends AbstractObjectSet<Byte2FloatMap.Entry> implements Byte2FloatOrderedMap.FastOrderedSet {
@Override
public void addFirst(Byte2FloatMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(Byte2FloatMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(Byte2FloatMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
@ -691,7 +698,7 @@ public class ImmutableByte2FloatOpenHashMap extends AbstractByte2FloatMap implem
}
@Override
public Byte2FloatMap.Entry reduce(ObjectObjectUnaryOperator<Byte2FloatMap.Entry, Byte2FloatMap.Entry> operator) {
public Optional<Byte2FloatMap.Entry> reduce(ObjectObjectUnaryOperator<Byte2FloatMap.Entry, Byte2FloatMap.Entry> operator) {
Objects.requireNonNull(operator);
Byte2FloatMap.Entry state = null;
boolean empty = true;
@ -706,21 +713,21 @@ public class ImmutableByte2FloatOpenHashMap extends AbstractByte2FloatMap implem
state = operator.apply(state, new BasicEntry(keys[index], values[index]));
index = (int)links[index];
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public Byte2FloatMap.Entry findFirst(Predicate<Byte2FloatMap.Entry> filter) {
public Optional<Byte2FloatMap.Entry> findFirst(Predicate<Byte2FloatMap.Entry> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return null;
if(size() <= 0) return Optional.empty();
BasicEntry entry = new BasicEntry();
int index = firstIndex;
while(index != -1) {
entry.set(keys[index], values[index]);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
index = (int)links[index];
}
return null;
return Optional.empty();
}
@Override
@ -783,6 +790,12 @@ public class ImmutableByte2FloatOpenHashMap extends AbstractByte2FloatMap implem
throw new UnsupportedOperationException();
}
@Override
public void addFirst(byte o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(byte o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(byte o) { throw new UnsupportedOperationException(); }
@ -918,7 +931,7 @@ public class ImmutableByte2FloatOpenHashMap extends AbstractByte2FloatMap implem
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -933,19 +946,19 @@ public class ImmutableByte2FloatOpenHashMap extends AbstractByte2FloatMap implem
state = operator.applyAsByte(state, keys[index]);
index = (int)links[index];
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return (byte)0;
if(size() <= 0) return OptionalByte.empty();
int index = firstIndex;
while(index != -1){
if(filter.test(keys[index])) return keys[index];
if(filter.test(keys[index])) return OptionalByte.of(keys[index]);
index = (int)links[index];
}
return (byte)0;
return OptionalByte.empty();
}
@Override
@ -1072,7 +1085,7 @@ public class ImmutableByte2FloatOpenHashMap extends AbstractByte2FloatMap implem
}
@Override
public float reduce(FloatFloatUnaryOperator operator) {
public OptionalFloat reduce(FloatFloatUnaryOperator operator) {
Objects.requireNonNull(operator);
float state = 0F;
boolean empty = true;
@ -1087,19 +1100,19 @@ public class ImmutableByte2FloatOpenHashMap extends AbstractByte2FloatMap implem
state = operator.applyAsFloat(state, values[index]);
index = (int)links[index];
}
return state;
return empty ? OptionalFloat.empty() : OptionalFloat.of(state);
}
@Override
public float findFirst(FloatPredicate filter) {
public OptionalFloat findFirst(FloatPredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return 0F;
if(size() <= 0) return OptionalFloat.empty();
int index = firstIndex;
while(index != -1){
if(filter.test(values[index])) return values[index];
if(filter.test(values[index])) return OptionalFloat.of(values[index]);
index = (int)links[index];
}
return 0F;
return OptionalFloat.empty();
}
@Override

View File

@ -4,10 +4,12 @@ import java.util.Arrays;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.BiFunction;
import java.util.function.Predicate;
import java.util.function.IntPredicate;
import java.util.OptionalInt;
import speiger.src.collections.bytes.collections.ByteBidirectionalIterator;
import speiger.src.collections.bytes.functions.ByteConsumer;
@ -15,6 +17,7 @@ import speiger.src.collections.objects.functions.consumer.ObjectByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
import speiger.src.collections.ints.functions.consumer.IntIntConsumer;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.functions.function.BytePredicate;
import speiger.src.collections.bytes.functions.consumer.ByteIntConsumer;
import speiger.src.collections.bytes.functions.function.Byte2IntFunction;
@ -538,6 +541,10 @@ public class ImmutableByte2IntOpenHashMap extends AbstractByte2IntMap implements
}
private class MapEntrySet extends AbstractObjectSet<Byte2IntMap.Entry> implements Byte2IntOrderedMap.FastOrderedSet {
@Override
public void addFirst(Byte2IntMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(Byte2IntMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(Byte2IntMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
@ -691,7 +698,7 @@ public class ImmutableByte2IntOpenHashMap extends AbstractByte2IntMap implements
}
@Override
public Byte2IntMap.Entry reduce(ObjectObjectUnaryOperator<Byte2IntMap.Entry, Byte2IntMap.Entry> operator) {
public Optional<Byte2IntMap.Entry> reduce(ObjectObjectUnaryOperator<Byte2IntMap.Entry, Byte2IntMap.Entry> operator) {
Objects.requireNonNull(operator);
Byte2IntMap.Entry state = null;
boolean empty = true;
@ -706,21 +713,21 @@ public class ImmutableByte2IntOpenHashMap extends AbstractByte2IntMap implements
state = operator.apply(state, new BasicEntry(keys[index], values[index]));
index = (int)links[index];
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public Byte2IntMap.Entry findFirst(Predicate<Byte2IntMap.Entry> filter) {
public Optional<Byte2IntMap.Entry> findFirst(Predicate<Byte2IntMap.Entry> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return null;
if(size() <= 0) return Optional.empty();
BasicEntry entry = new BasicEntry();
int index = firstIndex;
while(index != -1) {
entry.set(keys[index], values[index]);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
index = (int)links[index];
}
return null;
return Optional.empty();
}
@Override
@ -783,6 +790,12 @@ public class ImmutableByte2IntOpenHashMap extends AbstractByte2IntMap implements
throw new UnsupportedOperationException();
}
@Override
public void addFirst(byte o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(byte o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(byte o) { throw new UnsupportedOperationException(); }
@ -918,7 +931,7 @@ public class ImmutableByte2IntOpenHashMap extends AbstractByte2IntMap implements
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -933,19 +946,19 @@ public class ImmutableByte2IntOpenHashMap extends AbstractByte2IntMap implements
state = operator.applyAsByte(state, keys[index]);
index = (int)links[index];
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return (byte)0;
if(size() <= 0) return OptionalByte.empty();
int index = firstIndex;
while(index != -1){
if(filter.test(keys[index])) return keys[index];
if(filter.test(keys[index])) return OptionalByte.of(keys[index]);
index = (int)links[index];
}
return (byte)0;
return OptionalByte.empty();
}
@Override
@ -1072,7 +1085,7 @@ public class ImmutableByte2IntOpenHashMap extends AbstractByte2IntMap implements
}
@Override
public int reduce(IntIntUnaryOperator operator) {
public OptionalInt reduce(IntIntUnaryOperator operator) {
Objects.requireNonNull(operator);
int state = 0;
boolean empty = true;
@ -1087,19 +1100,19 @@ public class ImmutableByte2IntOpenHashMap extends AbstractByte2IntMap implements
state = operator.applyAsInt(state, values[index]);
index = (int)links[index];
}
return state;
return empty ? OptionalInt.empty() : OptionalInt.of(state);
}
@Override
public int findFirst(IntPredicate filter) {
public OptionalInt findFirst(IntPredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return 0;
if(size() <= 0) return OptionalInt.empty();
int index = firstIndex;
while(index != -1){
if(filter.test(values[index])) return values[index];
if(filter.test(values[index])) return OptionalInt.of(values[index]);
index = (int)links[index];
}
return 0;
return OptionalInt.empty();
}
@Override

View File

@ -4,10 +4,12 @@ import java.util.Arrays;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.BiFunction;
import java.util.function.Predicate;
import java.util.function.LongPredicate;
import java.util.OptionalLong;
import speiger.src.collections.bytes.collections.ByteBidirectionalIterator;
import speiger.src.collections.bytes.functions.ByteConsumer;
@ -15,6 +17,7 @@ import speiger.src.collections.objects.functions.consumer.ObjectByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
import speiger.src.collections.ints.functions.consumer.IntLongConsumer;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.functions.function.BytePredicate;
import speiger.src.collections.bytes.functions.consumer.ByteLongConsumer;
import speiger.src.collections.bytes.functions.function.Byte2LongFunction;
@ -538,6 +541,10 @@ public class ImmutableByte2LongOpenHashMap extends AbstractByte2LongMap implemen
}
private class MapEntrySet extends AbstractObjectSet<Byte2LongMap.Entry> implements Byte2LongOrderedMap.FastOrderedSet {
@Override
public void addFirst(Byte2LongMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(Byte2LongMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(Byte2LongMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
@ -691,7 +698,7 @@ public class ImmutableByte2LongOpenHashMap extends AbstractByte2LongMap implemen
}
@Override
public Byte2LongMap.Entry reduce(ObjectObjectUnaryOperator<Byte2LongMap.Entry, Byte2LongMap.Entry> operator) {
public Optional<Byte2LongMap.Entry> reduce(ObjectObjectUnaryOperator<Byte2LongMap.Entry, Byte2LongMap.Entry> operator) {
Objects.requireNonNull(operator);
Byte2LongMap.Entry state = null;
boolean empty = true;
@ -706,21 +713,21 @@ public class ImmutableByte2LongOpenHashMap extends AbstractByte2LongMap implemen
state = operator.apply(state, new BasicEntry(keys[index], values[index]));
index = (int)links[index];
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public Byte2LongMap.Entry findFirst(Predicate<Byte2LongMap.Entry> filter) {
public Optional<Byte2LongMap.Entry> findFirst(Predicate<Byte2LongMap.Entry> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return null;
if(size() <= 0) return Optional.empty();
BasicEntry entry = new BasicEntry();
int index = firstIndex;
while(index != -1) {
entry.set(keys[index], values[index]);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
index = (int)links[index];
}
return null;
return Optional.empty();
}
@Override
@ -783,6 +790,12 @@ public class ImmutableByte2LongOpenHashMap extends AbstractByte2LongMap implemen
throw new UnsupportedOperationException();
}
@Override
public void addFirst(byte o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(byte o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(byte o) { throw new UnsupportedOperationException(); }
@ -918,7 +931,7 @@ public class ImmutableByte2LongOpenHashMap extends AbstractByte2LongMap implemen
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -933,19 +946,19 @@ public class ImmutableByte2LongOpenHashMap extends AbstractByte2LongMap implemen
state = operator.applyAsByte(state, keys[index]);
index = (int)links[index];
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return (byte)0;
if(size() <= 0) return OptionalByte.empty();
int index = firstIndex;
while(index != -1){
if(filter.test(keys[index])) return keys[index];
if(filter.test(keys[index])) return OptionalByte.of(keys[index]);
index = (int)links[index];
}
return (byte)0;
return OptionalByte.empty();
}
@Override
@ -1072,7 +1085,7 @@ public class ImmutableByte2LongOpenHashMap extends AbstractByte2LongMap implemen
}
@Override
public long reduce(LongLongUnaryOperator operator) {
public OptionalLong reduce(LongLongUnaryOperator operator) {
Objects.requireNonNull(operator);
long state = 0L;
boolean empty = true;
@ -1087,19 +1100,19 @@ public class ImmutableByte2LongOpenHashMap extends AbstractByte2LongMap implemen
state = operator.applyAsLong(state, values[index]);
index = (int)links[index];
}
return state;
return empty ? OptionalLong.empty() : OptionalLong.of(state);
}
@Override
public long findFirst(LongPredicate filter) {
public OptionalLong findFirst(LongPredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return 0L;
if(size() <= 0) return OptionalLong.empty();
int index = firstIndex;
while(index != -1){
if(filter.test(values[index])) return values[index];
if(filter.test(values[index])) return OptionalLong.of(values[index]);
index = (int)links[index];
}
return 0L;
return OptionalLong.empty();
}
@Override

View File

@ -4,6 +4,7 @@ import java.util.Arrays;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.BiFunction;
import java.util.function.Predicate;
@ -13,6 +14,7 @@ import speiger.src.collections.bytes.functions.ByteConsumer;
import speiger.src.collections.objects.functions.consumer.ObjectByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.functions.function.BytePredicate;
import speiger.src.collections.bytes.functions.consumer.ByteObjectConsumer;
import speiger.src.collections.bytes.functions.function.ByteFunction;
@ -509,6 +511,10 @@ public class ImmutableByte2ObjectOpenHashMap<V> extends AbstractByte2ObjectMap<V
}
private class MapEntrySet extends AbstractObjectSet<Byte2ObjectMap.Entry<V>> implements Byte2ObjectOrderedMap.FastOrderedSet<V> {
@Override
public void addFirst(Byte2ObjectMap.Entry<V> o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(Byte2ObjectMap.Entry<V> o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(Byte2ObjectMap.Entry<V> o) { throw new UnsupportedOperationException(); }
@Override
@ -662,7 +668,7 @@ public class ImmutableByte2ObjectOpenHashMap<V> extends AbstractByte2ObjectMap<V
}
@Override
public Byte2ObjectMap.Entry<V> reduce(ObjectObjectUnaryOperator<Byte2ObjectMap.Entry<V>, Byte2ObjectMap.Entry<V>> operator) {
public Optional<Byte2ObjectMap.Entry<V>> reduce(ObjectObjectUnaryOperator<Byte2ObjectMap.Entry<V>, Byte2ObjectMap.Entry<V>> operator) {
Objects.requireNonNull(operator);
Byte2ObjectMap.Entry<V> state = null;
boolean empty = true;
@ -677,21 +683,21 @@ public class ImmutableByte2ObjectOpenHashMap<V> extends AbstractByte2ObjectMap<V
state = operator.apply(state, new BasicEntry<>(keys[index], values[index]));
index = (int)links[index];
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public Byte2ObjectMap.Entry<V> findFirst(Predicate<Byte2ObjectMap.Entry<V>> filter) {
public Optional<Byte2ObjectMap.Entry<V>> findFirst(Predicate<Byte2ObjectMap.Entry<V>> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return null;
if(size() <= 0) return Optional.empty();
BasicEntry<V> entry = new BasicEntry<>();
int index = firstIndex;
while(index != -1) {
entry.set(keys[index], values[index]);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
index = (int)links[index];
}
return null;
return Optional.empty();
}
@Override
@ -754,6 +760,12 @@ public class ImmutableByte2ObjectOpenHashMap<V> extends AbstractByte2ObjectMap<V
throw new UnsupportedOperationException();
}
@Override
public void addFirst(byte o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(byte o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(byte o) { throw new UnsupportedOperationException(); }
@ -889,7 +901,7 @@ public class ImmutableByte2ObjectOpenHashMap<V> extends AbstractByte2ObjectMap<V
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -904,19 +916,19 @@ public class ImmutableByte2ObjectOpenHashMap<V> extends AbstractByte2ObjectMap<V
state = operator.applyAsByte(state, keys[index]);
index = (int)links[index];
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return (byte)0;
if(size() <= 0) return OptionalByte.empty();
int index = firstIndex;
while(index != -1){
if(filter.test(keys[index])) return keys[index];
if(filter.test(keys[index])) return OptionalByte.of(keys[index]);
index = (int)links[index];
}
return (byte)0;
return OptionalByte.empty();
}
@Override
@ -1044,7 +1056,7 @@ public class ImmutableByte2ObjectOpenHashMap<V> extends AbstractByte2ObjectMap<V
}
@Override
public V reduce(ObjectObjectUnaryOperator<V, V> operator) {
public Optional<V> reduce(ObjectObjectUnaryOperator<V, V> operator) {
Objects.requireNonNull(operator);
V state = null;
boolean empty = true;
@ -1059,19 +1071,19 @@ public class ImmutableByte2ObjectOpenHashMap<V> extends AbstractByte2ObjectMap<V
state = operator.apply(state, values[index]);
index = (int)links[index];
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public V findFirst(Predicate<V> filter) {
public Optional<V> findFirst(Predicate<V> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return null;
if(size() <= 0) return Optional.empty();
int index = firstIndex;
while(index != -1){
if(filter.test(values[index])) return values[index];
if(filter.test(values[index])) return Optional.ofNullable(values[index]);
index = (int)links[index];
}
return null;
return Optional.empty();
}
@Override

View File

@ -4,6 +4,7 @@ import java.util.Arrays;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.BiFunction;
import java.util.function.Predicate;
@ -14,6 +15,7 @@ import speiger.src.collections.objects.functions.consumer.ObjectByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
import speiger.src.collections.ints.functions.consumer.IntShortConsumer;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.functions.function.BytePredicate;
import speiger.src.collections.bytes.functions.consumer.ByteShortConsumer;
import speiger.src.collections.bytes.functions.function.Byte2ShortFunction;
@ -29,6 +31,7 @@ import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer;
import speiger.src.collections.objects.functions.consumer.ObjectShortConsumer;
import speiger.src.collections.shorts.functions.function.ShortPredicate;
import speiger.src.collections.shorts.functions.OptionalShort;
import speiger.src.collections.bytes.sets.AbstractByteSet;
import speiger.src.collections.shorts.collections.AbstractShortCollection;
import speiger.src.collections.shorts.collections.ShortOrderedCollection;
@ -538,6 +541,10 @@ public class ImmutableByte2ShortOpenHashMap extends AbstractByte2ShortMap implem
}
private class MapEntrySet extends AbstractObjectSet<Byte2ShortMap.Entry> implements Byte2ShortOrderedMap.FastOrderedSet {
@Override
public void addFirst(Byte2ShortMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(Byte2ShortMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(Byte2ShortMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
@ -691,7 +698,7 @@ public class ImmutableByte2ShortOpenHashMap extends AbstractByte2ShortMap implem
}
@Override
public Byte2ShortMap.Entry reduce(ObjectObjectUnaryOperator<Byte2ShortMap.Entry, Byte2ShortMap.Entry> operator) {
public Optional<Byte2ShortMap.Entry> reduce(ObjectObjectUnaryOperator<Byte2ShortMap.Entry, Byte2ShortMap.Entry> operator) {
Objects.requireNonNull(operator);
Byte2ShortMap.Entry state = null;
boolean empty = true;
@ -706,21 +713,21 @@ public class ImmutableByte2ShortOpenHashMap extends AbstractByte2ShortMap implem
state = operator.apply(state, new BasicEntry(keys[index], values[index]));
index = (int)links[index];
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public Byte2ShortMap.Entry findFirst(Predicate<Byte2ShortMap.Entry> filter) {
public Optional<Byte2ShortMap.Entry> findFirst(Predicate<Byte2ShortMap.Entry> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return null;
if(size() <= 0) return Optional.empty();
BasicEntry entry = new BasicEntry();
int index = firstIndex;
while(index != -1) {
entry.set(keys[index], values[index]);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
index = (int)links[index];
}
return null;
return Optional.empty();
}
@Override
@ -783,6 +790,12 @@ public class ImmutableByte2ShortOpenHashMap extends AbstractByte2ShortMap implem
throw new UnsupportedOperationException();
}
@Override
public void addFirst(byte o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(byte o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(byte o) { throw new UnsupportedOperationException(); }
@ -918,7 +931,7 @@ public class ImmutableByte2ShortOpenHashMap extends AbstractByte2ShortMap implem
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -933,19 +946,19 @@ public class ImmutableByte2ShortOpenHashMap extends AbstractByte2ShortMap implem
state = operator.applyAsByte(state, keys[index]);
index = (int)links[index];
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return (byte)0;
if(size() <= 0) return OptionalByte.empty();
int index = firstIndex;
while(index != -1){
if(filter.test(keys[index])) return keys[index];
if(filter.test(keys[index])) return OptionalByte.of(keys[index]);
index = (int)links[index];
}
return (byte)0;
return OptionalByte.empty();
}
@Override
@ -1072,7 +1085,7 @@ public class ImmutableByte2ShortOpenHashMap extends AbstractByte2ShortMap implem
}
@Override
public short reduce(ShortShortUnaryOperator operator) {
public OptionalShort reduce(ShortShortUnaryOperator operator) {
Objects.requireNonNull(operator);
short state = (short)0;
boolean empty = true;
@ -1087,19 +1100,19 @@ public class ImmutableByte2ShortOpenHashMap extends AbstractByte2ShortMap implem
state = operator.applyAsShort(state, values[index]);
index = (int)links[index];
}
return state;
return empty ? OptionalShort.empty() : OptionalShort.of(state);
}
@Override
public short findFirst(ShortPredicate filter) {
public OptionalShort findFirst(ShortPredicate filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return (short)0;
if(size() <= 0) return OptionalShort.empty();
int index = firstIndex;
while(index != -1){
if(filter.test(values[index])) return values[index];
if(filter.test(values[index])) return OptionalShort.of(values[index]);
index = (int)links[index];
}
return (short)0;
return OptionalShort.empty();
}
@Override

View File

@ -4,6 +4,7 @@ import java.util.Arrays;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.BiFunction;
import java.util.function.Predicate;
@ -14,6 +15,7 @@ import speiger.src.collections.objects.functions.consumer.ObjectByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
import speiger.src.collections.ints.functions.consumer.IntBooleanConsumer;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.functions.consumer.ByteBooleanConsumer;
import speiger.src.collections.bytes.functions.function.BytePredicate;
import speiger.src.collections.bytes.functions.function.ByteBooleanUnaryOperator;
@ -34,6 +36,7 @@ import speiger.src.collections.booleans.lists.BooleanListIterator;
import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer;
import speiger.src.collections.booleans.functions.function.BooleanPredicate;
import speiger.src.collections.booleans.functions.OptionalBoolean;
import speiger.src.collections.objects.collections.ObjectIterator;
import speiger.src.collections.objects.functions.function.ObjectObjectUnaryOperator;
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
@ -728,6 +731,10 @@ public class Byte2BooleanArrayMap extends AbstractByte2BooleanMap implements Byt
}
private class MapEntrySet extends AbstractObjectSet<Byte2BooleanMap.Entry> implements Byte2BooleanOrderedMap.FastOrderedSet {
@Override
public void addFirst(Byte2BooleanMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(Byte2BooleanMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(Byte2BooleanMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
@ -876,7 +883,7 @@ public class Byte2BooleanArrayMap extends AbstractByte2BooleanMap implements Byt
}
@Override
public Byte2BooleanMap.Entry reduce(ObjectObjectUnaryOperator<Byte2BooleanMap.Entry, Byte2BooleanMap.Entry> operator) {
public Optional<Byte2BooleanMap.Entry> reduce(ObjectObjectUnaryOperator<Byte2BooleanMap.Entry, Byte2BooleanMap.Entry> operator) {
Objects.requireNonNull(operator);
Byte2BooleanMap.Entry state = null;
boolean empty = true;
@ -888,19 +895,19 @@ public class Byte2BooleanArrayMap extends AbstractByte2BooleanMap implements Byt
}
state = operator.apply(state, new ValueMapEntry(i));
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public Byte2BooleanMap.Entry findFirst(Predicate<Byte2BooleanMap.Entry> filter) {
public Optional<Byte2BooleanMap.Entry> findFirst(Predicate<Byte2BooleanMap.Entry> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return null;
if(size() <= 0) return Optional.empty();
MapEntry entry = new MapEntry();
for(int i = 0;i<size;i++) {
entry.set(i);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
}
return null;
return Optional.empty();
}
@Override
@ -973,6 +980,10 @@ public class Byte2BooleanArrayMap extends AbstractByte2BooleanMap implements Byt
@Override
public boolean add(byte o) { throw new UnsupportedOperationException(); }
@Override
public void addFirst(byte o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(byte o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(byte o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToLast(byte o) { throw new UnsupportedOperationException(); }
@ -1059,7 +1070,7 @@ public class Byte2BooleanArrayMap extends AbstractByte2BooleanMap implements Byt
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -1071,16 +1082,16 @@ public class Byte2BooleanArrayMap extends AbstractByte2BooleanMap implements Byt
}
state = operator.applyAsByte(state, keys[i]);
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
for(int i = 0;i<size;i++) {
if(filter.test(keys[i])) return keys[i];
if(filter.test(keys[i])) return OptionalByte.of(keys[i]);
}
return (byte)0;
return OptionalByte.empty();
}
@Override
@ -1181,7 +1192,7 @@ public class Byte2BooleanArrayMap extends AbstractByte2BooleanMap implements Byt
}
@Override
public boolean reduce(BooleanBooleanUnaryOperator operator) {
public OptionalBoolean reduce(BooleanBooleanUnaryOperator operator) {
Objects.requireNonNull(operator);
boolean state = false;
boolean empty = true;
@ -1193,16 +1204,16 @@ public class Byte2BooleanArrayMap extends AbstractByte2BooleanMap implements Byt
}
state = operator.applyAsBoolean(state, values[i]);
}
return state;
return empty ? OptionalBoolean.empty() : OptionalBoolean.of(state);
}
@Override
public boolean findFirst(BooleanPredicate filter) {
public OptionalBoolean findFirst(BooleanPredicate filter) {
Objects.requireNonNull(filter);
for(int i = 0;i<size;i++) {
if(filter.test(values[i])) return values[i];
if(filter.test(values[i])) return OptionalBoolean.of(values[i]);
}
return false;
return OptionalBoolean.empty();
}
@Override

View File

@ -4,6 +4,7 @@ import java.util.Arrays;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.BiFunction;
import java.util.function.Predicate;
@ -13,6 +14,7 @@ import speiger.src.collections.bytes.functions.ByteConsumer;
import speiger.src.collections.objects.functions.consumer.ObjectByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.functions.function.BytePredicate;
import speiger.src.collections.bytes.functions.consumer.ByteByteConsumer;
import speiger.src.collections.bytes.functions.function.ByteUnaryOperator;
@ -744,6 +746,10 @@ public class Byte2ByteArrayMap extends AbstractByte2ByteMap implements Byte2Byte
}
private class MapEntrySet extends AbstractObjectSet<Byte2ByteMap.Entry> implements Byte2ByteOrderedMap.FastOrderedSet {
@Override
public void addFirst(Byte2ByteMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(Byte2ByteMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(Byte2ByteMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
@ -892,7 +898,7 @@ public class Byte2ByteArrayMap extends AbstractByte2ByteMap implements Byte2Byte
}
@Override
public Byte2ByteMap.Entry reduce(ObjectObjectUnaryOperator<Byte2ByteMap.Entry, Byte2ByteMap.Entry> operator) {
public Optional<Byte2ByteMap.Entry> reduce(ObjectObjectUnaryOperator<Byte2ByteMap.Entry, Byte2ByteMap.Entry> operator) {
Objects.requireNonNull(operator);
Byte2ByteMap.Entry state = null;
boolean empty = true;
@ -904,19 +910,19 @@ public class Byte2ByteArrayMap extends AbstractByte2ByteMap implements Byte2Byte
}
state = operator.apply(state, new ValueMapEntry(i));
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public Byte2ByteMap.Entry findFirst(Predicate<Byte2ByteMap.Entry> filter) {
public Optional<Byte2ByteMap.Entry> findFirst(Predicate<Byte2ByteMap.Entry> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return null;
if(size() <= 0) return Optional.empty();
MapEntry entry = new MapEntry();
for(int i = 0;i<size;i++) {
entry.set(i);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
}
return null;
return Optional.empty();
}
@Override
@ -989,6 +995,10 @@ public class Byte2ByteArrayMap extends AbstractByte2ByteMap implements Byte2Byte
@Override
public boolean add(byte o) { throw new UnsupportedOperationException(); }
@Override
public void addFirst(byte o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(byte o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(byte o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToLast(byte o) { throw new UnsupportedOperationException(); }
@ -1075,7 +1085,7 @@ public class Byte2ByteArrayMap extends AbstractByte2ByteMap implements Byte2Byte
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -1087,16 +1097,16 @@ public class Byte2ByteArrayMap extends AbstractByte2ByteMap implements Byte2Byte
}
state = operator.applyAsByte(state, keys[i]);
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
for(int i = 0;i<size;i++) {
if(filter.test(keys[i])) return keys[i];
if(filter.test(keys[i])) return OptionalByte.of(keys[i]);
}
return (byte)0;
return OptionalByte.empty();
}
@Override
@ -1197,7 +1207,7 @@ public class Byte2ByteArrayMap extends AbstractByte2ByteMap implements Byte2Byte
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -1209,16 +1219,16 @@ public class Byte2ByteArrayMap extends AbstractByte2ByteMap implements Byte2Byte
}
state = operator.applyAsByte(state, values[i]);
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
for(int i = 0;i<size;i++) {
if(filter.test(values[i])) return values[i];
if(filter.test(values[i])) return OptionalByte.of(values[i]);
}
return (byte)0;
return OptionalByte.empty();
}
@Override

View File

@ -4,6 +4,7 @@ import java.util.Arrays;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.BiFunction;
import java.util.function.Predicate;
@ -14,6 +15,7 @@ import speiger.src.collections.objects.functions.consumer.ObjectByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
import speiger.src.collections.ints.functions.consumer.IntCharConsumer;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.functions.function.BytePredicate;
import speiger.src.collections.bytes.functions.consumer.ByteCharConsumer;
import speiger.src.collections.bytes.functions.function.Byte2CharFunction;
@ -35,6 +37,7 @@ import speiger.src.collections.chars.lists.CharListIterator;
import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer;
import speiger.src.collections.chars.functions.function.CharPredicate;
import speiger.src.collections.chars.functions.OptionalChar;
import speiger.src.collections.objects.collections.ObjectIterator;
import speiger.src.collections.objects.functions.function.ObjectObjectUnaryOperator;
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
@ -751,6 +754,10 @@ public class Byte2CharArrayMap extends AbstractByte2CharMap implements Byte2Char
}
private class MapEntrySet extends AbstractObjectSet<Byte2CharMap.Entry> implements Byte2CharOrderedMap.FastOrderedSet {
@Override
public void addFirst(Byte2CharMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(Byte2CharMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(Byte2CharMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
@ -899,7 +906,7 @@ public class Byte2CharArrayMap extends AbstractByte2CharMap implements Byte2Char
}
@Override
public Byte2CharMap.Entry reduce(ObjectObjectUnaryOperator<Byte2CharMap.Entry, Byte2CharMap.Entry> operator) {
public Optional<Byte2CharMap.Entry> reduce(ObjectObjectUnaryOperator<Byte2CharMap.Entry, Byte2CharMap.Entry> operator) {
Objects.requireNonNull(operator);
Byte2CharMap.Entry state = null;
boolean empty = true;
@ -911,19 +918,19 @@ public class Byte2CharArrayMap extends AbstractByte2CharMap implements Byte2Char
}
state = operator.apply(state, new ValueMapEntry(i));
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public Byte2CharMap.Entry findFirst(Predicate<Byte2CharMap.Entry> filter) {
public Optional<Byte2CharMap.Entry> findFirst(Predicate<Byte2CharMap.Entry> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return null;
if(size() <= 0) return Optional.empty();
MapEntry entry = new MapEntry();
for(int i = 0;i<size;i++) {
entry.set(i);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
}
return null;
return Optional.empty();
}
@Override
@ -996,6 +1003,10 @@ public class Byte2CharArrayMap extends AbstractByte2CharMap implements Byte2Char
@Override
public boolean add(byte o) { throw new UnsupportedOperationException(); }
@Override
public void addFirst(byte o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(byte o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(byte o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToLast(byte o) { throw new UnsupportedOperationException(); }
@ -1082,7 +1093,7 @@ public class Byte2CharArrayMap extends AbstractByte2CharMap implements Byte2Char
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -1094,16 +1105,16 @@ public class Byte2CharArrayMap extends AbstractByte2CharMap implements Byte2Char
}
state = operator.applyAsByte(state, keys[i]);
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
for(int i = 0;i<size;i++) {
if(filter.test(keys[i])) return keys[i];
if(filter.test(keys[i])) return OptionalByte.of(keys[i]);
}
return (byte)0;
return OptionalByte.empty();
}
@Override
@ -1204,7 +1215,7 @@ public class Byte2CharArrayMap extends AbstractByte2CharMap implements Byte2Char
}
@Override
public char reduce(CharCharUnaryOperator operator) {
public OptionalChar reduce(CharCharUnaryOperator operator) {
Objects.requireNonNull(operator);
char state = (char)0;
boolean empty = true;
@ -1216,16 +1227,16 @@ public class Byte2CharArrayMap extends AbstractByte2CharMap implements Byte2Char
}
state = operator.applyAsChar(state, values[i]);
}
return state;
return empty ? OptionalChar.empty() : OptionalChar.of(state);
}
@Override
public char findFirst(CharPredicate filter) {
public OptionalChar findFirst(CharPredicate filter) {
Objects.requireNonNull(filter);
for(int i = 0;i<size;i++) {
if(filter.test(values[i])) return values[i];
if(filter.test(values[i])) return OptionalChar.of(values[i]);
}
return (char)0;
return OptionalChar.empty();
}
@Override

View File

@ -4,10 +4,12 @@ import java.util.Arrays;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.BiFunction;
import java.util.function.Predicate;
import java.util.function.DoublePredicate;
import java.util.OptionalDouble;
import speiger.src.collections.bytes.collections.ByteBidirectionalIterator;
import speiger.src.collections.bytes.functions.ByteConsumer;
@ -15,6 +17,7 @@ import speiger.src.collections.objects.functions.consumer.ObjectByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
import speiger.src.collections.ints.functions.consumer.IntDoubleConsumer;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.functions.function.BytePredicate;
import speiger.src.collections.bytes.functions.consumer.ByteDoubleConsumer;
import speiger.src.collections.bytes.functions.function.Byte2DoubleFunction;
@ -751,6 +754,10 @@ public class Byte2DoubleArrayMap extends AbstractByte2DoubleMap implements Byte2
}
private class MapEntrySet extends AbstractObjectSet<Byte2DoubleMap.Entry> implements Byte2DoubleOrderedMap.FastOrderedSet {
@Override
public void addFirst(Byte2DoubleMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(Byte2DoubleMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(Byte2DoubleMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
@ -899,7 +906,7 @@ public class Byte2DoubleArrayMap extends AbstractByte2DoubleMap implements Byte2
}
@Override
public Byte2DoubleMap.Entry reduce(ObjectObjectUnaryOperator<Byte2DoubleMap.Entry, Byte2DoubleMap.Entry> operator) {
public Optional<Byte2DoubleMap.Entry> reduce(ObjectObjectUnaryOperator<Byte2DoubleMap.Entry, Byte2DoubleMap.Entry> operator) {
Objects.requireNonNull(operator);
Byte2DoubleMap.Entry state = null;
boolean empty = true;
@ -911,19 +918,19 @@ public class Byte2DoubleArrayMap extends AbstractByte2DoubleMap implements Byte2
}
state = operator.apply(state, new ValueMapEntry(i));
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public Byte2DoubleMap.Entry findFirst(Predicate<Byte2DoubleMap.Entry> filter) {
public Optional<Byte2DoubleMap.Entry> findFirst(Predicate<Byte2DoubleMap.Entry> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return null;
if(size() <= 0) return Optional.empty();
MapEntry entry = new MapEntry();
for(int i = 0;i<size;i++) {
entry.set(i);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
}
return null;
return Optional.empty();
}
@Override
@ -996,6 +1003,10 @@ public class Byte2DoubleArrayMap extends AbstractByte2DoubleMap implements Byte2
@Override
public boolean add(byte o) { throw new UnsupportedOperationException(); }
@Override
public void addFirst(byte o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(byte o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(byte o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToLast(byte o) { throw new UnsupportedOperationException(); }
@ -1082,7 +1093,7 @@ public class Byte2DoubleArrayMap extends AbstractByte2DoubleMap implements Byte2
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -1094,16 +1105,16 @@ public class Byte2DoubleArrayMap extends AbstractByte2DoubleMap implements Byte2
}
state = operator.applyAsByte(state, keys[i]);
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
for(int i = 0;i<size;i++) {
if(filter.test(keys[i])) return keys[i];
if(filter.test(keys[i])) return OptionalByte.of(keys[i]);
}
return (byte)0;
return OptionalByte.empty();
}
@Override
@ -1204,7 +1215,7 @@ public class Byte2DoubleArrayMap extends AbstractByte2DoubleMap implements Byte2
}
@Override
public double reduce(DoubleDoubleUnaryOperator operator) {
public OptionalDouble reduce(DoubleDoubleUnaryOperator operator) {
Objects.requireNonNull(operator);
double state = 0D;
boolean empty = true;
@ -1216,16 +1227,16 @@ public class Byte2DoubleArrayMap extends AbstractByte2DoubleMap implements Byte2
}
state = operator.applyAsDouble(state, values[i]);
}
return state;
return empty ? OptionalDouble.empty() : OptionalDouble.of(state);
}
@Override
public double findFirst(DoublePredicate filter) {
public OptionalDouble findFirst(DoublePredicate filter) {
Objects.requireNonNull(filter);
for(int i = 0;i<size;i++) {
if(filter.test(values[i])) return values[i];
if(filter.test(values[i])) return OptionalDouble.of(values[i]);
}
return 0D;
return OptionalDouble.empty();
}
@Override

View File

@ -4,6 +4,7 @@ import java.util.Arrays;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.BiFunction;
import java.util.function.Predicate;
@ -14,6 +15,7 @@ import speiger.src.collections.objects.functions.consumer.ObjectByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
import speiger.src.collections.ints.functions.consumer.IntFloatConsumer;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.functions.function.BytePredicate;
import speiger.src.collections.bytes.functions.consumer.ByteFloatConsumer;
import speiger.src.collections.bytes.functions.function.Byte2FloatFunction;
@ -35,6 +37,7 @@ import speiger.src.collections.floats.lists.FloatListIterator;
import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer;
import speiger.src.collections.floats.functions.function.FloatPredicate;
import speiger.src.collections.floats.functions.OptionalFloat;
import speiger.src.collections.objects.collections.ObjectIterator;
import speiger.src.collections.objects.functions.function.ObjectObjectUnaryOperator;
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
@ -751,6 +754,10 @@ public class Byte2FloatArrayMap extends AbstractByte2FloatMap implements Byte2Fl
}
private class MapEntrySet extends AbstractObjectSet<Byte2FloatMap.Entry> implements Byte2FloatOrderedMap.FastOrderedSet {
@Override
public void addFirst(Byte2FloatMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(Byte2FloatMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(Byte2FloatMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
@ -899,7 +906,7 @@ public class Byte2FloatArrayMap extends AbstractByte2FloatMap implements Byte2Fl
}
@Override
public Byte2FloatMap.Entry reduce(ObjectObjectUnaryOperator<Byte2FloatMap.Entry, Byte2FloatMap.Entry> operator) {
public Optional<Byte2FloatMap.Entry> reduce(ObjectObjectUnaryOperator<Byte2FloatMap.Entry, Byte2FloatMap.Entry> operator) {
Objects.requireNonNull(operator);
Byte2FloatMap.Entry state = null;
boolean empty = true;
@ -911,19 +918,19 @@ public class Byte2FloatArrayMap extends AbstractByte2FloatMap implements Byte2Fl
}
state = operator.apply(state, new ValueMapEntry(i));
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public Byte2FloatMap.Entry findFirst(Predicate<Byte2FloatMap.Entry> filter) {
public Optional<Byte2FloatMap.Entry> findFirst(Predicate<Byte2FloatMap.Entry> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return null;
if(size() <= 0) return Optional.empty();
MapEntry entry = new MapEntry();
for(int i = 0;i<size;i++) {
entry.set(i);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
}
return null;
return Optional.empty();
}
@Override
@ -996,6 +1003,10 @@ public class Byte2FloatArrayMap extends AbstractByte2FloatMap implements Byte2Fl
@Override
public boolean add(byte o) { throw new UnsupportedOperationException(); }
@Override
public void addFirst(byte o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(byte o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(byte o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToLast(byte o) { throw new UnsupportedOperationException(); }
@ -1082,7 +1093,7 @@ public class Byte2FloatArrayMap extends AbstractByte2FloatMap implements Byte2Fl
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -1094,16 +1105,16 @@ public class Byte2FloatArrayMap extends AbstractByte2FloatMap implements Byte2Fl
}
state = operator.applyAsByte(state, keys[i]);
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
for(int i = 0;i<size;i++) {
if(filter.test(keys[i])) return keys[i];
if(filter.test(keys[i])) return OptionalByte.of(keys[i]);
}
return (byte)0;
return OptionalByte.empty();
}
@Override
@ -1204,7 +1215,7 @@ public class Byte2FloatArrayMap extends AbstractByte2FloatMap implements Byte2Fl
}
@Override
public float reduce(FloatFloatUnaryOperator operator) {
public OptionalFloat reduce(FloatFloatUnaryOperator operator) {
Objects.requireNonNull(operator);
float state = 0F;
boolean empty = true;
@ -1216,16 +1227,16 @@ public class Byte2FloatArrayMap extends AbstractByte2FloatMap implements Byte2Fl
}
state = operator.applyAsFloat(state, values[i]);
}
return state;
return empty ? OptionalFloat.empty() : OptionalFloat.of(state);
}
@Override
public float findFirst(FloatPredicate filter) {
public OptionalFloat findFirst(FloatPredicate filter) {
Objects.requireNonNull(filter);
for(int i = 0;i<size;i++) {
if(filter.test(values[i])) return values[i];
if(filter.test(values[i])) return OptionalFloat.of(values[i]);
}
return 0F;
return OptionalFloat.empty();
}
@Override

View File

@ -4,10 +4,12 @@ import java.util.Arrays;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.BiFunction;
import java.util.function.Predicate;
import java.util.function.IntPredicate;
import java.util.OptionalInt;
import speiger.src.collections.bytes.collections.ByteBidirectionalIterator;
import speiger.src.collections.bytes.functions.ByteConsumer;
@ -15,6 +17,7 @@ import speiger.src.collections.objects.functions.consumer.ObjectByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
import speiger.src.collections.ints.functions.consumer.IntIntConsumer;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.functions.function.BytePredicate;
import speiger.src.collections.bytes.functions.consumer.ByteIntConsumer;
import speiger.src.collections.bytes.functions.function.Byte2IntFunction;
@ -751,6 +754,10 @@ public class Byte2IntArrayMap extends AbstractByte2IntMap implements Byte2IntOrd
}
private class MapEntrySet extends AbstractObjectSet<Byte2IntMap.Entry> implements Byte2IntOrderedMap.FastOrderedSet {
@Override
public void addFirst(Byte2IntMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(Byte2IntMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(Byte2IntMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
@ -899,7 +906,7 @@ public class Byte2IntArrayMap extends AbstractByte2IntMap implements Byte2IntOrd
}
@Override
public Byte2IntMap.Entry reduce(ObjectObjectUnaryOperator<Byte2IntMap.Entry, Byte2IntMap.Entry> operator) {
public Optional<Byte2IntMap.Entry> reduce(ObjectObjectUnaryOperator<Byte2IntMap.Entry, Byte2IntMap.Entry> operator) {
Objects.requireNonNull(operator);
Byte2IntMap.Entry state = null;
boolean empty = true;
@ -911,19 +918,19 @@ public class Byte2IntArrayMap extends AbstractByte2IntMap implements Byte2IntOrd
}
state = operator.apply(state, new ValueMapEntry(i));
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public Byte2IntMap.Entry findFirst(Predicate<Byte2IntMap.Entry> filter) {
public Optional<Byte2IntMap.Entry> findFirst(Predicate<Byte2IntMap.Entry> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return null;
if(size() <= 0) return Optional.empty();
MapEntry entry = new MapEntry();
for(int i = 0;i<size;i++) {
entry.set(i);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
}
return null;
return Optional.empty();
}
@Override
@ -996,6 +1003,10 @@ public class Byte2IntArrayMap extends AbstractByte2IntMap implements Byte2IntOrd
@Override
public boolean add(byte o) { throw new UnsupportedOperationException(); }
@Override
public void addFirst(byte o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(byte o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(byte o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToLast(byte o) { throw new UnsupportedOperationException(); }
@ -1082,7 +1093,7 @@ public class Byte2IntArrayMap extends AbstractByte2IntMap implements Byte2IntOrd
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -1094,16 +1105,16 @@ public class Byte2IntArrayMap extends AbstractByte2IntMap implements Byte2IntOrd
}
state = operator.applyAsByte(state, keys[i]);
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
for(int i = 0;i<size;i++) {
if(filter.test(keys[i])) return keys[i];
if(filter.test(keys[i])) return OptionalByte.of(keys[i]);
}
return (byte)0;
return OptionalByte.empty();
}
@Override
@ -1204,7 +1215,7 @@ public class Byte2IntArrayMap extends AbstractByte2IntMap implements Byte2IntOrd
}
@Override
public int reduce(IntIntUnaryOperator operator) {
public OptionalInt reduce(IntIntUnaryOperator operator) {
Objects.requireNonNull(operator);
int state = 0;
boolean empty = true;
@ -1216,16 +1227,16 @@ public class Byte2IntArrayMap extends AbstractByte2IntMap implements Byte2IntOrd
}
state = operator.applyAsInt(state, values[i]);
}
return state;
return empty ? OptionalInt.empty() : OptionalInt.of(state);
}
@Override
public int findFirst(IntPredicate filter) {
public OptionalInt findFirst(IntPredicate filter) {
Objects.requireNonNull(filter);
for(int i = 0;i<size;i++) {
if(filter.test(values[i])) return values[i];
if(filter.test(values[i])) return OptionalInt.of(values[i]);
}
return 0;
return OptionalInt.empty();
}
@Override

View File

@ -4,10 +4,12 @@ import java.util.Arrays;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.BiFunction;
import java.util.function.Predicate;
import java.util.function.LongPredicate;
import java.util.OptionalLong;
import speiger.src.collections.bytes.collections.ByteBidirectionalIterator;
import speiger.src.collections.bytes.functions.ByteConsumer;
@ -15,6 +17,7 @@ import speiger.src.collections.objects.functions.consumer.ObjectByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
import speiger.src.collections.ints.functions.consumer.IntLongConsumer;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.functions.function.BytePredicate;
import speiger.src.collections.bytes.functions.consumer.ByteLongConsumer;
import speiger.src.collections.bytes.functions.function.Byte2LongFunction;
@ -751,6 +754,10 @@ public class Byte2LongArrayMap extends AbstractByte2LongMap implements Byte2Long
}
private class MapEntrySet extends AbstractObjectSet<Byte2LongMap.Entry> implements Byte2LongOrderedMap.FastOrderedSet {
@Override
public void addFirst(Byte2LongMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(Byte2LongMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(Byte2LongMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
@ -899,7 +906,7 @@ public class Byte2LongArrayMap extends AbstractByte2LongMap implements Byte2Long
}
@Override
public Byte2LongMap.Entry reduce(ObjectObjectUnaryOperator<Byte2LongMap.Entry, Byte2LongMap.Entry> operator) {
public Optional<Byte2LongMap.Entry> reduce(ObjectObjectUnaryOperator<Byte2LongMap.Entry, Byte2LongMap.Entry> operator) {
Objects.requireNonNull(operator);
Byte2LongMap.Entry state = null;
boolean empty = true;
@ -911,19 +918,19 @@ public class Byte2LongArrayMap extends AbstractByte2LongMap implements Byte2Long
}
state = operator.apply(state, new ValueMapEntry(i));
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public Byte2LongMap.Entry findFirst(Predicate<Byte2LongMap.Entry> filter) {
public Optional<Byte2LongMap.Entry> findFirst(Predicate<Byte2LongMap.Entry> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return null;
if(size() <= 0) return Optional.empty();
MapEntry entry = new MapEntry();
for(int i = 0;i<size;i++) {
entry.set(i);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
}
return null;
return Optional.empty();
}
@Override
@ -996,6 +1003,10 @@ public class Byte2LongArrayMap extends AbstractByte2LongMap implements Byte2Long
@Override
public boolean add(byte o) { throw new UnsupportedOperationException(); }
@Override
public void addFirst(byte o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(byte o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(byte o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToLast(byte o) { throw new UnsupportedOperationException(); }
@ -1082,7 +1093,7 @@ public class Byte2LongArrayMap extends AbstractByte2LongMap implements Byte2Long
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -1094,16 +1105,16 @@ public class Byte2LongArrayMap extends AbstractByte2LongMap implements Byte2Long
}
state = operator.applyAsByte(state, keys[i]);
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
for(int i = 0;i<size;i++) {
if(filter.test(keys[i])) return keys[i];
if(filter.test(keys[i])) return OptionalByte.of(keys[i]);
}
return (byte)0;
return OptionalByte.empty();
}
@Override
@ -1204,7 +1215,7 @@ public class Byte2LongArrayMap extends AbstractByte2LongMap implements Byte2Long
}
@Override
public long reduce(LongLongUnaryOperator operator) {
public OptionalLong reduce(LongLongUnaryOperator operator) {
Objects.requireNonNull(operator);
long state = 0L;
boolean empty = true;
@ -1216,16 +1227,16 @@ public class Byte2LongArrayMap extends AbstractByte2LongMap implements Byte2Long
}
state = operator.applyAsLong(state, values[i]);
}
return state;
return empty ? OptionalLong.empty() : OptionalLong.of(state);
}
@Override
public long findFirst(LongPredicate filter) {
public OptionalLong findFirst(LongPredicate filter) {
Objects.requireNonNull(filter);
for(int i = 0;i<size;i++) {
if(filter.test(values[i])) return values[i];
if(filter.test(values[i])) return OptionalLong.of(values[i]);
}
return 0L;
return OptionalLong.empty();
}
@Override

View File

@ -4,6 +4,7 @@ import java.util.Arrays;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.BiFunction;
import java.util.function.Predicate;
@ -13,6 +14,7 @@ import speiger.src.collections.bytes.functions.ByteConsumer;
import speiger.src.collections.objects.functions.consumer.ObjectByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.functions.function.BytePredicate;
import speiger.src.collections.bytes.functions.consumer.ByteObjectConsumer;
import speiger.src.collections.bytes.functions.function.ByteFunction;
@ -664,6 +666,10 @@ public class Byte2ObjectArrayMap<V> extends AbstractByte2ObjectMap<V> implements
}
private class MapEntrySet extends AbstractObjectSet<Byte2ObjectMap.Entry<V>> implements Byte2ObjectOrderedMap.FastOrderedSet<V> {
@Override
public void addFirst(Byte2ObjectMap.Entry<V> o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(Byte2ObjectMap.Entry<V> o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(Byte2ObjectMap.Entry<V> o) { throw new UnsupportedOperationException(); }
@Override
@ -812,7 +818,7 @@ public class Byte2ObjectArrayMap<V> extends AbstractByte2ObjectMap<V> implements
}
@Override
public Byte2ObjectMap.Entry<V> reduce(ObjectObjectUnaryOperator<Byte2ObjectMap.Entry<V>, Byte2ObjectMap.Entry<V>> operator) {
public Optional<Byte2ObjectMap.Entry<V>> reduce(ObjectObjectUnaryOperator<Byte2ObjectMap.Entry<V>, Byte2ObjectMap.Entry<V>> operator) {
Objects.requireNonNull(operator);
Byte2ObjectMap.Entry<V> state = null;
boolean empty = true;
@ -824,19 +830,19 @@ public class Byte2ObjectArrayMap<V> extends AbstractByte2ObjectMap<V> implements
}
state = operator.apply(state, new ValueMapEntry(i));
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public Byte2ObjectMap.Entry<V> findFirst(Predicate<Byte2ObjectMap.Entry<V>> filter) {
public Optional<Byte2ObjectMap.Entry<V>> findFirst(Predicate<Byte2ObjectMap.Entry<V>> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return null;
if(size() <= 0) return Optional.empty();
MapEntry entry = new MapEntry();
for(int i = 0;i<size;i++) {
entry.set(i);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
}
return null;
return Optional.empty();
}
@Override
@ -909,6 +915,10 @@ public class Byte2ObjectArrayMap<V> extends AbstractByte2ObjectMap<V> implements
@Override
public boolean add(byte o) { throw new UnsupportedOperationException(); }
@Override
public void addFirst(byte o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(byte o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(byte o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToLast(byte o) { throw new UnsupportedOperationException(); }
@ -995,7 +1005,7 @@ public class Byte2ObjectArrayMap<V> extends AbstractByte2ObjectMap<V> implements
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -1007,16 +1017,16 @@ public class Byte2ObjectArrayMap<V> extends AbstractByte2ObjectMap<V> implements
}
state = operator.applyAsByte(state, keys[i]);
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
for(int i = 0;i<size;i++) {
if(filter.test(keys[i])) return keys[i];
if(filter.test(keys[i])) return OptionalByte.of(keys[i]);
}
return (byte)0;
return OptionalByte.empty();
}
@Override
@ -1117,7 +1127,7 @@ public class Byte2ObjectArrayMap<V> extends AbstractByte2ObjectMap<V> implements
}
@Override
public V reduce(ObjectObjectUnaryOperator<V, V> operator) {
public Optional<V> reduce(ObjectObjectUnaryOperator<V, V> operator) {
Objects.requireNonNull(operator);
V state = null;
boolean empty = true;
@ -1129,16 +1139,16 @@ public class Byte2ObjectArrayMap<V> extends AbstractByte2ObjectMap<V> implements
}
state = operator.apply(state, values[i]);
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public V findFirst(Predicate<V> filter) {
public Optional<V> findFirst(Predicate<V> filter) {
Objects.requireNonNull(filter);
for(int i = 0;i<size;i++) {
if(filter.test(values[i])) return values[i];
if(filter.test(values[i])) return Optional.ofNullable(values[i]);
}
return null;
return Optional.empty();
}
@Override

View File

@ -4,6 +4,7 @@ import java.util.Arrays;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.BiFunction;
import java.util.function.Predicate;
@ -14,6 +15,7 @@ import speiger.src.collections.objects.functions.consumer.ObjectByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntByteConsumer;
import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
import speiger.src.collections.ints.functions.consumer.IntShortConsumer;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.functions.function.BytePredicate;
import speiger.src.collections.bytes.functions.consumer.ByteShortConsumer;
import speiger.src.collections.bytes.functions.function.Byte2ShortFunction;
@ -35,6 +37,7 @@ import speiger.src.collections.shorts.lists.ShortListIterator;
import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer;
import speiger.src.collections.shorts.functions.function.ShortPredicate;
import speiger.src.collections.shorts.functions.OptionalShort;
import speiger.src.collections.objects.collections.ObjectIterator;
import speiger.src.collections.objects.functions.function.ObjectObjectUnaryOperator;
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
@ -751,6 +754,10 @@ public class Byte2ShortArrayMap extends AbstractByte2ShortMap implements Byte2Sh
}
private class MapEntrySet extends AbstractObjectSet<Byte2ShortMap.Entry> implements Byte2ShortOrderedMap.FastOrderedSet {
@Override
public void addFirst(Byte2ShortMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(Byte2ShortMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(Byte2ShortMap.Entry o) { throw new UnsupportedOperationException(); }
@Override
@ -899,7 +906,7 @@ public class Byte2ShortArrayMap extends AbstractByte2ShortMap implements Byte2Sh
}
@Override
public Byte2ShortMap.Entry reduce(ObjectObjectUnaryOperator<Byte2ShortMap.Entry, Byte2ShortMap.Entry> operator) {
public Optional<Byte2ShortMap.Entry> reduce(ObjectObjectUnaryOperator<Byte2ShortMap.Entry, Byte2ShortMap.Entry> operator) {
Objects.requireNonNull(operator);
Byte2ShortMap.Entry state = null;
boolean empty = true;
@ -911,19 +918,19 @@ public class Byte2ShortArrayMap extends AbstractByte2ShortMap implements Byte2Sh
}
state = operator.apply(state, new ValueMapEntry(i));
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public Byte2ShortMap.Entry findFirst(Predicate<Byte2ShortMap.Entry> filter) {
public Optional<Byte2ShortMap.Entry> findFirst(Predicate<Byte2ShortMap.Entry> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return null;
if(size() <= 0) return Optional.empty();
MapEntry entry = new MapEntry();
for(int i = 0;i<size;i++) {
entry.set(i);
if(filter.test(entry)) return entry;
if(filter.test(entry)) return Optional.ofNullable(entry);
}
return null;
return Optional.empty();
}
@Override
@ -996,6 +1003,10 @@ public class Byte2ShortArrayMap extends AbstractByte2ShortMap implements Byte2Sh
@Override
public boolean add(byte o) { throw new UnsupportedOperationException(); }
@Override
public void addFirst(byte o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(byte o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToFirst(byte o) { throw new UnsupportedOperationException(); }
@Override
public boolean addAndMoveToLast(byte o) { throw new UnsupportedOperationException(); }
@ -1082,7 +1093,7 @@ public class Byte2ShortArrayMap extends AbstractByte2ShortMap implements Byte2Sh
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -1094,16 +1105,16 @@ public class Byte2ShortArrayMap extends AbstractByte2ShortMap implements Byte2Sh
}
state = operator.applyAsByte(state, keys[i]);
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
for(int i = 0;i<size;i++) {
if(filter.test(keys[i])) return keys[i];
if(filter.test(keys[i])) return OptionalByte.of(keys[i]);
}
return (byte)0;
return OptionalByte.empty();
}
@Override
@ -1204,7 +1215,7 @@ public class Byte2ShortArrayMap extends AbstractByte2ShortMap implements Byte2Sh
}
@Override
public short reduce(ShortShortUnaryOperator operator) {
public OptionalShort reduce(ShortShortUnaryOperator operator) {
Objects.requireNonNull(operator);
short state = (short)0;
boolean empty = true;
@ -1216,16 +1227,16 @@ public class Byte2ShortArrayMap extends AbstractByte2ShortMap implements Byte2Sh
}
state = operator.applyAsShort(state, values[i]);
}
return state;
return empty ? OptionalShort.empty() : OptionalShort.of(state);
}
@Override
public short findFirst(ShortPredicate filter) {
public OptionalShort findFirst(ShortPredicate filter) {
Objects.requireNonNull(filter);
for(int i = 0;i<size;i++) {
if(filter.test(values[i])) return values[i];
if(filter.test(values[i])) return OptionalShort.of(values[i]);
}
return (short)0;
return OptionalShort.empty();
}
@Override

View File

@ -3,6 +3,7 @@ package speiger.src.collections.bytes.maps.impl.tree;
import java.util.Collections;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.NoSuchElementException;
import java.util.function.Consumer;
import java.util.function.BiFunction;
@ -18,6 +19,7 @@ import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
import speiger.src.collections.ints.functions.consumer.IntBooleanConsumer;
import speiger.src.collections.bytes.functions.function.BytePredicate;
import speiger.src.collections.bytes.functions.consumer.ByteBooleanConsumer;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.functions.function.ByteBooleanUnaryOperator;
import speiger.src.collections.bytes.functions.function.ByteByteUnaryOperator;
import speiger.src.collections.bytes.maps.abstracts.AbstractByte2BooleanMap;
@ -36,6 +38,7 @@ import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer;
import speiger.src.collections.objects.functions.consumer.ObjectBooleanConsumer;
import speiger.src.collections.booleans.functions.function.BooleanPredicate;
import speiger.src.collections.booleans.functions.OptionalBoolean;
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
import speiger.src.collections.objects.collections.ObjectIterator;
import speiger.src.collections.objects.functions.function.ObjectObjectUnaryOperator;
@ -1070,7 +1073,7 @@ public class Byte2BooleanAVLTreeMap extends AbstractByte2BooleanMap implements B
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -1082,15 +1085,15 @@ public class Byte2BooleanAVLTreeMap extends AbstractByte2BooleanMap implements B
}
state = operator.applyAsByte(state, entry.key);
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
for(Node entry = start(), end = end();entry != null && (end == null || (end != previous(entry)));entry = next(entry))
if(filter.test(entry.key)) return entry.key;
return (byte)0;
if(filter.test(entry.key)) return OptionalByte.of(entry.key);
return OptionalByte.empty();
}
@Override
@ -1712,7 +1715,7 @@ public class Byte2BooleanAVLTreeMap extends AbstractByte2BooleanMap implements B
}
@Override
public Byte2BooleanMap.Entry reduce(ObjectObjectUnaryOperator<Byte2BooleanMap.Entry, Byte2BooleanMap.Entry> operator) {
public Optional<Byte2BooleanMap.Entry> reduce(ObjectObjectUnaryOperator<Byte2BooleanMap.Entry, Byte2BooleanMap.Entry> operator) {
Objects.requireNonNull(operator);
Byte2BooleanMap.Entry state = null;
boolean empty = true;
@ -1724,19 +1727,19 @@ public class Byte2BooleanAVLTreeMap extends AbstractByte2BooleanMap implements B
}
state = operator.apply(state, new BasicEntry(entry.key, entry.value));
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public Byte2BooleanMap.Entry findFirst(Predicate<Byte2BooleanMap.Entry> filter) {
public Optional<Byte2BooleanMap.Entry> findFirst(Predicate<Byte2BooleanMap.Entry> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return null;
if(size() <= 0) return Optional.empty();
BasicEntry subEntry = new BasicEntry();
for(Node entry = subLowest(), last = subHighest();entry != null && (last == null || last != previous(entry));entry = next(entry)) {
subEntry.set(entry.key, entry.value);
if(filter.test(subEntry)) return subEntry;
if(filter.test(subEntry)) return Optional.ofNullable(subEntry);
}
return null;
return Optional.empty();
}
@Override
@ -1831,7 +1834,7 @@ public class Byte2BooleanAVLTreeMap extends AbstractByte2BooleanMap implements B
}
@Override
public boolean reduce(BooleanBooleanUnaryOperator operator) {
public OptionalBoolean reduce(BooleanBooleanUnaryOperator operator) {
Objects.requireNonNull(operator);
boolean state = false;
boolean empty = true;
@ -1843,15 +1846,15 @@ public class Byte2BooleanAVLTreeMap extends AbstractByte2BooleanMap implements B
}
state = operator.applyAsBoolean(state, entry.value);
}
return state;
return empty ? OptionalBoolean.empty() : OptionalBoolean.of(state);
}
@Override
public boolean findFirst(BooleanPredicate filter) {
public OptionalBoolean findFirst(BooleanPredicate filter) {
Objects.requireNonNull(filter);
for(Node entry = subLowest(), last = subHighest();entry != null && (last == null || last != previous(entry));entry = next(entry))
if(filter.test(entry.value)) return entry.value;
return false;
if(filter.test(entry.value)) return OptionalBoolean.of(entry.value);
return OptionalBoolean.empty();
}
@Override
@ -2167,7 +2170,7 @@ public class Byte2BooleanAVLTreeMap extends AbstractByte2BooleanMap implements B
}
@Override
public boolean reduce(BooleanBooleanUnaryOperator operator) {
public OptionalBoolean reduce(BooleanBooleanUnaryOperator operator) {
Objects.requireNonNull(operator);
boolean state = false;
boolean empty = true;
@ -2179,15 +2182,15 @@ public class Byte2BooleanAVLTreeMap extends AbstractByte2BooleanMap implements B
}
state = operator.applyAsBoolean(state, entry.value);
}
return state;
return empty ? OptionalBoolean.empty() : OptionalBoolean.of(state);
}
@Override
public boolean findFirst(BooleanPredicate filter) {
public OptionalBoolean findFirst(BooleanPredicate filter) {
Objects.requireNonNull(filter);
for(Node entry = first;entry != null;entry = entry.next())
if(filter.test(entry.value)) return entry.value;
return false;
if(filter.test(entry.value)) return OptionalBoolean.of(entry.value);
return OptionalBoolean.empty();
}
@Override
@ -2328,7 +2331,7 @@ public class Byte2BooleanAVLTreeMap extends AbstractByte2BooleanMap implements B
}
@Override
public Byte2BooleanMap.Entry reduce(ObjectObjectUnaryOperator<Byte2BooleanMap.Entry, Byte2BooleanMap.Entry> operator) {
public Optional<Byte2BooleanMap.Entry> reduce(ObjectObjectUnaryOperator<Byte2BooleanMap.Entry, Byte2BooleanMap.Entry> operator) {
Objects.requireNonNull(operator);
Byte2BooleanMap.Entry state = null;
boolean empty = true;
@ -2340,19 +2343,19 @@ public class Byte2BooleanAVLTreeMap extends AbstractByte2BooleanMap implements B
}
state = operator.apply(state, new BasicEntry(entry.key, entry.value));
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public Byte2BooleanMap.Entry findFirst(Predicate<Byte2BooleanMap.Entry> filter) {
public Optional<Byte2BooleanMap.Entry> findFirst(Predicate<Byte2BooleanMap.Entry> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return null;
if(size() <= 0) return Optional.empty();
BasicEntry subEntry = new BasicEntry();
for(Node entry = first;entry != null;entry = entry.next()) {
subEntry.set(entry.key, entry.value);
if(filter.test(subEntry)) return subEntry;
if(filter.test(subEntry)) return Optional.ofNullable(subEntry);
}
return null;
return Optional.empty();
}
@Override

View File

@ -3,6 +3,7 @@ package speiger.src.collections.bytes.maps.impl.tree;
import java.util.Collections;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.NoSuchElementException;
import java.util.function.Consumer;
import java.util.function.BiFunction;
@ -17,6 +18,7 @@ import speiger.src.collections.ints.functions.consumer.IntObjectConsumer;
import speiger.src.collections.ints.functions.consumer.IntBooleanConsumer;
import speiger.src.collections.bytes.functions.function.BytePredicate;
import speiger.src.collections.bytes.functions.consumer.ByteBooleanConsumer;
import speiger.src.collections.bytes.functions.OptionalByte;
import speiger.src.collections.bytes.functions.function.ByteBooleanUnaryOperator;
import speiger.src.collections.bytes.functions.function.ByteByteUnaryOperator;
import speiger.src.collections.bytes.maps.abstracts.AbstractByte2BooleanMap;
@ -35,6 +37,7 @@ import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer;
import speiger.src.collections.objects.functions.consumer.ObjectBooleanConsumer;
import speiger.src.collections.booleans.functions.function.BooleanPredicate;
import speiger.src.collections.booleans.functions.OptionalBoolean;
import speiger.src.collections.objects.collections.ObjectBidirectionalIterator;
import speiger.src.collections.objects.collections.ObjectIterator;
import speiger.src.collections.objects.functions.function.ObjectObjectUnaryOperator;
@ -1123,7 +1126,7 @@ public class Byte2BooleanRBTreeMap extends AbstractByte2BooleanMap implements By
}
@Override
public byte reduce(ByteByteUnaryOperator operator) {
public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator);
byte state = (byte)0;
boolean empty = true;
@ -1135,15 +1138,15 @@ public class Byte2BooleanRBTreeMap extends AbstractByte2BooleanMap implements By
}
state = operator.applyAsByte(state, entry.key);
}
return state;
return empty ? OptionalByte.empty() : OptionalByte.of(state);
}
@Override
public byte findFirst(BytePredicate filter) {
public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter);
for(Node entry = start(), end = end();entry != null && (end == null || (end != previous(entry)));entry = next(entry))
if(filter.test(entry.key)) return entry.key;
return (byte)0;
if(filter.test(entry.key)) return OptionalByte.of(entry.key);
return OptionalByte.empty();
}
@Override
@ -1775,7 +1778,7 @@ public class Byte2BooleanRBTreeMap extends AbstractByte2BooleanMap implements By
}
@Override
public Byte2BooleanMap.Entry reduce(ObjectObjectUnaryOperator<Byte2BooleanMap.Entry, Byte2BooleanMap.Entry> operator) {
public Optional<Byte2BooleanMap.Entry> reduce(ObjectObjectUnaryOperator<Byte2BooleanMap.Entry, Byte2BooleanMap.Entry> operator) {
Objects.requireNonNull(operator);
Byte2BooleanMap.Entry state = null;
boolean empty = true;
@ -1787,19 +1790,19 @@ public class Byte2BooleanRBTreeMap extends AbstractByte2BooleanMap implements By
}
state = operator.apply(state, new BasicEntry(entry.key, entry.value));
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public Byte2BooleanMap.Entry findFirst(Predicate<Byte2BooleanMap.Entry> filter) {
public Optional<Byte2BooleanMap.Entry> findFirst(Predicate<Byte2BooleanMap.Entry> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return null;
if(size() <= 0) return Optional.empty();
BasicEntry subEntry = new BasicEntry();
for(Node entry = subLowest(), last = subHighest();entry != null && (last == null || last != previous(entry));entry = next(entry)) {
subEntry.set(entry.key, entry.value);
if(filter.test(subEntry)) return subEntry;
if(filter.test(subEntry)) return Optional.ofNullable(subEntry);
}
return null;
return Optional.empty();
}
@Override
@ -1894,7 +1897,7 @@ public class Byte2BooleanRBTreeMap extends AbstractByte2BooleanMap implements By
}
@Override
public boolean reduce(BooleanBooleanUnaryOperator operator) {
public OptionalBoolean reduce(BooleanBooleanUnaryOperator operator) {
Objects.requireNonNull(operator);
boolean state = false;
boolean empty = true;
@ -1906,15 +1909,15 @@ public class Byte2BooleanRBTreeMap extends AbstractByte2BooleanMap implements By
}
state = operator.applyAsBoolean(state, entry.value);
}
return state;
return empty ? OptionalBoolean.empty() : OptionalBoolean.of(state);
}
@Override
public boolean findFirst(BooleanPredicate filter) {
public OptionalBoolean findFirst(BooleanPredicate filter) {
Objects.requireNonNull(filter);
for(Node entry = subLowest(), last = subHighest();entry != null && (last == null || last != previous(entry));entry = next(entry))
if(filter.test(entry.value)) return entry.value;
return false;
if(filter.test(entry.value)) return OptionalBoolean.of(entry.value);
return OptionalBoolean.empty();
}
@Override
@ -2230,7 +2233,7 @@ public class Byte2BooleanRBTreeMap extends AbstractByte2BooleanMap implements By
}
@Override
public boolean reduce(BooleanBooleanUnaryOperator operator) {
public OptionalBoolean reduce(BooleanBooleanUnaryOperator operator) {
Objects.requireNonNull(operator);
boolean state = false;
boolean empty = true;
@ -2242,15 +2245,15 @@ public class Byte2BooleanRBTreeMap extends AbstractByte2BooleanMap implements By
}
state = operator.applyAsBoolean(state, entry.value);
}
return state;
return empty ? OptionalBoolean.empty() : OptionalBoolean.of(state);
}
@Override
public boolean findFirst(BooleanPredicate filter) {
public OptionalBoolean findFirst(BooleanPredicate filter) {
Objects.requireNonNull(filter);
for(Node entry = first;entry != null;entry = entry.next())
if(filter.test(entry.value)) return entry.value;
return false;
if(filter.test(entry.value)) return OptionalBoolean.of(entry.value);
return OptionalBoolean.empty();
}
@Override
@ -2391,7 +2394,7 @@ public class Byte2BooleanRBTreeMap extends AbstractByte2BooleanMap implements By
}
@Override
public Byte2BooleanMap.Entry reduce(ObjectObjectUnaryOperator<Byte2BooleanMap.Entry, Byte2BooleanMap.Entry> operator) {
public Optional<Byte2BooleanMap.Entry> reduce(ObjectObjectUnaryOperator<Byte2BooleanMap.Entry, Byte2BooleanMap.Entry> operator) {
Objects.requireNonNull(operator);
Byte2BooleanMap.Entry state = null;
boolean empty = true;
@ -2403,19 +2406,19 @@ public class Byte2BooleanRBTreeMap extends AbstractByte2BooleanMap implements By
}
state = operator.apply(state, new BasicEntry(entry.key, entry.value));
}
return state;
return empty ? Optional.empty() : Optional.ofNullable(state);
}
@Override
public Byte2BooleanMap.Entry findFirst(Predicate<Byte2BooleanMap.Entry> filter) {
public Optional<Byte2BooleanMap.Entry> findFirst(Predicate<Byte2BooleanMap.Entry> filter) {
Objects.requireNonNull(filter);
if(size() <= 0) return null;
if(size() <= 0) return Optional.empty();
BasicEntry subEntry = new BasicEntry();
for(Node entry = first;entry != null;entry = entry.next()) {
subEntry.set(entry.key, entry.value);
if(filter.test(subEntry)) return subEntry;
if(filter.test(subEntry)) return Optional.ofNullable(subEntry);
}
return null;
return Optional.empty();
}
@Override

Some files were not shown because too many files have changed in this diff Show More