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("SortedMapNavigationTester");
addBiRequirement("OrderedMapNavigationTester"); addBiRequirement("OrderedMapNavigationTester");
addBiRequirement("OrderedMapMoveTester"); addBiRequirement("OrderedMapMoveTester");
addBiRequirement("OrderedMapPutTester");
addBiRequirement("MapConstructorTester"); addBiRequirement("MapConstructorTester");
addRemapper("TestMapGenerator", "Test%sMapGenerator"); 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 { 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 @Override
public boolean addAndMoveToFirst(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); } public boolean addAndMoveToFirst(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
@Override @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) { public boolean add(KEY_TYPE o) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
@Override
public void addFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(KEY_TYPE o) { throw new UnsupportedOperationException(); }
@Override @Override
public boolean addAndMoveToFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); } public boolean addAndMoveToFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); }
@Override @Override
public boolean addAndMoveToLast(KEY_TYPE o) { throw new UnsupportedOperationException(); } 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 { 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 @Override
public boolean addAndMoveToFirst(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); } public boolean addAndMoveToFirst(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
@Override @Override
@ -1003,6 +1007,12 @@ public class LINKED_HASH_MAP KEY_VALUE_GENERIC_TYPE extends HASH_MAP KEY_VALUE_G
#endif #endif
@Override @Override
public boolean add(KEY_TYPE o) { throw new UnsupportedOperationException(); } 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 @Override
public boolean addAndMoveToFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); } 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 { 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 @Override
public boolean addAndMoveToFirst(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); } public boolean addAndMoveToFirst(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
@Override @Override
@ -894,6 +898,12 @@ public class IMMUTABLE_HASH_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
@Override
public void addFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(KEY_TYPE o) { throw new UnsupportedOperationException(); }
@Override @Override
public boolean addAndMoveToFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); } 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 { 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 @Override
public boolean addAndMoveToFirst(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); } public boolean addAndMoveToFirst(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
@Override @Override
@ -1126,6 +1130,10 @@ public class ARRAY_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_GEN
@Override @Override
public boolean add(KEY_TYPE o) { throw new UnsupportedOperationException(); } public boolean add(KEY_TYPE o) { throw new UnsupportedOperationException(); }
@Override @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(); } public boolean addAndMoveToFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); }
@Override @Override
public boolean addAndMoveToLast(KEY_TYPE o) { throw new UnsupportedOperationException(); } 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 { 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 @Override
public boolean addAndMoveToFirst(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); } public boolean addAndMoveToFirst(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
@Override @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) { public boolean add(T o) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
@Override
public void addFirst(T o) { throw new UnsupportedOperationException(); }
@Override
public void addLast(T o) { throw new UnsupportedOperationException(); }
@Override @Override
public boolean addAndMoveToFirst(T o) { throw new UnsupportedOperationException(); } 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() { public BI_ITERATOR KEY_GENERIC_TYPE reverseIterator() {
return set.iterator(); return set.iterator();
} }
@Override
public void addFirst(KEY_TYPE o) {
set.addLast(o);
}
@Override
public void addLast(KEY_TYPE o) {
set.addFirst(o);
}
@Override @Override
#if !TYPE_OBJECT #if !TYPE_OBJECT
public boolean remove(KEY_TYPE o) { 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 #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 @Override
public boolean addAndMoveToFirst(KEY_TYPE o) { public boolean addAndMoveToFirst(KEY_TYPE o) {
int index = findIndex(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 @Override
public boolean addAll(COLLECTION KEY_GENERIC_TYPE c) { throw new UnsupportedOperationException(); } public boolean addAll(COLLECTION KEY_GENERIC_TYPE c) { throw new UnsupportedOperationException(); }
@Override @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(); } public boolean addAndMoveToFirst(KEY_TYPE o) { throw new UnsupportedOperationException(); }
@Override @Override
public boolean addAndMoveToLast(KEY_TYPE o) { throw new UnsupportedOperationException(); } 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 #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 @Override
public boolean addAndMoveToFirst(KEY_TYPE o) { public boolean addAndMoveToFirst(KEY_TYPE o) {
if(strategy.equals(o, EMPTY_KEY_VALUE)) { 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 #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 @Override
public boolean addAndMoveToFirst(KEY_TYPE o) { public boolean addAndMoveToFirst(KEY_TYPE o) {
if(KEY_EQUALS_NULL(o)) { if(KEY_EQUALS_NULL(o)) {

View File

@ -5,6 +5,7 @@ import java.util.SequencedSet;
#endif #endif
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR; import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
import speiger.src.collections.PACKAGE.collections.ORDERED_COLLECTION;
#if SPLIT_ITERATOR_FEATURE #if SPLIT_ITERATOR_FEATURE
import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR; import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR;
import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS; import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS;
@ -23,9 +24,9 @@ import speiger.src.collections.PACKAGE.utils.SETS;
* @Type(T) * @Type(T)
*/ */
#if JAVA_VERSION>=21 #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 #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 #endif
{ {
/** /**

View File

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

View File

@ -754,7 +754,11 @@ public class MAPS
super(c); super(c);
set = 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 @Override
public boolean addAndMoveToFirst(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); } public boolean addAndMoveToFirst(MAP.Entry KEY_VALUE_GENERIC_TYPE o) { throw new UnsupportedOperationException(); }
@Override @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.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_TYPEOrderedMapMoveTester;
import speiger.src.testers.PACKAGE.tests.maps.FILE_KEY_TYPE2FILE_VALUE_TYPEOrderedMapNavigationTester; 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 #if !TYPE_OBJECT
import speiger.src.testers.objects.builder.ObjectSetTestSuiteBuilder; import speiger.src.testers.objects.builder.ObjectSetTestSuiteBuilder;
import speiger.src.testers.objects.generators.TestObjectSetGenerator; 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(); List<Class<? extends AbstractTester>> testers = super.getTesters();
testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEOrderedMapMoveTester.class); testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEOrderedMapMoveTester.class);
testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEOrderedMapNavigationTester.class); testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEOrderedMapNavigationTester.class);
testers.add(FILE_KEY_TYPE2FILE_VALUE_TYPEOrderedMapPutTester.class);
return testers; return testers;
} }

View File

@ -27,6 +27,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapContainsTester KEY_VALUE_GENERIC_TY
#ignore #ignore
@CollectionSize.Require(absent = ZERO) @CollectionSize.Require(absent = ZERO)
@SuppressWarnings("unlikely-arg-type")
#endignore #endignore
public void testContainsObject_yes() { public void testContainsObject_yes() {
assertTrue("contains(present) should return true", getMap().ENTRY_SET().contains(new AbstractMap.SimpleEntry<>(e0()))); 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())); assertFalse("contains(notPresent) should return false", getMap().ENTRY_SET().contains(e3()));
} }
@SuppressWarnings("unlikely-arg-type")
public void testContainsObject_no() { public void testContainsObject_no() {
assertFalse("contains(notPresent) should return false", getMap().ENTRY_SET().contains(new AbstractMap.SimpleEntry<>(e3()))); 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 #ignore
@CollectionSize.Require(ONE) @CollectionSize.Require(ONE)
@MapFeature.Require(SUPPORTS_REMOVE) @MapFeature.Require(SUPPORTS_REMOVE)
@SuppressWarnings("unlikely-arg-type")
#endignore #endignore
public void testRemove_supportedObjectEntryPresent() { public void testRemove_supportedObjectEntryPresent() {
assertTrue(getMap().ENTRY_SET().remove(new AbstractMap.SimpleEntry<>(e0()))); assertTrue(getMap().ENTRY_SET().remove(new AbstractMap.SimpleEntry<>(e0())));
@ -154,6 +155,7 @@ public class FILE_KEY_TYPE2FILE_VALUE_TYPEMapRemoveEntryTester KEY_VALUE_GENERIC
#ignore #ignore
@CollectionSize.Require(ONE) @CollectionSize.Require(ONE)
@MapFeature.Require(SUPPORTS_REMOVE) @MapFeature.Require(SUPPORTS_REMOVE)
@SuppressWarnings("unlikely-arg-type")
#endignore #endignore
public void testRemove_supportedObjectEntryMissing() { public void testRemove_supportedObjectEntryMissing() {
assertFalse(getMap().ENTRY_SET().remove(new AbstractMap.SimpleEntry<>(e3()))); 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 #if TYPE_OBJECT
import java.util.Objects; import java.util.Objects;
#endif
#if JDK_TYPE
import java.util.OPTIONAL;
#else
import speiger.src.collections.PACKAGE.functions.OPTIONAL;
#endif #endif
import org.junit.Ignore; import org.junit.Ignore;
@ -27,17 +32,17 @@ public class FILE_KEY_TYPEQueueFindFirstTester KEY_GENERIC_TYPE extends ABSTRACT
@CollectionSize.Require(absent = CollectionSize.ZERO) @CollectionSize.Require(absent = CollectionSize.ZERO)
#endignore #endignore
public void testQueueFindFirst_FindFirstElements() { 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() { 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 #ignore
@CollectionSize.Require(CollectionSize.SEVERAL) @CollectionSize.Require(CollectionSize.SEVERAL)
#endignore #endignore
public void testQueueFindFirst_FindLastElement() { 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 #if TYPE_OBJECT
import java.util.Objects; import java.util.Objects;
#endif
#if JDK_TYPE
import java.util.OPTIONAL;
#else
import speiger.src.collections.PACKAGE.functions.OPTIONAL;
#endif #endif
import org.junit.Ignore; import org.junit.Ignore;
import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_QUEUE_TESTER; import speiger.src.testers.PACKAGE.tests.base.ABSTRACT_QUEUE_TESTER;
import com.google.common.collect.testing.features.CollectionSize;
@Ignore @Ignore
@SuppressWarnings("javadoc") @SuppressWarnings("javadoc")
@ -29,7 +35,7 @@ public class FILE_KEY_TYPEQueueReduceTester KEY_GENERIC_TYPE extends ABSTRACT_QU
} }
public void testQueueReduce() { 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() { 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.BooleanConsumer;
import speiger.src.collections.booleans.functions.BooleanComparator; import speiger.src.collections.booleans.functions.BooleanComparator;
import speiger.src.collections.objects.collections.ObjectIterable; 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.booleans.functions.function.BooleanFunction;
import speiger.src.collections.ints.functions.consumer.IntBooleanConsumer; import speiger.src.collections.ints.functions.consumer.IntBooleanConsumer;
import speiger.src.collections.objects.functions.consumer.ObjectBooleanConsumer; import speiger.src.collections.objects.functions.consumer.ObjectBooleanConsumer;
@ -271,13 +272,13 @@ public interface BooleanIterable extends Iterable<Boolean>
* @param filter that should be applied * @param filter that should be applied
* @return the found value or the null equivalent variant. * @return the found value or the null equivalent variant.
*/ */
default boolean findFirst(BooleanPredicate filter) { default OptionalBoolean findFirst(BooleanPredicate filter) {
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
for(BooleanIterator iter = iterator();iter.hasNext();) { for(BooleanIterator iter = iterator();iter.hasNext();) {
boolean entry = iter.nextBoolean(); 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 * @param operator the operation that should be applied
* @return the reduction result, returns null value if nothing was found * @return the reduction result, returns null value if nothing was found
*/ */
default boolean reduce(BooleanBooleanUnaryOperator operator) { default OptionalBoolean reduce(BooleanBooleanUnaryOperator operator) {
Objects.requireNonNull(operator); Objects.requireNonNull(operator);
boolean state = false; boolean state = false;
boolean empty = true; boolean empty = true;
@ -314,7 +315,7 @@ public interface BooleanIterable extends Iterable<Boolean>
} }
state = operator.applyAsBoolean(state, iter.nextBoolean()); 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.BooleanCollection;
import speiger.src.collections.booleans.collections.BooleanStack; import speiger.src.collections.booleans.collections.BooleanStack;
import speiger.src.collections.booleans.collections.BooleanIterator; 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.BooleanComparator;
import speiger.src.collections.booleans.functions.BooleanConsumer; import speiger.src.collections.booleans.functions.BooleanConsumer;
import speiger.src.collections.objects.functions.consumer.ObjectBooleanConsumer; import speiger.src.collections.objects.functions.consumer.ObjectBooleanConsumer;
@ -510,12 +511,12 @@ public class BooleanArrayList extends AbstractBooleanList implements IBooleanArr
} }
@Override @Override
public boolean findFirst(BooleanPredicate filter) { public OptionalBoolean findFirst(BooleanPredicate filter) {
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
for(int i = 0;i<size;i++) { 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 @Override
@ -529,7 +530,7 @@ public class BooleanArrayList extends AbstractBooleanList implements IBooleanArr
} }
@Override @Override
public boolean reduce(BooleanBooleanUnaryOperator operator) { public OptionalBoolean reduce(BooleanBooleanUnaryOperator operator) {
Objects.requireNonNull(operator); Objects.requireNonNull(operator);
boolean state = false; boolean state = false;
boolean empty = true; boolean empty = true;
@ -541,7 +542,7 @@ public class BooleanArrayList extends AbstractBooleanList implements IBooleanArr
} }
state = operator.applyAsBoolean(state, data[i]); state = operator.applyAsBoolean(state, data[i]);
} }
return state; return empty ? OptionalBoolean.empty() : OptionalBoolean.of(state);
} }
@Override @Override

View File

@ -8,6 +8,7 @@ import java.util.Spliterator;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.function.Predicate; import java.util.function.Predicate;
import java.util.function.UnaryOperator; import java.util.function.UnaryOperator;
import speiger.src.collections.booleans.functions.OptionalBoolean;
import speiger.src.collections.ints.functions.consumer.IntBooleanConsumer; import speiger.src.collections.ints.functions.consumer.IntBooleanConsumer;
import speiger.src.collections.objects.functions.consumer.ObjectBooleanConsumer; import speiger.src.collections.objects.functions.consumer.ObjectBooleanConsumer;
import speiger.src.collections.booleans.functions.function.BooleanPredicate; import speiger.src.collections.booleans.functions.function.BooleanPredicate;
@ -415,12 +416,12 @@ public class BooleanLinkedList extends AbstractBooleanList implements BooleanPri
} }
@Override @Override
public boolean findFirst(BooleanPredicate filter) { public OptionalBoolean findFirst(BooleanPredicate filter) {
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
for(Entry entry = first;entry != null;entry = entry.next) { 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 @Override
@ -434,7 +435,7 @@ public class BooleanLinkedList extends AbstractBooleanList implements BooleanPri
} }
@Override @Override
public boolean reduce(BooleanBooleanUnaryOperator operator) { public OptionalBoolean reduce(BooleanBooleanUnaryOperator operator) {
Objects.requireNonNull(operator); Objects.requireNonNull(operator);
boolean state = false; boolean state = false;
boolean empty = true; boolean empty = true;
@ -446,7 +447,7 @@ public class BooleanLinkedList extends AbstractBooleanList implements BooleanPri
} }
state = operator.applyAsBoolean(state, entry.value); state = operator.applyAsBoolean(state, entry.value);
} }
return state; return empty ? OptionalBoolean.empty() : OptionalBoolean.of(state);
} }
@Override @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.BooleanCollection;
import speiger.src.collections.booleans.collections.BooleanStack; import speiger.src.collections.booleans.collections.BooleanStack;
import speiger.src.collections.booleans.collections.BooleanIterator; 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.BooleanComparator;
import speiger.src.collections.booleans.functions.BooleanConsumer; import speiger.src.collections.booleans.functions.BooleanConsumer;
import speiger.src.collections.objects.functions.consumer.ObjectBooleanConsumer; import speiger.src.collections.objects.functions.consumer.ObjectBooleanConsumer;
@ -645,13 +646,13 @@ public class CopyOnWriteBooleanArrayList extends AbstractBooleanList implements
} }
@Override @Override
public boolean findFirst(BooleanPredicate filter) { public OptionalBoolean findFirst(BooleanPredicate filter) {
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
boolean[] data = this.data; boolean[] data = this.data;
for(int i = 0,m=data.length;i<m;i++) { 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 @Override
@ -666,7 +667,7 @@ public class CopyOnWriteBooleanArrayList extends AbstractBooleanList implements
} }
@Override @Override
public boolean reduce(BooleanBooleanUnaryOperator operator) { public OptionalBoolean reduce(BooleanBooleanUnaryOperator operator) {
Objects.requireNonNull(operator); Objects.requireNonNull(operator);
boolean[] data = this.data; boolean[] data = this.data;
boolean state = false; boolean state = false;
@ -679,7 +680,7 @@ public class CopyOnWriteBooleanArrayList extends AbstractBooleanList implements
} }
state = operator.applyAsBoolean(state, data[i]); state = operator.applyAsBoolean(state, data[i]);
} }
return state; return empty ? OptionalBoolean.empty() : OptionalBoolean.of(state);
} }
@Override @Override

View File

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

View File

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

View File

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

View File

@ -6,6 +6,7 @@ import java.util.Objects;
import speiger.src.collections.booleans.collections.BooleanCollection; import speiger.src.collections.booleans.collections.BooleanCollection;
import speiger.src.collections.booleans.collections.BooleanIterator; 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.BooleanComparator;
import speiger.src.collections.booleans.functions.BooleanConsumer; import speiger.src.collections.booleans.functions.BooleanConsumer;
import speiger.src.collections.ints.functions.consumer.IntBooleanConsumer; import speiger.src.collections.ints.functions.consumer.IntBooleanConsumer;
@ -290,7 +291,7 @@ public class BooleanHeapPriorityQueue extends AbstractBooleanPriorityQueue
} }
@Override @Override
public boolean reduce(BooleanBooleanUnaryOperator operator) { public OptionalBoolean reduce(BooleanBooleanUnaryOperator operator) {
Objects.requireNonNull(operator); Objects.requireNonNull(operator);
boolean state = false; boolean state = false;
boolean empty = true; boolean empty = true;
@ -302,20 +303,20 @@ public class BooleanHeapPriorityQueue extends AbstractBooleanPriorityQueue
} }
state = operator.applyAsBoolean(state, array[i]); state = operator.applyAsBoolean(state, array[i]);
} }
return state; return empty ? OptionalBoolean.empty() : OptionalBoolean.of(state);
} }
@Override @Override
public boolean findFirst(BooleanPredicate filter) { public OptionalBoolean findFirst(BooleanPredicate filter) {
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
for(int i = 0;i<size;i++) { for(int i = 0;i<size;i++) {
if(filter.test(array[i])) { if(filter.test(array[i])) {
boolean data = array[i]; boolean data = array[i];
removeIndex(i); removeIndex(i);
return data; return OptionalBoolean.of(data);
} }
} }
return false; return OptionalBoolean.empty();
} }
@Override @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.BooleanOrderedCollection;
import speiger.src.collections.booleans.collections.BooleanIterator; import speiger.src.collections.booleans.collections.BooleanIterator;
import speiger.src.collections.booleans.functions.BooleanComparator; 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.objects.utils.ObjectArrays;
import speiger.src.collections.booleans.functions.BooleanConsumer; import speiger.src.collections.booleans.functions.BooleanConsumer;
import speiger.src.collections.booleans.functions.function.BooleanPredicate; import speiger.src.collections.booleans.functions.function.BooleanPredicate;
@ -460,9 +461,9 @@ public class BooleanCollections
@Override @Override
public boolean reduce(boolean identity, BooleanBooleanUnaryOperator operator) { synchronized(mutex) { return c.reduce(identity, operator); } } public boolean reduce(boolean identity, BooleanBooleanUnaryOperator operator) { synchronized(mutex) { return c.reduce(identity, operator); } }
@Override @Override
public boolean reduce(BooleanBooleanUnaryOperator operator) { synchronized(mutex) { return c.reduce(operator); } } public OptionalBoolean reduce(BooleanBooleanUnaryOperator operator) { synchronized(mutex) { return c.reduce(operator); } }
@Override @Override
public boolean findFirst(BooleanPredicate filter) { synchronized(mutex) { return c.findFirst(filter); } } public OptionalBoolean findFirst(BooleanPredicate filter) { synchronized(mutex) { return c.findFirst(filter); } }
@Override @Override
public int count(BooleanPredicate filter) { synchronized(mutex) { return c.count(filter); } } public int count(BooleanPredicate filter) { synchronized(mutex) { return c.count(filter); } }
} }
@ -588,9 +589,9 @@ public class BooleanCollections
@Override @Override
public boolean reduce(boolean identity, BooleanBooleanUnaryOperator operator) { return c.reduce(identity, operator); } public boolean reduce(boolean identity, BooleanBooleanUnaryOperator operator) { return c.reduce(identity, operator); }
@Override @Override
public boolean reduce(BooleanBooleanUnaryOperator operator) { return c.reduce(operator); } public OptionalBoolean reduce(BooleanBooleanUnaryOperator operator) { return c.reduce(operator); }
@Override @Override
public boolean findFirst(BooleanPredicate filter) { return c.findFirst(filter); } public OptionalBoolean findFirst(BooleanPredicate filter) { return c.findFirst(filter); }
@Override @Override
public int count(BooleanPredicate filter) { return c.count(filter); } public int count(BooleanPredicate filter) { return c.count(filter); }
} }

View File

@ -1,13 +1,14 @@
package speiger.src.collections.booleans.utils; package speiger.src.collections.booleans.utils;
import speiger.src.collections.booleans.collections.BooleanIterator; import speiger.src.collections.booleans.collections.BooleanIterator;
import speiger.src.collections.booleans.collections.BooleanCollection; import speiger.src.collections.booleans.collections.BooleanCollection;
import speiger.src.collections.booleans.functions.BooleanComparator; 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.BooleanPriorityDequeue;
import speiger.src.collections.booleans.queues.BooleanPriorityQueue; import speiger.src.collections.booleans.queues.BooleanPriorityQueue;
import speiger.src.collections.booleans.functions.BooleanConsumer; import speiger.src.collections.booleans.functions.BooleanConsumer;
import speiger.src.collections.booleans.functions.function.BooleanPredicate; import speiger.src.collections.booleans.functions.function.BooleanPredicate;
import speiger.src.collections.booleans.functions.function.BooleanBooleanUnaryOperator;
import speiger.src.collections.objects.functions.consumer.ObjectBooleanConsumer; import speiger.src.collections.objects.functions.consumer.ObjectBooleanConsumer;
/** /**
@ -113,7 +114,11 @@ public class BooleanPriorityQueues
@Override @Override
public boolean matchesAll(BooleanPredicate filter) { synchronized(mutex) { return queue.matchesAll(filter); } } public boolean matchesAll(BooleanPredicate filter) { synchronized(mutex) { return queue.matchesAll(filter); } }
@Override @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 @Override
public int count(BooleanPredicate filter) { synchronized(mutex) { return queue.count(filter); } } 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.ByteConsumer;
import speiger.src.collections.bytes.functions.ByteComparator; import speiger.src.collections.bytes.functions.ByteComparator;
import speiger.src.collections.objects.collections.ObjectIterable; 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.bytes.functions.function.ByteFunction;
import speiger.src.collections.ints.functions.consumer.IntByteConsumer; import speiger.src.collections.ints.functions.consumer.IntByteConsumer;
import speiger.src.collections.objects.functions.consumer.ObjectByteConsumer; import speiger.src.collections.objects.functions.consumer.ObjectByteConsumer;
@ -281,13 +282,13 @@ public interface ByteIterable extends Iterable<Byte>
* @param filter that should be applied * @param filter that should be applied
* @return the found value or the null equivalent variant. * @return the found value or the null equivalent variant.
*/ */
default byte findFirst(BytePredicate filter) { default OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
for(ByteIterator iter = iterator();iter.hasNext();) { for(ByteIterator iter = iterator();iter.hasNext();) {
byte entry = iter.nextByte(); 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 * @param operator the operation that should be applied
* @return the reduction result, returns null value if nothing was found * @return the reduction result, returns null value if nothing was found
*/ */
default byte reduce(ByteByteUnaryOperator operator) { default OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator); Objects.requireNonNull(operator);
byte state = (byte)0; byte state = (byte)0;
boolean empty = true; boolean empty = true;
@ -324,7 +325,7 @@ public interface ByteIterable extends Iterable<Byte>
} }
state = operator.applyAsByte(state, iter.nextByte()); 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.ByteCollection;
import speiger.src.collections.bytes.collections.ByteStack; import speiger.src.collections.bytes.collections.ByteStack;
import speiger.src.collections.bytes.collections.ByteIterator; 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.ByteComparator;
import speiger.src.collections.bytes.functions.ByteConsumer; import speiger.src.collections.bytes.functions.ByteConsumer;
import speiger.src.collections.objects.functions.consumer.ObjectByteConsumer; import speiger.src.collections.objects.functions.consumer.ObjectByteConsumer;
@ -519,12 +520,12 @@ public class ByteArrayList extends AbstractByteList implements IByteArray, ByteS
} }
@Override @Override
public byte findFirst(BytePredicate filter) { public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
for(int i = 0;i<size;i++) { 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 @Override
@ -538,7 +539,7 @@ public class ByteArrayList extends AbstractByteList implements IByteArray, ByteS
} }
@Override @Override
public byte reduce(ByteByteUnaryOperator operator) { public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator); Objects.requireNonNull(operator);
byte state = (byte)0; byte state = (byte)0;
boolean empty = true; boolean empty = true;
@ -550,7 +551,7 @@ public class ByteArrayList extends AbstractByteList implements IByteArray, ByteS
} }
state = operator.applyAsByte(state, data[i]); state = operator.applyAsByte(state, data[i]);
} }
return state; return empty ? OptionalByte.empty() : OptionalByte.of(state);
} }
@Override @Override

View File

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

View File

@ -16,6 +16,7 @@ import java.nio.ByteBuffer;
import speiger.src.collections.bytes.collections.ByteCollection; import speiger.src.collections.bytes.collections.ByteCollection;
import speiger.src.collections.bytes.collections.ByteStack; import speiger.src.collections.bytes.collections.ByteStack;
import speiger.src.collections.bytes.collections.ByteIterator; 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.ByteComparator;
import speiger.src.collections.bytes.functions.ByteConsumer; import speiger.src.collections.bytes.functions.ByteConsumer;
import speiger.src.collections.objects.functions.consumer.ObjectByteConsumer; import speiger.src.collections.objects.functions.consumer.ObjectByteConsumer;
@ -654,13 +655,13 @@ public class CopyOnWriteByteArrayList extends AbstractByteList implements ITrimm
} }
@Override @Override
public byte findFirst(BytePredicate filter) { public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
byte[] data = this.data; byte[] data = this.data;
for(int i = 0,m=data.length;i<m;i++) { 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 @Override
@ -675,7 +676,7 @@ public class CopyOnWriteByteArrayList extends AbstractByteList implements ITrimm
} }
@Override @Override
public byte reduce(ByteByteUnaryOperator operator) { public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator); Objects.requireNonNull(operator);
byte[] data = this.data; byte[] data = this.data;
byte state = (byte)0; byte state = (byte)0;
@ -688,7 +689,7 @@ public class CopyOnWriteByteArrayList extends AbstractByteList implements ITrimm
} }
state = operator.applyAsByte(state, data[i]); state = operator.applyAsByte(state, data[i]);
} }
return state; return empty ? OptionalByte.empty() : OptionalByte.of(state);
} }
@Override @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.collections.ByteCollection;
import speiger.src.collections.bytes.functions.ByteComparator; import speiger.src.collections.bytes.functions.ByteComparator;
import speiger.src.collections.bytes.functions.ByteConsumer; 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.bytes.utils.ByteArrays;
import speiger.src.collections.objects.functions.consumer.ObjectByteConsumer; import speiger.src.collections.objects.functions.consumer.ObjectByteConsumer;
import speiger.src.collections.bytes.functions.function.BytePredicate; import speiger.src.collections.bytes.functions.function.BytePredicate;
@ -273,12 +274,12 @@ public class ImmutableByteList extends AbstractByteList
} }
@Override @Override
public byte findFirst(BytePredicate filter) { public OptionalByte findFirst(BytePredicate filter) {
Objects.requireNonNull(filter); Objects.requireNonNull(filter);
for(int i = 0,m=data.length;i<m;i++) { 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 @Override
@ -292,7 +293,7 @@ public class ImmutableByteList extends AbstractByteList
} }
@Override @Override
public byte reduce(ByteByteUnaryOperator operator) { public OptionalByte reduce(ByteByteUnaryOperator operator) {
Objects.requireNonNull(operator); Objects.requireNonNull(operator);
byte state = (byte)0; byte state = (byte)0;
boolean empty = true; boolean empty = true;
@ -304,7 +305,7 @@ public class ImmutableByteList extends AbstractByteList
} }
state = operator.applyAsByte(state, data[i]); state = operator.applyAsByte(state, data[i]);
} }
return state; return empty ? OptionalByte.empty() : OptionalByte.of(state);
} }
@Override @Override

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

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