diff --git a/src/main/java/speiger/src/collections/booleans/lists/AbstractBooleanList.java b/src/main/java/speiger/src/collections/booleans/lists/AbstractBooleanList.java index f0d9e8fe..7d47bc48 100644 --- a/src/main/java/speiger/src/collections/booleans/lists/AbstractBooleanList.java +++ b/src/main/java/speiger/src/collections/booleans/lists/AbstractBooleanList.java @@ -12,6 +12,7 @@ import speiger.src.collections.booleans.collections.BooleanCollection; import speiger.src.collections.booleans.collections.BooleanIterator; import speiger.src.collections.booleans.collections.BooleanSplititerator; +import speiger.src.collections.ints.lists.IntList; import speiger.src.collections.booleans.utils.BooleanSplititerators; import speiger.src.collections.utils.SanityChecks; @@ -205,13 +206,23 @@ public BooleanIterator iterator() { public BooleanListIterator listIterator() { return listIterator(0); } - + @Override public BooleanListIterator listIterator(int index) { if(index < 0 || index > size()) throw new IndexOutOfBoundsException(); return new BooleanListIter(index); } + @Override + public BooleanListIterator indexedIterator(int...indecies) { + return new IndexedIterator(indecies); + } + + @Override + public BooleanListIterator indexedIterator(IntList indecies) { + return new ListIndexedIterator(indecies); + } + @Override public void size(int size) { while(size > size()) add(false); @@ -566,7 +577,153 @@ public int back(int amount) { } } } + + private class ListIndexedIterator implements BooleanListIterator { + IntList indecies; + int index; + int lastReturned = -1; + + ListIndexedIterator(IntList indecies) { + this.indecies = indecies; + } + + @Override + public boolean hasNext() { + return index < indecies.size(); + } + + @Override + public boolean nextBoolean() { + if(!hasNext()) throw new NoSuchElementException(); + int i = index++; + return getBoolean((lastReturned = indecies.getInt(i))); + } + + @Override + public boolean hasPrevious() { + return index > 0; + } + + @Override + public boolean previousBoolean() { + if(!hasPrevious()) throw new NoSuchElementException(); + index--; + return getBoolean((lastReturned = indecies.getInt(index))); + } + + @Override + public int nextIndex() { + return index; + } + + @Override + public int previousIndex() { + return index-1; + } + + @Override + public void remove() { throw new UnsupportedOperationException(); } + @Override + public void add(boolean e) { throw new UnsupportedOperationException(); } + + @Override + public void set(boolean e) { + if(lastReturned == -1) throw new IllegalStateException(); + AbstractBooleanList.this.set(lastReturned, e); + } + + @Override + public int skip(int amount) { + if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed"); + int steps = Math.min(amount, indecies.size() - index); + index += steps; + if(steps > 0) lastReturned = Math.min(index-1, indecies.size()-1); + return steps; + } + + @Override + public int back(int amount) { + if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed"); + int steps = Math.min(amount, index); + index -= steps; + if(steps > 0) lastReturned = Math.max(index, 0); + return steps; + } + } + + private class IndexedIterator implements BooleanListIterator { + int[] indecies; + int index; + int lastReturned = -1; + + IndexedIterator(int[] indecies) { + this.indecies = indecies; + } + @Override + public boolean hasNext() { + return index < indecies.length; + } + + @Override + public boolean nextBoolean() { + if(!hasNext()) throw new NoSuchElementException(); + int i = index++; + return getBoolean((lastReturned = indecies[i])); + } + + @Override + public boolean hasPrevious() { + return index > 0; + } + + @Override + public boolean previousBoolean() { + if(!hasPrevious()) throw new NoSuchElementException(); + index--; + return getBoolean((lastReturned = indecies[index])); + } + + @Override + public int nextIndex() { + return index; + } + + @Override + public int previousIndex() { + return index-1; + } + + @Override + public void remove() { throw new UnsupportedOperationException(); } + @Override + public void add(boolean e) { throw new UnsupportedOperationException(); } + + @Override + public void set(boolean e) { + if(lastReturned == -1) throw new IllegalStateException(); + AbstractBooleanList.this.set(lastReturned, e); + } + + @Override + public int skip(int amount) { + if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed"); + int steps = Math.min(amount, indecies.length - index); + index += steps; + if(steps > 0) lastReturned = Math.min(index-1, indecies.length-1); + return steps; + } + + @Override + public int back(int amount) { + if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed"); + int steps = Math.min(amount, index); + index -= steps; + if(steps > 0) lastReturned = Math.max(index, 0); + return steps; + } + } + private class BooleanListIter implements BooleanListIterator { int index; int lastReturned = -1; @@ -644,7 +801,7 @@ public int back(int amount) { if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed"); int steps = Math.min(amount, index); index -= steps; - if(steps > 0) lastReturned = Math.min(index, size()-1); + if(steps > 0) lastReturned = Math.max(index, 0); return steps; } } diff --git a/src/main/java/speiger/src/collections/booleans/lists/BooleanList.java b/src/main/java/speiger/src/collections/booleans/lists/BooleanList.java index a28cd9f0..d31cb4db 100644 --- a/src/main/java/speiger/src/collections/booleans/lists/BooleanList.java +++ b/src/main/java/speiger/src/collections/booleans/lists/BooleanList.java @@ -11,6 +11,7 @@ import speiger.src.collections.booleans.functions.BooleanComparator; import speiger.src.collections.booleans.utils.BooleanArrays; import speiger.src.collections.booleans.utils.BooleanLists; +import speiger.src.collections.ints.lists.IntList; import speiger.src.collections.booleans.utils.BooleanSplititerators; /** @@ -320,6 +321,24 @@ public default void forEachIndexed(IntBooleanConsumer action) { @Override public BooleanListIterator listIterator(int index); + /** + * Creates a Iterator that follows the indecies provided.
+ * For example if the Lists Contents is:
-1, 0 1
and the indecies are:
0, 1, 2, 2, 1, 0
+ * then the iterator will return the following values:
-1, 0, 1, 1, 0, -1 + * @param indecies that should be used for the iteration. + * @return a custom indexed iterator + */ + public BooleanListIterator indexedIterator(int...indecies); + + /** + * Creates a Iterator that follows the indecies provided.
+ * For example if the Lists Contents is:
-1, 0 1
and the indecies are:
0, 1, 2, 2, 1, 0
+ * then the iterator will return the following values:
-1, 0, 1, 1, 0, -1 + * @param indecies that should be used for the iteration. + * @return a custom indexed iterator + */ + public BooleanListIterator indexedIterator(IntList indecies); + /** * A Type-Specific List of subList * @see java.util.List#subList(int, int) diff --git a/src/main/java/speiger/src/collections/booleans/queues/BooleanArrayFIFOQueue.java b/src/main/java/speiger/src/collections/booleans/queues/BooleanArrayFIFOQueue.java index 77967c64..1c7d010d 100644 --- a/src/main/java/speiger/src/collections/booleans/queues/BooleanArrayFIFOQueue.java +++ b/src/main/java/speiger/src/collections/booleans/queues/BooleanArrayFIFOQueue.java @@ -146,6 +146,15 @@ public boolean peek(int index) { return index >= array.length ? array[index-array.length] : array[index]; } + @Override + public boolean contains(boolean e) { + if(first == last) return false; + for(int i = 0,m=size();i iterator, int r return new RepeatingIterator(wrap(iterator), repeats); } + /** + * A Helper function that creates a infinitely looping iterator + * @param iterator that should be looping infinitely + * @return a infinitely looping iterator + */ + public static BooleanIterator infinite(BooleanIterator iterator) { + return new InfiniteIterator(iterator); + } + + /** + * A Helper function that creates a infinitely looping iterator from a Java Iterator + * @param iterator that should be looping infinitely + * @return a infinitely looping iterator + */ + public static BooleanIterator infinite(Iterator iterator) { + return new InfiniteIterator(wrap(iterator)); + } + /** * A Helper function that hard limits the Iterator to a specific size * @param iterator that should be limited @@ -841,6 +862,40 @@ public T next() { } } + private static class InfiniteIterator implements BooleanIterator + { + BooleanIterator iter; + CollectionWrapper looper = BooleanCollections.wrapper(); + int index = 0; + + public InfiniteIterator(BooleanIterator iter) { + this.iter = iter; + } + + @Override + public boolean hasNext() { + return true; + } + + @Override + public boolean nextBoolean() { + if(iter != null) { + if(iter.hasNext()) { + boolean value = iter.nextBoolean(); + looper.add(value); + return value; + } + else iter = null; + } + return looper.getBoolean((index++) % looper.size()); + } + + @Override + public void forEachRemaining(BooleanConsumer action) { throw new UnsupportedOperationException("This is a instant deadlock, so unsupported"); } + public void forEachRemaining(Consumer action) { throw new UnsupportedOperationException("This is a instant deadlock, so unsupported"); } + public void forEachRemaining(E input, ObjectBooleanConsumer action) { throw new UnsupportedOperationException("This is a instant deadlock, so unsupported"); } + } + private static class RepeatingIterator implements BooleanIterator { final int repeats; diff --git a/src/main/java/speiger/src/collections/booleans/utils/BooleanLists.java b/src/main/java/speiger/src/collections/booleans/utils/BooleanLists.java index 75ffdc7b..c05f5763 100644 --- a/src/main/java/speiger/src/collections/booleans/utils/BooleanLists.java +++ b/src/main/java/speiger/src/collections/booleans/utils/BooleanLists.java @@ -11,6 +11,7 @@ import speiger.src.collections.booleans.functions.BooleanConsumer; import speiger.src.collections.booleans.lists.AbstractBooleanList; import speiger.src.collections.booleans.lists.BooleanList; +import speiger.src.collections.ints.lists.IntList; import speiger.src.collections.booleans.lists.BooleanListIterator; import speiger.src.collections.utils.SanityChecks; @@ -313,6 +314,16 @@ public BooleanListIterator listIterator(int index) { return l.listIterator(index); } + @Override + public BooleanListIterator indexedIterator(int...indecies) { + return l.indexedIterator(indecies); + } + + @Override + public BooleanListIterator indexedIterator(IntList indecies) { + return l.indexedIterator(indecies); + } + @Override public BooleanList subList(int from, int to) { return BooleanLists.synchronize(l.subList(from, to)); @@ -420,6 +431,16 @@ public BooleanListIterator listIterator(int index) { return BooleanIterators.unmodifiable(l.listIterator(index)); } + @Override + public BooleanListIterator indexedIterator(int...indecies) { + return BooleanIterators.unmodifiable(l.indexedIterator(indecies)); + } + + @Override + public BooleanListIterator indexedIterator(IntList indecies) { + return BooleanIterators.unmodifiable(l.indexedIterator(indecies)); + } + @Override public BooleanList subList(int from, int to) { return BooleanLists.unmodifiable(l.subList(from, to)); @@ -508,6 +529,16 @@ public BooleanListIterator listIterator(int index) { return BooleanIterators.empty(); } + @Override + public BooleanListIterator indexedIterator(int...indecies) { + return BooleanIterators.empty(); + } + + @Override + public BooleanListIterator indexedIterator(IntList indecies) { + return BooleanIterators.empty(); + } + @Override public int hashCode() { return 1; } diff --git a/src/main/java/speiger/src/collections/booleans/utils/BooleanPriorityQueues.java b/src/main/java/speiger/src/collections/booleans/utils/BooleanPriorityQueues.java index fd8011e9..6fda575c 100644 --- a/src/main/java/speiger/src/collections/booleans/utils/BooleanPriorityQueues.java +++ b/src/main/java/speiger/src/collections/booleans/utils/BooleanPriorityQueues.java @@ -89,6 +89,8 @@ protected SynchronizedPriorityQueue(BooleanPriorityQueue queue, Object mutex) { @Override public boolean peek(int index) { synchronized(mutex) { return queue.peek(index); } } @Override + public boolean contains(boolean e) { synchronized(mutex) { return queue.contains(e); } } + @Override public boolean removeFirst(boolean e) { synchronized(mutex) { return queue.removeFirst(e); } } @Override public boolean removeLast(boolean e) { synchronized(mutex) { return queue.removeLast(e); } } diff --git a/src/main/java/speiger/src/collections/bytes/functions/ByteSupplier.java b/src/main/java/speiger/src/collections/bytes/functions/ByteSupplier.java index de0e3f6c..54367744 100644 --- a/src/main/java/speiger/src/collections/bytes/functions/ByteSupplier.java +++ b/src/main/java/speiger/src/collections/bytes/functions/ByteSupplier.java @@ -8,5 +8,5 @@ public interface ByteSupplier /** * @return the supplied value */ - public byte getAsInt(); + public byte getAsByte(); } \ No newline at end of file diff --git a/src/main/java/speiger/src/collections/bytes/lists/AbstractByteList.java b/src/main/java/speiger/src/collections/bytes/lists/AbstractByteList.java index 52aeb213..360803f8 100644 --- a/src/main/java/speiger/src/collections/bytes/lists/AbstractByteList.java +++ b/src/main/java/speiger/src/collections/bytes/lists/AbstractByteList.java @@ -12,6 +12,7 @@ import speiger.src.collections.bytes.collections.ByteCollection; import speiger.src.collections.bytes.collections.ByteIterator; import speiger.src.collections.bytes.collections.ByteSplititerator; +import speiger.src.collections.ints.lists.IntList; import speiger.src.collections.bytes.utils.ByteSplititerators; import speiger.src.collections.utils.SanityChecks; @@ -205,13 +206,23 @@ public ByteIterator iterator() { public ByteListIterator listIterator() { return listIterator(0); } - + @Override public ByteListIterator listIterator(int index) { if(index < 0 || index > size()) throw new IndexOutOfBoundsException(); return new ByteListIter(index); } + @Override + public ByteListIterator indexedIterator(int...indecies) { + return new IndexedIterator(indecies); + } + + @Override + public ByteListIterator indexedIterator(IntList indecies) { + return new ListIndexedIterator(indecies); + } + @Override public void size(int size) { while(size > size()) add((byte)0); @@ -566,7 +577,153 @@ public int back(int amount) { } } } + + private class ListIndexedIterator implements ByteListIterator { + IntList indecies; + int index; + int lastReturned = -1; + + ListIndexedIterator(IntList indecies) { + this.indecies = indecies; + } + + @Override + public boolean hasNext() { + return index < indecies.size(); + } + + @Override + public byte nextByte() { + if(!hasNext()) throw new NoSuchElementException(); + int i = index++; + return getByte((lastReturned = indecies.getInt(i))); + } + + @Override + public boolean hasPrevious() { + return index > 0; + } + + @Override + public byte previousByte() { + if(!hasPrevious()) throw new NoSuchElementException(); + index--; + return getByte((lastReturned = indecies.getInt(index))); + } + + @Override + public int nextIndex() { + return index; + } + + @Override + public int previousIndex() { + return index-1; + } + + @Override + public void remove() { throw new UnsupportedOperationException(); } + @Override + public void add(byte e) { throw new UnsupportedOperationException(); } + + @Override + public void set(byte e) { + if(lastReturned == -1) throw new IllegalStateException(); + AbstractByteList.this.set(lastReturned, e); + } + + @Override + public int skip(int amount) { + if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed"); + int steps = Math.min(amount, indecies.size() - index); + index += steps; + if(steps > 0) lastReturned = Math.min(index-1, indecies.size()-1); + return steps; + } + + @Override + public int back(int amount) { + if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed"); + int steps = Math.min(amount, index); + index -= steps; + if(steps > 0) lastReturned = Math.max(index, 0); + return steps; + } + } + + private class IndexedIterator implements ByteListIterator { + int[] indecies; + int index; + int lastReturned = -1; + + IndexedIterator(int[] indecies) { + this.indecies = indecies; + } + @Override + public boolean hasNext() { + return index < indecies.length; + } + + @Override + public byte nextByte() { + if(!hasNext()) throw new NoSuchElementException(); + int i = index++; + return getByte((lastReturned = indecies[i])); + } + + @Override + public boolean hasPrevious() { + return index > 0; + } + + @Override + public byte previousByte() { + if(!hasPrevious()) throw new NoSuchElementException(); + index--; + return getByte((lastReturned = indecies[index])); + } + + @Override + public int nextIndex() { + return index; + } + + @Override + public int previousIndex() { + return index-1; + } + + @Override + public void remove() { throw new UnsupportedOperationException(); } + @Override + public void add(byte e) { throw new UnsupportedOperationException(); } + + @Override + public void set(byte e) { + if(lastReturned == -1) throw new IllegalStateException(); + AbstractByteList.this.set(lastReturned, e); + } + + @Override + public int skip(int amount) { + if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed"); + int steps = Math.min(amount, indecies.length - index); + index += steps; + if(steps > 0) lastReturned = Math.min(index-1, indecies.length-1); + return steps; + } + + @Override + public int back(int amount) { + if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed"); + int steps = Math.min(amount, index); + index -= steps; + if(steps > 0) lastReturned = Math.max(index, 0); + return steps; + } + } + private class ByteListIter implements ByteListIterator { int index; int lastReturned = -1; @@ -644,7 +801,7 @@ public int back(int amount) { if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed"); int steps = Math.min(amount, index); index -= steps; - if(steps > 0) lastReturned = Math.min(index, size()-1); + if(steps > 0) lastReturned = Math.max(index, 0); return steps; } } diff --git a/src/main/java/speiger/src/collections/bytes/lists/ByteList.java b/src/main/java/speiger/src/collections/bytes/lists/ByteList.java index 459044e7..b47b05a4 100644 --- a/src/main/java/speiger/src/collections/bytes/lists/ByteList.java +++ b/src/main/java/speiger/src/collections/bytes/lists/ByteList.java @@ -14,6 +14,7 @@ import speiger.src.collections.bytes.functions.ByteComparator; import speiger.src.collections.bytes.utils.ByteArrays; import speiger.src.collections.bytes.utils.ByteLists; +import speiger.src.collections.ints.lists.IntList; import speiger.src.collections.bytes.utils.ByteSplititerators; import speiger.src.collections.utils.SanityChecks; @@ -342,6 +343,24 @@ public default void forEachIndexed(IntByteConsumer action) { @Override public ByteListIterator listIterator(int index); + /** + * Creates a Iterator that follows the indecies provided.
+ * For example if the Lists Contents is:
-1, 0 1
and the indecies are:
0, 1, 2, 2, 1, 0
+ * then the iterator will return the following values:
-1, 0, 1, 1, 0, -1 + * @param indecies that should be used for the iteration. + * @return a custom indexed iterator + */ + public ByteListIterator indexedIterator(int...indecies); + + /** + * Creates a Iterator that follows the indecies provided.
+ * For example if the Lists Contents is:
-1, 0 1
and the indecies are:
0, 1, 2, 2, 1, 0
+ * then the iterator will return the following values:
-1, 0, 1, 1, 0, -1 + * @param indecies that should be used for the iteration. + * @return a custom indexed iterator + */ + public ByteListIterator indexedIterator(IntList indecies); + /** * A Type-Specific List of subList * @see java.util.List#subList(int, int) diff --git a/src/main/java/speiger/src/collections/bytes/maps/abstracts/AbstractByte2BooleanMap.java b/src/main/java/speiger/src/collections/bytes/maps/abstracts/AbstractByte2BooleanMap.java index 6b2eaf73..5d930b71 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/abstracts/AbstractByte2BooleanMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/abstracts/AbstractByte2BooleanMap.java @@ -151,6 +151,39 @@ public boolean computeBoolean(byte key, ByteBooleanUnaryOperator mappingFunction return newValue; } + @Override + public boolean computeBooleanIfAbsent(byte key, BytePredicate mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(!containsKey(key)) { + boolean newValue = mappingFunction.test(key); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public boolean supplyBooleanIfAbsent(byte key, BooleanSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + if(!containsKey(key)) { + boolean newValue = valueProvider.getAsBoolean(); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public boolean computeBooleanIfPresent(byte key, ByteBooleanUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(containsKey(key)) { + boolean newValue = mappingFunction.applyAsBoolean(key, get(key)); + put(key, newValue); + return newValue; + } + return getDefaultReturnValue(); + } + @Override public boolean computeBooleanNonDefault(byte key, ByteBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -167,17 +200,6 @@ public boolean computeBooleanNonDefault(byte key, ByteBooleanUnaryOperator mappi return newValue; } - @Override - public boolean computeBooleanIfAbsent(byte key, BytePredicate mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(!containsKey(key)) { - boolean newValue = mappingFunction.test(key); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public boolean computeBooleanIfAbsentNonDefault(byte key, BytePredicate mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -192,17 +214,6 @@ public boolean computeBooleanIfAbsentNonDefault(byte key, BytePredicate mappingF return value; } - @Override - public boolean supplyBooleanIfAbsent(byte key, BooleanSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - if(!containsKey(key)) { - boolean newValue = valueProvider.getAsBoolean(); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public boolean supplyBooleanIfAbsentNonDefault(byte key, BooleanSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -217,17 +228,6 @@ public boolean supplyBooleanIfAbsentNonDefault(byte key, BooleanSupplier valuePr return value; } - @Override - public boolean computeBooleanIfPresent(byte key, ByteBooleanUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(containsKey(key)) { - boolean newValue = mappingFunction.applyAsBoolean(key, get(key)); - put(key, newValue); - return newValue; - } - return getDefaultReturnValue(); - } - @Override public boolean computeBooleanIfPresentNonDefault(byte key, ByteBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/bytes/maps/abstracts/AbstractByte2ByteMap.java b/src/main/java/speiger/src/collections/bytes/maps/abstracts/AbstractByte2ByteMap.java index cf08f102..62847fc7 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/abstracts/AbstractByte2ByteMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/abstracts/AbstractByte2ByteMap.java @@ -155,6 +155,39 @@ public byte computeByte(byte key, ByteByteUnaryOperator mappingFunction) { return newValue; } + @Override + public byte computeByteIfAbsent(byte key, ByteUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(!containsKey(key)) { + byte newValue = mappingFunction.applyAsByte(key); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public byte supplyByteIfAbsent(byte key, ByteSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + if(!containsKey(key)) { + byte newValue = valueProvider.getAsByte(); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public byte computeByteIfPresent(byte key, ByteByteUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(containsKey(key)) { + byte newValue = mappingFunction.applyAsByte(key, get(key)); + put(key, newValue); + return newValue; + } + return getDefaultReturnValue(); + } + @Override public byte computeByteNonDefault(byte key, ByteByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -171,17 +204,6 @@ public byte computeByteNonDefault(byte key, ByteByteUnaryOperator mappingFunctio return newValue; } - @Override - public byte computeByteIfAbsent(byte key, ByteUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(!containsKey(key)) { - byte newValue = mappingFunction.applyAsByte(key); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public byte computeByteIfAbsentNonDefault(byte key, ByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -196,23 +218,12 @@ public byte computeByteIfAbsentNonDefault(byte key, ByteUnaryOperator mappingFun return value; } - @Override - public byte supplyByteIfAbsent(byte key, ByteSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - if(!containsKey(key)) { - byte newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public byte supplyByteIfAbsentNonDefault(byte key, ByteSupplier valueProvider) { Objects.requireNonNull(valueProvider); byte value; if((value = get(key)) == getDefaultReturnValue() || !containsKey(key)) { - byte newValue = valueProvider.getAsInt(); + byte newValue = valueProvider.getAsByte(); if(newValue != getDefaultReturnValue()) { put(key, newValue); return newValue; @@ -221,17 +232,6 @@ public byte supplyByteIfAbsentNonDefault(byte key, ByteSupplier valueProvider) { return value; } - @Override - public byte computeByteIfPresent(byte key, ByteByteUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(containsKey(key)) { - byte newValue = mappingFunction.applyAsByte(key, get(key)); - put(key, newValue); - return newValue; - } - return getDefaultReturnValue(); - } - @Override public byte computeByteIfPresentNonDefault(byte key, ByteByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/bytes/maps/abstracts/AbstractByte2CharMap.java b/src/main/java/speiger/src/collections/bytes/maps/abstracts/AbstractByte2CharMap.java index 8a6190f0..97f5398f 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/abstracts/AbstractByte2CharMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/abstracts/AbstractByte2CharMap.java @@ -157,6 +157,39 @@ public char computeChar(byte key, ByteCharUnaryOperator mappingFunction) { return newValue; } + @Override + public char computeCharIfAbsent(byte key, Byte2CharFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(!containsKey(key)) { + char newValue = mappingFunction.applyAsChar(key); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public char supplyCharIfAbsent(byte key, CharSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + if(!containsKey(key)) { + char newValue = valueProvider.getAsChar(); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public char computeCharIfPresent(byte key, ByteCharUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(containsKey(key)) { + char newValue = mappingFunction.applyAsChar(key, get(key)); + put(key, newValue); + return newValue; + } + return getDefaultReturnValue(); + } + @Override public char computeCharNonDefault(byte key, ByteCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -173,17 +206,6 @@ public char computeCharNonDefault(byte key, ByteCharUnaryOperator mappingFunctio return newValue; } - @Override - public char computeCharIfAbsent(byte key, Byte2CharFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(!containsKey(key)) { - char newValue = mappingFunction.applyAsChar(key); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public char computeCharIfAbsentNonDefault(byte key, Byte2CharFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -198,23 +220,12 @@ public char computeCharIfAbsentNonDefault(byte key, Byte2CharFunction mappingFun return value; } - @Override - public char supplyCharIfAbsent(byte key, CharSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - if(!containsKey(key)) { - char newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public char supplyCharIfAbsentNonDefault(byte key, CharSupplier valueProvider) { Objects.requireNonNull(valueProvider); char value; if((value = get(key)) == getDefaultReturnValue() || !containsKey(key)) { - char newValue = valueProvider.getAsInt(); + char newValue = valueProvider.getAsChar(); if(newValue != getDefaultReturnValue()) { put(key, newValue); return newValue; @@ -223,17 +234,6 @@ public char supplyCharIfAbsentNonDefault(byte key, CharSupplier valueProvider) { return value; } - @Override - public char computeCharIfPresent(byte key, ByteCharUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(containsKey(key)) { - char newValue = mappingFunction.applyAsChar(key, get(key)); - put(key, newValue); - return newValue; - } - return getDefaultReturnValue(); - } - @Override public char computeCharIfPresentNonDefault(byte key, ByteCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/bytes/maps/abstracts/AbstractByte2DoubleMap.java b/src/main/java/speiger/src/collections/bytes/maps/abstracts/AbstractByte2DoubleMap.java index 75181013..0e3db33d 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/abstracts/AbstractByte2DoubleMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/abstracts/AbstractByte2DoubleMap.java @@ -157,6 +157,39 @@ public double computeDouble(byte key, ByteDoubleUnaryOperator mappingFunction) { return newValue; } + @Override + public double computeDoubleIfAbsent(byte key, Byte2DoubleFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(!containsKey(key)) { + double newValue = mappingFunction.applyAsDouble(key); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public double supplyDoubleIfAbsent(byte key, DoubleSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + if(!containsKey(key)) { + double newValue = valueProvider.getAsDouble(); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public double computeDoubleIfPresent(byte key, ByteDoubleUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(containsKey(key)) { + double newValue = mappingFunction.applyAsDouble(key, get(key)); + put(key, newValue); + return newValue; + } + return getDefaultReturnValue(); + } + @Override public double computeDoubleNonDefault(byte key, ByteDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -173,17 +206,6 @@ public double computeDoubleNonDefault(byte key, ByteDoubleUnaryOperator mappingF return newValue; } - @Override - public double computeDoubleIfAbsent(byte key, Byte2DoubleFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(!containsKey(key)) { - double newValue = mappingFunction.applyAsDouble(key); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public double computeDoubleIfAbsentNonDefault(byte key, Byte2DoubleFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -198,17 +220,6 @@ public double computeDoubleIfAbsentNonDefault(byte key, Byte2DoubleFunction mapp return value; } - @Override - public double supplyDoubleIfAbsent(byte key, DoubleSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - if(!containsKey(key)) { - double newValue = valueProvider.getAsDouble(); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public double supplyDoubleIfAbsentNonDefault(byte key, DoubleSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -223,17 +234,6 @@ public double supplyDoubleIfAbsentNonDefault(byte key, DoubleSupplier valueProvi return value; } - @Override - public double computeDoubleIfPresent(byte key, ByteDoubleUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(containsKey(key)) { - double newValue = mappingFunction.applyAsDouble(key, get(key)); - put(key, newValue); - return newValue; - } - return getDefaultReturnValue(); - } - @Override public double computeDoubleIfPresentNonDefault(byte key, ByteDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/bytes/maps/abstracts/AbstractByte2FloatMap.java b/src/main/java/speiger/src/collections/bytes/maps/abstracts/AbstractByte2FloatMap.java index 585d3648..9d8c6bb2 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/abstracts/AbstractByte2FloatMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/abstracts/AbstractByte2FloatMap.java @@ -157,6 +157,39 @@ public float computeFloat(byte key, ByteFloatUnaryOperator mappingFunction) { return newValue; } + @Override + public float computeFloatIfAbsent(byte key, Byte2FloatFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(!containsKey(key)) { + float newValue = mappingFunction.applyAsFloat(key); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public float supplyFloatIfAbsent(byte key, FloatSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + if(!containsKey(key)) { + float newValue = valueProvider.getAsFloat(); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public float computeFloatIfPresent(byte key, ByteFloatUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(containsKey(key)) { + float newValue = mappingFunction.applyAsFloat(key, get(key)); + put(key, newValue); + return newValue; + } + return getDefaultReturnValue(); + } + @Override public float computeFloatNonDefault(byte key, ByteFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -173,17 +206,6 @@ public float computeFloatNonDefault(byte key, ByteFloatUnaryOperator mappingFunc return newValue; } - @Override - public float computeFloatIfAbsent(byte key, Byte2FloatFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(!containsKey(key)) { - float newValue = mappingFunction.applyAsFloat(key); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public float computeFloatIfAbsentNonDefault(byte key, Byte2FloatFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -198,23 +220,12 @@ public float computeFloatIfAbsentNonDefault(byte key, Byte2FloatFunction mapping return value; } - @Override - public float supplyFloatIfAbsent(byte key, FloatSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - if(!containsKey(key)) { - float newValue = valueProvider.getAsDouble(); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public float supplyFloatIfAbsentNonDefault(byte key, FloatSupplier valueProvider) { Objects.requireNonNull(valueProvider); float value; if((value = get(key)) == getDefaultReturnValue() || !containsKey(key)) { - float newValue = valueProvider.getAsDouble(); + float newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) != Float.floatToIntBits(getDefaultReturnValue())) { put(key, newValue); return newValue; @@ -223,17 +234,6 @@ public float supplyFloatIfAbsentNonDefault(byte key, FloatSupplier valueProvider return value; } - @Override - public float computeFloatIfPresent(byte key, ByteFloatUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(containsKey(key)) { - float newValue = mappingFunction.applyAsFloat(key, get(key)); - put(key, newValue); - return newValue; - } - return getDefaultReturnValue(); - } - @Override public float computeFloatIfPresentNonDefault(byte key, ByteFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/bytes/maps/abstracts/AbstractByte2IntMap.java b/src/main/java/speiger/src/collections/bytes/maps/abstracts/AbstractByte2IntMap.java index 8ca1f7a0..f2b7195c 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/abstracts/AbstractByte2IntMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/abstracts/AbstractByte2IntMap.java @@ -157,6 +157,39 @@ public int computeInt(byte key, ByteIntUnaryOperator mappingFunction) { return newValue; } + @Override + public int computeIntIfAbsent(byte key, Byte2IntFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(!containsKey(key)) { + int newValue = mappingFunction.applyAsInt(key); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public int supplyIntIfAbsent(byte key, IntSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + if(!containsKey(key)) { + int newValue = valueProvider.getAsInt(); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public int computeIntIfPresent(byte key, ByteIntUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(containsKey(key)) { + int newValue = mappingFunction.applyAsInt(key, get(key)); + put(key, newValue); + return newValue; + } + return getDefaultReturnValue(); + } + @Override public int computeIntNonDefault(byte key, ByteIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -173,17 +206,6 @@ public int computeIntNonDefault(byte key, ByteIntUnaryOperator mappingFunction) return newValue; } - @Override - public int computeIntIfAbsent(byte key, Byte2IntFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(!containsKey(key)) { - int newValue = mappingFunction.applyAsInt(key); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public int computeIntIfAbsentNonDefault(byte key, Byte2IntFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -198,17 +220,6 @@ public int computeIntIfAbsentNonDefault(byte key, Byte2IntFunction mappingFuncti return value; } - @Override - public int supplyIntIfAbsent(byte key, IntSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - if(!containsKey(key)) { - int newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public int supplyIntIfAbsentNonDefault(byte key, IntSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -223,17 +234,6 @@ public int supplyIntIfAbsentNonDefault(byte key, IntSupplier valueProvider) { return value; } - @Override - public int computeIntIfPresent(byte key, ByteIntUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(containsKey(key)) { - int newValue = mappingFunction.applyAsInt(key, get(key)); - put(key, newValue); - return newValue; - } - return getDefaultReturnValue(); - } - @Override public int computeIntIfPresentNonDefault(byte key, ByteIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/bytes/maps/abstracts/AbstractByte2LongMap.java b/src/main/java/speiger/src/collections/bytes/maps/abstracts/AbstractByte2LongMap.java index 9c89cce7..8d551173 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/abstracts/AbstractByte2LongMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/abstracts/AbstractByte2LongMap.java @@ -157,6 +157,39 @@ public long computeLong(byte key, ByteLongUnaryOperator mappingFunction) { return newValue; } + @Override + public long computeLongIfAbsent(byte key, Byte2LongFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(!containsKey(key)) { + long newValue = mappingFunction.applyAsLong(key); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public long supplyLongIfAbsent(byte key, LongSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + if(!containsKey(key)) { + long newValue = valueProvider.getAsLong(); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public long computeLongIfPresent(byte key, ByteLongUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(containsKey(key)) { + long newValue = mappingFunction.applyAsLong(key, get(key)); + put(key, newValue); + return newValue; + } + return getDefaultReturnValue(); + } + @Override public long computeLongNonDefault(byte key, ByteLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -173,17 +206,6 @@ public long computeLongNonDefault(byte key, ByteLongUnaryOperator mappingFunctio return newValue; } - @Override - public long computeLongIfAbsent(byte key, Byte2LongFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(!containsKey(key)) { - long newValue = mappingFunction.applyAsLong(key); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public long computeLongIfAbsentNonDefault(byte key, Byte2LongFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -198,17 +220,6 @@ public long computeLongIfAbsentNonDefault(byte key, Byte2LongFunction mappingFun return value; } - @Override - public long supplyLongIfAbsent(byte key, LongSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - if(!containsKey(key)) { - long newValue = valueProvider.getAsLong(); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public long supplyLongIfAbsentNonDefault(byte key, LongSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -223,17 +234,6 @@ public long supplyLongIfAbsentNonDefault(byte key, LongSupplier valueProvider) { return value; } - @Override - public long computeLongIfPresent(byte key, ByteLongUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(containsKey(key)) { - long newValue = mappingFunction.applyAsLong(key, get(key)); - put(key, newValue); - return newValue; - } - return getDefaultReturnValue(); - } - @Override public long computeLongIfPresentNonDefault(byte key, ByteLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/bytes/maps/abstracts/AbstractByte2ObjectMap.java b/src/main/java/speiger/src/collections/bytes/maps/abstracts/AbstractByte2ObjectMap.java index 45682390..e258494c 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/abstracts/AbstractByte2ObjectMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/abstracts/AbstractByte2ObjectMap.java @@ -159,22 +159,6 @@ public V compute(byte key, ByteObjectUnaryOperator mappingFunction) { return newValue; } - @Override - public V computeNonDefault(byte key, ByteObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - V value = get(key); - V newValue = mappingFunction.apply(key, value); - if(Objects.equals(newValue, getDefaultReturnValue())) { - if(!Objects.equals(value, getDefaultReturnValue()) || containsKey(key)) { - remove(key); - return getDefaultReturnValue(); - } - return getDefaultReturnValue(); - } - put(key, newValue); - return newValue; - } - @Override public V computeIfAbsent(byte key, ByteFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -189,20 +173,6 @@ public V computeIfAbsent(byte key, ByteFunction mappingFunction) { return value; } - @Override - public V computeIfAbsentNonDefault(byte key, ByteFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - V value; - if((value = get(key)) == getDefaultReturnValue() || !containsKey(key)) { - V newValue = mappingFunction.apply(key); - if(!Objects.equals(newValue, getDefaultReturnValue())) { - put(key, newValue); - return newValue; - } - } - return value; - } - @Override public V supplyIfAbsent(byte key, ObjectSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -217,20 +187,6 @@ public V supplyIfAbsent(byte key, ObjectSupplier valueProvider) { return value; } - @Override - public V supplyIfAbsentNonDefault(byte key, ObjectSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - V value; - if((value = get(key)) == getDefaultReturnValue() || !containsKey(key)) { - V newValue = valueProvider.get(); - if(!Objects.equals(newValue, getDefaultReturnValue())) { - put(key, newValue); - return newValue; - } - } - return value; - } - @Override public V computeIfPresent(byte key, ByteObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -246,21 +202,6 @@ public V computeIfPresent(byte key, ByteObjectUnaryOperator mappingFunction) return getDefaultReturnValue(); } - @Override - public V computeIfPresentNonDefault(byte key, ByteObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - V value; - if(!Objects.equals((value = get(key)), getDefaultReturnValue()) || containsKey(key)) { - V newValue = mappingFunction.apply(key, value); - if(!Objects.equals(newValue, getDefaultReturnValue())) { - put(key, newValue); - return newValue; - } - remove(key); - } - return getDefaultReturnValue(); - } - @Override public V merge(byte key, V value, ObjectObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/bytes/maps/abstracts/AbstractByte2ShortMap.java b/src/main/java/speiger/src/collections/bytes/maps/abstracts/AbstractByte2ShortMap.java index 64b0ebc3..3922aa3f 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/abstracts/AbstractByte2ShortMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/abstracts/AbstractByte2ShortMap.java @@ -157,6 +157,39 @@ public short computeShort(byte key, ByteShortUnaryOperator mappingFunction) { return newValue; } + @Override + public short computeShortIfAbsent(byte key, Byte2ShortFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(!containsKey(key)) { + short newValue = mappingFunction.applyAsShort(key); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public short supplyShortIfAbsent(byte key, ShortSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + if(!containsKey(key)) { + short newValue = valueProvider.getAsShort(); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public short computeShortIfPresent(byte key, ByteShortUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(containsKey(key)) { + short newValue = mappingFunction.applyAsShort(key, get(key)); + put(key, newValue); + return newValue; + } + return getDefaultReturnValue(); + } + @Override public short computeShortNonDefault(byte key, ByteShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -173,17 +206,6 @@ public short computeShortNonDefault(byte key, ByteShortUnaryOperator mappingFunc return newValue; } - @Override - public short computeShortIfAbsent(byte key, Byte2ShortFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(!containsKey(key)) { - short newValue = mappingFunction.applyAsShort(key); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public short computeShortIfAbsentNonDefault(byte key, Byte2ShortFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -198,23 +220,12 @@ public short computeShortIfAbsentNonDefault(byte key, Byte2ShortFunction mapping return value; } - @Override - public short supplyShortIfAbsent(byte key, ShortSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - if(!containsKey(key)) { - short newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public short supplyShortIfAbsentNonDefault(byte key, ShortSupplier valueProvider) { Objects.requireNonNull(valueProvider); short value; if((value = get(key)) == getDefaultReturnValue() || !containsKey(key)) { - short newValue = valueProvider.getAsInt(); + short newValue = valueProvider.getAsShort(); if(newValue != getDefaultReturnValue()) { put(key, newValue); return newValue; @@ -223,17 +234,6 @@ public short supplyShortIfAbsentNonDefault(byte key, ShortSupplier valueProvider return value; } - @Override - public short computeShortIfPresent(byte key, ByteShortUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(containsKey(key)) { - short newValue = mappingFunction.applyAsShort(key, get(key)); - put(key, newValue); - return newValue; - } - return getDefaultReturnValue(); - } - @Override public short computeShortIfPresentNonDefault(byte key, ByteShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/concurrent/Byte2BooleanConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/concurrent/Byte2BooleanConcurrentOpenHashMap.java index 856c9eb7..866147a5 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/concurrent/Byte2BooleanConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/concurrent/Byte2BooleanConcurrentOpenHashMap.java @@ -438,13 +438,6 @@ public boolean computeBoolean(byte key, ByteBooleanUnaryOperator mappingFunction return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public boolean computeBooleanNonDefault(byte key, ByteBooleanUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public boolean computeBooleanIfAbsent(byte key, BytePredicate mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -452,13 +445,6 @@ public boolean computeBooleanIfAbsent(byte key, BytePredicate mappingFunction) { return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public boolean computeBooleanIfAbsentNonDefault(byte key, BytePredicate mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public boolean supplyBooleanIfAbsent(byte key, BooleanSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -467,17 +453,31 @@ public boolean supplyBooleanIfAbsent(byte key, BooleanSupplier valueProvider) { } @Override - public boolean supplyBooleanIfAbsentNonDefault(byte key, BooleanSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public boolean computeBooleanIfPresent(byte key, ByteBooleanUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); + return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } @Override - public boolean computeBooleanIfPresent(byte key, ByteBooleanUnaryOperator mappingFunction) { + public boolean computeBooleanNonDefault(byte key, ByteBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).computeIfPresent(hash, key, mappingFunction); + return getSegment(hash).computeNonDefault(hash, key, mappingFunction); + } + + @Override + public boolean computeBooleanIfAbsentNonDefault(byte key, BytePredicate mappingFunction) { + Objects.requireNonNull(mappingFunction); + int hash = getHashCode(key); + return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); + } + + @Override + public boolean supplyBooleanIfAbsentNonDefault(byte key, BooleanSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + int hash = getHashCode(key); + return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); } @Override @@ -2032,35 +2032,29 @@ protected boolean compute(int hash, byte key, ByteBooleanUnaryOperator mappingFu } } - protected boolean computeNonDefault(int hash, byte key, ByteBooleanUnaryOperator mappingFunction) { + protected boolean computeIfAbsent(int hash, byte key, BytePredicate mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + boolean newValue = mappingFunction.test(key); insert(-index-1, key, newValue); return newValue; } - boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + boolean newValue = values[index]; return newValue; } finally { unlockWrite(stamp); } } - - protected boolean computeIfAbsent(int hash, byte key, BytePredicate mappingFunction) { + + protected boolean supplyIfAbsent(int hash, byte key, BooleanSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - boolean newValue = mappingFunction.test(key); + boolean newValue = valueProvider.getAsBoolean(); insert(-index-1, key, newValue); return newValue; } @@ -2071,23 +2065,37 @@ protected boolean computeIfAbsent(int hash, byte key, BytePredicate mappingFunct unlockWrite(stamp); } } + + protected boolean computeIfPresent(int hash, byte key, ByteBooleanUnaryOperator mappingFunction) { + long stamp = writeLock(); + try { + int index = findIndex(hash, key); + if(index < 0) return getDefaultReturnValue(); + boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); + values[index] = newValue; + return newValue; + } + finally { + unlockWrite(stamp); + } + } - protected boolean computeIfAbsentNonDefault(int hash, byte key, BytePredicate mappingFunction) { + protected boolean computeNonDefault(int hash, byte key, ByteBooleanUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - boolean newValue = mappingFunction.test(key); + boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - boolean newValue = values[index]; + boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.test(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } finally { @@ -2095,16 +2103,22 @@ protected boolean computeIfAbsentNonDefault(int hash, byte key, BytePredicate ma } } - protected boolean supplyIfAbsent(int hash, byte key, BooleanSupplier valueProvider) { + protected boolean computeIfAbsentNonDefault(int hash, byte key, BytePredicate mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - boolean newValue = valueProvider.getAsBoolean(); + boolean newValue = mappingFunction.test(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } boolean newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.test(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } finally { @@ -2135,20 +2149,6 @@ protected boolean supplyIfAbsentNonDefault(int hash, byte key, BooleanSupplier v } } - protected boolean computeIfPresent(int hash, byte key, ByteBooleanUnaryOperator mappingFunction) { - long stamp = writeLock(); - try { - int index = findIndex(hash, key); - if(index < 0) return getDefaultReturnValue(); - boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); - values[index] = newValue; - return newValue; - } - finally { - unlockWrite(stamp); - } - } - protected boolean computeIfPresentNonDefault(int hash, byte key, ByteBooleanUnaryOperator mappingFunction) { long stamp = writeLock(); try { diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/concurrent/Byte2ByteConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/concurrent/Byte2ByteConcurrentOpenHashMap.java index 1f020dfd..1c24085b 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/concurrent/Byte2ByteConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/concurrent/Byte2ByteConcurrentOpenHashMap.java @@ -444,13 +444,6 @@ public byte computeByte(byte key, ByteByteUnaryOperator mappingFunction) { return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public byte computeByteNonDefault(byte key, ByteByteUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public byte computeByteIfAbsent(byte key, ByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -458,13 +451,6 @@ public byte computeByteIfAbsent(byte key, ByteUnaryOperator mappingFunction) { return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public byte computeByteIfAbsentNonDefault(byte key, ByteUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public byte supplyByteIfAbsent(byte key, ByteSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -473,17 +459,31 @@ public byte supplyByteIfAbsent(byte key, ByteSupplier valueProvider) { } @Override - public byte supplyByteIfAbsentNonDefault(byte key, ByteSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public byte computeByteIfPresent(byte key, ByteByteUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); + return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } @Override - public byte computeByteIfPresent(byte key, ByteByteUnaryOperator mappingFunction) { + public byte computeByteNonDefault(byte key, ByteByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).computeIfPresent(hash, key, mappingFunction); + return getSegment(hash).computeNonDefault(hash, key, mappingFunction); + } + + @Override + public byte computeByteIfAbsentNonDefault(byte key, ByteUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int hash = getHashCode(key); + return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); + } + + @Override + public byte supplyByteIfAbsentNonDefault(byte key, ByteSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + int hash = getHashCode(key); + return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); } @Override @@ -2069,35 +2069,29 @@ protected byte compute(int hash, byte key, ByteByteUnaryOperator mappingFunction } } - protected byte computeNonDefault(int hash, byte key, ByteByteUnaryOperator mappingFunction) { + protected byte computeIfAbsent(int hash, byte key, ByteUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + byte newValue = mappingFunction.applyAsByte(key); insert(-index-1, key, newValue); return newValue; } - byte newValue = mappingFunction.applyAsByte(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + byte newValue = values[index]; return newValue; } finally { unlockWrite(stamp); } } - - protected byte computeIfAbsent(int hash, byte key, ByteUnaryOperator mappingFunction) { + + protected byte supplyIfAbsent(int hash, byte key, ByteSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = valueProvider.getAsByte(); insert(-index-1, key, newValue); return newValue; } @@ -2108,23 +2102,14 @@ protected byte computeIfAbsent(int hash, byte key, ByteUnaryOperator mappingFunc unlockWrite(stamp); } } - - protected byte computeIfAbsentNonDefault(int hash, byte key, ByteUnaryOperator mappingFunction) { + + protected byte computeIfPresent(int hash, byte key, ByteByteUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key); - if(newValue == getDefaultReturnValue()) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - byte newValue = values[index]; - if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsByte(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; - } + if(index < 0) return getDefaultReturnValue(); + byte newValue = mappingFunction.applyAsByte(key, values[index]); + values[index] = newValue; return newValue; } finally { @@ -2132,16 +2117,22 @@ protected byte computeIfAbsentNonDefault(int hash, byte key, ByteUnaryOperator m } } - protected byte supplyIfAbsent(int hash, byte key, ByteSupplier valueProvider) { + protected byte computeNonDefault(int hash, byte key, ByteByteUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - byte newValue = valueProvider.getAsInt(); + byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - byte newValue = values[index]; + byte newValue = mappingFunction.applyAsByte(key, values[index]); + if(newValue == getDefaultReturnValue()) { + removeIndex(index); + return newValue; + } + values[index] = newValue; return newValue; } finally { @@ -2149,19 +2140,19 @@ protected byte supplyIfAbsent(int hash, byte key, ByteSupplier valueProvider) { } } - protected byte supplyIfAbsentNonDefault(int hash, byte key, ByteSupplier valueProvider) { + protected byte computeIfAbsentNonDefault(int hash, byte key, ByteUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - byte newValue = valueProvider.getAsInt(); + byte newValue = mappingFunction.applyAsByte(key); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } byte newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = mappingFunction.applyAsByte(key); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } @@ -2172,13 +2163,22 @@ protected byte supplyIfAbsentNonDefault(int hash, byte key, ByteSupplier valuePr } } - protected byte computeIfPresent(int hash, byte key, ByteByteUnaryOperator mappingFunction) { + protected byte supplyIfAbsentNonDefault(int hash, byte key, ByteSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0) return getDefaultReturnValue(); - byte newValue = mappingFunction.applyAsByte(key, values[index]); - values[index] = newValue; + if(index < 0) { + byte newValue = valueProvider.getAsByte(); + if(newValue == getDefaultReturnValue()) return newValue; + insert(-index-1, key, newValue); + return newValue; + } + byte newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = valueProvider.getAsByte(); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } finally { diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/concurrent/Byte2CharConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/concurrent/Byte2CharConcurrentOpenHashMap.java index c27fcbd7..98ca658e 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/concurrent/Byte2CharConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/concurrent/Byte2CharConcurrentOpenHashMap.java @@ -451,13 +451,6 @@ public char computeChar(byte key, ByteCharUnaryOperator mappingFunction) { return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public char computeCharNonDefault(byte key, ByteCharUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public char computeCharIfAbsent(byte key, Byte2CharFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -465,13 +458,6 @@ public char computeCharIfAbsent(byte key, Byte2CharFunction mappingFunction) { return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public char computeCharIfAbsentNonDefault(byte key, Byte2CharFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public char supplyCharIfAbsent(byte key, CharSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -480,17 +466,31 @@ public char supplyCharIfAbsent(byte key, CharSupplier valueProvider) { } @Override - public char supplyCharIfAbsentNonDefault(byte key, CharSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public char computeCharIfPresent(byte key, ByteCharUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); + return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } @Override - public char computeCharIfPresent(byte key, ByteCharUnaryOperator mappingFunction) { + public char computeCharNonDefault(byte key, ByteCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).computeIfPresent(hash, key, mappingFunction); + return getSegment(hash).computeNonDefault(hash, key, mappingFunction); + } + + @Override + public char computeCharIfAbsentNonDefault(byte key, Byte2CharFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + int hash = getHashCode(key); + return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); + } + + @Override + public char supplyCharIfAbsentNonDefault(byte key, CharSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + int hash = getHashCode(key); + return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); } @Override @@ -2076,35 +2076,29 @@ protected char compute(int hash, byte key, ByteCharUnaryOperator mappingFunction } } - protected char computeNonDefault(int hash, byte key, ByteCharUnaryOperator mappingFunction) { + protected char computeIfAbsent(int hash, byte key, Byte2CharFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + char newValue = mappingFunction.applyAsChar(key); insert(-index-1, key, newValue); return newValue; } - char newValue = mappingFunction.applyAsChar(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + char newValue = values[index]; return newValue; } finally { unlockWrite(stamp); } } - - protected char computeIfAbsent(int hash, byte key, Byte2CharFunction mappingFunction) { + + protected char supplyIfAbsent(int hash, byte key, CharSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = valueProvider.getAsChar(); insert(-index-1, key, newValue); return newValue; } @@ -2115,23 +2109,14 @@ protected char computeIfAbsent(int hash, byte key, Byte2CharFunction mappingFunc unlockWrite(stamp); } } - - protected char computeIfAbsentNonDefault(int hash, byte key, Byte2CharFunction mappingFunction) { + + protected char computeIfPresent(int hash, byte key, ByteCharUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0) { - char newValue = mappingFunction.applyAsChar(key); - if(newValue == getDefaultReturnValue()) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - char newValue = values[index]; - if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsChar(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; - } + if(index < 0) return getDefaultReturnValue(); + char newValue = mappingFunction.applyAsChar(key, values[index]); + values[index] = newValue; return newValue; } finally { @@ -2139,16 +2124,22 @@ protected char computeIfAbsentNonDefault(int hash, byte key, Byte2CharFunction m } } - protected char supplyIfAbsent(int hash, byte key, CharSupplier valueProvider) { + protected char computeNonDefault(int hash, byte key, ByteCharUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - char newValue = valueProvider.getAsInt(); + char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - char newValue = values[index]; + char newValue = mappingFunction.applyAsChar(key, values[index]); + if(newValue == getDefaultReturnValue()) { + removeIndex(index); + return newValue; + } + values[index] = newValue; return newValue; } finally { @@ -2156,19 +2147,19 @@ protected char supplyIfAbsent(int hash, byte key, CharSupplier valueProvider) { } } - protected char supplyIfAbsentNonDefault(int hash, byte key, CharSupplier valueProvider) { + protected char computeIfAbsentNonDefault(int hash, byte key, Byte2CharFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - char newValue = valueProvider.getAsInt(); + char newValue = mappingFunction.applyAsChar(key); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } char newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = mappingFunction.applyAsChar(key); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } @@ -2179,13 +2170,22 @@ protected char supplyIfAbsentNonDefault(int hash, byte key, CharSupplier valuePr } } - protected char computeIfPresent(int hash, byte key, ByteCharUnaryOperator mappingFunction) { + protected char supplyIfAbsentNonDefault(int hash, byte key, CharSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0) return getDefaultReturnValue(); - char newValue = mappingFunction.applyAsChar(key, values[index]); - values[index] = newValue; + if(index < 0) { + char newValue = valueProvider.getAsChar(); + if(newValue == getDefaultReturnValue()) return newValue; + insert(-index-1, key, newValue); + return newValue; + } + char newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = valueProvider.getAsChar(); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } finally { diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/concurrent/Byte2DoubleConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/concurrent/Byte2DoubleConcurrentOpenHashMap.java index 5eb8cf64..2ddbfc76 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/concurrent/Byte2DoubleConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/concurrent/Byte2DoubleConcurrentOpenHashMap.java @@ -451,13 +451,6 @@ public double computeDouble(byte key, ByteDoubleUnaryOperator mappingFunction) { return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public double computeDoubleNonDefault(byte key, ByteDoubleUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public double computeDoubleIfAbsent(byte key, Byte2DoubleFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -465,13 +458,6 @@ public double computeDoubleIfAbsent(byte key, Byte2DoubleFunction mappingFunctio return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public double computeDoubleIfAbsentNonDefault(byte key, Byte2DoubleFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public double supplyDoubleIfAbsent(byte key, DoubleSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -480,17 +466,31 @@ public double supplyDoubleIfAbsent(byte key, DoubleSupplier valueProvider) { } @Override - public double supplyDoubleIfAbsentNonDefault(byte key, DoubleSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public double computeDoubleIfPresent(byte key, ByteDoubleUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); + return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } @Override - public double computeDoubleIfPresent(byte key, ByteDoubleUnaryOperator mappingFunction) { + public double computeDoubleNonDefault(byte key, ByteDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).computeIfPresent(hash, key, mappingFunction); + return getSegment(hash).computeNonDefault(hash, key, mappingFunction); + } + + @Override + public double computeDoubleIfAbsentNonDefault(byte key, Byte2DoubleFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + int hash = getHashCode(key); + return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); + } + + @Override + public double supplyDoubleIfAbsentNonDefault(byte key, DoubleSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + int hash = getHashCode(key); + return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); } @Override @@ -2076,35 +2076,29 @@ protected double compute(int hash, byte key, ByteDoubleUnaryOperator mappingFunc } } - protected double computeNonDefault(int hash, byte key, ByteDoubleUnaryOperator mappingFunction) { + protected double computeIfAbsent(int hash, byte key, Byte2DoubleFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + double newValue = mappingFunction.applyAsDouble(key); insert(-index-1, key, newValue); return newValue; } - double newValue = mappingFunction.applyAsDouble(key, values[index]); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + double newValue = values[index]; return newValue; } finally { unlockWrite(stamp); } } - - protected double computeIfAbsent(int hash, byte key, Byte2DoubleFunction mappingFunction) { + + protected double supplyIfAbsent(int hash, byte key, DoubleSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = valueProvider.getAsDouble(); insert(-index-1, key, newValue); return newValue; } @@ -2115,23 +2109,37 @@ protected double computeIfAbsent(int hash, byte key, Byte2DoubleFunction mapping unlockWrite(stamp); } } + + protected double computeIfPresent(int hash, byte key, ByteDoubleUnaryOperator mappingFunction) { + long stamp = writeLock(); + try { + int index = findIndex(hash, key); + if(index < 0) return getDefaultReturnValue(); + double newValue = mappingFunction.applyAsDouble(key, values[index]); + values[index] = newValue; + return newValue; + } + finally { + unlockWrite(stamp); + } + } - protected double computeIfAbsentNonDefault(int hash, byte key, Byte2DoubleFunction mappingFunction) { + protected double computeNonDefault(int hash, byte key, ByteDoubleUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } - double newValue = values[index]; + double newValue = mappingFunction.applyAsDouble(key, values[index]); if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - newValue = mappingFunction.applyAsDouble(key); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } finally { @@ -2139,16 +2147,22 @@ protected double computeIfAbsentNonDefault(int hash, byte key, Byte2DoubleFuncti } } - protected double supplyIfAbsent(int hash, byte key, DoubleSupplier valueProvider) { + protected double computeIfAbsentNonDefault(int hash, byte key, Byte2DoubleFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - double newValue = valueProvider.getAsDouble(); + double newValue = mappingFunction.applyAsDouble(key); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } double newValue = values[index]; + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { + newValue = mappingFunction.applyAsDouble(key); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + values[index] = newValue; + } return newValue; } finally { @@ -2179,20 +2193,6 @@ protected double supplyIfAbsentNonDefault(int hash, byte key, DoubleSupplier val } } - protected double computeIfPresent(int hash, byte key, ByteDoubleUnaryOperator mappingFunction) { - long stamp = writeLock(); - try { - int index = findIndex(hash, key); - if(index < 0) return getDefaultReturnValue(); - double newValue = mappingFunction.applyAsDouble(key, values[index]); - values[index] = newValue; - return newValue; - } - finally { - unlockWrite(stamp); - } - } - protected double computeIfPresentNonDefault(int hash, byte key, ByteDoubleUnaryOperator mappingFunction) { long stamp = writeLock(); try { diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/concurrent/Byte2FloatConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/concurrent/Byte2FloatConcurrentOpenHashMap.java index 239fdbc9..179dffb3 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/concurrent/Byte2FloatConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/concurrent/Byte2FloatConcurrentOpenHashMap.java @@ -451,13 +451,6 @@ public float computeFloat(byte key, ByteFloatUnaryOperator mappingFunction) { return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public float computeFloatNonDefault(byte key, ByteFloatUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public float computeFloatIfAbsent(byte key, Byte2FloatFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -465,13 +458,6 @@ public float computeFloatIfAbsent(byte key, Byte2FloatFunction mappingFunction) return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public float computeFloatIfAbsentNonDefault(byte key, Byte2FloatFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public float supplyFloatIfAbsent(byte key, FloatSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -480,17 +466,31 @@ public float supplyFloatIfAbsent(byte key, FloatSupplier valueProvider) { } @Override - public float supplyFloatIfAbsentNonDefault(byte key, FloatSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public float computeFloatIfPresent(byte key, ByteFloatUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); + return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } @Override - public float computeFloatIfPresent(byte key, ByteFloatUnaryOperator mappingFunction) { + public float computeFloatNonDefault(byte key, ByteFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).computeIfPresent(hash, key, mappingFunction); + return getSegment(hash).computeNonDefault(hash, key, mappingFunction); + } + + @Override + public float computeFloatIfAbsentNonDefault(byte key, Byte2FloatFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + int hash = getHashCode(key); + return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); + } + + @Override + public float supplyFloatIfAbsentNonDefault(byte key, FloatSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + int hash = getHashCode(key); + return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); } @Override @@ -2076,35 +2076,29 @@ protected float compute(int hash, byte key, ByteFloatUnaryOperator mappingFuncti } } - protected float computeNonDefault(int hash, byte key, ByteFloatUnaryOperator mappingFunction) { + protected float computeIfAbsent(int hash, byte key, Byte2FloatFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + float newValue = mappingFunction.applyAsFloat(key); insert(-index-1, key, newValue); return newValue; } - float newValue = mappingFunction.applyAsFloat(key, values[index]); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + float newValue = values[index]; return newValue; } finally { unlockWrite(stamp); } } - - protected float computeIfAbsent(int hash, byte key, Byte2FloatFunction mappingFunction) { + + protected float supplyIfAbsent(int hash, byte key, FloatSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = valueProvider.getAsFloat(); insert(-index-1, key, newValue); return newValue; } @@ -2115,23 +2109,14 @@ protected float computeIfAbsent(int hash, byte key, Byte2FloatFunction mappingFu unlockWrite(stamp); } } - - protected float computeIfAbsentNonDefault(int hash, byte key, Byte2FloatFunction mappingFunction) { + + protected float computeIfPresent(int hash, byte key, ByteFloatUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - float newValue = values[index]; - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - newValue = mappingFunction.applyAsFloat(key); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; - values[index] = newValue; - } + if(index < 0) return getDefaultReturnValue(); + float newValue = mappingFunction.applyAsFloat(key, values[index]); + values[index] = newValue; return newValue; } finally { @@ -2139,16 +2124,22 @@ protected float computeIfAbsentNonDefault(int hash, byte key, Byte2FloatFunction } } - protected float supplyIfAbsent(int hash, byte key, FloatSupplier valueProvider) { + protected float computeNonDefault(int hash, byte key, ByteFloatUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - float newValue = valueProvider.getAsDouble(); + float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } - float newValue = values[index]; + float newValue = mappingFunction.applyAsFloat(key, values[index]); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { + removeIndex(index); + return newValue; + } + values[index] = newValue; return newValue; } finally { @@ -2156,19 +2147,19 @@ protected float supplyIfAbsent(int hash, byte key, FloatSupplier valueProvider) } } - protected float supplyIfAbsentNonDefault(int hash, byte key, FloatSupplier valueProvider) { + protected float computeIfAbsentNonDefault(int hash, byte key, Byte2FloatFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - float newValue = valueProvider.getAsDouble(); + float newValue = mappingFunction.applyAsFloat(key); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } float newValue = values[index]; if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - newValue = valueProvider.getAsDouble(); + newValue = mappingFunction.applyAsFloat(key); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; values[index] = newValue; } @@ -2179,13 +2170,22 @@ protected float supplyIfAbsentNonDefault(int hash, byte key, FloatSupplier value } } - protected float computeIfPresent(int hash, byte key, ByteFloatUnaryOperator mappingFunction) { + protected float supplyIfAbsentNonDefault(int hash, byte key, FloatSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0) return getDefaultReturnValue(); - float newValue = mappingFunction.applyAsFloat(key, values[index]); - values[index] = newValue; + if(index < 0) { + float newValue = valueProvider.getAsFloat(); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + insert(-index-1, key, newValue); + return newValue; + } + float newValue = values[index]; + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { + newValue = valueProvider.getAsFloat(); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + values[index] = newValue; + } return newValue; } finally { diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/concurrent/Byte2IntConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/concurrent/Byte2IntConcurrentOpenHashMap.java index d4af8ac2..cf35fa1f 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/concurrent/Byte2IntConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/concurrent/Byte2IntConcurrentOpenHashMap.java @@ -451,13 +451,6 @@ public int computeInt(byte key, ByteIntUnaryOperator mappingFunction) { return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public int computeIntNonDefault(byte key, ByteIntUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public int computeIntIfAbsent(byte key, Byte2IntFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -465,13 +458,6 @@ public int computeIntIfAbsent(byte key, Byte2IntFunction mappingFunction) { return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public int computeIntIfAbsentNonDefault(byte key, Byte2IntFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public int supplyIntIfAbsent(byte key, IntSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -480,17 +466,31 @@ public int supplyIntIfAbsent(byte key, IntSupplier valueProvider) { } @Override - public int supplyIntIfAbsentNonDefault(byte key, IntSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public int computeIntIfPresent(byte key, ByteIntUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); + return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } @Override - public int computeIntIfPresent(byte key, ByteIntUnaryOperator mappingFunction) { + public int computeIntNonDefault(byte key, ByteIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).computeIfPresent(hash, key, mappingFunction); + return getSegment(hash).computeNonDefault(hash, key, mappingFunction); + } + + @Override + public int computeIntIfAbsentNonDefault(byte key, Byte2IntFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + int hash = getHashCode(key); + return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); + } + + @Override + public int supplyIntIfAbsentNonDefault(byte key, IntSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + int hash = getHashCode(key); + return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); } @Override @@ -2076,35 +2076,29 @@ protected int compute(int hash, byte key, ByteIntUnaryOperator mappingFunction) } } - protected int computeNonDefault(int hash, byte key, ByteIntUnaryOperator mappingFunction) { + protected int computeIfAbsent(int hash, byte key, Byte2IntFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + int newValue = mappingFunction.applyAsInt(key); insert(-index-1, key, newValue); return newValue; } - int newValue = mappingFunction.applyAsInt(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + int newValue = values[index]; return newValue; } finally { unlockWrite(stamp); } } - - protected int computeIfAbsent(int hash, byte key, Byte2IntFunction mappingFunction) { + + protected int supplyIfAbsent(int hash, byte key, IntSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = valueProvider.getAsInt(); insert(-index-1, key, newValue); return newValue; } @@ -2115,23 +2109,37 @@ protected int computeIfAbsent(int hash, byte key, Byte2IntFunction mappingFuncti unlockWrite(stamp); } } + + protected int computeIfPresent(int hash, byte key, ByteIntUnaryOperator mappingFunction) { + long stamp = writeLock(); + try { + int index = findIndex(hash, key); + if(index < 0) return getDefaultReturnValue(); + int newValue = mappingFunction.applyAsInt(key, values[index]); + values[index] = newValue; + return newValue; + } + finally { + unlockWrite(stamp); + } + } - protected int computeIfAbsentNonDefault(int hash, byte key, Byte2IntFunction mappingFunction) { + protected int computeNonDefault(int hash, byte key, ByteIntUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - int newValue = values[index]; + int newValue = mappingFunction.applyAsInt(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsInt(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } finally { @@ -2139,16 +2147,22 @@ protected int computeIfAbsentNonDefault(int hash, byte key, Byte2IntFunction map } } - protected int supplyIfAbsent(int hash, byte key, IntSupplier valueProvider) { + protected int computeIfAbsentNonDefault(int hash, byte key, Byte2IntFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - int newValue = valueProvider.getAsInt(); + int newValue = mappingFunction.applyAsInt(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } int newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsInt(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } finally { @@ -2179,20 +2193,6 @@ protected int supplyIfAbsentNonDefault(int hash, byte key, IntSupplier valueProv } } - protected int computeIfPresent(int hash, byte key, ByteIntUnaryOperator mappingFunction) { - long stamp = writeLock(); - try { - int index = findIndex(hash, key); - if(index < 0) return getDefaultReturnValue(); - int newValue = mappingFunction.applyAsInt(key, values[index]); - values[index] = newValue; - return newValue; - } - finally { - unlockWrite(stamp); - } - } - protected int computeIfPresentNonDefault(int hash, byte key, ByteIntUnaryOperator mappingFunction) { long stamp = writeLock(); try { diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/concurrent/Byte2LongConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/concurrent/Byte2LongConcurrentOpenHashMap.java index 7185e272..f350730d 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/concurrent/Byte2LongConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/concurrent/Byte2LongConcurrentOpenHashMap.java @@ -451,13 +451,6 @@ public long computeLong(byte key, ByteLongUnaryOperator mappingFunction) { return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public long computeLongNonDefault(byte key, ByteLongUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public long computeLongIfAbsent(byte key, Byte2LongFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -465,13 +458,6 @@ public long computeLongIfAbsent(byte key, Byte2LongFunction mappingFunction) { return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public long computeLongIfAbsentNonDefault(byte key, Byte2LongFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public long supplyLongIfAbsent(byte key, LongSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -480,17 +466,31 @@ public long supplyLongIfAbsent(byte key, LongSupplier valueProvider) { } @Override - public long supplyLongIfAbsentNonDefault(byte key, LongSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public long computeLongIfPresent(byte key, ByteLongUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); + return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } @Override - public long computeLongIfPresent(byte key, ByteLongUnaryOperator mappingFunction) { + public long computeLongNonDefault(byte key, ByteLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).computeIfPresent(hash, key, mappingFunction); + return getSegment(hash).computeNonDefault(hash, key, mappingFunction); + } + + @Override + public long computeLongIfAbsentNonDefault(byte key, Byte2LongFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + int hash = getHashCode(key); + return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); + } + + @Override + public long supplyLongIfAbsentNonDefault(byte key, LongSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + int hash = getHashCode(key); + return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); } @Override @@ -2076,35 +2076,29 @@ protected long compute(int hash, byte key, ByteLongUnaryOperator mappingFunction } } - protected long computeNonDefault(int hash, byte key, ByteLongUnaryOperator mappingFunction) { + protected long computeIfAbsent(int hash, byte key, Byte2LongFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + long newValue = mappingFunction.applyAsLong(key); insert(-index-1, key, newValue); return newValue; } - long newValue = mappingFunction.applyAsLong(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + long newValue = values[index]; return newValue; } finally { unlockWrite(stamp); } } - - protected long computeIfAbsent(int hash, byte key, Byte2LongFunction mappingFunction) { + + protected long supplyIfAbsent(int hash, byte key, LongSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = valueProvider.getAsLong(); insert(-index-1, key, newValue); return newValue; } @@ -2115,23 +2109,37 @@ protected long computeIfAbsent(int hash, byte key, Byte2LongFunction mappingFunc unlockWrite(stamp); } } + + protected long computeIfPresent(int hash, byte key, ByteLongUnaryOperator mappingFunction) { + long stamp = writeLock(); + try { + int index = findIndex(hash, key); + if(index < 0) return getDefaultReturnValue(); + long newValue = mappingFunction.applyAsLong(key, values[index]); + values[index] = newValue; + return newValue; + } + finally { + unlockWrite(stamp); + } + } - protected long computeIfAbsentNonDefault(int hash, byte key, Byte2LongFunction mappingFunction) { + protected long computeNonDefault(int hash, byte key, ByteLongUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - long newValue = values[index]; + long newValue = mappingFunction.applyAsLong(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsLong(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } finally { @@ -2139,16 +2147,22 @@ protected long computeIfAbsentNonDefault(int hash, byte key, Byte2LongFunction m } } - protected long supplyIfAbsent(int hash, byte key, LongSupplier valueProvider) { + protected long computeIfAbsentNonDefault(int hash, byte key, Byte2LongFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - long newValue = valueProvider.getAsLong(); + long newValue = mappingFunction.applyAsLong(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } long newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsLong(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } finally { @@ -2179,20 +2193,6 @@ protected long supplyIfAbsentNonDefault(int hash, byte key, LongSupplier valuePr } } - protected long computeIfPresent(int hash, byte key, ByteLongUnaryOperator mappingFunction) { - long stamp = writeLock(); - try { - int index = findIndex(hash, key); - if(index < 0) return getDefaultReturnValue(); - long newValue = mappingFunction.applyAsLong(key, values[index]); - values[index] = newValue; - return newValue; - } - finally { - unlockWrite(stamp); - } - } - protected long computeIfPresentNonDefault(int hash, byte key, ByteLongUnaryOperator mappingFunction) { long stamp = writeLock(); try { diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/concurrent/Byte2ObjectConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/concurrent/Byte2ObjectConcurrentOpenHashMap.java index 4ab870a8..bf4042ed 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/concurrent/Byte2ObjectConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/concurrent/Byte2ObjectConcurrentOpenHashMap.java @@ -426,13 +426,6 @@ public V compute(byte key, ByteObjectUnaryOperator mappingFunction) { return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public V computeNonDefault(byte key, ByteObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public V computeIfAbsent(byte key, ByteFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -440,13 +433,6 @@ public V computeIfAbsent(byte key, ByteFunction mappingFunction) { return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public V computeIfAbsentNonDefault(byte key, ByteFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public V supplyIfAbsent(byte key, ObjectSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -454,13 +440,6 @@ public V supplyIfAbsent(byte key, ObjectSupplier valueProvider) { return getSegment(hash).supplyIfAbsent(hash, key, valueProvider); } - @Override - public V supplyIfAbsentNonDefault(byte key, ObjectSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); - } - @Override public V computeIfPresent(byte key, ByteObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -468,13 +447,6 @@ public V computeIfPresent(byte key, ByteObjectUnaryOperator mappingFunction) return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } - @Override - public V computeIfPresentNonDefault(byte key, ByteObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfPresentNonDefault(hash, key, mappingFunction); - } - @Override public V merge(byte key, V value, ObjectObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -2011,29 +1983,6 @@ protected V compute(int hash, byte key, ByteObjectUnaryOperator mappingFuncti } } - protected V computeNonDefault(int hash, byte key, ByteObjectUnaryOperator mappingFunction) { - long stamp = writeLock(); - try { - int index = findIndex(hash, key); - if(index < 0) { - V newValue = mappingFunction.apply(key, getDefaultReturnValue()); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = mappingFunction.apply(key, values[index]); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; - return newValue; - } - finally { - unlockWrite(stamp); - } - } - protected V computeIfAbsent(int hash, byte key, ByteFunction mappingFunction) { long stamp = writeLock(); try { @@ -2056,30 +2005,7 @@ protected V computeIfAbsent(int hash, byte key, ByteFunction mappingFunction) unlockWrite(stamp); } } - - protected V computeIfAbsentNonDefault(int hash, byte key, ByteFunction mappingFunction) { - long stamp = writeLock(); - try { - int index = findIndex(hash, key); - if(index < 0) { - V newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = values[index]; - if(Objects.equals(newValue, getDefaultReturnValue())) { - newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - values[index] = newValue; - } - return newValue; - } - finally { - unlockWrite(stamp); - } - } - + protected V supplyIfAbsent(int hash, byte key, ObjectSupplier valueProvider) { long stamp = writeLock(); try { @@ -2102,30 +2028,7 @@ protected V supplyIfAbsent(int hash, byte key, ObjectSupplier valueProvider) unlockWrite(stamp); } } - - protected V supplyIfAbsentNonDefault(int hash, byte key, ObjectSupplier valueProvider) { - long stamp = writeLock(); - try { - int index = findIndex(hash, key); - if(index < 0) { - V newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = values[index]; - if(Objects.equals(newValue, getDefaultReturnValue())) { - newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - values[index] = newValue; - } - return newValue; - } - finally { - unlockWrite(stamp); - } - } - + protected V computeIfPresent(int hash, byte key, ByteObjectUnaryOperator mappingFunction) { long stamp = writeLock(); try { @@ -2144,11 +2047,16 @@ protected V computeIfPresent(int hash, byte key, ByteObjectUnaryOperator mapp } } - protected V computeIfPresentNonDefault(int hash, byte key, ByteObjectUnaryOperator mappingFunction) { + protected V computeNonDefault(int hash, byte key, ByteObjectUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0 || Objects.equals(values[index], getDefaultReturnValue())) return getDefaultReturnValue(); + if(index < 0) { + V newValue = mappingFunction.apply(key, getDefaultReturnValue()); + if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; + insert(-index-1, key, newValue); + return newValue; + } V newValue = mappingFunction.apply(key, values[index]); if(Objects.equals(newValue, getDefaultReturnValue())) { removeIndex(index); diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/concurrent/Byte2ShortConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/concurrent/Byte2ShortConcurrentOpenHashMap.java index 5f301058..8ea1dd68 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/concurrent/Byte2ShortConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/concurrent/Byte2ShortConcurrentOpenHashMap.java @@ -451,13 +451,6 @@ public short computeShort(byte key, ByteShortUnaryOperator mappingFunction) { return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public short computeShortNonDefault(byte key, ByteShortUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public short computeShortIfAbsent(byte key, Byte2ShortFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -465,13 +458,6 @@ public short computeShortIfAbsent(byte key, Byte2ShortFunction mappingFunction) return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public short computeShortIfAbsentNonDefault(byte key, Byte2ShortFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public short supplyShortIfAbsent(byte key, ShortSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -480,17 +466,31 @@ public short supplyShortIfAbsent(byte key, ShortSupplier valueProvider) { } @Override - public short supplyShortIfAbsentNonDefault(byte key, ShortSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public short computeShortIfPresent(byte key, ByteShortUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); + return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } @Override - public short computeShortIfPresent(byte key, ByteShortUnaryOperator mappingFunction) { + public short computeShortNonDefault(byte key, ByteShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).computeIfPresent(hash, key, mappingFunction); + return getSegment(hash).computeNonDefault(hash, key, mappingFunction); + } + + @Override + public short computeShortIfAbsentNonDefault(byte key, Byte2ShortFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + int hash = getHashCode(key); + return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); + } + + @Override + public short supplyShortIfAbsentNonDefault(byte key, ShortSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + int hash = getHashCode(key); + return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); } @Override @@ -2076,35 +2076,29 @@ protected short compute(int hash, byte key, ByteShortUnaryOperator mappingFuncti } } - protected short computeNonDefault(int hash, byte key, ByteShortUnaryOperator mappingFunction) { + protected short computeIfAbsent(int hash, byte key, Byte2ShortFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + short newValue = mappingFunction.applyAsShort(key); insert(-index-1, key, newValue); return newValue; } - short newValue = mappingFunction.applyAsShort(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + short newValue = values[index]; return newValue; } finally { unlockWrite(stamp); } } - - protected short computeIfAbsent(int hash, byte key, Byte2ShortFunction mappingFunction) { + + protected short supplyIfAbsent(int hash, byte key, ShortSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = valueProvider.getAsShort(); insert(-index-1, key, newValue); return newValue; } @@ -2115,23 +2109,14 @@ protected short computeIfAbsent(int hash, byte key, Byte2ShortFunction mappingFu unlockWrite(stamp); } } - - protected short computeIfAbsentNonDefault(int hash, byte key, Byte2ShortFunction mappingFunction) { + + protected short computeIfPresent(int hash, byte key, ByteShortUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0) { - short newValue = mappingFunction.applyAsShort(key); - if(newValue == getDefaultReturnValue()) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - short newValue = values[index]; - if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsShort(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; - } + if(index < 0) return getDefaultReturnValue(); + short newValue = mappingFunction.applyAsShort(key, values[index]); + values[index] = newValue; return newValue; } finally { @@ -2139,16 +2124,22 @@ protected short computeIfAbsentNonDefault(int hash, byte key, Byte2ShortFunction } } - protected short supplyIfAbsent(int hash, byte key, ShortSupplier valueProvider) { + protected short computeNonDefault(int hash, byte key, ByteShortUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - short newValue = valueProvider.getAsInt(); + short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - short newValue = values[index]; + short newValue = mappingFunction.applyAsShort(key, values[index]); + if(newValue == getDefaultReturnValue()) { + removeIndex(index); + return newValue; + } + values[index] = newValue; return newValue; } finally { @@ -2156,19 +2147,19 @@ protected short supplyIfAbsent(int hash, byte key, ShortSupplier valueProvider) } } - protected short supplyIfAbsentNonDefault(int hash, byte key, ShortSupplier valueProvider) { + protected short computeIfAbsentNonDefault(int hash, byte key, Byte2ShortFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - short newValue = valueProvider.getAsInt(); + short newValue = mappingFunction.applyAsShort(key); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } short newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = mappingFunction.applyAsShort(key); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } @@ -2179,13 +2170,22 @@ protected short supplyIfAbsentNonDefault(int hash, byte key, ShortSupplier value } } - protected short computeIfPresent(int hash, byte key, ByteShortUnaryOperator mappingFunction) { + protected short supplyIfAbsentNonDefault(int hash, byte key, ShortSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0) return getDefaultReturnValue(); - short newValue = mappingFunction.applyAsShort(key, values[index]); - values[index] = newValue; + if(index < 0) { + short newValue = valueProvider.getAsShort(); + if(newValue == getDefaultReturnValue()) return newValue; + insert(-index-1, key, newValue); + return newValue; + } + short newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = valueProvider.getAsShort(); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } finally { diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2BooleanOpenCustomHashMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2BooleanOpenCustomHashMap.java index b09b2520..fb5bfb67 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2BooleanOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2BooleanOpenCustomHashMap.java @@ -441,30 +441,24 @@ public boolean computeBoolean(byte key, ByteBooleanUnaryOperator mappingFunction } @Override - public boolean computeBooleanNonDefault(byte key, ByteBooleanUnaryOperator mappingFunction) { + public boolean computeBooleanIfAbsent(byte key, BytePredicate mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + boolean newValue = mappingFunction.test(key); insert(-index-1, key, newValue); return newValue; } - boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + boolean newValue = values[index]; return newValue; } - + @Override - public boolean computeBooleanIfAbsent(byte key, BytePredicate mappingFunction) { - Objects.requireNonNull(mappingFunction); + public boolean supplyBooleanIfAbsent(byte key, BooleanSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - boolean newValue = mappingFunction.test(key); + boolean newValue = valueProvider.getAsBoolean(); insert(-index-1, key, newValue); return newValue; } @@ -473,34 +467,50 @@ public boolean computeBooleanIfAbsent(byte key, BytePredicate mappingFunction) { } @Override - public boolean computeBooleanIfAbsentNonDefault(byte key, BytePredicate mappingFunction) { + public boolean computeBooleanIfPresent(byte key, ByteBooleanUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public boolean computeBooleanNonDefault(byte key, ByteBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - boolean newValue = mappingFunction.test(key); + boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - boolean newValue = values[index]; + boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.test(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public boolean supplyBooleanIfAbsent(byte key, BooleanSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public boolean computeBooleanIfAbsentNonDefault(byte key, BytePredicate mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - boolean newValue = valueProvider.getAsBoolean(); + boolean newValue = mappingFunction.test(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } boolean newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.test(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -523,16 +533,6 @@ public boolean supplyBooleanIfAbsentNonDefault(byte key, BooleanSupplier valuePr return newValue; } - @Override - public boolean computeBooleanIfPresent(byte key, ByteBooleanUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public boolean computeBooleanIfPresentNonDefault(byte key, ByteBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2ByteOpenCustomHashMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2ByteOpenCustomHashMap.java index 4a2322ae..616f06df 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2ByteOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2ByteOpenCustomHashMap.java @@ -455,30 +455,24 @@ public byte computeByte(byte key, ByteByteUnaryOperator mappingFunction) { } @Override - public byte computeByteNonDefault(byte key, ByteByteUnaryOperator mappingFunction) { + public byte computeByteIfAbsent(byte key, ByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + byte newValue = mappingFunction.applyAsByte(key); insert(-index-1, key, newValue); return newValue; } - byte newValue = mappingFunction.applyAsByte(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + byte newValue = values[index]; return newValue; } - + @Override - public byte computeByteIfAbsent(byte key, ByteUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); + public byte supplyByteIfAbsent(byte key, ByteSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = valueProvider.getAsByte(); insert(-index-1, key, newValue); return newValue; } @@ -487,34 +481,50 @@ public byte computeByteIfAbsent(byte key, ByteUnaryOperator mappingFunction) { } @Override - public byte computeByteIfAbsentNonDefault(byte key, ByteUnaryOperator mappingFunction) { + public byte computeByteIfPresent(byte key, ByteByteUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + byte newValue = mappingFunction.applyAsByte(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public byte computeByteNonDefault(byte key, ByteByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - byte newValue = values[index]; + byte newValue = mappingFunction.applyAsByte(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsByte(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public byte supplyByteIfAbsent(byte key, ByteSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public byte computeByteIfAbsentNonDefault(byte key, ByteUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - byte newValue = valueProvider.getAsInt(); + byte newValue = mappingFunction.applyAsByte(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } byte newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsByte(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -523,30 +533,20 @@ public byte supplyByteIfAbsentNonDefault(byte key, ByteSupplier valueProvider) { Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - byte newValue = valueProvider.getAsInt(); + byte newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } byte newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public byte computeByteIfPresent(byte key, ByteByteUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - byte newValue = mappingFunction.applyAsByte(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public byte computeByteIfPresentNonDefault(byte key, ByteByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2CharOpenCustomHashMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2CharOpenCustomHashMap.java index f7dda8ef..f0db65c7 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2CharOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2CharOpenCustomHashMap.java @@ -463,30 +463,24 @@ public char computeChar(byte key, ByteCharUnaryOperator mappingFunction) { } @Override - public char computeCharNonDefault(byte key, ByteCharUnaryOperator mappingFunction) { + public char computeCharIfAbsent(byte key, Byte2CharFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + char newValue = mappingFunction.applyAsChar(key); insert(-index-1, key, newValue); return newValue; } - char newValue = mappingFunction.applyAsChar(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + char newValue = values[index]; return newValue; } - + @Override - public char computeCharIfAbsent(byte key, Byte2CharFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public char supplyCharIfAbsent(byte key, CharSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = valueProvider.getAsChar(); insert(-index-1, key, newValue); return newValue; } @@ -495,34 +489,50 @@ public char computeCharIfAbsent(byte key, Byte2CharFunction mappingFunction) { } @Override - public char computeCharIfAbsentNonDefault(byte key, Byte2CharFunction mappingFunction) { + public char computeCharIfPresent(byte key, ByteCharUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + char newValue = mappingFunction.applyAsChar(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public char computeCharNonDefault(byte key, ByteCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - char newValue = values[index]; + char newValue = mappingFunction.applyAsChar(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsChar(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public char supplyCharIfAbsent(byte key, CharSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public char computeCharIfAbsentNonDefault(byte key, Byte2CharFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - char newValue = valueProvider.getAsInt(); + char newValue = mappingFunction.applyAsChar(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } char newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsChar(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -531,30 +541,20 @@ public char supplyCharIfAbsentNonDefault(byte key, CharSupplier valueProvider) { Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - char newValue = valueProvider.getAsInt(); + char newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } char newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public char computeCharIfPresent(byte key, ByteCharUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - char newValue = mappingFunction.applyAsChar(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public char computeCharIfPresentNonDefault(byte key, ByteCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2DoubleOpenCustomHashMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2DoubleOpenCustomHashMap.java index 2d5d7f35..96a025be 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2DoubleOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2DoubleOpenCustomHashMap.java @@ -463,30 +463,24 @@ public double computeDouble(byte key, ByteDoubleUnaryOperator mappingFunction) { } @Override - public double computeDoubleNonDefault(byte key, ByteDoubleUnaryOperator mappingFunction) { + public double computeDoubleIfAbsent(byte key, Byte2DoubleFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + double newValue = mappingFunction.applyAsDouble(key); insert(-index-1, key, newValue); return newValue; } - double newValue = mappingFunction.applyAsDouble(key, values[index]); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + double newValue = values[index]; return newValue; } - + @Override - public double computeDoubleIfAbsent(byte key, Byte2DoubleFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public double supplyDoubleIfAbsent(byte key, DoubleSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = valueProvider.getAsDouble(); insert(-index-1, key, newValue); return newValue; } @@ -495,34 +489,50 @@ public double computeDoubleIfAbsent(byte key, Byte2DoubleFunction mappingFunctio } @Override - public double computeDoubleIfAbsentNonDefault(byte key, Byte2DoubleFunction mappingFunction) { + public double computeDoubleIfPresent(byte key, ByteDoubleUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + double newValue = mappingFunction.applyAsDouble(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public double computeDoubleNonDefault(byte key, ByteDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } - double newValue = values[index]; + double newValue = mappingFunction.applyAsDouble(key, values[index]); if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - newValue = mappingFunction.applyAsDouble(key); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public double supplyDoubleIfAbsent(byte key, DoubleSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public double computeDoubleIfAbsentNonDefault(byte key, Byte2DoubleFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - double newValue = valueProvider.getAsDouble(); + double newValue = mappingFunction.applyAsDouble(key); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } double newValue = values[index]; + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { + newValue = mappingFunction.applyAsDouble(key); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + values[index] = newValue; + } return newValue; } @@ -545,16 +555,6 @@ public double supplyDoubleIfAbsentNonDefault(byte key, DoubleSupplier valueProvi return newValue; } - @Override - public double computeDoubleIfPresent(byte key, ByteDoubleUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - double newValue = mappingFunction.applyAsDouble(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public double computeDoubleIfPresentNonDefault(byte key, ByteDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2FloatOpenCustomHashMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2FloatOpenCustomHashMap.java index 9f71328b..452bc6d5 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2FloatOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2FloatOpenCustomHashMap.java @@ -463,30 +463,24 @@ public float computeFloat(byte key, ByteFloatUnaryOperator mappingFunction) { } @Override - public float computeFloatNonDefault(byte key, ByteFloatUnaryOperator mappingFunction) { + public float computeFloatIfAbsent(byte key, Byte2FloatFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + float newValue = mappingFunction.applyAsFloat(key); insert(-index-1, key, newValue); return newValue; } - float newValue = mappingFunction.applyAsFloat(key, values[index]); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + float newValue = values[index]; return newValue; } - + @Override - public float computeFloatIfAbsent(byte key, Byte2FloatFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public float supplyFloatIfAbsent(byte key, FloatSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = valueProvider.getAsFloat(); insert(-index-1, key, newValue); return newValue; } @@ -495,34 +489,50 @@ public float computeFloatIfAbsent(byte key, Byte2FloatFunction mappingFunction) } @Override - public float computeFloatIfAbsentNonDefault(byte key, Byte2FloatFunction mappingFunction) { + public float computeFloatIfPresent(byte key, ByteFloatUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + float newValue = mappingFunction.applyAsFloat(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public float computeFloatNonDefault(byte key, ByteFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } - float newValue = values[index]; + float newValue = mappingFunction.applyAsFloat(key, values[index]); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - newValue = mappingFunction.applyAsFloat(key); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public float supplyFloatIfAbsent(byte key, FloatSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public float computeFloatIfAbsentNonDefault(byte key, Byte2FloatFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - float newValue = valueProvider.getAsDouble(); + float newValue = mappingFunction.applyAsFloat(key); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } float newValue = values[index]; + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { + newValue = mappingFunction.applyAsFloat(key); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + values[index] = newValue; + } return newValue; } @@ -531,30 +541,20 @@ public float supplyFloatIfAbsentNonDefault(byte key, FloatSupplier valueProvider Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - float newValue = valueProvider.getAsDouble(); + float newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } float newValue = values[index]; if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - newValue = valueProvider.getAsDouble(); + newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; values[index] = newValue; } return newValue; } - @Override - public float computeFloatIfPresent(byte key, ByteFloatUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - float newValue = mappingFunction.applyAsFloat(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public float computeFloatIfPresentNonDefault(byte key, ByteFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2IntOpenCustomHashMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2IntOpenCustomHashMap.java index 164803f8..b8ac58fc 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2IntOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2IntOpenCustomHashMap.java @@ -463,30 +463,24 @@ public int computeInt(byte key, ByteIntUnaryOperator mappingFunction) { } @Override - public int computeIntNonDefault(byte key, ByteIntUnaryOperator mappingFunction) { + public int computeIntIfAbsent(byte key, Byte2IntFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + int newValue = mappingFunction.applyAsInt(key); insert(-index-1, key, newValue); return newValue; } - int newValue = mappingFunction.applyAsInt(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + int newValue = values[index]; return newValue; } - + @Override - public int computeIntIfAbsent(byte key, Byte2IntFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public int supplyIntIfAbsent(byte key, IntSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = valueProvider.getAsInt(); insert(-index-1, key, newValue); return newValue; } @@ -495,34 +489,50 @@ public int computeIntIfAbsent(byte key, Byte2IntFunction mappingFunction) { } @Override - public int computeIntIfAbsentNonDefault(byte key, Byte2IntFunction mappingFunction) { + public int computeIntIfPresent(byte key, ByteIntUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + int newValue = mappingFunction.applyAsInt(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public int computeIntNonDefault(byte key, ByteIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - int newValue = values[index]; + int newValue = mappingFunction.applyAsInt(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsInt(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public int supplyIntIfAbsent(byte key, IntSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public int computeIntIfAbsentNonDefault(byte key, Byte2IntFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - int newValue = valueProvider.getAsInt(); + int newValue = mappingFunction.applyAsInt(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } int newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsInt(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -545,16 +555,6 @@ public int supplyIntIfAbsentNonDefault(byte key, IntSupplier valueProvider) { return newValue; } - @Override - public int computeIntIfPresent(byte key, ByteIntUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - int newValue = mappingFunction.applyAsInt(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public int computeIntIfPresentNonDefault(byte key, ByteIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2LongOpenCustomHashMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2LongOpenCustomHashMap.java index 98280eb9..6b68b2de 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2LongOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2LongOpenCustomHashMap.java @@ -463,30 +463,24 @@ public long computeLong(byte key, ByteLongUnaryOperator mappingFunction) { } @Override - public long computeLongNonDefault(byte key, ByteLongUnaryOperator mappingFunction) { + public long computeLongIfAbsent(byte key, Byte2LongFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + long newValue = mappingFunction.applyAsLong(key); insert(-index-1, key, newValue); return newValue; } - long newValue = mappingFunction.applyAsLong(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + long newValue = values[index]; return newValue; } - + @Override - public long computeLongIfAbsent(byte key, Byte2LongFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public long supplyLongIfAbsent(byte key, LongSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = valueProvider.getAsLong(); insert(-index-1, key, newValue); return newValue; } @@ -495,34 +489,50 @@ public long computeLongIfAbsent(byte key, Byte2LongFunction mappingFunction) { } @Override - public long computeLongIfAbsentNonDefault(byte key, Byte2LongFunction mappingFunction) { + public long computeLongIfPresent(byte key, ByteLongUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + long newValue = mappingFunction.applyAsLong(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public long computeLongNonDefault(byte key, ByteLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - long newValue = values[index]; + long newValue = mappingFunction.applyAsLong(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsLong(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public long supplyLongIfAbsent(byte key, LongSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public long computeLongIfAbsentNonDefault(byte key, Byte2LongFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - long newValue = valueProvider.getAsLong(); + long newValue = mappingFunction.applyAsLong(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } long newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsLong(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -545,16 +555,6 @@ public long supplyLongIfAbsentNonDefault(byte key, LongSupplier valueProvider) { return newValue; } - @Override - public long computeLongIfPresent(byte key, ByteLongUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - long newValue = mappingFunction.applyAsLong(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public long computeLongIfPresentNonDefault(byte key, ByteLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2ObjectOpenCustomHashMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2ObjectOpenCustomHashMap.java index b1c1bd46..0e3d8ab0 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2ObjectOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2ObjectOpenCustomHashMap.java @@ -432,25 +432,6 @@ public V compute(byte key, ByteObjectUnaryOperator mappingFunction) { return newValue; } - @Override - public V computeNonDefault(byte key, ByteObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) { - V newValue = mappingFunction.apply(key, getDefaultReturnValue()); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = mappingFunction.apply(key, values[index]); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; - return newValue; - } - @Override public V computeIfAbsent(byte key, ByteFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -469,26 +450,7 @@ public V computeIfAbsent(byte key, ByteFunction mappingFunction) { } return newValue; } - - @Override - public V computeIfAbsentNonDefault(byte key, ByteFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) { - V newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = values[index]; - if(Objects.equals(newValue, getDefaultReturnValue())) { - newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - values[index] = newValue; - } - return newValue; - } - + @Override public V supplyIfAbsent(byte key, ObjectSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -508,25 +470,6 @@ public V supplyIfAbsent(byte key, ObjectSupplier valueProvider) { return newValue; } - @Override - public V supplyIfAbsentNonDefault(byte key, ObjectSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - int index = findIndex(key); - if(index < 0) { - V newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = values[index]; - if(Objects.equals(newValue, getDefaultReturnValue())) { - newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - values[index] = newValue; - } - return newValue; - } - @Override public V computeIfPresent(byte key, ByteObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -541,20 +484,6 @@ public V computeIfPresent(byte key, ByteObjectUnaryOperator mappingFunction) return newValue; } - @Override - public V computeIfPresentNonDefault(byte key, ByteObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0 || Objects.equals(values[index], getDefaultReturnValue())) return getDefaultReturnValue(); - V newValue = mappingFunction.apply(key, values[index]); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; - return newValue; - } - @Override public V merge(byte key, V value, ObjectObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2ShortOpenCustomHashMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2ShortOpenCustomHashMap.java index 4942d142..d27135f3 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2ShortOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/customHash/Byte2ShortOpenCustomHashMap.java @@ -463,30 +463,24 @@ public short computeShort(byte key, ByteShortUnaryOperator mappingFunction) { } @Override - public short computeShortNonDefault(byte key, ByteShortUnaryOperator mappingFunction) { + public short computeShortIfAbsent(byte key, Byte2ShortFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + short newValue = mappingFunction.applyAsShort(key); insert(-index-1, key, newValue); return newValue; } - short newValue = mappingFunction.applyAsShort(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + short newValue = values[index]; return newValue; } - + @Override - public short computeShortIfAbsent(byte key, Byte2ShortFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public short supplyShortIfAbsent(byte key, ShortSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = valueProvider.getAsShort(); insert(-index-1, key, newValue); return newValue; } @@ -495,34 +489,50 @@ public short computeShortIfAbsent(byte key, Byte2ShortFunction mappingFunction) } @Override - public short computeShortIfAbsentNonDefault(byte key, Byte2ShortFunction mappingFunction) { + public short computeShortIfPresent(byte key, ByteShortUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + short newValue = mappingFunction.applyAsShort(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public short computeShortNonDefault(byte key, ByteShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - short newValue = values[index]; + short newValue = mappingFunction.applyAsShort(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsShort(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public short supplyShortIfAbsent(byte key, ShortSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public short computeShortIfAbsentNonDefault(byte key, Byte2ShortFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - short newValue = valueProvider.getAsInt(); + short newValue = mappingFunction.applyAsShort(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } short newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsShort(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -531,30 +541,20 @@ public short supplyShortIfAbsentNonDefault(byte key, ShortSupplier valueProvider Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - short newValue = valueProvider.getAsInt(); + short newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } short newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public short computeShortIfPresent(byte key, ByteShortUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - short newValue = mappingFunction.applyAsShort(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public short computeShortIfPresentNonDefault(byte key, ByteShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2BooleanOpenHashMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2BooleanOpenHashMap.java index 24f196fb..ba5debd5 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2BooleanOpenHashMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2BooleanOpenHashMap.java @@ -408,68 +408,78 @@ public boolean computeBoolean(byte key, ByteBooleanUnaryOperator mappingFunction values[index] = newValue; return newValue; } - + @Override - public boolean computeBooleanNonDefault(byte key, ByteBooleanUnaryOperator mappingFunction) { + public boolean computeBooleanIfAbsent(byte key, BytePredicate mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + boolean newValue = mappingFunction.test(key); insert(-index-1, key, newValue); return newValue; } - boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + boolean newValue = values[index]; return newValue; } @Override - public boolean computeBooleanIfAbsent(byte key, BytePredicate mappingFunction) { - Objects.requireNonNull(mappingFunction); + public boolean supplyBooleanIfAbsent(byte key, BooleanSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - boolean newValue = mappingFunction.test(key); + boolean newValue = valueProvider.getAsBoolean(); insert(-index-1, key, newValue); return newValue; } boolean newValue = values[index]; return newValue; } + + @Override + public boolean computeBooleanIfPresent(byte key, ByteBooleanUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public boolean computeBooleanIfAbsentNonDefault(byte key, BytePredicate mappingFunction) { + public boolean computeBooleanNonDefault(byte key, ByteBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - boolean newValue = mappingFunction.test(key); + boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - boolean newValue = values[index]; + boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.test(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public boolean supplyBooleanIfAbsent(byte key, BooleanSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public boolean computeBooleanIfAbsentNonDefault(byte key, BytePredicate mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - boolean newValue = valueProvider.getAsBoolean(); + boolean newValue = mappingFunction.test(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } boolean newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.test(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -492,16 +502,6 @@ public boolean supplyBooleanIfAbsentNonDefault(byte key, BooleanSupplier valuePr return newValue; } - @Override - public boolean computeBooleanIfPresent(byte key, ByteBooleanUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public boolean computeBooleanIfPresentNonDefault(byte key, ByteBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2ByteOpenHashMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2ByteOpenHashMap.java index f69eb936..90ff012a 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2ByteOpenHashMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2ByteOpenHashMap.java @@ -424,68 +424,78 @@ public byte computeByte(byte key, ByteByteUnaryOperator mappingFunction) { values[index] = newValue; return newValue; } - + @Override - public byte computeByteNonDefault(byte key, ByteByteUnaryOperator mappingFunction) { + public byte computeByteIfAbsent(byte key, ByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + byte newValue = mappingFunction.applyAsByte(key); insert(-index-1, key, newValue); return newValue; } - byte newValue = mappingFunction.applyAsByte(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + byte newValue = values[index]; return newValue; } @Override - public byte computeByteIfAbsent(byte key, ByteUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); + public byte supplyByteIfAbsent(byte key, ByteSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = valueProvider.getAsByte(); insert(-index-1, key, newValue); return newValue; } byte newValue = values[index]; return newValue; } + + @Override + public byte computeByteIfPresent(byte key, ByteByteUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + byte newValue = mappingFunction.applyAsByte(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public byte computeByteIfAbsentNonDefault(byte key, ByteUnaryOperator mappingFunction) { + public byte computeByteNonDefault(byte key, ByteByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - byte newValue = values[index]; + byte newValue = mappingFunction.applyAsByte(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsByte(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public byte supplyByteIfAbsent(byte key, ByteSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public byte computeByteIfAbsentNonDefault(byte key, ByteUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - byte newValue = valueProvider.getAsInt(); + byte newValue = mappingFunction.applyAsByte(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } byte newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsByte(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -494,30 +504,20 @@ public byte supplyByteIfAbsentNonDefault(byte key, ByteSupplier valueProvider) { Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - byte newValue = valueProvider.getAsInt(); + byte newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } byte newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public byte computeByteIfPresent(byte key, ByteByteUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - byte newValue = mappingFunction.applyAsByte(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public byte computeByteIfPresentNonDefault(byte key, ByteByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2CharOpenHashMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2CharOpenHashMap.java index 977f6769..bf4e02a2 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2CharOpenHashMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2CharOpenHashMap.java @@ -430,68 +430,78 @@ public char computeChar(byte key, ByteCharUnaryOperator mappingFunction) { values[index] = newValue; return newValue; } - + @Override - public char computeCharNonDefault(byte key, ByteCharUnaryOperator mappingFunction) { + public char computeCharIfAbsent(byte key, Byte2CharFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + char newValue = mappingFunction.applyAsChar(key); insert(-index-1, key, newValue); return newValue; } - char newValue = mappingFunction.applyAsChar(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + char newValue = values[index]; return newValue; } @Override - public char computeCharIfAbsent(byte key, Byte2CharFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public char supplyCharIfAbsent(byte key, CharSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = valueProvider.getAsChar(); insert(-index-1, key, newValue); return newValue; } char newValue = values[index]; return newValue; } + + @Override + public char computeCharIfPresent(byte key, ByteCharUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + char newValue = mappingFunction.applyAsChar(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public char computeCharIfAbsentNonDefault(byte key, Byte2CharFunction mappingFunction) { + public char computeCharNonDefault(byte key, ByteCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - char newValue = values[index]; + char newValue = mappingFunction.applyAsChar(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsChar(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public char supplyCharIfAbsent(byte key, CharSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public char computeCharIfAbsentNonDefault(byte key, Byte2CharFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - char newValue = valueProvider.getAsInt(); + char newValue = mappingFunction.applyAsChar(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } char newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsChar(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -500,30 +510,20 @@ public char supplyCharIfAbsentNonDefault(byte key, CharSupplier valueProvider) { Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - char newValue = valueProvider.getAsInt(); + char newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } char newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public char computeCharIfPresent(byte key, ByteCharUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - char newValue = mappingFunction.applyAsChar(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public char computeCharIfPresentNonDefault(byte key, ByteCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2DoubleOpenHashMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2DoubleOpenHashMap.java index 179487fc..1d8a415b 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2DoubleOpenHashMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2DoubleOpenHashMap.java @@ -430,68 +430,78 @@ public double computeDouble(byte key, ByteDoubleUnaryOperator mappingFunction) { values[index] = newValue; return newValue; } - + @Override - public double computeDoubleNonDefault(byte key, ByteDoubleUnaryOperator mappingFunction) { + public double computeDoubleIfAbsent(byte key, Byte2DoubleFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + double newValue = mappingFunction.applyAsDouble(key); insert(-index-1, key, newValue); return newValue; } - double newValue = mappingFunction.applyAsDouble(key, values[index]); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + double newValue = values[index]; return newValue; } @Override - public double computeDoubleIfAbsent(byte key, Byte2DoubleFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public double supplyDoubleIfAbsent(byte key, DoubleSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = valueProvider.getAsDouble(); insert(-index-1, key, newValue); return newValue; } double newValue = values[index]; return newValue; } + + @Override + public double computeDoubleIfPresent(byte key, ByteDoubleUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + double newValue = mappingFunction.applyAsDouble(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public double computeDoubleIfAbsentNonDefault(byte key, Byte2DoubleFunction mappingFunction) { + public double computeDoubleNonDefault(byte key, ByteDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } - double newValue = values[index]; + double newValue = mappingFunction.applyAsDouble(key, values[index]); if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - newValue = mappingFunction.applyAsDouble(key); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public double supplyDoubleIfAbsent(byte key, DoubleSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public double computeDoubleIfAbsentNonDefault(byte key, Byte2DoubleFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - double newValue = valueProvider.getAsDouble(); + double newValue = mappingFunction.applyAsDouble(key); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } double newValue = values[index]; + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { + newValue = mappingFunction.applyAsDouble(key); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + values[index] = newValue; + } return newValue; } @@ -514,16 +524,6 @@ public double supplyDoubleIfAbsentNonDefault(byte key, DoubleSupplier valueProvi return newValue; } - @Override - public double computeDoubleIfPresent(byte key, ByteDoubleUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - double newValue = mappingFunction.applyAsDouble(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public double computeDoubleIfPresentNonDefault(byte key, ByteDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2FloatOpenHashMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2FloatOpenHashMap.java index 3ec3f763..4aae4401 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2FloatOpenHashMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2FloatOpenHashMap.java @@ -430,68 +430,78 @@ public float computeFloat(byte key, ByteFloatUnaryOperator mappingFunction) { values[index] = newValue; return newValue; } - + @Override - public float computeFloatNonDefault(byte key, ByteFloatUnaryOperator mappingFunction) { + public float computeFloatIfAbsent(byte key, Byte2FloatFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + float newValue = mappingFunction.applyAsFloat(key); insert(-index-1, key, newValue); return newValue; } - float newValue = mappingFunction.applyAsFloat(key, values[index]); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + float newValue = values[index]; return newValue; } @Override - public float computeFloatIfAbsent(byte key, Byte2FloatFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public float supplyFloatIfAbsent(byte key, FloatSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = valueProvider.getAsFloat(); insert(-index-1, key, newValue); return newValue; } float newValue = values[index]; return newValue; } + + @Override + public float computeFloatIfPresent(byte key, ByteFloatUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + float newValue = mappingFunction.applyAsFloat(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public float computeFloatIfAbsentNonDefault(byte key, Byte2FloatFunction mappingFunction) { + public float computeFloatNonDefault(byte key, ByteFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } - float newValue = values[index]; + float newValue = mappingFunction.applyAsFloat(key, values[index]); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - newValue = mappingFunction.applyAsFloat(key); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public float supplyFloatIfAbsent(byte key, FloatSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public float computeFloatIfAbsentNonDefault(byte key, Byte2FloatFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - float newValue = valueProvider.getAsDouble(); + float newValue = mappingFunction.applyAsFloat(key); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } float newValue = values[index]; + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { + newValue = mappingFunction.applyAsFloat(key); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + values[index] = newValue; + } return newValue; } @@ -500,30 +510,20 @@ public float supplyFloatIfAbsentNonDefault(byte key, FloatSupplier valueProvider Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - float newValue = valueProvider.getAsDouble(); + float newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } float newValue = values[index]; if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - newValue = valueProvider.getAsDouble(); + newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; values[index] = newValue; } return newValue; } - @Override - public float computeFloatIfPresent(byte key, ByteFloatUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - float newValue = mappingFunction.applyAsFloat(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public float computeFloatIfPresentNonDefault(byte key, ByteFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2IntOpenHashMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2IntOpenHashMap.java index d0be51a2..42b872aa 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2IntOpenHashMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2IntOpenHashMap.java @@ -430,68 +430,78 @@ public int computeInt(byte key, ByteIntUnaryOperator mappingFunction) { values[index] = newValue; return newValue; } - + @Override - public int computeIntNonDefault(byte key, ByteIntUnaryOperator mappingFunction) { + public int computeIntIfAbsent(byte key, Byte2IntFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + int newValue = mappingFunction.applyAsInt(key); insert(-index-1, key, newValue); return newValue; } - int newValue = mappingFunction.applyAsInt(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + int newValue = values[index]; return newValue; } @Override - public int computeIntIfAbsent(byte key, Byte2IntFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public int supplyIntIfAbsent(byte key, IntSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = valueProvider.getAsInt(); insert(-index-1, key, newValue); return newValue; } int newValue = values[index]; return newValue; } + + @Override + public int computeIntIfPresent(byte key, ByteIntUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + int newValue = mappingFunction.applyAsInt(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public int computeIntIfAbsentNonDefault(byte key, Byte2IntFunction mappingFunction) { + public int computeIntNonDefault(byte key, ByteIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - int newValue = values[index]; + int newValue = mappingFunction.applyAsInt(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsInt(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public int supplyIntIfAbsent(byte key, IntSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public int computeIntIfAbsentNonDefault(byte key, Byte2IntFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - int newValue = valueProvider.getAsInt(); + int newValue = mappingFunction.applyAsInt(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } int newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsInt(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -514,16 +524,6 @@ public int supplyIntIfAbsentNonDefault(byte key, IntSupplier valueProvider) { return newValue; } - @Override - public int computeIntIfPresent(byte key, ByteIntUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - int newValue = mappingFunction.applyAsInt(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public int computeIntIfPresentNonDefault(byte key, ByteIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2LongOpenHashMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2LongOpenHashMap.java index af187491..a3c51427 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2LongOpenHashMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2LongOpenHashMap.java @@ -430,68 +430,78 @@ public long computeLong(byte key, ByteLongUnaryOperator mappingFunction) { values[index] = newValue; return newValue; } - + @Override - public long computeLongNonDefault(byte key, ByteLongUnaryOperator mappingFunction) { + public long computeLongIfAbsent(byte key, Byte2LongFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + long newValue = mappingFunction.applyAsLong(key); insert(-index-1, key, newValue); return newValue; } - long newValue = mappingFunction.applyAsLong(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + long newValue = values[index]; return newValue; } @Override - public long computeLongIfAbsent(byte key, Byte2LongFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public long supplyLongIfAbsent(byte key, LongSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = valueProvider.getAsLong(); insert(-index-1, key, newValue); return newValue; } long newValue = values[index]; return newValue; } + + @Override + public long computeLongIfPresent(byte key, ByteLongUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + long newValue = mappingFunction.applyAsLong(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public long computeLongIfAbsentNonDefault(byte key, Byte2LongFunction mappingFunction) { + public long computeLongNonDefault(byte key, ByteLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - long newValue = values[index]; + long newValue = mappingFunction.applyAsLong(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsLong(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public long supplyLongIfAbsent(byte key, LongSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public long computeLongIfAbsentNonDefault(byte key, Byte2LongFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - long newValue = valueProvider.getAsLong(); + long newValue = mappingFunction.applyAsLong(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } long newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsLong(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -514,16 +524,6 @@ public long supplyLongIfAbsentNonDefault(byte key, LongSupplier valueProvider) { return newValue; } - @Override - public long computeLongIfPresent(byte key, ByteLongUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - long newValue = mappingFunction.applyAsLong(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public long computeLongIfPresentNonDefault(byte key, ByteLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2ObjectOpenHashMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2ObjectOpenHashMap.java index 4770dbbf..2a26e1a0 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2ObjectOpenHashMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2ObjectOpenHashMap.java @@ -401,26 +401,7 @@ public V compute(byte key, ByteObjectUnaryOperator mappingFunction) { values[index] = newValue; return newValue; } - - @Override - public V computeNonDefault(byte key, ByteObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) { - V newValue = mappingFunction.apply(key, getDefaultReturnValue()); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = mappingFunction.apply(key, values[index]); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; - return newValue; - } - + @Override public V computeIfAbsent(byte key, ByteFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -440,25 +421,6 @@ public V computeIfAbsent(byte key, ByteFunction mappingFunction) { return newValue; } - @Override - public V computeIfAbsentNonDefault(byte key, ByteFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) { - V newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = values[index]; - if(Objects.equals(newValue, getDefaultReturnValue())) { - newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - values[index] = newValue; - } - return newValue; - } - @Override public V supplyIfAbsent(byte key, ObjectSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -477,26 +439,7 @@ public V supplyIfAbsent(byte key, ObjectSupplier valueProvider) { } return newValue; } - - @Override - public V supplyIfAbsentNonDefault(byte key, ObjectSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - int index = findIndex(key); - if(index < 0) { - V newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = values[index]; - if(Objects.equals(newValue, getDefaultReturnValue())) { - newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - values[index] = newValue; - } - return newValue; - } - + @Override public V computeIfPresent(byte key, ByteObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -511,20 +454,6 @@ public V computeIfPresent(byte key, ByteObjectUnaryOperator mappingFunction) return newValue; } - @Override - public V computeIfPresentNonDefault(byte key, ByteObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0 || Objects.equals(values[index], getDefaultReturnValue())) return getDefaultReturnValue(); - V newValue = mappingFunction.apply(key, values[index]); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; - return newValue; - } - @Override public V merge(byte key, V value, ObjectObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2ShortOpenHashMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2ShortOpenHashMap.java index fbe3a98b..261a7d09 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2ShortOpenHashMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/hash/Byte2ShortOpenHashMap.java @@ -430,68 +430,78 @@ public short computeShort(byte key, ByteShortUnaryOperator mappingFunction) { values[index] = newValue; return newValue; } - + @Override - public short computeShortNonDefault(byte key, ByteShortUnaryOperator mappingFunction) { + public short computeShortIfAbsent(byte key, Byte2ShortFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + short newValue = mappingFunction.applyAsShort(key); insert(-index-1, key, newValue); return newValue; } - short newValue = mappingFunction.applyAsShort(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + short newValue = values[index]; return newValue; } @Override - public short computeShortIfAbsent(byte key, Byte2ShortFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public short supplyShortIfAbsent(byte key, ShortSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = valueProvider.getAsShort(); insert(-index-1, key, newValue); return newValue; } short newValue = values[index]; return newValue; } + + @Override + public short computeShortIfPresent(byte key, ByteShortUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + short newValue = mappingFunction.applyAsShort(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public short computeShortIfAbsentNonDefault(byte key, Byte2ShortFunction mappingFunction) { + public short computeShortNonDefault(byte key, ByteShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - short newValue = values[index]; + short newValue = mappingFunction.applyAsShort(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsShort(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public short supplyShortIfAbsent(byte key, ShortSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public short computeShortIfAbsentNonDefault(byte key, Byte2ShortFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - short newValue = valueProvider.getAsInt(); + short newValue = mappingFunction.applyAsShort(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } short newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsShort(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -500,30 +510,20 @@ public short supplyShortIfAbsentNonDefault(byte key, ShortSupplier valueProvider Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - short newValue = valueProvider.getAsInt(); + short newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } short newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public short computeShortIfPresent(byte key, ByteShortUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - short newValue = mappingFunction.applyAsShort(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public short computeShortIfPresentNonDefault(byte key, ByteShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/immutable/ImmutableByte2BooleanOpenHashMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/immutable/ImmutableByte2BooleanOpenHashMap.java index eddec887..65c0ff90 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/immutable/ImmutableByte2BooleanOpenHashMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/immutable/ImmutableByte2BooleanOpenHashMap.java @@ -413,20 +413,19 @@ public void forEach(ByteBooleanConsumer action) { @Override public boolean computeBoolean(byte key, ByteBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanNonDefault(byte key, ByteBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean computeBooleanIfAbsent(byte key, BytePredicate mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanIfAbsentNonDefault(byte key, BytePredicate mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean supplyBooleanIfAbsent(byte key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public boolean supplyBooleanIfAbsentNonDefault(byte key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public boolean computeBooleanIfPresent(byte key, ByteBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override + public boolean computeBooleanNonDefault(byte key, ByteBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public boolean computeBooleanIfAbsentNonDefault(byte key, BytePredicate mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public boolean supplyBooleanIfAbsentNonDefault(byte key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } + @Override public boolean computeBooleanIfPresentNonDefault(byte key, ByteBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean mergeBoolean(byte key, boolean value, BooleanBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/immutable/ImmutableByte2ByteOpenHashMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/immutable/ImmutableByte2ByteOpenHashMap.java index 716ca350..efe0c01f 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/immutable/ImmutableByte2ByteOpenHashMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/immutable/ImmutableByte2ByteOpenHashMap.java @@ -409,20 +409,19 @@ public void forEach(ByteByteConsumer action) { @Override public byte computeByte(byte key, ByteByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteNonDefault(byte key, ByteByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte computeByteIfAbsent(byte key, ByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteIfAbsentNonDefault(byte key, ByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte supplyByteIfAbsent(byte key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public byte supplyByteIfAbsentNonDefault(byte key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public byte computeByteIfPresent(byte key, ByteByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override + public byte computeByteNonDefault(byte key, ByteByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public byte computeByteIfAbsentNonDefault(byte key, ByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public byte supplyByteIfAbsentNonDefault(byte key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } + @Override public byte computeByteIfPresentNonDefault(byte key, ByteByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte mergeByte(byte key, byte value, ByteByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/immutable/ImmutableByte2CharOpenHashMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/immutable/ImmutableByte2CharOpenHashMap.java index e2f1b626..779b272c 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/immutable/ImmutableByte2CharOpenHashMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/immutable/ImmutableByte2CharOpenHashMap.java @@ -418,20 +418,19 @@ public void forEach(ByteCharConsumer action) { @Override public char computeChar(byte key, ByteCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharNonDefault(byte key, ByteCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char computeCharIfAbsent(byte key, Byte2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharIfAbsentNonDefault(byte key, Byte2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char supplyCharIfAbsent(byte key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public char supplyCharIfAbsentNonDefault(byte key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public char computeCharIfPresent(byte key, ByteCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override + public char computeCharNonDefault(byte key, ByteCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public char computeCharIfAbsentNonDefault(byte key, Byte2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public char supplyCharIfAbsentNonDefault(byte key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } + @Override public char computeCharIfPresentNonDefault(byte key, ByteCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char mergeChar(byte key, char value, CharCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/immutable/ImmutableByte2DoubleOpenHashMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/immutable/ImmutableByte2DoubleOpenHashMap.java index edcb48e3..cdf07d95 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/immutable/ImmutableByte2DoubleOpenHashMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/immutable/ImmutableByte2DoubleOpenHashMap.java @@ -418,20 +418,19 @@ public void forEach(ByteDoubleConsumer action) { @Override public double computeDouble(byte key, ByteDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleNonDefault(byte key, ByteDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double computeDoubleIfAbsent(byte key, Byte2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleIfAbsentNonDefault(byte key, Byte2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double supplyDoubleIfAbsent(byte key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public double supplyDoubleIfAbsentNonDefault(byte key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public double computeDoubleIfPresent(byte key, ByteDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override + public double computeDoubleNonDefault(byte key, ByteDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public double computeDoubleIfAbsentNonDefault(byte key, Byte2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public double supplyDoubleIfAbsentNonDefault(byte key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } + @Override public double computeDoubleIfPresentNonDefault(byte key, ByteDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double mergeDouble(byte key, double value, DoubleDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/immutable/ImmutableByte2FloatOpenHashMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/immutable/ImmutableByte2FloatOpenHashMap.java index 2b30c54a..af6bb16c 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/immutable/ImmutableByte2FloatOpenHashMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/immutable/ImmutableByte2FloatOpenHashMap.java @@ -418,20 +418,19 @@ public void forEach(ByteFloatConsumer action) { @Override public float computeFloat(byte key, ByteFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatNonDefault(byte key, ByteFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float computeFloatIfAbsent(byte key, Byte2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatIfAbsentNonDefault(byte key, Byte2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float supplyFloatIfAbsent(byte key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public float supplyFloatIfAbsentNonDefault(byte key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public float computeFloatIfPresent(byte key, ByteFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override + public float computeFloatNonDefault(byte key, ByteFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public float computeFloatIfAbsentNonDefault(byte key, Byte2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public float supplyFloatIfAbsentNonDefault(byte key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } + @Override public float computeFloatIfPresentNonDefault(byte key, ByteFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float mergeFloat(byte key, float value, FloatFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/immutable/ImmutableByte2IntOpenHashMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/immutable/ImmutableByte2IntOpenHashMap.java index a8079202..91d46ecf 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/immutable/ImmutableByte2IntOpenHashMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/immutable/ImmutableByte2IntOpenHashMap.java @@ -418,20 +418,19 @@ public void forEach(ByteIntConsumer action) { @Override public int computeInt(byte key, ByteIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntNonDefault(byte key, ByteIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int computeIntIfAbsent(byte key, Byte2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntIfAbsentNonDefault(byte key, Byte2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int supplyIntIfAbsent(byte key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public int supplyIntIfAbsentNonDefault(byte key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public int computeIntIfPresent(byte key, ByteIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override + public int computeIntNonDefault(byte key, ByteIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public int computeIntIfAbsentNonDefault(byte key, Byte2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public int supplyIntIfAbsentNonDefault(byte key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } + @Override public int computeIntIfPresentNonDefault(byte key, ByteIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int mergeInt(byte key, int value, IntIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/immutable/ImmutableByte2LongOpenHashMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/immutable/ImmutableByte2LongOpenHashMap.java index 46284693..d7385a98 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/immutable/ImmutableByte2LongOpenHashMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/immutable/ImmutableByte2LongOpenHashMap.java @@ -418,20 +418,19 @@ public void forEach(ByteLongConsumer action) { @Override public long computeLong(byte key, ByteLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongNonDefault(byte key, ByteLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long computeLongIfAbsent(byte key, Byte2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongIfAbsentNonDefault(byte key, Byte2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long supplyLongIfAbsent(byte key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public long supplyLongIfAbsentNonDefault(byte key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public long computeLongIfPresent(byte key, ByteLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override + public long computeLongNonDefault(byte key, ByteLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public long computeLongIfAbsentNonDefault(byte key, Byte2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public long supplyLongIfAbsentNonDefault(byte key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } + @Override public long computeLongIfPresentNonDefault(byte key, ByteLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long mergeLong(byte key, long value, LongLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/immutable/ImmutableByte2ObjectOpenHashMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/immutable/ImmutableByte2ObjectOpenHashMap.java index 6c92f626..8a655ddf 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/immutable/ImmutableByte2ObjectOpenHashMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/immutable/ImmutableByte2ObjectOpenHashMap.java @@ -397,20 +397,11 @@ public void forEach(ByteObjectConsumer action) { @Override public V compute(byte key, ByteObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeNonDefault(byte key, ByteObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V computeIfAbsent(byte key, ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeIfAbsentNonDefault(byte key, ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V supplyIfAbsent(byte key, ObjectSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public V supplyIfAbsentNonDefault(byte key, ObjectSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public V computeIfPresent(byte key, ByteObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override - public V computeIfPresentNonDefault(byte key, ByteObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V merge(byte key, V value, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/immutable/ImmutableByte2ShortOpenHashMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/immutable/ImmutableByte2ShortOpenHashMap.java index 5bfd8953..b79011b4 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/immutable/ImmutableByte2ShortOpenHashMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/immutable/ImmutableByte2ShortOpenHashMap.java @@ -418,20 +418,19 @@ public void forEach(ByteShortConsumer action) { @Override public short computeShort(byte key, ByteShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortNonDefault(byte key, ByteShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short computeShortIfAbsent(byte key, Byte2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortIfAbsentNonDefault(byte key, Byte2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short supplyShortIfAbsent(byte key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public short supplyShortIfAbsentNonDefault(byte key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public short computeShortIfPresent(byte key, ByteShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override + public short computeShortNonDefault(byte key, ByteShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public short computeShortIfAbsentNonDefault(byte key, Byte2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public short supplyShortIfAbsentNonDefault(byte key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } + @Override public short computeShortIfPresentNonDefault(byte key, ByteShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short mergeShort(byte key, short value, ShortShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/misc/Byte2BooleanArrayMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/misc/Byte2BooleanArrayMap.java index bbfb3504..3e4e630d 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/misc/Byte2BooleanArrayMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/misc/Byte2BooleanArrayMap.java @@ -420,66 +420,76 @@ public boolean computeBoolean(byte key, ByteBooleanUnaryOperator mappingFunction } @Override - public boolean computeBooleanNonDefault(byte key, ByteBooleanUnaryOperator mappingFunction) { + public boolean computeBooleanIfAbsent(byte key, BytePredicate mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + boolean newValue = mappingFunction.test(key); insertIndex(size++, key, newValue); return newValue; } - boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + boolean newValue = values[index]; return newValue; } - + @Override - public boolean computeBooleanIfAbsent(byte key, BytePredicate mappingFunction) { - Objects.requireNonNull(mappingFunction); + public boolean supplyBooleanIfAbsent(byte key, BooleanSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - boolean newValue = mappingFunction.test(key); + boolean newValue = valueProvider.getAsBoolean(); insertIndex(size++, key, newValue); return newValue; } boolean newValue = values[index]; return newValue; } + + @Override + public boolean computeBooleanIfPresent(byte key, ByteBooleanUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index == -1) return getDefaultReturnValue(); + boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public boolean computeBooleanIfAbsentNonDefault(byte key, BytePredicate mappingFunction) { + public boolean computeBooleanNonDefault(byte key, ByteBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - boolean newValue = mappingFunction.test(key); + boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } - boolean newValue = values[index]; + boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.test(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public boolean supplyBooleanIfAbsent(byte key, BooleanSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public boolean computeBooleanIfAbsentNonDefault(byte key, BytePredicate mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - boolean newValue = valueProvider.getAsBoolean(); + boolean newValue = mappingFunction.test(key); + if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } boolean newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.test(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -502,16 +512,6 @@ public boolean supplyBooleanIfAbsentNonDefault(byte key, BooleanSupplier valuePr return newValue; } - @Override - public boolean computeBooleanIfPresent(byte key, ByteBooleanUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) return getDefaultReturnValue(); - boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public boolean computeBooleanIfPresentNonDefault(byte key, ByteBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/misc/Byte2ByteArrayMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/misc/Byte2ByteArrayMap.java index 5c9cc355..de0e62f3 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/misc/Byte2ByteArrayMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/misc/Byte2ByteArrayMap.java @@ -436,66 +436,76 @@ public byte computeByte(byte key, ByteByteUnaryOperator mappingFunction) { } @Override - public byte computeByteNonDefault(byte key, ByteByteUnaryOperator mappingFunction) { + public byte computeByteIfAbsent(byte key, ByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + byte newValue = mappingFunction.applyAsByte(key); insertIndex(size++, key, newValue); return newValue; } - byte newValue = mappingFunction.applyAsByte(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + byte newValue = values[index]; return newValue; } - + @Override - public byte computeByteIfAbsent(byte key, ByteUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); + public byte supplyByteIfAbsent(byte key, ByteSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = valueProvider.getAsByte(); insertIndex(size++, key, newValue); return newValue; } byte newValue = values[index]; return newValue; } + + @Override + public byte computeByteIfPresent(byte key, ByteByteUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index == -1) return getDefaultReturnValue(); + byte newValue = mappingFunction.applyAsByte(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public byte computeByteIfAbsentNonDefault(byte key, ByteUnaryOperator mappingFunction) { + public byte computeByteNonDefault(byte key, ByteByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } - byte newValue = values[index]; + byte newValue = mappingFunction.applyAsByte(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsByte(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public byte supplyByteIfAbsent(byte key, ByteSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public byte computeByteIfAbsentNonDefault(byte key, ByteUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - byte newValue = valueProvider.getAsInt(); + byte newValue = mappingFunction.applyAsByte(key); + if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } byte newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsByte(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -504,30 +514,20 @@ public byte supplyByteIfAbsentNonDefault(byte key, ByteSupplier valueProvider) { Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - byte newValue = valueProvider.getAsInt(); + byte newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } byte newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public byte computeByteIfPresent(byte key, ByteByteUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) return getDefaultReturnValue(); - byte newValue = mappingFunction.applyAsByte(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public byte computeByteIfPresentNonDefault(byte key, ByteByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/misc/Byte2CharArrayMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/misc/Byte2CharArrayMap.java index a1228f93..bfecf909 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/misc/Byte2CharArrayMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/misc/Byte2CharArrayMap.java @@ -443,66 +443,76 @@ public char computeChar(byte key, ByteCharUnaryOperator mappingFunction) { } @Override - public char computeCharNonDefault(byte key, ByteCharUnaryOperator mappingFunction) { + public char computeCharIfAbsent(byte key, Byte2CharFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + char newValue = mappingFunction.applyAsChar(key); insertIndex(size++, key, newValue); return newValue; } - char newValue = mappingFunction.applyAsChar(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + char newValue = values[index]; return newValue; } - + @Override - public char computeCharIfAbsent(byte key, Byte2CharFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public char supplyCharIfAbsent(byte key, CharSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = valueProvider.getAsChar(); insertIndex(size++, key, newValue); return newValue; } char newValue = values[index]; return newValue; } + + @Override + public char computeCharIfPresent(byte key, ByteCharUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index == -1) return getDefaultReturnValue(); + char newValue = mappingFunction.applyAsChar(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public char computeCharIfAbsentNonDefault(byte key, Byte2CharFunction mappingFunction) { + public char computeCharNonDefault(byte key, ByteCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } - char newValue = values[index]; + char newValue = mappingFunction.applyAsChar(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsChar(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public char supplyCharIfAbsent(byte key, CharSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public char computeCharIfAbsentNonDefault(byte key, Byte2CharFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - char newValue = valueProvider.getAsInt(); + char newValue = mappingFunction.applyAsChar(key); + if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } char newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsChar(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -511,30 +521,20 @@ public char supplyCharIfAbsentNonDefault(byte key, CharSupplier valueProvider) { Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - char newValue = valueProvider.getAsInt(); + char newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } char newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public char computeCharIfPresent(byte key, ByteCharUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) return getDefaultReturnValue(); - char newValue = mappingFunction.applyAsChar(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public char computeCharIfPresentNonDefault(byte key, ByteCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/misc/Byte2DoubleArrayMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/misc/Byte2DoubleArrayMap.java index ba3549f1..87e4db59 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/misc/Byte2DoubleArrayMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/misc/Byte2DoubleArrayMap.java @@ -443,66 +443,76 @@ public double computeDouble(byte key, ByteDoubleUnaryOperator mappingFunction) { } @Override - public double computeDoubleNonDefault(byte key, ByteDoubleUnaryOperator mappingFunction) { + public double computeDoubleIfAbsent(byte key, Byte2DoubleFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + double newValue = mappingFunction.applyAsDouble(key); insertIndex(size++, key, newValue); return newValue; } - double newValue = mappingFunction.applyAsDouble(key, values[index]); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + double newValue = values[index]; return newValue; } - + @Override - public double computeDoubleIfAbsent(byte key, Byte2DoubleFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public double supplyDoubleIfAbsent(byte key, DoubleSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = valueProvider.getAsDouble(); insertIndex(size++, key, newValue); return newValue; } double newValue = values[index]; return newValue; } + + @Override + public double computeDoubleIfPresent(byte key, ByteDoubleUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index == -1) return getDefaultReturnValue(); + double newValue = mappingFunction.applyAsDouble(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public double computeDoubleIfAbsentNonDefault(byte key, Byte2DoubleFunction mappingFunction) { + public double computeDoubleNonDefault(byte key, ByteDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; insertIndex(size++, key, newValue); return newValue; } - double newValue = values[index]; + double newValue = mappingFunction.applyAsDouble(key, values[index]); if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - newValue = mappingFunction.applyAsDouble(key); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public double supplyDoubleIfAbsent(byte key, DoubleSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public double computeDoubleIfAbsentNonDefault(byte key, Byte2DoubleFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - double newValue = valueProvider.getAsDouble(); + double newValue = mappingFunction.applyAsDouble(key); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; insertIndex(size++, key, newValue); return newValue; } double newValue = values[index]; + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { + newValue = mappingFunction.applyAsDouble(key); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + values[index] = newValue; + } return newValue; } @@ -525,16 +535,6 @@ public double supplyDoubleIfAbsentNonDefault(byte key, DoubleSupplier valueProvi return newValue; } - @Override - public double computeDoubleIfPresent(byte key, ByteDoubleUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) return getDefaultReturnValue(); - double newValue = mappingFunction.applyAsDouble(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public double computeDoubleIfPresentNonDefault(byte key, ByteDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/misc/Byte2FloatArrayMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/misc/Byte2FloatArrayMap.java index 0ebe48bd..8ca091e3 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/misc/Byte2FloatArrayMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/misc/Byte2FloatArrayMap.java @@ -443,66 +443,76 @@ public float computeFloat(byte key, ByteFloatUnaryOperator mappingFunction) { } @Override - public float computeFloatNonDefault(byte key, ByteFloatUnaryOperator mappingFunction) { + public float computeFloatIfAbsent(byte key, Byte2FloatFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + float newValue = mappingFunction.applyAsFloat(key); insertIndex(size++, key, newValue); return newValue; } - float newValue = mappingFunction.applyAsFloat(key, values[index]); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + float newValue = values[index]; return newValue; } - + @Override - public float computeFloatIfAbsent(byte key, Byte2FloatFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public float supplyFloatIfAbsent(byte key, FloatSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = valueProvider.getAsFloat(); insertIndex(size++, key, newValue); return newValue; } float newValue = values[index]; return newValue; } + + @Override + public float computeFloatIfPresent(byte key, ByteFloatUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index == -1) return getDefaultReturnValue(); + float newValue = mappingFunction.applyAsFloat(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public float computeFloatIfAbsentNonDefault(byte key, Byte2FloatFunction mappingFunction) { + public float computeFloatNonDefault(byte key, ByteFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insertIndex(size++, key, newValue); return newValue; } - float newValue = values[index]; + float newValue = mappingFunction.applyAsFloat(key, values[index]); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - newValue = mappingFunction.applyAsFloat(key); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public float supplyFloatIfAbsent(byte key, FloatSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public float computeFloatIfAbsentNonDefault(byte key, Byte2FloatFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - float newValue = valueProvider.getAsDouble(); + float newValue = mappingFunction.applyAsFloat(key); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insertIndex(size++, key, newValue); return newValue; } float newValue = values[index]; + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { + newValue = mappingFunction.applyAsFloat(key); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + values[index] = newValue; + } return newValue; } @@ -511,30 +521,20 @@ public float supplyFloatIfAbsentNonDefault(byte key, FloatSupplier valueProvider Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - float newValue = valueProvider.getAsDouble(); + float newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insertIndex(size++, key, newValue); return newValue; } float newValue = values[index]; if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - newValue = valueProvider.getAsDouble(); + newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; values[index] = newValue; } return newValue; } - @Override - public float computeFloatIfPresent(byte key, ByteFloatUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) return getDefaultReturnValue(); - float newValue = mappingFunction.applyAsFloat(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public float computeFloatIfPresentNonDefault(byte key, ByteFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/misc/Byte2IntArrayMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/misc/Byte2IntArrayMap.java index b0320eca..2ab28490 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/misc/Byte2IntArrayMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/misc/Byte2IntArrayMap.java @@ -443,66 +443,76 @@ public int computeInt(byte key, ByteIntUnaryOperator mappingFunction) { } @Override - public int computeIntNonDefault(byte key, ByteIntUnaryOperator mappingFunction) { + public int computeIntIfAbsent(byte key, Byte2IntFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + int newValue = mappingFunction.applyAsInt(key); insertIndex(size++, key, newValue); return newValue; } - int newValue = mappingFunction.applyAsInt(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + int newValue = values[index]; return newValue; } - + @Override - public int computeIntIfAbsent(byte key, Byte2IntFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public int supplyIntIfAbsent(byte key, IntSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = valueProvider.getAsInt(); insertIndex(size++, key, newValue); return newValue; } int newValue = values[index]; return newValue; } + + @Override + public int computeIntIfPresent(byte key, ByteIntUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index == -1) return getDefaultReturnValue(); + int newValue = mappingFunction.applyAsInt(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public int computeIntIfAbsentNonDefault(byte key, Byte2IntFunction mappingFunction) { + public int computeIntNonDefault(byte key, ByteIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } - int newValue = values[index]; + int newValue = mappingFunction.applyAsInt(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsInt(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public int supplyIntIfAbsent(byte key, IntSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public int computeIntIfAbsentNonDefault(byte key, Byte2IntFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - int newValue = valueProvider.getAsInt(); + int newValue = mappingFunction.applyAsInt(key); + if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } int newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsInt(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -525,16 +535,6 @@ public int supplyIntIfAbsentNonDefault(byte key, IntSupplier valueProvider) { return newValue; } - @Override - public int computeIntIfPresent(byte key, ByteIntUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) return getDefaultReturnValue(); - int newValue = mappingFunction.applyAsInt(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public int computeIntIfPresentNonDefault(byte key, ByteIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/misc/Byte2LongArrayMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/misc/Byte2LongArrayMap.java index e52bb50f..390700b0 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/misc/Byte2LongArrayMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/misc/Byte2LongArrayMap.java @@ -443,66 +443,76 @@ public long computeLong(byte key, ByteLongUnaryOperator mappingFunction) { } @Override - public long computeLongNonDefault(byte key, ByteLongUnaryOperator mappingFunction) { + public long computeLongIfAbsent(byte key, Byte2LongFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + long newValue = mappingFunction.applyAsLong(key); insertIndex(size++, key, newValue); return newValue; } - long newValue = mappingFunction.applyAsLong(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + long newValue = values[index]; return newValue; } - + @Override - public long computeLongIfAbsent(byte key, Byte2LongFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public long supplyLongIfAbsent(byte key, LongSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = valueProvider.getAsLong(); insertIndex(size++, key, newValue); return newValue; } long newValue = values[index]; return newValue; } + + @Override + public long computeLongIfPresent(byte key, ByteLongUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index == -1) return getDefaultReturnValue(); + long newValue = mappingFunction.applyAsLong(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public long computeLongIfAbsentNonDefault(byte key, Byte2LongFunction mappingFunction) { + public long computeLongNonDefault(byte key, ByteLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } - long newValue = values[index]; + long newValue = mappingFunction.applyAsLong(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsLong(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public long supplyLongIfAbsent(byte key, LongSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public long computeLongIfAbsentNonDefault(byte key, Byte2LongFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - long newValue = valueProvider.getAsLong(); + long newValue = mappingFunction.applyAsLong(key); + if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } long newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsLong(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -525,16 +535,6 @@ public long supplyLongIfAbsentNonDefault(byte key, LongSupplier valueProvider) { return newValue; } - @Override - public long computeLongIfPresent(byte key, ByteLongUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) return getDefaultReturnValue(); - long newValue = mappingFunction.applyAsLong(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public long computeLongIfPresentNonDefault(byte key, ByteLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/misc/Byte2ObjectArrayMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/misc/Byte2ObjectArrayMap.java index 0d4eea7f..a4d6a6ac 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/misc/Byte2ObjectArrayMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/misc/Byte2ObjectArrayMap.java @@ -415,25 +415,6 @@ public V compute(byte key, ByteObjectUnaryOperator mappingFunction) { return newValue; } - @Override - public V computeNonDefault(byte key, ByteObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) { - V newValue = mappingFunction.apply(key, getDefaultReturnValue()); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insertIndex(size++, key, newValue); - return newValue; - } - V newValue = mappingFunction.apply(key, values[index]); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; - return newValue; - } - @Override public V computeIfAbsent(byte key, ByteFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -452,26 +433,7 @@ public V computeIfAbsent(byte key, ByteFunction mappingFunction) { } return newValue; } - - @Override - public V computeIfAbsentNonDefault(byte key, ByteFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) { - V newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insertIndex(size++, key, newValue); - return newValue; - } - V newValue = values[index]; - if(Objects.equals(newValue, getDefaultReturnValue())) { - newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - values[index] = newValue; - } - return newValue; - } - + @Override public V supplyIfAbsent(byte key, ObjectSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -490,26 +452,7 @@ public V supplyIfAbsent(byte key, ObjectSupplier valueProvider) { } return newValue; } - - @Override - public V supplyIfAbsentNonDefault(byte key, ObjectSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - int index = findIndex(key); - if(index == -1) { - V newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insertIndex(size++, key, newValue); - return newValue; - } - V newValue = values[index]; - if(Objects.equals(newValue, getDefaultReturnValue())) { - newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - values[index] = newValue; - } - return newValue; - } - + @Override public V computeIfPresent(byte key, ByteObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -524,20 +467,6 @@ public V computeIfPresent(byte key, ByteObjectUnaryOperator mappingFunction) return newValue; } - @Override - public V computeIfPresentNonDefault(byte key, ByteObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1 || Objects.equals(values[index], getDefaultReturnValue())) return getDefaultReturnValue(); - V newValue = mappingFunction.apply(key, values[index]); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; - return newValue; - } - @Override public V merge(byte key, V value, ObjectObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/misc/Byte2ShortArrayMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/misc/Byte2ShortArrayMap.java index adcf2916..3ccd8ab2 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/misc/Byte2ShortArrayMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/misc/Byte2ShortArrayMap.java @@ -443,66 +443,76 @@ public short computeShort(byte key, ByteShortUnaryOperator mappingFunction) { } @Override - public short computeShortNonDefault(byte key, ByteShortUnaryOperator mappingFunction) { + public short computeShortIfAbsent(byte key, Byte2ShortFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + short newValue = mappingFunction.applyAsShort(key); insertIndex(size++, key, newValue); return newValue; } - short newValue = mappingFunction.applyAsShort(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + short newValue = values[index]; return newValue; } - + @Override - public short computeShortIfAbsent(byte key, Byte2ShortFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public short supplyShortIfAbsent(byte key, ShortSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = valueProvider.getAsShort(); insertIndex(size++, key, newValue); return newValue; } short newValue = values[index]; return newValue; } + + @Override + public short computeShortIfPresent(byte key, ByteShortUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index == -1) return getDefaultReturnValue(); + short newValue = mappingFunction.applyAsShort(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public short computeShortIfAbsentNonDefault(byte key, Byte2ShortFunction mappingFunction) { + public short computeShortNonDefault(byte key, ByteShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } - short newValue = values[index]; + short newValue = mappingFunction.applyAsShort(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsShort(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public short supplyShortIfAbsent(byte key, ShortSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public short computeShortIfAbsentNonDefault(byte key, Byte2ShortFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - short newValue = valueProvider.getAsInt(); + short newValue = mappingFunction.applyAsShort(key); + if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } short newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsShort(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -511,30 +521,20 @@ public short supplyShortIfAbsentNonDefault(byte key, ShortSupplier valueProvider Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - short newValue = valueProvider.getAsInt(); + short newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } short newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public short computeShortIfPresent(byte key, ByteShortUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) return getDefaultReturnValue(); - short newValue = mappingFunction.applyAsShort(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public short computeShortIfPresentNonDefault(byte key, ByteShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2BooleanAVLTreeMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2BooleanAVLTreeMap.java index 9b3a2564..5e0621d0 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2BooleanAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2BooleanAVLTreeMap.java @@ -396,34 +396,56 @@ public boolean computeBoolean(byte key, ByteBooleanUnaryOperator mappingFunction } @Override - public boolean computeBooleanNonDefault(byte key, ByteBooleanUnaryOperator mappingFunction) { + public boolean computeBooleanIfAbsent(byte key, BytePredicate mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + boolean newValue = mappingFunction.test(key); put(key, newValue); return newValue; } - boolean newValue = mappingFunction.applyAsBoolean(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public boolean supplyBooleanIfAbsent(byte key, BooleanSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + boolean newValue = valueProvider.getAsBoolean(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public boolean computeBooleanIfPresent(byte key, ByteBooleanUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + boolean newValue = mappingFunction.applyAsBoolean(key, entry.value); entry.value = newValue; return newValue; } @Override - public boolean computeBooleanIfAbsent(byte key, BytePredicate mappingFunction) { + public boolean computeBooleanNonDefault(byte key, ByteBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - boolean newValue = mappingFunction.test(key); + boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + boolean newValue = mappingFunction.applyAsBoolean(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -444,18 +466,6 @@ public boolean computeBooleanIfAbsentNonDefault(byte key, BytePredicate mappingF return entry.value; } - @Override - public boolean supplyBooleanIfAbsent(byte key, BooleanSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - boolean newValue = valueProvider.getAsBoolean(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public boolean supplyBooleanIfAbsentNonDefault(byte key, BooleanSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -474,16 +484,6 @@ public boolean supplyBooleanIfAbsentNonDefault(byte key, BooleanSupplier valuePr return entry.value; } - @Override - public boolean computeBooleanIfPresent(byte key, ByteBooleanUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - boolean newValue = mappingFunction.applyAsBoolean(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public boolean computeBooleanIfPresentNonDefault(byte key, ByteBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1487,14 +1487,9 @@ public boolean computeBooleanIfPresent(byte key, ByteBooleanUnaryOperator mappin Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - boolean newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2BooleanRBTreeMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2BooleanRBTreeMap.java index 43e7c629..5e9799e4 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2BooleanRBTreeMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2BooleanRBTreeMap.java @@ -395,34 +395,56 @@ public boolean computeBoolean(byte key, ByteBooleanUnaryOperator mappingFunction } @Override - public boolean computeBooleanNonDefault(byte key, ByteBooleanUnaryOperator mappingFunction) { + public boolean computeBooleanIfAbsent(byte key, BytePredicate mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + boolean newValue = mappingFunction.test(key); put(key, newValue); return newValue; } - boolean newValue = mappingFunction.applyAsBoolean(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public boolean supplyBooleanIfAbsent(byte key, BooleanSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + boolean newValue = valueProvider.getAsBoolean(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public boolean computeBooleanIfPresent(byte key, ByteBooleanUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + boolean newValue = mappingFunction.applyAsBoolean(key, entry.value); entry.value = newValue; return newValue; } @Override - public boolean computeBooleanIfAbsent(byte key, BytePredicate mappingFunction) { + public boolean computeBooleanNonDefault(byte key, ByteBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - boolean newValue = mappingFunction.test(key); + boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + boolean newValue = mappingFunction.applyAsBoolean(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -443,18 +465,6 @@ public boolean computeBooleanIfAbsentNonDefault(byte key, BytePredicate mappingF return entry.value; } - @Override - public boolean supplyBooleanIfAbsent(byte key, BooleanSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - boolean newValue = valueProvider.getAsBoolean(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public boolean supplyBooleanIfAbsentNonDefault(byte key, BooleanSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -473,16 +483,6 @@ public boolean supplyBooleanIfAbsentNonDefault(byte key, BooleanSupplier valuePr return entry.value; } - @Override - public boolean computeBooleanIfPresent(byte key, ByteBooleanUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - boolean newValue = mappingFunction.applyAsBoolean(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public boolean computeBooleanIfPresentNonDefault(byte key, ByteBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1550,14 +1550,9 @@ public boolean computeBooleanIfPresent(byte key, ByteBooleanUnaryOperator mappin Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - boolean newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2ByteAVLTreeMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2ByteAVLTreeMap.java index f732da1f..b4fd9985 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2ByteAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2ByteAVLTreeMap.java @@ -447,34 +447,56 @@ public byte computeByte(byte key, ByteByteUnaryOperator mappingFunction) { } @Override - public byte computeByteNonDefault(byte key, ByteByteUnaryOperator mappingFunction) { + public byte computeByteIfAbsent(byte key, ByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + byte newValue = mappingFunction.applyAsByte(key); put(key, newValue); return newValue; } - byte newValue = mappingFunction.applyAsByte(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public byte supplyByteIfAbsent(byte key, ByteSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + byte newValue = valueProvider.getAsByte(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public byte computeByteIfPresent(byte key, ByteByteUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + byte newValue = mappingFunction.applyAsByte(key, entry.value); entry.value = newValue; return newValue; } @Override - public byte computeByteIfAbsent(byte key, ByteUnaryOperator mappingFunction) { + public byte computeByteNonDefault(byte key, ByteByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + byte newValue = mappingFunction.applyAsByte(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -495,46 +517,24 @@ public byte computeByteIfAbsentNonDefault(byte key, ByteUnaryOperator mappingFun return entry.value; } - @Override - public byte supplyByteIfAbsent(byte key, ByteSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - byte newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public byte supplyByteIfAbsentNonDefault(byte key, ByteSupplier valueProvider) { Objects.requireNonNull(valueProvider); Node entry = findNode(key); if(entry == null) { - byte newValue = valueProvider.getAsInt(); + byte newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } if(entry.value == getDefaultReturnValue()) { - byte newValue = valueProvider.getAsInt(); + byte newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; entry.value = newValue; } return entry.value; } - @Override - public byte computeByteIfPresent(byte key, ByteByteUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - byte newValue = mappingFunction.applyAsByte(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public byte computeByteIfPresentNonDefault(byte key, ByteByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1550,14 +1550,9 @@ public byte computeByteIfPresent(byte key, ByteByteUnaryOperator mappingFunction Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - byte newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2ByteRBTreeMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2ByteRBTreeMap.java index 608f3ed6..309d5acb 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2ByteRBTreeMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2ByteRBTreeMap.java @@ -446,34 +446,56 @@ public byte computeByte(byte key, ByteByteUnaryOperator mappingFunction) { } @Override - public byte computeByteNonDefault(byte key, ByteByteUnaryOperator mappingFunction) { + public byte computeByteIfAbsent(byte key, ByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + byte newValue = mappingFunction.applyAsByte(key); put(key, newValue); return newValue; } - byte newValue = mappingFunction.applyAsByte(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public byte supplyByteIfAbsent(byte key, ByteSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + byte newValue = valueProvider.getAsByte(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public byte computeByteIfPresent(byte key, ByteByteUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + byte newValue = mappingFunction.applyAsByte(key, entry.value); entry.value = newValue; return newValue; } @Override - public byte computeByteIfAbsent(byte key, ByteUnaryOperator mappingFunction) { + public byte computeByteNonDefault(byte key, ByteByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + byte newValue = mappingFunction.applyAsByte(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -494,46 +516,24 @@ public byte computeByteIfAbsentNonDefault(byte key, ByteUnaryOperator mappingFun return entry.value; } - @Override - public byte supplyByteIfAbsent(byte key, ByteSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - byte newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public byte supplyByteIfAbsentNonDefault(byte key, ByteSupplier valueProvider) { Objects.requireNonNull(valueProvider); Node entry = findNode(key); if(entry == null) { - byte newValue = valueProvider.getAsInt(); + byte newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } if(entry.value == getDefaultReturnValue()) { - byte newValue = valueProvider.getAsInt(); + byte newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; entry.value = newValue; } return entry.value; } - @Override - public byte computeByteIfPresent(byte key, ByteByteUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - byte newValue = mappingFunction.applyAsByte(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public byte computeByteIfPresentNonDefault(byte key, ByteByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1613,14 +1613,9 @@ public byte computeByteIfPresent(byte key, ByteByteUnaryOperator mappingFunction Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - byte newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2CharAVLTreeMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2CharAVLTreeMap.java index 84846f68..f7c4e657 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2CharAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2CharAVLTreeMap.java @@ -455,34 +455,56 @@ public char computeChar(byte key, ByteCharUnaryOperator mappingFunction) { } @Override - public char computeCharNonDefault(byte key, ByteCharUnaryOperator mappingFunction) { + public char computeCharIfAbsent(byte key, Byte2CharFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + char newValue = mappingFunction.applyAsChar(key); put(key, newValue); return newValue; } - char newValue = mappingFunction.applyAsChar(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public char supplyCharIfAbsent(byte key, CharSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + char newValue = valueProvider.getAsChar(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public char computeCharIfPresent(byte key, ByteCharUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + char newValue = mappingFunction.applyAsChar(key, entry.value); entry.value = newValue; return newValue; } @Override - public char computeCharIfAbsent(byte key, Byte2CharFunction mappingFunction) { + public char computeCharNonDefault(byte key, ByteCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + char newValue = mappingFunction.applyAsChar(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -503,46 +525,24 @@ public char computeCharIfAbsentNonDefault(byte key, Byte2CharFunction mappingFun return entry.value; } - @Override - public char supplyCharIfAbsent(byte key, CharSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - char newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public char supplyCharIfAbsentNonDefault(byte key, CharSupplier valueProvider) { Objects.requireNonNull(valueProvider); Node entry = findNode(key); if(entry == null) { - char newValue = valueProvider.getAsInt(); + char newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } if(entry.value == getDefaultReturnValue()) { - char newValue = valueProvider.getAsInt(); + char newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; entry.value = newValue; } return entry.value; } - @Override - public char computeCharIfPresent(byte key, ByteCharUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - char newValue = mappingFunction.applyAsChar(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public char computeCharIfPresentNonDefault(byte key, ByteCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1558,14 +1558,9 @@ public char computeCharIfPresent(byte key, ByteCharUnaryOperator mappingFunction Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - char newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2CharRBTreeMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2CharRBTreeMap.java index 280ebc2f..11f0caa3 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2CharRBTreeMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2CharRBTreeMap.java @@ -454,34 +454,56 @@ public char computeChar(byte key, ByteCharUnaryOperator mappingFunction) { } @Override - public char computeCharNonDefault(byte key, ByteCharUnaryOperator mappingFunction) { + public char computeCharIfAbsent(byte key, Byte2CharFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + char newValue = mappingFunction.applyAsChar(key); put(key, newValue); return newValue; } - char newValue = mappingFunction.applyAsChar(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public char supplyCharIfAbsent(byte key, CharSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + char newValue = valueProvider.getAsChar(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public char computeCharIfPresent(byte key, ByteCharUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + char newValue = mappingFunction.applyAsChar(key, entry.value); entry.value = newValue; return newValue; } @Override - public char computeCharIfAbsent(byte key, Byte2CharFunction mappingFunction) { + public char computeCharNonDefault(byte key, ByteCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + char newValue = mappingFunction.applyAsChar(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -502,46 +524,24 @@ public char computeCharIfAbsentNonDefault(byte key, Byte2CharFunction mappingFun return entry.value; } - @Override - public char supplyCharIfAbsent(byte key, CharSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - char newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public char supplyCharIfAbsentNonDefault(byte key, CharSupplier valueProvider) { Objects.requireNonNull(valueProvider); Node entry = findNode(key); if(entry == null) { - char newValue = valueProvider.getAsInt(); + char newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } if(entry.value == getDefaultReturnValue()) { - char newValue = valueProvider.getAsInt(); + char newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; entry.value = newValue; } return entry.value; } - @Override - public char computeCharIfPresent(byte key, ByteCharUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - char newValue = mappingFunction.applyAsChar(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public char computeCharIfPresentNonDefault(byte key, ByteCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1621,14 +1621,9 @@ public char computeCharIfPresent(byte key, ByteCharUnaryOperator mappingFunction Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - char newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2DoubleAVLTreeMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2DoubleAVLTreeMap.java index 36ad54c0..438ec1f4 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2DoubleAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2DoubleAVLTreeMap.java @@ -455,34 +455,56 @@ public double computeDouble(byte key, ByteDoubleUnaryOperator mappingFunction) { } @Override - public double computeDoubleNonDefault(byte key, ByteDoubleUnaryOperator mappingFunction) { + public double computeDoubleIfAbsent(byte key, Byte2DoubleFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + double newValue = mappingFunction.applyAsDouble(key); put(key, newValue); return newValue; } - double newValue = mappingFunction.applyAsDouble(key, entry.value); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - removeNode(entry); + return entry.value; + } + + @Override + public double supplyDoubleIfAbsent(byte key, DoubleSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + double newValue = valueProvider.getAsDouble(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public double computeDoubleIfPresent(byte key, ByteDoubleUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + double newValue = mappingFunction.applyAsDouble(key, entry.value); entry.value = newValue; return newValue; } @Override - public double computeDoubleIfAbsent(byte key, Byte2DoubleFunction mappingFunction) { + public double computeDoubleNonDefault(byte key, ByteDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; put(key, newValue); return newValue; } - return entry.value; + double newValue = mappingFunction.applyAsDouble(key, entry.value); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -503,18 +525,6 @@ public double computeDoubleIfAbsentNonDefault(byte key, Byte2DoubleFunction mapp return entry.value; } - @Override - public double supplyDoubleIfAbsent(byte key, DoubleSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - double newValue = valueProvider.getAsDouble(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public double supplyDoubleIfAbsentNonDefault(byte key, DoubleSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -533,16 +543,6 @@ public double supplyDoubleIfAbsentNonDefault(byte key, DoubleSupplier valueProvi return entry.value; } - @Override - public double computeDoubleIfPresent(byte key, ByteDoubleUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - double newValue = mappingFunction.applyAsDouble(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public double computeDoubleIfPresentNonDefault(byte key, ByteDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1558,14 +1558,9 @@ public double computeDoubleIfPresent(byte key, ByteDoubleUnaryOperator mappingFu Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || Double.doubleToLongBits(entry.value) == Double.doubleToLongBits(getDefaultReturnValue())) return getDefaultReturnValue(); - double newValue = mappingFunction.apply(key, entry.value); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2DoubleRBTreeMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2DoubleRBTreeMap.java index f2b41130..c72f3a35 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2DoubleRBTreeMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2DoubleRBTreeMap.java @@ -454,34 +454,56 @@ public double computeDouble(byte key, ByteDoubleUnaryOperator mappingFunction) { } @Override - public double computeDoubleNonDefault(byte key, ByteDoubleUnaryOperator mappingFunction) { + public double computeDoubleIfAbsent(byte key, Byte2DoubleFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + double newValue = mappingFunction.applyAsDouble(key); put(key, newValue); return newValue; } - double newValue = mappingFunction.applyAsDouble(key, entry.value); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - removeNode(entry); + return entry.value; + } + + @Override + public double supplyDoubleIfAbsent(byte key, DoubleSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + double newValue = valueProvider.getAsDouble(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public double computeDoubleIfPresent(byte key, ByteDoubleUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + double newValue = mappingFunction.applyAsDouble(key, entry.value); entry.value = newValue; return newValue; } @Override - public double computeDoubleIfAbsent(byte key, Byte2DoubleFunction mappingFunction) { + public double computeDoubleNonDefault(byte key, ByteDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; put(key, newValue); return newValue; } - return entry.value; + double newValue = mappingFunction.applyAsDouble(key, entry.value); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -502,18 +524,6 @@ public double computeDoubleIfAbsentNonDefault(byte key, Byte2DoubleFunction mapp return entry.value; } - @Override - public double supplyDoubleIfAbsent(byte key, DoubleSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - double newValue = valueProvider.getAsDouble(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public double supplyDoubleIfAbsentNonDefault(byte key, DoubleSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -532,16 +542,6 @@ public double supplyDoubleIfAbsentNonDefault(byte key, DoubleSupplier valueProvi return entry.value; } - @Override - public double computeDoubleIfPresent(byte key, ByteDoubleUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - double newValue = mappingFunction.applyAsDouble(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public double computeDoubleIfPresentNonDefault(byte key, ByteDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1621,14 +1621,9 @@ public double computeDoubleIfPresent(byte key, ByteDoubleUnaryOperator mappingFu Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || Double.doubleToLongBits(entry.value) == Double.doubleToLongBits(getDefaultReturnValue())) return getDefaultReturnValue(); - double newValue = mappingFunction.apply(key, entry.value); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2FloatAVLTreeMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2FloatAVLTreeMap.java index 7c5e38f1..22d69d43 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2FloatAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2FloatAVLTreeMap.java @@ -455,34 +455,56 @@ public float computeFloat(byte key, ByteFloatUnaryOperator mappingFunction) { } @Override - public float computeFloatNonDefault(byte key, ByteFloatUnaryOperator mappingFunction) { + public float computeFloatIfAbsent(byte key, Byte2FloatFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + float newValue = mappingFunction.applyAsFloat(key); put(key, newValue); return newValue; } - float newValue = mappingFunction.applyAsFloat(key, entry.value); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - removeNode(entry); + return entry.value; + } + + @Override + public float supplyFloatIfAbsent(byte key, FloatSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + float newValue = valueProvider.getAsFloat(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public float computeFloatIfPresent(byte key, ByteFloatUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + float newValue = mappingFunction.applyAsFloat(key, entry.value); entry.value = newValue; return newValue; } @Override - public float computeFloatIfAbsent(byte key, Byte2FloatFunction mappingFunction) { + public float computeFloatNonDefault(byte key, ByteFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; put(key, newValue); return newValue; } - return entry.value; + float newValue = mappingFunction.applyAsFloat(key, entry.value); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -503,46 +525,24 @@ public float computeFloatIfAbsentNonDefault(byte key, Byte2FloatFunction mapping return entry.value; } - @Override - public float supplyFloatIfAbsent(byte key, FloatSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - float newValue = valueProvider.getAsDouble(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public float supplyFloatIfAbsentNonDefault(byte key, FloatSupplier valueProvider) { Objects.requireNonNull(valueProvider); Node entry = findNode(key); if(entry == null) { - float newValue = valueProvider.getAsDouble(); + float newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; put(key, newValue); return newValue; } if(Float.floatToIntBits(entry.value) == Float.floatToIntBits(getDefaultReturnValue())) { - float newValue = valueProvider.getAsDouble(); + float newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; entry.value = newValue; } return entry.value; } - @Override - public float computeFloatIfPresent(byte key, ByteFloatUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - float newValue = mappingFunction.applyAsFloat(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public float computeFloatIfPresentNonDefault(byte key, ByteFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1558,14 +1558,9 @@ public float computeFloatIfPresent(byte key, ByteFloatUnaryOperator mappingFunct Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || Float.floatToIntBits(entry.value) == Float.floatToIntBits(getDefaultReturnValue())) return getDefaultReturnValue(); - float newValue = mappingFunction.apply(key, entry.value); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2FloatRBTreeMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2FloatRBTreeMap.java index 08c207c1..54ba4ea1 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2FloatRBTreeMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2FloatRBTreeMap.java @@ -454,34 +454,56 @@ public float computeFloat(byte key, ByteFloatUnaryOperator mappingFunction) { } @Override - public float computeFloatNonDefault(byte key, ByteFloatUnaryOperator mappingFunction) { + public float computeFloatIfAbsent(byte key, Byte2FloatFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + float newValue = mappingFunction.applyAsFloat(key); put(key, newValue); return newValue; } - float newValue = mappingFunction.applyAsFloat(key, entry.value); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - removeNode(entry); + return entry.value; + } + + @Override + public float supplyFloatIfAbsent(byte key, FloatSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + float newValue = valueProvider.getAsFloat(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public float computeFloatIfPresent(byte key, ByteFloatUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + float newValue = mappingFunction.applyAsFloat(key, entry.value); entry.value = newValue; return newValue; } @Override - public float computeFloatIfAbsent(byte key, Byte2FloatFunction mappingFunction) { + public float computeFloatNonDefault(byte key, ByteFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; put(key, newValue); return newValue; } - return entry.value; + float newValue = mappingFunction.applyAsFloat(key, entry.value); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -502,46 +524,24 @@ public float computeFloatIfAbsentNonDefault(byte key, Byte2FloatFunction mapping return entry.value; } - @Override - public float supplyFloatIfAbsent(byte key, FloatSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - float newValue = valueProvider.getAsDouble(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public float supplyFloatIfAbsentNonDefault(byte key, FloatSupplier valueProvider) { Objects.requireNonNull(valueProvider); Node entry = findNode(key); if(entry == null) { - float newValue = valueProvider.getAsDouble(); + float newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; put(key, newValue); return newValue; } if(Float.floatToIntBits(entry.value) == Float.floatToIntBits(getDefaultReturnValue())) { - float newValue = valueProvider.getAsDouble(); + float newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; entry.value = newValue; } return entry.value; } - @Override - public float computeFloatIfPresent(byte key, ByteFloatUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - float newValue = mappingFunction.applyAsFloat(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public float computeFloatIfPresentNonDefault(byte key, ByteFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1621,14 +1621,9 @@ public float computeFloatIfPresent(byte key, ByteFloatUnaryOperator mappingFunct Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || Float.floatToIntBits(entry.value) == Float.floatToIntBits(getDefaultReturnValue())) return getDefaultReturnValue(); - float newValue = mappingFunction.apply(key, entry.value); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2IntAVLTreeMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2IntAVLTreeMap.java index f489a425..533b7662 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2IntAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2IntAVLTreeMap.java @@ -455,34 +455,56 @@ public int computeInt(byte key, ByteIntUnaryOperator mappingFunction) { } @Override - public int computeIntNonDefault(byte key, ByteIntUnaryOperator mappingFunction) { + public int computeIntIfAbsent(byte key, Byte2IntFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + int newValue = mappingFunction.applyAsInt(key); put(key, newValue); return newValue; } - int newValue = mappingFunction.applyAsInt(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public int supplyIntIfAbsent(byte key, IntSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + int newValue = valueProvider.getAsInt(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public int computeIntIfPresent(byte key, ByteIntUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + int newValue = mappingFunction.applyAsInt(key, entry.value); entry.value = newValue; return newValue; } @Override - public int computeIntIfAbsent(byte key, Byte2IntFunction mappingFunction) { + public int computeIntNonDefault(byte key, ByteIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + int newValue = mappingFunction.applyAsInt(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -503,18 +525,6 @@ public int computeIntIfAbsentNonDefault(byte key, Byte2IntFunction mappingFuncti return entry.value; } - @Override - public int supplyIntIfAbsent(byte key, IntSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - int newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public int supplyIntIfAbsentNonDefault(byte key, IntSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -533,16 +543,6 @@ public int supplyIntIfAbsentNonDefault(byte key, IntSupplier valueProvider) { return entry.value; } - @Override - public int computeIntIfPresent(byte key, ByteIntUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - int newValue = mappingFunction.applyAsInt(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public int computeIntIfPresentNonDefault(byte key, ByteIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1558,14 +1558,9 @@ public int computeIntIfPresent(byte key, ByteIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - int newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2IntRBTreeMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2IntRBTreeMap.java index e3422924..5cfbedab 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2IntRBTreeMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2IntRBTreeMap.java @@ -454,34 +454,56 @@ public int computeInt(byte key, ByteIntUnaryOperator mappingFunction) { } @Override - public int computeIntNonDefault(byte key, ByteIntUnaryOperator mappingFunction) { + public int computeIntIfAbsent(byte key, Byte2IntFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + int newValue = mappingFunction.applyAsInt(key); put(key, newValue); return newValue; } - int newValue = mappingFunction.applyAsInt(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public int supplyIntIfAbsent(byte key, IntSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + int newValue = valueProvider.getAsInt(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public int computeIntIfPresent(byte key, ByteIntUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + int newValue = mappingFunction.applyAsInt(key, entry.value); entry.value = newValue; return newValue; } @Override - public int computeIntIfAbsent(byte key, Byte2IntFunction mappingFunction) { + public int computeIntNonDefault(byte key, ByteIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + int newValue = mappingFunction.applyAsInt(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -502,18 +524,6 @@ public int computeIntIfAbsentNonDefault(byte key, Byte2IntFunction mappingFuncti return entry.value; } - @Override - public int supplyIntIfAbsent(byte key, IntSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - int newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public int supplyIntIfAbsentNonDefault(byte key, IntSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -532,16 +542,6 @@ public int supplyIntIfAbsentNonDefault(byte key, IntSupplier valueProvider) { return entry.value; } - @Override - public int computeIntIfPresent(byte key, ByteIntUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - int newValue = mappingFunction.applyAsInt(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public int computeIntIfPresentNonDefault(byte key, ByteIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1621,14 +1621,9 @@ public int computeIntIfPresent(byte key, ByteIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - int newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2LongAVLTreeMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2LongAVLTreeMap.java index c4149663..ee198d56 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2LongAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2LongAVLTreeMap.java @@ -455,34 +455,56 @@ public long computeLong(byte key, ByteLongUnaryOperator mappingFunction) { } @Override - public long computeLongNonDefault(byte key, ByteLongUnaryOperator mappingFunction) { + public long computeLongIfAbsent(byte key, Byte2LongFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + long newValue = mappingFunction.applyAsLong(key); put(key, newValue); return newValue; } - long newValue = mappingFunction.applyAsLong(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public long supplyLongIfAbsent(byte key, LongSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + long newValue = valueProvider.getAsLong(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public long computeLongIfPresent(byte key, ByteLongUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + long newValue = mappingFunction.applyAsLong(key, entry.value); entry.value = newValue; return newValue; } @Override - public long computeLongIfAbsent(byte key, Byte2LongFunction mappingFunction) { + public long computeLongNonDefault(byte key, ByteLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + long newValue = mappingFunction.applyAsLong(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -503,18 +525,6 @@ public long computeLongIfAbsentNonDefault(byte key, Byte2LongFunction mappingFun return entry.value; } - @Override - public long supplyLongIfAbsent(byte key, LongSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - long newValue = valueProvider.getAsLong(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public long supplyLongIfAbsentNonDefault(byte key, LongSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -533,16 +543,6 @@ public long supplyLongIfAbsentNonDefault(byte key, LongSupplier valueProvider) { return entry.value; } - @Override - public long computeLongIfPresent(byte key, ByteLongUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - long newValue = mappingFunction.applyAsLong(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public long computeLongIfPresentNonDefault(byte key, ByteLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1558,14 +1558,9 @@ public long computeLongIfPresent(byte key, ByteLongUnaryOperator mappingFunction Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - long newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2LongRBTreeMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2LongRBTreeMap.java index 5a16c4e9..7355d9ce 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2LongRBTreeMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2LongRBTreeMap.java @@ -454,34 +454,56 @@ public long computeLong(byte key, ByteLongUnaryOperator mappingFunction) { } @Override - public long computeLongNonDefault(byte key, ByteLongUnaryOperator mappingFunction) { + public long computeLongIfAbsent(byte key, Byte2LongFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + long newValue = mappingFunction.applyAsLong(key); put(key, newValue); return newValue; } - long newValue = mappingFunction.applyAsLong(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public long supplyLongIfAbsent(byte key, LongSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + long newValue = valueProvider.getAsLong(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public long computeLongIfPresent(byte key, ByteLongUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + long newValue = mappingFunction.applyAsLong(key, entry.value); entry.value = newValue; return newValue; } @Override - public long computeLongIfAbsent(byte key, Byte2LongFunction mappingFunction) { + public long computeLongNonDefault(byte key, ByteLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + long newValue = mappingFunction.applyAsLong(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -502,18 +524,6 @@ public long computeLongIfAbsentNonDefault(byte key, Byte2LongFunction mappingFun return entry.value; } - @Override - public long supplyLongIfAbsent(byte key, LongSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - long newValue = valueProvider.getAsLong(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public long supplyLongIfAbsentNonDefault(byte key, LongSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -532,16 +542,6 @@ public long supplyLongIfAbsentNonDefault(byte key, LongSupplier valueProvider) { return entry.value; } - @Override - public long computeLongIfPresent(byte key, ByteLongUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - long newValue = mappingFunction.applyAsLong(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public long computeLongIfPresentNonDefault(byte key, ByteLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1621,14 +1621,9 @@ public long computeLongIfPresent(byte key, ByteLongUnaryOperator mappingFunction Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - long newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2ObjectAVLTreeMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2ObjectAVLTreeMap.java index 0b886dca..2cd9c397 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2ObjectAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2ObjectAVLTreeMap.java @@ -395,25 +395,6 @@ public V compute(byte key, ByteObjectUnaryOperator mappingFunction) { return newValue; } - @Override - public V computeNonDefault(byte key, ByteObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) { - V newValue = mappingFunction.apply(key, getDefaultReturnValue()); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - put(key, newValue); - return newValue; - } - V newValue = mappingFunction.apply(key, entry.value); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; - } - @Override public V computeIfAbsent(byte key, ByteFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -432,24 +413,6 @@ public V computeIfAbsent(byte key, ByteFunction mappingFunction) { return entry.value; } - @Override - public V computeIfAbsentNonDefault(byte key, ByteFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) { - V newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - put(key, newValue); - return newValue; - } - if(Objects.equals(entry.value, getDefaultReturnValue())) { - V newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - entry.value = newValue; - } - return entry.value; - } - @Override public V supplyIfAbsent(byte key, ObjectSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -468,24 +431,6 @@ public V supplyIfAbsent(byte key, ObjectSupplier valueProvider) { return entry.value; } - @Override - public V supplyIfAbsentNonDefault(byte key, ObjectSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - V newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - put(key, newValue); - return newValue; - } - if(Objects.equals(entry.value, getDefaultReturnValue())) { - V newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - entry.value = newValue; - } - return entry.value; - } - @Override public V computeIfPresent(byte key, ByteObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -500,20 +445,6 @@ public V computeIfPresent(byte key, ByteObjectUnaryOperator mappingFunction) return newValue; } - @Override - public V computeIfPresentNonDefault(byte key, ByteObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null || Objects.equals(entry.value, getDefaultReturnValue())) return getDefaultReturnValue(); - V newValue = mappingFunction.apply(key, entry.value); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; - } - @Override public V merge(byte key, V value, ObjectObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2ObjectRBTreeMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2ObjectRBTreeMap.java index ce7a338d..62844db5 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2ObjectRBTreeMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2ObjectRBTreeMap.java @@ -394,25 +394,6 @@ public V compute(byte key, ByteObjectUnaryOperator mappingFunction) { return newValue; } - @Override - public V computeNonDefault(byte key, ByteObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) { - V newValue = mappingFunction.apply(key, getDefaultReturnValue()); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - put(key, newValue); - return newValue; - } - V newValue = mappingFunction.apply(key, entry.value); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; - } - @Override public V computeIfAbsent(byte key, ByteFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -431,24 +412,6 @@ public V computeIfAbsent(byte key, ByteFunction mappingFunction) { return entry.value; } - @Override - public V computeIfAbsentNonDefault(byte key, ByteFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) { - V newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - put(key, newValue); - return newValue; - } - if(Objects.equals(entry.value, getDefaultReturnValue())) { - V newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - entry.value = newValue; - } - return entry.value; - } - @Override public V supplyIfAbsent(byte key, ObjectSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -467,24 +430,6 @@ public V supplyIfAbsent(byte key, ObjectSupplier valueProvider) { return entry.value; } - @Override - public V supplyIfAbsentNonDefault(byte key, ObjectSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - V newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - put(key, newValue); - return newValue; - } - if(Objects.equals(entry.value, getDefaultReturnValue())) { - V newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - entry.value = newValue; - } - return entry.value; - } - @Override public V computeIfPresent(byte key, ByteObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -499,20 +444,6 @@ public V computeIfPresent(byte key, ByteObjectUnaryOperator mappingFunction) return newValue; } - @Override - public V computeIfPresentNonDefault(byte key, ByteObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null || Objects.equals(entry.value, getDefaultReturnValue())) return getDefaultReturnValue(); - V newValue = mappingFunction.apply(key, entry.value); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; - } - @Override public V merge(byte key, V value, ObjectObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2ShortAVLTreeMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2ShortAVLTreeMap.java index 6565e914..6d262bec 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2ShortAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2ShortAVLTreeMap.java @@ -455,34 +455,56 @@ public short computeShort(byte key, ByteShortUnaryOperator mappingFunction) { } @Override - public short computeShortNonDefault(byte key, ByteShortUnaryOperator mappingFunction) { + public short computeShortIfAbsent(byte key, Byte2ShortFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + short newValue = mappingFunction.applyAsShort(key); put(key, newValue); return newValue; } - short newValue = mappingFunction.applyAsShort(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public short supplyShortIfAbsent(byte key, ShortSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + short newValue = valueProvider.getAsShort(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public short computeShortIfPresent(byte key, ByteShortUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + short newValue = mappingFunction.applyAsShort(key, entry.value); entry.value = newValue; return newValue; } @Override - public short computeShortIfAbsent(byte key, Byte2ShortFunction mappingFunction) { + public short computeShortNonDefault(byte key, ByteShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + short newValue = mappingFunction.applyAsShort(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -503,46 +525,24 @@ public short computeShortIfAbsentNonDefault(byte key, Byte2ShortFunction mapping return entry.value; } - @Override - public short supplyShortIfAbsent(byte key, ShortSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - short newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public short supplyShortIfAbsentNonDefault(byte key, ShortSupplier valueProvider) { Objects.requireNonNull(valueProvider); Node entry = findNode(key); if(entry == null) { - short newValue = valueProvider.getAsInt(); + short newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } if(entry.value == getDefaultReturnValue()) { - short newValue = valueProvider.getAsInt(); + short newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; entry.value = newValue; } return entry.value; } - @Override - public short computeShortIfPresent(byte key, ByteShortUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - short newValue = mappingFunction.applyAsShort(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public short computeShortIfPresentNonDefault(byte key, ByteShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1558,14 +1558,9 @@ public short computeShortIfPresent(byte key, ByteShortUnaryOperator mappingFunct Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - short newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2ShortRBTreeMap.java b/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2ShortRBTreeMap.java index ffc1042b..03215894 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2ShortRBTreeMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/impl/tree/Byte2ShortRBTreeMap.java @@ -454,34 +454,56 @@ public short computeShort(byte key, ByteShortUnaryOperator mappingFunction) { } @Override - public short computeShortNonDefault(byte key, ByteShortUnaryOperator mappingFunction) { + public short computeShortIfAbsent(byte key, Byte2ShortFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + short newValue = mappingFunction.applyAsShort(key); put(key, newValue); return newValue; } - short newValue = mappingFunction.applyAsShort(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public short supplyShortIfAbsent(byte key, ShortSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + short newValue = valueProvider.getAsShort(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public short computeShortIfPresent(byte key, ByteShortUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + short newValue = mappingFunction.applyAsShort(key, entry.value); entry.value = newValue; return newValue; } @Override - public short computeShortIfAbsent(byte key, Byte2ShortFunction mappingFunction) { + public short computeShortNonDefault(byte key, ByteShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + short newValue = mappingFunction.applyAsShort(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -502,46 +524,24 @@ public short computeShortIfAbsentNonDefault(byte key, Byte2ShortFunction mapping return entry.value; } - @Override - public short supplyShortIfAbsent(byte key, ShortSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - short newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public short supplyShortIfAbsentNonDefault(byte key, ShortSupplier valueProvider) { Objects.requireNonNull(valueProvider); Node entry = findNode(key); if(entry == null) { - short newValue = valueProvider.getAsInt(); + short newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } if(entry.value == getDefaultReturnValue()) { - short newValue = valueProvider.getAsInt(); + short newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; entry.value = newValue; } return entry.value; } - @Override - public short computeShortIfPresent(byte key, ByteShortUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - short newValue = mappingFunction.applyAsShort(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public short computeShortIfPresentNonDefault(byte key, ByteShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1621,14 +1621,9 @@ public short computeShortIfPresent(byte key, ByteShortUnaryOperator mappingFunct Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - short newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/bytes/maps/interfaces/Byte2BooleanMap.java b/src/main/java/speiger/src/collections/bytes/maps/interfaces/Byte2BooleanMap.java index 4b24bfc8..d8ddccc8 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/interfaces/Byte2BooleanMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/interfaces/Byte2BooleanMap.java @@ -284,41 +284,51 @@ public default boolean remove(Object key, Object value) { */ public boolean computeBoolean(byte key, ByteBooleanUnaryOperator mappingFunction); /** - * A Type Specific compute method to reduce boxing/unboxing + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation + * @param mappingFunction the operator that should generate the value if not present + * @return the result of the computed value or present value */ - public boolean computeBooleanNonDefault(byte key, ByteBooleanUnaryOperator mappingFunction); + public boolean computeBooleanIfAbsent(byte key, BytePredicate mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present + * @param valueProvider the value if not present * @return the result of the computed value or present value + */ + public boolean supplyBooleanIfAbsent(byte key, BooleanSupplier valueProvider); + /** + * A Type Specific compute method to reduce boxing/unboxing + * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". + * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. + * @param key the key that should be computed + * @param mappingFunction the operator that should generate the value if present + * @return the result of the default return value or present value + * @note if not present then compute is not executed */ - public boolean computeBooleanIfAbsent(byte key, BytePredicate mappingFunction); + public boolean computeBooleanIfPresent(byte key, ByteBooleanUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value + * @param mappingFunction the operator that should generate the value + * @return the result of the computation */ - public boolean computeBooleanIfAbsentNonDefault(byte key, BytePredicate mappingFunction); + public boolean computeBooleanNonDefault(byte key, ByteBooleanUnaryOperator mappingFunction); /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param valueProvider the value if not present + * @param mappingFunction the operator that should generate the value if not present * @return the result of the computed value or present value - */ - public boolean supplyBooleanIfAbsent(byte key, BooleanSupplier valueProvider); + */ + public boolean computeBooleanIfAbsentNonDefault(byte key, BytePredicate mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -328,16 +338,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public boolean supplyBooleanIfAbsentNonDefault(byte key, BooleanSupplier valueProvider); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public boolean computeBooleanIfPresent(byte key, ByteBooleanUnaryOperator mappingFunction); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/bytes/maps/interfaces/Byte2ByteMap.java b/src/main/java/speiger/src/collections/bytes/maps/interfaces/Byte2ByteMap.java index 8bd81c2a..74acdd0c 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/interfaces/Byte2ByteMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/interfaces/Byte2ByteMap.java @@ -308,41 +308,51 @@ public default boolean remove(Object key, Object value) { */ public byte computeByte(byte key, ByteByteUnaryOperator mappingFunction); /** - * A Type Specific compute method to reduce boxing/unboxing + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation + * @param mappingFunction the operator that should generate the value if not present + * @return the result of the computed value or present value */ - public byte computeByteNonDefault(byte key, ByteByteUnaryOperator mappingFunction); + public byte computeByteIfAbsent(byte key, ByteUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present + * @param valueProvider the value if not present * @return the result of the computed value or present value + */ + public byte supplyByteIfAbsent(byte key, ByteSupplier valueProvider); + /** + * A Type Specific compute method to reduce boxing/unboxing + * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". + * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. + * @param key the key that should be computed + * @param mappingFunction the operator that should generate the value if present + * @return the result of the default return value or present value + * @note if not present then compute is not executed */ - public byte computeByteIfAbsent(byte key, ByteUnaryOperator mappingFunction); + public byte computeByteIfPresent(byte key, ByteByteUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value + * @param mappingFunction the operator that should generate the value + * @return the result of the computation */ - public byte computeByteIfAbsentNonDefault(byte key, ByteUnaryOperator mappingFunction); + public byte computeByteNonDefault(byte key, ByteByteUnaryOperator mappingFunction); /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param valueProvider the value if not present + * @param mappingFunction the operator that should generate the value if not present * @return the result of the computed value or present value - */ - public byte supplyByteIfAbsent(byte key, ByteSupplier valueProvider); + */ + public byte computeByteIfAbsentNonDefault(byte key, ByteUnaryOperator mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -352,16 +362,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public byte supplyByteIfAbsentNonDefault(byte key, ByteSupplier valueProvider); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public byte computeByteIfPresent(byte key, ByteByteUnaryOperator mappingFunction); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/bytes/maps/interfaces/Byte2CharMap.java b/src/main/java/speiger/src/collections/bytes/maps/interfaces/Byte2CharMap.java index f4886028..986a2e2a 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/interfaces/Byte2CharMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/interfaces/Byte2CharMap.java @@ -309,41 +309,51 @@ public default boolean remove(Object key, Object value) { */ public char computeChar(byte key, ByteCharUnaryOperator mappingFunction); /** - * A Type Specific compute method to reduce boxing/unboxing + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation + * @param mappingFunction the operator that should generate the value if not present + * @return the result of the computed value or present value */ - public char computeCharNonDefault(byte key, ByteCharUnaryOperator mappingFunction); + public char computeCharIfAbsent(byte key, Byte2CharFunction mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present + * @param valueProvider the value if not present * @return the result of the computed value or present value + */ + public char supplyCharIfAbsent(byte key, CharSupplier valueProvider); + /** + * A Type Specific compute method to reduce boxing/unboxing + * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". + * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. + * @param key the key that should be computed + * @param mappingFunction the operator that should generate the value if present + * @return the result of the default return value or present value + * @note if not present then compute is not executed */ - public char computeCharIfAbsent(byte key, Byte2CharFunction mappingFunction); + public char computeCharIfPresent(byte key, ByteCharUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value + * @param mappingFunction the operator that should generate the value + * @return the result of the computation */ - public char computeCharIfAbsentNonDefault(byte key, Byte2CharFunction mappingFunction); + public char computeCharNonDefault(byte key, ByteCharUnaryOperator mappingFunction); /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param valueProvider the value if not present + * @param mappingFunction the operator that should generate the value if not present * @return the result of the computed value or present value - */ - public char supplyCharIfAbsent(byte key, CharSupplier valueProvider); + */ + public char computeCharIfAbsentNonDefault(byte key, Byte2CharFunction mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -353,16 +363,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public char supplyCharIfAbsentNonDefault(byte key, CharSupplier valueProvider); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public char computeCharIfPresent(byte key, ByteCharUnaryOperator mappingFunction); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/bytes/maps/interfaces/Byte2DoubleMap.java b/src/main/java/speiger/src/collections/bytes/maps/interfaces/Byte2DoubleMap.java index 91fa0ef9..95fe7684 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/interfaces/Byte2DoubleMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/interfaces/Byte2DoubleMap.java @@ -309,41 +309,51 @@ public default boolean remove(Object key, Object value) { */ public double computeDouble(byte key, ByteDoubleUnaryOperator mappingFunction); /** - * A Type Specific compute method to reduce boxing/unboxing + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation + * @param mappingFunction the operator that should generate the value if not present + * @return the result of the computed value or present value */ - public double computeDoubleNonDefault(byte key, ByteDoubleUnaryOperator mappingFunction); + public double computeDoubleIfAbsent(byte key, Byte2DoubleFunction mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present + * @param valueProvider the value if not present * @return the result of the computed value or present value + */ + public double supplyDoubleIfAbsent(byte key, DoubleSupplier valueProvider); + /** + * A Type Specific compute method to reduce boxing/unboxing + * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". + * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. + * @param key the key that should be computed + * @param mappingFunction the operator that should generate the value if present + * @return the result of the default return value or present value + * @note if not present then compute is not executed */ - public double computeDoubleIfAbsent(byte key, Byte2DoubleFunction mappingFunction); + public double computeDoubleIfPresent(byte key, ByteDoubleUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value + * @param mappingFunction the operator that should generate the value + * @return the result of the computation */ - public double computeDoubleIfAbsentNonDefault(byte key, Byte2DoubleFunction mappingFunction); + public double computeDoubleNonDefault(byte key, ByteDoubleUnaryOperator mappingFunction); /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param valueProvider the value if not present + * @param mappingFunction the operator that should generate the value if not present * @return the result of the computed value or present value - */ - public double supplyDoubleIfAbsent(byte key, DoubleSupplier valueProvider); + */ + public double computeDoubleIfAbsentNonDefault(byte key, Byte2DoubleFunction mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -353,16 +363,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public double supplyDoubleIfAbsentNonDefault(byte key, DoubleSupplier valueProvider); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public double computeDoubleIfPresent(byte key, ByteDoubleUnaryOperator mappingFunction); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/bytes/maps/interfaces/Byte2FloatMap.java b/src/main/java/speiger/src/collections/bytes/maps/interfaces/Byte2FloatMap.java index 096cb368..4c7cee87 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/interfaces/Byte2FloatMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/interfaces/Byte2FloatMap.java @@ -309,41 +309,51 @@ public default boolean remove(Object key, Object value) { */ public float computeFloat(byte key, ByteFloatUnaryOperator mappingFunction); /** - * A Type Specific compute method to reduce boxing/unboxing + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation + * @param mappingFunction the operator that should generate the value if not present + * @return the result of the computed value or present value */ - public float computeFloatNonDefault(byte key, ByteFloatUnaryOperator mappingFunction); + public float computeFloatIfAbsent(byte key, Byte2FloatFunction mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present + * @param valueProvider the value if not present * @return the result of the computed value or present value + */ + public float supplyFloatIfAbsent(byte key, FloatSupplier valueProvider); + /** + * A Type Specific compute method to reduce boxing/unboxing + * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". + * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. + * @param key the key that should be computed + * @param mappingFunction the operator that should generate the value if present + * @return the result of the default return value or present value + * @note if not present then compute is not executed */ - public float computeFloatIfAbsent(byte key, Byte2FloatFunction mappingFunction); + public float computeFloatIfPresent(byte key, ByteFloatUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value + * @param mappingFunction the operator that should generate the value + * @return the result of the computation */ - public float computeFloatIfAbsentNonDefault(byte key, Byte2FloatFunction mappingFunction); + public float computeFloatNonDefault(byte key, ByteFloatUnaryOperator mappingFunction); /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param valueProvider the value if not present + * @param mappingFunction the operator that should generate the value if not present * @return the result of the computed value or present value - */ - public float supplyFloatIfAbsent(byte key, FloatSupplier valueProvider); + */ + public float computeFloatIfAbsentNonDefault(byte key, Byte2FloatFunction mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -353,16 +363,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public float supplyFloatIfAbsentNonDefault(byte key, FloatSupplier valueProvider); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public float computeFloatIfPresent(byte key, ByteFloatUnaryOperator mappingFunction); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/bytes/maps/interfaces/Byte2IntMap.java b/src/main/java/speiger/src/collections/bytes/maps/interfaces/Byte2IntMap.java index 7e383c2c..75be994c 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/interfaces/Byte2IntMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/interfaces/Byte2IntMap.java @@ -309,41 +309,51 @@ public default boolean remove(Object key, Object value) { */ public int computeInt(byte key, ByteIntUnaryOperator mappingFunction); /** - * A Type Specific compute method to reduce boxing/unboxing + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation + * @param mappingFunction the operator that should generate the value if not present + * @return the result of the computed value or present value */ - public int computeIntNonDefault(byte key, ByteIntUnaryOperator mappingFunction); + public int computeIntIfAbsent(byte key, Byte2IntFunction mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present + * @param valueProvider the value if not present * @return the result of the computed value or present value + */ + public int supplyIntIfAbsent(byte key, IntSupplier valueProvider); + /** + * A Type Specific compute method to reduce boxing/unboxing + * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". + * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. + * @param key the key that should be computed + * @param mappingFunction the operator that should generate the value if present + * @return the result of the default return value or present value + * @note if not present then compute is not executed */ - public int computeIntIfAbsent(byte key, Byte2IntFunction mappingFunction); + public int computeIntIfPresent(byte key, ByteIntUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value + * @param mappingFunction the operator that should generate the value + * @return the result of the computation */ - public int computeIntIfAbsentNonDefault(byte key, Byte2IntFunction mappingFunction); + public int computeIntNonDefault(byte key, ByteIntUnaryOperator mappingFunction); /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param valueProvider the value if not present + * @param mappingFunction the operator that should generate the value if not present * @return the result of the computed value or present value - */ - public int supplyIntIfAbsent(byte key, IntSupplier valueProvider); + */ + public int computeIntIfAbsentNonDefault(byte key, Byte2IntFunction mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -353,16 +363,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public int supplyIntIfAbsentNonDefault(byte key, IntSupplier valueProvider); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public int computeIntIfPresent(byte key, ByteIntUnaryOperator mappingFunction); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/bytes/maps/interfaces/Byte2LongMap.java b/src/main/java/speiger/src/collections/bytes/maps/interfaces/Byte2LongMap.java index 35441a4c..88930203 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/interfaces/Byte2LongMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/interfaces/Byte2LongMap.java @@ -309,41 +309,51 @@ public default boolean remove(Object key, Object value) { */ public long computeLong(byte key, ByteLongUnaryOperator mappingFunction); /** - * A Type Specific compute method to reduce boxing/unboxing + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation + * @param mappingFunction the operator that should generate the value if not present + * @return the result of the computed value or present value */ - public long computeLongNonDefault(byte key, ByteLongUnaryOperator mappingFunction); + public long computeLongIfAbsent(byte key, Byte2LongFunction mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present + * @param valueProvider the value if not present * @return the result of the computed value or present value + */ + public long supplyLongIfAbsent(byte key, LongSupplier valueProvider); + /** + * A Type Specific compute method to reduce boxing/unboxing + * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". + * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. + * @param key the key that should be computed + * @param mappingFunction the operator that should generate the value if present + * @return the result of the default return value or present value + * @note if not present then compute is not executed */ - public long computeLongIfAbsent(byte key, Byte2LongFunction mappingFunction); + public long computeLongIfPresent(byte key, ByteLongUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value + * @param mappingFunction the operator that should generate the value + * @return the result of the computation */ - public long computeLongIfAbsentNonDefault(byte key, Byte2LongFunction mappingFunction); + public long computeLongNonDefault(byte key, ByteLongUnaryOperator mappingFunction); /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param valueProvider the value if not present + * @param mappingFunction the operator that should generate the value if not present * @return the result of the computed value or present value - */ - public long supplyLongIfAbsent(byte key, LongSupplier valueProvider); + */ + public long computeLongIfAbsentNonDefault(byte key, Byte2LongFunction mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -353,16 +363,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public long supplyLongIfAbsentNonDefault(byte key, LongSupplier valueProvider); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public long computeLongIfPresent(byte key, ByteLongUnaryOperator mappingFunction); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/bytes/maps/interfaces/Byte2ObjectMap.java b/src/main/java/speiger/src/collections/bytes/maps/interfaces/Byte2ObjectMap.java index c7641c69..f1145bd0 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/interfaces/Byte2ObjectMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/interfaces/Byte2ObjectMap.java @@ -266,15 +266,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computation */ public V compute(byte key, ByteObjectUnaryOperator mappingFunction); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation - */ - public V computeNonDefault(byte key, ByteObjectUnaryOperator mappingFunction); /** * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -284,15 +275,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public V computeIfAbsent(byte key, ByteFunction mappingFunction); - /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value - */ - public V computeIfAbsentNonDefault(byte key, ByteFunction mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -302,15 +284,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public V supplyIfAbsent(byte key, ObjectSupplier valueProvider); - /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param valueProvider the value if not present - * @return the result of the computed value or present value - */ - public V supplyIfAbsentNonDefault(byte key, ObjectSupplier valueProvider); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -321,16 +294,6 @@ public default boolean remove(Object key, Object value) { * @note if not present then compute is not executed */ public V computeIfPresent(byte key, ByteObjectUnaryOperator mappingFunction); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public V computeIfPresentNonDefault(byte key, ByteObjectUnaryOperator mappingFunction); /** * A Type Specific merge method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/bytes/maps/interfaces/Byte2ShortMap.java b/src/main/java/speiger/src/collections/bytes/maps/interfaces/Byte2ShortMap.java index 7bdac5d8..88225d11 100644 --- a/src/main/java/speiger/src/collections/bytes/maps/interfaces/Byte2ShortMap.java +++ b/src/main/java/speiger/src/collections/bytes/maps/interfaces/Byte2ShortMap.java @@ -309,41 +309,51 @@ public default boolean remove(Object key, Object value) { */ public short computeShort(byte key, ByteShortUnaryOperator mappingFunction); /** - * A Type Specific compute method to reduce boxing/unboxing + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation + * @param mappingFunction the operator that should generate the value if not present + * @return the result of the computed value or present value */ - public short computeShortNonDefault(byte key, ByteShortUnaryOperator mappingFunction); + public short computeShortIfAbsent(byte key, Byte2ShortFunction mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present + * @param valueProvider the value if not present * @return the result of the computed value or present value + */ + public short supplyShortIfAbsent(byte key, ShortSupplier valueProvider); + /** + * A Type Specific compute method to reduce boxing/unboxing + * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". + * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. + * @param key the key that should be computed + * @param mappingFunction the operator that should generate the value if present + * @return the result of the default return value or present value + * @note if not present then compute is not executed */ - public short computeShortIfAbsent(byte key, Byte2ShortFunction mappingFunction); + public short computeShortIfPresent(byte key, ByteShortUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value + * @param mappingFunction the operator that should generate the value + * @return the result of the computation */ - public short computeShortIfAbsentNonDefault(byte key, Byte2ShortFunction mappingFunction); + public short computeShortNonDefault(byte key, ByteShortUnaryOperator mappingFunction); /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param valueProvider the value if not present + * @param mappingFunction the operator that should generate the value if not present * @return the result of the computed value or present value - */ - public short supplyShortIfAbsent(byte key, ShortSupplier valueProvider); + */ + public short computeShortIfAbsentNonDefault(byte key, Byte2ShortFunction mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -353,16 +363,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public short supplyShortIfAbsentNonDefault(byte key, ShortSupplier valueProvider); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public short computeShortIfPresent(byte key, ByteShortUnaryOperator mappingFunction); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/bytes/queues/ByteArrayFIFOQueue.java b/src/main/java/speiger/src/collections/bytes/queues/ByteArrayFIFOQueue.java index 9812bd7a..41d89bed 100644 --- a/src/main/java/speiger/src/collections/bytes/queues/ByteArrayFIFOQueue.java +++ b/src/main/java/speiger/src/collections/bytes/queues/ByteArrayFIFOQueue.java @@ -146,6 +146,15 @@ public byte peek(int index) { return index >= array.length ? array[index-array.length] : array[index]; } + @Override + public boolean contains(byte e) { + if(first == last) return false; + for(int i = 0,m=size();i iterator, int repeats return new RepeatingIterator(wrap(iterator), repeats); } + /** + * A Helper function that creates a infinitely looping iterator + * @param iterator that should be looping infinitely + * @return a infinitely looping iterator + */ + public static ByteIterator infinite(ByteIterator iterator) { + return new InfiniteIterator(iterator); + } + + /** + * A Helper function that creates a infinitely looping iterator from a Java Iterator + * @param iterator that should be looping infinitely + * @return a infinitely looping iterator + */ + public static ByteIterator infinite(Iterator iterator) { + return new InfiniteIterator(wrap(iterator)); + } + /** * A Helper function that hard limits the Iterator to a specific size * @param iterator that should be limited @@ -841,6 +862,40 @@ public T next() { } } + private static class InfiniteIterator implements ByteIterator + { + ByteIterator iter; + CollectionWrapper looper = ByteCollections.wrapper(); + int index = 0; + + public InfiniteIterator(ByteIterator iter) { + this.iter = iter; + } + + @Override + public boolean hasNext() { + return true; + } + + @Override + public byte nextByte() { + if(iter != null) { + if(iter.hasNext()) { + byte value = iter.nextByte(); + looper.add(value); + return value; + } + else iter = null; + } + return looper.getByte((index++) % looper.size()); + } + + @Override + public void forEachRemaining(ByteConsumer action) { throw new UnsupportedOperationException("This is a instant deadlock, so unsupported"); } + public void forEachRemaining(Consumer action) { throw new UnsupportedOperationException("This is a instant deadlock, so unsupported"); } + public void forEachRemaining(E input, ObjectByteConsumer action) { throw new UnsupportedOperationException("This is a instant deadlock, so unsupported"); } + } + private static class RepeatingIterator implements ByteIterator { final int repeats; diff --git a/src/main/java/speiger/src/collections/bytes/utils/ByteLists.java b/src/main/java/speiger/src/collections/bytes/utils/ByteLists.java index 3d52d57c..29f3c317 100644 --- a/src/main/java/speiger/src/collections/bytes/utils/ByteLists.java +++ b/src/main/java/speiger/src/collections/bytes/utils/ByteLists.java @@ -12,6 +12,7 @@ import speiger.src.collections.bytes.functions.ByteConsumer; import speiger.src.collections.bytes.lists.AbstractByteList; import speiger.src.collections.bytes.lists.ByteList; +import speiger.src.collections.ints.lists.IntList; import speiger.src.collections.bytes.lists.ByteListIterator; import speiger.src.collections.utils.SanityChecks; @@ -317,6 +318,16 @@ public ByteListIterator listIterator(int index) { return l.listIterator(index); } + @Override + public ByteListIterator indexedIterator(int...indecies) { + return l.indexedIterator(indecies); + } + + @Override + public ByteListIterator indexedIterator(IntList indecies) { + return l.indexedIterator(indecies); + } + @Override public ByteList subList(int from, int to) { return ByteLists.synchronize(l.subList(from, to)); @@ -426,6 +437,16 @@ public ByteListIterator listIterator(int index) { return ByteIterators.unmodifiable(l.listIterator(index)); } + @Override + public ByteListIterator indexedIterator(int...indecies) { + return ByteIterators.unmodifiable(l.indexedIterator(indecies)); + } + + @Override + public ByteListIterator indexedIterator(IntList indecies) { + return ByteIterators.unmodifiable(l.indexedIterator(indecies)); + } + @Override public ByteList subList(int from, int to) { return ByteLists.unmodifiable(l.subList(from, to)); @@ -514,6 +535,16 @@ public ByteListIterator listIterator(int index) { return ByteIterators.empty(); } + @Override + public ByteListIterator indexedIterator(int...indecies) { + return ByteIterators.empty(); + } + + @Override + public ByteListIterator indexedIterator(IntList indecies) { + return ByteIterators.empty(); + } + @Override public int hashCode() { return 1; } diff --git a/src/main/java/speiger/src/collections/bytes/utils/BytePriorityQueues.java b/src/main/java/speiger/src/collections/bytes/utils/BytePriorityQueues.java index 0663d197..67d9603e 100644 --- a/src/main/java/speiger/src/collections/bytes/utils/BytePriorityQueues.java +++ b/src/main/java/speiger/src/collections/bytes/utils/BytePriorityQueues.java @@ -89,6 +89,8 @@ protected SynchronizedPriorityQueue(BytePriorityQueue queue, Object mutex) { @Override public byte peek(int index) { synchronized(mutex) { return queue.peek(index); } } @Override + public boolean contains(byte e) { synchronized(mutex) { return queue.contains(e); } } + @Override public boolean removeFirst(byte e) { synchronized(mutex) { return queue.removeFirst(e); } } @Override public boolean removeLast(byte e) { synchronized(mutex) { return queue.removeLast(e); } } diff --git a/src/main/java/speiger/src/collections/bytes/utils/maps/Byte2BooleanMaps.java b/src/main/java/speiger/src/collections/bytes/utils/maps/Byte2BooleanMaps.java index 3e63491b..42442f23 100644 --- a/src/main/java/speiger/src/collections/bytes/utils/maps/Byte2BooleanMaps.java +++ b/src/main/java/speiger/src/collections/bytes/utils/maps/Byte2BooleanMaps.java @@ -246,18 +246,18 @@ public static class SingletonMap extends AbstractByte2BooleanMap { @Override public boolean computeBoolean(byte key, ByteBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanNonDefault(byte key, ByteBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean computeBooleanIfAbsent(byte key, BytePredicate mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanIfAbsentNonDefault(byte key, BytePredicate mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean computeBooleanIfPresent(byte key, ByteBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanIfPresentNonDefault(byte key, ByteBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean supplyBooleanIfAbsent(byte key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public boolean computeBooleanNonDefault(byte key, ByteBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public boolean computeBooleanIfAbsentNonDefault(byte key, BytePredicate mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public boolean computeBooleanIfPresentNonDefault(byte key, ByteBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public boolean supplyBooleanIfAbsentNonDefault(byte key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public boolean mergeBoolean(byte key, boolean value, BooleanBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -304,18 +304,18 @@ public static class EmptyMap extends AbstractByte2BooleanMap { @Override public boolean computeBoolean(byte key, ByteBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanNonDefault(byte key, ByteBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean computeBooleanIfAbsent(byte key, BytePredicate mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanIfAbsentNonDefault(byte key, BytePredicate mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean computeBooleanIfPresent(byte key, ByteBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanIfPresentNonDefault(byte key, ByteBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean supplyBooleanIfAbsent(byte key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public boolean computeBooleanNonDefault(byte key, ByteBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public boolean computeBooleanIfAbsentNonDefault(byte key, BytePredicate mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public boolean computeBooleanIfPresentNonDefault(byte key, ByteBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public boolean supplyBooleanIfAbsentNonDefault(byte key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public boolean mergeBoolean(byte key, boolean value, BooleanBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -535,18 +535,18 @@ public boolean get(byte key) { @Override public boolean computeBoolean(byte key, ByteBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanNonDefault(byte key, ByteBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean computeBooleanIfAbsent(byte key, BytePredicate mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanIfAbsentNonDefault(byte key, BytePredicate mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean computeBooleanIfPresent(byte key, ByteBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanIfPresentNonDefault(byte key, ByteBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean supplyBooleanIfAbsent(byte key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public boolean computeBooleanNonDefault(byte key, ByteBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public boolean computeBooleanIfAbsentNonDefault(byte key, BytePredicate mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public boolean computeBooleanIfPresentNonDefault(byte key, ByteBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public boolean supplyBooleanIfAbsentNonDefault(byte key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public boolean mergeBoolean(byte key, boolean value, BooleanBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -938,18 +938,18 @@ public AbstractByte2BooleanMap setDefaultReturnValue(boolean v) { @Override public boolean computeBoolean(byte key, ByteBooleanUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeBoolean(key, mappingFunction); } } @Override - public boolean computeBooleanNonDefault(byte key, ByteBooleanUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeBooleanNonDefault(key, mappingFunction); } } - @Override public boolean computeBooleanIfAbsent(byte key, BytePredicate mappingFunction) { synchronized(mutex) { return map.computeBooleanIfAbsent(key, mappingFunction); } } @Override - public boolean computeBooleanIfAbsentNonDefault(byte key, BytePredicate mappingFunction) { synchronized(mutex) { return map.computeBooleanIfAbsentNonDefault(key, mappingFunction); } } - @Override public boolean computeBooleanIfPresent(byte key, ByteBooleanUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeBooleanIfPresent(key, mappingFunction); } } @Override - public boolean computeBooleanIfPresentNonDefault(byte key, ByteBooleanUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeBooleanIfPresentNonDefault(key, mappingFunction); } } - @Override public boolean supplyBooleanIfAbsent(byte key, BooleanSupplier valueProvider) { synchronized(mutex) { return map.supplyBooleanIfAbsent(key, valueProvider); } } @Override + public boolean computeBooleanNonDefault(byte key, ByteBooleanUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeBooleanNonDefault(key, mappingFunction); } } + @Override + public boolean computeBooleanIfAbsentNonDefault(byte key, BytePredicate mappingFunction) { synchronized(mutex) { return map.computeBooleanIfAbsentNonDefault(key, mappingFunction); } } + @Override + public boolean computeBooleanIfPresentNonDefault(byte key, ByteBooleanUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeBooleanIfPresentNonDefault(key, mappingFunction); } } + @Override public boolean supplyBooleanIfAbsentNonDefault(byte key, BooleanSupplier valueProvider) { synchronized(mutex) { return map.supplyBooleanIfAbsentNonDefault(key, valueProvider); } } @Override public boolean mergeBoolean(byte key, boolean value, BooleanBooleanUnaryOperator mappingFunction) { synchronized(mutex) { return map.mergeBoolean(key, value, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/bytes/utils/maps/Byte2ByteMaps.java b/src/main/java/speiger/src/collections/bytes/utils/maps/Byte2ByteMaps.java index a4c19371..8bb6a3f4 100644 --- a/src/main/java/speiger/src/collections/bytes/utils/maps/Byte2ByteMaps.java +++ b/src/main/java/speiger/src/collections/bytes/utils/maps/Byte2ByteMaps.java @@ -249,18 +249,18 @@ public static class SingletonMap extends AbstractByte2ByteMap { @Override public byte computeByte(byte key, ByteByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteNonDefault(byte key, ByteByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte computeByteIfAbsent(byte key, ByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteIfAbsentNonDefault(byte key, ByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte computeByteIfPresent(byte key, ByteByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteIfPresentNonDefault(byte key, ByteByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte supplyByteIfAbsent(byte key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public byte computeByteNonDefault(byte key, ByteByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public byte computeByteIfAbsentNonDefault(byte key, ByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public byte computeByteIfPresentNonDefault(byte key, ByteByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public byte supplyByteIfAbsentNonDefault(byte key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public byte mergeByte(byte key, byte value, ByteByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -311,18 +311,18 @@ public static class EmptyMap extends AbstractByte2ByteMap { @Override public byte computeByte(byte key, ByteByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteNonDefault(byte key, ByteByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte computeByteIfAbsent(byte key, ByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteIfAbsentNonDefault(byte key, ByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte computeByteIfPresent(byte key, ByteByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteIfPresentNonDefault(byte key, ByteByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte supplyByteIfAbsent(byte key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public byte computeByteNonDefault(byte key, ByteByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public byte computeByteIfAbsentNonDefault(byte key, ByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public byte computeByteIfPresentNonDefault(byte key, ByteByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public byte supplyByteIfAbsentNonDefault(byte key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public byte mergeByte(byte key, byte value, ByteByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -546,18 +546,18 @@ public byte get(byte key) { @Override public byte computeByte(byte key, ByteByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteNonDefault(byte key, ByteByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte computeByteIfAbsent(byte key, ByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteIfAbsentNonDefault(byte key, ByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte computeByteIfPresent(byte key, ByteByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteIfPresentNonDefault(byte key, ByteByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte supplyByteIfAbsent(byte key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public byte computeByteNonDefault(byte key, ByteByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public byte computeByteIfAbsentNonDefault(byte key, ByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public byte computeByteIfPresentNonDefault(byte key, ByteByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public byte supplyByteIfAbsentNonDefault(byte key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public byte mergeByte(byte key, byte value, ByteByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -954,18 +954,18 @@ public AbstractByte2ByteMap setDefaultReturnValue(byte v) { @Override public byte computeByte(byte key, ByteByteUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeByte(key, mappingFunction); } } @Override - public byte computeByteNonDefault(byte key, ByteByteUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeByteNonDefault(key, mappingFunction); } } - @Override public byte computeByteIfAbsent(byte key, ByteUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeByteIfAbsent(key, mappingFunction); } } @Override - public byte computeByteIfAbsentNonDefault(byte key, ByteUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeByteIfAbsentNonDefault(key, mappingFunction); } } - @Override public byte computeByteIfPresent(byte key, ByteByteUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeByteIfPresent(key, mappingFunction); } } @Override - public byte computeByteIfPresentNonDefault(byte key, ByteByteUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeByteIfPresentNonDefault(key, mappingFunction); } } - @Override public byte supplyByteIfAbsent(byte key, ByteSupplier valueProvider) { synchronized(mutex) { return map.supplyByteIfAbsent(key, valueProvider); } } @Override + public byte computeByteNonDefault(byte key, ByteByteUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeByteNonDefault(key, mappingFunction); } } + @Override + public byte computeByteIfAbsentNonDefault(byte key, ByteUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeByteIfAbsentNonDefault(key, mappingFunction); } } + @Override + public byte computeByteIfPresentNonDefault(byte key, ByteByteUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeByteIfPresentNonDefault(key, mappingFunction); } } + @Override public byte supplyByteIfAbsentNonDefault(byte key, ByteSupplier valueProvider) { synchronized(mutex) { return map.supplyByteIfAbsentNonDefault(key, valueProvider); } } @Override public byte mergeByte(byte key, byte value, ByteByteUnaryOperator mappingFunction) { synchronized(mutex) { return map.mergeByte(key, value, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/bytes/utils/maps/Byte2CharMaps.java b/src/main/java/speiger/src/collections/bytes/utils/maps/Byte2CharMaps.java index 53b74b2d..3a92fc41 100644 --- a/src/main/java/speiger/src/collections/bytes/utils/maps/Byte2CharMaps.java +++ b/src/main/java/speiger/src/collections/bytes/utils/maps/Byte2CharMaps.java @@ -250,18 +250,18 @@ public static class SingletonMap extends AbstractByte2CharMap { @Override public char computeChar(byte key, ByteCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharNonDefault(byte key, ByteCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char computeCharIfAbsent(byte key, Byte2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharIfAbsentNonDefault(byte key, Byte2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char computeCharIfPresent(byte key, ByteCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharIfPresentNonDefault(byte key, ByteCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char supplyCharIfAbsent(byte key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public char computeCharNonDefault(byte key, ByteCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public char computeCharIfAbsentNonDefault(byte key, Byte2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public char computeCharIfPresentNonDefault(byte key, ByteCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public char supplyCharIfAbsentNonDefault(byte key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public char mergeChar(byte key, char value, CharCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -312,18 +312,18 @@ public static class EmptyMap extends AbstractByte2CharMap { @Override public char computeChar(byte key, ByteCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharNonDefault(byte key, ByteCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char computeCharIfAbsent(byte key, Byte2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharIfAbsentNonDefault(byte key, Byte2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char computeCharIfPresent(byte key, ByteCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharIfPresentNonDefault(byte key, ByteCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char supplyCharIfAbsent(byte key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public char computeCharNonDefault(byte key, ByteCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public char computeCharIfAbsentNonDefault(byte key, Byte2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public char computeCharIfPresentNonDefault(byte key, ByteCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public char supplyCharIfAbsentNonDefault(byte key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public char mergeChar(byte key, char value, CharCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -547,18 +547,18 @@ public char get(byte key) { @Override public char computeChar(byte key, ByteCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharNonDefault(byte key, ByteCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char computeCharIfAbsent(byte key, Byte2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharIfAbsentNonDefault(byte key, Byte2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char computeCharIfPresent(byte key, ByteCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharIfPresentNonDefault(byte key, ByteCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char supplyCharIfAbsent(byte key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public char computeCharNonDefault(byte key, ByteCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public char computeCharIfAbsentNonDefault(byte key, Byte2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public char computeCharIfPresentNonDefault(byte key, ByteCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public char supplyCharIfAbsentNonDefault(byte key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public char mergeChar(byte key, char value, CharCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -955,18 +955,18 @@ public AbstractByte2CharMap setDefaultReturnValue(char v) { @Override public char computeChar(byte key, ByteCharUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeChar(key, mappingFunction); } } @Override - public char computeCharNonDefault(byte key, ByteCharUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeCharNonDefault(key, mappingFunction); } } - @Override public char computeCharIfAbsent(byte key, Byte2CharFunction mappingFunction) { synchronized(mutex) { return map.computeCharIfAbsent(key, mappingFunction); } } @Override - public char computeCharIfAbsentNonDefault(byte key, Byte2CharFunction mappingFunction) { synchronized(mutex) { return map.computeCharIfAbsentNonDefault(key, mappingFunction); } } - @Override public char computeCharIfPresent(byte key, ByteCharUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeCharIfPresent(key, mappingFunction); } } @Override - public char computeCharIfPresentNonDefault(byte key, ByteCharUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeCharIfPresentNonDefault(key, mappingFunction); } } - @Override public char supplyCharIfAbsent(byte key, CharSupplier valueProvider) { synchronized(mutex) { return map.supplyCharIfAbsent(key, valueProvider); } } @Override + public char computeCharNonDefault(byte key, ByteCharUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeCharNonDefault(key, mappingFunction); } } + @Override + public char computeCharIfAbsentNonDefault(byte key, Byte2CharFunction mappingFunction) { synchronized(mutex) { return map.computeCharIfAbsentNonDefault(key, mappingFunction); } } + @Override + public char computeCharIfPresentNonDefault(byte key, ByteCharUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeCharIfPresentNonDefault(key, mappingFunction); } } + @Override public char supplyCharIfAbsentNonDefault(byte key, CharSupplier valueProvider) { synchronized(mutex) { return map.supplyCharIfAbsentNonDefault(key, valueProvider); } } @Override public char mergeChar(byte key, char value, CharCharUnaryOperator mappingFunction) { synchronized(mutex) { return map.mergeChar(key, value, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/bytes/utils/maps/Byte2DoubleMaps.java b/src/main/java/speiger/src/collections/bytes/utils/maps/Byte2DoubleMaps.java index 17c4c912..30233700 100644 --- a/src/main/java/speiger/src/collections/bytes/utils/maps/Byte2DoubleMaps.java +++ b/src/main/java/speiger/src/collections/bytes/utils/maps/Byte2DoubleMaps.java @@ -250,18 +250,18 @@ public static class SingletonMap extends AbstractByte2DoubleMap { @Override public double computeDouble(byte key, ByteDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleNonDefault(byte key, ByteDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double computeDoubleIfAbsent(byte key, Byte2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleIfAbsentNonDefault(byte key, Byte2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double computeDoubleIfPresent(byte key, ByteDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleIfPresentNonDefault(byte key, ByteDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double supplyDoubleIfAbsent(byte key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public double computeDoubleNonDefault(byte key, ByteDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public double computeDoubleIfAbsentNonDefault(byte key, Byte2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public double computeDoubleIfPresentNonDefault(byte key, ByteDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public double supplyDoubleIfAbsentNonDefault(byte key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public double mergeDouble(byte key, double value, DoubleDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -312,18 +312,18 @@ public static class EmptyMap extends AbstractByte2DoubleMap { @Override public double computeDouble(byte key, ByteDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleNonDefault(byte key, ByteDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double computeDoubleIfAbsent(byte key, Byte2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleIfAbsentNonDefault(byte key, Byte2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double computeDoubleIfPresent(byte key, ByteDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleIfPresentNonDefault(byte key, ByteDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double supplyDoubleIfAbsent(byte key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public double computeDoubleNonDefault(byte key, ByteDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public double computeDoubleIfAbsentNonDefault(byte key, Byte2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public double computeDoubleIfPresentNonDefault(byte key, ByteDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public double supplyDoubleIfAbsentNonDefault(byte key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public double mergeDouble(byte key, double value, DoubleDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -547,18 +547,18 @@ public double get(byte key) { @Override public double computeDouble(byte key, ByteDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleNonDefault(byte key, ByteDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double computeDoubleIfAbsent(byte key, Byte2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleIfAbsentNonDefault(byte key, Byte2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double computeDoubleIfPresent(byte key, ByteDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleIfPresentNonDefault(byte key, ByteDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double supplyDoubleIfAbsent(byte key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public double computeDoubleNonDefault(byte key, ByteDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public double computeDoubleIfAbsentNonDefault(byte key, Byte2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public double computeDoubleIfPresentNonDefault(byte key, ByteDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public double supplyDoubleIfAbsentNonDefault(byte key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public double mergeDouble(byte key, double value, DoubleDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -955,18 +955,18 @@ public AbstractByte2DoubleMap setDefaultReturnValue(double v) { @Override public double computeDouble(byte key, ByteDoubleUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeDouble(key, mappingFunction); } } @Override - public double computeDoubleNonDefault(byte key, ByteDoubleUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeDoubleNonDefault(key, mappingFunction); } } - @Override public double computeDoubleIfAbsent(byte key, Byte2DoubleFunction mappingFunction) { synchronized(mutex) { return map.computeDoubleIfAbsent(key, mappingFunction); } } @Override - public double computeDoubleIfAbsentNonDefault(byte key, Byte2DoubleFunction mappingFunction) { synchronized(mutex) { return map.computeDoubleIfAbsentNonDefault(key, mappingFunction); } } - @Override public double computeDoubleIfPresent(byte key, ByteDoubleUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeDoubleIfPresent(key, mappingFunction); } } @Override - public double computeDoubleIfPresentNonDefault(byte key, ByteDoubleUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeDoubleIfPresentNonDefault(key, mappingFunction); } } - @Override public double supplyDoubleIfAbsent(byte key, DoubleSupplier valueProvider) { synchronized(mutex) { return map.supplyDoubleIfAbsent(key, valueProvider); } } @Override + public double computeDoubleNonDefault(byte key, ByteDoubleUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeDoubleNonDefault(key, mappingFunction); } } + @Override + public double computeDoubleIfAbsentNonDefault(byte key, Byte2DoubleFunction mappingFunction) { synchronized(mutex) { return map.computeDoubleIfAbsentNonDefault(key, mappingFunction); } } + @Override + public double computeDoubleIfPresentNonDefault(byte key, ByteDoubleUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeDoubleIfPresentNonDefault(key, mappingFunction); } } + @Override public double supplyDoubleIfAbsentNonDefault(byte key, DoubleSupplier valueProvider) { synchronized(mutex) { return map.supplyDoubleIfAbsentNonDefault(key, valueProvider); } } @Override public double mergeDouble(byte key, double value, DoubleDoubleUnaryOperator mappingFunction) { synchronized(mutex) { return map.mergeDouble(key, value, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/bytes/utils/maps/Byte2FloatMaps.java b/src/main/java/speiger/src/collections/bytes/utils/maps/Byte2FloatMaps.java index bc2bff1f..4bfd042f 100644 --- a/src/main/java/speiger/src/collections/bytes/utils/maps/Byte2FloatMaps.java +++ b/src/main/java/speiger/src/collections/bytes/utils/maps/Byte2FloatMaps.java @@ -250,18 +250,18 @@ public static class SingletonMap extends AbstractByte2FloatMap { @Override public float computeFloat(byte key, ByteFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatNonDefault(byte key, ByteFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float computeFloatIfAbsent(byte key, Byte2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatIfAbsentNonDefault(byte key, Byte2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float computeFloatIfPresent(byte key, ByteFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatIfPresentNonDefault(byte key, ByteFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float supplyFloatIfAbsent(byte key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public float computeFloatNonDefault(byte key, ByteFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public float computeFloatIfAbsentNonDefault(byte key, Byte2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public float computeFloatIfPresentNonDefault(byte key, ByteFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public float supplyFloatIfAbsentNonDefault(byte key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public float mergeFloat(byte key, float value, FloatFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -312,18 +312,18 @@ public static class EmptyMap extends AbstractByte2FloatMap { @Override public float computeFloat(byte key, ByteFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatNonDefault(byte key, ByteFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float computeFloatIfAbsent(byte key, Byte2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatIfAbsentNonDefault(byte key, Byte2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float computeFloatIfPresent(byte key, ByteFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatIfPresentNonDefault(byte key, ByteFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float supplyFloatIfAbsent(byte key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public float computeFloatNonDefault(byte key, ByteFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public float computeFloatIfAbsentNonDefault(byte key, Byte2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public float computeFloatIfPresentNonDefault(byte key, ByteFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public float supplyFloatIfAbsentNonDefault(byte key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public float mergeFloat(byte key, float value, FloatFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -547,18 +547,18 @@ public float get(byte key) { @Override public float computeFloat(byte key, ByteFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatNonDefault(byte key, ByteFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float computeFloatIfAbsent(byte key, Byte2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatIfAbsentNonDefault(byte key, Byte2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float computeFloatIfPresent(byte key, ByteFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatIfPresentNonDefault(byte key, ByteFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float supplyFloatIfAbsent(byte key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public float computeFloatNonDefault(byte key, ByteFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public float computeFloatIfAbsentNonDefault(byte key, Byte2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public float computeFloatIfPresentNonDefault(byte key, ByteFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public float supplyFloatIfAbsentNonDefault(byte key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public float mergeFloat(byte key, float value, FloatFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -955,18 +955,18 @@ public AbstractByte2FloatMap setDefaultReturnValue(float v) { @Override public float computeFloat(byte key, ByteFloatUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeFloat(key, mappingFunction); } } @Override - public float computeFloatNonDefault(byte key, ByteFloatUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeFloatNonDefault(key, mappingFunction); } } - @Override public float computeFloatIfAbsent(byte key, Byte2FloatFunction mappingFunction) { synchronized(mutex) { return map.computeFloatIfAbsent(key, mappingFunction); } } @Override - public float computeFloatIfAbsentNonDefault(byte key, Byte2FloatFunction mappingFunction) { synchronized(mutex) { return map.computeFloatIfAbsentNonDefault(key, mappingFunction); } } - @Override public float computeFloatIfPresent(byte key, ByteFloatUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeFloatIfPresent(key, mappingFunction); } } @Override - public float computeFloatIfPresentNonDefault(byte key, ByteFloatUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeFloatIfPresentNonDefault(key, mappingFunction); } } - @Override public float supplyFloatIfAbsent(byte key, FloatSupplier valueProvider) { synchronized(mutex) { return map.supplyFloatIfAbsent(key, valueProvider); } } @Override + public float computeFloatNonDefault(byte key, ByteFloatUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeFloatNonDefault(key, mappingFunction); } } + @Override + public float computeFloatIfAbsentNonDefault(byte key, Byte2FloatFunction mappingFunction) { synchronized(mutex) { return map.computeFloatIfAbsentNonDefault(key, mappingFunction); } } + @Override + public float computeFloatIfPresentNonDefault(byte key, ByteFloatUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeFloatIfPresentNonDefault(key, mappingFunction); } } + @Override public float supplyFloatIfAbsentNonDefault(byte key, FloatSupplier valueProvider) { synchronized(mutex) { return map.supplyFloatIfAbsentNonDefault(key, valueProvider); } } @Override public float mergeFloat(byte key, float value, FloatFloatUnaryOperator mappingFunction) { synchronized(mutex) { return map.mergeFloat(key, value, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/bytes/utils/maps/Byte2IntMaps.java b/src/main/java/speiger/src/collections/bytes/utils/maps/Byte2IntMaps.java index 13ab6576..78a456a6 100644 --- a/src/main/java/speiger/src/collections/bytes/utils/maps/Byte2IntMaps.java +++ b/src/main/java/speiger/src/collections/bytes/utils/maps/Byte2IntMaps.java @@ -250,18 +250,18 @@ public static class SingletonMap extends AbstractByte2IntMap { @Override public int computeInt(byte key, ByteIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntNonDefault(byte key, ByteIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int computeIntIfAbsent(byte key, Byte2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntIfAbsentNonDefault(byte key, Byte2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int computeIntIfPresent(byte key, ByteIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntIfPresentNonDefault(byte key, ByteIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int supplyIntIfAbsent(byte key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public int computeIntNonDefault(byte key, ByteIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public int computeIntIfAbsentNonDefault(byte key, Byte2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public int computeIntIfPresentNonDefault(byte key, ByteIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public int supplyIntIfAbsentNonDefault(byte key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public int mergeInt(byte key, int value, IntIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -312,18 +312,18 @@ public static class EmptyMap extends AbstractByte2IntMap { @Override public int computeInt(byte key, ByteIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntNonDefault(byte key, ByteIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int computeIntIfAbsent(byte key, Byte2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntIfAbsentNonDefault(byte key, Byte2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int computeIntIfPresent(byte key, ByteIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntIfPresentNonDefault(byte key, ByteIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int supplyIntIfAbsent(byte key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public int computeIntNonDefault(byte key, ByteIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public int computeIntIfAbsentNonDefault(byte key, Byte2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public int computeIntIfPresentNonDefault(byte key, ByteIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public int supplyIntIfAbsentNonDefault(byte key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public int mergeInt(byte key, int value, IntIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -547,18 +547,18 @@ public int get(byte key) { @Override public int computeInt(byte key, ByteIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntNonDefault(byte key, ByteIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int computeIntIfAbsent(byte key, Byte2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntIfAbsentNonDefault(byte key, Byte2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int computeIntIfPresent(byte key, ByteIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntIfPresentNonDefault(byte key, ByteIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int supplyIntIfAbsent(byte key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public int computeIntNonDefault(byte key, ByteIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public int computeIntIfAbsentNonDefault(byte key, Byte2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public int computeIntIfPresentNonDefault(byte key, ByteIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public int supplyIntIfAbsentNonDefault(byte key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public int mergeInt(byte key, int value, IntIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -955,18 +955,18 @@ public AbstractByte2IntMap setDefaultReturnValue(int v) { @Override public int computeInt(byte key, ByteIntUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeInt(key, mappingFunction); } } @Override - public int computeIntNonDefault(byte key, ByteIntUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeIntNonDefault(key, mappingFunction); } } - @Override public int computeIntIfAbsent(byte key, Byte2IntFunction mappingFunction) { synchronized(mutex) { return map.computeIntIfAbsent(key, mappingFunction); } } @Override - public int computeIntIfAbsentNonDefault(byte key, Byte2IntFunction mappingFunction) { synchronized(mutex) { return map.computeIntIfAbsentNonDefault(key, mappingFunction); } } - @Override public int computeIntIfPresent(byte key, ByteIntUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeIntIfPresent(key, mappingFunction); } } @Override - public int computeIntIfPresentNonDefault(byte key, ByteIntUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeIntIfPresentNonDefault(key, mappingFunction); } } - @Override public int supplyIntIfAbsent(byte key, IntSupplier valueProvider) { synchronized(mutex) { return map.supplyIntIfAbsent(key, valueProvider); } } @Override + public int computeIntNonDefault(byte key, ByteIntUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeIntNonDefault(key, mappingFunction); } } + @Override + public int computeIntIfAbsentNonDefault(byte key, Byte2IntFunction mappingFunction) { synchronized(mutex) { return map.computeIntIfAbsentNonDefault(key, mappingFunction); } } + @Override + public int computeIntIfPresentNonDefault(byte key, ByteIntUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeIntIfPresentNonDefault(key, mappingFunction); } } + @Override public int supplyIntIfAbsentNonDefault(byte key, IntSupplier valueProvider) { synchronized(mutex) { return map.supplyIntIfAbsentNonDefault(key, valueProvider); } } @Override public int mergeInt(byte key, int value, IntIntUnaryOperator mappingFunction) { synchronized(mutex) { return map.mergeInt(key, value, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/bytes/utils/maps/Byte2LongMaps.java b/src/main/java/speiger/src/collections/bytes/utils/maps/Byte2LongMaps.java index 7367968b..2dcde038 100644 --- a/src/main/java/speiger/src/collections/bytes/utils/maps/Byte2LongMaps.java +++ b/src/main/java/speiger/src/collections/bytes/utils/maps/Byte2LongMaps.java @@ -250,18 +250,18 @@ public static class SingletonMap extends AbstractByte2LongMap { @Override public long computeLong(byte key, ByteLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongNonDefault(byte key, ByteLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long computeLongIfAbsent(byte key, Byte2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongIfAbsentNonDefault(byte key, Byte2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long computeLongIfPresent(byte key, ByteLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongIfPresentNonDefault(byte key, ByteLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long supplyLongIfAbsent(byte key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public long computeLongNonDefault(byte key, ByteLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public long computeLongIfAbsentNonDefault(byte key, Byte2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public long computeLongIfPresentNonDefault(byte key, ByteLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public long supplyLongIfAbsentNonDefault(byte key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public long mergeLong(byte key, long value, LongLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -312,18 +312,18 @@ public static class EmptyMap extends AbstractByte2LongMap { @Override public long computeLong(byte key, ByteLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongNonDefault(byte key, ByteLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long computeLongIfAbsent(byte key, Byte2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongIfAbsentNonDefault(byte key, Byte2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long computeLongIfPresent(byte key, ByteLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongIfPresentNonDefault(byte key, ByteLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long supplyLongIfAbsent(byte key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public long computeLongNonDefault(byte key, ByteLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public long computeLongIfAbsentNonDefault(byte key, Byte2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public long computeLongIfPresentNonDefault(byte key, ByteLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public long supplyLongIfAbsentNonDefault(byte key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public long mergeLong(byte key, long value, LongLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -547,18 +547,18 @@ public long get(byte key) { @Override public long computeLong(byte key, ByteLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongNonDefault(byte key, ByteLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long computeLongIfAbsent(byte key, Byte2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongIfAbsentNonDefault(byte key, Byte2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long computeLongIfPresent(byte key, ByteLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongIfPresentNonDefault(byte key, ByteLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long supplyLongIfAbsent(byte key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public long computeLongNonDefault(byte key, ByteLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public long computeLongIfAbsentNonDefault(byte key, Byte2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public long computeLongIfPresentNonDefault(byte key, ByteLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public long supplyLongIfAbsentNonDefault(byte key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public long mergeLong(byte key, long value, LongLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -955,18 +955,18 @@ public AbstractByte2LongMap setDefaultReturnValue(long v) { @Override public long computeLong(byte key, ByteLongUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeLong(key, mappingFunction); } } @Override - public long computeLongNonDefault(byte key, ByteLongUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeLongNonDefault(key, mappingFunction); } } - @Override public long computeLongIfAbsent(byte key, Byte2LongFunction mappingFunction) { synchronized(mutex) { return map.computeLongIfAbsent(key, mappingFunction); } } @Override - public long computeLongIfAbsentNonDefault(byte key, Byte2LongFunction mappingFunction) { synchronized(mutex) { return map.computeLongIfAbsentNonDefault(key, mappingFunction); } } - @Override public long computeLongIfPresent(byte key, ByteLongUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeLongIfPresent(key, mappingFunction); } } @Override - public long computeLongIfPresentNonDefault(byte key, ByteLongUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeLongIfPresentNonDefault(key, mappingFunction); } } - @Override public long supplyLongIfAbsent(byte key, LongSupplier valueProvider) { synchronized(mutex) { return map.supplyLongIfAbsent(key, valueProvider); } } @Override + public long computeLongNonDefault(byte key, ByteLongUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeLongNonDefault(key, mappingFunction); } } + @Override + public long computeLongIfAbsentNonDefault(byte key, Byte2LongFunction mappingFunction) { synchronized(mutex) { return map.computeLongIfAbsentNonDefault(key, mappingFunction); } } + @Override + public long computeLongIfPresentNonDefault(byte key, ByteLongUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeLongIfPresentNonDefault(key, mappingFunction); } } + @Override public long supplyLongIfAbsentNonDefault(byte key, LongSupplier valueProvider) { synchronized(mutex) { return map.supplyLongIfAbsentNonDefault(key, valueProvider); } } @Override public long mergeLong(byte key, long value, LongLongUnaryOperator mappingFunction) { synchronized(mutex) { return map.mergeLong(key, value, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/bytes/utils/maps/Byte2ObjectMaps.java b/src/main/java/speiger/src/collections/bytes/utils/maps/Byte2ObjectMaps.java index 39b484c5..d926d88e 100644 --- a/src/main/java/speiger/src/collections/bytes/utils/maps/Byte2ObjectMaps.java +++ b/src/main/java/speiger/src/collections/bytes/utils/maps/Byte2ObjectMaps.java @@ -266,20 +266,12 @@ public static class SingletonMap extends AbstractByte2ObjectMap { @Override public V compute(byte key, ByteObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeNonDefault(byte key, ByteObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V computeIfAbsent(byte key, ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeIfAbsentNonDefault(byte key, ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V computeIfPresent(byte key, ByteObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeIfPresentNonDefault(byte key, ByteObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V supplyIfAbsent(byte key, ObjectSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public V supplyIfAbsentNonDefault(byte key, ObjectSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public V merge(byte key, V value, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override public void mergeAll(Byte2ObjectMap m, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -325,20 +317,12 @@ public static class EmptyMap extends AbstractByte2ObjectMap { @Override public V compute(byte key, ByteObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeNonDefault(byte key, ByteObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V computeIfAbsent(byte key, ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeIfAbsentNonDefault(byte key, ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V computeIfPresent(byte key, ByteObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeIfPresentNonDefault(byte key, ByteObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V supplyIfAbsent(byte key, ObjectSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public V supplyIfAbsentNonDefault(byte key, ObjectSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public V merge(byte key, V value, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override public void mergeAll(Byte2ObjectMap m, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -561,20 +545,12 @@ public V get(byte key) { @Override public V compute(byte key, ByteObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeNonDefault(byte key, ByteObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V computeIfAbsent(byte key, ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeIfAbsentNonDefault(byte key, ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V computeIfPresent(byte key, ByteObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeIfPresentNonDefault(byte key, ByteObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V supplyIfAbsent(byte key, ObjectSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public V supplyIfAbsentNonDefault(byte key, ObjectSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public V merge(byte key, V value, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override public void mergeAll(Byte2ObjectMap m, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -968,20 +944,12 @@ public AbstractByte2ObjectMap setDefaultReturnValue(V v) { @Override public V compute(byte key, ByteObjectUnaryOperator mappingFunction) { synchronized(mutex) { return map.compute(key, mappingFunction); } } @Override - public V computeNonDefault(byte key, ByteObjectUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeNonDefault(key, mappingFunction); } } - @Override public V computeIfAbsent(byte key, ByteFunction mappingFunction) { synchronized(mutex) { return map.computeIfAbsent(key, mappingFunction); } } @Override - public V computeIfAbsentNonDefault(byte key, ByteFunction mappingFunction) { synchronized(mutex) { return map.computeIfAbsentNonDefault(key, mappingFunction); } } - @Override public V computeIfPresent(byte key, ByteObjectUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeIfPresent(key, mappingFunction); } } @Override - public V computeIfPresentNonDefault(byte key, ByteObjectUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeIfPresentNonDefault(key, mappingFunction); } } - @Override public V supplyIfAbsent(byte key, ObjectSupplier valueProvider) { synchronized(mutex) { return map.supplyIfAbsent(key, valueProvider); } } @Override - public V supplyIfAbsentNonDefault(byte key, ObjectSupplier valueProvider) { synchronized(mutex) { return map.supplyIfAbsentNonDefault(key, valueProvider); } } - @Override public V merge(byte key, V value, ObjectObjectUnaryOperator mappingFunction) { synchronized(mutex) { return map.merge(key, value, mappingFunction); } } @Override public void mergeAll(Byte2ObjectMap m, ObjectObjectUnaryOperator mappingFunction) { synchronized(mutex) { map.mergeAll(m, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/bytes/utils/maps/Byte2ShortMaps.java b/src/main/java/speiger/src/collections/bytes/utils/maps/Byte2ShortMaps.java index cf3e17a5..0c73b7e3 100644 --- a/src/main/java/speiger/src/collections/bytes/utils/maps/Byte2ShortMaps.java +++ b/src/main/java/speiger/src/collections/bytes/utils/maps/Byte2ShortMaps.java @@ -250,18 +250,18 @@ public static class SingletonMap extends AbstractByte2ShortMap { @Override public short computeShort(byte key, ByteShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortNonDefault(byte key, ByteShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short computeShortIfAbsent(byte key, Byte2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortIfAbsentNonDefault(byte key, Byte2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short computeShortIfPresent(byte key, ByteShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortIfPresentNonDefault(byte key, ByteShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short supplyShortIfAbsent(byte key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public short computeShortNonDefault(byte key, ByteShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public short computeShortIfAbsentNonDefault(byte key, Byte2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public short computeShortIfPresentNonDefault(byte key, ByteShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public short supplyShortIfAbsentNonDefault(byte key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public short mergeShort(byte key, short value, ShortShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -312,18 +312,18 @@ public static class EmptyMap extends AbstractByte2ShortMap { @Override public short computeShort(byte key, ByteShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortNonDefault(byte key, ByteShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short computeShortIfAbsent(byte key, Byte2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortIfAbsentNonDefault(byte key, Byte2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short computeShortIfPresent(byte key, ByteShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortIfPresentNonDefault(byte key, ByteShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short supplyShortIfAbsent(byte key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public short computeShortNonDefault(byte key, ByteShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public short computeShortIfAbsentNonDefault(byte key, Byte2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public short computeShortIfPresentNonDefault(byte key, ByteShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public short supplyShortIfAbsentNonDefault(byte key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public short mergeShort(byte key, short value, ShortShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -547,18 +547,18 @@ public short get(byte key) { @Override public short computeShort(byte key, ByteShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortNonDefault(byte key, ByteShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short computeShortIfAbsent(byte key, Byte2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortIfAbsentNonDefault(byte key, Byte2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short computeShortIfPresent(byte key, ByteShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortIfPresentNonDefault(byte key, ByteShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short supplyShortIfAbsent(byte key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public short computeShortNonDefault(byte key, ByteShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public short computeShortIfAbsentNonDefault(byte key, Byte2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public short computeShortIfPresentNonDefault(byte key, ByteShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public short supplyShortIfAbsentNonDefault(byte key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public short mergeShort(byte key, short value, ShortShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -955,18 +955,18 @@ public AbstractByte2ShortMap setDefaultReturnValue(short v) { @Override public short computeShort(byte key, ByteShortUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeShort(key, mappingFunction); } } @Override - public short computeShortNonDefault(byte key, ByteShortUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeShortNonDefault(key, mappingFunction); } } - @Override public short computeShortIfAbsent(byte key, Byte2ShortFunction mappingFunction) { synchronized(mutex) { return map.computeShortIfAbsent(key, mappingFunction); } } @Override - public short computeShortIfAbsentNonDefault(byte key, Byte2ShortFunction mappingFunction) { synchronized(mutex) { return map.computeShortIfAbsentNonDefault(key, mappingFunction); } } - @Override public short computeShortIfPresent(byte key, ByteShortUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeShortIfPresent(key, mappingFunction); } } @Override - public short computeShortIfPresentNonDefault(byte key, ByteShortUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeShortIfPresentNonDefault(key, mappingFunction); } } - @Override public short supplyShortIfAbsent(byte key, ShortSupplier valueProvider) { synchronized(mutex) { return map.supplyShortIfAbsent(key, valueProvider); } } @Override + public short computeShortNonDefault(byte key, ByteShortUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeShortNonDefault(key, mappingFunction); } } + @Override + public short computeShortIfAbsentNonDefault(byte key, Byte2ShortFunction mappingFunction) { synchronized(mutex) { return map.computeShortIfAbsentNonDefault(key, mappingFunction); } } + @Override + public short computeShortIfPresentNonDefault(byte key, ByteShortUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeShortIfPresentNonDefault(key, mappingFunction); } } + @Override public short supplyShortIfAbsentNonDefault(byte key, ShortSupplier valueProvider) { synchronized(mutex) { return map.supplyShortIfAbsentNonDefault(key, valueProvider); } } @Override public short mergeShort(byte key, short value, ShortShortUnaryOperator mappingFunction) { synchronized(mutex) { return map.mergeShort(key, value, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/chars/functions/CharSupplier.java b/src/main/java/speiger/src/collections/chars/functions/CharSupplier.java index 8d675dce..e4c6c66c 100644 --- a/src/main/java/speiger/src/collections/chars/functions/CharSupplier.java +++ b/src/main/java/speiger/src/collections/chars/functions/CharSupplier.java @@ -8,5 +8,5 @@ public interface CharSupplier /** * @return the supplied value */ - public char getAsInt(); + public char getAsChar(); } \ No newline at end of file diff --git a/src/main/java/speiger/src/collections/chars/lists/AbstractCharList.java b/src/main/java/speiger/src/collections/chars/lists/AbstractCharList.java index ad1ffd82..db993971 100644 --- a/src/main/java/speiger/src/collections/chars/lists/AbstractCharList.java +++ b/src/main/java/speiger/src/collections/chars/lists/AbstractCharList.java @@ -12,6 +12,7 @@ import speiger.src.collections.chars.collections.CharCollection; import speiger.src.collections.chars.collections.CharIterator; import speiger.src.collections.chars.collections.CharSplititerator; +import speiger.src.collections.ints.lists.IntList; import speiger.src.collections.chars.utils.CharSplititerators; import speiger.src.collections.utils.SanityChecks; @@ -205,13 +206,23 @@ public CharIterator iterator() { public CharListIterator listIterator() { return listIterator(0); } - + @Override public CharListIterator listIterator(int index) { if(index < 0 || index > size()) throw new IndexOutOfBoundsException(); return new CharListIter(index); } + @Override + public CharListIterator indexedIterator(int...indecies) { + return new IndexedIterator(indecies); + } + + @Override + public CharListIterator indexedIterator(IntList indecies) { + return new ListIndexedIterator(indecies); + } + @Override public void size(int size) { while(size > size()) add((char)0); @@ -566,7 +577,153 @@ public int back(int amount) { } } } + + private class ListIndexedIterator implements CharListIterator { + IntList indecies; + int index; + int lastReturned = -1; + + ListIndexedIterator(IntList indecies) { + this.indecies = indecies; + } + + @Override + public boolean hasNext() { + return index < indecies.size(); + } + + @Override + public char nextChar() { + if(!hasNext()) throw new NoSuchElementException(); + int i = index++; + return getChar((lastReturned = indecies.getInt(i))); + } + + @Override + public boolean hasPrevious() { + return index > 0; + } + + @Override + public char previousChar() { + if(!hasPrevious()) throw new NoSuchElementException(); + index--; + return getChar((lastReturned = indecies.getInt(index))); + } + + @Override + public int nextIndex() { + return index; + } + + @Override + public int previousIndex() { + return index-1; + } + + @Override + public void remove() { throw new UnsupportedOperationException(); } + @Override + public void add(char e) { throw new UnsupportedOperationException(); } + + @Override + public void set(char e) { + if(lastReturned == -1) throw new IllegalStateException(); + AbstractCharList.this.set(lastReturned, e); + } + + @Override + public int skip(int amount) { + if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed"); + int steps = Math.min(amount, indecies.size() - index); + index += steps; + if(steps > 0) lastReturned = Math.min(index-1, indecies.size()-1); + return steps; + } + + @Override + public int back(int amount) { + if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed"); + int steps = Math.min(amount, index); + index -= steps; + if(steps > 0) lastReturned = Math.max(index, 0); + return steps; + } + } + + private class IndexedIterator implements CharListIterator { + int[] indecies; + int index; + int lastReturned = -1; + + IndexedIterator(int[] indecies) { + this.indecies = indecies; + } + @Override + public boolean hasNext() { + return index < indecies.length; + } + + @Override + public char nextChar() { + if(!hasNext()) throw new NoSuchElementException(); + int i = index++; + return getChar((lastReturned = indecies[i])); + } + + @Override + public boolean hasPrevious() { + return index > 0; + } + + @Override + public char previousChar() { + if(!hasPrevious()) throw new NoSuchElementException(); + index--; + return getChar((lastReturned = indecies[index])); + } + + @Override + public int nextIndex() { + return index; + } + + @Override + public int previousIndex() { + return index-1; + } + + @Override + public void remove() { throw new UnsupportedOperationException(); } + @Override + public void add(char e) { throw new UnsupportedOperationException(); } + + @Override + public void set(char e) { + if(lastReturned == -1) throw new IllegalStateException(); + AbstractCharList.this.set(lastReturned, e); + } + + @Override + public int skip(int amount) { + if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed"); + int steps = Math.min(amount, indecies.length - index); + index += steps; + if(steps > 0) lastReturned = Math.min(index-1, indecies.length-1); + return steps; + } + + @Override + public int back(int amount) { + if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed"); + int steps = Math.min(amount, index); + index -= steps; + if(steps > 0) lastReturned = Math.max(index, 0); + return steps; + } + } + private class CharListIter implements CharListIterator { int index; int lastReturned = -1; @@ -644,7 +801,7 @@ public int back(int amount) { if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed"); int steps = Math.min(amount, index); index -= steps; - if(steps > 0) lastReturned = Math.min(index, size()-1); + if(steps > 0) lastReturned = Math.max(index, 0); return steps; } } diff --git a/src/main/java/speiger/src/collections/chars/lists/CharList.java b/src/main/java/speiger/src/collections/chars/lists/CharList.java index b2781896..6d86715c 100644 --- a/src/main/java/speiger/src/collections/chars/lists/CharList.java +++ b/src/main/java/speiger/src/collections/chars/lists/CharList.java @@ -14,6 +14,7 @@ import speiger.src.collections.chars.functions.CharComparator; import speiger.src.collections.chars.utils.CharArrays; import speiger.src.collections.chars.utils.CharLists; +import speiger.src.collections.ints.lists.IntList; import speiger.src.collections.chars.utils.CharSplititerators; import speiger.src.collections.utils.SanityChecks; @@ -342,6 +343,24 @@ public default void forEachIndexed(IntCharConsumer action) { @Override public CharListIterator listIterator(int index); + /** + * Creates a Iterator that follows the indecies provided.
+ * For example if the Lists Contents is:
-1, 0 1
and the indecies are:
0, 1, 2, 2, 1, 0
+ * then the iterator will return the following values:
-1, 0, 1, 1, 0, -1 + * @param indecies that should be used for the iteration. + * @return a custom indexed iterator + */ + public CharListIterator indexedIterator(int...indecies); + + /** + * Creates a Iterator that follows the indecies provided.
+ * For example if the Lists Contents is:
-1, 0 1
and the indecies are:
0, 1, 2, 2, 1, 0
+ * then the iterator will return the following values:
-1, 0, 1, 1, 0, -1 + * @param indecies that should be used for the iteration. + * @return a custom indexed iterator + */ + public CharListIterator indexedIterator(IntList indecies); + /** * A Type-Specific List of subList * @see java.util.List#subList(int, int) diff --git a/src/main/java/speiger/src/collections/chars/maps/abstracts/AbstractChar2BooleanMap.java b/src/main/java/speiger/src/collections/chars/maps/abstracts/AbstractChar2BooleanMap.java index 441bfa8a..f1df3557 100644 --- a/src/main/java/speiger/src/collections/chars/maps/abstracts/AbstractChar2BooleanMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/abstracts/AbstractChar2BooleanMap.java @@ -151,6 +151,39 @@ public boolean computeBoolean(char key, CharBooleanUnaryOperator mappingFunction return newValue; } + @Override + public boolean computeBooleanIfAbsent(char key, CharPredicate mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(!containsKey(key)) { + boolean newValue = mappingFunction.test(key); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public boolean supplyBooleanIfAbsent(char key, BooleanSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + if(!containsKey(key)) { + boolean newValue = valueProvider.getAsBoolean(); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public boolean computeBooleanIfPresent(char key, CharBooleanUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(containsKey(key)) { + boolean newValue = mappingFunction.applyAsBoolean(key, get(key)); + put(key, newValue); + return newValue; + } + return getDefaultReturnValue(); + } + @Override public boolean computeBooleanNonDefault(char key, CharBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -167,17 +200,6 @@ public boolean computeBooleanNonDefault(char key, CharBooleanUnaryOperator mappi return newValue; } - @Override - public boolean computeBooleanIfAbsent(char key, CharPredicate mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(!containsKey(key)) { - boolean newValue = mappingFunction.test(key); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public boolean computeBooleanIfAbsentNonDefault(char key, CharPredicate mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -192,17 +214,6 @@ public boolean computeBooleanIfAbsentNonDefault(char key, CharPredicate mappingF return value; } - @Override - public boolean supplyBooleanIfAbsent(char key, BooleanSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - if(!containsKey(key)) { - boolean newValue = valueProvider.getAsBoolean(); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public boolean supplyBooleanIfAbsentNonDefault(char key, BooleanSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -217,17 +228,6 @@ public boolean supplyBooleanIfAbsentNonDefault(char key, BooleanSupplier valuePr return value; } - @Override - public boolean computeBooleanIfPresent(char key, CharBooleanUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(containsKey(key)) { - boolean newValue = mappingFunction.applyAsBoolean(key, get(key)); - put(key, newValue); - return newValue; - } - return getDefaultReturnValue(); - } - @Override public boolean computeBooleanIfPresentNonDefault(char key, CharBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/chars/maps/abstracts/AbstractChar2ByteMap.java b/src/main/java/speiger/src/collections/chars/maps/abstracts/AbstractChar2ByteMap.java index 11751864..7e7e4bca 100644 --- a/src/main/java/speiger/src/collections/chars/maps/abstracts/AbstractChar2ByteMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/abstracts/AbstractChar2ByteMap.java @@ -157,6 +157,39 @@ public byte computeByte(char key, CharByteUnaryOperator mappingFunction) { return newValue; } + @Override + public byte computeByteIfAbsent(char key, Char2ByteFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(!containsKey(key)) { + byte newValue = mappingFunction.applyAsByte(key); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public byte supplyByteIfAbsent(char key, ByteSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + if(!containsKey(key)) { + byte newValue = valueProvider.getAsByte(); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public byte computeByteIfPresent(char key, CharByteUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(containsKey(key)) { + byte newValue = mappingFunction.applyAsByte(key, get(key)); + put(key, newValue); + return newValue; + } + return getDefaultReturnValue(); + } + @Override public byte computeByteNonDefault(char key, CharByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -173,17 +206,6 @@ public byte computeByteNonDefault(char key, CharByteUnaryOperator mappingFunctio return newValue; } - @Override - public byte computeByteIfAbsent(char key, Char2ByteFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(!containsKey(key)) { - byte newValue = mappingFunction.applyAsByte(key); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public byte computeByteIfAbsentNonDefault(char key, Char2ByteFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -198,23 +220,12 @@ public byte computeByteIfAbsentNonDefault(char key, Char2ByteFunction mappingFun return value; } - @Override - public byte supplyByteIfAbsent(char key, ByteSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - if(!containsKey(key)) { - byte newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public byte supplyByteIfAbsentNonDefault(char key, ByteSupplier valueProvider) { Objects.requireNonNull(valueProvider); byte value; if((value = get(key)) == getDefaultReturnValue() || !containsKey(key)) { - byte newValue = valueProvider.getAsInt(); + byte newValue = valueProvider.getAsByte(); if(newValue != getDefaultReturnValue()) { put(key, newValue); return newValue; @@ -223,17 +234,6 @@ public byte supplyByteIfAbsentNonDefault(char key, ByteSupplier valueProvider) { return value; } - @Override - public byte computeByteIfPresent(char key, CharByteUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(containsKey(key)) { - byte newValue = mappingFunction.applyAsByte(key, get(key)); - put(key, newValue); - return newValue; - } - return getDefaultReturnValue(); - } - @Override public byte computeByteIfPresentNonDefault(char key, CharByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/chars/maps/abstracts/AbstractChar2CharMap.java b/src/main/java/speiger/src/collections/chars/maps/abstracts/AbstractChar2CharMap.java index b676f32b..9d6a53d2 100644 --- a/src/main/java/speiger/src/collections/chars/maps/abstracts/AbstractChar2CharMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/abstracts/AbstractChar2CharMap.java @@ -155,6 +155,39 @@ public char computeChar(char key, CharCharUnaryOperator mappingFunction) { return newValue; } + @Override + public char computeCharIfAbsent(char key, CharUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(!containsKey(key)) { + char newValue = mappingFunction.applyAsChar(key); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public char supplyCharIfAbsent(char key, CharSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + if(!containsKey(key)) { + char newValue = valueProvider.getAsChar(); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public char computeCharIfPresent(char key, CharCharUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(containsKey(key)) { + char newValue = mappingFunction.applyAsChar(key, get(key)); + put(key, newValue); + return newValue; + } + return getDefaultReturnValue(); + } + @Override public char computeCharNonDefault(char key, CharCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -171,17 +204,6 @@ public char computeCharNonDefault(char key, CharCharUnaryOperator mappingFunctio return newValue; } - @Override - public char computeCharIfAbsent(char key, CharUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(!containsKey(key)) { - char newValue = mappingFunction.applyAsChar(key); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public char computeCharIfAbsentNonDefault(char key, CharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -196,23 +218,12 @@ public char computeCharIfAbsentNonDefault(char key, CharUnaryOperator mappingFun return value; } - @Override - public char supplyCharIfAbsent(char key, CharSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - if(!containsKey(key)) { - char newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public char supplyCharIfAbsentNonDefault(char key, CharSupplier valueProvider) { Objects.requireNonNull(valueProvider); char value; if((value = get(key)) == getDefaultReturnValue() || !containsKey(key)) { - char newValue = valueProvider.getAsInt(); + char newValue = valueProvider.getAsChar(); if(newValue != getDefaultReturnValue()) { put(key, newValue); return newValue; @@ -221,17 +232,6 @@ public char supplyCharIfAbsentNonDefault(char key, CharSupplier valueProvider) { return value; } - @Override - public char computeCharIfPresent(char key, CharCharUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(containsKey(key)) { - char newValue = mappingFunction.applyAsChar(key, get(key)); - put(key, newValue); - return newValue; - } - return getDefaultReturnValue(); - } - @Override public char computeCharIfPresentNonDefault(char key, CharCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/chars/maps/abstracts/AbstractChar2DoubleMap.java b/src/main/java/speiger/src/collections/chars/maps/abstracts/AbstractChar2DoubleMap.java index 8a365291..acc6d857 100644 --- a/src/main/java/speiger/src/collections/chars/maps/abstracts/AbstractChar2DoubleMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/abstracts/AbstractChar2DoubleMap.java @@ -157,6 +157,39 @@ public double computeDouble(char key, CharDoubleUnaryOperator mappingFunction) { return newValue; } + @Override + public double computeDoubleIfAbsent(char key, Char2DoubleFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(!containsKey(key)) { + double newValue = mappingFunction.applyAsDouble(key); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public double supplyDoubleIfAbsent(char key, DoubleSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + if(!containsKey(key)) { + double newValue = valueProvider.getAsDouble(); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public double computeDoubleIfPresent(char key, CharDoubleUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(containsKey(key)) { + double newValue = mappingFunction.applyAsDouble(key, get(key)); + put(key, newValue); + return newValue; + } + return getDefaultReturnValue(); + } + @Override public double computeDoubleNonDefault(char key, CharDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -173,17 +206,6 @@ public double computeDoubleNonDefault(char key, CharDoubleUnaryOperator mappingF return newValue; } - @Override - public double computeDoubleIfAbsent(char key, Char2DoubleFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(!containsKey(key)) { - double newValue = mappingFunction.applyAsDouble(key); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public double computeDoubleIfAbsentNonDefault(char key, Char2DoubleFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -198,17 +220,6 @@ public double computeDoubleIfAbsentNonDefault(char key, Char2DoubleFunction mapp return value; } - @Override - public double supplyDoubleIfAbsent(char key, DoubleSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - if(!containsKey(key)) { - double newValue = valueProvider.getAsDouble(); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public double supplyDoubleIfAbsentNonDefault(char key, DoubleSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -223,17 +234,6 @@ public double supplyDoubleIfAbsentNonDefault(char key, DoubleSupplier valueProvi return value; } - @Override - public double computeDoubleIfPresent(char key, CharDoubleUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(containsKey(key)) { - double newValue = mappingFunction.applyAsDouble(key, get(key)); - put(key, newValue); - return newValue; - } - return getDefaultReturnValue(); - } - @Override public double computeDoubleIfPresentNonDefault(char key, CharDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/chars/maps/abstracts/AbstractChar2FloatMap.java b/src/main/java/speiger/src/collections/chars/maps/abstracts/AbstractChar2FloatMap.java index 87cea2e6..358202b7 100644 --- a/src/main/java/speiger/src/collections/chars/maps/abstracts/AbstractChar2FloatMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/abstracts/AbstractChar2FloatMap.java @@ -157,6 +157,39 @@ public float computeFloat(char key, CharFloatUnaryOperator mappingFunction) { return newValue; } + @Override + public float computeFloatIfAbsent(char key, Char2FloatFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(!containsKey(key)) { + float newValue = mappingFunction.applyAsFloat(key); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public float supplyFloatIfAbsent(char key, FloatSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + if(!containsKey(key)) { + float newValue = valueProvider.getAsFloat(); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public float computeFloatIfPresent(char key, CharFloatUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(containsKey(key)) { + float newValue = mappingFunction.applyAsFloat(key, get(key)); + put(key, newValue); + return newValue; + } + return getDefaultReturnValue(); + } + @Override public float computeFloatNonDefault(char key, CharFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -173,17 +206,6 @@ public float computeFloatNonDefault(char key, CharFloatUnaryOperator mappingFunc return newValue; } - @Override - public float computeFloatIfAbsent(char key, Char2FloatFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(!containsKey(key)) { - float newValue = mappingFunction.applyAsFloat(key); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public float computeFloatIfAbsentNonDefault(char key, Char2FloatFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -198,23 +220,12 @@ public float computeFloatIfAbsentNonDefault(char key, Char2FloatFunction mapping return value; } - @Override - public float supplyFloatIfAbsent(char key, FloatSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - if(!containsKey(key)) { - float newValue = valueProvider.getAsDouble(); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public float supplyFloatIfAbsentNonDefault(char key, FloatSupplier valueProvider) { Objects.requireNonNull(valueProvider); float value; if((value = get(key)) == getDefaultReturnValue() || !containsKey(key)) { - float newValue = valueProvider.getAsDouble(); + float newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) != Float.floatToIntBits(getDefaultReturnValue())) { put(key, newValue); return newValue; @@ -223,17 +234,6 @@ public float supplyFloatIfAbsentNonDefault(char key, FloatSupplier valueProvider return value; } - @Override - public float computeFloatIfPresent(char key, CharFloatUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(containsKey(key)) { - float newValue = mappingFunction.applyAsFloat(key, get(key)); - put(key, newValue); - return newValue; - } - return getDefaultReturnValue(); - } - @Override public float computeFloatIfPresentNonDefault(char key, CharFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/chars/maps/abstracts/AbstractChar2IntMap.java b/src/main/java/speiger/src/collections/chars/maps/abstracts/AbstractChar2IntMap.java index 941b3e49..34c7a3f2 100644 --- a/src/main/java/speiger/src/collections/chars/maps/abstracts/AbstractChar2IntMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/abstracts/AbstractChar2IntMap.java @@ -157,6 +157,39 @@ public int computeInt(char key, CharIntUnaryOperator mappingFunction) { return newValue; } + @Override + public int computeIntIfAbsent(char key, Char2IntFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(!containsKey(key)) { + int newValue = mappingFunction.applyAsInt(key); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public int supplyIntIfAbsent(char key, IntSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + if(!containsKey(key)) { + int newValue = valueProvider.getAsInt(); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public int computeIntIfPresent(char key, CharIntUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(containsKey(key)) { + int newValue = mappingFunction.applyAsInt(key, get(key)); + put(key, newValue); + return newValue; + } + return getDefaultReturnValue(); + } + @Override public int computeIntNonDefault(char key, CharIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -173,17 +206,6 @@ public int computeIntNonDefault(char key, CharIntUnaryOperator mappingFunction) return newValue; } - @Override - public int computeIntIfAbsent(char key, Char2IntFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(!containsKey(key)) { - int newValue = mappingFunction.applyAsInt(key); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public int computeIntIfAbsentNonDefault(char key, Char2IntFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -198,17 +220,6 @@ public int computeIntIfAbsentNonDefault(char key, Char2IntFunction mappingFuncti return value; } - @Override - public int supplyIntIfAbsent(char key, IntSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - if(!containsKey(key)) { - int newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public int supplyIntIfAbsentNonDefault(char key, IntSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -223,17 +234,6 @@ public int supplyIntIfAbsentNonDefault(char key, IntSupplier valueProvider) { return value; } - @Override - public int computeIntIfPresent(char key, CharIntUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(containsKey(key)) { - int newValue = mappingFunction.applyAsInt(key, get(key)); - put(key, newValue); - return newValue; - } - return getDefaultReturnValue(); - } - @Override public int computeIntIfPresentNonDefault(char key, CharIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/chars/maps/abstracts/AbstractChar2LongMap.java b/src/main/java/speiger/src/collections/chars/maps/abstracts/AbstractChar2LongMap.java index ca1ea4a7..b6013f65 100644 --- a/src/main/java/speiger/src/collections/chars/maps/abstracts/AbstractChar2LongMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/abstracts/AbstractChar2LongMap.java @@ -157,6 +157,39 @@ public long computeLong(char key, CharLongUnaryOperator mappingFunction) { return newValue; } + @Override + public long computeLongIfAbsent(char key, Char2LongFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(!containsKey(key)) { + long newValue = mappingFunction.applyAsLong(key); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public long supplyLongIfAbsent(char key, LongSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + if(!containsKey(key)) { + long newValue = valueProvider.getAsLong(); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public long computeLongIfPresent(char key, CharLongUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(containsKey(key)) { + long newValue = mappingFunction.applyAsLong(key, get(key)); + put(key, newValue); + return newValue; + } + return getDefaultReturnValue(); + } + @Override public long computeLongNonDefault(char key, CharLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -173,17 +206,6 @@ public long computeLongNonDefault(char key, CharLongUnaryOperator mappingFunctio return newValue; } - @Override - public long computeLongIfAbsent(char key, Char2LongFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(!containsKey(key)) { - long newValue = mappingFunction.applyAsLong(key); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public long computeLongIfAbsentNonDefault(char key, Char2LongFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -198,17 +220,6 @@ public long computeLongIfAbsentNonDefault(char key, Char2LongFunction mappingFun return value; } - @Override - public long supplyLongIfAbsent(char key, LongSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - if(!containsKey(key)) { - long newValue = valueProvider.getAsLong(); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public long supplyLongIfAbsentNonDefault(char key, LongSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -223,17 +234,6 @@ public long supplyLongIfAbsentNonDefault(char key, LongSupplier valueProvider) { return value; } - @Override - public long computeLongIfPresent(char key, CharLongUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(containsKey(key)) { - long newValue = mappingFunction.applyAsLong(key, get(key)); - put(key, newValue); - return newValue; - } - return getDefaultReturnValue(); - } - @Override public long computeLongIfPresentNonDefault(char key, CharLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/chars/maps/abstracts/AbstractChar2ObjectMap.java b/src/main/java/speiger/src/collections/chars/maps/abstracts/AbstractChar2ObjectMap.java index 75ad7840..97b3cdce 100644 --- a/src/main/java/speiger/src/collections/chars/maps/abstracts/AbstractChar2ObjectMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/abstracts/AbstractChar2ObjectMap.java @@ -159,22 +159,6 @@ public V compute(char key, CharObjectUnaryOperator mappingFunction) { return newValue; } - @Override - public V computeNonDefault(char key, CharObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - V value = get(key); - V newValue = mappingFunction.apply(key, value); - if(Objects.equals(newValue, getDefaultReturnValue())) { - if(!Objects.equals(value, getDefaultReturnValue()) || containsKey(key)) { - remove(key); - return getDefaultReturnValue(); - } - return getDefaultReturnValue(); - } - put(key, newValue); - return newValue; - } - @Override public V computeIfAbsent(char key, CharFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -189,20 +173,6 @@ public V computeIfAbsent(char key, CharFunction mappingFunction) { return value; } - @Override - public V computeIfAbsentNonDefault(char key, CharFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - V value; - if((value = get(key)) == getDefaultReturnValue() || !containsKey(key)) { - V newValue = mappingFunction.apply(key); - if(!Objects.equals(newValue, getDefaultReturnValue())) { - put(key, newValue); - return newValue; - } - } - return value; - } - @Override public V supplyIfAbsent(char key, ObjectSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -217,20 +187,6 @@ public V supplyIfAbsent(char key, ObjectSupplier valueProvider) { return value; } - @Override - public V supplyIfAbsentNonDefault(char key, ObjectSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - V value; - if((value = get(key)) == getDefaultReturnValue() || !containsKey(key)) { - V newValue = valueProvider.get(); - if(!Objects.equals(newValue, getDefaultReturnValue())) { - put(key, newValue); - return newValue; - } - } - return value; - } - @Override public V computeIfPresent(char key, CharObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -246,21 +202,6 @@ public V computeIfPresent(char key, CharObjectUnaryOperator mappingFunction) return getDefaultReturnValue(); } - @Override - public V computeIfPresentNonDefault(char key, CharObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - V value; - if(!Objects.equals((value = get(key)), getDefaultReturnValue()) || containsKey(key)) { - V newValue = mappingFunction.apply(key, value); - if(!Objects.equals(newValue, getDefaultReturnValue())) { - put(key, newValue); - return newValue; - } - remove(key); - } - return getDefaultReturnValue(); - } - @Override public V merge(char key, V value, ObjectObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/chars/maps/abstracts/AbstractChar2ShortMap.java b/src/main/java/speiger/src/collections/chars/maps/abstracts/AbstractChar2ShortMap.java index 7c506bbe..56518fcd 100644 --- a/src/main/java/speiger/src/collections/chars/maps/abstracts/AbstractChar2ShortMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/abstracts/AbstractChar2ShortMap.java @@ -157,6 +157,39 @@ public short computeShort(char key, CharShortUnaryOperator mappingFunction) { return newValue; } + @Override + public short computeShortIfAbsent(char key, Char2ShortFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(!containsKey(key)) { + short newValue = mappingFunction.applyAsShort(key); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public short supplyShortIfAbsent(char key, ShortSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + if(!containsKey(key)) { + short newValue = valueProvider.getAsShort(); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public short computeShortIfPresent(char key, CharShortUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(containsKey(key)) { + short newValue = mappingFunction.applyAsShort(key, get(key)); + put(key, newValue); + return newValue; + } + return getDefaultReturnValue(); + } + @Override public short computeShortNonDefault(char key, CharShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -173,17 +206,6 @@ public short computeShortNonDefault(char key, CharShortUnaryOperator mappingFunc return newValue; } - @Override - public short computeShortIfAbsent(char key, Char2ShortFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(!containsKey(key)) { - short newValue = mappingFunction.applyAsShort(key); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public short computeShortIfAbsentNonDefault(char key, Char2ShortFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -198,23 +220,12 @@ public short computeShortIfAbsentNonDefault(char key, Char2ShortFunction mapping return value; } - @Override - public short supplyShortIfAbsent(char key, ShortSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - if(!containsKey(key)) { - short newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public short supplyShortIfAbsentNonDefault(char key, ShortSupplier valueProvider) { Objects.requireNonNull(valueProvider); short value; if((value = get(key)) == getDefaultReturnValue() || !containsKey(key)) { - short newValue = valueProvider.getAsInt(); + short newValue = valueProvider.getAsShort(); if(newValue != getDefaultReturnValue()) { put(key, newValue); return newValue; @@ -223,17 +234,6 @@ public short supplyShortIfAbsentNonDefault(char key, ShortSupplier valueProvider return value; } - @Override - public short computeShortIfPresent(char key, CharShortUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(containsKey(key)) { - short newValue = mappingFunction.applyAsShort(key, get(key)); - put(key, newValue); - return newValue; - } - return getDefaultReturnValue(); - } - @Override public short computeShortIfPresentNonDefault(char key, CharShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/concurrent/Char2BooleanConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/concurrent/Char2BooleanConcurrentOpenHashMap.java index 4a691a34..5695aa30 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/concurrent/Char2BooleanConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/concurrent/Char2BooleanConcurrentOpenHashMap.java @@ -438,13 +438,6 @@ public boolean computeBoolean(char key, CharBooleanUnaryOperator mappingFunction return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public boolean computeBooleanNonDefault(char key, CharBooleanUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public boolean computeBooleanIfAbsent(char key, CharPredicate mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -452,13 +445,6 @@ public boolean computeBooleanIfAbsent(char key, CharPredicate mappingFunction) { return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public boolean computeBooleanIfAbsentNonDefault(char key, CharPredicate mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public boolean supplyBooleanIfAbsent(char key, BooleanSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -467,17 +453,31 @@ public boolean supplyBooleanIfAbsent(char key, BooleanSupplier valueProvider) { } @Override - public boolean supplyBooleanIfAbsentNonDefault(char key, BooleanSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public boolean computeBooleanIfPresent(char key, CharBooleanUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); + return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } @Override - public boolean computeBooleanIfPresent(char key, CharBooleanUnaryOperator mappingFunction) { + public boolean computeBooleanNonDefault(char key, CharBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).computeIfPresent(hash, key, mappingFunction); + return getSegment(hash).computeNonDefault(hash, key, mappingFunction); + } + + @Override + public boolean computeBooleanIfAbsentNonDefault(char key, CharPredicate mappingFunction) { + Objects.requireNonNull(mappingFunction); + int hash = getHashCode(key); + return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); + } + + @Override + public boolean supplyBooleanIfAbsentNonDefault(char key, BooleanSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + int hash = getHashCode(key); + return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); } @Override @@ -2032,35 +2032,29 @@ protected boolean compute(int hash, char key, CharBooleanUnaryOperator mappingFu } } - protected boolean computeNonDefault(int hash, char key, CharBooleanUnaryOperator mappingFunction) { + protected boolean computeIfAbsent(int hash, char key, CharPredicate mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + boolean newValue = mappingFunction.test(key); insert(-index-1, key, newValue); return newValue; } - boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + boolean newValue = values[index]; return newValue; } finally { unlockWrite(stamp); } } - - protected boolean computeIfAbsent(int hash, char key, CharPredicate mappingFunction) { + + protected boolean supplyIfAbsent(int hash, char key, BooleanSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - boolean newValue = mappingFunction.test(key); + boolean newValue = valueProvider.getAsBoolean(); insert(-index-1, key, newValue); return newValue; } @@ -2071,23 +2065,37 @@ protected boolean computeIfAbsent(int hash, char key, CharPredicate mappingFunct unlockWrite(stamp); } } + + protected boolean computeIfPresent(int hash, char key, CharBooleanUnaryOperator mappingFunction) { + long stamp = writeLock(); + try { + int index = findIndex(hash, key); + if(index < 0) return getDefaultReturnValue(); + boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); + values[index] = newValue; + return newValue; + } + finally { + unlockWrite(stamp); + } + } - protected boolean computeIfAbsentNonDefault(int hash, char key, CharPredicate mappingFunction) { + protected boolean computeNonDefault(int hash, char key, CharBooleanUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - boolean newValue = mappingFunction.test(key); + boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - boolean newValue = values[index]; + boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.test(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } finally { @@ -2095,16 +2103,22 @@ protected boolean computeIfAbsentNonDefault(int hash, char key, CharPredicate ma } } - protected boolean supplyIfAbsent(int hash, char key, BooleanSupplier valueProvider) { + protected boolean computeIfAbsentNonDefault(int hash, char key, CharPredicate mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - boolean newValue = valueProvider.getAsBoolean(); + boolean newValue = mappingFunction.test(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } boolean newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.test(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } finally { @@ -2135,20 +2149,6 @@ protected boolean supplyIfAbsentNonDefault(int hash, char key, BooleanSupplier v } } - protected boolean computeIfPresent(int hash, char key, CharBooleanUnaryOperator mappingFunction) { - long stamp = writeLock(); - try { - int index = findIndex(hash, key); - if(index < 0) return getDefaultReturnValue(); - boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); - values[index] = newValue; - return newValue; - } - finally { - unlockWrite(stamp); - } - } - protected boolean computeIfPresentNonDefault(int hash, char key, CharBooleanUnaryOperator mappingFunction) { long stamp = writeLock(); try { diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/concurrent/Char2ByteConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/concurrent/Char2ByteConcurrentOpenHashMap.java index 5c905f21..b468f5a9 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/concurrent/Char2ByteConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/concurrent/Char2ByteConcurrentOpenHashMap.java @@ -451,13 +451,6 @@ public byte computeByte(char key, CharByteUnaryOperator mappingFunction) { return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public byte computeByteNonDefault(char key, CharByteUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public byte computeByteIfAbsent(char key, Char2ByteFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -465,13 +458,6 @@ public byte computeByteIfAbsent(char key, Char2ByteFunction mappingFunction) { return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public byte computeByteIfAbsentNonDefault(char key, Char2ByteFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public byte supplyByteIfAbsent(char key, ByteSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -480,17 +466,31 @@ public byte supplyByteIfAbsent(char key, ByteSupplier valueProvider) { } @Override - public byte supplyByteIfAbsentNonDefault(char key, ByteSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public byte computeByteIfPresent(char key, CharByteUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); + return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } @Override - public byte computeByteIfPresent(char key, CharByteUnaryOperator mappingFunction) { + public byte computeByteNonDefault(char key, CharByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).computeIfPresent(hash, key, mappingFunction); + return getSegment(hash).computeNonDefault(hash, key, mappingFunction); + } + + @Override + public byte computeByteIfAbsentNonDefault(char key, Char2ByteFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + int hash = getHashCode(key); + return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); + } + + @Override + public byte supplyByteIfAbsentNonDefault(char key, ByteSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + int hash = getHashCode(key); + return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); } @Override @@ -2076,35 +2076,29 @@ protected byte compute(int hash, char key, CharByteUnaryOperator mappingFunction } } - protected byte computeNonDefault(int hash, char key, CharByteUnaryOperator mappingFunction) { + protected byte computeIfAbsent(int hash, char key, Char2ByteFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + byte newValue = mappingFunction.applyAsByte(key); insert(-index-1, key, newValue); return newValue; } - byte newValue = mappingFunction.applyAsByte(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + byte newValue = values[index]; return newValue; } finally { unlockWrite(stamp); } } - - protected byte computeIfAbsent(int hash, char key, Char2ByteFunction mappingFunction) { + + protected byte supplyIfAbsent(int hash, char key, ByteSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = valueProvider.getAsByte(); insert(-index-1, key, newValue); return newValue; } @@ -2115,23 +2109,14 @@ protected byte computeIfAbsent(int hash, char key, Char2ByteFunction mappingFunc unlockWrite(stamp); } } - - protected byte computeIfAbsentNonDefault(int hash, char key, Char2ByteFunction mappingFunction) { + + protected byte computeIfPresent(int hash, char key, CharByteUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key); - if(newValue == getDefaultReturnValue()) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - byte newValue = values[index]; - if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsByte(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; - } + if(index < 0) return getDefaultReturnValue(); + byte newValue = mappingFunction.applyAsByte(key, values[index]); + values[index] = newValue; return newValue; } finally { @@ -2139,16 +2124,22 @@ protected byte computeIfAbsentNonDefault(int hash, char key, Char2ByteFunction m } } - protected byte supplyIfAbsent(int hash, char key, ByteSupplier valueProvider) { + protected byte computeNonDefault(int hash, char key, CharByteUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - byte newValue = valueProvider.getAsInt(); + byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - byte newValue = values[index]; + byte newValue = mappingFunction.applyAsByte(key, values[index]); + if(newValue == getDefaultReturnValue()) { + removeIndex(index); + return newValue; + } + values[index] = newValue; return newValue; } finally { @@ -2156,19 +2147,19 @@ protected byte supplyIfAbsent(int hash, char key, ByteSupplier valueProvider) { } } - protected byte supplyIfAbsentNonDefault(int hash, char key, ByteSupplier valueProvider) { + protected byte computeIfAbsentNonDefault(int hash, char key, Char2ByteFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - byte newValue = valueProvider.getAsInt(); + byte newValue = mappingFunction.applyAsByte(key); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } byte newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = mappingFunction.applyAsByte(key); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } @@ -2179,13 +2170,22 @@ protected byte supplyIfAbsentNonDefault(int hash, char key, ByteSupplier valuePr } } - protected byte computeIfPresent(int hash, char key, CharByteUnaryOperator mappingFunction) { + protected byte supplyIfAbsentNonDefault(int hash, char key, ByteSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0) return getDefaultReturnValue(); - byte newValue = mappingFunction.applyAsByte(key, values[index]); - values[index] = newValue; + if(index < 0) { + byte newValue = valueProvider.getAsByte(); + if(newValue == getDefaultReturnValue()) return newValue; + insert(-index-1, key, newValue); + return newValue; + } + byte newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = valueProvider.getAsByte(); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } finally { diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/concurrent/Char2CharConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/concurrent/Char2CharConcurrentOpenHashMap.java index d333fd0b..f47e2278 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/concurrent/Char2CharConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/concurrent/Char2CharConcurrentOpenHashMap.java @@ -444,13 +444,6 @@ public char computeChar(char key, CharCharUnaryOperator mappingFunction) { return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public char computeCharNonDefault(char key, CharCharUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public char computeCharIfAbsent(char key, CharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -458,13 +451,6 @@ public char computeCharIfAbsent(char key, CharUnaryOperator mappingFunction) { return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public char computeCharIfAbsentNonDefault(char key, CharUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public char supplyCharIfAbsent(char key, CharSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -473,17 +459,31 @@ public char supplyCharIfAbsent(char key, CharSupplier valueProvider) { } @Override - public char supplyCharIfAbsentNonDefault(char key, CharSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public char computeCharIfPresent(char key, CharCharUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); + return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } @Override - public char computeCharIfPresent(char key, CharCharUnaryOperator mappingFunction) { + public char computeCharNonDefault(char key, CharCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).computeIfPresent(hash, key, mappingFunction); + return getSegment(hash).computeNonDefault(hash, key, mappingFunction); + } + + @Override + public char computeCharIfAbsentNonDefault(char key, CharUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int hash = getHashCode(key); + return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); + } + + @Override + public char supplyCharIfAbsentNonDefault(char key, CharSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + int hash = getHashCode(key); + return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); } @Override @@ -2069,35 +2069,29 @@ protected char compute(int hash, char key, CharCharUnaryOperator mappingFunction } } - protected char computeNonDefault(int hash, char key, CharCharUnaryOperator mappingFunction) { + protected char computeIfAbsent(int hash, char key, CharUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + char newValue = mappingFunction.applyAsChar(key); insert(-index-1, key, newValue); return newValue; } - char newValue = mappingFunction.applyAsChar(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + char newValue = values[index]; return newValue; } finally { unlockWrite(stamp); } } - - protected char computeIfAbsent(int hash, char key, CharUnaryOperator mappingFunction) { + + protected char supplyIfAbsent(int hash, char key, CharSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = valueProvider.getAsChar(); insert(-index-1, key, newValue); return newValue; } @@ -2108,23 +2102,14 @@ protected char computeIfAbsent(int hash, char key, CharUnaryOperator mappingFunc unlockWrite(stamp); } } - - protected char computeIfAbsentNonDefault(int hash, char key, CharUnaryOperator mappingFunction) { + + protected char computeIfPresent(int hash, char key, CharCharUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0) { - char newValue = mappingFunction.applyAsChar(key); - if(newValue == getDefaultReturnValue()) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - char newValue = values[index]; - if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsChar(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; - } + if(index < 0) return getDefaultReturnValue(); + char newValue = mappingFunction.applyAsChar(key, values[index]); + values[index] = newValue; return newValue; } finally { @@ -2132,16 +2117,22 @@ protected char computeIfAbsentNonDefault(int hash, char key, CharUnaryOperator m } } - protected char supplyIfAbsent(int hash, char key, CharSupplier valueProvider) { + protected char computeNonDefault(int hash, char key, CharCharUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - char newValue = valueProvider.getAsInt(); + char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - char newValue = values[index]; + char newValue = mappingFunction.applyAsChar(key, values[index]); + if(newValue == getDefaultReturnValue()) { + removeIndex(index); + return newValue; + } + values[index] = newValue; return newValue; } finally { @@ -2149,19 +2140,19 @@ protected char supplyIfAbsent(int hash, char key, CharSupplier valueProvider) { } } - protected char supplyIfAbsentNonDefault(int hash, char key, CharSupplier valueProvider) { + protected char computeIfAbsentNonDefault(int hash, char key, CharUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - char newValue = valueProvider.getAsInt(); + char newValue = mappingFunction.applyAsChar(key); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } char newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = mappingFunction.applyAsChar(key); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } @@ -2172,13 +2163,22 @@ protected char supplyIfAbsentNonDefault(int hash, char key, CharSupplier valuePr } } - protected char computeIfPresent(int hash, char key, CharCharUnaryOperator mappingFunction) { + protected char supplyIfAbsentNonDefault(int hash, char key, CharSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0) return getDefaultReturnValue(); - char newValue = mappingFunction.applyAsChar(key, values[index]); - values[index] = newValue; + if(index < 0) { + char newValue = valueProvider.getAsChar(); + if(newValue == getDefaultReturnValue()) return newValue; + insert(-index-1, key, newValue); + return newValue; + } + char newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = valueProvider.getAsChar(); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } finally { diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/concurrent/Char2DoubleConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/concurrent/Char2DoubleConcurrentOpenHashMap.java index bc2a54c5..c1b9b909 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/concurrent/Char2DoubleConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/concurrent/Char2DoubleConcurrentOpenHashMap.java @@ -451,13 +451,6 @@ public double computeDouble(char key, CharDoubleUnaryOperator mappingFunction) { return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public double computeDoubleNonDefault(char key, CharDoubleUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public double computeDoubleIfAbsent(char key, Char2DoubleFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -465,13 +458,6 @@ public double computeDoubleIfAbsent(char key, Char2DoubleFunction mappingFunctio return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public double computeDoubleIfAbsentNonDefault(char key, Char2DoubleFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public double supplyDoubleIfAbsent(char key, DoubleSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -480,17 +466,31 @@ public double supplyDoubleIfAbsent(char key, DoubleSupplier valueProvider) { } @Override - public double supplyDoubleIfAbsentNonDefault(char key, DoubleSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public double computeDoubleIfPresent(char key, CharDoubleUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); + return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } @Override - public double computeDoubleIfPresent(char key, CharDoubleUnaryOperator mappingFunction) { + public double computeDoubleNonDefault(char key, CharDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).computeIfPresent(hash, key, mappingFunction); + return getSegment(hash).computeNonDefault(hash, key, mappingFunction); + } + + @Override + public double computeDoubleIfAbsentNonDefault(char key, Char2DoubleFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + int hash = getHashCode(key); + return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); + } + + @Override + public double supplyDoubleIfAbsentNonDefault(char key, DoubleSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + int hash = getHashCode(key); + return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); } @Override @@ -2076,35 +2076,29 @@ protected double compute(int hash, char key, CharDoubleUnaryOperator mappingFunc } } - protected double computeNonDefault(int hash, char key, CharDoubleUnaryOperator mappingFunction) { + protected double computeIfAbsent(int hash, char key, Char2DoubleFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + double newValue = mappingFunction.applyAsDouble(key); insert(-index-1, key, newValue); return newValue; } - double newValue = mappingFunction.applyAsDouble(key, values[index]); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + double newValue = values[index]; return newValue; } finally { unlockWrite(stamp); } } - - protected double computeIfAbsent(int hash, char key, Char2DoubleFunction mappingFunction) { + + protected double supplyIfAbsent(int hash, char key, DoubleSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = valueProvider.getAsDouble(); insert(-index-1, key, newValue); return newValue; } @@ -2115,23 +2109,37 @@ protected double computeIfAbsent(int hash, char key, Char2DoubleFunction mapping unlockWrite(stamp); } } + + protected double computeIfPresent(int hash, char key, CharDoubleUnaryOperator mappingFunction) { + long stamp = writeLock(); + try { + int index = findIndex(hash, key); + if(index < 0) return getDefaultReturnValue(); + double newValue = mappingFunction.applyAsDouble(key, values[index]); + values[index] = newValue; + return newValue; + } + finally { + unlockWrite(stamp); + } + } - protected double computeIfAbsentNonDefault(int hash, char key, Char2DoubleFunction mappingFunction) { + protected double computeNonDefault(int hash, char key, CharDoubleUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } - double newValue = values[index]; + double newValue = mappingFunction.applyAsDouble(key, values[index]); if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - newValue = mappingFunction.applyAsDouble(key); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } finally { @@ -2139,16 +2147,22 @@ protected double computeIfAbsentNonDefault(int hash, char key, Char2DoubleFuncti } } - protected double supplyIfAbsent(int hash, char key, DoubleSupplier valueProvider) { + protected double computeIfAbsentNonDefault(int hash, char key, Char2DoubleFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - double newValue = valueProvider.getAsDouble(); + double newValue = mappingFunction.applyAsDouble(key); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } double newValue = values[index]; + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { + newValue = mappingFunction.applyAsDouble(key); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + values[index] = newValue; + } return newValue; } finally { @@ -2179,20 +2193,6 @@ protected double supplyIfAbsentNonDefault(int hash, char key, DoubleSupplier val } } - protected double computeIfPresent(int hash, char key, CharDoubleUnaryOperator mappingFunction) { - long stamp = writeLock(); - try { - int index = findIndex(hash, key); - if(index < 0) return getDefaultReturnValue(); - double newValue = mappingFunction.applyAsDouble(key, values[index]); - values[index] = newValue; - return newValue; - } - finally { - unlockWrite(stamp); - } - } - protected double computeIfPresentNonDefault(int hash, char key, CharDoubleUnaryOperator mappingFunction) { long stamp = writeLock(); try { diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/concurrent/Char2FloatConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/concurrent/Char2FloatConcurrentOpenHashMap.java index 0b718f45..a7cd51c5 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/concurrent/Char2FloatConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/concurrent/Char2FloatConcurrentOpenHashMap.java @@ -451,13 +451,6 @@ public float computeFloat(char key, CharFloatUnaryOperator mappingFunction) { return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public float computeFloatNonDefault(char key, CharFloatUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public float computeFloatIfAbsent(char key, Char2FloatFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -465,13 +458,6 @@ public float computeFloatIfAbsent(char key, Char2FloatFunction mappingFunction) return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public float computeFloatIfAbsentNonDefault(char key, Char2FloatFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public float supplyFloatIfAbsent(char key, FloatSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -480,17 +466,31 @@ public float supplyFloatIfAbsent(char key, FloatSupplier valueProvider) { } @Override - public float supplyFloatIfAbsentNonDefault(char key, FloatSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public float computeFloatIfPresent(char key, CharFloatUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); + return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } @Override - public float computeFloatIfPresent(char key, CharFloatUnaryOperator mappingFunction) { + public float computeFloatNonDefault(char key, CharFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).computeIfPresent(hash, key, mappingFunction); + return getSegment(hash).computeNonDefault(hash, key, mappingFunction); + } + + @Override + public float computeFloatIfAbsentNonDefault(char key, Char2FloatFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + int hash = getHashCode(key); + return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); + } + + @Override + public float supplyFloatIfAbsentNonDefault(char key, FloatSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + int hash = getHashCode(key); + return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); } @Override @@ -2076,35 +2076,29 @@ protected float compute(int hash, char key, CharFloatUnaryOperator mappingFuncti } } - protected float computeNonDefault(int hash, char key, CharFloatUnaryOperator mappingFunction) { + protected float computeIfAbsent(int hash, char key, Char2FloatFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + float newValue = mappingFunction.applyAsFloat(key); insert(-index-1, key, newValue); return newValue; } - float newValue = mappingFunction.applyAsFloat(key, values[index]); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + float newValue = values[index]; return newValue; } finally { unlockWrite(stamp); } } - - protected float computeIfAbsent(int hash, char key, Char2FloatFunction mappingFunction) { + + protected float supplyIfAbsent(int hash, char key, FloatSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = valueProvider.getAsFloat(); insert(-index-1, key, newValue); return newValue; } @@ -2115,23 +2109,14 @@ protected float computeIfAbsent(int hash, char key, Char2FloatFunction mappingFu unlockWrite(stamp); } } - - protected float computeIfAbsentNonDefault(int hash, char key, Char2FloatFunction mappingFunction) { + + protected float computeIfPresent(int hash, char key, CharFloatUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - float newValue = values[index]; - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - newValue = mappingFunction.applyAsFloat(key); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; - values[index] = newValue; - } + if(index < 0) return getDefaultReturnValue(); + float newValue = mappingFunction.applyAsFloat(key, values[index]); + values[index] = newValue; return newValue; } finally { @@ -2139,16 +2124,22 @@ protected float computeIfAbsentNonDefault(int hash, char key, Char2FloatFunction } } - protected float supplyIfAbsent(int hash, char key, FloatSupplier valueProvider) { + protected float computeNonDefault(int hash, char key, CharFloatUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - float newValue = valueProvider.getAsDouble(); + float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } - float newValue = values[index]; + float newValue = mappingFunction.applyAsFloat(key, values[index]); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { + removeIndex(index); + return newValue; + } + values[index] = newValue; return newValue; } finally { @@ -2156,19 +2147,19 @@ protected float supplyIfAbsent(int hash, char key, FloatSupplier valueProvider) } } - protected float supplyIfAbsentNonDefault(int hash, char key, FloatSupplier valueProvider) { + protected float computeIfAbsentNonDefault(int hash, char key, Char2FloatFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - float newValue = valueProvider.getAsDouble(); + float newValue = mappingFunction.applyAsFloat(key); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } float newValue = values[index]; if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - newValue = valueProvider.getAsDouble(); + newValue = mappingFunction.applyAsFloat(key); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; values[index] = newValue; } @@ -2179,13 +2170,22 @@ protected float supplyIfAbsentNonDefault(int hash, char key, FloatSupplier value } } - protected float computeIfPresent(int hash, char key, CharFloatUnaryOperator mappingFunction) { + protected float supplyIfAbsentNonDefault(int hash, char key, FloatSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0) return getDefaultReturnValue(); - float newValue = mappingFunction.applyAsFloat(key, values[index]); - values[index] = newValue; + if(index < 0) { + float newValue = valueProvider.getAsFloat(); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + insert(-index-1, key, newValue); + return newValue; + } + float newValue = values[index]; + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { + newValue = valueProvider.getAsFloat(); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + values[index] = newValue; + } return newValue; } finally { diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/concurrent/Char2IntConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/concurrent/Char2IntConcurrentOpenHashMap.java index d22322a3..2dab4017 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/concurrent/Char2IntConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/concurrent/Char2IntConcurrentOpenHashMap.java @@ -451,13 +451,6 @@ public int computeInt(char key, CharIntUnaryOperator mappingFunction) { return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public int computeIntNonDefault(char key, CharIntUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public int computeIntIfAbsent(char key, Char2IntFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -465,13 +458,6 @@ public int computeIntIfAbsent(char key, Char2IntFunction mappingFunction) { return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public int computeIntIfAbsentNonDefault(char key, Char2IntFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public int supplyIntIfAbsent(char key, IntSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -480,17 +466,31 @@ public int supplyIntIfAbsent(char key, IntSupplier valueProvider) { } @Override - public int supplyIntIfAbsentNonDefault(char key, IntSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public int computeIntIfPresent(char key, CharIntUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); + return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } @Override - public int computeIntIfPresent(char key, CharIntUnaryOperator mappingFunction) { + public int computeIntNonDefault(char key, CharIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).computeIfPresent(hash, key, mappingFunction); + return getSegment(hash).computeNonDefault(hash, key, mappingFunction); + } + + @Override + public int computeIntIfAbsentNonDefault(char key, Char2IntFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + int hash = getHashCode(key); + return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); + } + + @Override + public int supplyIntIfAbsentNonDefault(char key, IntSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + int hash = getHashCode(key); + return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); } @Override @@ -2076,35 +2076,29 @@ protected int compute(int hash, char key, CharIntUnaryOperator mappingFunction) } } - protected int computeNonDefault(int hash, char key, CharIntUnaryOperator mappingFunction) { + protected int computeIfAbsent(int hash, char key, Char2IntFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + int newValue = mappingFunction.applyAsInt(key); insert(-index-1, key, newValue); return newValue; } - int newValue = mappingFunction.applyAsInt(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + int newValue = values[index]; return newValue; } finally { unlockWrite(stamp); } } - - protected int computeIfAbsent(int hash, char key, Char2IntFunction mappingFunction) { + + protected int supplyIfAbsent(int hash, char key, IntSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = valueProvider.getAsInt(); insert(-index-1, key, newValue); return newValue; } @@ -2115,23 +2109,37 @@ protected int computeIfAbsent(int hash, char key, Char2IntFunction mappingFuncti unlockWrite(stamp); } } + + protected int computeIfPresent(int hash, char key, CharIntUnaryOperator mappingFunction) { + long stamp = writeLock(); + try { + int index = findIndex(hash, key); + if(index < 0) return getDefaultReturnValue(); + int newValue = mappingFunction.applyAsInt(key, values[index]); + values[index] = newValue; + return newValue; + } + finally { + unlockWrite(stamp); + } + } - protected int computeIfAbsentNonDefault(int hash, char key, Char2IntFunction mappingFunction) { + protected int computeNonDefault(int hash, char key, CharIntUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - int newValue = values[index]; + int newValue = mappingFunction.applyAsInt(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsInt(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } finally { @@ -2139,16 +2147,22 @@ protected int computeIfAbsentNonDefault(int hash, char key, Char2IntFunction map } } - protected int supplyIfAbsent(int hash, char key, IntSupplier valueProvider) { + protected int computeIfAbsentNonDefault(int hash, char key, Char2IntFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - int newValue = valueProvider.getAsInt(); + int newValue = mappingFunction.applyAsInt(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } int newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsInt(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } finally { @@ -2179,20 +2193,6 @@ protected int supplyIfAbsentNonDefault(int hash, char key, IntSupplier valueProv } } - protected int computeIfPresent(int hash, char key, CharIntUnaryOperator mappingFunction) { - long stamp = writeLock(); - try { - int index = findIndex(hash, key); - if(index < 0) return getDefaultReturnValue(); - int newValue = mappingFunction.applyAsInt(key, values[index]); - values[index] = newValue; - return newValue; - } - finally { - unlockWrite(stamp); - } - } - protected int computeIfPresentNonDefault(int hash, char key, CharIntUnaryOperator mappingFunction) { long stamp = writeLock(); try { diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/concurrent/Char2LongConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/concurrent/Char2LongConcurrentOpenHashMap.java index c14a127a..ad35d955 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/concurrent/Char2LongConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/concurrent/Char2LongConcurrentOpenHashMap.java @@ -451,13 +451,6 @@ public long computeLong(char key, CharLongUnaryOperator mappingFunction) { return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public long computeLongNonDefault(char key, CharLongUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public long computeLongIfAbsent(char key, Char2LongFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -465,13 +458,6 @@ public long computeLongIfAbsent(char key, Char2LongFunction mappingFunction) { return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public long computeLongIfAbsentNonDefault(char key, Char2LongFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public long supplyLongIfAbsent(char key, LongSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -480,17 +466,31 @@ public long supplyLongIfAbsent(char key, LongSupplier valueProvider) { } @Override - public long supplyLongIfAbsentNonDefault(char key, LongSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public long computeLongIfPresent(char key, CharLongUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); + return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } @Override - public long computeLongIfPresent(char key, CharLongUnaryOperator mappingFunction) { + public long computeLongNonDefault(char key, CharLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).computeIfPresent(hash, key, mappingFunction); + return getSegment(hash).computeNonDefault(hash, key, mappingFunction); + } + + @Override + public long computeLongIfAbsentNonDefault(char key, Char2LongFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + int hash = getHashCode(key); + return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); + } + + @Override + public long supplyLongIfAbsentNonDefault(char key, LongSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + int hash = getHashCode(key); + return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); } @Override @@ -2076,35 +2076,29 @@ protected long compute(int hash, char key, CharLongUnaryOperator mappingFunction } } - protected long computeNonDefault(int hash, char key, CharLongUnaryOperator mappingFunction) { + protected long computeIfAbsent(int hash, char key, Char2LongFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + long newValue = mappingFunction.applyAsLong(key); insert(-index-1, key, newValue); return newValue; } - long newValue = mappingFunction.applyAsLong(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + long newValue = values[index]; return newValue; } finally { unlockWrite(stamp); } } - - protected long computeIfAbsent(int hash, char key, Char2LongFunction mappingFunction) { + + protected long supplyIfAbsent(int hash, char key, LongSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = valueProvider.getAsLong(); insert(-index-1, key, newValue); return newValue; } @@ -2115,23 +2109,37 @@ protected long computeIfAbsent(int hash, char key, Char2LongFunction mappingFunc unlockWrite(stamp); } } + + protected long computeIfPresent(int hash, char key, CharLongUnaryOperator mappingFunction) { + long stamp = writeLock(); + try { + int index = findIndex(hash, key); + if(index < 0) return getDefaultReturnValue(); + long newValue = mappingFunction.applyAsLong(key, values[index]); + values[index] = newValue; + return newValue; + } + finally { + unlockWrite(stamp); + } + } - protected long computeIfAbsentNonDefault(int hash, char key, Char2LongFunction mappingFunction) { + protected long computeNonDefault(int hash, char key, CharLongUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - long newValue = values[index]; + long newValue = mappingFunction.applyAsLong(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsLong(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } finally { @@ -2139,16 +2147,22 @@ protected long computeIfAbsentNonDefault(int hash, char key, Char2LongFunction m } } - protected long supplyIfAbsent(int hash, char key, LongSupplier valueProvider) { + protected long computeIfAbsentNonDefault(int hash, char key, Char2LongFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - long newValue = valueProvider.getAsLong(); + long newValue = mappingFunction.applyAsLong(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } long newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsLong(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } finally { @@ -2179,20 +2193,6 @@ protected long supplyIfAbsentNonDefault(int hash, char key, LongSupplier valuePr } } - protected long computeIfPresent(int hash, char key, CharLongUnaryOperator mappingFunction) { - long stamp = writeLock(); - try { - int index = findIndex(hash, key); - if(index < 0) return getDefaultReturnValue(); - long newValue = mappingFunction.applyAsLong(key, values[index]); - values[index] = newValue; - return newValue; - } - finally { - unlockWrite(stamp); - } - } - protected long computeIfPresentNonDefault(int hash, char key, CharLongUnaryOperator mappingFunction) { long stamp = writeLock(); try { diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/concurrent/Char2ObjectConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/concurrent/Char2ObjectConcurrentOpenHashMap.java index e3ef131f..82087e1e 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/concurrent/Char2ObjectConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/concurrent/Char2ObjectConcurrentOpenHashMap.java @@ -426,13 +426,6 @@ public V compute(char key, CharObjectUnaryOperator mappingFunction) { return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public V computeNonDefault(char key, CharObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public V computeIfAbsent(char key, CharFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -440,13 +433,6 @@ public V computeIfAbsent(char key, CharFunction mappingFunction) { return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public V computeIfAbsentNonDefault(char key, CharFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public V supplyIfAbsent(char key, ObjectSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -454,13 +440,6 @@ public V supplyIfAbsent(char key, ObjectSupplier valueProvider) { return getSegment(hash).supplyIfAbsent(hash, key, valueProvider); } - @Override - public V supplyIfAbsentNonDefault(char key, ObjectSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); - } - @Override public V computeIfPresent(char key, CharObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -468,13 +447,6 @@ public V computeIfPresent(char key, CharObjectUnaryOperator mappingFunction) return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } - @Override - public V computeIfPresentNonDefault(char key, CharObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfPresentNonDefault(hash, key, mappingFunction); - } - @Override public V merge(char key, V value, ObjectObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -2011,29 +1983,6 @@ protected V compute(int hash, char key, CharObjectUnaryOperator mappingFuncti } } - protected V computeNonDefault(int hash, char key, CharObjectUnaryOperator mappingFunction) { - long stamp = writeLock(); - try { - int index = findIndex(hash, key); - if(index < 0) { - V newValue = mappingFunction.apply(key, getDefaultReturnValue()); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = mappingFunction.apply(key, values[index]); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; - return newValue; - } - finally { - unlockWrite(stamp); - } - } - protected V computeIfAbsent(int hash, char key, CharFunction mappingFunction) { long stamp = writeLock(); try { @@ -2056,30 +2005,7 @@ protected V computeIfAbsent(int hash, char key, CharFunction mappingFunction) unlockWrite(stamp); } } - - protected V computeIfAbsentNonDefault(int hash, char key, CharFunction mappingFunction) { - long stamp = writeLock(); - try { - int index = findIndex(hash, key); - if(index < 0) { - V newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = values[index]; - if(Objects.equals(newValue, getDefaultReturnValue())) { - newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - values[index] = newValue; - } - return newValue; - } - finally { - unlockWrite(stamp); - } - } - + protected V supplyIfAbsent(int hash, char key, ObjectSupplier valueProvider) { long stamp = writeLock(); try { @@ -2102,30 +2028,7 @@ protected V supplyIfAbsent(int hash, char key, ObjectSupplier valueProvider) unlockWrite(stamp); } } - - protected V supplyIfAbsentNonDefault(int hash, char key, ObjectSupplier valueProvider) { - long stamp = writeLock(); - try { - int index = findIndex(hash, key); - if(index < 0) { - V newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = values[index]; - if(Objects.equals(newValue, getDefaultReturnValue())) { - newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - values[index] = newValue; - } - return newValue; - } - finally { - unlockWrite(stamp); - } - } - + protected V computeIfPresent(int hash, char key, CharObjectUnaryOperator mappingFunction) { long stamp = writeLock(); try { @@ -2144,11 +2047,16 @@ protected V computeIfPresent(int hash, char key, CharObjectUnaryOperator mapp } } - protected V computeIfPresentNonDefault(int hash, char key, CharObjectUnaryOperator mappingFunction) { + protected V computeNonDefault(int hash, char key, CharObjectUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0 || Objects.equals(values[index], getDefaultReturnValue())) return getDefaultReturnValue(); + if(index < 0) { + V newValue = mappingFunction.apply(key, getDefaultReturnValue()); + if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; + insert(-index-1, key, newValue); + return newValue; + } V newValue = mappingFunction.apply(key, values[index]); if(Objects.equals(newValue, getDefaultReturnValue())) { removeIndex(index); diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/concurrent/Char2ShortConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/concurrent/Char2ShortConcurrentOpenHashMap.java index f7f6a316..0742c01c 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/concurrent/Char2ShortConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/concurrent/Char2ShortConcurrentOpenHashMap.java @@ -451,13 +451,6 @@ public short computeShort(char key, CharShortUnaryOperator mappingFunction) { return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public short computeShortNonDefault(char key, CharShortUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public short computeShortIfAbsent(char key, Char2ShortFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -465,13 +458,6 @@ public short computeShortIfAbsent(char key, Char2ShortFunction mappingFunction) return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public short computeShortIfAbsentNonDefault(char key, Char2ShortFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public short supplyShortIfAbsent(char key, ShortSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -480,17 +466,31 @@ public short supplyShortIfAbsent(char key, ShortSupplier valueProvider) { } @Override - public short supplyShortIfAbsentNonDefault(char key, ShortSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public short computeShortIfPresent(char key, CharShortUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); + return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } @Override - public short computeShortIfPresent(char key, CharShortUnaryOperator mappingFunction) { + public short computeShortNonDefault(char key, CharShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).computeIfPresent(hash, key, mappingFunction); + return getSegment(hash).computeNonDefault(hash, key, mappingFunction); + } + + @Override + public short computeShortIfAbsentNonDefault(char key, Char2ShortFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + int hash = getHashCode(key); + return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); + } + + @Override + public short supplyShortIfAbsentNonDefault(char key, ShortSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + int hash = getHashCode(key); + return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); } @Override @@ -2076,35 +2076,29 @@ protected short compute(int hash, char key, CharShortUnaryOperator mappingFuncti } } - protected short computeNonDefault(int hash, char key, CharShortUnaryOperator mappingFunction) { + protected short computeIfAbsent(int hash, char key, Char2ShortFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + short newValue = mappingFunction.applyAsShort(key); insert(-index-1, key, newValue); return newValue; } - short newValue = mappingFunction.applyAsShort(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + short newValue = values[index]; return newValue; } finally { unlockWrite(stamp); } } - - protected short computeIfAbsent(int hash, char key, Char2ShortFunction mappingFunction) { + + protected short supplyIfAbsent(int hash, char key, ShortSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = valueProvider.getAsShort(); insert(-index-1, key, newValue); return newValue; } @@ -2115,23 +2109,14 @@ protected short computeIfAbsent(int hash, char key, Char2ShortFunction mappingFu unlockWrite(stamp); } } - - protected short computeIfAbsentNonDefault(int hash, char key, Char2ShortFunction mappingFunction) { + + protected short computeIfPresent(int hash, char key, CharShortUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0) { - short newValue = mappingFunction.applyAsShort(key); - if(newValue == getDefaultReturnValue()) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - short newValue = values[index]; - if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsShort(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; - } + if(index < 0) return getDefaultReturnValue(); + short newValue = mappingFunction.applyAsShort(key, values[index]); + values[index] = newValue; return newValue; } finally { @@ -2139,16 +2124,22 @@ protected short computeIfAbsentNonDefault(int hash, char key, Char2ShortFunction } } - protected short supplyIfAbsent(int hash, char key, ShortSupplier valueProvider) { + protected short computeNonDefault(int hash, char key, CharShortUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - short newValue = valueProvider.getAsInt(); + short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - short newValue = values[index]; + short newValue = mappingFunction.applyAsShort(key, values[index]); + if(newValue == getDefaultReturnValue()) { + removeIndex(index); + return newValue; + } + values[index] = newValue; return newValue; } finally { @@ -2156,19 +2147,19 @@ protected short supplyIfAbsent(int hash, char key, ShortSupplier valueProvider) } } - protected short supplyIfAbsentNonDefault(int hash, char key, ShortSupplier valueProvider) { + protected short computeIfAbsentNonDefault(int hash, char key, Char2ShortFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - short newValue = valueProvider.getAsInt(); + short newValue = mappingFunction.applyAsShort(key); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } short newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = mappingFunction.applyAsShort(key); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } @@ -2179,13 +2170,22 @@ protected short supplyIfAbsentNonDefault(int hash, char key, ShortSupplier value } } - protected short computeIfPresent(int hash, char key, CharShortUnaryOperator mappingFunction) { + protected short supplyIfAbsentNonDefault(int hash, char key, ShortSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0) return getDefaultReturnValue(); - short newValue = mappingFunction.applyAsShort(key, values[index]); - values[index] = newValue; + if(index < 0) { + short newValue = valueProvider.getAsShort(); + if(newValue == getDefaultReturnValue()) return newValue; + insert(-index-1, key, newValue); + return newValue; + } + short newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = valueProvider.getAsShort(); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } finally { diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2BooleanOpenCustomHashMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2BooleanOpenCustomHashMap.java index 294e799f..33a755cb 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2BooleanOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2BooleanOpenCustomHashMap.java @@ -441,30 +441,24 @@ public boolean computeBoolean(char key, CharBooleanUnaryOperator mappingFunction } @Override - public boolean computeBooleanNonDefault(char key, CharBooleanUnaryOperator mappingFunction) { + public boolean computeBooleanIfAbsent(char key, CharPredicate mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + boolean newValue = mappingFunction.test(key); insert(-index-1, key, newValue); return newValue; } - boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + boolean newValue = values[index]; return newValue; } - + @Override - public boolean computeBooleanIfAbsent(char key, CharPredicate mappingFunction) { - Objects.requireNonNull(mappingFunction); + public boolean supplyBooleanIfAbsent(char key, BooleanSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - boolean newValue = mappingFunction.test(key); + boolean newValue = valueProvider.getAsBoolean(); insert(-index-1, key, newValue); return newValue; } @@ -473,34 +467,50 @@ public boolean computeBooleanIfAbsent(char key, CharPredicate mappingFunction) { } @Override - public boolean computeBooleanIfAbsentNonDefault(char key, CharPredicate mappingFunction) { + public boolean computeBooleanIfPresent(char key, CharBooleanUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public boolean computeBooleanNonDefault(char key, CharBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - boolean newValue = mappingFunction.test(key); + boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - boolean newValue = values[index]; + boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.test(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public boolean supplyBooleanIfAbsent(char key, BooleanSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public boolean computeBooleanIfAbsentNonDefault(char key, CharPredicate mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - boolean newValue = valueProvider.getAsBoolean(); + boolean newValue = mappingFunction.test(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } boolean newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.test(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -523,16 +533,6 @@ public boolean supplyBooleanIfAbsentNonDefault(char key, BooleanSupplier valuePr return newValue; } - @Override - public boolean computeBooleanIfPresent(char key, CharBooleanUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public boolean computeBooleanIfPresentNonDefault(char key, CharBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2ByteOpenCustomHashMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2ByteOpenCustomHashMap.java index b88ea935..d24f11d7 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2ByteOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2ByteOpenCustomHashMap.java @@ -463,30 +463,24 @@ public byte computeByte(char key, CharByteUnaryOperator mappingFunction) { } @Override - public byte computeByteNonDefault(char key, CharByteUnaryOperator mappingFunction) { + public byte computeByteIfAbsent(char key, Char2ByteFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + byte newValue = mappingFunction.applyAsByte(key); insert(-index-1, key, newValue); return newValue; } - byte newValue = mappingFunction.applyAsByte(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + byte newValue = values[index]; return newValue; } - + @Override - public byte computeByteIfAbsent(char key, Char2ByteFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public byte supplyByteIfAbsent(char key, ByteSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = valueProvider.getAsByte(); insert(-index-1, key, newValue); return newValue; } @@ -495,34 +489,50 @@ public byte computeByteIfAbsent(char key, Char2ByteFunction mappingFunction) { } @Override - public byte computeByteIfAbsentNonDefault(char key, Char2ByteFunction mappingFunction) { + public byte computeByteIfPresent(char key, CharByteUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + byte newValue = mappingFunction.applyAsByte(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public byte computeByteNonDefault(char key, CharByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - byte newValue = values[index]; + byte newValue = mappingFunction.applyAsByte(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsByte(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public byte supplyByteIfAbsent(char key, ByteSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public byte computeByteIfAbsentNonDefault(char key, Char2ByteFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - byte newValue = valueProvider.getAsInt(); + byte newValue = mappingFunction.applyAsByte(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } byte newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsByte(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -531,30 +541,20 @@ public byte supplyByteIfAbsentNonDefault(char key, ByteSupplier valueProvider) { Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - byte newValue = valueProvider.getAsInt(); + byte newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } byte newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public byte computeByteIfPresent(char key, CharByteUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - byte newValue = mappingFunction.applyAsByte(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public byte computeByteIfPresentNonDefault(char key, CharByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2CharOpenCustomHashMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2CharOpenCustomHashMap.java index 600e09b5..202a6953 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2CharOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2CharOpenCustomHashMap.java @@ -455,30 +455,24 @@ public char computeChar(char key, CharCharUnaryOperator mappingFunction) { } @Override - public char computeCharNonDefault(char key, CharCharUnaryOperator mappingFunction) { + public char computeCharIfAbsent(char key, CharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + char newValue = mappingFunction.applyAsChar(key); insert(-index-1, key, newValue); return newValue; } - char newValue = mappingFunction.applyAsChar(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + char newValue = values[index]; return newValue; } - + @Override - public char computeCharIfAbsent(char key, CharUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); + public char supplyCharIfAbsent(char key, CharSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = valueProvider.getAsChar(); insert(-index-1, key, newValue); return newValue; } @@ -487,34 +481,50 @@ public char computeCharIfAbsent(char key, CharUnaryOperator mappingFunction) { } @Override - public char computeCharIfAbsentNonDefault(char key, CharUnaryOperator mappingFunction) { + public char computeCharIfPresent(char key, CharCharUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + char newValue = mappingFunction.applyAsChar(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public char computeCharNonDefault(char key, CharCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - char newValue = values[index]; + char newValue = mappingFunction.applyAsChar(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsChar(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public char supplyCharIfAbsent(char key, CharSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public char computeCharIfAbsentNonDefault(char key, CharUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - char newValue = valueProvider.getAsInt(); + char newValue = mappingFunction.applyAsChar(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } char newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsChar(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -523,30 +533,20 @@ public char supplyCharIfAbsentNonDefault(char key, CharSupplier valueProvider) { Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - char newValue = valueProvider.getAsInt(); + char newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } char newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public char computeCharIfPresent(char key, CharCharUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - char newValue = mappingFunction.applyAsChar(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public char computeCharIfPresentNonDefault(char key, CharCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2DoubleOpenCustomHashMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2DoubleOpenCustomHashMap.java index f920ea75..2827a379 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2DoubleOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2DoubleOpenCustomHashMap.java @@ -463,30 +463,24 @@ public double computeDouble(char key, CharDoubleUnaryOperator mappingFunction) { } @Override - public double computeDoubleNonDefault(char key, CharDoubleUnaryOperator mappingFunction) { + public double computeDoubleIfAbsent(char key, Char2DoubleFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + double newValue = mappingFunction.applyAsDouble(key); insert(-index-1, key, newValue); return newValue; } - double newValue = mappingFunction.applyAsDouble(key, values[index]); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + double newValue = values[index]; return newValue; } - + @Override - public double computeDoubleIfAbsent(char key, Char2DoubleFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public double supplyDoubleIfAbsent(char key, DoubleSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = valueProvider.getAsDouble(); insert(-index-1, key, newValue); return newValue; } @@ -495,34 +489,50 @@ public double computeDoubleIfAbsent(char key, Char2DoubleFunction mappingFunctio } @Override - public double computeDoubleIfAbsentNonDefault(char key, Char2DoubleFunction mappingFunction) { + public double computeDoubleIfPresent(char key, CharDoubleUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + double newValue = mappingFunction.applyAsDouble(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public double computeDoubleNonDefault(char key, CharDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } - double newValue = values[index]; + double newValue = mappingFunction.applyAsDouble(key, values[index]); if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - newValue = mappingFunction.applyAsDouble(key); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public double supplyDoubleIfAbsent(char key, DoubleSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public double computeDoubleIfAbsentNonDefault(char key, Char2DoubleFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - double newValue = valueProvider.getAsDouble(); + double newValue = mappingFunction.applyAsDouble(key); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } double newValue = values[index]; + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { + newValue = mappingFunction.applyAsDouble(key); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + values[index] = newValue; + } return newValue; } @@ -545,16 +555,6 @@ public double supplyDoubleIfAbsentNonDefault(char key, DoubleSupplier valueProvi return newValue; } - @Override - public double computeDoubleIfPresent(char key, CharDoubleUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - double newValue = mappingFunction.applyAsDouble(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public double computeDoubleIfPresentNonDefault(char key, CharDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2FloatOpenCustomHashMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2FloatOpenCustomHashMap.java index 4c50118e..fefed7da 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2FloatOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2FloatOpenCustomHashMap.java @@ -463,30 +463,24 @@ public float computeFloat(char key, CharFloatUnaryOperator mappingFunction) { } @Override - public float computeFloatNonDefault(char key, CharFloatUnaryOperator mappingFunction) { + public float computeFloatIfAbsent(char key, Char2FloatFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + float newValue = mappingFunction.applyAsFloat(key); insert(-index-1, key, newValue); return newValue; } - float newValue = mappingFunction.applyAsFloat(key, values[index]); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + float newValue = values[index]; return newValue; } - + @Override - public float computeFloatIfAbsent(char key, Char2FloatFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public float supplyFloatIfAbsent(char key, FloatSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = valueProvider.getAsFloat(); insert(-index-1, key, newValue); return newValue; } @@ -495,34 +489,50 @@ public float computeFloatIfAbsent(char key, Char2FloatFunction mappingFunction) } @Override - public float computeFloatIfAbsentNonDefault(char key, Char2FloatFunction mappingFunction) { + public float computeFloatIfPresent(char key, CharFloatUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + float newValue = mappingFunction.applyAsFloat(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public float computeFloatNonDefault(char key, CharFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } - float newValue = values[index]; + float newValue = mappingFunction.applyAsFloat(key, values[index]); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - newValue = mappingFunction.applyAsFloat(key); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public float supplyFloatIfAbsent(char key, FloatSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public float computeFloatIfAbsentNonDefault(char key, Char2FloatFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - float newValue = valueProvider.getAsDouble(); + float newValue = mappingFunction.applyAsFloat(key); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } float newValue = values[index]; + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { + newValue = mappingFunction.applyAsFloat(key); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + values[index] = newValue; + } return newValue; } @@ -531,30 +541,20 @@ public float supplyFloatIfAbsentNonDefault(char key, FloatSupplier valueProvider Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - float newValue = valueProvider.getAsDouble(); + float newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } float newValue = values[index]; if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - newValue = valueProvider.getAsDouble(); + newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; values[index] = newValue; } return newValue; } - @Override - public float computeFloatIfPresent(char key, CharFloatUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - float newValue = mappingFunction.applyAsFloat(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public float computeFloatIfPresentNonDefault(char key, CharFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2IntOpenCustomHashMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2IntOpenCustomHashMap.java index ec8f3fa8..4f483fe9 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2IntOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2IntOpenCustomHashMap.java @@ -463,30 +463,24 @@ public int computeInt(char key, CharIntUnaryOperator mappingFunction) { } @Override - public int computeIntNonDefault(char key, CharIntUnaryOperator mappingFunction) { + public int computeIntIfAbsent(char key, Char2IntFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + int newValue = mappingFunction.applyAsInt(key); insert(-index-1, key, newValue); return newValue; } - int newValue = mappingFunction.applyAsInt(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + int newValue = values[index]; return newValue; } - + @Override - public int computeIntIfAbsent(char key, Char2IntFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public int supplyIntIfAbsent(char key, IntSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = valueProvider.getAsInt(); insert(-index-1, key, newValue); return newValue; } @@ -495,34 +489,50 @@ public int computeIntIfAbsent(char key, Char2IntFunction mappingFunction) { } @Override - public int computeIntIfAbsentNonDefault(char key, Char2IntFunction mappingFunction) { + public int computeIntIfPresent(char key, CharIntUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + int newValue = mappingFunction.applyAsInt(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public int computeIntNonDefault(char key, CharIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - int newValue = values[index]; + int newValue = mappingFunction.applyAsInt(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsInt(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public int supplyIntIfAbsent(char key, IntSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public int computeIntIfAbsentNonDefault(char key, Char2IntFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - int newValue = valueProvider.getAsInt(); + int newValue = mappingFunction.applyAsInt(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } int newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsInt(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -545,16 +555,6 @@ public int supplyIntIfAbsentNonDefault(char key, IntSupplier valueProvider) { return newValue; } - @Override - public int computeIntIfPresent(char key, CharIntUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - int newValue = mappingFunction.applyAsInt(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public int computeIntIfPresentNonDefault(char key, CharIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2LongOpenCustomHashMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2LongOpenCustomHashMap.java index 6f263cd9..3a531d9e 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2LongOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2LongOpenCustomHashMap.java @@ -463,30 +463,24 @@ public long computeLong(char key, CharLongUnaryOperator mappingFunction) { } @Override - public long computeLongNonDefault(char key, CharLongUnaryOperator mappingFunction) { + public long computeLongIfAbsent(char key, Char2LongFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + long newValue = mappingFunction.applyAsLong(key); insert(-index-1, key, newValue); return newValue; } - long newValue = mappingFunction.applyAsLong(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + long newValue = values[index]; return newValue; } - + @Override - public long computeLongIfAbsent(char key, Char2LongFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public long supplyLongIfAbsent(char key, LongSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = valueProvider.getAsLong(); insert(-index-1, key, newValue); return newValue; } @@ -495,34 +489,50 @@ public long computeLongIfAbsent(char key, Char2LongFunction mappingFunction) { } @Override - public long computeLongIfAbsentNonDefault(char key, Char2LongFunction mappingFunction) { + public long computeLongIfPresent(char key, CharLongUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + long newValue = mappingFunction.applyAsLong(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public long computeLongNonDefault(char key, CharLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - long newValue = values[index]; + long newValue = mappingFunction.applyAsLong(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsLong(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public long supplyLongIfAbsent(char key, LongSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public long computeLongIfAbsentNonDefault(char key, Char2LongFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - long newValue = valueProvider.getAsLong(); + long newValue = mappingFunction.applyAsLong(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } long newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsLong(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -545,16 +555,6 @@ public long supplyLongIfAbsentNonDefault(char key, LongSupplier valueProvider) { return newValue; } - @Override - public long computeLongIfPresent(char key, CharLongUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - long newValue = mappingFunction.applyAsLong(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public long computeLongIfPresentNonDefault(char key, CharLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2ObjectOpenCustomHashMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2ObjectOpenCustomHashMap.java index 0c7fe745..b72f1502 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2ObjectOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2ObjectOpenCustomHashMap.java @@ -432,25 +432,6 @@ public V compute(char key, CharObjectUnaryOperator mappingFunction) { return newValue; } - @Override - public V computeNonDefault(char key, CharObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) { - V newValue = mappingFunction.apply(key, getDefaultReturnValue()); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = mappingFunction.apply(key, values[index]); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; - return newValue; - } - @Override public V computeIfAbsent(char key, CharFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -469,26 +450,7 @@ public V computeIfAbsent(char key, CharFunction mappingFunction) { } return newValue; } - - @Override - public V computeIfAbsentNonDefault(char key, CharFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) { - V newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = values[index]; - if(Objects.equals(newValue, getDefaultReturnValue())) { - newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - values[index] = newValue; - } - return newValue; - } - + @Override public V supplyIfAbsent(char key, ObjectSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -508,25 +470,6 @@ public V supplyIfAbsent(char key, ObjectSupplier valueProvider) { return newValue; } - @Override - public V supplyIfAbsentNonDefault(char key, ObjectSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - int index = findIndex(key); - if(index < 0) { - V newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = values[index]; - if(Objects.equals(newValue, getDefaultReturnValue())) { - newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - values[index] = newValue; - } - return newValue; - } - @Override public V computeIfPresent(char key, CharObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -541,20 +484,6 @@ public V computeIfPresent(char key, CharObjectUnaryOperator mappingFunction) return newValue; } - @Override - public V computeIfPresentNonDefault(char key, CharObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0 || Objects.equals(values[index], getDefaultReturnValue())) return getDefaultReturnValue(); - V newValue = mappingFunction.apply(key, values[index]); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; - return newValue; - } - @Override public V merge(char key, V value, ObjectObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2ShortOpenCustomHashMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2ShortOpenCustomHashMap.java index d4866f64..0b1bc66f 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2ShortOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/customHash/Char2ShortOpenCustomHashMap.java @@ -463,30 +463,24 @@ public short computeShort(char key, CharShortUnaryOperator mappingFunction) { } @Override - public short computeShortNonDefault(char key, CharShortUnaryOperator mappingFunction) { + public short computeShortIfAbsent(char key, Char2ShortFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + short newValue = mappingFunction.applyAsShort(key); insert(-index-1, key, newValue); return newValue; } - short newValue = mappingFunction.applyAsShort(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + short newValue = values[index]; return newValue; } - + @Override - public short computeShortIfAbsent(char key, Char2ShortFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public short supplyShortIfAbsent(char key, ShortSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = valueProvider.getAsShort(); insert(-index-1, key, newValue); return newValue; } @@ -495,34 +489,50 @@ public short computeShortIfAbsent(char key, Char2ShortFunction mappingFunction) } @Override - public short computeShortIfAbsentNonDefault(char key, Char2ShortFunction mappingFunction) { + public short computeShortIfPresent(char key, CharShortUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + short newValue = mappingFunction.applyAsShort(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public short computeShortNonDefault(char key, CharShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - short newValue = values[index]; + short newValue = mappingFunction.applyAsShort(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsShort(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public short supplyShortIfAbsent(char key, ShortSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public short computeShortIfAbsentNonDefault(char key, Char2ShortFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - short newValue = valueProvider.getAsInt(); + short newValue = mappingFunction.applyAsShort(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } short newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsShort(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -531,30 +541,20 @@ public short supplyShortIfAbsentNonDefault(char key, ShortSupplier valueProvider Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - short newValue = valueProvider.getAsInt(); + short newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } short newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public short computeShortIfPresent(char key, CharShortUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - short newValue = mappingFunction.applyAsShort(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public short computeShortIfPresentNonDefault(char key, CharShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2BooleanOpenHashMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2BooleanOpenHashMap.java index 148c9bdf..2c2a74c0 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2BooleanOpenHashMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2BooleanOpenHashMap.java @@ -408,68 +408,78 @@ public boolean computeBoolean(char key, CharBooleanUnaryOperator mappingFunction values[index] = newValue; return newValue; } - + @Override - public boolean computeBooleanNonDefault(char key, CharBooleanUnaryOperator mappingFunction) { + public boolean computeBooleanIfAbsent(char key, CharPredicate mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + boolean newValue = mappingFunction.test(key); insert(-index-1, key, newValue); return newValue; } - boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + boolean newValue = values[index]; return newValue; } @Override - public boolean computeBooleanIfAbsent(char key, CharPredicate mappingFunction) { - Objects.requireNonNull(mappingFunction); + public boolean supplyBooleanIfAbsent(char key, BooleanSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - boolean newValue = mappingFunction.test(key); + boolean newValue = valueProvider.getAsBoolean(); insert(-index-1, key, newValue); return newValue; } boolean newValue = values[index]; return newValue; } + + @Override + public boolean computeBooleanIfPresent(char key, CharBooleanUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public boolean computeBooleanIfAbsentNonDefault(char key, CharPredicate mappingFunction) { + public boolean computeBooleanNonDefault(char key, CharBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - boolean newValue = mappingFunction.test(key); + boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - boolean newValue = values[index]; + boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.test(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public boolean supplyBooleanIfAbsent(char key, BooleanSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public boolean computeBooleanIfAbsentNonDefault(char key, CharPredicate mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - boolean newValue = valueProvider.getAsBoolean(); + boolean newValue = mappingFunction.test(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } boolean newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.test(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -492,16 +502,6 @@ public boolean supplyBooleanIfAbsentNonDefault(char key, BooleanSupplier valuePr return newValue; } - @Override - public boolean computeBooleanIfPresent(char key, CharBooleanUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public boolean computeBooleanIfPresentNonDefault(char key, CharBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2ByteOpenHashMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2ByteOpenHashMap.java index eb2c38d0..0dc979bf 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2ByteOpenHashMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2ByteOpenHashMap.java @@ -430,68 +430,78 @@ public byte computeByte(char key, CharByteUnaryOperator mappingFunction) { values[index] = newValue; return newValue; } - + @Override - public byte computeByteNonDefault(char key, CharByteUnaryOperator mappingFunction) { + public byte computeByteIfAbsent(char key, Char2ByteFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + byte newValue = mappingFunction.applyAsByte(key); insert(-index-1, key, newValue); return newValue; } - byte newValue = mappingFunction.applyAsByte(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + byte newValue = values[index]; return newValue; } @Override - public byte computeByteIfAbsent(char key, Char2ByteFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public byte supplyByteIfAbsent(char key, ByteSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = valueProvider.getAsByte(); insert(-index-1, key, newValue); return newValue; } byte newValue = values[index]; return newValue; } + + @Override + public byte computeByteIfPresent(char key, CharByteUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + byte newValue = mappingFunction.applyAsByte(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public byte computeByteIfAbsentNonDefault(char key, Char2ByteFunction mappingFunction) { + public byte computeByteNonDefault(char key, CharByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - byte newValue = values[index]; + byte newValue = mappingFunction.applyAsByte(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsByte(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public byte supplyByteIfAbsent(char key, ByteSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public byte computeByteIfAbsentNonDefault(char key, Char2ByteFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - byte newValue = valueProvider.getAsInt(); + byte newValue = mappingFunction.applyAsByte(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } byte newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsByte(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -500,30 +510,20 @@ public byte supplyByteIfAbsentNonDefault(char key, ByteSupplier valueProvider) { Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - byte newValue = valueProvider.getAsInt(); + byte newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } byte newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public byte computeByteIfPresent(char key, CharByteUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - byte newValue = mappingFunction.applyAsByte(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public byte computeByteIfPresentNonDefault(char key, CharByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2CharOpenHashMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2CharOpenHashMap.java index dd8c9687..04202627 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2CharOpenHashMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2CharOpenHashMap.java @@ -424,68 +424,78 @@ public char computeChar(char key, CharCharUnaryOperator mappingFunction) { values[index] = newValue; return newValue; } - + @Override - public char computeCharNonDefault(char key, CharCharUnaryOperator mappingFunction) { + public char computeCharIfAbsent(char key, CharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + char newValue = mappingFunction.applyAsChar(key); insert(-index-1, key, newValue); return newValue; } - char newValue = mappingFunction.applyAsChar(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + char newValue = values[index]; return newValue; } @Override - public char computeCharIfAbsent(char key, CharUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); + public char supplyCharIfAbsent(char key, CharSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = valueProvider.getAsChar(); insert(-index-1, key, newValue); return newValue; } char newValue = values[index]; return newValue; } + + @Override + public char computeCharIfPresent(char key, CharCharUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + char newValue = mappingFunction.applyAsChar(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public char computeCharIfAbsentNonDefault(char key, CharUnaryOperator mappingFunction) { + public char computeCharNonDefault(char key, CharCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - char newValue = values[index]; + char newValue = mappingFunction.applyAsChar(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsChar(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public char supplyCharIfAbsent(char key, CharSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public char computeCharIfAbsentNonDefault(char key, CharUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - char newValue = valueProvider.getAsInt(); + char newValue = mappingFunction.applyAsChar(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } char newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsChar(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -494,30 +504,20 @@ public char supplyCharIfAbsentNonDefault(char key, CharSupplier valueProvider) { Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - char newValue = valueProvider.getAsInt(); + char newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } char newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public char computeCharIfPresent(char key, CharCharUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - char newValue = mappingFunction.applyAsChar(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public char computeCharIfPresentNonDefault(char key, CharCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2DoubleOpenHashMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2DoubleOpenHashMap.java index 7b1ee796..7020e0fd 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2DoubleOpenHashMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2DoubleOpenHashMap.java @@ -430,68 +430,78 @@ public double computeDouble(char key, CharDoubleUnaryOperator mappingFunction) { values[index] = newValue; return newValue; } - + @Override - public double computeDoubleNonDefault(char key, CharDoubleUnaryOperator mappingFunction) { + public double computeDoubleIfAbsent(char key, Char2DoubleFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + double newValue = mappingFunction.applyAsDouble(key); insert(-index-1, key, newValue); return newValue; } - double newValue = mappingFunction.applyAsDouble(key, values[index]); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + double newValue = values[index]; return newValue; } @Override - public double computeDoubleIfAbsent(char key, Char2DoubleFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public double supplyDoubleIfAbsent(char key, DoubleSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = valueProvider.getAsDouble(); insert(-index-1, key, newValue); return newValue; } double newValue = values[index]; return newValue; } + + @Override + public double computeDoubleIfPresent(char key, CharDoubleUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + double newValue = mappingFunction.applyAsDouble(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public double computeDoubleIfAbsentNonDefault(char key, Char2DoubleFunction mappingFunction) { + public double computeDoubleNonDefault(char key, CharDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } - double newValue = values[index]; + double newValue = mappingFunction.applyAsDouble(key, values[index]); if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - newValue = mappingFunction.applyAsDouble(key); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public double supplyDoubleIfAbsent(char key, DoubleSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public double computeDoubleIfAbsentNonDefault(char key, Char2DoubleFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - double newValue = valueProvider.getAsDouble(); + double newValue = mappingFunction.applyAsDouble(key); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } double newValue = values[index]; + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { + newValue = mappingFunction.applyAsDouble(key); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + values[index] = newValue; + } return newValue; } @@ -514,16 +524,6 @@ public double supplyDoubleIfAbsentNonDefault(char key, DoubleSupplier valueProvi return newValue; } - @Override - public double computeDoubleIfPresent(char key, CharDoubleUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - double newValue = mappingFunction.applyAsDouble(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public double computeDoubleIfPresentNonDefault(char key, CharDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2FloatOpenHashMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2FloatOpenHashMap.java index 1e494b23..49b036d6 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2FloatOpenHashMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2FloatOpenHashMap.java @@ -430,68 +430,78 @@ public float computeFloat(char key, CharFloatUnaryOperator mappingFunction) { values[index] = newValue; return newValue; } - + @Override - public float computeFloatNonDefault(char key, CharFloatUnaryOperator mappingFunction) { + public float computeFloatIfAbsent(char key, Char2FloatFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + float newValue = mappingFunction.applyAsFloat(key); insert(-index-1, key, newValue); return newValue; } - float newValue = mappingFunction.applyAsFloat(key, values[index]); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + float newValue = values[index]; return newValue; } @Override - public float computeFloatIfAbsent(char key, Char2FloatFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public float supplyFloatIfAbsent(char key, FloatSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = valueProvider.getAsFloat(); insert(-index-1, key, newValue); return newValue; } float newValue = values[index]; return newValue; } + + @Override + public float computeFloatIfPresent(char key, CharFloatUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + float newValue = mappingFunction.applyAsFloat(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public float computeFloatIfAbsentNonDefault(char key, Char2FloatFunction mappingFunction) { + public float computeFloatNonDefault(char key, CharFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } - float newValue = values[index]; + float newValue = mappingFunction.applyAsFloat(key, values[index]); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - newValue = mappingFunction.applyAsFloat(key); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public float supplyFloatIfAbsent(char key, FloatSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public float computeFloatIfAbsentNonDefault(char key, Char2FloatFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - float newValue = valueProvider.getAsDouble(); + float newValue = mappingFunction.applyAsFloat(key); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } float newValue = values[index]; + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { + newValue = mappingFunction.applyAsFloat(key); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + values[index] = newValue; + } return newValue; } @@ -500,30 +510,20 @@ public float supplyFloatIfAbsentNonDefault(char key, FloatSupplier valueProvider Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - float newValue = valueProvider.getAsDouble(); + float newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } float newValue = values[index]; if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - newValue = valueProvider.getAsDouble(); + newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; values[index] = newValue; } return newValue; } - @Override - public float computeFloatIfPresent(char key, CharFloatUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - float newValue = mappingFunction.applyAsFloat(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public float computeFloatIfPresentNonDefault(char key, CharFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2IntOpenHashMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2IntOpenHashMap.java index 160d4cc6..eea889c4 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2IntOpenHashMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2IntOpenHashMap.java @@ -430,68 +430,78 @@ public int computeInt(char key, CharIntUnaryOperator mappingFunction) { values[index] = newValue; return newValue; } - + @Override - public int computeIntNonDefault(char key, CharIntUnaryOperator mappingFunction) { + public int computeIntIfAbsent(char key, Char2IntFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + int newValue = mappingFunction.applyAsInt(key); insert(-index-1, key, newValue); return newValue; } - int newValue = mappingFunction.applyAsInt(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + int newValue = values[index]; return newValue; } @Override - public int computeIntIfAbsent(char key, Char2IntFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public int supplyIntIfAbsent(char key, IntSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = valueProvider.getAsInt(); insert(-index-1, key, newValue); return newValue; } int newValue = values[index]; return newValue; } + + @Override + public int computeIntIfPresent(char key, CharIntUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + int newValue = mappingFunction.applyAsInt(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public int computeIntIfAbsentNonDefault(char key, Char2IntFunction mappingFunction) { + public int computeIntNonDefault(char key, CharIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - int newValue = values[index]; + int newValue = mappingFunction.applyAsInt(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsInt(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public int supplyIntIfAbsent(char key, IntSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public int computeIntIfAbsentNonDefault(char key, Char2IntFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - int newValue = valueProvider.getAsInt(); + int newValue = mappingFunction.applyAsInt(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } int newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsInt(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -514,16 +524,6 @@ public int supplyIntIfAbsentNonDefault(char key, IntSupplier valueProvider) { return newValue; } - @Override - public int computeIntIfPresent(char key, CharIntUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - int newValue = mappingFunction.applyAsInt(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public int computeIntIfPresentNonDefault(char key, CharIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2LongOpenHashMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2LongOpenHashMap.java index f8b54e06..52348d18 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2LongOpenHashMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2LongOpenHashMap.java @@ -430,68 +430,78 @@ public long computeLong(char key, CharLongUnaryOperator mappingFunction) { values[index] = newValue; return newValue; } - + @Override - public long computeLongNonDefault(char key, CharLongUnaryOperator mappingFunction) { + public long computeLongIfAbsent(char key, Char2LongFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + long newValue = mappingFunction.applyAsLong(key); insert(-index-1, key, newValue); return newValue; } - long newValue = mappingFunction.applyAsLong(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + long newValue = values[index]; return newValue; } @Override - public long computeLongIfAbsent(char key, Char2LongFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public long supplyLongIfAbsent(char key, LongSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = valueProvider.getAsLong(); insert(-index-1, key, newValue); return newValue; } long newValue = values[index]; return newValue; } + + @Override + public long computeLongIfPresent(char key, CharLongUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + long newValue = mappingFunction.applyAsLong(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public long computeLongIfAbsentNonDefault(char key, Char2LongFunction mappingFunction) { + public long computeLongNonDefault(char key, CharLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - long newValue = values[index]; + long newValue = mappingFunction.applyAsLong(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsLong(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public long supplyLongIfAbsent(char key, LongSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public long computeLongIfAbsentNonDefault(char key, Char2LongFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - long newValue = valueProvider.getAsLong(); + long newValue = mappingFunction.applyAsLong(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } long newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsLong(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -514,16 +524,6 @@ public long supplyLongIfAbsentNonDefault(char key, LongSupplier valueProvider) { return newValue; } - @Override - public long computeLongIfPresent(char key, CharLongUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - long newValue = mappingFunction.applyAsLong(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public long computeLongIfPresentNonDefault(char key, CharLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2ObjectOpenHashMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2ObjectOpenHashMap.java index 6e4a1b29..5b2ea01f 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2ObjectOpenHashMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2ObjectOpenHashMap.java @@ -401,26 +401,7 @@ public V compute(char key, CharObjectUnaryOperator mappingFunction) { values[index] = newValue; return newValue; } - - @Override - public V computeNonDefault(char key, CharObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) { - V newValue = mappingFunction.apply(key, getDefaultReturnValue()); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = mappingFunction.apply(key, values[index]); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; - return newValue; - } - + @Override public V computeIfAbsent(char key, CharFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -440,25 +421,6 @@ public V computeIfAbsent(char key, CharFunction mappingFunction) { return newValue; } - @Override - public V computeIfAbsentNonDefault(char key, CharFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) { - V newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = values[index]; - if(Objects.equals(newValue, getDefaultReturnValue())) { - newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - values[index] = newValue; - } - return newValue; - } - @Override public V supplyIfAbsent(char key, ObjectSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -477,26 +439,7 @@ public V supplyIfAbsent(char key, ObjectSupplier valueProvider) { } return newValue; } - - @Override - public V supplyIfAbsentNonDefault(char key, ObjectSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - int index = findIndex(key); - if(index < 0) { - V newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = values[index]; - if(Objects.equals(newValue, getDefaultReturnValue())) { - newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - values[index] = newValue; - } - return newValue; - } - + @Override public V computeIfPresent(char key, CharObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -511,20 +454,6 @@ public V computeIfPresent(char key, CharObjectUnaryOperator mappingFunction) return newValue; } - @Override - public V computeIfPresentNonDefault(char key, CharObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0 || Objects.equals(values[index], getDefaultReturnValue())) return getDefaultReturnValue(); - V newValue = mappingFunction.apply(key, values[index]); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; - return newValue; - } - @Override public V merge(char key, V value, ObjectObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2ShortOpenHashMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2ShortOpenHashMap.java index 0f7221fc..26674468 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2ShortOpenHashMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/hash/Char2ShortOpenHashMap.java @@ -430,68 +430,78 @@ public short computeShort(char key, CharShortUnaryOperator mappingFunction) { values[index] = newValue; return newValue; } - + @Override - public short computeShortNonDefault(char key, CharShortUnaryOperator mappingFunction) { + public short computeShortIfAbsent(char key, Char2ShortFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + short newValue = mappingFunction.applyAsShort(key); insert(-index-1, key, newValue); return newValue; } - short newValue = mappingFunction.applyAsShort(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + short newValue = values[index]; return newValue; } @Override - public short computeShortIfAbsent(char key, Char2ShortFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public short supplyShortIfAbsent(char key, ShortSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = valueProvider.getAsShort(); insert(-index-1, key, newValue); return newValue; } short newValue = values[index]; return newValue; } + + @Override + public short computeShortIfPresent(char key, CharShortUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + short newValue = mappingFunction.applyAsShort(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public short computeShortIfAbsentNonDefault(char key, Char2ShortFunction mappingFunction) { + public short computeShortNonDefault(char key, CharShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - short newValue = values[index]; + short newValue = mappingFunction.applyAsShort(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsShort(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public short supplyShortIfAbsent(char key, ShortSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public short computeShortIfAbsentNonDefault(char key, Char2ShortFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - short newValue = valueProvider.getAsInt(); + short newValue = mappingFunction.applyAsShort(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } short newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsShort(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -500,30 +510,20 @@ public short supplyShortIfAbsentNonDefault(char key, ShortSupplier valueProvider Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - short newValue = valueProvider.getAsInt(); + short newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } short newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public short computeShortIfPresent(char key, CharShortUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - short newValue = mappingFunction.applyAsShort(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public short computeShortIfPresentNonDefault(char key, CharShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/immutable/ImmutableChar2BooleanOpenHashMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/immutable/ImmutableChar2BooleanOpenHashMap.java index ab255f9d..5609e591 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/immutable/ImmutableChar2BooleanOpenHashMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/immutable/ImmutableChar2BooleanOpenHashMap.java @@ -413,20 +413,19 @@ public void forEach(CharBooleanConsumer action) { @Override public boolean computeBoolean(char key, CharBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanNonDefault(char key, CharBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean computeBooleanIfAbsent(char key, CharPredicate mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanIfAbsentNonDefault(char key, CharPredicate mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean supplyBooleanIfAbsent(char key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public boolean supplyBooleanIfAbsentNonDefault(char key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public boolean computeBooleanIfPresent(char key, CharBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override + public boolean computeBooleanNonDefault(char key, CharBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public boolean computeBooleanIfAbsentNonDefault(char key, CharPredicate mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public boolean supplyBooleanIfAbsentNonDefault(char key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } + @Override public boolean computeBooleanIfPresentNonDefault(char key, CharBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean mergeBoolean(char key, boolean value, BooleanBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/immutable/ImmutableChar2ByteOpenHashMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/immutable/ImmutableChar2ByteOpenHashMap.java index 261cf102..7e2c5022 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/immutable/ImmutableChar2ByteOpenHashMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/immutable/ImmutableChar2ByteOpenHashMap.java @@ -418,20 +418,19 @@ public void forEach(CharByteConsumer action) { @Override public byte computeByte(char key, CharByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteNonDefault(char key, CharByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte computeByteIfAbsent(char key, Char2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteIfAbsentNonDefault(char key, Char2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte supplyByteIfAbsent(char key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public byte supplyByteIfAbsentNonDefault(char key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public byte computeByteIfPresent(char key, CharByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override + public byte computeByteNonDefault(char key, CharByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public byte computeByteIfAbsentNonDefault(char key, Char2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public byte supplyByteIfAbsentNonDefault(char key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } + @Override public byte computeByteIfPresentNonDefault(char key, CharByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte mergeByte(char key, byte value, ByteByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/immutable/ImmutableChar2CharOpenHashMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/immutable/ImmutableChar2CharOpenHashMap.java index 6fe5a534..48e2675a 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/immutable/ImmutableChar2CharOpenHashMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/immutable/ImmutableChar2CharOpenHashMap.java @@ -409,20 +409,19 @@ public void forEach(CharCharConsumer action) { @Override public char computeChar(char key, CharCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharNonDefault(char key, CharCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char computeCharIfAbsent(char key, CharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharIfAbsentNonDefault(char key, CharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char supplyCharIfAbsent(char key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public char supplyCharIfAbsentNonDefault(char key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public char computeCharIfPresent(char key, CharCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override + public char computeCharNonDefault(char key, CharCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public char computeCharIfAbsentNonDefault(char key, CharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public char supplyCharIfAbsentNonDefault(char key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } + @Override public char computeCharIfPresentNonDefault(char key, CharCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char mergeChar(char key, char value, CharCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/immutable/ImmutableChar2DoubleOpenHashMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/immutable/ImmutableChar2DoubleOpenHashMap.java index 9b043016..ac400e2d 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/immutable/ImmutableChar2DoubleOpenHashMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/immutable/ImmutableChar2DoubleOpenHashMap.java @@ -418,20 +418,19 @@ public void forEach(CharDoubleConsumer action) { @Override public double computeDouble(char key, CharDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleNonDefault(char key, CharDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double computeDoubleIfAbsent(char key, Char2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleIfAbsentNonDefault(char key, Char2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double supplyDoubleIfAbsent(char key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public double supplyDoubleIfAbsentNonDefault(char key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public double computeDoubleIfPresent(char key, CharDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override + public double computeDoubleNonDefault(char key, CharDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public double computeDoubleIfAbsentNonDefault(char key, Char2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public double supplyDoubleIfAbsentNonDefault(char key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } + @Override public double computeDoubleIfPresentNonDefault(char key, CharDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double mergeDouble(char key, double value, DoubleDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/immutable/ImmutableChar2FloatOpenHashMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/immutable/ImmutableChar2FloatOpenHashMap.java index 09d8592d..33af531a 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/immutable/ImmutableChar2FloatOpenHashMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/immutable/ImmutableChar2FloatOpenHashMap.java @@ -418,20 +418,19 @@ public void forEach(CharFloatConsumer action) { @Override public float computeFloat(char key, CharFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatNonDefault(char key, CharFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float computeFloatIfAbsent(char key, Char2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatIfAbsentNonDefault(char key, Char2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float supplyFloatIfAbsent(char key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public float supplyFloatIfAbsentNonDefault(char key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public float computeFloatIfPresent(char key, CharFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override + public float computeFloatNonDefault(char key, CharFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public float computeFloatIfAbsentNonDefault(char key, Char2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public float supplyFloatIfAbsentNonDefault(char key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } + @Override public float computeFloatIfPresentNonDefault(char key, CharFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float mergeFloat(char key, float value, FloatFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/immutable/ImmutableChar2IntOpenHashMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/immutable/ImmutableChar2IntOpenHashMap.java index 5da1a673..5376a770 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/immutable/ImmutableChar2IntOpenHashMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/immutable/ImmutableChar2IntOpenHashMap.java @@ -418,20 +418,19 @@ public void forEach(CharIntConsumer action) { @Override public int computeInt(char key, CharIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntNonDefault(char key, CharIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int computeIntIfAbsent(char key, Char2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntIfAbsentNonDefault(char key, Char2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int supplyIntIfAbsent(char key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public int supplyIntIfAbsentNonDefault(char key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public int computeIntIfPresent(char key, CharIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override + public int computeIntNonDefault(char key, CharIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public int computeIntIfAbsentNonDefault(char key, Char2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public int supplyIntIfAbsentNonDefault(char key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } + @Override public int computeIntIfPresentNonDefault(char key, CharIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int mergeInt(char key, int value, IntIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/immutable/ImmutableChar2LongOpenHashMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/immutable/ImmutableChar2LongOpenHashMap.java index 39a64e00..73052944 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/immutable/ImmutableChar2LongOpenHashMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/immutable/ImmutableChar2LongOpenHashMap.java @@ -418,20 +418,19 @@ public void forEach(CharLongConsumer action) { @Override public long computeLong(char key, CharLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongNonDefault(char key, CharLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long computeLongIfAbsent(char key, Char2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongIfAbsentNonDefault(char key, Char2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long supplyLongIfAbsent(char key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public long supplyLongIfAbsentNonDefault(char key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public long computeLongIfPresent(char key, CharLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override + public long computeLongNonDefault(char key, CharLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public long computeLongIfAbsentNonDefault(char key, Char2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public long supplyLongIfAbsentNonDefault(char key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } + @Override public long computeLongIfPresentNonDefault(char key, CharLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long mergeLong(char key, long value, LongLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/immutable/ImmutableChar2ObjectOpenHashMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/immutable/ImmutableChar2ObjectOpenHashMap.java index d9f3efe7..fb2ea5a1 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/immutable/ImmutableChar2ObjectOpenHashMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/immutable/ImmutableChar2ObjectOpenHashMap.java @@ -397,20 +397,11 @@ public void forEach(CharObjectConsumer action) { @Override public V compute(char key, CharObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeNonDefault(char key, CharObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V computeIfAbsent(char key, CharFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeIfAbsentNonDefault(char key, CharFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V supplyIfAbsent(char key, ObjectSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public V supplyIfAbsentNonDefault(char key, ObjectSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public V computeIfPresent(char key, CharObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override - public V computeIfPresentNonDefault(char key, CharObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V merge(char key, V value, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/immutable/ImmutableChar2ShortOpenHashMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/immutable/ImmutableChar2ShortOpenHashMap.java index 35ef8a0d..8cd06ff1 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/immutable/ImmutableChar2ShortOpenHashMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/immutable/ImmutableChar2ShortOpenHashMap.java @@ -418,20 +418,19 @@ public void forEach(CharShortConsumer action) { @Override public short computeShort(char key, CharShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortNonDefault(char key, CharShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short computeShortIfAbsent(char key, Char2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortIfAbsentNonDefault(char key, Char2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short supplyShortIfAbsent(char key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public short supplyShortIfAbsentNonDefault(char key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public short computeShortIfPresent(char key, CharShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override + public short computeShortNonDefault(char key, CharShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public short computeShortIfAbsentNonDefault(char key, Char2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public short supplyShortIfAbsentNonDefault(char key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } + @Override public short computeShortIfPresentNonDefault(char key, CharShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short mergeShort(char key, short value, ShortShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/misc/Char2BooleanArrayMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/misc/Char2BooleanArrayMap.java index 319024c8..b31f12cd 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/misc/Char2BooleanArrayMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/misc/Char2BooleanArrayMap.java @@ -420,66 +420,76 @@ public boolean computeBoolean(char key, CharBooleanUnaryOperator mappingFunction } @Override - public boolean computeBooleanNonDefault(char key, CharBooleanUnaryOperator mappingFunction) { + public boolean computeBooleanIfAbsent(char key, CharPredicate mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + boolean newValue = mappingFunction.test(key); insertIndex(size++, key, newValue); return newValue; } - boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + boolean newValue = values[index]; return newValue; } - + @Override - public boolean computeBooleanIfAbsent(char key, CharPredicate mappingFunction) { - Objects.requireNonNull(mappingFunction); + public boolean supplyBooleanIfAbsent(char key, BooleanSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - boolean newValue = mappingFunction.test(key); + boolean newValue = valueProvider.getAsBoolean(); insertIndex(size++, key, newValue); return newValue; } boolean newValue = values[index]; return newValue; } + + @Override + public boolean computeBooleanIfPresent(char key, CharBooleanUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index == -1) return getDefaultReturnValue(); + boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public boolean computeBooleanIfAbsentNonDefault(char key, CharPredicate mappingFunction) { + public boolean computeBooleanNonDefault(char key, CharBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - boolean newValue = mappingFunction.test(key); + boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } - boolean newValue = values[index]; + boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.test(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public boolean supplyBooleanIfAbsent(char key, BooleanSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public boolean computeBooleanIfAbsentNonDefault(char key, CharPredicate mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - boolean newValue = valueProvider.getAsBoolean(); + boolean newValue = mappingFunction.test(key); + if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } boolean newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.test(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -502,16 +512,6 @@ public boolean supplyBooleanIfAbsentNonDefault(char key, BooleanSupplier valuePr return newValue; } - @Override - public boolean computeBooleanIfPresent(char key, CharBooleanUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) return getDefaultReturnValue(); - boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public boolean computeBooleanIfPresentNonDefault(char key, CharBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/misc/Char2ByteArrayMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/misc/Char2ByteArrayMap.java index 11cc422f..88731b86 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/misc/Char2ByteArrayMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/misc/Char2ByteArrayMap.java @@ -443,66 +443,76 @@ public byte computeByte(char key, CharByteUnaryOperator mappingFunction) { } @Override - public byte computeByteNonDefault(char key, CharByteUnaryOperator mappingFunction) { + public byte computeByteIfAbsent(char key, Char2ByteFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + byte newValue = mappingFunction.applyAsByte(key); insertIndex(size++, key, newValue); return newValue; } - byte newValue = mappingFunction.applyAsByte(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + byte newValue = values[index]; return newValue; } - + @Override - public byte computeByteIfAbsent(char key, Char2ByteFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public byte supplyByteIfAbsent(char key, ByteSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = valueProvider.getAsByte(); insertIndex(size++, key, newValue); return newValue; } byte newValue = values[index]; return newValue; } + + @Override + public byte computeByteIfPresent(char key, CharByteUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index == -1) return getDefaultReturnValue(); + byte newValue = mappingFunction.applyAsByte(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public byte computeByteIfAbsentNonDefault(char key, Char2ByteFunction mappingFunction) { + public byte computeByteNonDefault(char key, CharByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } - byte newValue = values[index]; + byte newValue = mappingFunction.applyAsByte(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsByte(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public byte supplyByteIfAbsent(char key, ByteSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public byte computeByteIfAbsentNonDefault(char key, Char2ByteFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - byte newValue = valueProvider.getAsInt(); + byte newValue = mappingFunction.applyAsByte(key); + if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } byte newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsByte(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -511,30 +521,20 @@ public byte supplyByteIfAbsentNonDefault(char key, ByteSupplier valueProvider) { Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - byte newValue = valueProvider.getAsInt(); + byte newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } byte newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public byte computeByteIfPresent(char key, CharByteUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) return getDefaultReturnValue(); - byte newValue = mappingFunction.applyAsByte(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public byte computeByteIfPresentNonDefault(char key, CharByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/misc/Char2CharArrayMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/misc/Char2CharArrayMap.java index e08dfd5b..67daf627 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/misc/Char2CharArrayMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/misc/Char2CharArrayMap.java @@ -436,66 +436,76 @@ public char computeChar(char key, CharCharUnaryOperator mappingFunction) { } @Override - public char computeCharNonDefault(char key, CharCharUnaryOperator mappingFunction) { + public char computeCharIfAbsent(char key, CharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + char newValue = mappingFunction.applyAsChar(key); insertIndex(size++, key, newValue); return newValue; } - char newValue = mappingFunction.applyAsChar(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + char newValue = values[index]; return newValue; } - + @Override - public char computeCharIfAbsent(char key, CharUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); + public char supplyCharIfAbsent(char key, CharSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = valueProvider.getAsChar(); insertIndex(size++, key, newValue); return newValue; } char newValue = values[index]; return newValue; } + + @Override + public char computeCharIfPresent(char key, CharCharUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index == -1) return getDefaultReturnValue(); + char newValue = mappingFunction.applyAsChar(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public char computeCharIfAbsentNonDefault(char key, CharUnaryOperator mappingFunction) { + public char computeCharNonDefault(char key, CharCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } - char newValue = values[index]; + char newValue = mappingFunction.applyAsChar(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsChar(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public char supplyCharIfAbsent(char key, CharSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public char computeCharIfAbsentNonDefault(char key, CharUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - char newValue = valueProvider.getAsInt(); + char newValue = mappingFunction.applyAsChar(key); + if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } char newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsChar(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -504,30 +514,20 @@ public char supplyCharIfAbsentNonDefault(char key, CharSupplier valueProvider) { Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - char newValue = valueProvider.getAsInt(); + char newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } char newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public char computeCharIfPresent(char key, CharCharUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) return getDefaultReturnValue(); - char newValue = mappingFunction.applyAsChar(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public char computeCharIfPresentNonDefault(char key, CharCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/misc/Char2DoubleArrayMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/misc/Char2DoubleArrayMap.java index 645ab293..0b828e95 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/misc/Char2DoubleArrayMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/misc/Char2DoubleArrayMap.java @@ -443,66 +443,76 @@ public double computeDouble(char key, CharDoubleUnaryOperator mappingFunction) { } @Override - public double computeDoubleNonDefault(char key, CharDoubleUnaryOperator mappingFunction) { + public double computeDoubleIfAbsent(char key, Char2DoubleFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + double newValue = mappingFunction.applyAsDouble(key); insertIndex(size++, key, newValue); return newValue; } - double newValue = mappingFunction.applyAsDouble(key, values[index]); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + double newValue = values[index]; return newValue; } - + @Override - public double computeDoubleIfAbsent(char key, Char2DoubleFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public double supplyDoubleIfAbsent(char key, DoubleSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = valueProvider.getAsDouble(); insertIndex(size++, key, newValue); return newValue; } double newValue = values[index]; return newValue; } + + @Override + public double computeDoubleIfPresent(char key, CharDoubleUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index == -1) return getDefaultReturnValue(); + double newValue = mappingFunction.applyAsDouble(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public double computeDoubleIfAbsentNonDefault(char key, Char2DoubleFunction mappingFunction) { + public double computeDoubleNonDefault(char key, CharDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; insertIndex(size++, key, newValue); return newValue; } - double newValue = values[index]; + double newValue = mappingFunction.applyAsDouble(key, values[index]); if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - newValue = mappingFunction.applyAsDouble(key); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public double supplyDoubleIfAbsent(char key, DoubleSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public double computeDoubleIfAbsentNonDefault(char key, Char2DoubleFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - double newValue = valueProvider.getAsDouble(); + double newValue = mappingFunction.applyAsDouble(key); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; insertIndex(size++, key, newValue); return newValue; } double newValue = values[index]; + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { + newValue = mappingFunction.applyAsDouble(key); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + values[index] = newValue; + } return newValue; } @@ -525,16 +535,6 @@ public double supplyDoubleIfAbsentNonDefault(char key, DoubleSupplier valueProvi return newValue; } - @Override - public double computeDoubleIfPresent(char key, CharDoubleUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) return getDefaultReturnValue(); - double newValue = mappingFunction.applyAsDouble(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public double computeDoubleIfPresentNonDefault(char key, CharDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/misc/Char2FloatArrayMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/misc/Char2FloatArrayMap.java index 74b1cb10..5fab7109 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/misc/Char2FloatArrayMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/misc/Char2FloatArrayMap.java @@ -443,66 +443,76 @@ public float computeFloat(char key, CharFloatUnaryOperator mappingFunction) { } @Override - public float computeFloatNonDefault(char key, CharFloatUnaryOperator mappingFunction) { + public float computeFloatIfAbsent(char key, Char2FloatFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + float newValue = mappingFunction.applyAsFloat(key); insertIndex(size++, key, newValue); return newValue; } - float newValue = mappingFunction.applyAsFloat(key, values[index]); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + float newValue = values[index]; return newValue; } - + @Override - public float computeFloatIfAbsent(char key, Char2FloatFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public float supplyFloatIfAbsent(char key, FloatSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = valueProvider.getAsFloat(); insertIndex(size++, key, newValue); return newValue; } float newValue = values[index]; return newValue; } + + @Override + public float computeFloatIfPresent(char key, CharFloatUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index == -1) return getDefaultReturnValue(); + float newValue = mappingFunction.applyAsFloat(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public float computeFloatIfAbsentNonDefault(char key, Char2FloatFunction mappingFunction) { + public float computeFloatNonDefault(char key, CharFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insertIndex(size++, key, newValue); return newValue; } - float newValue = values[index]; + float newValue = mappingFunction.applyAsFloat(key, values[index]); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - newValue = mappingFunction.applyAsFloat(key); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public float supplyFloatIfAbsent(char key, FloatSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public float computeFloatIfAbsentNonDefault(char key, Char2FloatFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - float newValue = valueProvider.getAsDouble(); + float newValue = mappingFunction.applyAsFloat(key); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insertIndex(size++, key, newValue); return newValue; } float newValue = values[index]; + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { + newValue = mappingFunction.applyAsFloat(key); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + values[index] = newValue; + } return newValue; } @@ -511,30 +521,20 @@ public float supplyFloatIfAbsentNonDefault(char key, FloatSupplier valueProvider Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - float newValue = valueProvider.getAsDouble(); + float newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insertIndex(size++, key, newValue); return newValue; } float newValue = values[index]; if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - newValue = valueProvider.getAsDouble(); + newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; values[index] = newValue; } return newValue; } - @Override - public float computeFloatIfPresent(char key, CharFloatUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) return getDefaultReturnValue(); - float newValue = mappingFunction.applyAsFloat(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public float computeFloatIfPresentNonDefault(char key, CharFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/misc/Char2IntArrayMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/misc/Char2IntArrayMap.java index 4965fd78..21a88051 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/misc/Char2IntArrayMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/misc/Char2IntArrayMap.java @@ -443,66 +443,76 @@ public int computeInt(char key, CharIntUnaryOperator mappingFunction) { } @Override - public int computeIntNonDefault(char key, CharIntUnaryOperator mappingFunction) { + public int computeIntIfAbsent(char key, Char2IntFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + int newValue = mappingFunction.applyAsInt(key); insertIndex(size++, key, newValue); return newValue; } - int newValue = mappingFunction.applyAsInt(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + int newValue = values[index]; return newValue; } - + @Override - public int computeIntIfAbsent(char key, Char2IntFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public int supplyIntIfAbsent(char key, IntSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = valueProvider.getAsInt(); insertIndex(size++, key, newValue); return newValue; } int newValue = values[index]; return newValue; } + + @Override + public int computeIntIfPresent(char key, CharIntUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index == -1) return getDefaultReturnValue(); + int newValue = mappingFunction.applyAsInt(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public int computeIntIfAbsentNonDefault(char key, Char2IntFunction mappingFunction) { + public int computeIntNonDefault(char key, CharIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } - int newValue = values[index]; + int newValue = mappingFunction.applyAsInt(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsInt(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public int supplyIntIfAbsent(char key, IntSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public int computeIntIfAbsentNonDefault(char key, Char2IntFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - int newValue = valueProvider.getAsInt(); + int newValue = mappingFunction.applyAsInt(key); + if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } int newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsInt(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -525,16 +535,6 @@ public int supplyIntIfAbsentNonDefault(char key, IntSupplier valueProvider) { return newValue; } - @Override - public int computeIntIfPresent(char key, CharIntUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) return getDefaultReturnValue(); - int newValue = mappingFunction.applyAsInt(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public int computeIntIfPresentNonDefault(char key, CharIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/misc/Char2LongArrayMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/misc/Char2LongArrayMap.java index 37b87ad7..a42f724b 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/misc/Char2LongArrayMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/misc/Char2LongArrayMap.java @@ -443,66 +443,76 @@ public long computeLong(char key, CharLongUnaryOperator mappingFunction) { } @Override - public long computeLongNonDefault(char key, CharLongUnaryOperator mappingFunction) { + public long computeLongIfAbsent(char key, Char2LongFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + long newValue = mappingFunction.applyAsLong(key); insertIndex(size++, key, newValue); return newValue; } - long newValue = mappingFunction.applyAsLong(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + long newValue = values[index]; return newValue; } - + @Override - public long computeLongIfAbsent(char key, Char2LongFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public long supplyLongIfAbsent(char key, LongSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = valueProvider.getAsLong(); insertIndex(size++, key, newValue); return newValue; } long newValue = values[index]; return newValue; } + + @Override + public long computeLongIfPresent(char key, CharLongUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index == -1) return getDefaultReturnValue(); + long newValue = mappingFunction.applyAsLong(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public long computeLongIfAbsentNonDefault(char key, Char2LongFunction mappingFunction) { + public long computeLongNonDefault(char key, CharLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } - long newValue = values[index]; + long newValue = mappingFunction.applyAsLong(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsLong(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public long supplyLongIfAbsent(char key, LongSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public long computeLongIfAbsentNonDefault(char key, Char2LongFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - long newValue = valueProvider.getAsLong(); + long newValue = mappingFunction.applyAsLong(key); + if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } long newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsLong(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -525,16 +535,6 @@ public long supplyLongIfAbsentNonDefault(char key, LongSupplier valueProvider) { return newValue; } - @Override - public long computeLongIfPresent(char key, CharLongUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) return getDefaultReturnValue(); - long newValue = mappingFunction.applyAsLong(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public long computeLongIfPresentNonDefault(char key, CharLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/misc/Char2ObjectArrayMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/misc/Char2ObjectArrayMap.java index 6d747dd6..82ec8a99 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/misc/Char2ObjectArrayMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/misc/Char2ObjectArrayMap.java @@ -415,25 +415,6 @@ public V compute(char key, CharObjectUnaryOperator mappingFunction) { return newValue; } - @Override - public V computeNonDefault(char key, CharObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) { - V newValue = mappingFunction.apply(key, getDefaultReturnValue()); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insertIndex(size++, key, newValue); - return newValue; - } - V newValue = mappingFunction.apply(key, values[index]); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; - return newValue; - } - @Override public V computeIfAbsent(char key, CharFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -452,26 +433,7 @@ public V computeIfAbsent(char key, CharFunction mappingFunction) { } return newValue; } - - @Override - public V computeIfAbsentNonDefault(char key, CharFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) { - V newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insertIndex(size++, key, newValue); - return newValue; - } - V newValue = values[index]; - if(Objects.equals(newValue, getDefaultReturnValue())) { - newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - values[index] = newValue; - } - return newValue; - } - + @Override public V supplyIfAbsent(char key, ObjectSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -490,26 +452,7 @@ public V supplyIfAbsent(char key, ObjectSupplier valueProvider) { } return newValue; } - - @Override - public V supplyIfAbsentNonDefault(char key, ObjectSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - int index = findIndex(key); - if(index == -1) { - V newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insertIndex(size++, key, newValue); - return newValue; - } - V newValue = values[index]; - if(Objects.equals(newValue, getDefaultReturnValue())) { - newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - values[index] = newValue; - } - return newValue; - } - + @Override public V computeIfPresent(char key, CharObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -524,20 +467,6 @@ public V computeIfPresent(char key, CharObjectUnaryOperator mappingFunction) return newValue; } - @Override - public V computeIfPresentNonDefault(char key, CharObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1 || Objects.equals(values[index], getDefaultReturnValue())) return getDefaultReturnValue(); - V newValue = mappingFunction.apply(key, values[index]); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; - return newValue; - } - @Override public V merge(char key, V value, ObjectObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/misc/Char2ShortArrayMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/misc/Char2ShortArrayMap.java index 6af5d8a1..82786502 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/misc/Char2ShortArrayMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/misc/Char2ShortArrayMap.java @@ -443,66 +443,76 @@ public short computeShort(char key, CharShortUnaryOperator mappingFunction) { } @Override - public short computeShortNonDefault(char key, CharShortUnaryOperator mappingFunction) { + public short computeShortIfAbsent(char key, Char2ShortFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + short newValue = mappingFunction.applyAsShort(key); insertIndex(size++, key, newValue); return newValue; } - short newValue = mappingFunction.applyAsShort(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + short newValue = values[index]; return newValue; } - + @Override - public short computeShortIfAbsent(char key, Char2ShortFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public short supplyShortIfAbsent(char key, ShortSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = valueProvider.getAsShort(); insertIndex(size++, key, newValue); return newValue; } short newValue = values[index]; return newValue; } + + @Override + public short computeShortIfPresent(char key, CharShortUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index == -1) return getDefaultReturnValue(); + short newValue = mappingFunction.applyAsShort(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public short computeShortIfAbsentNonDefault(char key, Char2ShortFunction mappingFunction) { + public short computeShortNonDefault(char key, CharShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } - short newValue = values[index]; + short newValue = mappingFunction.applyAsShort(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsShort(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public short supplyShortIfAbsent(char key, ShortSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public short computeShortIfAbsentNonDefault(char key, Char2ShortFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - short newValue = valueProvider.getAsInt(); + short newValue = mappingFunction.applyAsShort(key); + if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } short newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsShort(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -511,30 +521,20 @@ public short supplyShortIfAbsentNonDefault(char key, ShortSupplier valueProvider Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - short newValue = valueProvider.getAsInt(); + short newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } short newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public short computeShortIfPresent(char key, CharShortUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) return getDefaultReturnValue(); - short newValue = mappingFunction.applyAsShort(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public short computeShortIfPresentNonDefault(char key, CharShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2BooleanAVLTreeMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2BooleanAVLTreeMap.java index 8946dd09..cab1062a 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2BooleanAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2BooleanAVLTreeMap.java @@ -396,34 +396,56 @@ public boolean computeBoolean(char key, CharBooleanUnaryOperator mappingFunction } @Override - public boolean computeBooleanNonDefault(char key, CharBooleanUnaryOperator mappingFunction) { + public boolean computeBooleanIfAbsent(char key, CharPredicate mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + boolean newValue = mappingFunction.test(key); put(key, newValue); return newValue; } - boolean newValue = mappingFunction.applyAsBoolean(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public boolean supplyBooleanIfAbsent(char key, BooleanSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + boolean newValue = valueProvider.getAsBoolean(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public boolean computeBooleanIfPresent(char key, CharBooleanUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + boolean newValue = mappingFunction.applyAsBoolean(key, entry.value); entry.value = newValue; return newValue; } @Override - public boolean computeBooleanIfAbsent(char key, CharPredicate mappingFunction) { + public boolean computeBooleanNonDefault(char key, CharBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - boolean newValue = mappingFunction.test(key); + boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + boolean newValue = mappingFunction.applyAsBoolean(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -444,18 +466,6 @@ public boolean computeBooleanIfAbsentNonDefault(char key, CharPredicate mappingF return entry.value; } - @Override - public boolean supplyBooleanIfAbsent(char key, BooleanSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - boolean newValue = valueProvider.getAsBoolean(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public boolean supplyBooleanIfAbsentNonDefault(char key, BooleanSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -474,16 +484,6 @@ public boolean supplyBooleanIfAbsentNonDefault(char key, BooleanSupplier valuePr return entry.value; } - @Override - public boolean computeBooleanIfPresent(char key, CharBooleanUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - boolean newValue = mappingFunction.applyAsBoolean(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public boolean computeBooleanIfPresentNonDefault(char key, CharBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1487,14 +1487,9 @@ public boolean computeBooleanIfPresent(char key, CharBooleanUnaryOperator mappin Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - boolean newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2BooleanRBTreeMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2BooleanRBTreeMap.java index c721108f..4621948b 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2BooleanRBTreeMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2BooleanRBTreeMap.java @@ -395,34 +395,56 @@ public boolean computeBoolean(char key, CharBooleanUnaryOperator mappingFunction } @Override - public boolean computeBooleanNonDefault(char key, CharBooleanUnaryOperator mappingFunction) { + public boolean computeBooleanIfAbsent(char key, CharPredicate mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + boolean newValue = mappingFunction.test(key); put(key, newValue); return newValue; } - boolean newValue = mappingFunction.applyAsBoolean(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public boolean supplyBooleanIfAbsent(char key, BooleanSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + boolean newValue = valueProvider.getAsBoolean(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public boolean computeBooleanIfPresent(char key, CharBooleanUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + boolean newValue = mappingFunction.applyAsBoolean(key, entry.value); entry.value = newValue; return newValue; } @Override - public boolean computeBooleanIfAbsent(char key, CharPredicate mappingFunction) { + public boolean computeBooleanNonDefault(char key, CharBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - boolean newValue = mappingFunction.test(key); + boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + boolean newValue = mappingFunction.applyAsBoolean(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -443,18 +465,6 @@ public boolean computeBooleanIfAbsentNonDefault(char key, CharPredicate mappingF return entry.value; } - @Override - public boolean supplyBooleanIfAbsent(char key, BooleanSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - boolean newValue = valueProvider.getAsBoolean(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public boolean supplyBooleanIfAbsentNonDefault(char key, BooleanSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -473,16 +483,6 @@ public boolean supplyBooleanIfAbsentNonDefault(char key, BooleanSupplier valuePr return entry.value; } - @Override - public boolean computeBooleanIfPresent(char key, CharBooleanUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - boolean newValue = mappingFunction.applyAsBoolean(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public boolean computeBooleanIfPresentNonDefault(char key, CharBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1550,14 +1550,9 @@ public boolean computeBooleanIfPresent(char key, CharBooleanUnaryOperator mappin Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - boolean newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2ByteAVLTreeMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2ByteAVLTreeMap.java index 6d7895a1..c1ffbf47 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2ByteAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2ByteAVLTreeMap.java @@ -455,34 +455,56 @@ public byte computeByte(char key, CharByteUnaryOperator mappingFunction) { } @Override - public byte computeByteNonDefault(char key, CharByteUnaryOperator mappingFunction) { + public byte computeByteIfAbsent(char key, Char2ByteFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + byte newValue = mappingFunction.applyAsByte(key); put(key, newValue); return newValue; } - byte newValue = mappingFunction.applyAsByte(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public byte supplyByteIfAbsent(char key, ByteSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + byte newValue = valueProvider.getAsByte(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public byte computeByteIfPresent(char key, CharByteUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + byte newValue = mappingFunction.applyAsByte(key, entry.value); entry.value = newValue; return newValue; } @Override - public byte computeByteIfAbsent(char key, Char2ByteFunction mappingFunction) { + public byte computeByteNonDefault(char key, CharByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + byte newValue = mappingFunction.applyAsByte(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -503,46 +525,24 @@ public byte computeByteIfAbsentNonDefault(char key, Char2ByteFunction mappingFun return entry.value; } - @Override - public byte supplyByteIfAbsent(char key, ByteSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - byte newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public byte supplyByteIfAbsentNonDefault(char key, ByteSupplier valueProvider) { Objects.requireNonNull(valueProvider); Node entry = findNode(key); if(entry == null) { - byte newValue = valueProvider.getAsInt(); + byte newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } if(entry.value == getDefaultReturnValue()) { - byte newValue = valueProvider.getAsInt(); + byte newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; entry.value = newValue; } return entry.value; } - @Override - public byte computeByteIfPresent(char key, CharByteUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - byte newValue = mappingFunction.applyAsByte(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public byte computeByteIfPresentNonDefault(char key, CharByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1558,14 +1558,9 @@ public byte computeByteIfPresent(char key, CharByteUnaryOperator mappingFunction Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - byte newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2ByteRBTreeMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2ByteRBTreeMap.java index c4d2dc25..b2abf893 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2ByteRBTreeMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2ByteRBTreeMap.java @@ -454,34 +454,56 @@ public byte computeByte(char key, CharByteUnaryOperator mappingFunction) { } @Override - public byte computeByteNonDefault(char key, CharByteUnaryOperator mappingFunction) { + public byte computeByteIfAbsent(char key, Char2ByteFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + byte newValue = mappingFunction.applyAsByte(key); put(key, newValue); return newValue; } - byte newValue = mappingFunction.applyAsByte(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public byte supplyByteIfAbsent(char key, ByteSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + byte newValue = valueProvider.getAsByte(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public byte computeByteIfPresent(char key, CharByteUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + byte newValue = mappingFunction.applyAsByte(key, entry.value); entry.value = newValue; return newValue; } @Override - public byte computeByteIfAbsent(char key, Char2ByteFunction mappingFunction) { + public byte computeByteNonDefault(char key, CharByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + byte newValue = mappingFunction.applyAsByte(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -502,46 +524,24 @@ public byte computeByteIfAbsentNonDefault(char key, Char2ByteFunction mappingFun return entry.value; } - @Override - public byte supplyByteIfAbsent(char key, ByteSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - byte newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public byte supplyByteIfAbsentNonDefault(char key, ByteSupplier valueProvider) { Objects.requireNonNull(valueProvider); Node entry = findNode(key); if(entry == null) { - byte newValue = valueProvider.getAsInt(); + byte newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } if(entry.value == getDefaultReturnValue()) { - byte newValue = valueProvider.getAsInt(); + byte newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; entry.value = newValue; } return entry.value; } - @Override - public byte computeByteIfPresent(char key, CharByteUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - byte newValue = mappingFunction.applyAsByte(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public byte computeByteIfPresentNonDefault(char key, CharByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1621,14 +1621,9 @@ public byte computeByteIfPresent(char key, CharByteUnaryOperator mappingFunction Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - byte newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2CharAVLTreeMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2CharAVLTreeMap.java index 99d73244..ce036f2b 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2CharAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2CharAVLTreeMap.java @@ -447,34 +447,56 @@ public char computeChar(char key, CharCharUnaryOperator mappingFunction) { } @Override - public char computeCharNonDefault(char key, CharCharUnaryOperator mappingFunction) { + public char computeCharIfAbsent(char key, CharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + char newValue = mappingFunction.applyAsChar(key); put(key, newValue); return newValue; } - char newValue = mappingFunction.applyAsChar(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public char supplyCharIfAbsent(char key, CharSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + char newValue = valueProvider.getAsChar(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public char computeCharIfPresent(char key, CharCharUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + char newValue = mappingFunction.applyAsChar(key, entry.value); entry.value = newValue; return newValue; } @Override - public char computeCharIfAbsent(char key, CharUnaryOperator mappingFunction) { + public char computeCharNonDefault(char key, CharCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + char newValue = mappingFunction.applyAsChar(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -495,46 +517,24 @@ public char computeCharIfAbsentNonDefault(char key, CharUnaryOperator mappingFun return entry.value; } - @Override - public char supplyCharIfAbsent(char key, CharSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - char newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public char supplyCharIfAbsentNonDefault(char key, CharSupplier valueProvider) { Objects.requireNonNull(valueProvider); Node entry = findNode(key); if(entry == null) { - char newValue = valueProvider.getAsInt(); + char newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } if(entry.value == getDefaultReturnValue()) { - char newValue = valueProvider.getAsInt(); + char newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; entry.value = newValue; } return entry.value; } - @Override - public char computeCharIfPresent(char key, CharCharUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - char newValue = mappingFunction.applyAsChar(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public char computeCharIfPresentNonDefault(char key, CharCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1550,14 +1550,9 @@ public char computeCharIfPresent(char key, CharCharUnaryOperator mappingFunction Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - char newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2CharRBTreeMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2CharRBTreeMap.java index 71ec2012..d24412ed 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2CharRBTreeMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2CharRBTreeMap.java @@ -446,34 +446,56 @@ public char computeChar(char key, CharCharUnaryOperator mappingFunction) { } @Override - public char computeCharNonDefault(char key, CharCharUnaryOperator mappingFunction) { + public char computeCharIfAbsent(char key, CharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + char newValue = mappingFunction.applyAsChar(key); put(key, newValue); return newValue; } - char newValue = mappingFunction.applyAsChar(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public char supplyCharIfAbsent(char key, CharSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + char newValue = valueProvider.getAsChar(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public char computeCharIfPresent(char key, CharCharUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + char newValue = mappingFunction.applyAsChar(key, entry.value); entry.value = newValue; return newValue; } @Override - public char computeCharIfAbsent(char key, CharUnaryOperator mappingFunction) { + public char computeCharNonDefault(char key, CharCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + char newValue = mappingFunction.applyAsChar(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -494,46 +516,24 @@ public char computeCharIfAbsentNonDefault(char key, CharUnaryOperator mappingFun return entry.value; } - @Override - public char supplyCharIfAbsent(char key, CharSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - char newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public char supplyCharIfAbsentNonDefault(char key, CharSupplier valueProvider) { Objects.requireNonNull(valueProvider); Node entry = findNode(key); if(entry == null) { - char newValue = valueProvider.getAsInt(); + char newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } if(entry.value == getDefaultReturnValue()) { - char newValue = valueProvider.getAsInt(); + char newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; entry.value = newValue; } return entry.value; } - @Override - public char computeCharIfPresent(char key, CharCharUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - char newValue = mappingFunction.applyAsChar(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public char computeCharIfPresentNonDefault(char key, CharCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1613,14 +1613,9 @@ public char computeCharIfPresent(char key, CharCharUnaryOperator mappingFunction Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - char newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2DoubleAVLTreeMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2DoubleAVLTreeMap.java index 9affb84f..200f4dff 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2DoubleAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2DoubleAVLTreeMap.java @@ -455,34 +455,56 @@ public double computeDouble(char key, CharDoubleUnaryOperator mappingFunction) { } @Override - public double computeDoubleNonDefault(char key, CharDoubleUnaryOperator mappingFunction) { + public double computeDoubleIfAbsent(char key, Char2DoubleFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + double newValue = mappingFunction.applyAsDouble(key); put(key, newValue); return newValue; } - double newValue = mappingFunction.applyAsDouble(key, entry.value); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - removeNode(entry); + return entry.value; + } + + @Override + public double supplyDoubleIfAbsent(char key, DoubleSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + double newValue = valueProvider.getAsDouble(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public double computeDoubleIfPresent(char key, CharDoubleUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + double newValue = mappingFunction.applyAsDouble(key, entry.value); entry.value = newValue; return newValue; } @Override - public double computeDoubleIfAbsent(char key, Char2DoubleFunction mappingFunction) { + public double computeDoubleNonDefault(char key, CharDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; put(key, newValue); return newValue; } - return entry.value; + double newValue = mappingFunction.applyAsDouble(key, entry.value); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -503,18 +525,6 @@ public double computeDoubleIfAbsentNonDefault(char key, Char2DoubleFunction mapp return entry.value; } - @Override - public double supplyDoubleIfAbsent(char key, DoubleSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - double newValue = valueProvider.getAsDouble(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public double supplyDoubleIfAbsentNonDefault(char key, DoubleSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -533,16 +543,6 @@ public double supplyDoubleIfAbsentNonDefault(char key, DoubleSupplier valueProvi return entry.value; } - @Override - public double computeDoubleIfPresent(char key, CharDoubleUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - double newValue = mappingFunction.applyAsDouble(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public double computeDoubleIfPresentNonDefault(char key, CharDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1558,14 +1558,9 @@ public double computeDoubleIfPresent(char key, CharDoubleUnaryOperator mappingFu Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || Double.doubleToLongBits(entry.value) == Double.doubleToLongBits(getDefaultReturnValue())) return getDefaultReturnValue(); - double newValue = mappingFunction.apply(key, entry.value); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2DoubleRBTreeMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2DoubleRBTreeMap.java index da4d21da..d62da561 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2DoubleRBTreeMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2DoubleRBTreeMap.java @@ -454,34 +454,56 @@ public double computeDouble(char key, CharDoubleUnaryOperator mappingFunction) { } @Override - public double computeDoubleNonDefault(char key, CharDoubleUnaryOperator mappingFunction) { + public double computeDoubleIfAbsent(char key, Char2DoubleFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + double newValue = mappingFunction.applyAsDouble(key); put(key, newValue); return newValue; } - double newValue = mappingFunction.applyAsDouble(key, entry.value); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - removeNode(entry); + return entry.value; + } + + @Override + public double supplyDoubleIfAbsent(char key, DoubleSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + double newValue = valueProvider.getAsDouble(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public double computeDoubleIfPresent(char key, CharDoubleUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + double newValue = mappingFunction.applyAsDouble(key, entry.value); entry.value = newValue; return newValue; } @Override - public double computeDoubleIfAbsent(char key, Char2DoubleFunction mappingFunction) { + public double computeDoubleNonDefault(char key, CharDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; put(key, newValue); return newValue; } - return entry.value; + double newValue = mappingFunction.applyAsDouble(key, entry.value); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -502,18 +524,6 @@ public double computeDoubleIfAbsentNonDefault(char key, Char2DoubleFunction mapp return entry.value; } - @Override - public double supplyDoubleIfAbsent(char key, DoubleSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - double newValue = valueProvider.getAsDouble(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public double supplyDoubleIfAbsentNonDefault(char key, DoubleSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -532,16 +542,6 @@ public double supplyDoubleIfAbsentNonDefault(char key, DoubleSupplier valueProvi return entry.value; } - @Override - public double computeDoubleIfPresent(char key, CharDoubleUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - double newValue = mappingFunction.applyAsDouble(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public double computeDoubleIfPresentNonDefault(char key, CharDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1621,14 +1621,9 @@ public double computeDoubleIfPresent(char key, CharDoubleUnaryOperator mappingFu Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || Double.doubleToLongBits(entry.value) == Double.doubleToLongBits(getDefaultReturnValue())) return getDefaultReturnValue(); - double newValue = mappingFunction.apply(key, entry.value); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2FloatAVLTreeMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2FloatAVLTreeMap.java index 36c88e40..fba16b8b 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2FloatAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2FloatAVLTreeMap.java @@ -455,34 +455,56 @@ public float computeFloat(char key, CharFloatUnaryOperator mappingFunction) { } @Override - public float computeFloatNonDefault(char key, CharFloatUnaryOperator mappingFunction) { + public float computeFloatIfAbsent(char key, Char2FloatFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + float newValue = mappingFunction.applyAsFloat(key); put(key, newValue); return newValue; } - float newValue = mappingFunction.applyAsFloat(key, entry.value); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - removeNode(entry); + return entry.value; + } + + @Override + public float supplyFloatIfAbsent(char key, FloatSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + float newValue = valueProvider.getAsFloat(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public float computeFloatIfPresent(char key, CharFloatUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + float newValue = mappingFunction.applyAsFloat(key, entry.value); entry.value = newValue; return newValue; } @Override - public float computeFloatIfAbsent(char key, Char2FloatFunction mappingFunction) { + public float computeFloatNonDefault(char key, CharFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; put(key, newValue); return newValue; } - return entry.value; + float newValue = mappingFunction.applyAsFloat(key, entry.value); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -503,46 +525,24 @@ public float computeFloatIfAbsentNonDefault(char key, Char2FloatFunction mapping return entry.value; } - @Override - public float supplyFloatIfAbsent(char key, FloatSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - float newValue = valueProvider.getAsDouble(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public float supplyFloatIfAbsentNonDefault(char key, FloatSupplier valueProvider) { Objects.requireNonNull(valueProvider); Node entry = findNode(key); if(entry == null) { - float newValue = valueProvider.getAsDouble(); + float newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; put(key, newValue); return newValue; } if(Float.floatToIntBits(entry.value) == Float.floatToIntBits(getDefaultReturnValue())) { - float newValue = valueProvider.getAsDouble(); + float newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; entry.value = newValue; } return entry.value; } - @Override - public float computeFloatIfPresent(char key, CharFloatUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - float newValue = mappingFunction.applyAsFloat(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public float computeFloatIfPresentNonDefault(char key, CharFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1558,14 +1558,9 @@ public float computeFloatIfPresent(char key, CharFloatUnaryOperator mappingFunct Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || Float.floatToIntBits(entry.value) == Float.floatToIntBits(getDefaultReturnValue())) return getDefaultReturnValue(); - float newValue = mappingFunction.apply(key, entry.value); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2FloatRBTreeMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2FloatRBTreeMap.java index b3a5e741..b439296b 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2FloatRBTreeMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2FloatRBTreeMap.java @@ -454,34 +454,56 @@ public float computeFloat(char key, CharFloatUnaryOperator mappingFunction) { } @Override - public float computeFloatNonDefault(char key, CharFloatUnaryOperator mappingFunction) { + public float computeFloatIfAbsent(char key, Char2FloatFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + float newValue = mappingFunction.applyAsFloat(key); put(key, newValue); return newValue; } - float newValue = mappingFunction.applyAsFloat(key, entry.value); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - removeNode(entry); + return entry.value; + } + + @Override + public float supplyFloatIfAbsent(char key, FloatSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + float newValue = valueProvider.getAsFloat(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public float computeFloatIfPresent(char key, CharFloatUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + float newValue = mappingFunction.applyAsFloat(key, entry.value); entry.value = newValue; return newValue; } @Override - public float computeFloatIfAbsent(char key, Char2FloatFunction mappingFunction) { + public float computeFloatNonDefault(char key, CharFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; put(key, newValue); return newValue; } - return entry.value; + float newValue = mappingFunction.applyAsFloat(key, entry.value); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -502,46 +524,24 @@ public float computeFloatIfAbsentNonDefault(char key, Char2FloatFunction mapping return entry.value; } - @Override - public float supplyFloatIfAbsent(char key, FloatSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - float newValue = valueProvider.getAsDouble(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public float supplyFloatIfAbsentNonDefault(char key, FloatSupplier valueProvider) { Objects.requireNonNull(valueProvider); Node entry = findNode(key); if(entry == null) { - float newValue = valueProvider.getAsDouble(); + float newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; put(key, newValue); return newValue; } if(Float.floatToIntBits(entry.value) == Float.floatToIntBits(getDefaultReturnValue())) { - float newValue = valueProvider.getAsDouble(); + float newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; entry.value = newValue; } return entry.value; } - @Override - public float computeFloatIfPresent(char key, CharFloatUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - float newValue = mappingFunction.applyAsFloat(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public float computeFloatIfPresentNonDefault(char key, CharFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1621,14 +1621,9 @@ public float computeFloatIfPresent(char key, CharFloatUnaryOperator mappingFunct Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || Float.floatToIntBits(entry.value) == Float.floatToIntBits(getDefaultReturnValue())) return getDefaultReturnValue(); - float newValue = mappingFunction.apply(key, entry.value); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2IntAVLTreeMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2IntAVLTreeMap.java index 34d39376..0e4c487c 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2IntAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2IntAVLTreeMap.java @@ -455,34 +455,56 @@ public int computeInt(char key, CharIntUnaryOperator mappingFunction) { } @Override - public int computeIntNonDefault(char key, CharIntUnaryOperator mappingFunction) { + public int computeIntIfAbsent(char key, Char2IntFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + int newValue = mappingFunction.applyAsInt(key); put(key, newValue); return newValue; } - int newValue = mappingFunction.applyAsInt(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public int supplyIntIfAbsent(char key, IntSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + int newValue = valueProvider.getAsInt(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public int computeIntIfPresent(char key, CharIntUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + int newValue = mappingFunction.applyAsInt(key, entry.value); entry.value = newValue; return newValue; } @Override - public int computeIntIfAbsent(char key, Char2IntFunction mappingFunction) { + public int computeIntNonDefault(char key, CharIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + int newValue = mappingFunction.applyAsInt(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -503,18 +525,6 @@ public int computeIntIfAbsentNonDefault(char key, Char2IntFunction mappingFuncti return entry.value; } - @Override - public int supplyIntIfAbsent(char key, IntSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - int newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public int supplyIntIfAbsentNonDefault(char key, IntSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -533,16 +543,6 @@ public int supplyIntIfAbsentNonDefault(char key, IntSupplier valueProvider) { return entry.value; } - @Override - public int computeIntIfPresent(char key, CharIntUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - int newValue = mappingFunction.applyAsInt(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public int computeIntIfPresentNonDefault(char key, CharIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1558,14 +1558,9 @@ public int computeIntIfPresent(char key, CharIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - int newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2IntRBTreeMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2IntRBTreeMap.java index 51792220..c5581d68 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2IntRBTreeMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2IntRBTreeMap.java @@ -454,34 +454,56 @@ public int computeInt(char key, CharIntUnaryOperator mappingFunction) { } @Override - public int computeIntNonDefault(char key, CharIntUnaryOperator mappingFunction) { + public int computeIntIfAbsent(char key, Char2IntFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + int newValue = mappingFunction.applyAsInt(key); put(key, newValue); return newValue; } - int newValue = mappingFunction.applyAsInt(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public int supplyIntIfAbsent(char key, IntSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + int newValue = valueProvider.getAsInt(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public int computeIntIfPresent(char key, CharIntUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + int newValue = mappingFunction.applyAsInt(key, entry.value); entry.value = newValue; return newValue; } @Override - public int computeIntIfAbsent(char key, Char2IntFunction mappingFunction) { + public int computeIntNonDefault(char key, CharIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + int newValue = mappingFunction.applyAsInt(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -502,18 +524,6 @@ public int computeIntIfAbsentNonDefault(char key, Char2IntFunction mappingFuncti return entry.value; } - @Override - public int supplyIntIfAbsent(char key, IntSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - int newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public int supplyIntIfAbsentNonDefault(char key, IntSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -532,16 +542,6 @@ public int supplyIntIfAbsentNonDefault(char key, IntSupplier valueProvider) { return entry.value; } - @Override - public int computeIntIfPresent(char key, CharIntUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - int newValue = mappingFunction.applyAsInt(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public int computeIntIfPresentNonDefault(char key, CharIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1621,14 +1621,9 @@ public int computeIntIfPresent(char key, CharIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - int newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2LongAVLTreeMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2LongAVLTreeMap.java index a1fff5a6..233d69f2 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2LongAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2LongAVLTreeMap.java @@ -455,34 +455,56 @@ public long computeLong(char key, CharLongUnaryOperator mappingFunction) { } @Override - public long computeLongNonDefault(char key, CharLongUnaryOperator mappingFunction) { + public long computeLongIfAbsent(char key, Char2LongFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + long newValue = mappingFunction.applyAsLong(key); put(key, newValue); return newValue; } - long newValue = mappingFunction.applyAsLong(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public long supplyLongIfAbsent(char key, LongSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + long newValue = valueProvider.getAsLong(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public long computeLongIfPresent(char key, CharLongUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + long newValue = mappingFunction.applyAsLong(key, entry.value); entry.value = newValue; return newValue; } @Override - public long computeLongIfAbsent(char key, Char2LongFunction mappingFunction) { + public long computeLongNonDefault(char key, CharLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + long newValue = mappingFunction.applyAsLong(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -503,18 +525,6 @@ public long computeLongIfAbsentNonDefault(char key, Char2LongFunction mappingFun return entry.value; } - @Override - public long supplyLongIfAbsent(char key, LongSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - long newValue = valueProvider.getAsLong(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public long supplyLongIfAbsentNonDefault(char key, LongSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -533,16 +543,6 @@ public long supplyLongIfAbsentNonDefault(char key, LongSupplier valueProvider) { return entry.value; } - @Override - public long computeLongIfPresent(char key, CharLongUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - long newValue = mappingFunction.applyAsLong(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public long computeLongIfPresentNonDefault(char key, CharLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1558,14 +1558,9 @@ public long computeLongIfPresent(char key, CharLongUnaryOperator mappingFunction Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - long newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2LongRBTreeMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2LongRBTreeMap.java index 4198f889..f2cd6e62 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2LongRBTreeMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2LongRBTreeMap.java @@ -454,34 +454,56 @@ public long computeLong(char key, CharLongUnaryOperator mappingFunction) { } @Override - public long computeLongNonDefault(char key, CharLongUnaryOperator mappingFunction) { + public long computeLongIfAbsent(char key, Char2LongFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + long newValue = mappingFunction.applyAsLong(key); put(key, newValue); return newValue; } - long newValue = mappingFunction.applyAsLong(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public long supplyLongIfAbsent(char key, LongSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + long newValue = valueProvider.getAsLong(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public long computeLongIfPresent(char key, CharLongUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + long newValue = mappingFunction.applyAsLong(key, entry.value); entry.value = newValue; return newValue; } @Override - public long computeLongIfAbsent(char key, Char2LongFunction mappingFunction) { + public long computeLongNonDefault(char key, CharLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + long newValue = mappingFunction.applyAsLong(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -502,18 +524,6 @@ public long computeLongIfAbsentNonDefault(char key, Char2LongFunction mappingFun return entry.value; } - @Override - public long supplyLongIfAbsent(char key, LongSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - long newValue = valueProvider.getAsLong(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public long supplyLongIfAbsentNonDefault(char key, LongSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -532,16 +542,6 @@ public long supplyLongIfAbsentNonDefault(char key, LongSupplier valueProvider) { return entry.value; } - @Override - public long computeLongIfPresent(char key, CharLongUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - long newValue = mappingFunction.applyAsLong(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public long computeLongIfPresentNonDefault(char key, CharLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1621,14 +1621,9 @@ public long computeLongIfPresent(char key, CharLongUnaryOperator mappingFunction Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - long newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2ObjectAVLTreeMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2ObjectAVLTreeMap.java index 30369357..d6ec0565 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2ObjectAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2ObjectAVLTreeMap.java @@ -395,25 +395,6 @@ public V compute(char key, CharObjectUnaryOperator mappingFunction) { return newValue; } - @Override - public V computeNonDefault(char key, CharObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) { - V newValue = mappingFunction.apply(key, getDefaultReturnValue()); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - put(key, newValue); - return newValue; - } - V newValue = mappingFunction.apply(key, entry.value); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; - } - @Override public V computeIfAbsent(char key, CharFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -432,24 +413,6 @@ public V computeIfAbsent(char key, CharFunction mappingFunction) { return entry.value; } - @Override - public V computeIfAbsentNonDefault(char key, CharFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) { - V newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - put(key, newValue); - return newValue; - } - if(Objects.equals(entry.value, getDefaultReturnValue())) { - V newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - entry.value = newValue; - } - return entry.value; - } - @Override public V supplyIfAbsent(char key, ObjectSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -468,24 +431,6 @@ public V supplyIfAbsent(char key, ObjectSupplier valueProvider) { return entry.value; } - @Override - public V supplyIfAbsentNonDefault(char key, ObjectSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - V newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - put(key, newValue); - return newValue; - } - if(Objects.equals(entry.value, getDefaultReturnValue())) { - V newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - entry.value = newValue; - } - return entry.value; - } - @Override public V computeIfPresent(char key, CharObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -500,20 +445,6 @@ public V computeIfPresent(char key, CharObjectUnaryOperator mappingFunction) return newValue; } - @Override - public V computeIfPresentNonDefault(char key, CharObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null || Objects.equals(entry.value, getDefaultReturnValue())) return getDefaultReturnValue(); - V newValue = mappingFunction.apply(key, entry.value); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; - } - @Override public V merge(char key, V value, ObjectObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2ObjectRBTreeMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2ObjectRBTreeMap.java index 40932776..c4d94cf3 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2ObjectRBTreeMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2ObjectRBTreeMap.java @@ -394,25 +394,6 @@ public V compute(char key, CharObjectUnaryOperator mappingFunction) { return newValue; } - @Override - public V computeNonDefault(char key, CharObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) { - V newValue = mappingFunction.apply(key, getDefaultReturnValue()); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - put(key, newValue); - return newValue; - } - V newValue = mappingFunction.apply(key, entry.value); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; - } - @Override public V computeIfAbsent(char key, CharFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -431,24 +412,6 @@ public V computeIfAbsent(char key, CharFunction mappingFunction) { return entry.value; } - @Override - public V computeIfAbsentNonDefault(char key, CharFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) { - V newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - put(key, newValue); - return newValue; - } - if(Objects.equals(entry.value, getDefaultReturnValue())) { - V newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - entry.value = newValue; - } - return entry.value; - } - @Override public V supplyIfAbsent(char key, ObjectSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -467,24 +430,6 @@ public V supplyIfAbsent(char key, ObjectSupplier valueProvider) { return entry.value; } - @Override - public V supplyIfAbsentNonDefault(char key, ObjectSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - V newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - put(key, newValue); - return newValue; - } - if(Objects.equals(entry.value, getDefaultReturnValue())) { - V newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - entry.value = newValue; - } - return entry.value; - } - @Override public V computeIfPresent(char key, CharObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -499,20 +444,6 @@ public V computeIfPresent(char key, CharObjectUnaryOperator mappingFunction) return newValue; } - @Override - public V computeIfPresentNonDefault(char key, CharObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null || Objects.equals(entry.value, getDefaultReturnValue())) return getDefaultReturnValue(); - V newValue = mappingFunction.apply(key, entry.value); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; - } - @Override public V merge(char key, V value, ObjectObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2ShortAVLTreeMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2ShortAVLTreeMap.java index 55570cab..4ad19752 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2ShortAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2ShortAVLTreeMap.java @@ -455,34 +455,56 @@ public short computeShort(char key, CharShortUnaryOperator mappingFunction) { } @Override - public short computeShortNonDefault(char key, CharShortUnaryOperator mappingFunction) { + public short computeShortIfAbsent(char key, Char2ShortFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + short newValue = mappingFunction.applyAsShort(key); put(key, newValue); return newValue; } - short newValue = mappingFunction.applyAsShort(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public short supplyShortIfAbsent(char key, ShortSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + short newValue = valueProvider.getAsShort(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public short computeShortIfPresent(char key, CharShortUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + short newValue = mappingFunction.applyAsShort(key, entry.value); entry.value = newValue; return newValue; } @Override - public short computeShortIfAbsent(char key, Char2ShortFunction mappingFunction) { + public short computeShortNonDefault(char key, CharShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + short newValue = mappingFunction.applyAsShort(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -503,46 +525,24 @@ public short computeShortIfAbsentNonDefault(char key, Char2ShortFunction mapping return entry.value; } - @Override - public short supplyShortIfAbsent(char key, ShortSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - short newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public short supplyShortIfAbsentNonDefault(char key, ShortSupplier valueProvider) { Objects.requireNonNull(valueProvider); Node entry = findNode(key); if(entry == null) { - short newValue = valueProvider.getAsInt(); + short newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } if(entry.value == getDefaultReturnValue()) { - short newValue = valueProvider.getAsInt(); + short newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; entry.value = newValue; } return entry.value; } - @Override - public short computeShortIfPresent(char key, CharShortUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - short newValue = mappingFunction.applyAsShort(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public short computeShortIfPresentNonDefault(char key, CharShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1558,14 +1558,9 @@ public short computeShortIfPresent(char key, CharShortUnaryOperator mappingFunct Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - short newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2ShortRBTreeMap.java b/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2ShortRBTreeMap.java index ec4944a3..7edd274c 100644 --- a/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2ShortRBTreeMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/impl/tree/Char2ShortRBTreeMap.java @@ -454,34 +454,56 @@ public short computeShort(char key, CharShortUnaryOperator mappingFunction) { } @Override - public short computeShortNonDefault(char key, CharShortUnaryOperator mappingFunction) { + public short computeShortIfAbsent(char key, Char2ShortFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + short newValue = mappingFunction.applyAsShort(key); put(key, newValue); return newValue; } - short newValue = mappingFunction.applyAsShort(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public short supplyShortIfAbsent(char key, ShortSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + short newValue = valueProvider.getAsShort(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public short computeShortIfPresent(char key, CharShortUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + short newValue = mappingFunction.applyAsShort(key, entry.value); entry.value = newValue; return newValue; } @Override - public short computeShortIfAbsent(char key, Char2ShortFunction mappingFunction) { + public short computeShortNonDefault(char key, CharShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + short newValue = mappingFunction.applyAsShort(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -502,46 +524,24 @@ public short computeShortIfAbsentNonDefault(char key, Char2ShortFunction mapping return entry.value; } - @Override - public short supplyShortIfAbsent(char key, ShortSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - short newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public short supplyShortIfAbsentNonDefault(char key, ShortSupplier valueProvider) { Objects.requireNonNull(valueProvider); Node entry = findNode(key); if(entry == null) { - short newValue = valueProvider.getAsInt(); + short newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } if(entry.value == getDefaultReturnValue()) { - short newValue = valueProvider.getAsInt(); + short newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; entry.value = newValue; } return entry.value; } - @Override - public short computeShortIfPresent(char key, CharShortUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - short newValue = mappingFunction.applyAsShort(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public short computeShortIfPresentNonDefault(char key, CharShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1621,14 +1621,9 @@ public short computeShortIfPresent(char key, CharShortUnaryOperator mappingFunct Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - short newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/chars/maps/interfaces/Char2BooleanMap.java b/src/main/java/speiger/src/collections/chars/maps/interfaces/Char2BooleanMap.java index 0e9c4eee..6c89a5c7 100644 --- a/src/main/java/speiger/src/collections/chars/maps/interfaces/Char2BooleanMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/interfaces/Char2BooleanMap.java @@ -284,41 +284,51 @@ public default boolean remove(Object key, Object value) { */ public boolean computeBoolean(char key, CharBooleanUnaryOperator mappingFunction); /** - * A Type Specific compute method to reduce boxing/unboxing + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation + * @param mappingFunction the operator that should generate the value if not present + * @return the result of the computed value or present value */ - public boolean computeBooleanNonDefault(char key, CharBooleanUnaryOperator mappingFunction); + public boolean computeBooleanIfAbsent(char key, CharPredicate mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present + * @param valueProvider the value if not present * @return the result of the computed value or present value + */ + public boolean supplyBooleanIfAbsent(char key, BooleanSupplier valueProvider); + /** + * A Type Specific compute method to reduce boxing/unboxing + * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". + * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. + * @param key the key that should be computed + * @param mappingFunction the operator that should generate the value if present + * @return the result of the default return value or present value + * @note if not present then compute is not executed */ - public boolean computeBooleanIfAbsent(char key, CharPredicate mappingFunction); + public boolean computeBooleanIfPresent(char key, CharBooleanUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value + * @param mappingFunction the operator that should generate the value + * @return the result of the computation */ - public boolean computeBooleanIfAbsentNonDefault(char key, CharPredicate mappingFunction); + public boolean computeBooleanNonDefault(char key, CharBooleanUnaryOperator mappingFunction); /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param valueProvider the value if not present + * @param mappingFunction the operator that should generate the value if not present * @return the result of the computed value or present value - */ - public boolean supplyBooleanIfAbsent(char key, BooleanSupplier valueProvider); + */ + public boolean computeBooleanIfAbsentNonDefault(char key, CharPredicate mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -328,16 +338,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public boolean supplyBooleanIfAbsentNonDefault(char key, BooleanSupplier valueProvider); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public boolean computeBooleanIfPresent(char key, CharBooleanUnaryOperator mappingFunction); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/chars/maps/interfaces/Char2ByteMap.java b/src/main/java/speiger/src/collections/chars/maps/interfaces/Char2ByteMap.java index eeb5e62d..8ca7198f 100644 --- a/src/main/java/speiger/src/collections/chars/maps/interfaces/Char2ByteMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/interfaces/Char2ByteMap.java @@ -309,41 +309,51 @@ public default boolean remove(Object key, Object value) { */ public byte computeByte(char key, CharByteUnaryOperator mappingFunction); /** - * A Type Specific compute method to reduce boxing/unboxing + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation + * @param mappingFunction the operator that should generate the value if not present + * @return the result of the computed value or present value */ - public byte computeByteNonDefault(char key, CharByteUnaryOperator mappingFunction); + public byte computeByteIfAbsent(char key, Char2ByteFunction mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present + * @param valueProvider the value if not present * @return the result of the computed value or present value + */ + public byte supplyByteIfAbsent(char key, ByteSupplier valueProvider); + /** + * A Type Specific compute method to reduce boxing/unboxing + * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". + * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. + * @param key the key that should be computed + * @param mappingFunction the operator that should generate the value if present + * @return the result of the default return value or present value + * @note if not present then compute is not executed */ - public byte computeByteIfAbsent(char key, Char2ByteFunction mappingFunction); + public byte computeByteIfPresent(char key, CharByteUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value + * @param mappingFunction the operator that should generate the value + * @return the result of the computation */ - public byte computeByteIfAbsentNonDefault(char key, Char2ByteFunction mappingFunction); + public byte computeByteNonDefault(char key, CharByteUnaryOperator mappingFunction); /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param valueProvider the value if not present + * @param mappingFunction the operator that should generate the value if not present * @return the result of the computed value or present value - */ - public byte supplyByteIfAbsent(char key, ByteSupplier valueProvider); + */ + public byte computeByteIfAbsentNonDefault(char key, Char2ByteFunction mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -353,16 +363,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public byte supplyByteIfAbsentNonDefault(char key, ByteSupplier valueProvider); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public byte computeByteIfPresent(char key, CharByteUnaryOperator mappingFunction); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/chars/maps/interfaces/Char2CharMap.java b/src/main/java/speiger/src/collections/chars/maps/interfaces/Char2CharMap.java index c2d970ae..91294f68 100644 --- a/src/main/java/speiger/src/collections/chars/maps/interfaces/Char2CharMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/interfaces/Char2CharMap.java @@ -308,41 +308,51 @@ public default boolean remove(Object key, Object value) { */ public char computeChar(char key, CharCharUnaryOperator mappingFunction); /** - * A Type Specific compute method to reduce boxing/unboxing + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation + * @param mappingFunction the operator that should generate the value if not present + * @return the result of the computed value or present value */ - public char computeCharNonDefault(char key, CharCharUnaryOperator mappingFunction); + public char computeCharIfAbsent(char key, CharUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present + * @param valueProvider the value if not present * @return the result of the computed value or present value + */ + public char supplyCharIfAbsent(char key, CharSupplier valueProvider); + /** + * A Type Specific compute method to reduce boxing/unboxing + * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". + * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. + * @param key the key that should be computed + * @param mappingFunction the operator that should generate the value if present + * @return the result of the default return value or present value + * @note if not present then compute is not executed */ - public char computeCharIfAbsent(char key, CharUnaryOperator mappingFunction); + public char computeCharIfPresent(char key, CharCharUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value + * @param mappingFunction the operator that should generate the value + * @return the result of the computation */ - public char computeCharIfAbsentNonDefault(char key, CharUnaryOperator mappingFunction); + public char computeCharNonDefault(char key, CharCharUnaryOperator mappingFunction); /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param valueProvider the value if not present + * @param mappingFunction the operator that should generate the value if not present * @return the result of the computed value or present value - */ - public char supplyCharIfAbsent(char key, CharSupplier valueProvider); + */ + public char computeCharIfAbsentNonDefault(char key, CharUnaryOperator mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -352,16 +362,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public char supplyCharIfAbsentNonDefault(char key, CharSupplier valueProvider); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public char computeCharIfPresent(char key, CharCharUnaryOperator mappingFunction); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/chars/maps/interfaces/Char2DoubleMap.java b/src/main/java/speiger/src/collections/chars/maps/interfaces/Char2DoubleMap.java index a4f6dc7b..9e748a7d 100644 --- a/src/main/java/speiger/src/collections/chars/maps/interfaces/Char2DoubleMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/interfaces/Char2DoubleMap.java @@ -309,41 +309,51 @@ public default boolean remove(Object key, Object value) { */ public double computeDouble(char key, CharDoubleUnaryOperator mappingFunction); /** - * A Type Specific compute method to reduce boxing/unboxing + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation + * @param mappingFunction the operator that should generate the value if not present + * @return the result of the computed value or present value */ - public double computeDoubleNonDefault(char key, CharDoubleUnaryOperator mappingFunction); + public double computeDoubleIfAbsent(char key, Char2DoubleFunction mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present + * @param valueProvider the value if not present * @return the result of the computed value or present value + */ + public double supplyDoubleIfAbsent(char key, DoubleSupplier valueProvider); + /** + * A Type Specific compute method to reduce boxing/unboxing + * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". + * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. + * @param key the key that should be computed + * @param mappingFunction the operator that should generate the value if present + * @return the result of the default return value or present value + * @note if not present then compute is not executed */ - public double computeDoubleIfAbsent(char key, Char2DoubleFunction mappingFunction); + public double computeDoubleIfPresent(char key, CharDoubleUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value + * @param mappingFunction the operator that should generate the value + * @return the result of the computation */ - public double computeDoubleIfAbsentNonDefault(char key, Char2DoubleFunction mappingFunction); + public double computeDoubleNonDefault(char key, CharDoubleUnaryOperator mappingFunction); /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param valueProvider the value if not present + * @param mappingFunction the operator that should generate the value if not present * @return the result of the computed value or present value - */ - public double supplyDoubleIfAbsent(char key, DoubleSupplier valueProvider); + */ + public double computeDoubleIfAbsentNonDefault(char key, Char2DoubleFunction mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -353,16 +363,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public double supplyDoubleIfAbsentNonDefault(char key, DoubleSupplier valueProvider); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public double computeDoubleIfPresent(char key, CharDoubleUnaryOperator mappingFunction); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/chars/maps/interfaces/Char2FloatMap.java b/src/main/java/speiger/src/collections/chars/maps/interfaces/Char2FloatMap.java index f7e6f275..51e19220 100644 --- a/src/main/java/speiger/src/collections/chars/maps/interfaces/Char2FloatMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/interfaces/Char2FloatMap.java @@ -309,41 +309,51 @@ public default boolean remove(Object key, Object value) { */ public float computeFloat(char key, CharFloatUnaryOperator mappingFunction); /** - * A Type Specific compute method to reduce boxing/unboxing + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation + * @param mappingFunction the operator that should generate the value if not present + * @return the result of the computed value or present value */ - public float computeFloatNonDefault(char key, CharFloatUnaryOperator mappingFunction); + public float computeFloatIfAbsent(char key, Char2FloatFunction mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present + * @param valueProvider the value if not present * @return the result of the computed value or present value + */ + public float supplyFloatIfAbsent(char key, FloatSupplier valueProvider); + /** + * A Type Specific compute method to reduce boxing/unboxing + * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". + * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. + * @param key the key that should be computed + * @param mappingFunction the operator that should generate the value if present + * @return the result of the default return value or present value + * @note if not present then compute is not executed */ - public float computeFloatIfAbsent(char key, Char2FloatFunction mappingFunction); + public float computeFloatIfPresent(char key, CharFloatUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value + * @param mappingFunction the operator that should generate the value + * @return the result of the computation */ - public float computeFloatIfAbsentNonDefault(char key, Char2FloatFunction mappingFunction); + public float computeFloatNonDefault(char key, CharFloatUnaryOperator mappingFunction); /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param valueProvider the value if not present + * @param mappingFunction the operator that should generate the value if not present * @return the result of the computed value or present value - */ - public float supplyFloatIfAbsent(char key, FloatSupplier valueProvider); + */ + public float computeFloatIfAbsentNonDefault(char key, Char2FloatFunction mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -353,16 +363,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public float supplyFloatIfAbsentNonDefault(char key, FloatSupplier valueProvider); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public float computeFloatIfPresent(char key, CharFloatUnaryOperator mappingFunction); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/chars/maps/interfaces/Char2IntMap.java b/src/main/java/speiger/src/collections/chars/maps/interfaces/Char2IntMap.java index e782a7b3..11f4f8eb 100644 --- a/src/main/java/speiger/src/collections/chars/maps/interfaces/Char2IntMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/interfaces/Char2IntMap.java @@ -309,41 +309,51 @@ public default boolean remove(Object key, Object value) { */ public int computeInt(char key, CharIntUnaryOperator mappingFunction); /** - * A Type Specific compute method to reduce boxing/unboxing + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation + * @param mappingFunction the operator that should generate the value if not present + * @return the result of the computed value or present value */ - public int computeIntNonDefault(char key, CharIntUnaryOperator mappingFunction); + public int computeIntIfAbsent(char key, Char2IntFunction mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present + * @param valueProvider the value if not present * @return the result of the computed value or present value + */ + public int supplyIntIfAbsent(char key, IntSupplier valueProvider); + /** + * A Type Specific compute method to reduce boxing/unboxing + * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". + * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. + * @param key the key that should be computed + * @param mappingFunction the operator that should generate the value if present + * @return the result of the default return value or present value + * @note if not present then compute is not executed */ - public int computeIntIfAbsent(char key, Char2IntFunction mappingFunction); + public int computeIntIfPresent(char key, CharIntUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value + * @param mappingFunction the operator that should generate the value + * @return the result of the computation */ - public int computeIntIfAbsentNonDefault(char key, Char2IntFunction mappingFunction); + public int computeIntNonDefault(char key, CharIntUnaryOperator mappingFunction); /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param valueProvider the value if not present + * @param mappingFunction the operator that should generate the value if not present * @return the result of the computed value or present value - */ - public int supplyIntIfAbsent(char key, IntSupplier valueProvider); + */ + public int computeIntIfAbsentNonDefault(char key, Char2IntFunction mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -353,16 +363,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public int supplyIntIfAbsentNonDefault(char key, IntSupplier valueProvider); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public int computeIntIfPresent(char key, CharIntUnaryOperator mappingFunction); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/chars/maps/interfaces/Char2LongMap.java b/src/main/java/speiger/src/collections/chars/maps/interfaces/Char2LongMap.java index 7c8a61a1..597a9f16 100644 --- a/src/main/java/speiger/src/collections/chars/maps/interfaces/Char2LongMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/interfaces/Char2LongMap.java @@ -309,41 +309,51 @@ public default boolean remove(Object key, Object value) { */ public long computeLong(char key, CharLongUnaryOperator mappingFunction); /** - * A Type Specific compute method to reduce boxing/unboxing + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation + * @param mappingFunction the operator that should generate the value if not present + * @return the result of the computed value or present value */ - public long computeLongNonDefault(char key, CharLongUnaryOperator mappingFunction); + public long computeLongIfAbsent(char key, Char2LongFunction mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present + * @param valueProvider the value if not present * @return the result of the computed value or present value + */ + public long supplyLongIfAbsent(char key, LongSupplier valueProvider); + /** + * A Type Specific compute method to reduce boxing/unboxing + * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". + * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. + * @param key the key that should be computed + * @param mappingFunction the operator that should generate the value if present + * @return the result of the default return value or present value + * @note if not present then compute is not executed */ - public long computeLongIfAbsent(char key, Char2LongFunction mappingFunction); + public long computeLongIfPresent(char key, CharLongUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value + * @param mappingFunction the operator that should generate the value + * @return the result of the computation */ - public long computeLongIfAbsentNonDefault(char key, Char2LongFunction mappingFunction); + public long computeLongNonDefault(char key, CharLongUnaryOperator mappingFunction); /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param valueProvider the value if not present + * @param mappingFunction the operator that should generate the value if not present * @return the result of the computed value or present value - */ - public long supplyLongIfAbsent(char key, LongSupplier valueProvider); + */ + public long computeLongIfAbsentNonDefault(char key, Char2LongFunction mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -353,16 +363,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public long supplyLongIfAbsentNonDefault(char key, LongSupplier valueProvider); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public long computeLongIfPresent(char key, CharLongUnaryOperator mappingFunction); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/chars/maps/interfaces/Char2ObjectMap.java b/src/main/java/speiger/src/collections/chars/maps/interfaces/Char2ObjectMap.java index df3fe69e..6f8ad97a 100644 --- a/src/main/java/speiger/src/collections/chars/maps/interfaces/Char2ObjectMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/interfaces/Char2ObjectMap.java @@ -266,15 +266,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computation */ public V compute(char key, CharObjectUnaryOperator mappingFunction); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation - */ - public V computeNonDefault(char key, CharObjectUnaryOperator mappingFunction); /** * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -284,15 +275,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public V computeIfAbsent(char key, CharFunction mappingFunction); - /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value - */ - public V computeIfAbsentNonDefault(char key, CharFunction mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -302,15 +284,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public V supplyIfAbsent(char key, ObjectSupplier valueProvider); - /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param valueProvider the value if not present - * @return the result of the computed value or present value - */ - public V supplyIfAbsentNonDefault(char key, ObjectSupplier valueProvider); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -321,16 +294,6 @@ public default boolean remove(Object key, Object value) { * @note if not present then compute is not executed */ public V computeIfPresent(char key, CharObjectUnaryOperator mappingFunction); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public V computeIfPresentNonDefault(char key, CharObjectUnaryOperator mappingFunction); /** * A Type Specific merge method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/chars/maps/interfaces/Char2ShortMap.java b/src/main/java/speiger/src/collections/chars/maps/interfaces/Char2ShortMap.java index bff9e4fb..36cf1c0e 100644 --- a/src/main/java/speiger/src/collections/chars/maps/interfaces/Char2ShortMap.java +++ b/src/main/java/speiger/src/collections/chars/maps/interfaces/Char2ShortMap.java @@ -309,41 +309,51 @@ public default boolean remove(Object key, Object value) { */ public short computeShort(char key, CharShortUnaryOperator mappingFunction); /** - * A Type Specific compute method to reduce boxing/unboxing + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation + * @param mappingFunction the operator that should generate the value if not present + * @return the result of the computed value or present value */ - public short computeShortNonDefault(char key, CharShortUnaryOperator mappingFunction); + public short computeShortIfAbsent(char key, Char2ShortFunction mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present + * @param valueProvider the value if not present * @return the result of the computed value or present value + */ + public short supplyShortIfAbsent(char key, ShortSupplier valueProvider); + /** + * A Type Specific compute method to reduce boxing/unboxing + * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". + * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. + * @param key the key that should be computed + * @param mappingFunction the operator that should generate the value if present + * @return the result of the default return value or present value + * @note if not present then compute is not executed */ - public short computeShortIfAbsent(char key, Char2ShortFunction mappingFunction); + public short computeShortIfPresent(char key, CharShortUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value + * @param mappingFunction the operator that should generate the value + * @return the result of the computation */ - public short computeShortIfAbsentNonDefault(char key, Char2ShortFunction mappingFunction); + public short computeShortNonDefault(char key, CharShortUnaryOperator mappingFunction); /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param valueProvider the value if not present + * @param mappingFunction the operator that should generate the value if not present * @return the result of the computed value or present value - */ - public short supplyShortIfAbsent(char key, ShortSupplier valueProvider); + */ + public short computeShortIfAbsentNonDefault(char key, Char2ShortFunction mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -353,16 +363,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public short supplyShortIfAbsentNonDefault(char key, ShortSupplier valueProvider); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public short computeShortIfPresent(char key, CharShortUnaryOperator mappingFunction); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/chars/queues/CharArrayFIFOQueue.java b/src/main/java/speiger/src/collections/chars/queues/CharArrayFIFOQueue.java index 93435679..fbd78a44 100644 --- a/src/main/java/speiger/src/collections/chars/queues/CharArrayFIFOQueue.java +++ b/src/main/java/speiger/src/collections/chars/queues/CharArrayFIFOQueue.java @@ -146,6 +146,15 @@ public char peek(int index) { return index >= array.length ? array[index-array.length] : array[index]; } + @Override + public boolean contains(char e) { + if(first == last) return false; + for(int i = 0,m=size();i iterator, int re return new RepeatingIterator(wrap(iterator), repeats); } + /** + * A Helper function that creates a infinitely looping iterator + * @param iterator that should be looping infinitely + * @return a infinitely looping iterator + */ + public static CharIterator infinite(CharIterator iterator) { + return new InfiniteIterator(iterator); + } + + /** + * A Helper function that creates a infinitely looping iterator from a Java Iterator + * @param iterator that should be looping infinitely + * @return a infinitely looping iterator + */ + public static CharIterator infinite(Iterator iterator) { + return new InfiniteIterator(wrap(iterator)); + } + /** * A Helper function that hard limits the Iterator to a specific size * @param iterator that should be limited @@ -841,6 +862,40 @@ public T next() { } } + private static class InfiniteIterator implements CharIterator + { + CharIterator iter; + CollectionWrapper looper = CharCollections.wrapper(); + int index = 0; + + public InfiniteIterator(CharIterator iter) { + this.iter = iter; + } + + @Override + public boolean hasNext() { + return true; + } + + @Override + public char nextChar() { + if(iter != null) { + if(iter.hasNext()) { + char value = iter.nextChar(); + looper.add(value); + return value; + } + else iter = null; + } + return looper.getChar((index++) % looper.size()); + } + + @Override + public void forEachRemaining(CharConsumer action) { throw new UnsupportedOperationException("This is a instant deadlock, so unsupported"); } + public void forEachRemaining(Consumer action) { throw new UnsupportedOperationException("This is a instant deadlock, so unsupported"); } + public void forEachRemaining(E input, ObjectCharConsumer action) { throw new UnsupportedOperationException("This is a instant deadlock, so unsupported"); } + } + private static class RepeatingIterator implements CharIterator { final int repeats; diff --git a/src/main/java/speiger/src/collections/chars/utils/CharLists.java b/src/main/java/speiger/src/collections/chars/utils/CharLists.java index 5123b679..f83a514d 100644 --- a/src/main/java/speiger/src/collections/chars/utils/CharLists.java +++ b/src/main/java/speiger/src/collections/chars/utils/CharLists.java @@ -12,6 +12,7 @@ import speiger.src.collections.chars.functions.CharConsumer; import speiger.src.collections.chars.lists.AbstractCharList; import speiger.src.collections.chars.lists.CharList; +import speiger.src.collections.ints.lists.IntList; import speiger.src.collections.chars.lists.CharListIterator; import speiger.src.collections.utils.SanityChecks; @@ -317,6 +318,16 @@ public CharListIterator listIterator(int index) { return l.listIterator(index); } + @Override + public CharListIterator indexedIterator(int...indecies) { + return l.indexedIterator(indecies); + } + + @Override + public CharListIterator indexedIterator(IntList indecies) { + return l.indexedIterator(indecies); + } + @Override public CharList subList(int from, int to) { return CharLists.synchronize(l.subList(from, to)); @@ -426,6 +437,16 @@ public CharListIterator listIterator(int index) { return CharIterators.unmodifiable(l.listIterator(index)); } + @Override + public CharListIterator indexedIterator(int...indecies) { + return CharIterators.unmodifiable(l.indexedIterator(indecies)); + } + + @Override + public CharListIterator indexedIterator(IntList indecies) { + return CharIterators.unmodifiable(l.indexedIterator(indecies)); + } + @Override public CharList subList(int from, int to) { return CharLists.unmodifiable(l.subList(from, to)); @@ -514,6 +535,16 @@ public CharListIterator listIterator(int index) { return CharIterators.empty(); } + @Override + public CharListIterator indexedIterator(int...indecies) { + return CharIterators.empty(); + } + + @Override + public CharListIterator indexedIterator(IntList indecies) { + return CharIterators.empty(); + } + @Override public int hashCode() { return 1; } diff --git a/src/main/java/speiger/src/collections/chars/utils/CharPriorityQueues.java b/src/main/java/speiger/src/collections/chars/utils/CharPriorityQueues.java index 9247083d..f3bfa683 100644 --- a/src/main/java/speiger/src/collections/chars/utils/CharPriorityQueues.java +++ b/src/main/java/speiger/src/collections/chars/utils/CharPriorityQueues.java @@ -89,6 +89,8 @@ protected SynchronizedPriorityQueue(CharPriorityQueue queue, Object mutex) { @Override public char peek(int index) { synchronized(mutex) { return queue.peek(index); } } @Override + public boolean contains(char e) { synchronized(mutex) { return queue.contains(e); } } + @Override public boolean removeFirst(char e) { synchronized(mutex) { return queue.removeFirst(e); } } @Override public boolean removeLast(char e) { synchronized(mutex) { return queue.removeLast(e); } } diff --git a/src/main/java/speiger/src/collections/chars/utils/maps/Char2BooleanMaps.java b/src/main/java/speiger/src/collections/chars/utils/maps/Char2BooleanMaps.java index b2343a49..fb7b8711 100644 --- a/src/main/java/speiger/src/collections/chars/utils/maps/Char2BooleanMaps.java +++ b/src/main/java/speiger/src/collections/chars/utils/maps/Char2BooleanMaps.java @@ -246,18 +246,18 @@ public static class SingletonMap extends AbstractChar2BooleanMap { @Override public boolean computeBoolean(char key, CharBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanNonDefault(char key, CharBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean computeBooleanIfAbsent(char key, CharPredicate mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanIfAbsentNonDefault(char key, CharPredicate mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean computeBooleanIfPresent(char key, CharBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanIfPresentNonDefault(char key, CharBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean supplyBooleanIfAbsent(char key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public boolean computeBooleanNonDefault(char key, CharBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public boolean computeBooleanIfAbsentNonDefault(char key, CharPredicate mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public boolean computeBooleanIfPresentNonDefault(char key, CharBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public boolean supplyBooleanIfAbsentNonDefault(char key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public boolean mergeBoolean(char key, boolean value, BooleanBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -304,18 +304,18 @@ public static class EmptyMap extends AbstractChar2BooleanMap { @Override public boolean computeBoolean(char key, CharBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanNonDefault(char key, CharBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean computeBooleanIfAbsent(char key, CharPredicate mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanIfAbsentNonDefault(char key, CharPredicate mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean computeBooleanIfPresent(char key, CharBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanIfPresentNonDefault(char key, CharBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean supplyBooleanIfAbsent(char key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public boolean computeBooleanNonDefault(char key, CharBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public boolean computeBooleanIfAbsentNonDefault(char key, CharPredicate mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public boolean computeBooleanIfPresentNonDefault(char key, CharBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public boolean supplyBooleanIfAbsentNonDefault(char key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public boolean mergeBoolean(char key, boolean value, BooleanBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -535,18 +535,18 @@ public boolean get(char key) { @Override public boolean computeBoolean(char key, CharBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanNonDefault(char key, CharBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean computeBooleanIfAbsent(char key, CharPredicate mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanIfAbsentNonDefault(char key, CharPredicate mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean computeBooleanIfPresent(char key, CharBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanIfPresentNonDefault(char key, CharBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean supplyBooleanIfAbsent(char key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public boolean computeBooleanNonDefault(char key, CharBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public boolean computeBooleanIfAbsentNonDefault(char key, CharPredicate mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public boolean computeBooleanIfPresentNonDefault(char key, CharBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public boolean supplyBooleanIfAbsentNonDefault(char key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public boolean mergeBoolean(char key, boolean value, BooleanBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -938,18 +938,18 @@ public AbstractChar2BooleanMap setDefaultReturnValue(boolean v) { @Override public boolean computeBoolean(char key, CharBooleanUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeBoolean(key, mappingFunction); } } @Override - public boolean computeBooleanNonDefault(char key, CharBooleanUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeBooleanNonDefault(key, mappingFunction); } } - @Override public boolean computeBooleanIfAbsent(char key, CharPredicate mappingFunction) { synchronized(mutex) { return map.computeBooleanIfAbsent(key, mappingFunction); } } @Override - public boolean computeBooleanIfAbsentNonDefault(char key, CharPredicate mappingFunction) { synchronized(mutex) { return map.computeBooleanIfAbsentNonDefault(key, mappingFunction); } } - @Override public boolean computeBooleanIfPresent(char key, CharBooleanUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeBooleanIfPresent(key, mappingFunction); } } @Override - public boolean computeBooleanIfPresentNonDefault(char key, CharBooleanUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeBooleanIfPresentNonDefault(key, mappingFunction); } } - @Override public boolean supplyBooleanIfAbsent(char key, BooleanSupplier valueProvider) { synchronized(mutex) { return map.supplyBooleanIfAbsent(key, valueProvider); } } @Override + public boolean computeBooleanNonDefault(char key, CharBooleanUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeBooleanNonDefault(key, mappingFunction); } } + @Override + public boolean computeBooleanIfAbsentNonDefault(char key, CharPredicate mappingFunction) { synchronized(mutex) { return map.computeBooleanIfAbsentNonDefault(key, mappingFunction); } } + @Override + public boolean computeBooleanIfPresentNonDefault(char key, CharBooleanUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeBooleanIfPresentNonDefault(key, mappingFunction); } } + @Override public boolean supplyBooleanIfAbsentNonDefault(char key, BooleanSupplier valueProvider) { synchronized(mutex) { return map.supplyBooleanIfAbsentNonDefault(key, valueProvider); } } @Override public boolean mergeBoolean(char key, boolean value, BooleanBooleanUnaryOperator mappingFunction) { synchronized(mutex) { return map.mergeBoolean(key, value, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/chars/utils/maps/Char2ByteMaps.java b/src/main/java/speiger/src/collections/chars/utils/maps/Char2ByteMaps.java index 796aea30..df14315c 100644 --- a/src/main/java/speiger/src/collections/chars/utils/maps/Char2ByteMaps.java +++ b/src/main/java/speiger/src/collections/chars/utils/maps/Char2ByteMaps.java @@ -250,18 +250,18 @@ public static class SingletonMap extends AbstractChar2ByteMap { @Override public byte computeByte(char key, CharByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteNonDefault(char key, CharByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte computeByteIfAbsent(char key, Char2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteIfAbsentNonDefault(char key, Char2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte computeByteIfPresent(char key, CharByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteIfPresentNonDefault(char key, CharByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte supplyByteIfAbsent(char key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public byte computeByteNonDefault(char key, CharByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public byte computeByteIfAbsentNonDefault(char key, Char2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public byte computeByteIfPresentNonDefault(char key, CharByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public byte supplyByteIfAbsentNonDefault(char key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public byte mergeByte(char key, byte value, ByteByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -312,18 +312,18 @@ public static class EmptyMap extends AbstractChar2ByteMap { @Override public byte computeByte(char key, CharByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteNonDefault(char key, CharByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte computeByteIfAbsent(char key, Char2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteIfAbsentNonDefault(char key, Char2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte computeByteIfPresent(char key, CharByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteIfPresentNonDefault(char key, CharByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte supplyByteIfAbsent(char key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public byte computeByteNonDefault(char key, CharByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public byte computeByteIfAbsentNonDefault(char key, Char2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public byte computeByteIfPresentNonDefault(char key, CharByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public byte supplyByteIfAbsentNonDefault(char key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public byte mergeByte(char key, byte value, ByteByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -547,18 +547,18 @@ public byte get(char key) { @Override public byte computeByte(char key, CharByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteNonDefault(char key, CharByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte computeByteIfAbsent(char key, Char2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteIfAbsentNonDefault(char key, Char2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte computeByteIfPresent(char key, CharByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteIfPresentNonDefault(char key, CharByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte supplyByteIfAbsent(char key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public byte computeByteNonDefault(char key, CharByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public byte computeByteIfAbsentNonDefault(char key, Char2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public byte computeByteIfPresentNonDefault(char key, CharByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public byte supplyByteIfAbsentNonDefault(char key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public byte mergeByte(char key, byte value, ByteByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -955,18 +955,18 @@ public AbstractChar2ByteMap setDefaultReturnValue(byte v) { @Override public byte computeByte(char key, CharByteUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeByte(key, mappingFunction); } } @Override - public byte computeByteNonDefault(char key, CharByteUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeByteNonDefault(key, mappingFunction); } } - @Override public byte computeByteIfAbsent(char key, Char2ByteFunction mappingFunction) { synchronized(mutex) { return map.computeByteIfAbsent(key, mappingFunction); } } @Override - public byte computeByteIfAbsentNonDefault(char key, Char2ByteFunction mappingFunction) { synchronized(mutex) { return map.computeByteIfAbsentNonDefault(key, mappingFunction); } } - @Override public byte computeByteIfPresent(char key, CharByteUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeByteIfPresent(key, mappingFunction); } } @Override - public byte computeByteIfPresentNonDefault(char key, CharByteUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeByteIfPresentNonDefault(key, mappingFunction); } } - @Override public byte supplyByteIfAbsent(char key, ByteSupplier valueProvider) { synchronized(mutex) { return map.supplyByteIfAbsent(key, valueProvider); } } @Override + public byte computeByteNonDefault(char key, CharByteUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeByteNonDefault(key, mappingFunction); } } + @Override + public byte computeByteIfAbsentNonDefault(char key, Char2ByteFunction mappingFunction) { synchronized(mutex) { return map.computeByteIfAbsentNonDefault(key, mappingFunction); } } + @Override + public byte computeByteIfPresentNonDefault(char key, CharByteUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeByteIfPresentNonDefault(key, mappingFunction); } } + @Override public byte supplyByteIfAbsentNonDefault(char key, ByteSupplier valueProvider) { synchronized(mutex) { return map.supplyByteIfAbsentNonDefault(key, valueProvider); } } @Override public byte mergeByte(char key, byte value, ByteByteUnaryOperator mappingFunction) { synchronized(mutex) { return map.mergeByte(key, value, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/chars/utils/maps/Char2CharMaps.java b/src/main/java/speiger/src/collections/chars/utils/maps/Char2CharMaps.java index 307550d0..33ae0c7e 100644 --- a/src/main/java/speiger/src/collections/chars/utils/maps/Char2CharMaps.java +++ b/src/main/java/speiger/src/collections/chars/utils/maps/Char2CharMaps.java @@ -249,18 +249,18 @@ public static class SingletonMap extends AbstractChar2CharMap { @Override public char computeChar(char key, CharCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharNonDefault(char key, CharCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char computeCharIfAbsent(char key, CharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharIfAbsentNonDefault(char key, CharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char computeCharIfPresent(char key, CharCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharIfPresentNonDefault(char key, CharCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char supplyCharIfAbsent(char key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public char computeCharNonDefault(char key, CharCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public char computeCharIfAbsentNonDefault(char key, CharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public char computeCharIfPresentNonDefault(char key, CharCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public char supplyCharIfAbsentNonDefault(char key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public char mergeChar(char key, char value, CharCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -311,18 +311,18 @@ public static class EmptyMap extends AbstractChar2CharMap { @Override public char computeChar(char key, CharCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharNonDefault(char key, CharCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char computeCharIfAbsent(char key, CharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharIfAbsentNonDefault(char key, CharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char computeCharIfPresent(char key, CharCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharIfPresentNonDefault(char key, CharCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char supplyCharIfAbsent(char key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public char computeCharNonDefault(char key, CharCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public char computeCharIfAbsentNonDefault(char key, CharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public char computeCharIfPresentNonDefault(char key, CharCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public char supplyCharIfAbsentNonDefault(char key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public char mergeChar(char key, char value, CharCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -546,18 +546,18 @@ public char get(char key) { @Override public char computeChar(char key, CharCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharNonDefault(char key, CharCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char computeCharIfAbsent(char key, CharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharIfAbsentNonDefault(char key, CharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char computeCharIfPresent(char key, CharCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharIfPresentNonDefault(char key, CharCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char supplyCharIfAbsent(char key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public char computeCharNonDefault(char key, CharCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public char computeCharIfAbsentNonDefault(char key, CharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public char computeCharIfPresentNonDefault(char key, CharCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public char supplyCharIfAbsentNonDefault(char key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public char mergeChar(char key, char value, CharCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -954,18 +954,18 @@ public AbstractChar2CharMap setDefaultReturnValue(char v) { @Override public char computeChar(char key, CharCharUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeChar(key, mappingFunction); } } @Override - public char computeCharNonDefault(char key, CharCharUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeCharNonDefault(key, mappingFunction); } } - @Override public char computeCharIfAbsent(char key, CharUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeCharIfAbsent(key, mappingFunction); } } @Override - public char computeCharIfAbsentNonDefault(char key, CharUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeCharIfAbsentNonDefault(key, mappingFunction); } } - @Override public char computeCharIfPresent(char key, CharCharUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeCharIfPresent(key, mappingFunction); } } @Override - public char computeCharIfPresentNonDefault(char key, CharCharUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeCharIfPresentNonDefault(key, mappingFunction); } } - @Override public char supplyCharIfAbsent(char key, CharSupplier valueProvider) { synchronized(mutex) { return map.supplyCharIfAbsent(key, valueProvider); } } @Override + public char computeCharNonDefault(char key, CharCharUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeCharNonDefault(key, mappingFunction); } } + @Override + public char computeCharIfAbsentNonDefault(char key, CharUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeCharIfAbsentNonDefault(key, mappingFunction); } } + @Override + public char computeCharIfPresentNonDefault(char key, CharCharUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeCharIfPresentNonDefault(key, mappingFunction); } } + @Override public char supplyCharIfAbsentNonDefault(char key, CharSupplier valueProvider) { synchronized(mutex) { return map.supplyCharIfAbsentNonDefault(key, valueProvider); } } @Override public char mergeChar(char key, char value, CharCharUnaryOperator mappingFunction) { synchronized(mutex) { return map.mergeChar(key, value, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/chars/utils/maps/Char2DoubleMaps.java b/src/main/java/speiger/src/collections/chars/utils/maps/Char2DoubleMaps.java index 60b77a0a..89eac951 100644 --- a/src/main/java/speiger/src/collections/chars/utils/maps/Char2DoubleMaps.java +++ b/src/main/java/speiger/src/collections/chars/utils/maps/Char2DoubleMaps.java @@ -250,18 +250,18 @@ public static class SingletonMap extends AbstractChar2DoubleMap { @Override public double computeDouble(char key, CharDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleNonDefault(char key, CharDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double computeDoubleIfAbsent(char key, Char2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleIfAbsentNonDefault(char key, Char2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double computeDoubleIfPresent(char key, CharDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleIfPresentNonDefault(char key, CharDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double supplyDoubleIfAbsent(char key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public double computeDoubleNonDefault(char key, CharDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public double computeDoubleIfAbsentNonDefault(char key, Char2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public double computeDoubleIfPresentNonDefault(char key, CharDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public double supplyDoubleIfAbsentNonDefault(char key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public double mergeDouble(char key, double value, DoubleDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -312,18 +312,18 @@ public static class EmptyMap extends AbstractChar2DoubleMap { @Override public double computeDouble(char key, CharDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleNonDefault(char key, CharDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double computeDoubleIfAbsent(char key, Char2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleIfAbsentNonDefault(char key, Char2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double computeDoubleIfPresent(char key, CharDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleIfPresentNonDefault(char key, CharDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double supplyDoubleIfAbsent(char key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public double computeDoubleNonDefault(char key, CharDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public double computeDoubleIfAbsentNonDefault(char key, Char2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public double computeDoubleIfPresentNonDefault(char key, CharDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public double supplyDoubleIfAbsentNonDefault(char key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public double mergeDouble(char key, double value, DoubleDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -547,18 +547,18 @@ public double get(char key) { @Override public double computeDouble(char key, CharDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleNonDefault(char key, CharDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double computeDoubleIfAbsent(char key, Char2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleIfAbsentNonDefault(char key, Char2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double computeDoubleIfPresent(char key, CharDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleIfPresentNonDefault(char key, CharDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double supplyDoubleIfAbsent(char key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public double computeDoubleNonDefault(char key, CharDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public double computeDoubleIfAbsentNonDefault(char key, Char2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public double computeDoubleIfPresentNonDefault(char key, CharDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public double supplyDoubleIfAbsentNonDefault(char key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public double mergeDouble(char key, double value, DoubleDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -955,18 +955,18 @@ public AbstractChar2DoubleMap setDefaultReturnValue(double v) { @Override public double computeDouble(char key, CharDoubleUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeDouble(key, mappingFunction); } } @Override - public double computeDoubleNonDefault(char key, CharDoubleUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeDoubleNonDefault(key, mappingFunction); } } - @Override public double computeDoubleIfAbsent(char key, Char2DoubleFunction mappingFunction) { synchronized(mutex) { return map.computeDoubleIfAbsent(key, mappingFunction); } } @Override - public double computeDoubleIfAbsentNonDefault(char key, Char2DoubleFunction mappingFunction) { synchronized(mutex) { return map.computeDoubleIfAbsentNonDefault(key, mappingFunction); } } - @Override public double computeDoubleIfPresent(char key, CharDoubleUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeDoubleIfPresent(key, mappingFunction); } } @Override - public double computeDoubleIfPresentNonDefault(char key, CharDoubleUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeDoubleIfPresentNonDefault(key, mappingFunction); } } - @Override public double supplyDoubleIfAbsent(char key, DoubleSupplier valueProvider) { synchronized(mutex) { return map.supplyDoubleIfAbsent(key, valueProvider); } } @Override + public double computeDoubleNonDefault(char key, CharDoubleUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeDoubleNonDefault(key, mappingFunction); } } + @Override + public double computeDoubleIfAbsentNonDefault(char key, Char2DoubleFunction mappingFunction) { synchronized(mutex) { return map.computeDoubleIfAbsentNonDefault(key, mappingFunction); } } + @Override + public double computeDoubleIfPresentNonDefault(char key, CharDoubleUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeDoubleIfPresentNonDefault(key, mappingFunction); } } + @Override public double supplyDoubleIfAbsentNonDefault(char key, DoubleSupplier valueProvider) { synchronized(mutex) { return map.supplyDoubleIfAbsentNonDefault(key, valueProvider); } } @Override public double mergeDouble(char key, double value, DoubleDoubleUnaryOperator mappingFunction) { synchronized(mutex) { return map.mergeDouble(key, value, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/chars/utils/maps/Char2FloatMaps.java b/src/main/java/speiger/src/collections/chars/utils/maps/Char2FloatMaps.java index 49b5be4a..87cbee7b 100644 --- a/src/main/java/speiger/src/collections/chars/utils/maps/Char2FloatMaps.java +++ b/src/main/java/speiger/src/collections/chars/utils/maps/Char2FloatMaps.java @@ -250,18 +250,18 @@ public static class SingletonMap extends AbstractChar2FloatMap { @Override public float computeFloat(char key, CharFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatNonDefault(char key, CharFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float computeFloatIfAbsent(char key, Char2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatIfAbsentNonDefault(char key, Char2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float computeFloatIfPresent(char key, CharFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatIfPresentNonDefault(char key, CharFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float supplyFloatIfAbsent(char key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public float computeFloatNonDefault(char key, CharFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public float computeFloatIfAbsentNonDefault(char key, Char2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public float computeFloatIfPresentNonDefault(char key, CharFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public float supplyFloatIfAbsentNonDefault(char key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public float mergeFloat(char key, float value, FloatFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -312,18 +312,18 @@ public static class EmptyMap extends AbstractChar2FloatMap { @Override public float computeFloat(char key, CharFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatNonDefault(char key, CharFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float computeFloatIfAbsent(char key, Char2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatIfAbsentNonDefault(char key, Char2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float computeFloatIfPresent(char key, CharFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatIfPresentNonDefault(char key, CharFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float supplyFloatIfAbsent(char key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public float computeFloatNonDefault(char key, CharFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public float computeFloatIfAbsentNonDefault(char key, Char2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public float computeFloatIfPresentNonDefault(char key, CharFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public float supplyFloatIfAbsentNonDefault(char key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public float mergeFloat(char key, float value, FloatFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -547,18 +547,18 @@ public float get(char key) { @Override public float computeFloat(char key, CharFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatNonDefault(char key, CharFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float computeFloatIfAbsent(char key, Char2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatIfAbsentNonDefault(char key, Char2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float computeFloatIfPresent(char key, CharFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatIfPresentNonDefault(char key, CharFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float supplyFloatIfAbsent(char key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public float computeFloatNonDefault(char key, CharFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public float computeFloatIfAbsentNonDefault(char key, Char2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public float computeFloatIfPresentNonDefault(char key, CharFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public float supplyFloatIfAbsentNonDefault(char key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public float mergeFloat(char key, float value, FloatFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -955,18 +955,18 @@ public AbstractChar2FloatMap setDefaultReturnValue(float v) { @Override public float computeFloat(char key, CharFloatUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeFloat(key, mappingFunction); } } @Override - public float computeFloatNonDefault(char key, CharFloatUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeFloatNonDefault(key, mappingFunction); } } - @Override public float computeFloatIfAbsent(char key, Char2FloatFunction mappingFunction) { synchronized(mutex) { return map.computeFloatIfAbsent(key, mappingFunction); } } @Override - public float computeFloatIfAbsentNonDefault(char key, Char2FloatFunction mappingFunction) { synchronized(mutex) { return map.computeFloatIfAbsentNonDefault(key, mappingFunction); } } - @Override public float computeFloatIfPresent(char key, CharFloatUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeFloatIfPresent(key, mappingFunction); } } @Override - public float computeFloatIfPresentNonDefault(char key, CharFloatUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeFloatIfPresentNonDefault(key, mappingFunction); } } - @Override public float supplyFloatIfAbsent(char key, FloatSupplier valueProvider) { synchronized(mutex) { return map.supplyFloatIfAbsent(key, valueProvider); } } @Override + public float computeFloatNonDefault(char key, CharFloatUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeFloatNonDefault(key, mappingFunction); } } + @Override + public float computeFloatIfAbsentNonDefault(char key, Char2FloatFunction mappingFunction) { synchronized(mutex) { return map.computeFloatIfAbsentNonDefault(key, mappingFunction); } } + @Override + public float computeFloatIfPresentNonDefault(char key, CharFloatUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeFloatIfPresentNonDefault(key, mappingFunction); } } + @Override public float supplyFloatIfAbsentNonDefault(char key, FloatSupplier valueProvider) { synchronized(mutex) { return map.supplyFloatIfAbsentNonDefault(key, valueProvider); } } @Override public float mergeFloat(char key, float value, FloatFloatUnaryOperator mappingFunction) { synchronized(mutex) { return map.mergeFloat(key, value, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/chars/utils/maps/Char2IntMaps.java b/src/main/java/speiger/src/collections/chars/utils/maps/Char2IntMaps.java index abda506b..1ce34c37 100644 --- a/src/main/java/speiger/src/collections/chars/utils/maps/Char2IntMaps.java +++ b/src/main/java/speiger/src/collections/chars/utils/maps/Char2IntMaps.java @@ -250,18 +250,18 @@ public static class SingletonMap extends AbstractChar2IntMap { @Override public int computeInt(char key, CharIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntNonDefault(char key, CharIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int computeIntIfAbsent(char key, Char2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntIfAbsentNonDefault(char key, Char2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int computeIntIfPresent(char key, CharIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntIfPresentNonDefault(char key, CharIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int supplyIntIfAbsent(char key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public int computeIntNonDefault(char key, CharIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public int computeIntIfAbsentNonDefault(char key, Char2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public int computeIntIfPresentNonDefault(char key, CharIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public int supplyIntIfAbsentNonDefault(char key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public int mergeInt(char key, int value, IntIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -312,18 +312,18 @@ public static class EmptyMap extends AbstractChar2IntMap { @Override public int computeInt(char key, CharIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntNonDefault(char key, CharIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int computeIntIfAbsent(char key, Char2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntIfAbsentNonDefault(char key, Char2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int computeIntIfPresent(char key, CharIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntIfPresentNonDefault(char key, CharIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int supplyIntIfAbsent(char key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public int computeIntNonDefault(char key, CharIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public int computeIntIfAbsentNonDefault(char key, Char2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public int computeIntIfPresentNonDefault(char key, CharIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public int supplyIntIfAbsentNonDefault(char key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public int mergeInt(char key, int value, IntIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -547,18 +547,18 @@ public int get(char key) { @Override public int computeInt(char key, CharIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntNonDefault(char key, CharIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int computeIntIfAbsent(char key, Char2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntIfAbsentNonDefault(char key, Char2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int computeIntIfPresent(char key, CharIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntIfPresentNonDefault(char key, CharIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int supplyIntIfAbsent(char key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public int computeIntNonDefault(char key, CharIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public int computeIntIfAbsentNonDefault(char key, Char2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public int computeIntIfPresentNonDefault(char key, CharIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public int supplyIntIfAbsentNonDefault(char key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public int mergeInt(char key, int value, IntIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -955,18 +955,18 @@ public AbstractChar2IntMap setDefaultReturnValue(int v) { @Override public int computeInt(char key, CharIntUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeInt(key, mappingFunction); } } @Override - public int computeIntNonDefault(char key, CharIntUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeIntNonDefault(key, mappingFunction); } } - @Override public int computeIntIfAbsent(char key, Char2IntFunction mappingFunction) { synchronized(mutex) { return map.computeIntIfAbsent(key, mappingFunction); } } @Override - public int computeIntIfAbsentNonDefault(char key, Char2IntFunction mappingFunction) { synchronized(mutex) { return map.computeIntIfAbsentNonDefault(key, mappingFunction); } } - @Override public int computeIntIfPresent(char key, CharIntUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeIntIfPresent(key, mappingFunction); } } @Override - public int computeIntIfPresentNonDefault(char key, CharIntUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeIntIfPresentNonDefault(key, mappingFunction); } } - @Override public int supplyIntIfAbsent(char key, IntSupplier valueProvider) { synchronized(mutex) { return map.supplyIntIfAbsent(key, valueProvider); } } @Override + public int computeIntNonDefault(char key, CharIntUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeIntNonDefault(key, mappingFunction); } } + @Override + public int computeIntIfAbsentNonDefault(char key, Char2IntFunction mappingFunction) { synchronized(mutex) { return map.computeIntIfAbsentNonDefault(key, mappingFunction); } } + @Override + public int computeIntIfPresentNonDefault(char key, CharIntUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeIntIfPresentNonDefault(key, mappingFunction); } } + @Override public int supplyIntIfAbsentNonDefault(char key, IntSupplier valueProvider) { synchronized(mutex) { return map.supplyIntIfAbsentNonDefault(key, valueProvider); } } @Override public int mergeInt(char key, int value, IntIntUnaryOperator mappingFunction) { synchronized(mutex) { return map.mergeInt(key, value, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/chars/utils/maps/Char2LongMaps.java b/src/main/java/speiger/src/collections/chars/utils/maps/Char2LongMaps.java index 7c4944cc..9c4be5bc 100644 --- a/src/main/java/speiger/src/collections/chars/utils/maps/Char2LongMaps.java +++ b/src/main/java/speiger/src/collections/chars/utils/maps/Char2LongMaps.java @@ -250,18 +250,18 @@ public static class SingletonMap extends AbstractChar2LongMap { @Override public long computeLong(char key, CharLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongNonDefault(char key, CharLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long computeLongIfAbsent(char key, Char2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongIfAbsentNonDefault(char key, Char2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long computeLongIfPresent(char key, CharLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongIfPresentNonDefault(char key, CharLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long supplyLongIfAbsent(char key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public long computeLongNonDefault(char key, CharLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public long computeLongIfAbsentNonDefault(char key, Char2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public long computeLongIfPresentNonDefault(char key, CharLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public long supplyLongIfAbsentNonDefault(char key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public long mergeLong(char key, long value, LongLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -312,18 +312,18 @@ public static class EmptyMap extends AbstractChar2LongMap { @Override public long computeLong(char key, CharLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongNonDefault(char key, CharLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long computeLongIfAbsent(char key, Char2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongIfAbsentNonDefault(char key, Char2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long computeLongIfPresent(char key, CharLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongIfPresentNonDefault(char key, CharLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long supplyLongIfAbsent(char key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public long computeLongNonDefault(char key, CharLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public long computeLongIfAbsentNonDefault(char key, Char2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public long computeLongIfPresentNonDefault(char key, CharLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public long supplyLongIfAbsentNonDefault(char key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public long mergeLong(char key, long value, LongLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -547,18 +547,18 @@ public long get(char key) { @Override public long computeLong(char key, CharLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongNonDefault(char key, CharLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long computeLongIfAbsent(char key, Char2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongIfAbsentNonDefault(char key, Char2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long computeLongIfPresent(char key, CharLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongIfPresentNonDefault(char key, CharLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long supplyLongIfAbsent(char key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public long computeLongNonDefault(char key, CharLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public long computeLongIfAbsentNonDefault(char key, Char2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public long computeLongIfPresentNonDefault(char key, CharLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public long supplyLongIfAbsentNonDefault(char key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public long mergeLong(char key, long value, LongLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -955,18 +955,18 @@ public AbstractChar2LongMap setDefaultReturnValue(long v) { @Override public long computeLong(char key, CharLongUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeLong(key, mappingFunction); } } @Override - public long computeLongNonDefault(char key, CharLongUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeLongNonDefault(key, mappingFunction); } } - @Override public long computeLongIfAbsent(char key, Char2LongFunction mappingFunction) { synchronized(mutex) { return map.computeLongIfAbsent(key, mappingFunction); } } @Override - public long computeLongIfAbsentNonDefault(char key, Char2LongFunction mappingFunction) { synchronized(mutex) { return map.computeLongIfAbsentNonDefault(key, mappingFunction); } } - @Override public long computeLongIfPresent(char key, CharLongUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeLongIfPresent(key, mappingFunction); } } @Override - public long computeLongIfPresentNonDefault(char key, CharLongUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeLongIfPresentNonDefault(key, mappingFunction); } } - @Override public long supplyLongIfAbsent(char key, LongSupplier valueProvider) { synchronized(mutex) { return map.supplyLongIfAbsent(key, valueProvider); } } @Override + public long computeLongNonDefault(char key, CharLongUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeLongNonDefault(key, mappingFunction); } } + @Override + public long computeLongIfAbsentNonDefault(char key, Char2LongFunction mappingFunction) { synchronized(mutex) { return map.computeLongIfAbsentNonDefault(key, mappingFunction); } } + @Override + public long computeLongIfPresentNonDefault(char key, CharLongUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeLongIfPresentNonDefault(key, mappingFunction); } } + @Override public long supplyLongIfAbsentNonDefault(char key, LongSupplier valueProvider) { synchronized(mutex) { return map.supplyLongIfAbsentNonDefault(key, valueProvider); } } @Override public long mergeLong(char key, long value, LongLongUnaryOperator mappingFunction) { synchronized(mutex) { return map.mergeLong(key, value, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/chars/utils/maps/Char2ObjectMaps.java b/src/main/java/speiger/src/collections/chars/utils/maps/Char2ObjectMaps.java index b985de63..fc306927 100644 --- a/src/main/java/speiger/src/collections/chars/utils/maps/Char2ObjectMaps.java +++ b/src/main/java/speiger/src/collections/chars/utils/maps/Char2ObjectMaps.java @@ -266,20 +266,12 @@ public static class SingletonMap extends AbstractChar2ObjectMap { @Override public V compute(char key, CharObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeNonDefault(char key, CharObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V computeIfAbsent(char key, CharFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeIfAbsentNonDefault(char key, CharFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V computeIfPresent(char key, CharObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeIfPresentNonDefault(char key, CharObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V supplyIfAbsent(char key, ObjectSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public V supplyIfAbsentNonDefault(char key, ObjectSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public V merge(char key, V value, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override public void mergeAll(Char2ObjectMap m, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -325,20 +317,12 @@ public static class EmptyMap extends AbstractChar2ObjectMap { @Override public V compute(char key, CharObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeNonDefault(char key, CharObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V computeIfAbsent(char key, CharFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeIfAbsentNonDefault(char key, CharFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V computeIfPresent(char key, CharObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeIfPresentNonDefault(char key, CharObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V supplyIfAbsent(char key, ObjectSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public V supplyIfAbsentNonDefault(char key, ObjectSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public V merge(char key, V value, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override public void mergeAll(Char2ObjectMap m, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -561,20 +545,12 @@ public V get(char key) { @Override public V compute(char key, CharObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeNonDefault(char key, CharObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V computeIfAbsent(char key, CharFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeIfAbsentNonDefault(char key, CharFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V computeIfPresent(char key, CharObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeIfPresentNonDefault(char key, CharObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V supplyIfAbsent(char key, ObjectSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public V supplyIfAbsentNonDefault(char key, ObjectSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public V merge(char key, V value, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override public void mergeAll(Char2ObjectMap m, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -968,20 +944,12 @@ public AbstractChar2ObjectMap setDefaultReturnValue(V v) { @Override public V compute(char key, CharObjectUnaryOperator mappingFunction) { synchronized(mutex) { return map.compute(key, mappingFunction); } } @Override - public V computeNonDefault(char key, CharObjectUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeNonDefault(key, mappingFunction); } } - @Override public V computeIfAbsent(char key, CharFunction mappingFunction) { synchronized(mutex) { return map.computeIfAbsent(key, mappingFunction); } } @Override - public V computeIfAbsentNonDefault(char key, CharFunction mappingFunction) { synchronized(mutex) { return map.computeIfAbsentNonDefault(key, mappingFunction); } } - @Override public V computeIfPresent(char key, CharObjectUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeIfPresent(key, mappingFunction); } } @Override - public V computeIfPresentNonDefault(char key, CharObjectUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeIfPresentNonDefault(key, mappingFunction); } } - @Override public V supplyIfAbsent(char key, ObjectSupplier valueProvider) { synchronized(mutex) { return map.supplyIfAbsent(key, valueProvider); } } @Override - public V supplyIfAbsentNonDefault(char key, ObjectSupplier valueProvider) { synchronized(mutex) { return map.supplyIfAbsentNonDefault(key, valueProvider); } } - @Override public V merge(char key, V value, ObjectObjectUnaryOperator mappingFunction) { synchronized(mutex) { return map.merge(key, value, mappingFunction); } } @Override public void mergeAll(Char2ObjectMap m, ObjectObjectUnaryOperator mappingFunction) { synchronized(mutex) { map.mergeAll(m, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/chars/utils/maps/Char2ShortMaps.java b/src/main/java/speiger/src/collections/chars/utils/maps/Char2ShortMaps.java index fa69134f..ef65cc83 100644 --- a/src/main/java/speiger/src/collections/chars/utils/maps/Char2ShortMaps.java +++ b/src/main/java/speiger/src/collections/chars/utils/maps/Char2ShortMaps.java @@ -250,18 +250,18 @@ public static class SingletonMap extends AbstractChar2ShortMap { @Override public short computeShort(char key, CharShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortNonDefault(char key, CharShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short computeShortIfAbsent(char key, Char2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortIfAbsentNonDefault(char key, Char2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short computeShortIfPresent(char key, CharShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortIfPresentNonDefault(char key, CharShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short supplyShortIfAbsent(char key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public short computeShortNonDefault(char key, CharShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public short computeShortIfAbsentNonDefault(char key, Char2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public short computeShortIfPresentNonDefault(char key, CharShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public short supplyShortIfAbsentNonDefault(char key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public short mergeShort(char key, short value, ShortShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -312,18 +312,18 @@ public static class EmptyMap extends AbstractChar2ShortMap { @Override public short computeShort(char key, CharShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortNonDefault(char key, CharShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short computeShortIfAbsent(char key, Char2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortIfAbsentNonDefault(char key, Char2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short computeShortIfPresent(char key, CharShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortIfPresentNonDefault(char key, CharShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short supplyShortIfAbsent(char key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public short computeShortNonDefault(char key, CharShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public short computeShortIfAbsentNonDefault(char key, Char2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public short computeShortIfPresentNonDefault(char key, CharShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public short supplyShortIfAbsentNonDefault(char key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public short mergeShort(char key, short value, ShortShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -547,18 +547,18 @@ public short get(char key) { @Override public short computeShort(char key, CharShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortNonDefault(char key, CharShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short computeShortIfAbsent(char key, Char2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortIfAbsentNonDefault(char key, Char2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short computeShortIfPresent(char key, CharShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortIfPresentNonDefault(char key, CharShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short supplyShortIfAbsent(char key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public short computeShortNonDefault(char key, CharShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public short computeShortIfAbsentNonDefault(char key, Char2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public short computeShortIfPresentNonDefault(char key, CharShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public short supplyShortIfAbsentNonDefault(char key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public short mergeShort(char key, short value, ShortShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -955,18 +955,18 @@ public AbstractChar2ShortMap setDefaultReturnValue(short v) { @Override public short computeShort(char key, CharShortUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeShort(key, mappingFunction); } } @Override - public short computeShortNonDefault(char key, CharShortUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeShortNonDefault(key, mappingFunction); } } - @Override public short computeShortIfAbsent(char key, Char2ShortFunction mappingFunction) { synchronized(mutex) { return map.computeShortIfAbsent(key, mappingFunction); } } @Override - public short computeShortIfAbsentNonDefault(char key, Char2ShortFunction mappingFunction) { synchronized(mutex) { return map.computeShortIfAbsentNonDefault(key, mappingFunction); } } - @Override public short computeShortIfPresent(char key, CharShortUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeShortIfPresent(key, mappingFunction); } } @Override - public short computeShortIfPresentNonDefault(char key, CharShortUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeShortIfPresentNonDefault(key, mappingFunction); } } - @Override public short supplyShortIfAbsent(char key, ShortSupplier valueProvider) { synchronized(mutex) { return map.supplyShortIfAbsent(key, valueProvider); } } @Override + public short computeShortNonDefault(char key, CharShortUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeShortNonDefault(key, mappingFunction); } } + @Override + public short computeShortIfAbsentNonDefault(char key, Char2ShortFunction mappingFunction) { synchronized(mutex) { return map.computeShortIfAbsentNonDefault(key, mappingFunction); } } + @Override + public short computeShortIfPresentNonDefault(char key, CharShortUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeShortIfPresentNonDefault(key, mappingFunction); } } + @Override public short supplyShortIfAbsentNonDefault(char key, ShortSupplier valueProvider) { synchronized(mutex) { return map.supplyShortIfAbsentNonDefault(key, valueProvider); } } @Override public short mergeShort(char key, short value, ShortShortUnaryOperator mappingFunction) { synchronized(mutex) { return map.mergeShort(key, value, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/doubles/lists/AbstractDoubleList.java b/src/main/java/speiger/src/collections/doubles/lists/AbstractDoubleList.java index e8668156..a1ec7fef 100644 --- a/src/main/java/speiger/src/collections/doubles/lists/AbstractDoubleList.java +++ b/src/main/java/speiger/src/collections/doubles/lists/AbstractDoubleList.java @@ -12,6 +12,7 @@ import speiger.src.collections.doubles.collections.DoubleCollection; import speiger.src.collections.doubles.collections.DoubleIterator; import speiger.src.collections.doubles.collections.DoubleSplititerator; +import speiger.src.collections.ints.lists.IntList; import speiger.src.collections.doubles.utils.DoubleSplititerators; import speiger.src.collections.utils.SanityChecks; @@ -205,13 +206,23 @@ public DoubleIterator iterator() { public DoubleListIterator listIterator() { return listIterator(0); } - + @Override public DoubleListIterator listIterator(int index) { if(index < 0 || index > size()) throw new IndexOutOfBoundsException(); return new DoubleListIter(index); } + @Override + public DoubleListIterator indexedIterator(int...indecies) { + return new IndexedIterator(indecies); + } + + @Override + public DoubleListIterator indexedIterator(IntList indecies) { + return new ListIndexedIterator(indecies); + } + @Override public void size(int size) { while(size > size()) add(0D); @@ -566,7 +577,153 @@ public int back(int amount) { } } } + + private class ListIndexedIterator implements DoubleListIterator { + IntList indecies; + int index; + int lastReturned = -1; + + ListIndexedIterator(IntList indecies) { + this.indecies = indecies; + } + + @Override + public boolean hasNext() { + return index < indecies.size(); + } + + @Override + public double nextDouble() { + if(!hasNext()) throw new NoSuchElementException(); + int i = index++; + return getDouble((lastReturned = indecies.getInt(i))); + } + + @Override + public boolean hasPrevious() { + return index > 0; + } + + @Override + public double previousDouble() { + if(!hasPrevious()) throw new NoSuchElementException(); + index--; + return getDouble((lastReturned = indecies.getInt(index))); + } + + @Override + public int nextIndex() { + return index; + } + + @Override + public int previousIndex() { + return index-1; + } + + @Override + public void remove() { throw new UnsupportedOperationException(); } + @Override + public void add(double e) { throw new UnsupportedOperationException(); } + + @Override + public void set(double e) { + if(lastReturned == -1) throw new IllegalStateException(); + AbstractDoubleList.this.set(lastReturned, e); + } + + @Override + public int skip(int amount) { + if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed"); + int steps = Math.min(amount, indecies.size() - index); + index += steps; + if(steps > 0) lastReturned = Math.min(index-1, indecies.size()-1); + return steps; + } + + @Override + public int back(int amount) { + if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed"); + int steps = Math.min(amount, index); + index -= steps; + if(steps > 0) lastReturned = Math.max(index, 0); + return steps; + } + } + + private class IndexedIterator implements DoubleListIterator { + int[] indecies; + int index; + int lastReturned = -1; + + IndexedIterator(int[] indecies) { + this.indecies = indecies; + } + @Override + public boolean hasNext() { + return index < indecies.length; + } + + @Override + public double nextDouble() { + if(!hasNext()) throw new NoSuchElementException(); + int i = index++; + return getDouble((lastReturned = indecies[i])); + } + + @Override + public boolean hasPrevious() { + return index > 0; + } + + @Override + public double previousDouble() { + if(!hasPrevious()) throw new NoSuchElementException(); + index--; + return getDouble((lastReturned = indecies[index])); + } + + @Override + public int nextIndex() { + return index; + } + + @Override + public int previousIndex() { + return index-1; + } + + @Override + public void remove() { throw new UnsupportedOperationException(); } + @Override + public void add(double e) { throw new UnsupportedOperationException(); } + + @Override + public void set(double e) { + if(lastReturned == -1) throw new IllegalStateException(); + AbstractDoubleList.this.set(lastReturned, e); + } + + @Override + public int skip(int amount) { + if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed"); + int steps = Math.min(amount, indecies.length - index); + index += steps; + if(steps > 0) lastReturned = Math.min(index-1, indecies.length-1); + return steps; + } + + @Override + public int back(int amount) { + if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed"); + int steps = Math.min(amount, index); + index -= steps; + if(steps > 0) lastReturned = Math.max(index, 0); + return steps; + } + } + private class DoubleListIter implements DoubleListIterator { int index; int lastReturned = -1; @@ -644,7 +801,7 @@ public int back(int amount) { if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed"); int steps = Math.min(amount, index); index -= steps; - if(steps > 0) lastReturned = Math.min(index, size()-1); + if(steps > 0) lastReturned = Math.max(index, 0); return steps; } } diff --git a/src/main/java/speiger/src/collections/doubles/lists/DoubleList.java b/src/main/java/speiger/src/collections/doubles/lists/DoubleList.java index efdc5cc3..8e209f50 100644 --- a/src/main/java/speiger/src/collections/doubles/lists/DoubleList.java +++ b/src/main/java/speiger/src/collections/doubles/lists/DoubleList.java @@ -14,6 +14,7 @@ import speiger.src.collections.doubles.functions.DoubleComparator; import speiger.src.collections.doubles.utils.DoubleArrays; import speiger.src.collections.doubles.utils.DoubleLists; +import speiger.src.collections.ints.lists.IntList; import speiger.src.collections.doubles.utils.DoubleSplititerators; /** @@ -341,6 +342,24 @@ public default void forEachIndexed(IntDoubleConsumer action) { @Override public DoubleListIterator listIterator(int index); + /** + * Creates a Iterator that follows the indecies provided.
+ * For example if the Lists Contents is:
-1, 0 1
and the indecies are:
0, 1, 2, 2, 1, 0
+ * then the iterator will return the following values:
-1, 0, 1, 1, 0, -1 + * @param indecies that should be used for the iteration. + * @return a custom indexed iterator + */ + public DoubleListIterator indexedIterator(int...indecies); + + /** + * Creates a Iterator that follows the indecies provided.
+ * For example if the Lists Contents is:
-1, 0 1
and the indecies are:
0, 1, 2, 2, 1, 0
+ * then the iterator will return the following values:
-1, 0, 1, 1, 0, -1 + * @param indecies that should be used for the iteration. + * @return a custom indexed iterator + */ + public DoubleListIterator indexedIterator(IntList indecies); + /** * A Type-Specific List of subList * @see java.util.List#subList(int, int) diff --git a/src/main/java/speiger/src/collections/doubles/maps/abstracts/AbstractDouble2BooleanMap.java b/src/main/java/speiger/src/collections/doubles/maps/abstracts/AbstractDouble2BooleanMap.java index 032c6d6d..d9ac97e8 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/abstracts/AbstractDouble2BooleanMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/abstracts/AbstractDouble2BooleanMap.java @@ -151,6 +151,39 @@ public boolean computeBoolean(double key, DoubleBooleanUnaryOperator mappingFunc return newValue; } + @Override + public boolean computeBooleanIfAbsent(double key, DoublePredicate mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(!containsKey(key)) { + boolean newValue = mappingFunction.test(key); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public boolean supplyBooleanIfAbsent(double key, BooleanSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + if(!containsKey(key)) { + boolean newValue = valueProvider.getAsBoolean(); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public boolean computeBooleanIfPresent(double key, DoubleBooleanUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(containsKey(key)) { + boolean newValue = mappingFunction.applyAsBoolean(key, get(key)); + put(key, newValue); + return newValue; + } + return getDefaultReturnValue(); + } + @Override public boolean computeBooleanNonDefault(double key, DoubleBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -167,17 +200,6 @@ public boolean computeBooleanNonDefault(double key, DoubleBooleanUnaryOperator m return newValue; } - @Override - public boolean computeBooleanIfAbsent(double key, DoublePredicate mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(!containsKey(key)) { - boolean newValue = mappingFunction.test(key); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public boolean computeBooleanIfAbsentNonDefault(double key, DoublePredicate mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -192,17 +214,6 @@ public boolean computeBooleanIfAbsentNonDefault(double key, DoublePredicate mapp return value; } - @Override - public boolean supplyBooleanIfAbsent(double key, BooleanSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - if(!containsKey(key)) { - boolean newValue = valueProvider.getAsBoolean(); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public boolean supplyBooleanIfAbsentNonDefault(double key, BooleanSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -217,17 +228,6 @@ public boolean supplyBooleanIfAbsentNonDefault(double key, BooleanSupplier value return value; } - @Override - public boolean computeBooleanIfPresent(double key, DoubleBooleanUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(containsKey(key)) { - boolean newValue = mappingFunction.applyAsBoolean(key, get(key)); - put(key, newValue); - return newValue; - } - return getDefaultReturnValue(); - } - @Override public boolean computeBooleanIfPresentNonDefault(double key, DoubleBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/doubles/maps/abstracts/AbstractDouble2ByteMap.java b/src/main/java/speiger/src/collections/doubles/maps/abstracts/AbstractDouble2ByteMap.java index adbfea7f..ca0bed0b 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/abstracts/AbstractDouble2ByteMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/abstracts/AbstractDouble2ByteMap.java @@ -157,6 +157,39 @@ public byte computeByte(double key, DoubleByteUnaryOperator mappingFunction) { return newValue; } + @Override + public byte computeByteIfAbsent(double key, Double2ByteFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(!containsKey(key)) { + byte newValue = mappingFunction.applyAsByte(key); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public byte supplyByteIfAbsent(double key, ByteSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + if(!containsKey(key)) { + byte newValue = valueProvider.getAsByte(); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public byte computeByteIfPresent(double key, DoubleByteUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(containsKey(key)) { + byte newValue = mappingFunction.applyAsByte(key, get(key)); + put(key, newValue); + return newValue; + } + return getDefaultReturnValue(); + } + @Override public byte computeByteNonDefault(double key, DoubleByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -173,17 +206,6 @@ public byte computeByteNonDefault(double key, DoubleByteUnaryOperator mappingFun return newValue; } - @Override - public byte computeByteIfAbsent(double key, Double2ByteFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(!containsKey(key)) { - byte newValue = mappingFunction.applyAsByte(key); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public byte computeByteIfAbsentNonDefault(double key, Double2ByteFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -198,23 +220,12 @@ public byte computeByteIfAbsentNonDefault(double key, Double2ByteFunction mappin return value; } - @Override - public byte supplyByteIfAbsent(double key, ByteSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - if(!containsKey(key)) { - byte newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public byte supplyByteIfAbsentNonDefault(double key, ByteSupplier valueProvider) { Objects.requireNonNull(valueProvider); byte value; if((value = get(key)) == getDefaultReturnValue() || !containsKey(key)) { - byte newValue = valueProvider.getAsInt(); + byte newValue = valueProvider.getAsByte(); if(newValue != getDefaultReturnValue()) { put(key, newValue); return newValue; @@ -223,17 +234,6 @@ public byte supplyByteIfAbsentNonDefault(double key, ByteSupplier valueProvider) return value; } - @Override - public byte computeByteIfPresent(double key, DoubleByteUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(containsKey(key)) { - byte newValue = mappingFunction.applyAsByte(key, get(key)); - put(key, newValue); - return newValue; - } - return getDefaultReturnValue(); - } - @Override public byte computeByteIfPresentNonDefault(double key, DoubleByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/doubles/maps/abstracts/AbstractDouble2CharMap.java b/src/main/java/speiger/src/collections/doubles/maps/abstracts/AbstractDouble2CharMap.java index efadc09a..d3f9d269 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/abstracts/AbstractDouble2CharMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/abstracts/AbstractDouble2CharMap.java @@ -157,6 +157,39 @@ public char computeChar(double key, DoubleCharUnaryOperator mappingFunction) { return newValue; } + @Override + public char computeCharIfAbsent(double key, Double2CharFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(!containsKey(key)) { + char newValue = mappingFunction.applyAsChar(key); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public char supplyCharIfAbsent(double key, CharSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + if(!containsKey(key)) { + char newValue = valueProvider.getAsChar(); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public char computeCharIfPresent(double key, DoubleCharUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(containsKey(key)) { + char newValue = mappingFunction.applyAsChar(key, get(key)); + put(key, newValue); + return newValue; + } + return getDefaultReturnValue(); + } + @Override public char computeCharNonDefault(double key, DoubleCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -173,17 +206,6 @@ public char computeCharNonDefault(double key, DoubleCharUnaryOperator mappingFun return newValue; } - @Override - public char computeCharIfAbsent(double key, Double2CharFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(!containsKey(key)) { - char newValue = mappingFunction.applyAsChar(key); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public char computeCharIfAbsentNonDefault(double key, Double2CharFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -198,23 +220,12 @@ public char computeCharIfAbsentNonDefault(double key, Double2CharFunction mappin return value; } - @Override - public char supplyCharIfAbsent(double key, CharSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - if(!containsKey(key)) { - char newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public char supplyCharIfAbsentNonDefault(double key, CharSupplier valueProvider) { Objects.requireNonNull(valueProvider); char value; if((value = get(key)) == getDefaultReturnValue() || !containsKey(key)) { - char newValue = valueProvider.getAsInt(); + char newValue = valueProvider.getAsChar(); if(newValue != getDefaultReturnValue()) { put(key, newValue); return newValue; @@ -223,17 +234,6 @@ public char supplyCharIfAbsentNonDefault(double key, CharSupplier valueProvider) return value; } - @Override - public char computeCharIfPresent(double key, DoubleCharUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(containsKey(key)) { - char newValue = mappingFunction.applyAsChar(key, get(key)); - put(key, newValue); - return newValue; - } - return getDefaultReturnValue(); - } - @Override public char computeCharIfPresentNonDefault(double key, DoubleCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/doubles/maps/abstracts/AbstractDouble2DoubleMap.java b/src/main/java/speiger/src/collections/doubles/maps/abstracts/AbstractDouble2DoubleMap.java index 883fc329..8d7e52dc 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/abstracts/AbstractDouble2DoubleMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/abstracts/AbstractDouble2DoubleMap.java @@ -155,6 +155,39 @@ public double computeDouble(double key, DoubleDoubleUnaryOperator mappingFunctio return newValue; } + @Override + public double computeDoubleIfAbsent(double key, DoubleUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(!containsKey(key)) { + double newValue = mappingFunction.applyAsDouble(key); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public double supplyDoubleIfAbsent(double key, DoubleSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + if(!containsKey(key)) { + double newValue = valueProvider.getAsDouble(); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public double computeDoubleIfPresent(double key, DoubleDoubleUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(containsKey(key)) { + double newValue = mappingFunction.applyAsDouble(key, get(key)); + put(key, newValue); + return newValue; + } + return getDefaultReturnValue(); + } + @Override public double computeDoubleNonDefault(double key, DoubleDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -171,17 +204,6 @@ public double computeDoubleNonDefault(double key, DoubleDoubleUnaryOperator mapp return newValue; } - @Override - public double computeDoubleIfAbsent(double key, DoubleUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(!containsKey(key)) { - double newValue = mappingFunction.applyAsDouble(key); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public double computeDoubleIfAbsentNonDefault(double key, DoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -196,17 +218,6 @@ public double computeDoubleIfAbsentNonDefault(double key, DoubleUnaryOperator ma return value; } - @Override - public double supplyDoubleIfAbsent(double key, DoubleSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - if(!containsKey(key)) { - double newValue = valueProvider.getAsDouble(); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public double supplyDoubleIfAbsentNonDefault(double key, DoubleSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -221,17 +232,6 @@ public double supplyDoubleIfAbsentNonDefault(double key, DoubleSupplier valuePro return value; } - @Override - public double computeDoubleIfPresent(double key, DoubleDoubleUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(containsKey(key)) { - double newValue = mappingFunction.applyAsDouble(key, get(key)); - put(key, newValue); - return newValue; - } - return getDefaultReturnValue(); - } - @Override public double computeDoubleIfPresentNonDefault(double key, DoubleDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/doubles/maps/abstracts/AbstractDouble2FloatMap.java b/src/main/java/speiger/src/collections/doubles/maps/abstracts/AbstractDouble2FloatMap.java index 6775eda1..09dafe42 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/abstracts/AbstractDouble2FloatMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/abstracts/AbstractDouble2FloatMap.java @@ -157,6 +157,39 @@ public float computeFloat(double key, DoubleFloatUnaryOperator mappingFunction) return newValue; } + @Override + public float computeFloatIfAbsent(double key, Double2FloatFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(!containsKey(key)) { + float newValue = mappingFunction.applyAsFloat(key); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public float supplyFloatIfAbsent(double key, FloatSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + if(!containsKey(key)) { + float newValue = valueProvider.getAsFloat(); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public float computeFloatIfPresent(double key, DoubleFloatUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(containsKey(key)) { + float newValue = mappingFunction.applyAsFloat(key, get(key)); + put(key, newValue); + return newValue; + } + return getDefaultReturnValue(); + } + @Override public float computeFloatNonDefault(double key, DoubleFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -173,17 +206,6 @@ public float computeFloatNonDefault(double key, DoubleFloatUnaryOperator mapping return newValue; } - @Override - public float computeFloatIfAbsent(double key, Double2FloatFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(!containsKey(key)) { - float newValue = mappingFunction.applyAsFloat(key); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public float computeFloatIfAbsentNonDefault(double key, Double2FloatFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -198,23 +220,12 @@ public float computeFloatIfAbsentNonDefault(double key, Double2FloatFunction map return value; } - @Override - public float supplyFloatIfAbsent(double key, FloatSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - if(!containsKey(key)) { - float newValue = valueProvider.getAsDouble(); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public float supplyFloatIfAbsentNonDefault(double key, FloatSupplier valueProvider) { Objects.requireNonNull(valueProvider); float value; if((value = get(key)) == getDefaultReturnValue() || !containsKey(key)) { - float newValue = valueProvider.getAsDouble(); + float newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) != Float.floatToIntBits(getDefaultReturnValue())) { put(key, newValue); return newValue; @@ -223,17 +234,6 @@ public float supplyFloatIfAbsentNonDefault(double key, FloatSupplier valueProvid return value; } - @Override - public float computeFloatIfPresent(double key, DoubleFloatUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(containsKey(key)) { - float newValue = mappingFunction.applyAsFloat(key, get(key)); - put(key, newValue); - return newValue; - } - return getDefaultReturnValue(); - } - @Override public float computeFloatIfPresentNonDefault(double key, DoubleFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/doubles/maps/abstracts/AbstractDouble2IntMap.java b/src/main/java/speiger/src/collections/doubles/maps/abstracts/AbstractDouble2IntMap.java index 6af63705..944e1211 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/abstracts/AbstractDouble2IntMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/abstracts/AbstractDouble2IntMap.java @@ -157,6 +157,39 @@ public int computeInt(double key, DoubleIntUnaryOperator mappingFunction) { return newValue; } + @Override + public int computeIntIfAbsent(double key, Double2IntFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(!containsKey(key)) { + int newValue = mappingFunction.applyAsInt(key); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public int supplyIntIfAbsent(double key, IntSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + if(!containsKey(key)) { + int newValue = valueProvider.getAsInt(); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public int computeIntIfPresent(double key, DoubleIntUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(containsKey(key)) { + int newValue = mappingFunction.applyAsInt(key, get(key)); + put(key, newValue); + return newValue; + } + return getDefaultReturnValue(); + } + @Override public int computeIntNonDefault(double key, DoubleIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -173,17 +206,6 @@ public int computeIntNonDefault(double key, DoubleIntUnaryOperator mappingFuncti return newValue; } - @Override - public int computeIntIfAbsent(double key, Double2IntFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(!containsKey(key)) { - int newValue = mappingFunction.applyAsInt(key); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public int computeIntIfAbsentNonDefault(double key, Double2IntFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -198,17 +220,6 @@ public int computeIntIfAbsentNonDefault(double key, Double2IntFunction mappingFu return value; } - @Override - public int supplyIntIfAbsent(double key, IntSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - if(!containsKey(key)) { - int newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public int supplyIntIfAbsentNonDefault(double key, IntSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -223,17 +234,6 @@ public int supplyIntIfAbsentNonDefault(double key, IntSupplier valueProvider) { return value; } - @Override - public int computeIntIfPresent(double key, DoubleIntUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(containsKey(key)) { - int newValue = mappingFunction.applyAsInt(key, get(key)); - put(key, newValue); - return newValue; - } - return getDefaultReturnValue(); - } - @Override public int computeIntIfPresentNonDefault(double key, DoubleIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/doubles/maps/abstracts/AbstractDouble2LongMap.java b/src/main/java/speiger/src/collections/doubles/maps/abstracts/AbstractDouble2LongMap.java index 78252513..abdbc5ee 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/abstracts/AbstractDouble2LongMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/abstracts/AbstractDouble2LongMap.java @@ -157,6 +157,39 @@ public long computeLong(double key, DoubleLongUnaryOperator mappingFunction) { return newValue; } + @Override + public long computeLongIfAbsent(double key, Double2LongFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(!containsKey(key)) { + long newValue = mappingFunction.applyAsLong(key); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public long supplyLongIfAbsent(double key, LongSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + if(!containsKey(key)) { + long newValue = valueProvider.getAsLong(); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public long computeLongIfPresent(double key, DoubleLongUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(containsKey(key)) { + long newValue = mappingFunction.applyAsLong(key, get(key)); + put(key, newValue); + return newValue; + } + return getDefaultReturnValue(); + } + @Override public long computeLongNonDefault(double key, DoubleLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -173,17 +206,6 @@ public long computeLongNonDefault(double key, DoubleLongUnaryOperator mappingFun return newValue; } - @Override - public long computeLongIfAbsent(double key, Double2LongFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(!containsKey(key)) { - long newValue = mappingFunction.applyAsLong(key); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public long computeLongIfAbsentNonDefault(double key, Double2LongFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -198,17 +220,6 @@ public long computeLongIfAbsentNonDefault(double key, Double2LongFunction mappin return value; } - @Override - public long supplyLongIfAbsent(double key, LongSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - if(!containsKey(key)) { - long newValue = valueProvider.getAsLong(); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public long supplyLongIfAbsentNonDefault(double key, LongSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -223,17 +234,6 @@ public long supplyLongIfAbsentNonDefault(double key, LongSupplier valueProvider) return value; } - @Override - public long computeLongIfPresent(double key, DoubleLongUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(containsKey(key)) { - long newValue = mappingFunction.applyAsLong(key, get(key)); - put(key, newValue); - return newValue; - } - return getDefaultReturnValue(); - } - @Override public long computeLongIfPresentNonDefault(double key, DoubleLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/doubles/maps/abstracts/AbstractDouble2ObjectMap.java b/src/main/java/speiger/src/collections/doubles/maps/abstracts/AbstractDouble2ObjectMap.java index 9265ea0e..7cc1df02 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/abstracts/AbstractDouble2ObjectMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/abstracts/AbstractDouble2ObjectMap.java @@ -159,22 +159,6 @@ public V compute(double key, DoubleObjectUnaryOperator mappingFunction) { return newValue; } - @Override - public V computeNonDefault(double key, DoubleObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - V value = get(key); - V newValue = mappingFunction.apply(key, value); - if(Objects.equals(newValue, getDefaultReturnValue())) { - if(!Objects.equals(value, getDefaultReturnValue()) || containsKey(key)) { - remove(key); - return getDefaultReturnValue(); - } - return getDefaultReturnValue(); - } - put(key, newValue); - return newValue; - } - @Override public V computeIfAbsent(double key, DoubleFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -189,20 +173,6 @@ public V computeIfAbsent(double key, DoubleFunction mappingFunction) { return value; } - @Override - public V computeIfAbsentNonDefault(double key, DoubleFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - V value; - if((value = get(key)) == getDefaultReturnValue() || !containsKey(key)) { - V newValue = mappingFunction.apply(key); - if(!Objects.equals(newValue, getDefaultReturnValue())) { - put(key, newValue); - return newValue; - } - } - return value; - } - @Override public V supplyIfAbsent(double key, ObjectSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -217,20 +187,6 @@ public V supplyIfAbsent(double key, ObjectSupplier valueProvider) { return value; } - @Override - public V supplyIfAbsentNonDefault(double key, ObjectSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - V value; - if((value = get(key)) == getDefaultReturnValue() || !containsKey(key)) { - V newValue = valueProvider.get(); - if(!Objects.equals(newValue, getDefaultReturnValue())) { - put(key, newValue); - return newValue; - } - } - return value; - } - @Override public V computeIfPresent(double key, DoubleObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -246,21 +202,6 @@ public V computeIfPresent(double key, DoubleObjectUnaryOperator mappingFuncti return getDefaultReturnValue(); } - @Override - public V computeIfPresentNonDefault(double key, DoubleObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - V value; - if(!Objects.equals((value = get(key)), getDefaultReturnValue()) || containsKey(key)) { - V newValue = mappingFunction.apply(key, value); - if(!Objects.equals(newValue, getDefaultReturnValue())) { - put(key, newValue); - return newValue; - } - remove(key); - } - return getDefaultReturnValue(); - } - @Override public V merge(double key, V value, ObjectObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/doubles/maps/abstracts/AbstractDouble2ShortMap.java b/src/main/java/speiger/src/collections/doubles/maps/abstracts/AbstractDouble2ShortMap.java index 51d25858..7aa3bb78 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/abstracts/AbstractDouble2ShortMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/abstracts/AbstractDouble2ShortMap.java @@ -157,6 +157,39 @@ public short computeShort(double key, DoubleShortUnaryOperator mappingFunction) return newValue; } + @Override + public short computeShortIfAbsent(double key, Double2ShortFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(!containsKey(key)) { + short newValue = mappingFunction.applyAsShort(key); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public short supplyShortIfAbsent(double key, ShortSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + if(!containsKey(key)) { + short newValue = valueProvider.getAsShort(); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public short computeShortIfPresent(double key, DoubleShortUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(containsKey(key)) { + short newValue = mappingFunction.applyAsShort(key, get(key)); + put(key, newValue); + return newValue; + } + return getDefaultReturnValue(); + } + @Override public short computeShortNonDefault(double key, DoubleShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -173,17 +206,6 @@ public short computeShortNonDefault(double key, DoubleShortUnaryOperator mapping return newValue; } - @Override - public short computeShortIfAbsent(double key, Double2ShortFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(!containsKey(key)) { - short newValue = mappingFunction.applyAsShort(key); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public short computeShortIfAbsentNonDefault(double key, Double2ShortFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -198,23 +220,12 @@ public short computeShortIfAbsentNonDefault(double key, Double2ShortFunction map return value; } - @Override - public short supplyShortIfAbsent(double key, ShortSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - if(!containsKey(key)) { - short newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public short supplyShortIfAbsentNonDefault(double key, ShortSupplier valueProvider) { Objects.requireNonNull(valueProvider); short value; if((value = get(key)) == getDefaultReturnValue() || !containsKey(key)) { - short newValue = valueProvider.getAsInt(); + short newValue = valueProvider.getAsShort(); if(newValue != getDefaultReturnValue()) { put(key, newValue); return newValue; @@ -223,17 +234,6 @@ public short supplyShortIfAbsentNonDefault(double key, ShortSupplier valueProvid return value; } - @Override - public short computeShortIfPresent(double key, DoubleShortUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(containsKey(key)) { - short newValue = mappingFunction.applyAsShort(key, get(key)); - put(key, newValue); - return newValue; - } - return getDefaultReturnValue(); - } - @Override public short computeShortIfPresentNonDefault(double key, DoubleShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/concurrent/Double2BooleanConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/concurrent/Double2BooleanConcurrentOpenHashMap.java index 941cc284..06286dcc 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/concurrent/Double2BooleanConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/concurrent/Double2BooleanConcurrentOpenHashMap.java @@ -438,13 +438,6 @@ public boolean computeBoolean(double key, DoubleBooleanUnaryOperator mappingFunc return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public boolean computeBooleanNonDefault(double key, DoubleBooleanUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public boolean computeBooleanIfAbsent(double key, DoublePredicate mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -452,13 +445,6 @@ public boolean computeBooleanIfAbsent(double key, DoublePredicate mappingFunctio return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public boolean computeBooleanIfAbsentNonDefault(double key, DoublePredicate mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public boolean supplyBooleanIfAbsent(double key, BooleanSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -467,17 +453,31 @@ public boolean supplyBooleanIfAbsent(double key, BooleanSupplier valueProvider) } @Override - public boolean supplyBooleanIfAbsentNonDefault(double key, BooleanSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public boolean computeBooleanIfPresent(double key, DoubleBooleanUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); + return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } @Override - public boolean computeBooleanIfPresent(double key, DoubleBooleanUnaryOperator mappingFunction) { + public boolean computeBooleanNonDefault(double key, DoubleBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).computeIfPresent(hash, key, mappingFunction); + return getSegment(hash).computeNonDefault(hash, key, mappingFunction); + } + + @Override + public boolean computeBooleanIfAbsentNonDefault(double key, DoublePredicate mappingFunction) { + Objects.requireNonNull(mappingFunction); + int hash = getHashCode(key); + return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); + } + + @Override + public boolean supplyBooleanIfAbsentNonDefault(double key, BooleanSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + int hash = getHashCode(key); + return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); } @Override @@ -2032,35 +2032,29 @@ protected boolean compute(int hash, double key, DoubleBooleanUnaryOperator mappi } } - protected boolean computeNonDefault(int hash, double key, DoubleBooleanUnaryOperator mappingFunction) { + protected boolean computeIfAbsent(int hash, double key, DoublePredicate mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + boolean newValue = mappingFunction.test(key); insert(-index-1, key, newValue); return newValue; } - boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + boolean newValue = values[index]; return newValue; } finally { unlockWrite(stamp); } } - - protected boolean computeIfAbsent(int hash, double key, DoublePredicate mappingFunction) { + + protected boolean supplyIfAbsent(int hash, double key, BooleanSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - boolean newValue = mappingFunction.test(key); + boolean newValue = valueProvider.getAsBoolean(); insert(-index-1, key, newValue); return newValue; } @@ -2071,23 +2065,37 @@ protected boolean computeIfAbsent(int hash, double key, DoublePredicate mappingF unlockWrite(stamp); } } + + protected boolean computeIfPresent(int hash, double key, DoubleBooleanUnaryOperator mappingFunction) { + long stamp = writeLock(); + try { + int index = findIndex(hash, key); + if(index < 0) return getDefaultReturnValue(); + boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); + values[index] = newValue; + return newValue; + } + finally { + unlockWrite(stamp); + } + } - protected boolean computeIfAbsentNonDefault(int hash, double key, DoublePredicate mappingFunction) { + protected boolean computeNonDefault(int hash, double key, DoubleBooleanUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - boolean newValue = mappingFunction.test(key); + boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - boolean newValue = values[index]; + boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.test(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } finally { @@ -2095,16 +2103,22 @@ protected boolean computeIfAbsentNonDefault(int hash, double key, DoublePredicat } } - protected boolean supplyIfAbsent(int hash, double key, BooleanSupplier valueProvider) { + protected boolean computeIfAbsentNonDefault(int hash, double key, DoublePredicate mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - boolean newValue = valueProvider.getAsBoolean(); + boolean newValue = mappingFunction.test(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } boolean newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.test(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } finally { @@ -2135,20 +2149,6 @@ protected boolean supplyIfAbsentNonDefault(int hash, double key, BooleanSupplier } } - protected boolean computeIfPresent(int hash, double key, DoubleBooleanUnaryOperator mappingFunction) { - long stamp = writeLock(); - try { - int index = findIndex(hash, key); - if(index < 0) return getDefaultReturnValue(); - boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); - values[index] = newValue; - return newValue; - } - finally { - unlockWrite(stamp); - } - } - protected boolean computeIfPresentNonDefault(int hash, double key, DoubleBooleanUnaryOperator mappingFunction) { long stamp = writeLock(); try { diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/concurrent/Double2ByteConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/concurrent/Double2ByteConcurrentOpenHashMap.java index 54cae6fe..cff0945c 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/concurrent/Double2ByteConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/concurrent/Double2ByteConcurrentOpenHashMap.java @@ -451,13 +451,6 @@ public byte computeByte(double key, DoubleByteUnaryOperator mappingFunction) { return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public byte computeByteNonDefault(double key, DoubleByteUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public byte computeByteIfAbsent(double key, Double2ByteFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -465,13 +458,6 @@ public byte computeByteIfAbsent(double key, Double2ByteFunction mappingFunction) return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public byte computeByteIfAbsentNonDefault(double key, Double2ByteFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public byte supplyByteIfAbsent(double key, ByteSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -480,17 +466,31 @@ public byte supplyByteIfAbsent(double key, ByteSupplier valueProvider) { } @Override - public byte supplyByteIfAbsentNonDefault(double key, ByteSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public byte computeByteIfPresent(double key, DoubleByteUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); + return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } @Override - public byte computeByteIfPresent(double key, DoubleByteUnaryOperator mappingFunction) { + public byte computeByteNonDefault(double key, DoubleByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).computeIfPresent(hash, key, mappingFunction); + return getSegment(hash).computeNonDefault(hash, key, mappingFunction); + } + + @Override + public byte computeByteIfAbsentNonDefault(double key, Double2ByteFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + int hash = getHashCode(key); + return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); + } + + @Override + public byte supplyByteIfAbsentNonDefault(double key, ByteSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + int hash = getHashCode(key); + return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); } @Override @@ -2076,35 +2076,29 @@ protected byte compute(int hash, double key, DoubleByteUnaryOperator mappingFunc } } - protected byte computeNonDefault(int hash, double key, DoubleByteUnaryOperator mappingFunction) { + protected byte computeIfAbsent(int hash, double key, Double2ByteFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + byte newValue = mappingFunction.applyAsByte(key); insert(-index-1, key, newValue); return newValue; } - byte newValue = mappingFunction.applyAsByte(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + byte newValue = values[index]; return newValue; } finally { unlockWrite(stamp); } } - - protected byte computeIfAbsent(int hash, double key, Double2ByteFunction mappingFunction) { + + protected byte supplyIfAbsent(int hash, double key, ByteSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = valueProvider.getAsByte(); insert(-index-1, key, newValue); return newValue; } @@ -2115,23 +2109,14 @@ protected byte computeIfAbsent(int hash, double key, Double2ByteFunction mapping unlockWrite(stamp); } } - - protected byte computeIfAbsentNonDefault(int hash, double key, Double2ByteFunction mappingFunction) { + + protected byte computeIfPresent(int hash, double key, DoubleByteUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key); - if(newValue == getDefaultReturnValue()) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - byte newValue = values[index]; - if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsByte(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; - } + if(index < 0) return getDefaultReturnValue(); + byte newValue = mappingFunction.applyAsByte(key, values[index]); + values[index] = newValue; return newValue; } finally { @@ -2139,16 +2124,22 @@ protected byte computeIfAbsentNonDefault(int hash, double key, Double2ByteFuncti } } - protected byte supplyIfAbsent(int hash, double key, ByteSupplier valueProvider) { + protected byte computeNonDefault(int hash, double key, DoubleByteUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - byte newValue = valueProvider.getAsInt(); + byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - byte newValue = values[index]; + byte newValue = mappingFunction.applyAsByte(key, values[index]); + if(newValue == getDefaultReturnValue()) { + removeIndex(index); + return newValue; + } + values[index] = newValue; return newValue; } finally { @@ -2156,19 +2147,19 @@ protected byte supplyIfAbsent(int hash, double key, ByteSupplier valueProvider) } } - protected byte supplyIfAbsentNonDefault(int hash, double key, ByteSupplier valueProvider) { + protected byte computeIfAbsentNonDefault(int hash, double key, Double2ByteFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - byte newValue = valueProvider.getAsInt(); + byte newValue = mappingFunction.applyAsByte(key); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } byte newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = mappingFunction.applyAsByte(key); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } @@ -2179,13 +2170,22 @@ protected byte supplyIfAbsentNonDefault(int hash, double key, ByteSupplier value } } - protected byte computeIfPresent(int hash, double key, DoubleByteUnaryOperator mappingFunction) { + protected byte supplyIfAbsentNonDefault(int hash, double key, ByteSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0) return getDefaultReturnValue(); - byte newValue = mappingFunction.applyAsByte(key, values[index]); - values[index] = newValue; + if(index < 0) { + byte newValue = valueProvider.getAsByte(); + if(newValue == getDefaultReturnValue()) return newValue; + insert(-index-1, key, newValue); + return newValue; + } + byte newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = valueProvider.getAsByte(); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } finally { diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/concurrent/Double2CharConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/concurrent/Double2CharConcurrentOpenHashMap.java index 198ea3e4..bd56d344 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/concurrent/Double2CharConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/concurrent/Double2CharConcurrentOpenHashMap.java @@ -451,13 +451,6 @@ public char computeChar(double key, DoubleCharUnaryOperator mappingFunction) { return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public char computeCharNonDefault(double key, DoubleCharUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public char computeCharIfAbsent(double key, Double2CharFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -465,13 +458,6 @@ public char computeCharIfAbsent(double key, Double2CharFunction mappingFunction) return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public char computeCharIfAbsentNonDefault(double key, Double2CharFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public char supplyCharIfAbsent(double key, CharSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -480,17 +466,31 @@ public char supplyCharIfAbsent(double key, CharSupplier valueProvider) { } @Override - public char supplyCharIfAbsentNonDefault(double key, CharSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public char computeCharIfPresent(double key, DoubleCharUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); + return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } @Override - public char computeCharIfPresent(double key, DoubleCharUnaryOperator mappingFunction) { + public char computeCharNonDefault(double key, DoubleCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).computeIfPresent(hash, key, mappingFunction); + return getSegment(hash).computeNonDefault(hash, key, mappingFunction); + } + + @Override + public char computeCharIfAbsentNonDefault(double key, Double2CharFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + int hash = getHashCode(key); + return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); + } + + @Override + public char supplyCharIfAbsentNonDefault(double key, CharSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + int hash = getHashCode(key); + return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); } @Override @@ -2076,35 +2076,29 @@ protected char compute(int hash, double key, DoubleCharUnaryOperator mappingFunc } } - protected char computeNonDefault(int hash, double key, DoubleCharUnaryOperator mappingFunction) { + protected char computeIfAbsent(int hash, double key, Double2CharFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + char newValue = mappingFunction.applyAsChar(key); insert(-index-1, key, newValue); return newValue; } - char newValue = mappingFunction.applyAsChar(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + char newValue = values[index]; return newValue; } finally { unlockWrite(stamp); } } - - protected char computeIfAbsent(int hash, double key, Double2CharFunction mappingFunction) { + + protected char supplyIfAbsent(int hash, double key, CharSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = valueProvider.getAsChar(); insert(-index-1, key, newValue); return newValue; } @@ -2115,23 +2109,14 @@ protected char computeIfAbsent(int hash, double key, Double2CharFunction mapping unlockWrite(stamp); } } - - protected char computeIfAbsentNonDefault(int hash, double key, Double2CharFunction mappingFunction) { + + protected char computeIfPresent(int hash, double key, DoubleCharUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0) { - char newValue = mappingFunction.applyAsChar(key); - if(newValue == getDefaultReturnValue()) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - char newValue = values[index]; - if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsChar(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; - } + if(index < 0) return getDefaultReturnValue(); + char newValue = mappingFunction.applyAsChar(key, values[index]); + values[index] = newValue; return newValue; } finally { @@ -2139,16 +2124,22 @@ protected char computeIfAbsentNonDefault(int hash, double key, Double2CharFuncti } } - protected char supplyIfAbsent(int hash, double key, CharSupplier valueProvider) { + protected char computeNonDefault(int hash, double key, DoubleCharUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - char newValue = valueProvider.getAsInt(); + char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - char newValue = values[index]; + char newValue = mappingFunction.applyAsChar(key, values[index]); + if(newValue == getDefaultReturnValue()) { + removeIndex(index); + return newValue; + } + values[index] = newValue; return newValue; } finally { @@ -2156,19 +2147,19 @@ protected char supplyIfAbsent(int hash, double key, CharSupplier valueProvider) } } - protected char supplyIfAbsentNonDefault(int hash, double key, CharSupplier valueProvider) { + protected char computeIfAbsentNonDefault(int hash, double key, Double2CharFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - char newValue = valueProvider.getAsInt(); + char newValue = mappingFunction.applyAsChar(key); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } char newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = mappingFunction.applyAsChar(key); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } @@ -2179,13 +2170,22 @@ protected char supplyIfAbsentNonDefault(int hash, double key, CharSupplier value } } - protected char computeIfPresent(int hash, double key, DoubleCharUnaryOperator mappingFunction) { + protected char supplyIfAbsentNonDefault(int hash, double key, CharSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0) return getDefaultReturnValue(); - char newValue = mappingFunction.applyAsChar(key, values[index]); - values[index] = newValue; + if(index < 0) { + char newValue = valueProvider.getAsChar(); + if(newValue == getDefaultReturnValue()) return newValue; + insert(-index-1, key, newValue); + return newValue; + } + char newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = valueProvider.getAsChar(); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } finally { diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/concurrent/Double2DoubleConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/concurrent/Double2DoubleConcurrentOpenHashMap.java index d5d5ad06..b9b91f4e 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/concurrent/Double2DoubleConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/concurrent/Double2DoubleConcurrentOpenHashMap.java @@ -444,13 +444,6 @@ public double computeDouble(double key, DoubleDoubleUnaryOperator mappingFunctio return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public double computeDoubleNonDefault(double key, DoubleDoubleUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public double computeDoubleIfAbsent(double key, DoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -458,13 +451,6 @@ public double computeDoubleIfAbsent(double key, DoubleUnaryOperator mappingFunct return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public double computeDoubleIfAbsentNonDefault(double key, DoubleUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public double supplyDoubleIfAbsent(double key, DoubleSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -473,17 +459,31 @@ public double supplyDoubleIfAbsent(double key, DoubleSupplier valueProvider) { } @Override - public double supplyDoubleIfAbsentNonDefault(double key, DoubleSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public double computeDoubleIfPresent(double key, DoubleDoubleUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); + return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } @Override - public double computeDoubleIfPresent(double key, DoubleDoubleUnaryOperator mappingFunction) { + public double computeDoubleNonDefault(double key, DoubleDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).computeIfPresent(hash, key, mappingFunction); + return getSegment(hash).computeNonDefault(hash, key, mappingFunction); + } + + @Override + public double computeDoubleIfAbsentNonDefault(double key, DoubleUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int hash = getHashCode(key); + return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); + } + + @Override + public double supplyDoubleIfAbsentNonDefault(double key, DoubleSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + int hash = getHashCode(key); + return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); } @Override @@ -2069,35 +2069,29 @@ protected double compute(int hash, double key, DoubleDoubleUnaryOperator mapping } } - protected double computeNonDefault(int hash, double key, DoubleDoubleUnaryOperator mappingFunction) { + protected double computeIfAbsent(int hash, double key, DoubleUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + double newValue = mappingFunction.applyAsDouble(key); insert(-index-1, key, newValue); return newValue; } - double newValue = mappingFunction.applyAsDouble(key, values[index]); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + double newValue = values[index]; return newValue; } finally { unlockWrite(stamp); } } - - protected double computeIfAbsent(int hash, double key, DoubleUnaryOperator mappingFunction) { + + protected double supplyIfAbsent(int hash, double key, DoubleSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = valueProvider.getAsDouble(); insert(-index-1, key, newValue); return newValue; } @@ -2108,23 +2102,37 @@ protected double computeIfAbsent(int hash, double key, DoubleUnaryOperator mappi unlockWrite(stamp); } } + + protected double computeIfPresent(int hash, double key, DoubleDoubleUnaryOperator mappingFunction) { + long stamp = writeLock(); + try { + int index = findIndex(hash, key); + if(index < 0) return getDefaultReturnValue(); + double newValue = mappingFunction.applyAsDouble(key, values[index]); + values[index] = newValue; + return newValue; + } + finally { + unlockWrite(stamp); + } + } - protected double computeIfAbsentNonDefault(int hash, double key, DoubleUnaryOperator mappingFunction) { + protected double computeNonDefault(int hash, double key, DoubleDoubleUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } - double newValue = values[index]; + double newValue = mappingFunction.applyAsDouble(key, values[index]); if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - newValue = mappingFunction.applyAsDouble(key); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } finally { @@ -2132,16 +2140,22 @@ protected double computeIfAbsentNonDefault(int hash, double key, DoubleUnaryOper } } - protected double supplyIfAbsent(int hash, double key, DoubleSupplier valueProvider) { + protected double computeIfAbsentNonDefault(int hash, double key, DoubleUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - double newValue = valueProvider.getAsDouble(); + double newValue = mappingFunction.applyAsDouble(key); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } double newValue = values[index]; + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { + newValue = mappingFunction.applyAsDouble(key); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + values[index] = newValue; + } return newValue; } finally { @@ -2172,20 +2186,6 @@ protected double supplyIfAbsentNonDefault(int hash, double key, DoubleSupplier v } } - protected double computeIfPresent(int hash, double key, DoubleDoubleUnaryOperator mappingFunction) { - long stamp = writeLock(); - try { - int index = findIndex(hash, key); - if(index < 0) return getDefaultReturnValue(); - double newValue = mappingFunction.applyAsDouble(key, values[index]); - values[index] = newValue; - return newValue; - } - finally { - unlockWrite(stamp); - } - } - protected double computeIfPresentNonDefault(int hash, double key, DoubleDoubleUnaryOperator mappingFunction) { long stamp = writeLock(); try { diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/concurrent/Double2FloatConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/concurrent/Double2FloatConcurrentOpenHashMap.java index aa37c306..d3d912ed 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/concurrent/Double2FloatConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/concurrent/Double2FloatConcurrentOpenHashMap.java @@ -451,13 +451,6 @@ public float computeFloat(double key, DoubleFloatUnaryOperator mappingFunction) return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public float computeFloatNonDefault(double key, DoubleFloatUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public float computeFloatIfAbsent(double key, Double2FloatFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -465,13 +458,6 @@ public float computeFloatIfAbsent(double key, Double2FloatFunction mappingFuncti return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public float computeFloatIfAbsentNonDefault(double key, Double2FloatFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public float supplyFloatIfAbsent(double key, FloatSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -480,17 +466,31 @@ public float supplyFloatIfAbsent(double key, FloatSupplier valueProvider) { } @Override - public float supplyFloatIfAbsentNonDefault(double key, FloatSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public float computeFloatIfPresent(double key, DoubleFloatUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); + return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } @Override - public float computeFloatIfPresent(double key, DoubleFloatUnaryOperator mappingFunction) { + public float computeFloatNonDefault(double key, DoubleFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).computeIfPresent(hash, key, mappingFunction); + return getSegment(hash).computeNonDefault(hash, key, mappingFunction); + } + + @Override + public float computeFloatIfAbsentNonDefault(double key, Double2FloatFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + int hash = getHashCode(key); + return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); + } + + @Override + public float supplyFloatIfAbsentNonDefault(double key, FloatSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + int hash = getHashCode(key); + return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); } @Override @@ -2076,35 +2076,29 @@ protected float compute(int hash, double key, DoubleFloatUnaryOperator mappingFu } } - protected float computeNonDefault(int hash, double key, DoubleFloatUnaryOperator mappingFunction) { + protected float computeIfAbsent(int hash, double key, Double2FloatFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + float newValue = mappingFunction.applyAsFloat(key); insert(-index-1, key, newValue); return newValue; } - float newValue = mappingFunction.applyAsFloat(key, values[index]); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + float newValue = values[index]; return newValue; } finally { unlockWrite(stamp); } } - - protected float computeIfAbsent(int hash, double key, Double2FloatFunction mappingFunction) { + + protected float supplyIfAbsent(int hash, double key, FloatSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = valueProvider.getAsFloat(); insert(-index-1, key, newValue); return newValue; } @@ -2115,23 +2109,14 @@ protected float computeIfAbsent(int hash, double key, Double2FloatFunction mappi unlockWrite(stamp); } } - - protected float computeIfAbsentNonDefault(int hash, double key, Double2FloatFunction mappingFunction) { + + protected float computeIfPresent(int hash, double key, DoubleFloatUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - float newValue = values[index]; - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - newValue = mappingFunction.applyAsFloat(key); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; - values[index] = newValue; - } + if(index < 0) return getDefaultReturnValue(); + float newValue = mappingFunction.applyAsFloat(key, values[index]); + values[index] = newValue; return newValue; } finally { @@ -2139,16 +2124,22 @@ protected float computeIfAbsentNonDefault(int hash, double key, Double2FloatFunc } } - protected float supplyIfAbsent(int hash, double key, FloatSupplier valueProvider) { + protected float computeNonDefault(int hash, double key, DoubleFloatUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - float newValue = valueProvider.getAsDouble(); + float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } - float newValue = values[index]; + float newValue = mappingFunction.applyAsFloat(key, values[index]); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { + removeIndex(index); + return newValue; + } + values[index] = newValue; return newValue; } finally { @@ -2156,19 +2147,19 @@ protected float supplyIfAbsent(int hash, double key, FloatSupplier valueProvider } } - protected float supplyIfAbsentNonDefault(int hash, double key, FloatSupplier valueProvider) { + protected float computeIfAbsentNonDefault(int hash, double key, Double2FloatFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - float newValue = valueProvider.getAsDouble(); + float newValue = mappingFunction.applyAsFloat(key); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } float newValue = values[index]; if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - newValue = valueProvider.getAsDouble(); + newValue = mappingFunction.applyAsFloat(key); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; values[index] = newValue; } @@ -2179,13 +2170,22 @@ protected float supplyIfAbsentNonDefault(int hash, double key, FloatSupplier val } } - protected float computeIfPresent(int hash, double key, DoubleFloatUnaryOperator mappingFunction) { + protected float supplyIfAbsentNonDefault(int hash, double key, FloatSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0) return getDefaultReturnValue(); - float newValue = mappingFunction.applyAsFloat(key, values[index]); - values[index] = newValue; + if(index < 0) { + float newValue = valueProvider.getAsFloat(); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + insert(-index-1, key, newValue); + return newValue; + } + float newValue = values[index]; + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { + newValue = valueProvider.getAsFloat(); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + values[index] = newValue; + } return newValue; } finally { diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/concurrent/Double2IntConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/concurrent/Double2IntConcurrentOpenHashMap.java index 6281ac69..33c3b4af 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/concurrent/Double2IntConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/concurrent/Double2IntConcurrentOpenHashMap.java @@ -451,13 +451,6 @@ public int computeInt(double key, DoubleIntUnaryOperator mappingFunction) { return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public int computeIntNonDefault(double key, DoubleIntUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public int computeIntIfAbsent(double key, Double2IntFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -465,13 +458,6 @@ public int computeIntIfAbsent(double key, Double2IntFunction mappingFunction) { return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public int computeIntIfAbsentNonDefault(double key, Double2IntFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public int supplyIntIfAbsent(double key, IntSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -480,17 +466,31 @@ public int supplyIntIfAbsent(double key, IntSupplier valueProvider) { } @Override - public int supplyIntIfAbsentNonDefault(double key, IntSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public int computeIntIfPresent(double key, DoubleIntUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); + return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } @Override - public int computeIntIfPresent(double key, DoubleIntUnaryOperator mappingFunction) { + public int computeIntNonDefault(double key, DoubleIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).computeIfPresent(hash, key, mappingFunction); + return getSegment(hash).computeNonDefault(hash, key, mappingFunction); + } + + @Override + public int computeIntIfAbsentNonDefault(double key, Double2IntFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + int hash = getHashCode(key); + return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); + } + + @Override + public int supplyIntIfAbsentNonDefault(double key, IntSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + int hash = getHashCode(key); + return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); } @Override @@ -2076,35 +2076,29 @@ protected int compute(int hash, double key, DoubleIntUnaryOperator mappingFuncti } } - protected int computeNonDefault(int hash, double key, DoubleIntUnaryOperator mappingFunction) { + protected int computeIfAbsent(int hash, double key, Double2IntFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + int newValue = mappingFunction.applyAsInt(key); insert(-index-1, key, newValue); return newValue; } - int newValue = mappingFunction.applyAsInt(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + int newValue = values[index]; return newValue; } finally { unlockWrite(stamp); } } - - protected int computeIfAbsent(int hash, double key, Double2IntFunction mappingFunction) { + + protected int supplyIfAbsent(int hash, double key, IntSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = valueProvider.getAsInt(); insert(-index-1, key, newValue); return newValue; } @@ -2115,23 +2109,37 @@ protected int computeIfAbsent(int hash, double key, Double2IntFunction mappingFu unlockWrite(stamp); } } + + protected int computeIfPresent(int hash, double key, DoubleIntUnaryOperator mappingFunction) { + long stamp = writeLock(); + try { + int index = findIndex(hash, key); + if(index < 0) return getDefaultReturnValue(); + int newValue = mappingFunction.applyAsInt(key, values[index]); + values[index] = newValue; + return newValue; + } + finally { + unlockWrite(stamp); + } + } - protected int computeIfAbsentNonDefault(int hash, double key, Double2IntFunction mappingFunction) { + protected int computeNonDefault(int hash, double key, DoubleIntUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - int newValue = values[index]; + int newValue = mappingFunction.applyAsInt(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsInt(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } finally { @@ -2139,16 +2147,22 @@ protected int computeIfAbsentNonDefault(int hash, double key, Double2IntFunction } } - protected int supplyIfAbsent(int hash, double key, IntSupplier valueProvider) { + protected int computeIfAbsentNonDefault(int hash, double key, Double2IntFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - int newValue = valueProvider.getAsInt(); + int newValue = mappingFunction.applyAsInt(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } int newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsInt(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } finally { @@ -2179,20 +2193,6 @@ protected int supplyIfAbsentNonDefault(int hash, double key, IntSupplier valuePr } } - protected int computeIfPresent(int hash, double key, DoubleIntUnaryOperator mappingFunction) { - long stamp = writeLock(); - try { - int index = findIndex(hash, key); - if(index < 0) return getDefaultReturnValue(); - int newValue = mappingFunction.applyAsInt(key, values[index]); - values[index] = newValue; - return newValue; - } - finally { - unlockWrite(stamp); - } - } - protected int computeIfPresentNonDefault(int hash, double key, DoubleIntUnaryOperator mappingFunction) { long stamp = writeLock(); try { diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/concurrent/Double2LongConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/concurrent/Double2LongConcurrentOpenHashMap.java index 7d2cb494..cd7442fe 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/concurrent/Double2LongConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/concurrent/Double2LongConcurrentOpenHashMap.java @@ -451,13 +451,6 @@ public long computeLong(double key, DoubleLongUnaryOperator mappingFunction) { return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public long computeLongNonDefault(double key, DoubleLongUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public long computeLongIfAbsent(double key, Double2LongFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -465,13 +458,6 @@ public long computeLongIfAbsent(double key, Double2LongFunction mappingFunction) return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public long computeLongIfAbsentNonDefault(double key, Double2LongFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public long supplyLongIfAbsent(double key, LongSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -480,17 +466,31 @@ public long supplyLongIfAbsent(double key, LongSupplier valueProvider) { } @Override - public long supplyLongIfAbsentNonDefault(double key, LongSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public long computeLongIfPresent(double key, DoubleLongUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); + return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } @Override - public long computeLongIfPresent(double key, DoubleLongUnaryOperator mappingFunction) { + public long computeLongNonDefault(double key, DoubleLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).computeIfPresent(hash, key, mappingFunction); + return getSegment(hash).computeNonDefault(hash, key, mappingFunction); + } + + @Override + public long computeLongIfAbsentNonDefault(double key, Double2LongFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + int hash = getHashCode(key); + return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); + } + + @Override + public long supplyLongIfAbsentNonDefault(double key, LongSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + int hash = getHashCode(key); + return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); } @Override @@ -2076,35 +2076,29 @@ protected long compute(int hash, double key, DoubleLongUnaryOperator mappingFunc } } - protected long computeNonDefault(int hash, double key, DoubleLongUnaryOperator mappingFunction) { + protected long computeIfAbsent(int hash, double key, Double2LongFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + long newValue = mappingFunction.applyAsLong(key); insert(-index-1, key, newValue); return newValue; } - long newValue = mappingFunction.applyAsLong(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + long newValue = values[index]; return newValue; } finally { unlockWrite(stamp); } } - - protected long computeIfAbsent(int hash, double key, Double2LongFunction mappingFunction) { + + protected long supplyIfAbsent(int hash, double key, LongSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = valueProvider.getAsLong(); insert(-index-1, key, newValue); return newValue; } @@ -2115,23 +2109,37 @@ protected long computeIfAbsent(int hash, double key, Double2LongFunction mapping unlockWrite(stamp); } } + + protected long computeIfPresent(int hash, double key, DoubleLongUnaryOperator mappingFunction) { + long stamp = writeLock(); + try { + int index = findIndex(hash, key); + if(index < 0) return getDefaultReturnValue(); + long newValue = mappingFunction.applyAsLong(key, values[index]); + values[index] = newValue; + return newValue; + } + finally { + unlockWrite(stamp); + } + } - protected long computeIfAbsentNonDefault(int hash, double key, Double2LongFunction mappingFunction) { + protected long computeNonDefault(int hash, double key, DoubleLongUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - long newValue = values[index]; + long newValue = mappingFunction.applyAsLong(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsLong(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } finally { @@ -2139,16 +2147,22 @@ protected long computeIfAbsentNonDefault(int hash, double key, Double2LongFuncti } } - protected long supplyIfAbsent(int hash, double key, LongSupplier valueProvider) { + protected long computeIfAbsentNonDefault(int hash, double key, Double2LongFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - long newValue = valueProvider.getAsLong(); + long newValue = mappingFunction.applyAsLong(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } long newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsLong(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } finally { @@ -2179,20 +2193,6 @@ protected long supplyIfAbsentNonDefault(int hash, double key, LongSupplier value } } - protected long computeIfPresent(int hash, double key, DoubleLongUnaryOperator mappingFunction) { - long stamp = writeLock(); - try { - int index = findIndex(hash, key); - if(index < 0) return getDefaultReturnValue(); - long newValue = mappingFunction.applyAsLong(key, values[index]); - values[index] = newValue; - return newValue; - } - finally { - unlockWrite(stamp); - } - } - protected long computeIfPresentNonDefault(int hash, double key, DoubleLongUnaryOperator mappingFunction) { long stamp = writeLock(); try { diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/concurrent/Double2ObjectConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/concurrent/Double2ObjectConcurrentOpenHashMap.java index 15a112ac..4beff518 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/concurrent/Double2ObjectConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/concurrent/Double2ObjectConcurrentOpenHashMap.java @@ -426,13 +426,6 @@ public V compute(double key, DoubleObjectUnaryOperator mappingFunction) { return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public V computeNonDefault(double key, DoubleObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public V computeIfAbsent(double key, DoubleFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -440,13 +433,6 @@ public V computeIfAbsent(double key, DoubleFunction mappingFunction) { return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public V computeIfAbsentNonDefault(double key, DoubleFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public V supplyIfAbsent(double key, ObjectSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -454,13 +440,6 @@ public V supplyIfAbsent(double key, ObjectSupplier valueProvider) { return getSegment(hash).supplyIfAbsent(hash, key, valueProvider); } - @Override - public V supplyIfAbsentNonDefault(double key, ObjectSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); - } - @Override public V computeIfPresent(double key, DoubleObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -468,13 +447,6 @@ public V computeIfPresent(double key, DoubleObjectUnaryOperator mappingFuncti return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } - @Override - public V computeIfPresentNonDefault(double key, DoubleObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfPresentNonDefault(hash, key, mappingFunction); - } - @Override public V merge(double key, V value, ObjectObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -2011,29 +1983,6 @@ protected V compute(int hash, double key, DoubleObjectUnaryOperator mappingFu } } - protected V computeNonDefault(int hash, double key, DoubleObjectUnaryOperator mappingFunction) { - long stamp = writeLock(); - try { - int index = findIndex(hash, key); - if(index < 0) { - V newValue = mappingFunction.apply(key, getDefaultReturnValue()); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = mappingFunction.apply(key, values[index]); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; - return newValue; - } - finally { - unlockWrite(stamp); - } - } - protected V computeIfAbsent(int hash, double key, DoubleFunction mappingFunction) { long stamp = writeLock(); try { @@ -2056,30 +2005,7 @@ protected V computeIfAbsent(int hash, double key, DoubleFunction mappingFunct unlockWrite(stamp); } } - - protected V computeIfAbsentNonDefault(int hash, double key, DoubleFunction mappingFunction) { - long stamp = writeLock(); - try { - int index = findIndex(hash, key); - if(index < 0) { - V newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = values[index]; - if(Objects.equals(newValue, getDefaultReturnValue())) { - newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - values[index] = newValue; - } - return newValue; - } - finally { - unlockWrite(stamp); - } - } - + protected V supplyIfAbsent(int hash, double key, ObjectSupplier valueProvider) { long stamp = writeLock(); try { @@ -2102,30 +2028,7 @@ protected V supplyIfAbsent(int hash, double key, ObjectSupplier valueProvider unlockWrite(stamp); } } - - protected V supplyIfAbsentNonDefault(int hash, double key, ObjectSupplier valueProvider) { - long stamp = writeLock(); - try { - int index = findIndex(hash, key); - if(index < 0) { - V newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = values[index]; - if(Objects.equals(newValue, getDefaultReturnValue())) { - newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - values[index] = newValue; - } - return newValue; - } - finally { - unlockWrite(stamp); - } - } - + protected V computeIfPresent(int hash, double key, DoubleObjectUnaryOperator mappingFunction) { long stamp = writeLock(); try { @@ -2144,11 +2047,16 @@ protected V computeIfPresent(int hash, double key, DoubleObjectUnaryOperator } } - protected V computeIfPresentNonDefault(int hash, double key, DoubleObjectUnaryOperator mappingFunction) { + protected V computeNonDefault(int hash, double key, DoubleObjectUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0 || Objects.equals(values[index], getDefaultReturnValue())) return getDefaultReturnValue(); + if(index < 0) { + V newValue = mappingFunction.apply(key, getDefaultReturnValue()); + if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; + insert(-index-1, key, newValue); + return newValue; + } V newValue = mappingFunction.apply(key, values[index]); if(Objects.equals(newValue, getDefaultReturnValue())) { removeIndex(index); diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/concurrent/Double2ShortConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/concurrent/Double2ShortConcurrentOpenHashMap.java index 956bb6e7..745f24f4 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/concurrent/Double2ShortConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/concurrent/Double2ShortConcurrentOpenHashMap.java @@ -451,13 +451,6 @@ public short computeShort(double key, DoubleShortUnaryOperator mappingFunction) return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public short computeShortNonDefault(double key, DoubleShortUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public short computeShortIfAbsent(double key, Double2ShortFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -465,13 +458,6 @@ public short computeShortIfAbsent(double key, Double2ShortFunction mappingFuncti return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public short computeShortIfAbsentNonDefault(double key, Double2ShortFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public short supplyShortIfAbsent(double key, ShortSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -480,17 +466,31 @@ public short supplyShortIfAbsent(double key, ShortSupplier valueProvider) { } @Override - public short supplyShortIfAbsentNonDefault(double key, ShortSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public short computeShortIfPresent(double key, DoubleShortUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); + return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } @Override - public short computeShortIfPresent(double key, DoubleShortUnaryOperator mappingFunction) { + public short computeShortNonDefault(double key, DoubleShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).computeIfPresent(hash, key, mappingFunction); + return getSegment(hash).computeNonDefault(hash, key, mappingFunction); + } + + @Override + public short computeShortIfAbsentNonDefault(double key, Double2ShortFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + int hash = getHashCode(key); + return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); + } + + @Override + public short supplyShortIfAbsentNonDefault(double key, ShortSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + int hash = getHashCode(key); + return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); } @Override @@ -2076,35 +2076,29 @@ protected short compute(int hash, double key, DoubleShortUnaryOperator mappingFu } } - protected short computeNonDefault(int hash, double key, DoubleShortUnaryOperator mappingFunction) { + protected short computeIfAbsent(int hash, double key, Double2ShortFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + short newValue = mappingFunction.applyAsShort(key); insert(-index-1, key, newValue); return newValue; } - short newValue = mappingFunction.applyAsShort(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + short newValue = values[index]; return newValue; } finally { unlockWrite(stamp); } } - - protected short computeIfAbsent(int hash, double key, Double2ShortFunction mappingFunction) { + + protected short supplyIfAbsent(int hash, double key, ShortSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = valueProvider.getAsShort(); insert(-index-1, key, newValue); return newValue; } @@ -2115,23 +2109,14 @@ protected short computeIfAbsent(int hash, double key, Double2ShortFunction mappi unlockWrite(stamp); } } - - protected short computeIfAbsentNonDefault(int hash, double key, Double2ShortFunction mappingFunction) { + + protected short computeIfPresent(int hash, double key, DoubleShortUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0) { - short newValue = mappingFunction.applyAsShort(key); - if(newValue == getDefaultReturnValue()) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - short newValue = values[index]; - if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsShort(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; - } + if(index < 0) return getDefaultReturnValue(); + short newValue = mappingFunction.applyAsShort(key, values[index]); + values[index] = newValue; return newValue; } finally { @@ -2139,16 +2124,22 @@ protected short computeIfAbsentNonDefault(int hash, double key, Double2ShortFunc } } - protected short supplyIfAbsent(int hash, double key, ShortSupplier valueProvider) { + protected short computeNonDefault(int hash, double key, DoubleShortUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - short newValue = valueProvider.getAsInt(); + short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - short newValue = values[index]; + short newValue = mappingFunction.applyAsShort(key, values[index]); + if(newValue == getDefaultReturnValue()) { + removeIndex(index); + return newValue; + } + values[index] = newValue; return newValue; } finally { @@ -2156,19 +2147,19 @@ protected short supplyIfAbsent(int hash, double key, ShortSupplier valueProvider } } - protected short supplyIfAbsentNonDefault(int hash, double key, ShortSupplier valueProvider) { + protected short computeIfAbsentNonDefault(int hash, double key, Double2ShortFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - short newValue = valueProvider.getAsInt(); + short newValue = mappingFunction.applyAsShort(key); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } short newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = mappingFunction.applyAsShort(key); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } @@ -2179,13 +2170,22 @@ protected short supplyIfAbsentNonDefault(int hash, double key, ShortSupplier val } } - protected short computeIfPresent(int hash, double key, DoubleShortUnaryOperator mappingFunction) { + protected short supplyIfAbsentNonDefault(int hash, double key, ShortSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0) return getDefaultReturnValue(); - short newValue = mappingFunction.applyAsShort(key, values[index]); - values[index] = newValue; + if(index < 0) { + short newValue = valueProvider.getAsShort(); + if(newValue == getDefaultReturnValue()) return newValue; + insert(-index-1, key, newValue); + return newValue; + } + short newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = valueProvider.getAsShort(); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } finally { diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2BooleanOpenCustomHashMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2BooleanOpenCustomHashMap.java index 9a8063c1..07cd9644 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2BooleanOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2BooleanOpenCustomHashMap.java @@ -441,30 +441,24 @@ public boolean computeBoolean(double key, DoubleBooleanUnaryOperator mappingFunc } @Override - public boolean computeBooleanNonDefault(double key, DoubleBooleanUnaryOperator mappingFunction) { + public boolean computeBooleanIfAbsent(double key, DoublePredicate mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + boolean newValue = mappingFunction.test(key); insert(-index-1, key, newValue); return newValue; } - boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + boolean newValue = values[index]; return newValue; } - + @Override - public boolean computeBooleanIfAbsent(double key, DoublePredicate mappingFunction) { - Objects.requireNonNull(mappingFunction); + public boolean supplyBooleanIfAbsent(double key, BooleanSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - boolean newValue = mappingFunction.test(key); + boolean newValue = valueProvider.getAsBoolean(); insert(-index-1, key, newValue); return newValue; } @@ -473,34 +467,50 @@ public boolean computeBooleanIfAbsent(double key, DoublePredicate mappingFunctio } @Override - public boolean computeBooleanIfAbsentNonDefault(double key, DoublePredicate mappingFunction) { + public boolean computeBooleanIfPresent(double key, DoubleBooleanUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public boolean computeBooleanNonDefault(double key, DoubleBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - boolean newValue = mappingFunction.test(key); + boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - boolean newValue = values[index]; + boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.test(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public boolean supplyBooleanIfAbsent(double key, BooleanSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public boolean computeBooleanIfAbsentNonDefault(double key, DoublePredicate mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - boolean newValue = valueProvider.getAsBoolean(); + boolean newValue = mappingFunction.test(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } boolean newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.test(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -523,16 +533,6 @@ public boolean supplyBooleanIfAbsentNonDefault(double key, BooleanSupplier value return newValue; } - @Override - public boolean computeBooleanIfPresent(double key, DoubleBooleanUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public boolean computeBooleanIfPresentNonDefault(double key, DoubleBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2ByteOpenCustomHashMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2ByteOpenCustomHashMap.java index 29218b6d..0d94dd4e 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2ByteOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2ByteOpenCustomHashMap.java @@ -463,30 +463,24 @@ public byte computeByte(double key, DoubleByteUnaryOperator mappingFunction) { } @Override - public byte computeByteNonDefault(double key, DoubleByteUnaryOperator mappingFunction) { + public byte computeByteIfAbsent(double key, Double2ByteFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + byte newValue = mappingFunction.applyAsByte(key); insert(-index-1, key, newValue); return newValue; } - byte newValue = mappingFunction.applyAsByte(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + byte newValue = values[index]; return newValue; } - + @Override - public byte computeByteIfAbsent(double key, Double2ByteFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public byte supplyByteIfAbsent(double key, ByteSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = valueProvider.getAsByte(); insert(-index-1, key, newValue); return newValue; } @@ -495,34 +489,50 @@ public byte computeByteIfAbsent(double key, Double2ByteFunction mappingFunction) } @Override - public byte computeByteIfAbsentNonDefault(double key, Double2ByteFunction mappingFunction) { + public byte computeByteIfPresent(double key, DoubleByteUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + byte newValue = mappingFunction.applyAsByte(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public byte computeByteNonDefault(double key, DoubleByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - byte newValue = values[index]; + byte newValue = mappingFunction.applyAsByte(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsByte(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public byte supplyByteIfAbsent(double key, ByteSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public byte computeByteIfAbsentNonDefault(double key, Double2ByteFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - byte newValue = valueProvider.getAsInt(); + byte newValue = mappingFunction.applyAsByte(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } byte newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsByte(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -531,30 +541,20 @@ public byte supplyByteIfAbsentNonDefault(double key, ByteSupplier valueProvider) Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - byte newValue = valueProvider.getAsInt(); + byte newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } byte newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public byte computeByteIfPresent(double key, DoubleByteUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - byte newValue = mappingFunction.applyAsByte(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public byte computeByteIfPresentNonDefault(double key, DoubleByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2CharOpenCustomHashMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2CharOpenCustomHashMap.java index ea641d88..abd4083a 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2CharOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2CharOpenCustomHashMap.java @@ -463,30 +463,24 @@ public char computeChar(double key, DoubleCharUnaryOperator mappingFunction) { } @Override - public char computeCharNonDefault(double key, DoubleCharUnaryOperator mappingFunction) { + public char computeCharIfAbsent(double key, Double2CharFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + char newValue = mappingFunction.applyAsChar(key); insert(-index-1, key, newValue); return newValue; } - char newValue = mappingFunction.applyAsChar(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + char newValue = values[index]; return newValue; } - + @Override - public char computeCharIfAbsent(double key, Double2CharFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public char supplyCharIfAbsent(double key, CharSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = valueProvider.getAsChar(); insert(-index-1, key, newValue); return newValue; } @@ -495,34 +489,50 @@ public char computeCharIfAbsent(double key, Double2CharFunction mappingFunction) } @Override - public char computeCharIfAbsentNonDefault(double key, Double2CharFunction mappingFunction) { + public char computeCharIfPresent(double key, DoubleCharUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + char newValue = mappingFunction.applyAsChar(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public char computeCharNonDefault(double key, DoubleCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - char newValue = values[index]; + char newValue = mappingFunction.applyAsChar(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsChar(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public char supplyCharIfAbsent(double key, CharSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public char computeCharIfAbsentNonDefault(double key, Double2CharFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - char newValue = valueProvider.getAsInt(); + char newValue = mappingFunction.applyAsChar(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } char newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsChar(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -531,30 +541,20 @@ public char supplyCharIfAbsentNonDefault(double key, CharSupplier valueProvider) Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - char newValue = valueProvider.getAsInt(); + char newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } char newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public char computeCharIfPresent(double key, DoubleCharUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - char newValue = mappingFunction.applyAsChar(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public char computeCharIfPresentNonDefault(double key, DoubleCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2DoubleOpenCustomHashMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2DoubleOpenCustomHashMap.java index b1d2b5d5..e127a3c5 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2DoubleOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2DoubleOpenCustomHashMap.java @@ -455,30 +455,24 @@ public double computeDouble(double key, DoubleDoubleUnaryOperator mappingFunctio } @Override - public double computeDoubleNonDefault(double key, DoubleDoubleUnaryOperator mappingFunction) { + public double computeDoubleIfAbsent(double key, DoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + double newValue = mappingFunction.applyAsDouble(key); insert(-index-1, key, newValue); return newValue; } - double newValue = mappingFunction.applyAsDouble(key, values[index]); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + double newValue = values[index]; return newValue; } - + @Override - public double computeDoubleIfAbsent(double key, DoubleUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); + public double supplyDoubleIfAbsent(double key, DoubleSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = valueProvider.getAsDouble(); insert(-index-1, key, newValue); return newValue; } @@ -487,34 +481,50 @@ public double computeDoubleIfAbsent(double key, DoubleUnaryOperator mappingFunct } @Override - public double computeDoubleIfAbsentNonDefault(double key, DoubleUnaryOperator mappingFunction) { + public double computeDoubleIfPresent(double key, DoubleDoubleUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + double newValue = mappingFunction.applyAsDouble(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public double computeDoubleNonDefault(double key, DoubleDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } - double newValue = values[index]; + double newValue = mappingFunction.applyAsDouble(key, values[index]); if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - newValue = mappingFunction.applyAsDouble(key); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public double supplyDoubleIfAbsent(double key, DoubleSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public double computeDoubleIfAbsentNonDefault(double key, DoubleUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - double newValue = valueProvider.getAsDouble(); + double newValue = mappingFunction.applyAsDouble(key); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } double newValue = values[index]; + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { + newValue = mappingFunction.applyAsDouble(key); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + values[index] = newValue; + } return newValue; } @@ -537,16 +547,6 @@ public double supplyDoubleIfAbsentNonDefault(double key, DoubleSupplier valuePro return newValue; } - @Override - public double computeDoubleIfPresent(double key, DoubleDoubleUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - double newValue = mappingFunction.applyAsDouble(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public double computeDoubleIfPresentNonDefault(double key, DoubleDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2FloatOpenCustomHashMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2FloatOpenCustomHashMap.java index e368dc8d..b1a1f2af 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2FloatOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2FloatOpenCustomHashMap.java @@ -463,30 +463,24 @@ public float computeFloat(double key, DoubleFloatUnaryOperator mappingFunction) } @Override - public float computeFloatNonDefault(double key, DoubleFloatUnaryOperator mappingFunction) { + public float computeFloatIfAbsent(double key, Double2FloatFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + float newValue = mappingFunction.applyAsFloat(key); insert(-index-1, key, newValue); return newValue; } - float newValue = mappingFunction.applyAsFloat(key, values[index]); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + float newValue = values[index]; return newValue; } - + @Override - public float computeFloatIfAbsent(double key, Double2FloatFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public float supplyFloatIfAbsent(double key, FloatSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = valueProvider.getAsFloat(); insert(-index-1, key, newValue); return newValue; } @@ -495,34 +489,50 @@ public float computeFloatIfAbsent(double key, Double2FloatFunction mappingFuncti } @Override - public float computeFloatIfAbsentNonDefault(double key, Double2FloatFunction mappingFunction) { + public float computeFloatIfPresent(double key, DoubleFloatUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + float newValue = mappingFunction.applyAsFloat(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public float computeFloatNonDefault(double key, DoubleFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } - float newValue = values[index]; + float newValue = mappingFunction.applyAsFloat(key, values[index]); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - newValue = mappingFunction.applyAsFloat(key); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public float supplyFloatIfAbsent(double key, FloatSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public float computeFloatIfAbsentNonDefault(double key, Double2FloatFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - float newValue = valueProvider.getAsDouble(); + float newValue = mappingFunction.applyAsFloat(key); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } float newValue = values[index]; + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { + newValue = mappingFunction.applyAsFloat(key); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + values[index] = newValue; + } return newValue; } @@ -531,30 +541,20 @@ public float supplyFloatIfAbsentNonDefault(double key, FloatSupplier valueProvid Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - float newValue = valueProvider.getAsDouble(); + float newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } float newValue = values[index]; if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - newValue = valueProvider.getAsDouble(); + newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; values[index] = newValue; } return newValue; } - @Override - public float computeFloatIfPresent(double key, DoubleFloatUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - float newValue = mappingFunction.applyAsFloat(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public float computeFloatIfPresentNonDefault(double key, DoubleFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2IntOpenCustomHashMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2IntOpenCustomHashMap.java index 35370bf9..c05505ec 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2IntOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2IntOpenCustomHashMap.java @@ -463,30 +463,24 @@ public int computeInt(double key, DoubleIntUnaryOperator mappingFunction) { } @Override - public int computeIntNonDefault(double key, DoubleIntUnaryOperator mappingFunction) { + public int computeIntIfAbsent(double key, Double2IntFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + int newValue = mappingFunction.applyAsInt(key); insert(-index-1, key, newValue); return newValue; } - int newValue = mappingFunction.applyAsInt(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + int newValue = values[index]; return newValue; } - + @Override - public int computeIntIfAbsent(double key, Double2IntFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public int supplyIntIfAbsent(double key, IntSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = valueProvider.getAsInt(); insert(-index-1, key, newValue); return newValue; } @@ -495,34 +489,50 @@ public int computeIntIfAbsent(double key, Double2IntFunction mappingFunction) { } @Override - public int computeIntIfAbsentNonDefault(double key, Double2IntFunction mappingFunction) { + public int computeIntIfPresent(double key, DoubleIntUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + int newValue = mappingFunction.applyAsInt(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public int computeIntNonDefault(double key, DoubleIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - int newValue = values[index]; + int newValue = mappingFunction.applyAsInt(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsInt(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public int supplyIntIfAbsent(double key, IntSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public int computeIntIfAbsentNonDefault(double key, Double2IntFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - int newValue = valueProvider.getAsInt(); + int newValue = mappingFunction.applyAsInt(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } int newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsInt(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -545,16 +555,6 @@ public int supplyIntIfAbsentNonDefault(double key, IntSupplier valueProvider) { return newValue; } - @Override - public int computeIntIfPresent(double key, DoubleIntUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - int newValue = mappingFunction.applyAsInt(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public int computeIntIfPresentNonDefault(double key, DoubleIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2LongOpenCustomHashMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2LongOpenCustomHashMap.java index 5d1a2a72..993e742b 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2LongOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2LongOpenCustomHashMap.java @@ -463,30 +463,24 @@ public long computeLong(double key, DoubleLongUnaryOperator mappingFunction) { } @Override - public long computeLongNonDefault(double key, DoubleLongUnaryOperator mappingFunction) { + public long computeLongIfAbsent(double key, Double2LongFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + long newValue = mappingFunction.applyAsLong(key); insert(-index-1, key, newValue); return newValue; } - long newValue = mappingFunction.applyAsLong(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + long newValue = values[index]; return newValue; } - + @Override - public long computeLongIfAbsent(double key, Double2LongFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public long supplyLongIfAbsent(double key, LongSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = valueProvider.getAsLong(); insert(-index-1, key, newValue); return newValue; } @@ -495,34 +489,50 @@ public long computeLongIfAbsent(double key, Double2LongFunction mappingFunction) } @Override - public long computeLongIfAbsentNonDefault(double key, Double2LongFunction mappingFunction) { + public long computeLongIfPresent(double key, DoubleLongUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + long newValue = mappingFunction.applyAsLong(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public long computeLongNonDefault(double key, DoubleLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - long newValue = values[index]; + long newValue = mappingFunction.applyAsLong(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsLong(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public long supplyLongIfAbsent(double key, LongSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public long computeLongIfAbsentNonDefault(double key, Double2LongFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - long newValue = valueProvider.getAsLong(); + long newValue = mappingFunction.applyAsLong(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } long newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsLong(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -545,16 +555,6 @@ public long supplyLongIfAbsentNonDefault(double key, LongSupplier valueProvider) return newValue; } - @Override - public long computeLongIfPresent(double key, DoubleLongUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - long newValue = mappingFunction.applyAsLong(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public long computeLongIfPresentNonDefault(double key, DoubleLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2ObjectOpenCustomHashMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2ObjectOpenCustomHashMap.java index 0f64a01a..0b5d7e71 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2ObjectOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2ObjectOpenCustomHashMap.java @@ -432,25 +432,6 @@ public V compute(double key, DoubleObjectUnaryOperator mappingFunction) { return newValue; } - @Override - public V computeNonDefault(double key, DoubleObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) { - V newValue = mappingFunction.apply(key, getDefaultReturnValue()); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = mappingFunction.apply(key, values[index]); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; - return newValue; - } - @Override public V computeIfAbsent(double key, DoubleFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -469,26 +450,7 @@ public V computeIfAbsent(double key, DoubleFunction mappingFunction) { } return newValue; } - - @Override - public V computeIfAbsentNonDefault(double key, DoubleFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) { - V newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = values[index]; - if(Objects.equals(newValue, getDefaultReturnValue())) { - newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - values[index] = newValue; - } - return newValue; - } - + @Override public V supplyIfAbsent(double key, ObjectSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -508,25 +470,6 @@ public V supplyIfAbsent(double key, ObjectSupplier valueProvider) { return newValue; } - @Override - public V supplyIfAbsentNonDefault(double key, ObjectSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - int index = findIndex(key); - if(index < 0) { - V newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = values[index]; - if(Objects.equals(newValue, getDefaultReturnValue())) { - newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - values[index] = newValue; - } - return newValue; - } - @Override public V computeIfPresent(double key, DoubleObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -541,20 +484,6 @@ public V computeIfPresent(double key, DoubleObjectUnaryOperator mappingFuncti return newValue; } - @Override - public V computeIfPresentNonDefault(double key, DoubleObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0 || Objects.equals(values[index], getDefaultReturnValue())) return getDefaultReturnValue(); - V newValue = mappingFunction.apply(key, values[index]); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; - return newValue; - } - @Override public V merge(double key, V value, ObjectObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2ShortOpenCustomHashMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2ShortOpenCustomHashMap.java index 932e483e..de38908c 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2ShortOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/customHash/Double2ShortOpenCustomHashMap.java @@ -463,30 +463,24 @@ public short computeShort(double key, DoubleShortUnaryOperator mappingFunction) } @Override - public short computeShortNonDefault(double key, DoubleShortUnaryOperator mappingFunction) { + public short computeShortIfAbsent(double key, Double2ShortFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + short newValue = mappingFunction.applyAsShort(key); insert(-index-1, key, newValue); return newValue; } - short newValue = mappingFunction.applyAsShort(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + short newValue = values[index]; return newValue; } - + @Override - public short computeShortIfAbsent(double key, Double2ShortFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public short supplyShortIfAbsent(double key, ShortSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = valueProvider.getAsShort(); insert(-index-1, key, newValue); return newValue; } @@ -495,34 +489,50 @@ public short computeShortIfAbsent(double key, Double2ShortFunction mappingFuncti } @Override - public short computeShortIfAbsentNonDefault(double key, Double2ShortFunction mappingFunction) { + public short computeShortIfPresent(double key, DoubleShortUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + short newValue = mappingFunction.applyAsShort(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public short computeShortNonDefault(double key, DoubleShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - short newValue = values[index]; + short newValue = mappingFunction.applyAsShort(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsShort(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public short supplyShortIfAbsent(double key, ShortSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public short computeShortIfAbsentNonDefault(double key, Double2ShortFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - short newValue = valueProvider.getAsInt(); + short newValue = mappingFunction.applyAsShort(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } short newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsShort(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -531,30 +541,20 @@ public short supplyShortIfAbsentNonDefault(double key, ShortSupplier valueProvid Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - short newValue = valueProvider.getAsInt(); + short newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } short newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public short computeShortIfPresent(double key, DoubleShortUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - short newValue = mappingFunction.applyAsShort(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public short computeShortIfPresentNonDefault(double key, DoubleShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2BooleanOpenHashMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2BooleanOpenHashMap.java index a8afb4e0..9bb6588b 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2BooleanOpenHashMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2BooleanOpenHashMap.java @@ -408,68 +408,78 @@ public boolean computeBoolean(double key, DoubleBooleanUnaryOperator mappingFunc values[index] = newValue; return newValue; } - + @Override - public boolean computeBooleanNonDefault(double key, DoubleBooleanUnaryOperator mappingFunction) { + public boolean computeBooleanIfAbsent(double key, DoublePredicate mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + boolean newValue = mappingFunction.test(key); insert(-index-1, key, newValue); return newValue; } - boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + boolean newValue = values[index]; return newValue; } @Override - public boolean computeBooleanIfAbsent(double key, DoublePredicate mappingFunction) { - Objects.requireNonNull(mappingFunction); + public boolean supplyBooleanIfAbsent(double key, BooleanSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - boolean newValue = mappingFunction.test(key); + boolean newValue = valueProvider.getAsBoolean(); insert(-index-1, key, newValue); return newValue; } boolean newValue = values[index]; return newValue; } + + @Override + public boolean computeBooleanIfPresent(double key, DoubleBooleanUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public boolean computeBooleanIfAbsentNonDefault(double key, DoublePredicate mappingFunction) { + public boolean computeBooleanNonDefault(double key, DoubleBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - boolean newValue = mappingFunction.test(key); + boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - boolean newValue = values[index]; + boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.test(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public boolean supplyBooleanIfAbsent(double key, BooleanSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public boolean computeBooleanIfAbsentNonDefault(double key, DoublePredicate mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - boolean newValue = valueProvider.getAsBoolean(); + boolean newValue = mappingFunction.test(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } boolean newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.test(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -492,16 +502,6 @@ public boolean supplyBooleanIfAbsentNonDefault(double key, BooleanSupplier value return newValue; } - @Override - public boolean computeBooleanIfPresent(double key, DoubleBooleanUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public boolean computeBooleanIfPresentNonDefault(double key, DoubleBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2ByteOpenHashMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2ByteOpenHashMap.java index 62aafcf3..2d8c5791 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2ByteOpenHashMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2ByteOpenHashMap.java @@ -430,68 +430,78 @@ public byte computeByte(double key, DoubleByteUnaryOperator mappingFunction) { values[index] = newValue; return newValue; } - + @Override - public byte computeByteNonDefault(double key, DoubleByteUnaryOperator mappingFunction) { + public byte computeByteIfAbsent(double key, Double2ByteFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + byte newValue = mappingFunction.applyAsByte(key); insert(-index-1, key, newValue); return newValue; } - byte newValue = mappingFunction.applyAsByte(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + byte newValue = values[index]; return newValue; } @Override - public byte computeByteIfAbsent(double key, Double2ByteFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public byte supplyByteIfAbsent(double key, ByteSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = valueProvider.getAsByte(); insert(-index-1, key, newValue); return newValue; } byte newValue = values[index]; return newValue; } + + @Override + public byte computeByteIfPresent(double key, DoubleByteUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + byte newValue = mappingFunction.applyAsByte(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public byte computeByteIfAbsentNonDefault(double key, Double2ByteFunction mappingFunction) { + public byte computeByteNonDefault(double key, DoubleByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - byte newValue = values[index]; + byte newValue = mappingFunction.applyAsByte(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsByte(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public byte supplyByteIfAbsent(double key, ByteSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public byte computeByteIfAbsentNonDefault(double key, Double2ByteFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - byte newValue = valueProvider.getAsInt(); + byte newValue = mappingFunction.applyAsByte(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } byte newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsByte(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -500,30 +510,20 @@ public byte supplyByteIfAbsentNonDefault(double key, ByteSupplier valueProvider) Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - byte newValue = valueProvider.getAsInt(); + byte newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } byte newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public byte computeByteIfPresent(double key, DoubleByteUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - byte newValue = mappingFunction.applyAsByte(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public byte computeByteIfPresentNonDefault(double key, DoubleByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2CharOpenHashMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2CharOpenHashMap.java index 692bfabe..fb8d46b9 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2CharOpenHashMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2CharOpenHashMap.java @@ -430,68 +430,78 @@ public char computeChar(double key, DoubleCharUnaryOperator mappingFunction) { values[index] = newValue; return newValue; } - + @Override - public char computeCharNonDefault(double key, DoubleCharUnaryOperator mappingFunction) { + public char computeCharIfAbsent(double key, Double2CharFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + char newValue = mappingFunction.applyAsChar(key); insert(-index-1, key, newValue); return newValue; } - char newValue = mappingFunction.applyAsChar(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + char newValue = values[index]; return newValue; } @Override - public char computeCharIfAbsent(double key, Double2CharFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public char supplyCharIfAbsent(double key, CharSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = valueProvider.getAsChar(); insert(-index-1, key, newValue); return newValue; } char newValue = values[index]; return newValue; } + + @Override + public char computeCharIfPresent(double key, DoubleCharUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + char newValue = mappingFunction.applyAsChar(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public char computeCharIfAbsentNonDefault(double key, Double2CharFunction mappingFunction) { + public char computeCharNonDefault(double key, DoubleCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - char newValue = values[index]; + char newValue = mappingFunction.applyAsChar(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsChar(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public char supplyCharIfAbsent(double key, CharSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public char computeCharIfAbsentNonDefault(double key, Double2CharFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - char newValue = valueProvider.getAsInt(); + char newValue = mappingFunction.applyAsChar(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } char newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsChar(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -500,30 +510,20 @@ public char supplyCharIfAbsentNonDefault(double key, CharSupplier valueProvider) Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - char newValue = valueProvider.getAsInt(); + char newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } char newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public char computeCharIfPresent(double key, DoubleCharUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - char newValue = mappingFunction.applyAsChar(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public char computeCharIfPresentNonDefault(double key, DoubleCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2DoubleOpenHashMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2DoubleOpenHashMap.java index 9ed1e1dd..d84466d4 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2DoubleOpenHashMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2DoubleOpenHashMap.java @@ -424,68 +424,78 @@ public double computeDouble(double key, DoubleDoubleUnaryOperator mappingFunctio values[index] = newValue; return newValue; } - + @Override - public double computeDoubleNonDefault(double key, DoubleDoubleUnaryOperator mappingFunction) { + public double computeDoubleIfAbsent(double key, DoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + double newValue = mappingFunction.applyAsDouble(key); insert(-index-1, key, newValue); return newValue; } - double newValue = mappingFunction.applyAsDouble(key, values[index]); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + double newValue = values[index]; return newValue; } @Override - public double computeDoubleIfAbsent(double key, DoubleUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); + public double supplyDoubleIfAbsent(double key, DoubleSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = valueProvider.getAsDouble(); insert(-index-1, key, newValue); return newValue; } double newValue = values[index]; return newValue; } + + @Override + public double computeDoubleIfPresent(double key, DoubleDoubleUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + double newValue = mappingFunction.applyAsDouble(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public double computeDoubleIfAbsentNonDefault(double key, DoubleUnaryOperator mappingFunction) { + public double computeDoubleNonDefault(double key, DoubleDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } - double newValue = values[index]; + double newValue = mappingFunction.applyAsDouble(key, values[index]); if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - newValue = mappingFunction.applyAsDouble(key); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public double supplyDoubleIfAbsent(double key, DoubleSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public double computeDoubleIfAbsentNonDefault(double key, DoubleUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - double newValue = valueProvider.getAsDouble(); + double newValue = mappingFunction.applyAsDouble(key); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } double newValue = values[index]; + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { + newValue = mappingFunction.applyAsDouble(key); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + values[index] = newValue; + } return newValue; } @@ -508,16 +518,6 @@ public double supplyDoubleIfAbsentNonDefault(double key, DoubleSupplier valuePro return newValue; } - @Override - public double computeDoubleIfPresent(double key, DoubleDoubleUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - double newValue = mappingFunction.applyAsDouble(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public double computeDoubleIfPresentNonDefault(double key, DoubleDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2FloatOpenHashMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2FloatOpenHashMap.java index cb143314..481ba54a 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2FloatOpenHashMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2FloatOpenHashMap.java @@ -430,68 +430,78 @@ public float computeFloat(double key, DoubleFloatUnaryOperator mappingFunction) values[index] = newValue; return newValue; } - + @Override - public float computeFloatNonDefault(double key, DoubleFloatUnaryOperator mappingFunction) { + public float computeFloatIfAbsent(double key, Double2FloatFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + float newValue = mappingFunction.applyAsFloat(key); insert(-index-1, key, newValue); return newValue; } - float newValue = mappingFunction.applyAsFloat(key, values[index]); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + float newValue = values[index]; return newValue; } @Override - public float computeFloatIfAbsent(double key, Double2FloatFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public float supplyFloatIfAbsent(double key, FloatSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = valueProvider.getAsFloat(); insert(-index-1, key, newValue); return newValue; } float newValue = values[index]; return newValue; } + + @Override + public float computeFloatIfPresent(double key, DoubleFloatUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + float newValue = mappingFunction.applyAsFloat(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public float computeFloatIfAbsentNonDefault(double key, Double2FloatFunction mappingFunction) { + public float computeFloatNonDefault(double key, DoubleFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } - float newValue = values[index]; + float newValue = mappingFunction.applyAsFloat(key, values[index]); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - newValue = mappingFunction.applyAsFloat(key); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public float supplyFloatIfAbsent(double key, FloatSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public float computeFloatIfAbsentNonDefault(double key, Double2FloatFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - float newValue = valueProvider.getAsDouble(); + float newValue = mappingFunction.applyAsFloat(key); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } float newValue = values[index]; + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { + newValue = mappingFunction.applyAsFloat(key); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + values[index] = newValue; + } return newValue; } @@ -500,30 +510,20 @@ public float supplyFloatIfAbsentNonDefault(double key, FloatSupplier valueProvid Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - float newValue = valueProvider.getAsDouble(); + float newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } float newValue = values[index]; if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - newValue = valueProvider.getAsDouble(); + newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; values[index] = newValue; } return newValue; } - @Override - public float computeFloatIfPresent(double key, DoubleFloatUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - float newValue = mappingFunction.applyAsFloat(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public float computeFloatIfPresentNonDefault(double key, DoubleFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2IntOpenHashMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2IntOpenHashMap.java index 0b82696c..4678e7b3 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2IntOpenHashMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2IntOpenHashMap.java @@ -430,68 +430,78 @@ public int computeInt(double key, DoubleIntUnaryOperator mappingFunction) { values[index] = newValue; return newValue; } - + @Override - public int computeIntNonDefault(double key, DoubleIntUnaryOperator mappingFunction) { + public int computeIntIfAbsent(double key, Double2IntFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + int newValue = mappingFunction.applyAsInt(key); insert(-index-1, key, newValue); return newValue; } - int newValue = mappingFunction.applyAsInt(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + int newValue = values[index]; return newValue; } @Override - public int computeIntIfAbsent(double key, Double2IntFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public int supplyIntIfAbsent(double key, IntSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = valueProvider.getAsInt(); insert(-index-1, key, newValue); return newValue; } int newValue = values[index]; return newValue; } + + @Override + public int computeIntIfPresent(double key, DoubleIntUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + int newValue = mappingFunction.applyAsInt(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public int computeIntIfAbsentNonDefault(double key, Double2IntFunction mappingFunction) { + public int computeIntNonDefault(double key, DoubleIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - int newValue = values[index]; + int newValue = mappingFunction.applyAsInt(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsInt(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public int supplyIntIfAbsent(double key, IntSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public int computeIntIfAbsentNonDefault(double key, Double2IntFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - int newValue = valueProvider.getAsInt(); + int newValue = mappingFunction.applyAsInt(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } int newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsInt(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -514,16 +524,6 @@ public int supplyIntIfAbsentNonDefault(double key, IntSupplier valueProvider) { return newValue; } - @Override - public int computeIntIfPresent(double key, DoubleIntUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - int newValue = mappingFunction.applyAsInt(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public int computeIntIfPresentNonDefault(double key, DoubleIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2LongOpenHashMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2LongOpenHashMap.java index a793263e..5b3cbaa5 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2LongOpenHashMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2LongOpenHashMap.java @@ -430,68 +430,78 @@ public long computeLong(double key, DoubleLongUnaryOperator mappingFunction) { values[index] = newValue; return newValue; } - + @Override - public long computeLongNonDefault(double key, DoubleLongUnaryOperator mappingFunction) { + public long computeLongIfAbsent(double key, Double2LongFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + long newValue = mappingFunction.applyAsLong(key); insert(-index-1, key, newValue); return newValue; } - long newValue = mappingFunction.applyAsLong(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + long newValue = values[index]; return newValue; } @Override - public long computeLongIfAbsent(double key, Double2LongFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public long supplyLongIfAbsent(double key, LongSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = valueProvider.getAsLong(); insert(-index-1, key, newValue); return newValue; } long newValue = values[index]; return newValue; } + + @Override + public long computeLongIfPresent(double key, DoubleLongUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + long newValue = mappingFunction.applyAsLong(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public long computeLongIfAbsentNonDefault(double key, Double2LongFunction mappingFunction) { + public long computeLongNonDefault(double key, DoubleLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - long newValue = values[index]; + long newValue = mappingFunction.applyAsLong(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsLong(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public long supplyLongIfAbsent(double key, LongSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public long computeLongIfAbsentNonDefault(double key, Double2LongFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - long newValue = valueProvider.getAsLong(); + long newValue = mappingFunction.applyAsLong(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } long newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsLong(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -514,16 +524,6 @@ public long supplyLongIfAbsentNonDefault(double key, LongSupplier valueProvider) return newValue; } - @Override - public long computeLongIfPresent(double key, DoubleLongUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - long newValue = mappingFunction.applyAsLong(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public long computeLongIfPresentNonDefault(double key, DoubleLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2ObjectOpenHashMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2ObjectOpenHashMap.java index 9a74c8f5..5fd98975 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2ObjectOpenHashMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2ObjectOpenHashMap.java @@ -401,26 +401,7 @@ public V compute(double key, DoubleObjectUnaryOperator mappingFunction) { values[index] = newValue; return newValue; } - - @Override - public V computeNonDefault(double key, DoubleObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) { - V newValue = mappingFunction.apply(key, getDefaultReturnValue()); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = mappingFunction.apply(key, values[index]); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; - return newValue; - } - + @Override public V computeIfAbsent(double key, DoubleFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -440,25 +421,6 @@ public V computeIfAbsent(double key, DoubleFunction mappingFunction) { return newValue; } - @Override - public V computeIfAbsentNonDefault(double key, DoubleFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) { - V newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = values[index]; - if(Objects.equals(newValue, getDefaultReturnValue())) { - newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - values[index] = newValue; - } - return newValue; - } - @Override public V supplyIfAbsent(double key, ObjectSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -477,26 +439,7 @@ public V supplyIfAbsent(double key, ObjectSupplier valueProvider) { } return newValue; } - - @Override - public V supplyIfAbsentNonDefault(double key, ObjectSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - int index = findIndex(key); - if(index < 0) { - V newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = values[index]; - if(Objects.equals(newValue, getDefaultReturnValue())) { - newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - values[index] = newValue; - } - return newValue; - } - + @Override public V computeIfPresent(double key, DoubleObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -511,20 +454,6 @@ public V computeIfPresent(double key, DoubleObjectUnaryOperator mappingFuncti return newValue; } - @Override - public V computeIfPresentNonDefault(double key, DoubleObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0 || Objects.equals(values[index], getDefaultReturnValue())) return getDefaultReturnValue(); - V newValue = mappingFunction.apply(key, values[index]); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; - return newValue; - } - @Override public V merge(double key, V value, ObjectObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2ShortOpenHashMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2ShortOpenHashMap.java index e0d401d7..321957ed 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2ShortOpenHashMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/hash/Double2ShortOpenHashMap.java @@ -430,68 +430,78 @@ public short computeShort(double key, DoubleShortUnaryOperator mappingFunction) values[index] = newValue; return newValue; } - + @Override - public short computeShortNonDefault(double key, DoubleShortUnaryOperator mappingFunction) { + public short computeShortIfAbsent(double key, Double2ShortFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + short newValue = mappingFunction.applyAsShort(key); insert(-index-1, key, newValue); return newValue; } - short newValue = mappingFunction.applyAsShort(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + short newValue = values[index]; return newValue; } @Override - public short computeShortIfAbsent(double key, Double2ShortFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public short supplyShortIfAbsent(double key, ShortSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = valueProvider.getAsShort(); insert(-index-1, key, newValue); return newValue; } short newValue = values[index]; return newValue; } + + @Override + public short computeShortIfPresent(double key, DoubleShortUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + short newValue = mappingFunction.applyAsShort(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public short computeShortIfAbsentNonDefault(double key, Double2ShortFunction mappingFunction) { + public short computeShortNonDefault(double key, DoubleShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - short newValue = values[index]; + short newValue = mappingFunction.applyAsShort(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsShort(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public short supplyShortIfAbsent(double key, ShortSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public short computeShortIfAbsentNonDefault(double key, Double2ShortFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - short newValue = valueProvider.getAsInt(); + short newValue = mappingFunction.applyAsShort(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } short newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsShort(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -500,30 +510,20 @@ public short supplyShortIfAbsentNonDefault(double key, ShortSupplier valueProvid Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - short newValue = valueProvider.getAsInt(); + short newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } short newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public short computeShortIfPresent(double key, DoubleShortUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - short newValue = mappingFunction.applyAsShort(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public short computeShortIfPresentNonDefault(double key, DoubleShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/immutable/ImmutableDouble2BooleanOpenHashMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/immutable/ImmutableDouble2BooleanOpenHashMap.java index 11f3e57d..bb78289d 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/immutable/ImmutableDouble2BooleanOpenHashMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/immutable/ImmutableDouble2BooleanOpenHashMap.java @@ -413,20 +413,19 @@ public void forEach(DoubleBooleanConsumer action) { @Override public boolean computeBoolean(double key, DoubleBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanNonDefault(double key, DoubleBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean computeBooleanIfAbsent(double key, DoublePredicate mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanIfAbsentNonDefault(double key, DoublePredicate mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean supplyBooleanIfAbsent(double key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public boolean supplyBooleanIfAbsentNonDefault(double key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public boolean computeBooleanIfPresent(double key, DoubleBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override + public boolean computeBooleanNonDefault(double key, DoubleBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public boolean computeBooleanIfAbsentNonDefault(double key, DoublePredicate mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public boolean supplyBooleanIfAbsentNonDefault(double key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } + @Override public boolean computeBooleanIfPresentNonDefault(double key, DoubleBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean mergeBoolean(double key, boolean value, BooleanBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/immutable/ImmutableDouble2ByteOpenHashMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/immutable/ImmutableDouble2ByteOpenHashMap.java index 85f7535a..20c5d0bd 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/immutable/ImmutableDouble2ByteOpenHashMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/immutable/ImmutableDouble2ByteOpenHashMap.java @@ -418,20 +418,19 @@ public void forEach(DoubleByteConsumer action) { @Override public byte computeByte(double key, DoubleByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteNonDefault(double key, DoubleByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte computeByteIfAbsent(double key, Double2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteIfAbsentNonDefault(double key, Double2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte supplyByteIfAbsent(double key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public byte supplyByteIfAbsentNonDefault(double key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public byte computeByteIfPresent(double key, DoubleByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override + public byte computeByteNonDefault(double key, DoubleByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public byte computeByteIfAbsentNonDefault(double key, Double2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public byte supplyByteIfAbsentNonDefault(double key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } + @Override public byte computeByteIfPresentNonDefault(double key, DoubleByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte mergeByte(double key, byte value, ByteByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/immutable/ImmutableDouble2CharOpenHashMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/immutable/ImmutableDouble2CharOpenHashMap.java index 8ef4ed68..71ef2009 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/immutable/ImmutableDouble2CharOpenHashMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/immutable/ImmutableDouble2CharOpenHashMap.java @@ -418,20 +418,19 @@ public void forEach(DoubleCharConsumer action) { @Override public char computeChar(double key, DoubleCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharNonDefault(double key, DoubleCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char computeCharIfAbsent(double key, Double2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharIfAbsentNonDefault(double key, Double2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char supplyCharIfAbsent(double key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public char supplyCharIfAbsentNonDefault(double key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public char computeCharIfPresent(double key, DoubleCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override + public char computeCharNonDefault(double key, DoubleCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public char computeCharIfAbsentNonDefault(double key, Double2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public char supplyCharIfAbsentNonDefault(double key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } + @Override public char computeCharIfPresentNonDefault(double key, DoubleCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char mergeChar(double key, char value, CharCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/immutable/ImmutableDouble2DoubleOpenHashMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/immutable/ImmutableDouble2DoubleOpenHashMap.java index 6c232585..ed25c4ae 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/immutable/ImmutableDouble2DoubleOpenHashMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/immutable/ImmutableDouble2DoubleOpenHashMap.java @@ -409,20 +409,19 @@ public void forEach(DoubleDoubleConsumer action) { @Override public double computeDouble(double key, DoubleDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleNonDefault(double key, DoubleDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double computeDoubleIfAbsent(double key, DoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleIfAbsentNonDefault(double key, DoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double supplyDoubleIfAbsent(double key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public double supplyDoubleIfAbsentNonDefault(double key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public double computeDoubleIfPresent(double key, DoubleDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override + public double computeDoubleNonDefault(double key, DoubleDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public double computeDoubleIfAbsentNonDefault(double key, DoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public double supplyDoubleIfAbsentNonDefault(double key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } + @Override public double computeDoubleIfPresentNonDefault(double key, DoubleDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double mergeDouble(double key, double value, DoubleDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/immutable/ImmutableDouble2FloatOpenHashMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/immutable/ImmutableDouble2FloatOpenHashMap.java index 6563d7c5..4a52f974 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/immutable/ImmutableDouble2FloatOpenHashMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/immutable/ImmutableDouble2FloatOpenHashMap.java @@ -418,20 +418,19 @@ public void forEach(DoubleFloatConsumer action) { @Override public float computeFloat(double key, DoubleFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatNonDefault(double key, DoubleFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float computeFloatIfAbsent(double key, Double2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatIfAbsentNonDefault(double key, Double2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float supplyFloatIfAbsent(double key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public float supplyFloatIfAbsentNonDefault(double key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public float computeFloatIfPresent(double key, DoubleFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override + public float computeFloatNonDefault(double key, DoubleFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public float computeFloatIfAbsentNonDefault(double key, Double2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public float supplyFloatIfAbsentNonDefault(double key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } + @Override public float computeFloatIfPresentNonDefault(double key, DoubleFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float mergeFloat(double key, float value, FloatFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/immutable/ImmutableDouble2IntOpenHashMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/immutable/ImmutableDouble2IntOpenHashMap.java index 27a3bb87..a402acbd 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/immutable/ImmutableDouble2IntOpenHashMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/immutable/ImmutableDouble2IntOpenHashMap.java @@ -418,20 +418,19 @@ public void forEach(DoubleIntConsumer action) { @Override public int computeInt(double key, DoubleIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntNonDefault(double key, DoubleIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int computeIntIfAbsent(double key, Double2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntIfAbsentNonDefault(double key, Double2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int supplyIntIfAbsent(double key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public int supplyIntIfAbsentNonDefault(double key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public int computeIntIfPresent(double key, DoubleIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override + public int computeIntNonDefault(double key, DoubleIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public int computeIntIfAbsentNonDefault(double key, Double2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public int supplyIntIfAbsentNonDefault(double key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } + @Override public int computeIntIfPresentNonDefault(double key, DoubleIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int mergeInt(double key, int value, IntIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/immutable/ImmutableDouble2LongOpenHashMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/immutable/ImmutableDouble2LongOpenHashMap.java index 14dd6d09..9557acc6 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/immutable/ImmutableDouble2LongOpenHashMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/immutable/ImmutableDouble2LongOpenHashMap.java @@ -418,20 +418,19 @@ public void forEach(DoubleLongConsumer action) { @Override public long computeLong(double key, DoubleLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongNonDefault(double key, DoubleLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long computeLongIfAbsent(double key, Double2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongIfAbsentNonDefault(double key, Double2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long supplyLongIfAbsent(double key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public long supplyLongIfAbsentNonDefault(double key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public long computeLongIfPresent(double key, DoubleLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override + public long computeLongNonDefault(double key, DoubleLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public long computeLongIfAbsentNonDefault(double key, Double2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public long supplyLongIfAbsentNonDefault(double key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } + @Override public long computeLongIfPresentNonDefault(double key, DoubleLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long mergeLong(double key, long value, LongLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/immutable/ImmutableDouble2ObjectOpenHashMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/immutable/ImmutableDouble2ObjectOpenHashMap.java index fa2cdf6a..090beaa3 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/immutable/ImmutableDouble2ObjectOpenHashMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/immutable/ImmutableDouble2ObjectOpenHashMap.java @@ -397,20 +397,11 @@ public void forEach(DoubleObjectConsumer action) { @Override public V compute(double key, DoubleObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeNonDefault(double key, DoubleObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V computeIfAbsent(double key, DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeIfAbsentNonDefault(double key, DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V supplyIfAbsent(double key, ObjectSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public V supplyIfAbsentNonDefault(double key, ObjectSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public V computeIfPresent(double key, DoubleObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override - public V computeIfPresentNonDefault(double key, DoubleObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V merge(double key, V value, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/immutable/ImmutableDouble2ShortOpenHashMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/immutable/ImmutableDouble2ShortOpenHashMap.java index c7067e7a..5a034383 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/immutable/ImmutableDouble2ShortOpenHashMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/immutable/ImmutableDouble2ShortOpenHashMap.java @@ -418,20 +418,19 @@ public void forEach(DoubleShortConsumer action) { @Override public short computeShort(double key, DoubleShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortNonDefault(double key, DoubleShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short computeShortIfAbsent(double key, Double2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortIfAbsentNonDefault(double key, Double2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short supplyShortIfAbsent(double key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public short supplyShortIfAbsentNonDefault(double key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public short computeShortIfPresent(double key, DoubleShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override + public short computeShortNonDefault(double key, DoubleShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public short computeShortIfAbsentNonDefault(double key, Double2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public short supplyShortIfAbsentNonDefault(double key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } + @Override public short computeShortIfPresentNonDefault(double key, DoubleShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short mergeShort(double key, short value, ShortShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/misc/Double2BooleanArrayMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/misc/Double2BooleanArrayMap.java index 03bf9473..44840854 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/misc/Double2BooleanArrayMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/misc/Double2BooleanArrayMap.java @@ -420,66 +420,76 @@ public boolean computeBoolean(double key, DoubleBooleanUnaryOperator mappingFunc } @Override - public boolean computeBooleanNonDefault(double key, DoubleBooleanUnaryOperator mappingFunction) { + public boolean computeBooleanIfAbsent(double key, DoublePredicate mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + boolean newValue = mappingFunction.test(key); insertIndex(size++, key, newValue); return newValue; } - boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + boolean newValue = values[index]; return newValue; } - + @Override - public boolean computeBooleanIfAbsent(double key, DoublePredicate mappingFunction) { - Objects.requireNonNull(mappingFunction); + public boolean supplyBooleanIfAbsent(double key, BooleanSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - boolean newValue = mappingFunction.test(key); + boolean newValue = valueProvider.getAsBoolean(); insertIndex(size++, key, newValue); return newValue; } boolean newValue = values[index]; return newValue; } + + @Override + public boolean computeBooleanIfPresent(double key, DoubleBooleanUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index == -1) return getDefaultReturnValue(); + boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public boolean computeBooleanIfAbsentNonDefault(double key, DoublePredicate mappingFunction) { + public boolean computeBooleanNonDefault(double key, DoubleBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - boolean newValue = mappingFunction.test(key); + boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } - boolean newValue = values[index]; + boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.test(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public boolean supplyBooleanIfAbsent(double key, BooleanSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public boolean computeBooleanIfAbsentNonDefault(double key, DoublePredicate mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - boolean newValue = valueProvider.getAsBoolean(); + boolean newValue = mappingFunction.test(key); + if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } boolean newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.test(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -502,16 +512,6 @@ public boolean supplyBooleanIfAbsentNonDefault(double key, BooleanSupplier value return newValue; } - @Override - public boolean computeBooleanIfPresent(double key, DoubleBooleanUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) return getDefaultReturnValue(); - boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public boolean computeBooleanIfPresentNonDefault(double key, DoubleBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/misc/Double2ByteArrayMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/misc/Double2ByteArrayMap.java index 3415178e..3f204f70 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/misc/Double2ByteArrayMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/misc/Double2ByteArrayMap.java @@ -443,66 +443,76 @@ public byte computeByte(double key, DoubleByteUnaryOperator mappingFunction) { } @Override - public byte computeByteNonDefault(double key, DoubleByteUnaryOperator mappingFunction) { + public byte computeByteIfAbsent(double key, Double2ByteFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + byte newValue = mappingFunction.applyAsByte(key); insertIndex(size++, key, newValue); return newValue; } - byte newValue = mappingFunction.applyAsByte(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + byte newValue = values[index]; return newValue; } - + @Override - public byte computeByteIfAbsent(double key, Double2ByteFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public byte supplyByteIfAbsent(double key, ByteSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = valueProvider.getAsByte(); insertIndex(size++, key, newValue); return newValue; } byte newValue = values[index]; return newValue; } + + @Override + public byte computeByteIfPresent(double key, DoubleByteUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index == -1) return getDefaultReturnValue(); + byte newValue = mappingFunction.applyAsByte(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public byte computeByteIfAbsentNonDefault(double key, Double2ByteFunction mappingFunction) { + public byte computeByteNonDefault(double key, DoubleByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } - byte newValue = values[index]; + byte newValue = mappingFunction.applyAsByte(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsByte(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public byte supplyByteIfAbsent(double key, ByteSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public byte computeByteIfAbsentNonDefault(double key, Double2ByteFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - byte newValue = valueProvider.getAsInt(); + byte newValue = mappingFunction.applyAsByte(key); + if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } byte newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsByte(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -511,30 +521,20 @@ public byte supplyByteIfAbsentNonDefault(double key, ByteSupplier valueProvider) Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - byte newValue = valueProvider.getAsInt(); + byte newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } byte newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public byte computeByteIfPresent(double key, DoubleByteUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) return getDefaultReturnValue(); - byte newValue = mappingFunction.applyAsByte(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public byte computeByteIfPresentNonDefault(double key, DoubleByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/misc/Double2CharArrayMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/misc/Double2CharArrayMap.java index 65fad453..453105fb 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/misc/Double2CharArrayMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/misc/Double2CharArrayMap.java @@ -443,66 +443,76 @@ public char computeChar(double key, DoubleCharUnaryOperator mappingFunction) { } @Override - public char computeCharNonDefault(double key, DoubleCharUnaryOperator mappingFunction) { + public char computeCharIfAbsent(double key, Double2CharFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + char newValue = mappingFunction.applyAsChar(key); insertIndex(size++, key, newValue); return newValue; } - char newValue = mappingFunction.applyAsChar(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + char newValue = values[index]; return newValue; } - + @Override - public char computeCharIfAbsent(double key, Double2CharFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public char supplyCharIfAbsent(double key, CharSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = valueProvider.getAsChar(); insertIndex(size++, key, newValue); return newValue; } char newValue = values[index]; return newValue; } + + @Override + public char computeCharIfPresent(double key, DoubleCharUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index == -1) return getDefaultReturnValue(); + char newValue = mappingFunction.applyAsChar(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public char computeCharIfAbsentNonDefault(double key, Double2CharFunction mappingFunction) { + public char computeCharNonDefault(double key, DoubleCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } - char newValue = values[index]; + char newValue = mappingFunction.applyAsChar(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsChar(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public char supplyCharIfAbsent(double key, CharSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public char computeCharIfAbsentNonDefault(double key, Double2CharFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - char newValue = valueProvider.getAsInt(); + char newValue = mappingFunction.applyAsChar(key); + if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } char newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsChar(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -511,30 +521,20 @@ public char supplyCharIfAbsentNonDefault(double key, CharSupplier valueProvider) Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - char newValue = valueProvider.getAsInt(); + char newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } char newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public char computeCharIfPresent(double key, DoubleCharUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) return getDefaultReturnValue(); - char newValue = mappingFunction.applyAsChar(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public char computeCharIfPresentNonDefault(double key, DoubleCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/misc/Double2DoubleArrayMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/misc/Double2DoubleArrayMap.java index 9081fc04..0f09fa04 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/misc/Double2DoubleArrayMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/misc/Double2DoubleArrayMap.java @@ -436,66 +436,76 @@ public double computeDouble(double key, DoubleDoubleUnaryOperator mappingFunctio } @Override - public double computeDoubleNonDefault(double key, DoubleDoubleUnaryOperator mappingFunction) { + public double computeDoubleIfAbsent(double key, DoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + double newValue = mappingFunction.applyAsDouble(key); insertIndex(size++, key, newValue); return newValue; } - double newValue = mappingFunction.applyAsDouble(key, values[index]); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + double newValue = values[index]; return newValue; } - + @Override - public double computeDoubleIfAbsent(double key, DoubleUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); + public double supplyDoubleIfAbsent(double key, DoubleSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = valueProvider.getAsDouble(); insertIndex(size++, key, newValue); return newValue; } double newValue = values[index]; return newValue; } + + @Override + public double computeDoubleIfPresent(double key, DoubleDoubleUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index == -1) return getDefaultReturnValue(); + double newValue = mappingFunction.applyAsDouble(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public double computeDoubleIfAbsentNonDefault(double key, DoubleUnaryOperator mappingFunction) { + public double computeDoubleNonDefault(double key, DoubleDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; insertIndex(size++, key, newValue); return newValue; } - double newValue = values[index]; + double newValue = mappingFunction.applyAsDouble(key, values[index]); if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - newValue = mappingFunction.applyAsDouble(key); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public double supplyDoubleIfAbsent(double key, DoubleSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public double computeDoubleIfAbsentNonDefault(double key, DoubleUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - double newValue = valueProvider.getAsDouble(); + double newValue = mappingFunction.applyAsDouble(key); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; insertIndex(size++, key, newValue); return newValue; } double newValue = values[index]; + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { + newValue = mappingFunction.applyAsDouble(key); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + values[index] = newValue; + } return newValue; } @@ -518,16 +528,6 @@ public double supplyDoubleIfAbsentNonDefault(double key, DoubleSupplier valuePro return newValue; } - @Override - public double computeDoubleIfPresent(double key, DoubleDoubleUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) return getDefaultReturnValue(); - double newValue = mappingFunction.applyAsDouble(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public double computeDoubleIfPresentNonDefault(double key, DoubleDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/misc/Double2FloatArrayMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/misc/Double2FloatArrayMap.java index 54fd7d8c..d5fdacc9 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/misc/Double2FloatArrayMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/misc/Double2FloatArrayMap.java @@ -443,66 +443,76 @@ public float computeFloat(double key, DoubleFloatUnaryOperator mappingFunction) } @Override - public float computeFloatNonDefault(double key, DoubleFloatUnaryOperator mappingFunction) { + public float computeFloatIfAbsent(double key, Double2FloatFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + float newValue = mappingFunction.applyAsFloat(key); insertIndex(size++, key, newValue); return newValue; } - float newValue = mappingFunction.applyAsFloat(key, values[index]); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + float newValue = values[index]; return newValue; } - + @Override - public float computeFloatIfAbsent(double key, Double2FloatFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public float supplyFloatIfAbsent(double key, FloatSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = valueProvider.getAsFloat(); insertIndex(size++, key, newValue); return newValue; } float newValue = values[index]; return newValue; } + + @Override + public float computeFloatIfPresent(double key, DoubleFloatUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index == -1) return getDefaultReturnValue(); + float newValue = mappingFunction.applyAsFloat(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public float computeFloatIfAbsentNonDefault(double key, Double2FloatFunction mappingFunction) { + public float computeFloatNonDefault(double key, DoubleFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insertIndex(size++, key, newValue); return newValue; } - float newValue = values[index]; + float newValue = mappingFunction.applyAsFloat(key, values[index]); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - newValue = mappingFunction.applyAsFloat(key); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public float supplyFloatIfAbsent(double key, FloatSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public float computeFloatIfAbsentNonDefault(double key, Double2FloatFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - float newValue = valueProvider.getAsDouble(); + float newValue = mappingFunction.applyAsFloat(key); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insertIndex(size++, key, newValue); return newValue; } float newValue = values[index]; + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { + newValue = mappingFunction.applyAsFloat(key); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + values[index] = newValue; + } return newValue; } @@ -511,30 +521,20 @@ public float supplyFloatIfAbsentNonDefault(double key, FloatSupplier valueProvid Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - float newValue = valueProvider.getAsDouble(); + float newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insertIndex(size++, key, newValue); return newValue; } float newValue = values[index]; if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - newValue = valueProvider.getAsDouble(); + newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; values[index] = newValue; } return newValue; } - @Override - public float computeFloatIfPresent(double key, DoubleFloatUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) return getDefaultReturnValue(); - float newValue = mappingFunction.applyAsFloat(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public float computeFloatIfPresentNonDefault(double key, DoubleFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/misc/Double2IntArrayMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/misc/Double2IntArrayMap.java index 43fd8933..b97624c5 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/misc/Double2IntArrayMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/misc/Double2IntArrayMap.java @@ -443,66 +443,76 @@ public int computeInt(double key, DoubleIntUnaryOperator mappingFunction) { } @Override - public int computeIntNonDefault(double key, DoubleIntUnaryOperator mappingFunction) { + public int computeIntIfAbsent(double key, Double2IntFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + int newValue = mappingFunction.applyAsInt(key); insertIndex(size++, key, newValue); return newValue; } - int newValue = mappingFunction.applyAsInt(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + int newValue = values[index]; return newValue; } - + @Override - public int computeIntIfAbsent(double key, Double2IntFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public int supplyIntIfAbsent(double key, IntSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = valueProvider.getAsInt(); insertIndex(size++, key, newValue); return newValue; } int newValue = values[index]; return newValue; } + + @Override + public int computeIntIfPresent(double key, DoubleIntUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index == -1) return getDefaultReturnValue(); + int newValue = mappingFunction.applyAsInt(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public int computeIntIfAbsentNonDefault(double key, Double2IntFunction mappingFunction) { + public int computeIntNonDefault(double key, DoubleIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } - int newValue = values[index]; + int newValue = mappingFunction.applyAsInt(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsInt(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public int supplyIntIfAbsent(double key, IntSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public int computeIntIfAbsentNonDefault(double key, Double2IntFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - int newValue = valueProvider.getAsInt(); + int newValue = mappingFunction.applyAsInt(key); + if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } int newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsInt(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -525,16 +535,6 @@ public int supplyIntIfAbsentNonDefault(double key, IntSupplier valueProvider) { return newValue; } - @Override - public int computeIntIfPresent(double key, DoubleIntUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) return getDefaultReturnValue(); - int newValue = mappingFunction.applyAsInt(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public int computeIntIfPresentNonDefault(double key, DoubleIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/misc/Double2LongArrayMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/misc/Double2LongArrayMap.java index b023e645..ed949e9b 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/misc/Double2LongArrayMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/misc/Double2LongArrayMap.java @@ -443,66 +443,76 @@ public long computeLong(double key, DoubleLongUnaryOperator mappingFunction) { } @Override - public long computeLongNonDefault(double key, DoubleLongUnaryOperator mappingFunction) { + public long computeLongIfAbsent(double key, Double2LongFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + long newValue = mappingFunction.applyAsLong(key); insertIndex(size++, key, newValue); return newValue; } - long newValue = mappingFunction.applyAsLong(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + long newValue = values[index]; return newValue; } - + @Override - public long computeLongIfAbsent(double key, Double2LongFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public long supplyLongIfAbsent(double key, LongSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = valueProvider.getAsLong(); insertIndex(size++, key, newValue); return newValue; } long newValue = values[index]; return newValue; } + + @Override + public long computeLongIfPresent(double key, DoubleLongUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index == -1) return getDefaultReturnValue(); + long newValue = mappingFunction.applyAsLong(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public long computeLongIfAbsentNonDefault(double key, Double2LongFunction mappingFunction) { + public long computeLongNonDefault(double key, DoubleLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } - long newValue = values[index]; + long newValue = mappingFunction.applyAsLong(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsLong(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public long supplyLongIfAbsent(double key, LongSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public long computeLongIfAbsentNonDefault(double key, Double2LongFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - long newValue = valueProvider.getAsLong(); + long newValue = mappingFunction.applyAsLong(key); + if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } long newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsLong(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -525,16 +535,6 @@ public long supplyLongIfAbsentNonDefault(double key, LongSupplier valueProvider) return newValue; } - @Override - public long computeLongIfPresent(double key, DoubleLongUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) return getDefaultReturnValue(); - long newValue = mappingFunction.applyAsLong(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public long computeLongIfPresentNonDefault(double key, DoubleLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/misc/Double2ObjectArrayMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/misc/Double2ObjectArrayMap.java index 44cc9f12..383824f6 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/misc/Double2ObjectArrayMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/misc/Double2ObjectArrayMap.java @@ -415,25 +415,6 @@ public V compute(double key, DoubleObjectUnaryOperator mappingFunction) { return newValue; } - @Override - public V computeNonDefault(double key, DoubleObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) { - V newValue = mappingFunction.apply(key, getDefaultReturnValue()); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insertIndex(size++, key, newValue); - return newValue; - } - V newValue = mappingFunction.apply(key, values[index]); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; - return newValue; - } - @Override public V computeIfAbsent(double key, DoubleFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -452,26 +433,7 @@ public V computeIfAbsent(double key, DoubleFunction mappingFunction) { } return newValue; } - - @Override - public V computeIfAbsentNonDefault(double key, DoubleFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) { - V newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insertIndex(size++, key, newValue); - return newValue; - } - V newValue = values[index]; - if(Objects.equals(newValue, getDefaultReturnValue())) { - newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - values[index] = newValue; - } - return newValue; - } - + @Override public V supplyIfAbsent(double key, ObjectSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -490,26 +452,7 @@ public V supplyIfAbsent(double key, ObjectSupplier valueProvider) { } return newValue; } - - @Override - public V supplyIfAbsentNonDefault(double key, ObjectSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - int index = findIndex(key); - if(index == -1) { - V newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insertIndex(size++, key, newValue); - return newValue; - } - V newValue = values[index]; - if(Objects.equals(newValue, getDefaultReturnValue())) { - newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - values[index] = newValue; - } - return newValue; - } - + @Override public V computeIfPresent(double key, DoubleObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -524,20 +467,6 @@ public V computeIfPresent(double key, DoubleObjectUnaryOperator mappingFuncti return newValue; } - @Override - public V computeIfPresentNonDefault(double key, DoubleObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1 || Objects.equals(values[index], getDefaultReturnValue())) return getDefaultReturnValue(); - V newValue = mappingFunction.apply(key, values[index]); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; - return newValue; - } - @Override public V merge(double key, V value, ObjectObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/misc/Double2ShortArrayMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/misc/Double2ShortArrayMap.java index b5fd846f..1c45eb95 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/misc/Double2ShortArrayMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/misc/Double2ShortArrayMap.java @@ -443,66 +443,76 @@ public short computeShort(double key, DoubleShortUnaryOperator mappingFunction) } @Override - public short computeShortNonDefault(double key, DoubleShortUnaryOperator mappingFunction) { + public short computeShortIfAbsent(double key, Double2ShortFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + short newValue = mappingFunction.applyAsShort(key); insertIndex(size++, key, newValue); return newValue; } - short newValue = mappingFunction.applyAsShort(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + short newValue = values[index]; return newValue; } - + @Override - public short computeShortIfAbsent(double key, Double2ShortFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public short supplyShortIfAbsent(double key, ShortSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = valueProvider.getAsShort(); insertIndex(size++, key, newValue); return newValue; } short newValue = values[index]; return newValue; } + + @Override + public short computeShortIfPresent(double key, DoubleShortUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index == -1) return getDefaultReturnValue(); + short newValue = mappingFunction.applyAsShort(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public short computeShortIfAbsentNonDefault(double key, Double2ShortFunction mappingFunction) { + public short computeShortNonDefault(double key, DoubleShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } - short newValue = values[index]; + short newValue = mappingFunction.applyAsShort(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsShort(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public short supplyShortIfAbsent(double key, ShortSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public short computeShortIfAbsentNonDefault(double key, Double2ShortFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - short newValue = valueProvider.getAsInt(); + short newValue = mappingFunction.applyAsShort(key); + if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } short newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsShort(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -511,30 +521,20 @@ public short supplyShortIfAbsentNonDefault(double key, ShortSupplier valueProvid Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - short newValue = valueProvider.getAsInt(); + short newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } short newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public short computeShortIfPresent(double key, DoubleShortUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) return getDefaultReturnValue(); - short newValue = mappingFunction.applyAsShort(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public short computeShortIfPresentNonDefault(double key, DoubleShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2BooleanAVLTreeMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2BooleanAVLTreeMap.java index eff5cec3..ac6e582b 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2BooleanAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2BooleanAVLTreeMap.java @@ -396,34 +396,56 @@ public boolean computeBoolean(double key, DoubleBooleanUnaryOperator mappingFunc } @Override - public boolean computeBooleanNonDefault(double key, DoubleBooleanUnaryOperator mappingFunction) { + public boolean computeBooleanIfAbsent(double key, DoublePredicate mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + boolean newValue = mappingFunction.test(key); put(key, newValue); return newValue; } - boolean newValue = mappingFunction.applyAsBoolean(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public boolean supplyBooleanIfAbsent(double key, BooleanSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + boolean newValue = valueProvider.getAsBoolean(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public boolean computeBooleanIfPresent(double key, DoubleBooleanUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + boolean newValue = mappingFunction.applyAsBoolean(key, entry.value); entry.value = newValue; return newValue; } @Override - public boolean computeBooleanIfAbsent(double key, DoublePredicate mappingFunction) { + public boolean computeBooleanNonDefault(double key, DoubleBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - boolean newValue = mappingFunction.test(key); + boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + boolean newValue = mappingFunction.applyAsBoolean(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -444,18 +466,6 @@ public boolean computeBooleanIfAbsentNonDefault(double key, DoublePredicate mapp return entry.value; } - @Override - public boolean supplyBooleanIfAbsent(double key, BooleanSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - boolean newValue = valueProvider.getAsBoolean(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public boolean supplyBooleanIfAbsentNonDefault(double key, BooleanSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -474,16 +484,6 @@ public boolean supplyBooleanIfAbsentNonDefault(double key, BooleanSupplier value return entry.value; } - @Override - public boolean computeBooleanIfPresent(double key, DoubleBooleanUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - boolean newValue = mappingFunction.applyAsBoolean(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public boolean computeBooleanIfPresentNonDefault(double key, DoubleBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1487,14 +1487,9 @@ public boolean computeBooleanIfPresent(double key, DoubleBooleanUnaryOperator ma Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - boolean newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2BooleanRBTreeMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2BooleanRBTreeMap.java index 2339aa95..4142677b 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2BooleanRBTreeMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2BooleanRBTreeMap.java @@ -395,34 +395,56 @@ public boolean computeBoolean(double key, DoubleBooleanUnaryOperator mappingFunc } @Override - public boolean computeBooleanNonDefault(double key, DoubleBooleanUnaryOperator mappingFunction) { + public boolean computeBooleanIfAbsent(double key, DoublePredicate mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + boolean newValue = mappingFunction.test(key); put(key, newValue); return newValue; } - boolean newValue = mappingFunction.applyAsBoolean(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public boolean supplyBooleanIfAbsent(double key, BooleanSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + boolean newValue = valueProvider.getAsBoolean(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public boolean computeBooleanIfPresent(double key, DoubleBooleanUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + boolean newValue = mappingFunction.applyAsBoolean(key, entry.value); entry.value = newValue; return newValue; } @Override - public boolean computeBooleanIfAbsent(double key, DoublePredicate mappingFunction) { + public boolean computeBooleanNonDefault(double key, DoubleBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - boolean newValue = mappingFunction.test(key); + boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + boolean newValue = mappingFunction.applyAsBoolean(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -443,18 +465,6 @@ public boolean computeBooleanIfAbsentNonDefault(double key, DoublePredicate mapp return entry.value; } - @Override - public boolean supplyBooleanIfAbsent(double key, BooleanSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - boolean newValue = valueProvider.getAsBoolean(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public boolean supplyBooleanIfAbsentNonDefault(double key, BooleanSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -473,16 +483,6 @@ public boolean supplyBooleanIfAbsentNonDefault(double key, BooleanSupplier value return entry.value; } - @Override - public boolean computeBooleanIfPresent(double key, DoubleBooleanUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - boolean newValue = mappingFunction.applyAsBoolean(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public boolean computeBooleanIfPresentNonDefault(double key, DoubleBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1550,14 +1550,9 @@ public boolean computeBooleanIfPresent(double key, DoubleBooleanUnaryOperator ma Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - boolean newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2ByteAVLTreeMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2ByteAVLTreeMap.java index d4f51bda..bd4f3e8b 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2ByteAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2ByteAVLTreeMap.java @@ -455,34 +455,56 @@ public byte computeByte(double key, DoubleByteUnaryOperator mappingFunction) { } @Override - public byte computeByteNonDefault(double key, DoubleByteUnaryOperator mappingFunction) { + public byte computeByteIfAbsent(double key, Double2ByteFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + byte newValue = mappingFunction.applyAsByte(key); put(key, newValue); return newValue; } - byte newValue = mappingFunction.applyAsByte(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public byte supplyByteIfAbsent(double key, ByteSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + byte newValue = valueProvider.getAsByte(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public byte computeByteIfPresent(double key, DoubleByteUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + byte newValue = mappingFunction.applyAsByte(key, entry.value); entry.value = newValue; return newValue; } @Override - public byte computeByteIfAbsent(double key, Double2ByteFunction mappingFunction) { + public byte computeByteNonDefault(double key, DoubleByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + byte newValue = mappingFunction.applyAsByte(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -503,46 +525,24 @@ public byte computeByteIfAbsentNonDefault(double key, Double2ByteFunction mappin return entry.value; } - @Override - public byte supplyByteIfAbsent(double key, ByteSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - byte newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public byte supplyByteIfAbsentNonDefault(double key, ByteSupplier valueProvider) { Objects.requireNonNull(valueProvider); Node entry = findNode(key); if(entry == null) { - byte newValue = valueProvider.getAsInt(); + byte newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } if(entry.value == getDefaultReturnValue()) { - byte newValue = valueProvider.getAsInt(); + byte newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; entry.value = newValue; } return entry.value; } - @Override - public byte computeByteIfPresent(double key, DoubleByteUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - byte newValue = mappingFunction.applyAsByte(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public byte computeByteIfPresentNonDefault(double key, DoubleByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1558,14 +1558,9 @@ public byte computeByteIfPresent(double key, DoubleByteUnaryOperator mappingFunc Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - byte newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2ByteRBTreeMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2ByteRBTreeMap.java index 640bb3e8..9af6023e 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2ByteRBTreeMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2ByteRBTreeMap.java @@ -454,34 +454,56 @@ public byte computeByte(double key, DoubleByteUnaryOperator mappingFunction) { } @Override - public byte computeByteNonDefault(double key, DoubleByteUnaryOperator mappingFunction) { + public byte computeByteIfAbsent(double key, Double2ByteFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + byte newValue = mappingFunction.applyAsByte(key); put(key, newValue); return newValue; } - byte newValue = mappingFunction.applyAsByte(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public byte supplyByteIfAbsent(double key, ByteSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + byte newValue = valueProvider.getAsByte(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public byte computeByteIfPresent(double key, DoubleByteUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + byte newValue = mappingFunction.applyAsByte(key, entry.value); entry.value = newValue; return newValue; } @Override - public byte computeByteIfAbsent(double key, Double2ByteFunction mappingFunction) { + public byte computeByteNonDefault(double key, DoubleByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + byte newValue = mappingFunction.applyAsByte(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -502,46 +524,24 @@ public byte computeByteIfAbsentNonDefault(double key, Double2ByteFunction mappin return entry.value; } - @Override - public byte supplyByteIfAbsent(double key, ByteSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - byte newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public byte supplyByteIfAbsentNonDefault(double key, ByteSupplier valueProvider) { Objects.requireNonNull(valueProvider); Node entry = findNode(key); if(entry == null) { - byte newValue = valueProvider.getAsInt(); + byte newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } if(entry.value == getDefaultReturnValue()) { - byte newValue = valueProvider.getAsInt(); + byte newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; entry.value = newValue; } return entry.value; } - @Override - public byte computeByteIfPresent(double key, DoubleByteUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - byte newValue = mappingFunction.applyAsByte(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public byte computeByteIfPresentNonDefault(double key, DoubleByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1621,14 +1621,9 @@ public byte computeByteIfPresent(double key, DoubleByteUnaryOperator mappingFunc Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - byte newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2CharAVLTreeMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2CharAVLTreeMap.java index 2c1caed4..af5a99ce 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2CharAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2CharAVLTreeMap.java @@ -455,34 +455,56 @@ public char computeChar(double key, DoubleCharUnaryOperator mappingFunction) { } @Override - public char computeCharNonDefault(double key, DoubleCharUnaryOperator mappingFunction) { + public char computeCharIfAbsent(double key, Double2CharFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + char newValue = mappingFunction.applyAsChar(key); put(key, newValue); return newValue; } - char newValue = mappingFunction.applyAsChar(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public char supplyCharIfAbsent(double key, CharSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + char newValue = valueProvider.getAsChar(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public char computeCharIfPresent(double key, DoubleCharUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + char newValue = mappingFunction.applyAsChar(key, entry.value); entry.value = newValue; return newValue; } @Override - public char computeCharIfAbsent(double key, Double2CharFunction mappingFunction) { + public char computeCharNonDefault(double key, DoubleCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + char newValue = mappingFunction.applyAsChar(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -503,46 +525,24 @@ public char computeCharIfAbsentNonDefault(double key, Double2CharFunction mappin return entry.value; } - @Override - public char supplyCharIfAbsent(double key, CharSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - char newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public char supplyCharIfAbsentNonDefault(double key, CharSupplier valueProvider) { Objects.requireNonNull(valueProvider); Node entry = findNode(key); if(entry == null) { - char newValue = valueProvider.getAsInt(); + char newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } if(entry.value == getDefaultReturnValue()) { - char newValue = valueProvider.getAsInt(); + char newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; entry.value = newValue; } return entry.value; } - @Override - public char computeCharIfPresent(double key, DoubleCharUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - char newValue = mappingFunction.applyAsChar(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public char computeCharIfPresentNonDefault(double key, DoubleCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1558,14 +1558,9 @@ public char computeCharIfPresent(double key, DoubleCharUnaryOperator mappingFunc Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - char newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2CharRBTreeMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2CharRBTreeMap.java index 76ce3e06..905f2bf7 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2CharRBTreeMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2CharRBTreeMap.java @@ -454,34 +454,56 @@ public char computeChar(double key, DoubleCharUnaryOperator mappingFunction) { } @Override - public char computeCharNonDefault(double key, DoubleCharUnaryOperator mappingFunction) { + public char computeCharIfAbsent(double key, Double2CharFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + char newValue = mappingFunction.applyAsChar(key); put(key, newValue); return newValue; } - char newValue = mappingFunction.applyAsChar(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public char supplyCharIfAbsent(double key, CharSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + char newValue = valueProvider.getAsChar(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public char computeCharIfPresent(double key, DoubleCharUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + char newValue = mappingFunction.applyAsChar(key, entry.value); entry.value = newValue; return newValue; } @Override - public char computeCharIfAbsent(double key, Double2CharFunction mappingFunction) { + public char computeCharNonDefault(double key, DoubleCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + char newValue = mappingFunction.applyAsChar(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -502,46 +524,24 @@ public char computeCharIfAbsentNonDefault(double key, Double2CharFunction mappin return entry.value; } - @Override - public char supplyCharIfAbsent(double key, CharSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - char newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public char supplyCharIfAbsentNonDefault(double key, CharSupplier valueProvider) { Objects.requireNonNull(valueProvider); Node entry = findNode(key); if(entry == null) { - char newValue = valueProvider.getAsInt(); + char newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } if(entry.value == getDefaultReturnValue()) { - char newValue = valueProvider.getAsInt(); + char newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; entry.value = newValue; } return entry.value; } - @Override - public char computeCharIfPresent(double key, DoubleCharUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - char newValue = mappingFunction.applyAsChar(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public char computeCharIfPresentNonDefault(double key, DoubleCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1621,14 +1621,9 @@ public char computeCharIfPresent(double key, DoubleCharUnaryOperator mappingFunc Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - char newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2DoubleAVLTreeMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2DoubleAVLTreeMap.java index cade7f49..2c312fe7 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2DoubleAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2DoubleAVLTreeMap.java @@ -447,34 +447,56 @@ public double computeDouble(double key, DoubleDoubleUnaryOperator mappingFunctio } @Override - public double computeDoubleNonDefault(double key, DoubleDoubleUnaryOperator mappingFunction) { + public double computeDoubleIfAbsent(double key, DoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + double newValue = mappingFunction.applyAsDouble(key); put(key, newValue); return newValue; } - double newValue = mappingFunction.applyAsDouble(key, entry.value); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - removeNode(entry); + return entry.value; + } + + @Override + public double supplyDoubleIfAbsent(double key, DoubleSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + double newValue = valueProvider.getAsDouble(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public double computeDoubleIfPresent(double key, DoubleDoubleUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + double newValue = mappingFunction.applyAsDouble(key, entry.value); entry.value = newValue; return newValue; } @Override - public double computeDoubleIfAbsent(double key, DoubleUnaryOperator mappingFunction) { + public double computeDoubleNonDefault(double key, DoubleDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; put(key, newValue); return newValue; } - return entry.value; + double newValue = mappingFunction.applyAsDouble(key, entry.value); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -495,18 +517,6 @@ public double computeDoubleIfAbsentNonDefault(double key, DoubleUnaryOperator ma return entry.value; } - @Override - public double supplyDoubleIfAbsent(double key, DoubleSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - double newValue = valueProvider.getAsDouble(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public double supplyDoubleIfAbsentNonDefault(double key, DoubleSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -525,16 +535,6 @@ public double supplyDoubleIfAbsentNonDefault(double key, DoubleSupplier valuePro return entry.value; } - @Override - public double computeDoubleIfPresent(double key, DoubleDoubleUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - double newValue = mappingFunction.applyAsDouble(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public double computeDoubleIfPresentNonDefault(double key, DoubleDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1550,14 +1550,9 @@ public double computeDoubleIfPresent(double key, DoubleDoubleUnaryOperator mappi Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || Double.doubleToLongBits(entry.value) == Double.doubleToLongBits(getDefaultReturnValue())) return getDefaultReturnValue(); - double newValue = mappingFunction.apply(key, entry.value); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2DoubleRBTreeMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2DoubleRBTreeMap.java index f02200da..676ce581 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2DoubleRBTreeMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2DoubleRBTreeMap.java @@ -446,34 +446,56 @@ public double computeDouble(double key, DoubleDoubleUnaryOperator mappingFunctio } @Override - public double computeDoubleNonDefault(double key, DoubleDoubleUnaryOperator mappingFunction) { + public double computeDoubleIfAbsent(double key, DoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + double newValue = mappingFunction.applyAsDouble(key); put(key, newValue); return newValue; } - double newValue = mappingFunction.applyAsDouble(key, entry.value); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - removeNode(entry); + return entry.value; + } + + @Override + public double supplyDoubleIfAbsent(double key, DoubleSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + double newValue = valueProvider.getAsDouble(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public double computeDoubleIfPresent(double key, DoubleDoubleUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + double newValue = mappingFunction.applyAsDouble(key, entry.value); entry.value = newValue; return newValue; } @Override - public double computeDoubleIfAbsent(double key, DoubleUnaryOperator mappingFunction) { + public double computeDoubleNonDefault(double key, DoubleDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; put(key, newValue); return newValue; } - return entry.value; + double newValue = mappingFunction.applyAsDouble(key, entry.value); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -494,18 +516,6 @@ public double computeDoubleIfAbsentNonDefault(double key, DoubleUnaryOperator ma return entry.value; } - @Override - public double supplyDoubleIfAbsent(double key, DoubleSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - double newValue = valueProvider.getAsDouble(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public double supplyDoubleIfAbsentNonDefault(double key, DoubleSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -524,16 +534,6 @@ public double supplyDoubleIfAbsentNonDefault(double key, DoubleSupplier valuePro return entry.value; } - @Override - public double computeDoubleIfPresent(double key, DoubleDoubleUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - double newValue = mappingFunction.applyAsDouble(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public double computeDoubleIfPresentNonDefault(double key, DoubleDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1613,14 +1613,9 @@ public double computeDoubleIfPresent(double key, DoubleDoubleUnaryOperator mappi Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || Double.doubleToLongBits(entry.value) == Double.doubleToLongBits(getDefaultReturnValue())) return getDefaultReturnValue(); - double newValue = mappingFunction.apply(key, entry.value); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2FloatAVLTreeMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2FloatAVLTreeMap.java index 38351e07..80c41b00 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2FloatAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2FloatAVLTreeMap.java @@ -455,34 +455,56 @@ public float computeFloat(double key, DoubleFloatUnaryOperator mappingFunction) } @Override - public float computeFloatNonDefault(double key, DoubleFloatUnaryOperator mappingFunction) { + public float computeFloatIfAbsent(double key, Double2FloatFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + float newValue = mappingFunction.applyAsFloat(key); put(key, newValue); return newValue; } - float newValue = mappingFunction.applyAsFloat(key, entry.value); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - removeNode(entry); + return entry.value; + } + + @Override + public float supplyFloatIfAbsent(double key, FloatSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + float newValue = valueProvider.getAsFloat(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public float computeFloatIfPresent(double key, DoubleFloatUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + float newValue = mappingFunction.applyAsFloat(key, entry.value); entry.value = newValue; return newValue; } @Override - public float computeFloatIfAbsent(double key, Double2FloatFunction mappingFunction) { + public float computeFloatNonDefault(double key, DoubleFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; put(key, newValue); return newValue; } - return entry.value; + float newValue = mappingFunction.applyAsFloat(key, entry.value); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -503,46 +525,24 @@ public float computeFloatIfAbsentNonDefault(double key, Double2FloatFunction map return entry.value; } - @Override - public float supplyFloatIfAbsent(double key, FloatSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - float newValue = valueProvider.getAsDouble(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public float supplyFloatIfAbsentNonDefault(double key, FloatSupplier valueProvider) { Objects.requireNonNull(valueProvider); Node entry = findNode(key); if(entry == null) { - float newValue = valueProvider.getAsDouble(); + float newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; put(key, newValue); return newValue; } if(Float.floatToIntBits(entry.value) == Float.floatToIntBits(getDefaultReturnValue())) { - float newValue = valueProvider.getAsDouble(); + float newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; entry.value = newValue; } return entry.value; } - @Override - public float computeFloatIfPresent(double key, DoubleFloatUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - float newValue = mappingFunction.applyAsFloat(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public float computeFloatIfPresentNonDefault(double key, DoubleFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1558,14 +1558,9 @@ public float computeFloatIfPresent(double key, DoubleFloatUnaryOperator mappingF Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || Float.floatToIntBits(entry.value) == Float.floatToIntBits(getDefaultReturnValue())) return getDefaultReturnValue(); - float newValue = mappingFunction.apply(key, entry.value); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2FloatRBTreeMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2FloatRBTreeMap.java index acd4ee05..a21dc4f2 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2FloatRBTreeMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2FloatRBTreeMap.java @@ -454,34 +454,56 @@ public float computeFloat(double key, DoubleFloatUnaryOperator mappingFunction) } @Override - public float computeFloatNonDefault(double key, DoubleFloatUnaryOperator mappingFunction) { + public float computeFloatIfAbsent(double key, Double2FloatFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + float newValue = mappingFunction.applyAsFloat(key); put(key, newValue); return newValue; } - float newValue = mappingFunction.applyAsFloat(key, entry.value); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - removeNode(entry); + return entry.value; + } + + @Override + public float supplyFloatIfAbsent(double key, FloatSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + float newValue = valueProvider.getAsFloat(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public float computeFloatIfPresent(double key, DoubleFloatUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + float newValue = mappingFunction.applyAsFloat(key, entry.value); entry.value = newValue; return newValue; } @Override - public float computeFloatIfAbsent(double key, Double2FloatFunction mappingFunction) { + public float computeFloatNonDefault(double key, DoubleFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; put(key, newValue); return newValue; } - return entry.value; + float newValue = mappingFunction.applyAsFloat(key, entry.value); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -502,46 +524,24 @@ public float computeFloatIfAbsentNonDefault(double key, Double2FloatFunction map return entry.value; } - @Override - public float supplyFloatIfAbsent(double key, FloatSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - float newValue = valueProvider.getAsDouble(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public float supplyFloatIfAbsentNonDefault(double key, FloatSupplier valueProvider) { Objects.requireNonNull(valueProvider); Node entry = findNode(key); if(entry == null) { - float newValue = valueProvider.getAsDouble(); + float newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; put(key, newValue); return newValue; } if(Float.floatToIntBits(entry.value) == Float.floatToIntBits(getDefaultReturnValue())) { - float newValue = valueProvider.getAsDouble(); + float newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; entry.value = newValue; } return entry.value; } - @Override - public float computeFloatIfPresent(double key, DoubleFloatUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - float newValue = mappingFunction.applyAsFloat(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public float computeFloatIfPresentNonDefault(double key, DoubleFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1621,14 +1621,9 @@ public float computeFloatIfPresent(double key, DoubleFloatUnaryOperator mappingF Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || Float.floatToIntBits(entry.value) == Float.floatToIntBits(getDefaultReturnValue())) return getDefaultReturnValue(); - float newValue = mappingFunction.apply(key, entry.value); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2IntAVLTreeMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2IntAVLTreeMap.java index e4d31625..5e347978 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2IntAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2IntAVLTreeMap.java @@ -455,34 +455,56 @@ public int computeInt(double key, DoubleIntUnaryOperator mappingFunction) { } @Override - public int computeIntNonDefault(double key, DoubleIntUnaryOperator mappingFunction) { + public int computeIntIfAbsent(double key, Double2IntFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + int newValue = mappingFunction.applyAsInt(key); put(key, newValue); return newValue; } - int newValue = mappingFunction.applyAsInt(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public int supplyIntIfAbsent(double key, IntSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + int newValue = valueProvider.getAsInt(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public int computeIntIfPresent(double key, DoubleIntUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + int newValue = mappingFunction.applyAsInt(key, entry.value); entry.value = newValue; return newValue; } @Override - public int computeIntIfAbsent(double key, Double2IntFunction mappingFunction) { + public int computeIntNonDefault(double key, DoubleIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + int newValue = mappingFunction.applyAsInt(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -503,18 +525,6 @@ public int computeIntIfAbsentNonDefault(double key, Double2IntFunction mappingFu return entry.value; } - @Override - public int supplyIntIfAbsent(double key, IntSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - int newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public int supplyIntIfAbsentNonDefault(double key, IntSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -533,16 +543,6 @@ public int supplyIntIfAbsentNonDefault(double key, IntSupplier valueProvider) { return entry.value; } - @Override - public int computeIntIfPresent(double key, DoubleIntUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - int newValue = mappingFunction.applyAsInt(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public int computeIntIfPresentNonDefault(double key, DoubleIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1558,14 +1558,9 @@ public int computeIntIfPresent(double key, DoubleIntUnaryOperator mappingFunctio Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - int newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2IntRBTreeMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2IntRBTreeMap.java index fa20ce7c..6897e52c 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2IntRBTreeMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2IntRBTreeMap.java @@ -454,34 +454,56 @@ public int computeInt(double key, DoubleIntUnaryOperator mappingFunction) { } @Override - public int computeIntNonDefault(double key, DoubleIntUnaryOperator mappingFunction) { + public int computeIntIfAbsent(double key, Double2IntFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + int newValue = mappingFunction.applyAsInt(key); put(key, newValue); return newValue; } - int newValue = mappingFunction.applyAsInt(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public int supplyIntIfAbsent(double key, IntSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + int newValue = valueProvider.getAsInt(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public int computeIntIfPresent(double key, DoubleIntUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + int newValue = mappingFunction.applyAsInt(key, entry.value); entry.value = newValue; return newValue; } @Override - public int computeIntIfAbsent(double key, Double2IntFunction mappingFunction) { + public int computeIntNonDefault(double key, DoubleIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + int newValue = mappingFunction.applyAsInt(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -502,18 +524,6 @@ public int computeIntIfAbsentNonDefault(double key, Double2IntFunction mappingFu return entry.value; } - @Override - public int supplyIntIfAbsent(double key, IntSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - int newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public int supplyIntIfAbsentNonDefault(double key, IntSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -532,16 +542,6 @@ public int supplyIntIfAbsentNonDefault(double key, IntSupplier valueProvider) { return entry.value; } - @Override - public int computeIntIfPresent(double key, DoubleIntUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - int newValue = mappingFunction.applyAsInt(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public int computeIntIfPresentNonDefault(double key, DoubleIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1621,14 +1621,9 @@ public int computeIntIfPresent(double key, DoubleIntUnaryOperator mappingFunctio Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - int newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2LongAVLTreeMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2LongAVLTreeMap.java index b9001bd4..96e966fe 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2LongAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2LongAVLTreeMap.java @@ -455,34 +455,56 @@ public long computeLong(double key, DoubleLongUnaryOperator mappingFunction) { } @Override - public long computeLongNonDefault(double key, DoubleLongUnaryOperator mappingFunction) { + public long computeLongIfAbsent(double key, Double2LongFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + long newValue = mappingFunction.applyAsLong(key); put(key, newValue); return newValue; } - long newValue = mappingFunction.applyAsLong(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public long supplyLongIfAbsent(double key, LongSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + long newValue = valueProvider.getAsLong(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public long computeLongIfPresent(double key, DoubleLongUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + long newValue = mappingFunction.applyAsLong(key, entry.value); entry.value = newValue; return newValue; } @Override - public long computeLongIfAbsent(double key, Double2LongFunction mappingFunction) { + public long computeLongNonDefault(double key, DoubleLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + long newValue = mappingFunction.applyAsLong(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -503,18 +525,6 @@ public long computeLongIfAbsentNonDefault(double key, Double2LongFunction mappin return entry.value; } - @Override - public long supplyLongIfAbsent(double key, LongSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - long newValue = valueProvider.getAsLong(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public long supplyLongIfAbsentNonDefault(double key, LongSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -533,16 +543,6 @@ public long supplyLongIfAbsentNonDefault(double key, LongSupplier valueProvider) return entry.value; } - @Override - public long computeLongIfPresent(double key, DoubleLongUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - long newValue = mappingFunction.applyAsLong(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public long computeLongIfPresentNonDefault(double key, DoubleLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1558,14 +1558,9 @@ public long computeLongIfPresent(double key, DoubleLongUnaryOperator mappingFunc Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - long newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2LongRBTreeMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2LongRBTreeMap.java index 872019d3..3ee5cd07 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2LongRBTreeMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2LongRBTreeMap.java @@ -454,34 +454,56 @@ public long computeLong(double key, DoubleLongUnaryOperator mappingFunction) { } @Override - public long computeLongNonDefault(double key, DoubleLongUnaryOperator mappingFunction) { + public long computeLongIfAbsent(double key, Double2LongFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + long newValue = mappingFunction.applyAsLong(key); put(key, newValue); return newValue; } - long newValue = mappingFunction.applyAsLong(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public long supplyLongIfAbsent(double key, LongSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + long newValue = valueProvider.getAsLong(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public long computeLongIfPresent(double key, DoubleLongUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + long newValue = mappingFunction.applyAsLong(key, entry.value); entry.value = newValue; return newValue; } @Override - public long computeLongIfAbsent(double key, Double2LongFunction mappingFunction) { + public long computeLongNonDefault(double key, DoubleLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + long newValue = mappingFunction.applyAsLong(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -502,18 +524,6 @@ public long computeLongIfAbsentNonDefault(double key, Double2LongFunction mappin return entry.value; } - @Override - public long supplyLongIfAbsent(double key, LongSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - long newValue = valueProvider.getAsLong(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public long supplyLongIfAbsentNonDefault(double key, LongSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -532,16 +542,6 @@ public long supplyLongIfAbsentNonDefault(double key, LongSupplier valueProvider) return entry.value; } - @Override - public long computeLongIfPresent(double key, DoubleLongUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - long newValue = mappingFunction.applyAsLong(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public long computeLongIfPresentNonDefault(double key, DoubleLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1621,14 +1621,9 @@ public long computeLongIfPresent(double key, DoubleLongUnaryOperator mappingFunc Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - long newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2ObjectAVLTreeMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2ObjectAVLTreeMap.java index f7e3b5d3..ec5151d0 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2ObjectAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2ObjectAVLTreeMap.java @@ -395,25 +395,6 @@ public V compute(double key, DoubleObjectUnaryOperator mappingFunction) { return newValue; } - @Override - public V computeNonDefault(double key, DoubleObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) { - V newValue = mappingFunction.apply(key, getDefaultReturnValue()); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - put(key, newValue); - return newValue; - } - V newValue = mappingFunction.apply(key, entry.value); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; - } - @Override public V computeIfAbsent(double key, DoubleFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -432,24 +413,6 @@ public V computeIfAbsent(double key, DoubleFunction mappingFunction) { return entry.value; } - @Override - public V computeIfAbsentNonDefault(double key, DoubleFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) { - V newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - put(key, newValue); - return newValue; - } - if(Objects.equals(entry.value, getDefaultReturnValue())) { - V newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - entry.value = newValue; - } - return entry.value; - } - @Override public V supplyIfAbsent(double key, ObjectSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -468,24 +431,6 @@ public V supplyIfAbsent(double key, ObjectSupplier valueProvider) { return entry.value; } - @Override - public V supplyIfAbsentNonDefault(double key, ObjectSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - V newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - put(key, newValue); - return newValue; - } - if(Objects.equals(entry.value, getDefaultReturnValue())) { - V newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - entry.value = newValue; - } - return entry.value; - } - @Override public V computeIfPresent(double key, DoubleObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -500,20 +445,6 @@ public V computeIfPresent(double key, DoubleObjectUnaryOperator mappingFuncti return newValue; } - @Override - public V computeIfPresentNonDefault(double key, DoubleObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null || Objects.equals(entry.value, getDefaultReturnValue())) return getDefaultReturnValue(); - V newValue = mappingFunction.apply(key, entry.value); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; - } - @Override public V merge(double key, V value, ObjectObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2ObjectRBTreeMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2ObjectRBTreeMap.java index 76a91d08..bd1b93b6 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2ObjectRBTreeMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2ObjectRBTreeMap.java @@ -394,25 +394,6 @@ public V compute(double key, DoubleObjectUnaryOperator mappingFunction) { return newValue; } - @Override - public V computeNonDefault(double key, DoubleObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) { - V newValue = mappingFunction.apply(key, getDefaultReturnValue()); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - put(key, newValue); - return newValue; - } - V newValue = mappingFunction.apply(key, entry.value); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; - } - @Override public V computeIfAbsent(double key, DoubleFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -431,24 +412,6 @@ public V computeIfAbsent(double key, DoubleFunction mappingFunction) { return entry.value; } - @Override - public V computeIfAbsentNonDefault(double key, DoubleFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) { - V newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - put(key, newValue); - return newValue; - } - if(Objects.equals(entry.value, getDefaultReturnValue())) { - V newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - entry.value = newValue; - } - return entry.value; - } - @Override public V supplyIfAbsent(double key, ObjectSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -467,24 +430,6 @@ public V supplyIfAbsent(double key, ObjectSupplier valueProvider) { return entry.value; } - @Override - public V supplyIfAbsentNonDefault(double key, ObjectSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - V newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - put(key, newValue); - return newValue; - } - if(Objects.equals(entry.value, getDefaultReturnValue())) { - V newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - entry.value = newValue; - } - return entry.value; - } - @Override public V computeIfPresent(double key, DoubleObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -499,20 +444,6 @@ public V computeIfPresent(double key, DoubleObjectUnaryOperator mappingFuncti return newValue; } - @Override - public V computeIfPresentNonDefault(double key, DoubleObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null || Objects.equals(entry.value, getDefaultReturnValue())) return getDefaultReturnValue(); - V newValue = mappingFunction.apply(key, entry.value); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; - } - @Override public V merge(double key, V value, ObjectObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2ShortAVLTreeMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2ShortAVLTreeMap.java index ff433d0a..f58e437f 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2ShortAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2ShortAVLTreeMap.java @@ -455,34 +455,56 @@ public short computeShort(double key, DoubleShortUnaryOperator mappingFunction) } @Override - public short computeShortNonDefault(double key, DoubleShortUnaryOperator mappingFunction) { + public short computeShortIfAbsent(double key, Double2ShortFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + short newValue = mappingFunction.applyAsShort(key); put(key, newValue); return newValue; } - short newValue = mappingFunction.applyAsShort(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public short supplyShortIfAbsent(double key, ShortSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + short newValue = valueProvider.getAsShort(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public short computeShortIfPresent(double key, DoubleShortUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + short newValue = mappingFunction.applyAsShort(key, entry.value); entry.value = newValue; return newValue; } @Override - public short computeShortIfAbsent(double key, Double2ShortFunction mappingFunction) { + public short computeShortNonDefault(double key, DoubleShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + short newValue = mappingFunction.applyAsShort(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -503,46 +525,24 @@ public short computeShortIfAbsentNonDefault(double key, Double2ShortFunction map return entry.value; } - @Override - public short supplyShortIfAbsent(double key, ShortSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - short newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public short supplyShortIfAbsentNonDefault(double key, ShortSupplier valueProvider) { Objects.requireNonNull(valueProvider); Node entry = findNode(key); if(entry == null) { - short newValue = valueProvider.getAsInt(); + short newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } if(entry.value == getDefaultReturnValue()) { - short newValue = valueProvider.getAsInt(); + short newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; entry.value = newValue; } return entry.value; } - @Override - public short computeShortIfPresent(double key, DoubleShortUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - short newValue = mappingFunction.applyAsShort(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public short computeShortIfPresentNonDefault(double key, DoubleShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1558,14 +1558,9 @@ public short computeShortIfPresent(double key, DoubleShortUnaryOperator mappingF Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - short newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2ShortRBTreeMap.java b/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2ShortRBTreeMap.java index e0126774..419f4309 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2ShortRBTreeMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/impl/tree/Double2ShortRBTreeMap.java @@ -454,34 +454,56 @@ public short computeShort(double key, DoubleShortUnaryOperator mappingFunction) } @Override - public short computeShortNonDefault(double key, DoubleShortUnaryOperator mappingFunction) { + public short computeShortIfAbsent(double key, Double2ShortFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + short newValue = mappingFunction.applyAsShort(key); put(key, newValue); return newValue; } - short newValue = mappingFunction.applyAsShort(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public short supplyShortIfAbsent(double key, ShortSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + short newValue = valueProvider.getAsShort(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public short computeShortIfPresent(double key, DoubleShortUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + short newValue = mappingFunction.applyAsShort(key, entry.value); entry.value = newValue; return newValue; } @Override - public short computeShortIfAbsent(double key, Double2ShortFunction mappingFunction) { + public short computeShortNonDefault(double key, DoubleShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + short newValue = mappingFunction.applyAsShort(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -502,46 +524,24 @@ public short computeShortIfAbsentNonDefault(double key, Double2ShortFunction map return entry.value; } - @Override - public short supplyShortIfAbsent(double key, ShortSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - short newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public short supplyShortIfAbsentNonDefault(double key, ShortSupplier valueProvider) { Objects.requireNonNull(valueProvider); Node entry = findNode(key); if(entry == null) { - short newValue = valueProvider.getAsInt(); + short newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } if(entry.value == getDefaultReturnValue()) { - short newValue = valueProvider.getAsInt(); + short newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; entry.value = newValue; } return entry.value; } - @Override - public short computeShortIfPresent(double key, DoubleShortUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - short newValue = mappingFunction.applyAsShort(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public short computeShortIfPresentNonDefault(double key, DoubleShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1621,14 +1621,9 @@ public short computeShortIfPresent(double key, DoubleShortUnaryOperator mappingF Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - short newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/doubles/maps/interfaces/Double2BooleanMap.java b/src/main/java/speiger/src/collections/doubles/maps/interfaces/Double2BooleanMap.java index 039c840e..7a5dc214 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/interfaces/Double2BooleanMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/interfaces/Double2BooleanMap.java @@ -284,41 +284,51 @@ public default boolean remove(Object key, Object value) { */ public boolean computeBoolean(double key, DoubleBooleanUnaryOperator mappingFunction); /** - * A Type Specific compute method to reduce boxing/unboxing + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation + * @param mappingFunction the operator that should generate the value if not present + * @return the result of the computed value or present value */ - public boolean computeBooleanNonDefault(double key, DoubleBooleanUnaryOperator mappingFunction); + public boolean computeBooleanIfAbsent(double key, DoublePredicate mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present + * @param valueProvider the value if not present * @return the result of the computed value or present value + */ + public boolean supplyBooleanIfAbsent(double key, BooleanSupplier valueProvider); + /** + * A Type Specific compute method to reduce boxing/unboxing + * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". + * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. + * @param key the key that should be computed + * @param mappingFunction the operator that should generate the value if present + * @return the result of the default return value or present value + * @note if not present then compute is not executed */ - public boolean computeBooleanIfAbsent(double key, DoublePredicate mappingFunction); + public boolean computeBooleanIfPresent(double key, DoubleBooleanUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value + * @param mappingFunction the operator that should generate the value + * @return the result of the computation */ - public boolean computeBooleanIfAbsentNonDefault(double key, DoublePredicate mappingFunction); + public boolean computeBooleanNonDefault(double key, DoubleBooleanUnaryOperator mappingFunction); /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param valueProvider the value if not present + * @param mappingFunction the operator that should generate the value if not present * @return the result of the computed value or present value - */ - public boolean supplyBooleanIfAbsent(double key, BooleanSupplier valueProvider); + */ + public boolean computeBooleanIfAbsentNonDefault(double key, DoublePredicate mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -328,16 +338,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public boolean supplyBooleanIfAbsentNonDefault(double key, BooleanSupplier valueProvider); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public boolean computeBooleanIfPresent(double key, DoubleBooleanUnaryOperator mappingFunction); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/doubles/maps/interfaces/Double2ByteMap.java b/src/main/java/speiger/src/collections/doubles/maps/interfaces/Double2ByteMap.java index f040787d..91dbf284 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/interfaces/Double2ByteMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/interfaces/Double2ByteMap.java @@ -309,41 +309,51 @@ public default boolean remove(Object key, Object value) { */ public byte computeByte(double key, DoubleByteUnaryOperator mappingFunction); /** - * A Type Specific compute method to reduce boxing/unboxing + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation + * @param mappingFunction the operator that should generate the value if not present + * @return the result of the computed value or present value */ - public byte computeByteNonDefault(double key, DoubleByteUnaryOperator mappingFunction); + public byte computeByteIfAbsent(double key, Double2ByteFunction mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present + * @param valueProvider the value if not present * @return the result of the computed value or present value + */ + public byte supplyByteIfAbsent(double key, ByteSupplier valueProvider); + /** + * A Type Specific compute method to reduce boxing/unboxing + * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". + * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. + * @param key the key that should be computed + * @param mappingFunction the operator that should generate the value if present + * @return the result of the default return value or present value + * @note if not present then compute is not executed */ - public byte computeByteIfAbsent(double key, Double2ByteFunction mappingFunction); + public byte computeByteIfPresent(double key, DoubleByteUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value + * @param mappingFunction the operator that should generate the value + * @return the result of the computation */ - public byte computeByteIfAbsentNonDefault(double key, Double2ByteFunction mappingFunction); + public byte computeByteNonDefault(double key, DoubleByteUnaryOperator mappingFunction); /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param valueProvider the value if not present + * @param mappingFunction the operator that should generate the value if not present * @return the result of the computed value or present value - */ - public byte supplyByteIfAbsent(double key, ByteSupplier valueProvider); + */ + public byte computeByteIfAbsentNonDefault(double key, Double2ByteFunction mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -353,16 +363,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public byte supplyByteIfAbsentNonDefault(double key, ByteSupplier valueProvider); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public byte computeByteIfPresent(double key, DoubleByteUnaryOperator mappingFunction); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/doubles/maps/interfaces/Double2CharMap.java b/src/main/java/speiger/src/collections/doubles/maps/interfaces/Double2CharMap.java index 3fcae9f5..97d15e34 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/interfaces/Double2CharMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/interfaces/Double2CharMap.java @@ -309,41 +309,51 @@ public default boolean remove(Object key, Object value) { */ public char computeChar(double key, DoubleCharUnaryOperator mappingFunction); /** - * A Type Specific compute method to reduce boxing/unboxing + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation + * @param mappingFunction the operator that should generate the value if not present + * @return the result of the computed value or present value */ - public char computeCharNonDefault(double key, DoubleCharUnaryOperator mappingFunction); + public char computeCharIfAbsent(double key, Double2CharFunction mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present + * @param valueProvider the value if not present * @return the result of the computed value or present value + */ + public char supplyCharIfAbsent(double key, CharSupplier valueProvider); + /** + * A Type Specific compute method to reduce boxing/unboxing + * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". + * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. + * @param key the key that should be computed + * @param mappingFunction the operator that should generate the value if present + * @return the result of the default return value or present value + * @note if not present then compute is not executed */ - public char computeCharIfAbsent(double key, Double2CharFunction mappingFunction); + public char computeCharIfPresent(double key, DoubleCharUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value + * @param mappingFunction the operator that should generate the value + * @return the result of the computation */ - public char computeCharIfAbsentNonDefault(double key, Double2CharFunction mappingFunction); + public char computeCharNonDefault(double key, DoubleCharUnaryOperator mappingFunction); /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param valueProvider the value if not present + * @param mappingFunction the operator that should generate the value if not present * @return the result of the computed value or present value - */ - public char supplyCharIfAbsent(double key, CharSupplier valueProvider); + */ + public char computeCharIfAbsentNonDefault(double key, Double2CharFunction mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -353,16 +363,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public char supplyCharIfAbsentNonDefault(double key, CharSupplier valueProvider); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public char computeCharIfPresent(double key, DoubleCharUnaryOperator mappingFunction); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/doubles/maps/interfaces/Double2DoubleMap.java b/src/main/java/speiger/src/collections/doubles/maps/interfaces/Double2DoubleMap.java index 15f5cb36..f35a5315 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/interfaces/Double2DoubleMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/interfaces/Double2DoubleMap.java @@ -308,41 +308,51 @@ public default boolean remove(Object key, Object value) { */ public double computeDouble(double key, DoubleDoubleUnaryOperator mappingFunction); /** - * A Type Specific compute method to reduce boxing/unboxing + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation + * @param mappingFunction the operator that should generate the value if not present + * @return the result of the computed value or present value */ - public double computeDoubleNonDefault(double key, DoubleDoubleUnaryOperator mappingFunction); + public double computeDoubleIfAbsent(double key, DoubleUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present + * @param valueProvider the value if not present * @return the result of the computed value or present value + */ + public double supplyDoubleIfAbsent(double key, DoubleSupplier valueProvider); + /** + * A Type Specific compute method to reduce boxing/unboxing + * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". + * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. + * @param key the key that should be computed + * @param mappingFunction the operator that should generate the value if present + * @return the result of the default return value or present value + * @note if not present then compute is not executed */ - public double computeDoubleIfAbsent(double key, DoubleUnaryOperator mappingFunction); + public double computeDoubleIfPresent(double key, DoubleDoubleUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value + * @param mappingFunction the operator that should generate the value + * @return the result of the computation */ - public double computeDoubleIfAbsentNonDefault(double key, DoubleUnaryOperator mappingFunction); + public double computeDoubleNonDefault(double key, DoubleDoubleUnaryOperator mappingFunction); /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param valueProvider the value if not present + * @param mappingFunction the operator that should generate the value if not present * @return the result of the computed value or present value - */ - public double supplyDoubleIfAbsent(double key, DoubleSupplier valueProvider); + */ + public double computeDoubleIfAbsentNonDefault(double key, DoubleUnaryOperator mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -352,16 +362,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public double supplyDoubleIfAbsentNonDefault(double key, DoubleSupplier valueProvider); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public double computeDoubleIfPresent(double key, DoubleDoubleUnaryOperator mappingFunction); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/doubles/maps/interfaces/Double2FloatMap.java b/src/main/java/speiger/src/collections/doubles/maps/interfaces/Double2FloatMap.java index a6577399..8c6f5028 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/interfaces/Double2FloatMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/interfaces/Double2FloatMap.java @@ -309,41 +309,51 @@ public default boolean remove(Object key, Object value) { */ public float computeFloat(double key, DoubleFloatUnaryOperator mappingFunction); /** - * A Type Specific compute method to reduce boxing/unboxing + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation + * @param mappingFunction the operator that should generate the value if not present + * @return the result of the computed value or present value */ - public float computeFloatNonDefault(double key, DoubleFloatUnaryOperator mappingFunction); + public float computeFloatIfAbsent(double key, Double2FloatFunction mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present + * @param valueProvider the value if not present * @return the result of the computed value or present value + */ + public float supplyFloatIfAbsent(double key, FloatSupplier valueProvider); + /** + * A Type Specific compute method to reduce boxing/unboxing + * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". + * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. + * @param key the key that should be computed + * @param mappingFunction the operator that should generate the value if present + * @return the result of the default return value or present value + * @note if not present then compute is not executed */ - public float computeFloatIfAbsent(double key, Double2FloatFunction mappingFunction); + public float computeFloatIfPresent(double key, DoubleFloatUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value + * @param mappingFunction the operator that should generate the value + * @return the result of the computation */ - public float computeFloatIfAbsentNonDefault(double key, Double2FloatFunction mappingFunction); + public float computeFloatNonDefault(double key, DoubleFloatUnaryOperator mappingFunction); /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param valueProvider the value if not present + * @param mappingFunction the operator that should generate the value if not present * @return the result of the computed value or present value - */ - public float supplyFloatIfAbsent(double key, FloatSupplier valueProvider); + */ + public float computeFloatIfAbsentNonDefault(double key, Double2FloatFunction mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -353,16 +363,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public float supplyFloatIfAbsentNonDefault(double key, FloatSupplier valueProvider); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public float computeFloatIfPresent(double key, DoubleFloatUnaryOperator mappingFunction); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/doubles/maps/interfaces/Double2IntMap.java b/src/main/java/speiger/src/collections/doubles/maps/interfaces/Double2IntMap.java index 61039efd..1a79d674 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/interfaces/Double2IntMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/interfaces/Double2IntMap.java @@ -309,41 +309,51 @@ public default boolean remove(Object key, Object value) { */ public int computeInt(double key, DoubleIntUnaryOperator mappingFunction); /** - * A Type Specific compute method to reduce boxing/unboxing + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation + * @param mappingFunction the operator that should generate the value if not present + * @return the result of the computed value or present value */ - public int computeIntNonDefault(double key, DoubleIntUnaryOperator mappingFunction); + public int computeIntIfAbsent(double key, Double2IntFunction mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present + * @param valueProvider the value if not present * @return the result of the computed value or present value + */ + public int supplyIntIfAbsent(double key, IntSupplier valueProvider); + /** + * A Type Specific compute method to reduce boxing/unboxing + * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". + * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. + * @param key the key that should be computed + * @param mappingFunction the operator that should generate the value if present + * @return the result of the default return value or present value + * @note if not present then compute is not executed */ - public int computeIntIfAbsent(double key, Double2IntFunction mappingFunction); + public int computeIntIfPresent(double key, DoubleIntUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value + * @param mappingFunction the operator that should generate the value + * @return the result of the computation */ - public int computeIntIfAbsentNonDefault(double key, Double2IntFunction mappingFunction); + public int computeIntNonDefault(double key, DoubleIntUnaryOperator mappingFunction); /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param valueProvider the value if not present + * @param mappingFunction the operator that should generate the value if not present * @return the result of the computed value or present value - */ - public int supplyIntIfAbsent(double key, IntSupplier valueProvider); + */ + public int computeIntIfAbsentNonDefault(double key, Double2IntFunction mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -353,16 +363,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public int supplyIntIfAbsentNonDefault(double key, IntSupplier valueProvider); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public int computeIntIfPresent(double key, DoubleIntUnaryOperator mappingFunction); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/doubles/maps/interfaces/Double2LongMap.java b/src/main/java/speiger/src/collections/doubles/maps/interfaces/Double2LongMap.java index 80924de4..9db6cb37 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/interfaces/Double2LongMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/interfaces/Double2LongMap.java @@ -309,41 +309,51 @@ public default boolean remove(Object key, Object value) { */ public long computeLong(double key, DoubleLongUnaryOperator mappingFunction); /** - * A Type Specific compute method to reduce boxing/unboxing + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation + * @param mappingFunction the operator that should generate the value if not present + * @return the result of the computed value or present value */ - public long computeLongNonDefault(double key, DoubleLongUnaryOperator mappingFunction); + public long computeLongIfAbsent(double key, Double2LongFunction mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present + * @param valueProvider the value if not present * @return the result of the computed value or present value + */ + public long supplyLongIfAbsent(double key, LongSupplier valueProvider); + /** + * A Type Specific compute method to reduce boxing/unboxing + * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". + * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. + * @param key the key that should be computed + * @param mappingFunction the operator that should generate the value if present + * @return the result of the default return value or present value + * @note if not present then compute is not executed */ - public long computeLongIfAbsent(double key, Double2LongFunction mappingFunction); + public long computeLongIfPresent(double key, DoubleLongUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value + * @param mappingFunction the operator that should generate the value + * @return the result of the computation */ - public long computeLongIfAbsentNonDefault(double key, Double2LongFunction mappingFunction); + public long computeLongNonDefault(double key, DoubleLongUnaryOperator mappingFunction); /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param valueProvider the value if not present + * @param mappingFunction the operator that should generate the value if not present * @return the result of the computed value or present value - */ - public long supplyLongIfAbsent(double key, LongSupplier valueProvider); + */ + public long computeLongIfAbsentNonDefault(double key, Double2LongFunction mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -353,16 +363,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public long supplyLongIfAbsentNonDefault(double key, LongSupplier valueProvider); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public long computeLongIfPresent(double key, DoubleLongUnaryOperator mappingFunction); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/doubles/maps/interfaces/Double2ObjectMap.java b/src/main/java/speiger/src/collections/doubles/maps/interfaces/Double2ObjectMap.java index e4cb80c8..52ff5d06 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/interfaces/Double2ObjectMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/interfaces/Double2ObjectMap.java @@ -266,15 +266,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computation */ public V compute(double key, DoubleObjectUnaryOperator mappingFunction); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation - */ - public V computeNonDefault(double key, DoubleObjectUnaryOperator mappingFunction); /** * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -284,15 +275,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public V computeIfAbsent(double key, DoubleFunction mappingFunction); - /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value - */ - public V computeIfAbsentNonDefault(double key, DoubleFunction mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -302,15 +284,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public V supplyIfAbsent(double key, ObjectSupplier valueProvider); - /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param valueProvider the value if not present - * @return the result of the computed value or present value - */ - public V supplyIfAbsentNonDefault(double key, ObjectSupplier valueProvider); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -321,16 +294,6 @@ public default boolean remove(Object key, Object value) { * @note if not present then compute is not executed */ public V computeIfPresent(double key, DoubleObjectUnaryOperator mappingFunction); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public V computeIfPresentNonDefault(double key, DoubleObjectUnaryOperator mappingFunction); /** * A Type Specific merge method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/doubles/maps/interfaces/Double2ShortMap.java b/src/main/java/speiger/src/collections/doubles/maps/interfaces/Double2ShortMap.java index f4a3cd51..e196423b 100644 --- a/src/main/java/speiger/src/collections/doubles/maps/interfaces/Double2ShortMap.java +++ b/src/main/java/speiger/src/collections/doubles/maps/interfaces/Double2ShortMap.java @@ -309,41 +309,51 @@ public default boolean remove(Object key, Object value) { */ public short computeShort(double key, DoubleShortUnaryOperator mappingFunction); /** - * A Type Specific compute method to reduce boxing/unboxing + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation + * @param mappingFunction the operator that should generate the value if not present + * @return the result of the computed value or present value */ - public short computeShortNonDefault(double key, DoubleShortUnaryOperator mappingFunction); + public short computeShortIfAbsent(double key, Double2ShortFunction mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present + * @param valueProvider the value if not present * @return the result of the computed value or present value + */ + public short supplyShortIfAbsent(double key, ShortSupplier valueProvider); + /** + * A Type Specific compute method to reduce boxing/unboxing + * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". + * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. + * @param key the key that should be computed + * @param mappingFunction the operator that should generate the value if present + * @return the result of the default return value or present value + * @note if not present then compute is not executed */ - public short computeShortIfAbsent(double key, Double2ShortFunction mappingFunction); + public short computeShortIfPresent(double key, DoubleShortUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value + * @param mappingFunction the operator that should generate the value + * @return the result of the computation */ - public short computeShortIfAbsentNonDefault(double key, Double2ShortFunction mappingFunction); + public short computeShortNonDefault(double key, DoubleShortUnaryOperator mappingFunction); /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param valueProvider the value if not present + * @param mappingFunction the operator that should generate the value if not present * @return the result of the computed value or present value - */ - public short supplyShortIfAbsent(double key, ShortSupplier valueProvider); + */ + public short computeShortIfAbsentNonDefault(double key, Double2ShortFunction mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -353,16 +363,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public short supplyShortIfAbsentNonDefault(double key, ShortSupplier valueProvider); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public short computeShortIfPresent(double key, DoubleShortUnaryOperator mappingFunction); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/doubles/queues/DoubleArrayFIFOQueue.java b/src/main/java/speiger/src/collections/doubles/queues/DoubleArrayFIFOQueue.java index 8d60339b..f9ba1b35 100644 --- a/src/main/java/speiger/src/collections/doubles/queues/DoubleArrayFIFOQueue.java +++ b/src/main/java/speiger/src/collections/doubles/queues/DoubleArrayFIFOQueue.java @@ -146,6 +146,15 @@ public double peek(int index) { return index >= array.length ? array[index-array.length] : array[index]; } + @Override + public boolean contains(double e) { + if(first == last) return false; + for(int i = 0,m=size();i iterator, int rep return new RepeatingIterator(wrap(iterator), repeats); } + /** + * A Helper function that creates a infinitely looping iterator + * @param iterator that should be looping infinitely + * @return a infinitely looping iterator + */ + public static DoubleIterator infinite(DoubleIterator iterator) { + return new InfiniteIterator(iterator); + } + + /** + * A Helper function that creates a infinitely looping iterator from a Java Iterator + * @param iterator that should be looping infinitely + * @return a infinitely looping iterator + */ + public static DoubleIterator infinite(Iterator iterator) { + return new InfiniteIterator(wrap(iterator)); + } + /** * A Helper function that hard limits the Iterator to a specific size * @param iterator that should be limited @@ -841,6 +862,40 @@ public T next() { } } + private static class InfiniteIterator implements DoubleIterator + { + DoubleIterator iter; + CollectionWrapper looper = DoubleCollections.wrapper(); + int index = 0; + + public InfiniteIterator(DoubleIterator iter) { + this.iter = iter; + } + + @Override + public boolean hasNext() { + return true; + } + + @Override + public double nextDouble() { + if(iter != null) { + if(iter.hasNext()) { + double value = iter.nextDouble(); + looper.add(value); + return value; + } + else iter = null; + } + return looper.getDouble((index++) % looper.size()); + } + + @Override + public void forEachRemaining(DoubleConsumer action) { throw new UnsupportedOperationException("This is a instant deadlock, so unsupported"); } + public void forEachRemaining(Consumer action) { throw new UnsupportedOperationException("This is a instant deadlock, so unsupported"); } + public void forEachRemaining(E input, ObjectDoubleConsumer action) { throw new UnsupportedOperationException("This is a instant deadlock, so unsupported"); } + } + private static class RepeatingIterator implements DoubleIterator { final int repeats; diff --git a/src/main/java/speiger/src/collections/doubles/utils/DoubleLists.java b/src/main/java/speiger/src/collections/doubles/utils/DoubleLists.java index 0361ba07..78e94322 100644 --- a/src/main/java/speiger/src/collections/doubles/utils/DoubleLists.java +++ b/src/main/java/speiger/src/collections/doubles/utils/DoubleLists.java @@ -12,6 +12,7 @@ import speiger.src.collections.doubles.functions.DoubleConsumer; import speiger.src.collections.doubles.lists.AbstractDoubleList; import speiger.src.collections.doubles.lists.DoubleList; +import speiger.src.collections.ints.lists.IntList; import speiger.src.collections.doubles.lists.DoubleListIterator; import speiger.src.collections.utils.SanityChecks; @@ -317,6 +318,16 @@ public DoubleListIterator listIterator(int index) { return l.listIterator(index); } + @Override + public DoubleListIterator indexedIterator(int...indecies) { + return l.indexedIterator(indecies); + } + + @Override + public DoubleListIterator indexedIterator(IntList indecies) { + return l.indexedIterator(indecies); + } + @Override public DoubleList subList(int from, int to) { return DoubleLists.synchronize(l.subList(from, to)); @@ -426,6 +437,16 @@ public DoubleListIterator listIterator(int index) { return DoubleIterators.unmodifiable(l.listIterator(index)); } + @Override + public DoubleListIterator indexedIterator(int...indecies) { + return DoubleIterators.unmodifiable(l.indexedIterator(indecies)); + } + + @Override + public DoubleListIterator indexedIterator(IntList indecies) { + return DoubleIterators.unmodifiable(l.indexedIterator(indecies)); + } + @Override public DoubleList subList(int from, int to) { return DoubleLists.unmodifiable(l.subList(from, to)); @@ -514,6 +535,16 @@ public DoubleListIterator listIterator(int index) { return DoubleIterators.empty(); } + @Override + public DoubleListIterator indexedIterator(int...indecies) { + return DoubleIterators.empty(); + } + + @Override + public DoubleListIterator indexedIterator(IntList indecies) { + return DoubleIterators.empty(); + } + @Override public int hashCode() { return 1; } diff --git a/src/main/java/speiger/src/collections/doubles/utils/DoublePriorityQueues.java b/src/main/java/speiger/src/collections/doubles/utils/DoublePriorityQueues.java index 6ecde3b6..3bdba4bc 100644 --- a/src/main/java/speiger/src/collections/doubles/utils/DoublePriorityQueues.java +++ b/src/main/java/speiger/src/collections/doubles/utils/DoublePriorityQueues.java @@ -89,6 +89,8 @@ protected SynchronizedPriorityQueue(DoublePriorityQueue queue, Object mutex) { @Override public double peek(int index) { synchronized(mutex) { return queue.peek(index); } } @Override + public boolean contains(double e) { synchronized(mutex) { return queue.contains(e); } } + @Override public boolean removeFirst(double e) { synchronized(mutex) { return queue.removeFirst(e); } } @Override public boolean removeLast(double e) { synchronized(mutex) { return queue.removeLast(e); } } diff --git a/src/main/java/speiger/src/collections/doubles/utils/maps/Double2BooleanMaps.java b/src/main/java/speiger/src/collections/doubles/utils/maps/Double2BooleanMaps.java index 23bf6a05..541ec036 100644 --- a/src/main/java/speiger/src/collections/doubles/utils/maps/Double2BooleanMaps.java +++ b/src/main/java/speiger/src/collections/doubles/utils/maps/Double2BooleanMaps.java @@ -246,18 +246,18 @@ public static class SingletonMap extends AbstractDouble2BooleanMap { @Override public boolean computeBoolean(double key, DoubleBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanNonDefault(double key, DoubleBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean computeBooleanIfAbsent(double key, DoublePredicate mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanIfAbsentNonDefault(double key, DoublePredicate mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean computeBooleanIfPresent(double key, DoubleBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanIfPresentNonDefault(double key, DoubleBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean supplyBooleanIfAbsent(double key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public boolean computeBooleanNonDefault(double key, DoubleBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public boolean computeBooleanIfAbsentNonDefault(double key, DoublePredicate mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public boolean computeBooleanIfPresentNonDefault(double key, DoubleBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public boolean supplyBooleanIfAbsentNonDefault(double key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public boolean mergeBoolean(double key, boolean value, BooleanBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -304,18 +304,18 @@ public static class EmptyMap extends AbstractDouble2BooleanMap { @Override public boolean computeBoolean(double key, DoubleBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanNonDefault(double key, DoubleBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean computeBooleanIfAbsent(double key, DoublePredicate mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanIfAbsentNonDefault(double key, DoublePredicate mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean computeBooleanIfPresent(double key, DoubleBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanIfPresentNonDefault(double key, DoubleBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean supplyBooleanIfAbsent(double key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public boolean computeBooleanNonDefault(double key, DoubleBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public boolean computeBooleanIfAbsentNonDefault(double key, DoublePredicate mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public boolean computeBooleanIfPresentNonDefault(double key, DoubleBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public boolean supplyBooleanIfAbsentNonDefault(double key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public boolean mergeBoolean(double key, boolean value, BooleanBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -535,18 +535,18 @@ public boolean get(double key) { @Override public boolean computeBoolean(double key, DoubleBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanNonDefault(double key, DoubleBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean computeBooleanIfAbsent(double key, DoublePredicate mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanIfAbsentNonDefault(double key, DoublePredicate mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean computeBooleanIfPresent(double key, DoubleBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanIfPresentNonDefault(double key, DoubleBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean supplyBooleanIfAbsent(double key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public boolean computeBooleanNonDefault(double key, DoubleBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public boolean computeBooleanIfAbsentNonDefault(double key, DoublePredicate mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public boolean computeBooleanIfPresentNonDefault(double key, DoubleBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public boolean supplyBooleanIfAbsentNonDefault(double key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public boolean mergeBoolean(double key, boolean value, BooleanBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -938,18 +938,18 @@ public AbstractDouble2BooleanMap setDefaultReturnValue(boolean v) { @Override public boolean computeBoolean(double key, DoubleBooleanUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeBoolean(key, mappingFunction); } } @Override - public boolean computeBooleanNonDefault(double key, DoubleBooleanUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeBooleanNonDefault(key, mappingFunction); } } - @Override public boolean computeBooleanIfAbsent(double key, DoublePredicate mappingFunction) { synchronized(mutex) { return map.computeBooleanIfAbsent(key, mappingFunction); } } @Override - public boolean computeBooleanIfAbsentNonDefault(double key, DoublePredicate mappingFunction) { synchronized(mutex) { return map.computeBooleanIfAbsentNonDefault(key, mappingFunction); } } - @Override public boolean computeBooleanIfPresent(double key, DoubleBooleanUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeBooleanIfPresent(key, mappingFunction); } } @Override - public boolean computeBooleanIfPresentNonDefault(double key, DoubleBooleanUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeBooleanIfPresentNonDefault(key, mappingFunction); } } - @Override public boolean supplyBooleanIfAbsent(double key, BooleanSupplier valueProvider) { synchronized(mutex) { return map.supplyBooleanIfAbsent(key, valueProvider); } } @Override + public boolean computeBooleanNonDefault(double key, DoubleBooleanUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeBooleanNonDefault(key, mappingFunction); } } + @Override + public boolean computeBooleanIfAbsentNonDefault(double key, DoublePredicate mappingFunction) { synchronized(mutex) { return map.computeBooleanIfAbsentNonDefault(key, mappingFunction); } } + @Override + public boolean computeBooleanIfPresentNonDefault(double key, DoubleBooleanUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeBooleanIfPresentNonDefault(key, mappingFunction); } } + @Override public boolean supplyBooleanIfAbsentNonDefault(double key, BooleanSupplier valueProvider) { synchronized(mutex) { return map.supplyBooleanIfAbsentNonDefault(key, valueProvider); } } @Override public boolean mergeBoolean(double key, boolean value, BooleanBooleanUnaryOperator mappingFunction) { synchronized(mutex) { return map.mergeBoolean(key, value, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/doubles/utils/maps/Double2ByteMaps.java b/src/main/java/speiger/src/collections/doubles/utils/maps/Double2ByteMaps.java index 1b5ca62a..e47407f0 100644 --- a/src/main/java/speiger/src/collections/doubles/utils/maps/Double2ByteMaps.java +++ b/src/main/java/speiger/src/collections/doubles/utils/maps/Double2ByteMaps.java @@ -250,18 +250,18 @@ public static class SingletonMap extends AbstractDouble2ByteMap { @Override public byte computeByte(double key, DoubleByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteNonDefault(double key, DoubleByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte computeByteIfAbsent(double key, Double2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteIfAbsentNonDefault(double key, Double2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte computeByteIfPresent(double key, DoubleByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteIfPresentNonDefault(double key, DoubleByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte supplyByteIfAbsent(double key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public byte computeByteNonDefault(double key, DoubleByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public byte computeByteIfAbsentNonDefault(double key, Double2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public byte computeByteIfPresentNonDefault(double key, DoubleByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public byte supplyByteIfAbsentNonDefault(double key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public byte mergeByte(double key, byte value, ByteByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -312,18 +312,18 @@ public static class EmptyMap extends AbstractDouble2ByteMap { @Override public byte computeByte(double key, DoubleByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteNonDefault(double key, DoubleByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte computeByteIfAbsent(double key, Double2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteIfAbsentNonDefault(double key, Double2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte computeByteIfPresent(double key, DoubleByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteIfPresentNonDefault(double key, DoubleByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte supplyByteIfAbsent(double key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public byte computeByteNonDefault(double key, DoubleByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public byte computeByteIfAbsentNonDefault(double key, Double2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public byte computeByteIfPresentNonDefault(double key, DoubleByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public byte supplyByteIfAbsentNonDefault(double key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public byte mergeByte(double key, byte value, ByteByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -547,18 +547,18 @@ public byte get(double key) { @Override public byte computeByte(double key, DoubleByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteNonDefault(double key, DoubleByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte computeByteIfAbsent(double key, Double2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteIfAbsentNonDefault(double key, Double2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte computeByteIfPresent(double key, DoubleByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteIfPresentNonDefault(double key, DoubleByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte supplyByteIfAbsent(double key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public byte computeByteNonDefault(double key, DoubleByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public byte computeByteIfAbsentNonDefault(double key, Double2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public byte computeByteIfPresentNonDefault(double key, DoubleByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public byte supplyByteIfAbsentNonDefault(double key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public byte mergeByte(double key, byte value, ByteByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -955,18 +955,18 @@ public AbstractDouble2ByteMap setDefaultReturnValue(byte v) { @Override public byte computeByte(double key, DoubleByteUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeByte(key, mappingFunction); } } @Override - public byte computeByteNonDefault(double key, DoubleByteUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeByteNonDefault(key, mappingFunction); } } - @Override public byte computeByteIfAbsent(double key, Double2ByteFunction mappingFunction) { synchronized(mutex) { return map.computeByteIfAbsent(key, mappingFunction); } } @Override - public byte computeByteIfAbsentNonDefault(double key, Double2ByteFunction mappingFunction) { synchronized(mutex) { return map.computeByteIfAbsentNonDefault(key, mappingFunction); } } - @Override public byte computeByteIfPresent(double key, DoubleByteUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeByteIfPresent(key, mappingFunction); } } @Override - public byte computeByteIfPresentNonDefault(double key, DoubleByteUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeByteIfPresentNonDefault(key, mappingFunction); } } - @Override public byte supplyByteIfAbsent(double key, ByteSupplier valueProvider) { synchronized(mutex) { return map.supplyByteIfAbsent(key, valueProvider); } } @Override + public byte computeByteNonDefault(double key, DoubleByteUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeByteNonDefault(key, mappingFunction); } } + @Override + public byte computeByteIfAbsentNonDefault(double key, Double2ByteFunction mappingFunction) { synchronized(mutex) { return map.computeByteIfAbsentNonDefault(key, mappingFunction); } } + @Override + public byte computeByteIfPresentNonDefault(double key, DoubleByteUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeByteIfPresentNonDefault(key, mappingFunction); } } + @Override public byte supplyByteIfAbsentNonDefault(double key, ByteSupplier valueProvider) { synchronized(mutex) { return map.supplyByteIfAbsentNonDefault(key, valueProvider); } } @Override public byte mergeByte(double key, byte value, ByteByteUnaryOperator mappingFunction) { synchronized(mutex) { return map.mergeByte(key, value, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/doubles/utils/maps/Double2CharMaps.java b/src/main/java/speiger/src/collections/doubles/utils/maps/Double2CharMaps.java index 5ffbf672..d6c61ae3 100644 --- a/src/main/java/speiger/src/collections/doubles/utils/maps/Double2CharMaps.java +++ b/src/main/java/speiger/src/collections/doubles/utils/maps/Double2CharMaps.java @@ -250,18 +250,18 @@ public static class SingletonMap extends AbstractDouble2CharMap { @Override public char computeChar(double key, DoubleCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharNonDefault(double key, DoubleCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char computeCharIfAbsent(double key, Double2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharIfAbsentNonDefault(double key, Double2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char computeCharIfPresent(double key, DoubleCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharIfPresentNonDefault(double key, DoubleCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char supplyCharIfAbsent(double key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public char computeCharNonDefault(double key, DoubleCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public char computeCharIfAbsentNonDefault(double key, Double2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public char computeCharIfPresentNonDefault(double key, DoubleCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public char supplyCharIfAbsentNonDefault(double key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public char mergeChar(double key, char value, CharCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -312,18 +312,18 @@ public static class EmptyMap extends AbstractDouble2CharMap { @Override public char computeChar(double key, DoubleCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharNonDefault(double key, DoubleCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char computeCharIfAbsent(double key, Double2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharIfAbsentNonDefault(double key, Double2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char computeCharIfPresent(double key, DoubleCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharIfPresentNonDefault(double key, DoubleCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char supplyCharIfAbsent(double key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public char computeCharNonDefault(double key, DoubleCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public char computeCharIfAbsentNonDefault(double key, Double2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public char computeCharIfPresentNonDefault(double key, DoubleCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public char supplyCharIfAbsentNonDefault(double key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public char mergeChar(double key, char value, CharCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -547,18 +547,18 @@ public char get(double key) { @Override public char computeChar(double key, DoubleCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharNonDefault(double key, DoubleCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char computeCharIfAbsent(double key, Double2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharIfAbsentNonDefault(double key, Double2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char computeCharIfPresent(double key, DoubleCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharIfPresentNonDefault(double key, DoubleCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char supplyCharIfAbsent(double key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public char computeCharNonDefault(double key, DoubleCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public char computeCharIfAbsentNonDefault(double key, Double2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public char computeCharIfPresentNonDefault(double key, DoubleCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public char supplyCharIfAbsentNonDefault(double key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public char mergeChar(double key, char value, CharCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -955,18 +955,18 @@ public AbstractDouble2CharMap setDefaultReturnValue(char v) { @Override public char computeChar(double key, DoubleCharUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeChar(key, mappingFunction); } } @Override - public char computeCharNonDefault(double key, DoubleCharUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeCharNonDefault(key, mappingFunction); } } - @Override public char computeCharIfAbsent(double key, Double2CharFunction mappingFunction) { synchronized(mutex) { return map.computeCharIfAbsent(key, mappingFunction); } } @Override - public char computeCharIfAbsentNonDefault(double key, Double2CharFunction mappingFunction) { synchronized(mutex) { return map.computeCharIfAbsentNonDefault(key, mappingFunction); } } - @Override public char computeCharIfPresent(double key, DoubleCharUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeCharIfPresent(key, mappingFunction); } } @Override - public char computeCharIfPresentNonDefault(double key, DoubleCharUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeCharIfPresentNonDefault(key, mappingFunction); } } - @Override public char supplyCharIfAbsent(double key, CharSupplier valueProvider) { synchronized(mutex) { return map.supplyCharIfAbsent(key, valueProvider); } } @Override + public char computeCharNonDefault(double key, DoubleCharUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeCharNonDefault(key, mappingFunction); } } + @Override + public char computeCharIfAbsentNonDefault(double key, Double2CharFunction mappingFunction) { synchronized(mutex) { return map.computeCharIfAbsentNonDefault(key, mappingFunction); } } + @Override + public char computeCharIfPresentNonDefault(double key, DoubleCharUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeCharIfPresentNonDefault(key, mappingFunction); } } + @Override public char supplyCharIfAbsentNonDefault(double key, CharSupplier valueProvider) { synchronized(mutex) { return map.supplyCharIfAbsentNonDefault(key, valueProvider); } } @Override public char mergeChar(double key, char value, CharCharUnaryOperator mappingFunction) { synchronized(mutex) { return map.mergeChar(key, value, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/doubles/utils/maps/Double2DoubleMaps.java b/src/main/java/speiger/src/collections/doubles/utils/maps/Double2DoubleMaps.java index 11b8652b..90d05d8b 100644 --- a/src/main/java/speiger/src/collections/doubles/utils/maps/Double2DoubleMaps.java +++ b/src/main/java/speiger/src/collections/doubles/utils/maps/Double2DoubleMaps.java @@ -249,18 +249,18 @@ public static class SingletonMap extends AbstractDouble2DoubleMap { @Override public double computeDouble(double key, DoubleDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleNonDefault(double key, DoubleDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double computeDoubleIfAbsent(double key, DoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleIfAbsentNonDefault(double key, DoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double computeDoubleIfPresent(double key, DoubleDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleIfPresentNonDefault(double key, DoubleDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double supplyDoubleIfAbsent(double key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public double computeDoubleNonDefault(double key, DoubleDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public double computeDoubleIfAbsentNonDefault(double key, DoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public double computeDoubleIfPresentNonDefault(double key, DoubleDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public double supplyDoubleIfAbsentNonDefault(double key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public double mergeDouble(double key, double value, DoubleDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -311,18 +311,18 @@ public static class EmptyMap extends AbstractDouble2DoubleMap { @Override public double computeDouble(double key, DoubleDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleNonDefault(double key, DoubleDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double computeDoubleIfAbsent(double key, DoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleIfAbsentNonDefault(double key, DoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double computeDoubleIfPresent(double key, DoubleDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleIfPresentNonDefault(double key, DoubleDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double supplyDoubleIfAbsent(double key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public double computeDoubleNonDefault(double key, DoubleDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public double computeDoubleIfAbsentNonDefault(double key, DoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public double computeDoubleIfPresentNonDefault(double key, DoubleDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public double supplyDoubleIfAbsentNonDefault(double key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public double mergeDouble(double key, double value, DoubleDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -546,18 +546,18 @@ public double get(double key) { @Override public double computeDouble(double key, DoubleDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleNonDefault(double key, DoubleDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double computeDoubleIfAbsent(double key, DoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleIfAbsentNonDefault(double key, DoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double computeDoubleIfPresent(double key, DoubleDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleIfPresentNonDefault(double key, DoubleDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double supplyDoubleIfAbsent(double key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public double computeDoubleNonDefault(double key, DoubleDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public double computeDoubleIfAbsentNonDefault(double key, DoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public double computeDoubleIfPresentNonDefault(double key, DoubleDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public double supplyDoubleIfAbsentNonDefault(double key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public double mergeDouble(double key, double value, DoubleDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -954,18 +954,18 @@ public AbstractDouble2DoubleMap setDefaultReturnValue(double v) { @Override public double computeDouble(double key, DoubleDoubleUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeDouble(key, mappingFunction); } } @Override - public double computeDoubleNonDefault(double key, DoubleDoubleUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeDoubleNonDefault(key, mappingFunction); } } - @Override public double computeDoubleIfAbsent(double key, DoubleUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeDoubleIfAbsent(key, mappingFunction); } } @Override - public double computeDoubleIfAbsentNonDefault(double key, DoubleUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeDoubleIfAbsentNonDefault(key, mappingFunction); } } - @Override public double computeDoubleIfPresent(double key, DoubleDoubleUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeDoubleIfPresent(key, mappingFunction); } } @Override - public double computeDoubleIfPresentNonDefault(double key, DoubleDoubleUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeDoubleIfPresentNonDefault(key, mappingFunction); } } - @Override public double supplyDoubleIfAbsent(double key, DoubleSupplier valueProvider) { synchronized(mutex) { return map.supplyDoubleIfAbsent(key, valueProvider); } } @Override + public double computeDoubleNonDefault(double key, DoubleDoubleUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeDoubleNonDefault(key, mappingFunction); } } + @Override + public double computeDoubleIfAbsentNonDefault(double key, DoubleUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeDoubleIfAbsentNonDefault(key, mappingFunction); } } + @Override + public double computeDoubleIfPresentNonDefault(double key, DoubleDoubleUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeDoubleIfPresentNonDefault(key, mappingFunction); } } + @Override public double supplyDoubleIfAbsentNonDefault(double key, DoubleSupplier valueProvider) { synchronized(mutex) { return map.supplyDoubleIfAbsentNonDefault(key, valueProvider); } } @Override public double mergeDouble(double key, double value, DoubleDoubleUnaryOperator mappingFunction) { synchronized(mutex) { return map.mergeDouble(key, value, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/doubles/utils/maps/Double2FloatMaps.java b/src/main/java/speiger/src/collections/doubles/utils/maps/Double2FloatMaps.java index bbf1a7b9..4f8821c4 100644 --- a/src/main/java/speiger/src/collections/doubles/utils/maps/Double2FloatMaps.java +++ b/src/main/java/speiger/src/collections/doubles/utils/maps/Double2FloatMaps.java @@ -250,18 +250,18 @@ public static class SingletonMap extends AbstractDouble2FloatMap { @Override public float computeFloat(double key, DoubleFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatNonDefault(double key, DoubleFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float computeFloatIfAbsent(double key, Double2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatIfAbsentNonDefault(double key, Double2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float computeFloatIfPresent(double key, DoubleFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatIfPresentNonDefault(double key, DoubleFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float supplyFloatIfAbsent(double key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public float computeFloatNonDefault(double key, DoubleFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public float computeFloatIfAbsentNonDefault(double key, Double2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public float computeFloatIfPresentNonDefault(double key, DoubleFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public float supplyFloatIfAbsentNonDefault(double key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public float mergeFloat(double key, float value, FloatFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -312,18 +312,18 @@ public static class EmptyMap extends AbstractDouble2FloatMap { @Override public float computeFloat(double key, DoubleFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatNonDefault(double key, DoubleFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float computeFloatIfAbsent(double key, Double2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatIfAbsentNonDefault(double key, Double2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float computeFloatIfPresent(double key, DoubleFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatIfPresentNonDefault(double key, DoubleFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float supplyFloatIfAbsent(double key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public float computeFloatNonDefault(double key, DoubleFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public float computeFloatIfAbsentNonDefault(double key, Double2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public float computeFloatIfPresentNonDefault(double key, DoubleFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public float supplyFloatIfAbsentNonDefault(double key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public float mergeFloat(double key, float value, FloatFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -547,18 +547,18 @@ public float get(double key) { @Override public float computeFloat(double key, DoubleFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatNonDefault(double key, DoubleFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float computeFloatIfAbsent(double key, Double2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatIfAbsentNonDefault(double key, Double2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float computeFloatIfPresent(double key, DoubleFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatIfPresentNonDefault(double key, DoubleFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float supplyFloatIfAbsent(double key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public float computeFloatNonDefault(double key, DoubleFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public float computeFloatIfAbsentNonDefault(double key, Double2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public float computeFloatIfPresentNonDefault(double key, DoubleFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public float supplyFloatIfAbsentNonDefault(double key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public float mergeFloat(double key, float value, FloatFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -955,18 +955,18 @@ public AbstractDouble2FloatMap setDefaultReturnValue(float v) { @Override public float computeFloat(double key, DoubleFloatUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeFloat(key, mappingFunction); } } @Override - public float computeFloatNonDefault(double key, DoubleFloatUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeFloatNonDefault(key, mappingFunction); } } - @Override public float computeFloatIfAbsent(double key, Double2FloatFunction mappingFunction) { synchronized(mutex) { return map.computeFloatIfAbsent(key, mappingFunction); } } @Override - public float computeFloatIfAbsentNonDefault(double key, Double2FloatFunction mappingFunction) { synchronized(mutex) { return map.computeFloatIfAbsentNonDefault(key, mappingFunction); } } - @Override public float computeFloatIfPresent(double key, DoubleFloatUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeFloatIfPresent(key, mappingFunction); } } @Override - public float computeFloatIfPresentNonDefault(double key, DoubleFloatUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeFloatIfPresentNonDefault(key, mappingFunction); } } - @Override public float supplyFloatIfAbsent(double key, FloatSupplier valueProvider) { synchronized(mutex) { return map.supplyFloatIfAbsent(key, valueProvider); } } @Override + public float computeFloatNonDefault(double key, DoubleFloatUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeFloatNonDefault(key, mappingFunction); } } + @Override + public float computeFloatIfAbsentNonDefault(double key, Double2FloatFunction mappingFunction) { synchronized(mutex) { return map.computeFloatIfAbsentNonDefault(key, mappingFunction); } } + @Override + public float computeFloatIfPresentNonDefault(double key, DoubleFloatUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeFloatIfPresentNonDefault(key, mappingFunction); } } + @Override public float supplyFloatIfAbsentNonDefault(double key, FloatSupplier valueProvider) { synchronized(mutex) { return map.supplyFloatIfAbsentNonDefault(key, valueProvider); } } @Override public float mergeFloat(double key, float value, FloatFloatUnaryOperator mappingFunction) { synchronized(mutex) { return map.mergeFloat(key, value, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/doubles/utils/maps/Double2IntMaps.java b/src/main/java/speiger/src/collections/doubles/utils/maps/Double2IntMaps.java index d178518c..6f5496b3 100644 --- a/src/main/java/speiger/src/collections/doubles/utils/maps/Double2IntMaps.java +++ b/src/main/java/speiger/src/collections/doubles/utils/maps/Double2IntMaps.java @@ -250,18 +250,18 @@ public static class SingletonMap extends AbstractDouble2IntMap { @Override public int computeInt(double key, DoubleIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntNonDefault(double key, DoubleIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int computeIntIfAbsent(double key, Double2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntIfAbsentNonDefault(double key, Double2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int computeIntIfPresent(double key, DoubleIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntIfPresentNonDefault(double key, DoubleIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int supplyIntIfAbsent(double key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public int computeIntNonDefault(double key, DoubleIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public int computeIntIfAbsentNonDefault(double key, Double2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public int computeIntIfPresentNonDefault(double key, DoubleIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public int supplyIntIfAbsentNonDefault(double key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public int mergeInt(double key, int value, IntIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -312,18 +312,18 @@ public static class EmptyMap extends AbstractDouble2IntMap { @Override public int computeInt(double key, DoubleIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntNonDefault(double key, DoubleIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int computeIntIfAbsent(double key, Double2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntIfAbsentNonDefault(double key, Double2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int computeIntIfPresent(double key, DoubleIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntIfPresentNonDefault(double key, DoubleIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int supplyIntIfAbsent(double key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public int computeIntNonDefault(double key, DoubleIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public int computeIntIfAbsentNonDefault(double key, Double2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public int computeIntIfPresentNonDefault(double key, DoubleIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public int supplyIntIfAbsentNonDefault(double key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public int mergeInt(double key, int value, IntIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -547,18 +547,18 @@ public int get(double key) { @Override public int computeInt(double key, DoubleIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntNonDefault(double key, DoubleIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int computeIntIfAbsent(double key, Double2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntIfAbsentNonDefault(double key, Double2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int computeIntIfPresent(double key, DoubleIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntIfPresentNonDefault(double key, DoubleIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int supplyIntIfAbsent(double key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public int computeIntNonDefault(double key, DoubleIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public int computeIntIfAbsentNonDefault(double key, Double2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public int computeIntIfPresentNonDefault(double key, DoubleIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public int supplyIntIfAbsentNonDefault(double key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public int mergeInt(double key, int value, IntIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -955,18 +955,18 @@ public AbstractDouble2IntMap setDefaultReturnValue(int v) { @Override public int computeInt(double key, DoubleIntUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeInt(key, mappingFunction); } } @Override - public int computeIntNonDefault(double key, DoubleIntUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeIntNonDefault(key, mappingFunction); } } - @Override public int computeIntIfAbsent(double key, Double2IntFunction mappingFunction) { synchronized(mutex) { return map.computeIntIfAbsent(key, mappingFunction); } } @Override - public int computeIntIfAbsentNonDefault(double key, Double2IntFunction mappingFunction) { synchronized(mutex) { return map.computeIntIfAbsentNonDefault(key, mappingFunction); } } - @Override public int computeIntIfPresent(double key, DoubleIntUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeIntIfPresent(key, mappingFunction); } } @Override - public int computeIntIfPresentNonDefault(double key, DoubleIntUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeIntIfPresentNonDefault(key, mappingFunction); } } - @Override public int supplyIntIfAbsent(double key, IntSupplier valueProvider) { synchronized(mutex) { return map.supplyIntIfAbsent(key, valueProvider); } } @Override + public int computeIntNonDefault(double key, DoubleIntUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeIntNonDefault(key, mappingFunction); } } + @Override + public int computeIntIfAbsentNonDefault(double key, Double2IntFunction mappingFunction) { synchronized(mutex) { return map.computeIntIfAbsentNonDefault(key, mappingFunction); } } + @Override + public int computeIntIfPresentNonDefault(double key, DoubleIntUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeIntIfPresentNonDefault(key, mappingFunction); } } + @Override public int supplyIntIfAbsentNonDefault(double key, IntSupplier valueProvider) { synchronized(mutex) { return map.supplyIntIfAbsentNonDefault(key, valueProvider); } } @Override public int mergeInt(double key, int value, IntIntUnaryOperator mappingFunction) { synchronized(mutex) { return map.mergeInt(key, value, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/doubles/utils/maps/Double2LongMaps.java b/src/main/java/speiger/src/collections/doubles/utils/maps/Double2LongMaps.java index 208dcd42..909dc12f 100644 --- a/src/main/java/speiger/src/collections/doubles/utils/maps/Double2LongMaps.java +++ b/src/main/java/speiger/src/collections/doubles/utils/maps/Double2LongMaps.java @@ -250,18 +250,18 @@ public static class SingletonMap extends AbstractDouble2LongMap { @Override public long computeLong(double key, DoubleLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongNonDefault(double key, DoubleLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long computeLongIfAbsent(double key, Double2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongIfAbsentNonDefault(double key, Double2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long computeLongIfPresent(double key, DoubleLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongIfPresentNonDefault(double key, DoubleLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long supplyLongIfAbsent(double key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public long computeLongNonDefault(double key, DoubleLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public long computeLongIfAbsentNonDefault(double key, Double2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public long computeLongIfPresentNonDefault(double key, DoubleLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public long supplyLongIfAbsentNonDefault(double key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public long mergeLong(double key, long value, LongLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -312,18 +312,18 @@ public static class EmptyMap extends AbstractDouble2LongMap { @Override public long computeLong(double key, DoubleLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongNonDefault(double key, DoubleLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long computeLongIfAbsent(double key, Double2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongIfAbsentNonDefault(double key, Double2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long computeLongIfPresent(double key, DoubleLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongIfPresentNonDefault(double key, DoubleLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long supplyLongIfAbsent(double key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public long computeLongNonDefault(double key, DoubleLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public long computeLongIfAbsentNonDefault(double key, Double2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public long computeLongIfPresentNonDefault(double key, DoubleLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public long supplyLongIfAbsentNonDefault(double key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public long mergeLong(double key, long value, LongLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -547,18 +547,18 @@ public long get(double key) { @Override public long computeLong(double key, DoubleLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongNonDefault(double key, DoubleLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long computeLongIfAbsent(double key, Double2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongIfAbsentNonDefault(double key, Double2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long computeLongIfPresent(double key, DoubleLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongIfPresentNonDefault(double key, DoubleLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long supplyLongIfAbsent(double key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public long computeLongNonDefault(double key, DoubleLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public long computeLongIfAbsentNonDefault(double key, Double2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public long computeLongIfPresentNonDefault(double key, DoubleLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public long supplyLongIfAbsentNonDefault(double key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public long mergeLong(double key, long value, LongLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -955,18 +955,18 @@ public AbstractDouble2LongMap setDefaultReturnValue(long v) { @Override public long computeLong(double key, DoubleLongUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeLong(key, mappingFunction); } } @Override - public long computeLongNonDefault(double key, DoubleLongUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeLongNonDefault(key, mappingFunction); } } - @Override public long computeLongIfAbsent(double key, Double2LongFunction mappingFunction) { synchronized(mutex) { return map.computeLongIfAbsent(key, mappingFunction); } } @Override - public long computeLongIfAbsentNonDefault(double key, Double2LongFunction mappingFunction) { synchronized(mutex) { return map.computeLongIfAbsentNonDefault(key, mappingFunction); } } - @Override public long computeLongIfPresent(double key, DoubleLongUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeLongIfPresent(key, mappingFunction); } } @Override - public long computeLongIfPresentNonDefault(double key, DoubleLongUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeLongIfPresentNonDefault(key, mappingFunction); } } - @Override public long supplyLongIfAbsent(double key, LongSupplier valueProvider) { synchronized(mutex) { return map.supplyLongIfAbsent(key, valueProvider); } } @Override + public long computeLongNonDefault(double key, DoubleLongUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeLongNonDefault(key, mappingFunction); } } + @Override + public long computeLongIfAbsentNonDefault(double key, Double2LongFunction mappingFunction) { synchronized(mutex) { return map.computeLongIfAbsentNonDefault(key, mappingFunction); } } + @Override + public long computeLongIfPresentNonDefault(double key, DoubleLongUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeLongIfPresentNonDefault(key, mappingFunction); } } + @Override public long supplyLongIfAbsentNonDefault(double key, LongSupplier valueProvider) { synchronized(mutex) { return map.supplyLongIfAbsentNonDefault(key, valueProvider); } } @Override public long mergeLong(double key, long value, LongLongUnaryOperator mappingFunction) { synchronized(mutex) { return map.mergeLong(key, value, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/doubles/utils/maps/Double2ObjectMaps.java b/src/main/java/speiger/src/collections/doubles/utils/maps/Double2ObjectMaps.java index 7b2f237b..d28ecf1d 100644 --- a/src/main/java/speiger/src/collections/doubles/utils/maps/Double2ObjectMaps.java +++ b/src/main/java/speiger/src/collections/doubles/utils/maps/Double2ObjectMaps.java @@ -266,20 +266,12 @@ public static class SingletonMap extends AbstractDouble2ObjectMap { @Override public V compute(double key, DoubleObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeNonDefault(double key, DoubleObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V computeIfAbsent(double key, DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeIfAbsentNonDefault(double key, DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V computeIfPresent(double key, DoubleObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeIfPresentNonDefault(double key, DoubleObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V supplyIfAbsent(double key, ObjectSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public V supplyIfAbsentNonDefault(double key, ObjectSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public V merge(double key, V value, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override public void mergeAll(Double2ObjectMap m, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -325,20 +317,12 @@ public static class EmptyMap extends AbstractDouble2ObjectMap { @Override public V compute(double key, DoubleObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeNonDefault(double key, DoubleObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V computeIfAbsent(double key, DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeIfAbsentNonDefault(double key, DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V computeIfPresent(double key, DoubleObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeIfPresentNonDefault(double key, DoubleObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V supplyIfAbsent(double key, ObjectSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public V supplyIfAbsentNonDefault(double key, ObjectSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public V merge(double key, V value, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override public void mergeAll(Double2ObjectMap m, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -561,20 +545,12 @@ public V get(double key) { @Override public V compute(double key, DoubleObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeNonDefault(double key, DoubleObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V computeIfAbsent(double key, DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeIfAbsentNonDefault(double key, DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V computeIfPresent(double key, DoubleObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeIfPresentNonDefault(double key, DoubleObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V supplyIfAbsent(double key, ObjectSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public V supplyIfAbsentNonDefault(double key, ObjectSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public V merge(double key, V value, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override public void mergeAll(Double2ObjectMap m, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -968,20 +944,12 @@ public AbstractDouble2ObjectMap setDefaultReturnValue(V v) { @Override public V compute(double key, DoubleObjectUnaryOperator mappingFunction) { synchronized(mutex) { return map.compute(key, mappingFunction); } } @Override - public V computeNonDefault(double key, DoubleObjectUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeNonDefault(key, mappingFunction); } } - @Override public V computeIfAbsent(double key, DoubleFunction mappingFunction) { synchronized(mutex) { return map.computeIfAbsent(key, mappingFunction); } } @Override - public V computeIfAbsentNonDefault(double key, DoubleFunction mappingFunction) { synchronized(mutex) { return map.computeIfAbsentNonDefault(key, mappingFunction); } } - @Override public V computeIfPresent(double key, DoubleObjectUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeIfPresent(key, mappingFunction); } } @Override - public V computeIfPresentNonDefault(double key, DoubleObjectUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeIfPresentNonDefault(key, mappingFunction); } } - @Override public V supplyIfAbsent(double key, ObjectSupplier valueProvider) { synchronized(mutex) { return map.supplyIfAbsent(key, valueProvider); } } @Override - public V supplyIfAbsentNonDefault(double key, ObjectSupplier valueProvider) { synchronized(mutex) { return map.supplyIfAbsentNonDefault(key, valueProvider); } } - @Override public V merge(double key, V value, ObjectObjectUnaryOperator mappingFunction) { synchronized(mutex) { return map.merge(key, value, mappingFunction); } } @Override public void mergeAll(Double2ObjectMap m, ObjectObjectUnaryOperator mappingFunction) { synchronized(mutex) { map.mergeAll(m, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/doubles/utils/maps/Double2ShortMaps.java b/src/main/java/speiger/src/collections/doubles/utils/maps/Double2ShortMaps.java index fc2945b4..f77709a8 100644 --- a/src/main/java/speiger/src/collections/doubles/utils/maps/Double2ShortMaps.java +++ b/src/main/java/speiger/src/collections/doubles/utils/maps/Double2ShortMaps.java @@ -250,18 +250,18 @@ public static class SingletonMap extends AbstractDouble2ShortMap { @Override public short computeShort(double key, DoubleShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortNonDefault(double key, DoubleShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short computeShortIfAbsent(double key, Double2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortIfAbsentNonDefault(double key, Double2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short computeShortIfPresent(double key, DoubleShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortIfPresentNonDefault(double key, DoubleShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short supplyShortIfAbsent(double key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public short computeShortNonDefault(double key, DoubleShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public short computeShortIfAbsentNonDefault(double key, Double2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public short computeShortIfPresentNonDefault(double key, DoubleShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public short supplyShortIfAbsentNonDefault(double key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public short mergeShort(double key, short value, ShortShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -312,18 +312,18 @@ public static class EmptyMap extends AbstractDouble2ShortMap { @Override public short computeShort(double key, DoubleShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortNonDefault(double key, DoubleShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short computeShortIfAbsent(double key, Double2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortIfAbsentNonDefault(double key, Double2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short computeShortIfPresent(double key, DoubleShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortIfPresentNonDefault(double key, DoubleShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short supplyShortIfAbsent(double key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public short computeShortNonDefault(double key, DoubleShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public short computeShortIfAbsentNonDefault(double key, Double2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public short computeShortIfPresentNonDefault(double key, DoubleShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public short supplyShortIfAbsentNonDefault(double key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public short mergeShort(double key, short value, ShortShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -547,18 +547,18 @@ public short get(double key) { @Override public short computeShort(double key, DoubleShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortNonDefault(double key, DoubleShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short computeShortIfAbsent(double key, Double2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortIfAbsentNonDefault(double key, Double2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short computeShortIfPresent(double key, DoubleShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortIfPresentNonDefault(double key, DoubleShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short supplyShortIfAbsent(double key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public short computeShortNonDefault(double key, DoubleShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public short computeShortIfAbsentNonDefault(double key, Double2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public short computeShortIfPresentNonDefault(double key, DoubleShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public short supplyShortIfAbsentNonDefault(double key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public short mergeShort(double key, short value, ShortShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -955,18 +955,18 @@ public AbstractDouble2ShortMap setDefaultReturnValue(short v) { @Override public short computeShort(double key, DoubleShortUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeShort(key, mappingFunction); } } @Override - public short computeShortNonDefault(double key, DoubleShortUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeShortNonDefault(key, mappingFunction); } } - @Override public short computeShortIfAbsent(double key, Double2ShortFunction mappingFunction) { synchronized(mutex) { return map.computeShortIfAbsent(key, mappingFunction); } } @Override - public short computeShortIfAbsentNonDefault(double key, Double2ShortFunction mappingFunction) { synchronized(mutex) { return map.computeShortIfAbsentNonDefault(key, mappingFunction); } } - @Override public short computeShortIfPresent(double key, DoubleShortUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeShortIfPresent(key, mappingFunction); } } @Override - public short computeShortIfPresentNonDefault(double key, DoubleShortUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeShortIfPresentNonDefault(key, mappingFunction); } } - @Override public short supplyShortIfAbsent(double key, ShortSupplier valueProvider) { synchronized(mutex) { return map.supplyShortIfAbsent(key, valueProvider); } } @Override + public short computeShortNonDefault(double key, DoubleShortUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeShortNonDefault(key, mappingFunction); } } + @Override + public short computeShortIfAbsentNonDefault(double key, Double2ShortFunction mappingFunction) { synchronized(mutex) { return map.computeShortIfAbsentNonDefault(key, mappingFunction); } } + @Override + public short computeShortIfPresentNonDefault(double key, DoubleShortUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeShortIfPresentNonDefault(key, mappingFunction); } } + @Override public short supplyShortIfAbsentNonDefault(double key, ShortSupplier valueProvider) { synchronized(mutex) { return map.supplyShortIfAbsentNonDefault(key, valueProvider); } } @Override public short mergeShort(double key, short value, ShortShortUnaryOperator mappingFunction) { synchronized(mutex) { return map.mergeShort(key, value, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/floats/functions/FloatSupplier.java b/src/main/java/speiger/src/collections/floats/functions/FloatSupplier.java index f0009ae9..561e2461 100644 --- a/src/main/java/speiger/src/collections/floats/functions/FloatSupplier.java +++ b/src/main/java/speiger/src/collections/floats/functions/FloatSupplier.java @@ -8,5 +8,5 @@ public interface FloatSupplier /** * @return the supplied value */ - public float getAsDouble(); + public float getAsFloat(); } \ No newline at end of file diff --git a/src/main/java/speiger/src/collections/floats/lists/AbstractFloatList.java b/src/main/java/speiger/src/collections/floats/lists/AbstractFloatList.java index dd68f291..6a64c296 100644 --- a/src/main/java/speiger/src/collections/floats/lists/AbstractFloatList.java +++ b/src/main/java/speiger/src/collections/floats/lists/AbstractFloatList.java @@ -12,6 +12,7 @@ import speiger.src.collections.floats.collections.FloatCollection; import speiger.src.collections.floats.collections.FloatIterator; import speiger.src.collections.floats.collections.FloatSplititerator; +import speiger.src.collections.ints.lists.IntList; import speiger.src.collections.floats.utils.FloatSplititerators; import speiger.src.collections.utils.SanityChecks; @@ -205,13 +206,23 @@ public FloatIterator iterator() { public FloatListIterator listIterator() { return listIterator(0); } - + @Override public FloatListIterator listIterator(int index) { if(index < 0 || index > size()) throw new IndexOutOfBoundsException(); return new FloatListIter(index); } + @Override + public FloatListIterator indexedIterator(int...indecies) { + return new IndexedIterator(indecies); + } + + @Override + public FloatListIterator indexedIterator(IntList indecies) { + return new ListIndexedIterator(indecies); + } + @Override public void size(int size) { while(size > size()) add(0F); @@ -566,7 +577,153 @@ public int back(int amount) { } } } + + private class ListIndexedIterator implements FloatListIterator { + IntList indecies; + int index; + int lastReturned = -1; + + ListIndexedIterator(IntList indecies) { + this.indecies = indecies; + } + + @Override + public boolean hasNext() { + return index < indecies.size(); + } + + @Override + public float nextFloat() { + if(!hasNext()) throw new NoSuchElementException(); + int i = index++; + return getFloat((lastReturned = indecies.getInt(i))); + } + + @Override + public boolean hasPrevious() { + return index > 0; + } + + @Override + public float previousFloat() { + if(!hasPrevious()) throw new NoSuchElementException(); + index--; + return getFloat((lastReturned = indecies.getInt(index))); + } + + @Override + public int nextIndex() { + return index; + } + + @Override + public int previousIndex() { + return index-1; + } + + @Override + public void remove() { throw new UnsupportedOperationException(); } + @Override + public void add(float e) { throw new UnsupportedOperationException(); } + + @Override + public void set(float e) { + if(lastReturned == -1) throw new IllegalStateException(); + AbstractFloatList.this.set(lastReturned, e); + } + + @Override + public int skip(int amount) { + if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed"); + int steps = Math.min(amount, indecies.size() - index); + index += steps; + if(steps > 0) lastReturned = Math.min(index-1, indecies.size()-1); + return steps; + } + + @Override + public int back(int amount) { + if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed"); + int steps = Math.min(amount, index); + index -= steps; + if(steps > 0) lastReturned = Math.max(index, 0); + return steps; + } + } + + private class IndexedIterator implements FloatListIterator { + int[] indecies; + int index; + int lastReturned = -1; + + IndexedIterator(int[] indecies) { + this.indecies = indecies; + } + @Override + public boolean hasNext() { + return index < indecies.length; + } + + @Override + public float nextFloat() { + if(!hasNext()) throw new NoSuchElementException(); + int i = index++; + return getFloat((lastReturned = indecies[i])); + } + + @Override + public boolean hasPrevious() { + return index > 0; + } + + @Override + public float previousFloat() { + if(!hasPrevious()) throw new NoSuchElementException(); + index--; + return getFloat((lastReturned = indecies[index])); + } + + @Override + public int nextIndex() { + return index; + } + + @Override + public int previousIndex() { + return index-1; + } + + @Override + public void remove() { throw new UnsupportedOperationException(); } + @Override + public void add(float e) { throw new UnsupportedOperationException(); } + + @Override + public void set(float e) { + if(lastReturned == -1) throw new IllegalStateException(); + AbstractFloatList.this.set(lastReturned, e); + } + + @Override + public int skip(int amount) { + if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed"); + int steps = Math.min(amount, indecies.length - index); + index += steps; + if(steps > 0) lastReturned = Math.min(index-1, indecies.length-1); + return steps; + } + + @Override + public int back(int amount) { + if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed"); + int steps = Math.min(amount, index); + index -= steps; + if(steps > 0) lastReturned = Math.max(index, 0); + return steps; + } + } + private class FloatListIter implements FloatListIterator { int index; int lastReturned = -1; @@ -644,7 +801,7 @@ public int back(int amount) { if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed"); int steps = Math.min(amount, index); index -= steps; - if(steps > 0) lastReturned = Math.min(index, size()-1); + if(steps > 0) lastReturned = Math.max(index, 0); return steps; } } diff --git a/src/main/java/speiger/src/collections/floats/lists/FloatList.java b/src/main/java/speiger/src/collections/floats/lists/FloatList.java index b1f7323b..fa9ba2e8 100644 --- a/src/main/java/speiger/src/collections/floats/lists/FloatList.java +++ b/src/main/java/speiger/src/collections/floats/lists/FloatList.java @@ -14,6 +14,7 @@ import speiger.src.collections.floats.functions.FloatComparator; import speiger.src.collections.floats.utils.FloatArrays; import speiger.src.collections.floats.utils.FloatLists; +import speiger.src.collections.ints.lists.IntList; import speiger.src.collections.floats.utils.FloatSplititerators; import speiger.src.collections.utils.SanityChecks; @@ -342,6 +343,24 @@ public default void forEachIndexed(IntFloatConsumer action) { @Override public FloatListIterator listIterator(int index); + /** + * Creates a Iterator that follows the indecies provided.
+ * For example if the Lists Contents is:
-1, 0 1
and the indecies are:
0, 1, 2, 2, 1, 0
+ * then the iterator will return the following values:
-1, 0, 1, 1, 0, -1 + * @param indecies that should be used for the iteration. + * @return a custom indexed iterator + */ + public FloatListIterator indexedIterator(int...indecies); + + /** + * Creates a Iterator that follows the indecies provided.
+ * For example if the Lists Contents is:
-1, 0 1
and the indecies are:
0, 1, 2, 2, 1, 0
+ * then the iterator will return the following values:
-1, 0, 1, 1, 0, -1 + * @param indecies that should be used for the iteration. + * @return a custom indexed iterator + */ + public FloatListIterator indexedIterator(IntList indecies); + /** * A Type-Specific List of subList * @see java.util.List#subList(int, int) diff --git a/src/main/java/speiger/src/collections/floats/maps/abstracts/AbstractFloat2BooleanMap.java b/src/main/java/speiger/src/collections/floats/maps/abstracts/AbstractFloat2BooleanMap.java index 5c32f192..49b36461 100644 --- a/src/main/java/speiger/src/collections/floats/maps/abstracts/AbstractFloat2BooleanMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/abstracts/AbstractFloat2BooleanMap.java @@ -151,6 +151,39 @@ public boolean computeBoolean(float key, FloatBooleanUnaryOperator mappingFuncti return newValue; } + @Override + public boolean computeBooleanIfAbsent(float key, FloatPredicate mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(!containsKey(key)) { + boolean newValue = mappingFunction.test(key); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public boolean supplyBooleanIfAbsent(float key, BooleanSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + if(!containsKey(key)) { + boolean newValue = valueProvider.getAsBoolean(); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public boolean computeBooleanIfPresent(float key, FloatBooleanUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(containsKey(key)) { + boolean newValue = mappingFunction.applyAsBoolean(key, get(key)); + put(key, newValue); + return newValue; + } + return getDefaultReturnValue(); + } + @Override public boolean computeBooleanNonDefault(float key, FloatBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -167,17 +200,6 @@ public boolean computeBooleanNonDefault(float key, FloatBooleanUnaryOperator map return newValue; } - @Override - public boolean computeBooleanIfAbsent(float key, FloatPredicate mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(!containsKey(key)) { - boolean newValue = mappingFunction.test(key); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public boolean computeBooleanIfAbsentNonDefault(float key, FloatPredicate mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -192,17 +214,6 @@ public boolean computeBooleanIfAbsentNonDefault(float key, FloatPredicate mappin return value; } - @Override - public boolean supplyBooleanIfAbsent(float key, BooleanSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - if(!containsKey(key)) { - boolean newValue = valueProvider.getAsBoolean(); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public boolean supplyBooleanIfAbsentNonDefault(float key, BooleanSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -217,17 +228,6 @@ public boolean supplyBooleanIfAbsentNonDefault(float key, BooleanSupplier valueP return value; } - @Override - public boolean computeBooleanIfPresent(float key, FloatBooleanUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(containsKey(key)) { - boolean newValue = mappingFunction.applyAsBoolean(key, get(key)); - put(key, newValue); - return newValue; - } - return getDefaultReturnValue(); - } - @Override public boolean computeBooleanIfPresentNonDefault(float key, FloatBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/floats/maps/abstracts/AbstractFloat2ByteMap.java b/src/main/java/speiger/src/collections/floats/maps/abstracts/AbstractFloat2ByteMap.java index 5ebf95d7..b0408978 100644 --- a/src/main/java/speiger/src/collections/floats/maps/abstracts/AbstractFloat2ByteMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/abstracts/AbstractFloat2ByteMap.java @@ -157,6 +157,39 @@ public byte computeByte(float key, FloatByteUnaryOperator mappingFunction) { return newValue; } + @Override + public byte computeByteIfAbsent(float key, Float2ByteFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(!containsKey(key)) { + byte newValue = mappingFunction.applyAsByte(key); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public byte supplyByteIfAbsent(float key, ByteSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + if(!containsKey(key)) { + byte newValue = valueProvider.getAsByte(); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public byte computeByteIfPresent(float key, FloatByteUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(containsKey(key)) { + byte newValue = mappingFunction.applyAsByte(key, get(key)); + put(key, newValue); + return newValue; + } + return getDefaultReturnValue(); + } + @Override public byte computeByteNonDefault(float key, FloatByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -173,17 +206,6 @@ public byte computeByteNonDefault(float key, FloatByteUnaryOperator mappingFunct return newValue; } - @Override - public byte computeByteIfAbsent(float key, Float2ByteFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(!containsKey(key)) { - byte newValue = mappingFunction.applyAsByte(key); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public byte computeByteIfAbsentNonDefault(float key, Float2ByteFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -198,23 +220,12 @@ public byte computeByteIfAbsentNonDefault(float key, Float2ByteFunction mappingF return value; } - @Override - public byte supplyByteIfAbsent(float key, ByteSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - if(!containsKey(key)) { - byte newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public byte supplyByteIfAbsentNonDefault(float key, ByteSupplier valueProvider) { Objects.requireNonNull(valueProvider); byte value; if((value = get(key)) == getDefaultReturnValue() || !containsKey(key)) { - byte newValue = valueProvider.getAsInt(); + byte newValue = valueProvider.getAsByte(); if(newValue != getDefaultReturnValue()) { put(key, newValue); return newValue; @@ -223,17 +234,6 @@ public byte supplyByteIfAbsentNonDefault(float key, ByteSupplier valueProvider) return value; } - @Override - public byte computeByteIfPresent(float key, FloatByteUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(containsKey(key)) { - byte newValue = mappingFunction.applyAsByte(key, get(key)); - put(key, newValue); - return newValue; - } - return getDefaultReturnValue(); - } - @Override public byte computeByteIfPresentNonDefault(float key, FloatByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/floats/maps/abstracts/AbstractFloat2CharMap.java b/src/main/java/speiger/src/collections/floats/maps/abstracts/AbstractFloat2CharMap.java index 7b06b001..4bff55fe 100644 --- a/src/main/java/speiger/src/collections/floats/maps/abstracts/AbstractFloat2CharMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/abstracts/AbstractFloat2CharMap.java @@ -157,6 +157,39 @@ public char computeChar(float key, FloatCharUnaryOperator mappingFunction) { return newValue; } + @Override + public char computeCharIfAbsent(float key, Float2CharFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(!containsKey(key)) { + char newValue = mappingFunction.applyAsChar(key); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public char supplyCharIfAbsent(float key, CharSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + if(!containsKey(key)) { + char newValue = valueProvider.getAsChar(); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public char computeCharIfPresent(float key, FloatCharUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(containsKey(key)) { + char newValue = mappingFunction.applyAsChar(key, get(key)); + put(key, newValue); + return newValue; + } + return getDefaultReturnValue(); + } + @Override public char computeCharNonDefault(float key, FloatCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -173,17 +206,6 @@ public char computeCharNonDefault(float key, FloatCharUnaryOperator mappingFunct return newValue; } - @Override - public char computeCharIfAbsent(float key, Float2CharFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(!containsKey(key)) { - char newValue = mappingFunction.applyAsChar(key); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public char computeCharIfAbsentNonDefault(float key, Float2CharFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -198,23 +220,12 @@ public char computeCharIfAbsentNonDefault(float key, Float2CharFunction mappingF return value; } - @Override - public char supplyCharIfAbsent(float key, CharSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - if(!containsKey(key)) { - char newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public char supplyCharIfAbsentNonDefault(float key, CharSupplier valueProvider) { Objects.requireNonNull(valueProvider); char value; if((value = get(key)) == getDefaultReturnValue() || !containsKey(key)) { - char newValue = valueProvider.getAsInt(); + char newValue = valueProvider.getAsChar(); if(newValue != getDefaultReturnValue()) { put(key, newValue); return newValue; @@ -223,17 +234,6 @@ public char supplyCharIfAbsentNonDefault(float key, CharSupplier valueProvider) return value; } - @Override - public char computeCharIfPresent(float key, FloatCharUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(containsKey(key)) { - char newValue = mappingFunction.applyAsChar(key, get(key)); - put(key, newValue); - return newValue; - } - return getDefaultReturnValue(); - } - @Override public char computeCharIfPresentNonDefault(float key, FloatCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/floats/maps/abstracts/AbstractFloat2DoubleMap.java b/src/main/java/speiger/src/collections/floats/maps/abstracts/AbstractFloat2DoubleMap.java index 5bc717ee..dfa4b1f2 100644 --- a/src/main/java/speiger/src/collections/floats/maps/abstracts/AbstractFloat2DoubleMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/abstracts/AbstractFloat2DoubleMap.java @@ -157,6 +157,39 @@ public double computeDouble(float key, FloatDoubleUnaryOperator mappingFunction) return newValue; } + @Override + public double computeDoubleIfAbsent(float key, Float2DoubleFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(!containsKey(key)) { + double newValue = mappingFunction.applyAsDouble(key); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public double supplyDoubleIfAbsent(float key, DoubleSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + if(!containsKey(key)) { + double newValue = valueProvider.getAsDouble(); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public double computeDoubleIfPresent(float key, FloatDoubleUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(containsKey(key)) { + double newValue = mappingFunction.applyAsDouble(key, get(key)); + put(key, newValue); + return newValue; + } + return getDefaultReturnValue(); + } + @Override public double computeDoubleNonDefault(float key, FloatDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -173,17 +206,6 @@ public double computeDoubleNonDefault(float key, FloatDoubleUnaryOperator mappin return newValue; } - @Override - public double computeDoubleIfAbsent(float key, Float2DoubleFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(!containsKey(key)) { - double newValue = mappingFunction.applyAsDouble(key); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public double computeDoubleIfAbsentNonDefault(float key, Float2DoubleFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -198,17 +220,6 @@ public double computeDoubleIfAbsentNonDefault(float key, Float2DoubleFunction ma return value; } - @Override - public double supplyDoubleIfAbsent(float key, DoubleSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - if(!containsKey(key)) { - double newValue = valueProvider.getAsDouble(); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public double supplyDoubleIfAbsentNonDefault(float key, DoubleSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -223,17 +234,6 @@ public double supplyDoubleIfAbsentNonDefault(float key, DoubleSupplier valueProv return value; } - @Override - public double computeDoubleIfPresent(float key, FloatDoubleUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(containsKey(key)) { - double newValue = mappingFunction.applyAsDouble(key, get(key)); - put(key, newValue); - return newValue; - } - return getDefaultReturnValue(); - } - @Override public double computeDoubleIfPresentNonDefault(float key, FloatDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/floats/maps/abstracts/AbstractFloat2FloatMap.java b/src/main/java/speiger/src/collections/floats/maps/abstracts/AbstractFloat2FloatMap.java index 339beb1a..50804058 100644 --- a/src/main/java/speiger/src/collections/floats/maps/abstracts/AbstractFloat2FloatMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/abstracts/AbstractFloat2FloatMap.java @@ -155,6 +155,39 @@ public float computeFloat(float key, FloatFloatUnaryOperator mappingFunction) { return newValue; } + @Override + public float computeFloatIfAbsent(float key, FloatUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(!containsKey(key)) { + float newValue = mappingFunction.applyAsFloat(key); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public float supplyFloatIfAbsent(float key, FloatSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + if(!containsKey(key)) { + float newValue = valueProvider.getAsFloat(); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public float computeFloatIfPresent(float key, FloatFloatUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(containsKey(key)) { + float newValue = mappingFunction.applyAsFloat(key, get(key)); + put(key, newValue); + return newValue; + } + return getDefaultReturnValue(); + } + @Override public float computeFloatNonDefault(float key, FloatFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -171,17 +204,6 @@ public float computeFloatNonDefault(float key, FloatFloatUnaryOperator mappingFu return newValue; } - @Override - public float computeFloatIfAbsent(float key, FloatUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(!containsKey(key)) { - float newValue = mappingFunction.applyAsFloat(key); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public float computeFloatIfAbsentNonDefault(float key, FloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -196,23 +218,12 @@ public float computeFloatIfAbsentNonDefault(float key, FloatUnaryOperator mappin return value; } - @Override - public float supplyFloatIfAbsent(float key, FloatSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - if(!containsKey(key)) { - float newValue = valueProvider.getAsDouble(); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public float supplyFloatIfAbsentNonDefault(float key, FloatSupplier valueProvider) { Objects.requireNonNull(valueProvider); float value; if((value = get(key)) == getDefaultReturnValue() || !containsKey(key)) { - float newValue = valueProvider.getAsDouble(); + float newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) != Float.floatToIntBits(getDefaultReturnValue())) { put(key, newValue); return newValue; @@ -221,17 +232,6 @@ public float supplyFloatIfAbsentNonDefault(float key, FloatSupplier valueProvide return value; } - @Override - public float computeFloatIfPresent(float key, FloatFloatUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(containsKey(key)) { - float newValue = mappingFunction.applyAsFloat(key, get(key)); - put(key, newValue); - return newValue; - } - return getDefaultReturnValue(); - } - @Override public float computeFloatIfPresentNonDefault(float key, FloatFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/floats/maps/abstracts/AbstractFloat2IntMap.java b/src/main/java/speiger/src/collections/floats/maps/abstracts/AbstractFloat2IntMap.java index 465ae9e5..5e409ed8 100644 --- a/src/main/java/speiger/src/collections/floats/maps/abstracts/AbstractFloat2IntMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/abstracts/AbstractFloat2IntMap.java @@ -157,6 +157,39 @@ public int computeInt(float key, FloatIntUnaryOperator mappingFunction) { return newValue; } + @Override + public int computeIntIfAbsent(float key, Float2IntFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(!containsKey(key)) { + int newValue = mappingFunction.applyAsInt(key); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public int supplyIntIfAbsent(float key, IntSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + if(!containsKey(key)) { + int newValue = valueProvider.getAsInt(); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public int computeIntIfPresent(float key, FloatIntUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(containsKey(key)) { + int newValue = mappingFunction.applyAsInt(key, get(key)); + put(key, newValue); + return newValue; + } + return getDefaultReturnValue(); + } + @Override public int computeIntNonDefault(float key, FloatIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -173,17 +206,6 @@ public int computeIntNonDefault(float key, FloatIntUnaryOperator mappingFunction return newValue; } - @Override - public int computeIntIfAbsent(float key, Float2IntFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(!containsKey(key)) { - int newValue = mappingFunction.applyAsInt(key); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public int computeIntIfAbsentNonDefault(float key, Float2IntFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -198,17 +220,6 @@ public int computeIntIfAbsentNonDefault(float key, Float2IntFunction mappingFunc return value; } - @Override - public int supplyIntIfAbsent(float key, IntSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - if(!containsKey(key)) { - int newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public int supplyIntIfAbsentNonDefault(float key, IntSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -223,17 +234,6 @@ public int supplyIntIfAbsentNonDefault(float key, IntSupplier valueProvider) { return value; } - @Override - public int computeIntIfPresent(float key, FloatIntUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(containsKey(key)) { - int newValue = mappingFunction.applyAsInt(key, get(key)); - put(key, newValue); - return newValue; - } - return getDefaultReturnValue(); - } - @Override public int computeIntIfPresentNonDefault(float key, FloatIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/floats/maps/abstracts/AbstractFloat2LongMap.java b/src/main/java/speiger/src/collections/floats/maps/abstracts/AbstractFloat2LongMap.java index 75d1a69f..4207688f 100644 --- a/src/main/java/speiger/src/collections/floats/maps/abstracts/AbstractFloat2LongMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/abstracts/AbstractFloat2LongMap.java @@ -157,6 +157,39 @@ public long computeLong(float key, FloatLongUnaryOperator mappingFunction) { return newValue; } + @Override + public long computeLongIfAbsent(float key, Float2LongFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(!containsKey(key)) { + long newValue = mappingFunction.applyAsLong(key); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public long supplyLongIfAbsent(float key, LongSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + if(!containsKey(key)) { + long newValue = valueProvider.getAsLong(); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public long computeLongIfPresent(float key, FloatLongUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(containsKey(key)) { + long newValue = mappingFunction.applyAsLong(key, get(key)); + put(key, newValue); + return newValue; + } + return getDefaultReturnValue(); + } + @Override public long computeLongNonDefault(float key, FloatLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -173,17 +206,6 @@ public long computeLongNonDefault(float key, FloatLongUnaryOperator mappingFunct return newValue; } - @Override - public long computeLongIfAbsent(float key, Float2LongFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(!containsKey(key)) { - long newValue = mappingFunction.applyAsLong(key); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public long computeLongIfAbsentNonDefault(float key, Float2LongFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -198,17 +220,6 @@ public long computeLongIfAbsentNonDefault(float key, Float2LongFunction mappingF return value; } - @Override - public long supplyLongIfAbsent(float key, LongSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - if(!containsKey(key)) { - long newValue = valueProvider.getAsLong(); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public long supplyLongIfAbsentNonDefault(float key, LongSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -223,17 +234,6 @@ public long supplyLongIfAbsentNonDefault(float key, LongSupplier valueProvider) return value; } - @Override - public long computeLongIfPresent(float key, FloatLongUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(containsKey(key)) { - long newValue = mappingFunction.applyAsLong(key, get(key)); - put(key, newValue); - return newValue; - } - return getDefaultReturnValue(); - } - @Override public long computeLongIfPresentNonDefault(float key, FloatLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/floats/maps/abstracts/AbstractFloat2ObjectMap.java b/src/main/java/speiger/src/collections/floats/maps/abstracts/AbstractFloat2ObjectMap.java index 66e35695..35af0922 100644 --- a/src/main/java/speiger/src/collections/floats/maps/abstracts/AbstractFloat2ObjectMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/abstracts/AbstractFloat2ObjectMap.java @@ -159,22 +159,6 @@ public V compute(float key, FloatObjectUnaryOperator mappingFunction) { return newValue; } - @Override - public V computeNonDefault(float key, FloatObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - V value = get(key); - V newValue = mappingFunction.apply(key, value); - if(Objects.equals(newValue, getDefaultReturnValue())) { - if(!Objects.equals(value, getDefaultReturnValue()) || containsKey(key)) { - remove(key); - return getDefaultReturnValue(); - } - return getDefaultReturnValue(); - } - put(key, newValue); - return newValue; - } - @Override public V computeIfAbsent(float key, FloatFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -189,20 +173,6 @@ public V computeIfAbsent(float key, FloatFunction mappingFunction) { return value; } - @Override - public V computeIfAbsentNonDefault(float key, FloatFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - V value; - if((value = get(key)) == getDefaultReturnValue() || !containsKey(key)) { - V newValue = mappingFunction.apply(key); - if(!Objects.equals(newValue, getDefaultReturnValue())) { - put(key, newValue); - return newValue; - } - } - return value; - } - @Override public V supplyIfAbsent(float key, ObjectSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -217,20 +187,6 @@ public V supplyIfAbsent(float key, ObjectSupplier valueProvider) { return value; } - @Override - public V supplyIfAbsentNonDefault(float key, ObjectSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - V value; - if((value = get(key)) == getDefaultReturnValue() || !containsKey(key)) { - V newValue = valueProvider.get(); - if(!Objects.equals(newValue, getDefaultReturnValue())) { - put(key, newValue); - return newValue; - } - } - return value; - } - @Override public V computeIfPresent(float key, FloatObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -246,21 +202,6 @@ public V computeIfPresent(float key, FloatObjectUnaryOperator mappingFunction return getDefaultReturnValue(); } - @Override - public V computeIfPresentNonDefault(float key, FloatObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - V value; - if(!Objects.equals((value = get(key)), getDefaultReturnValue()) || containsKey(key)) { - V newValue = mappingFunction.apply(key, value); - if(!Objects.equals(newValue, getDefaultReturnValue())) { - put(key, newValue); - return newValue; - } - remove(key); - } - return getDefaultReturnValue(); - } - @Override public V merge(float key, V value, ObjectObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/floats/maps/abstracts/AbstractFloat2ShortMap.java b/src/main/java/speiger/src/collections/floats/maps/abstracts/AbstractFloat2ShortMap.java index 16a3b80d..0ea44cef 100644 --- a/src/main/java/speiger/src/collections/floats/maps/abstracts/AbstractFloat2ShortMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/abstracts/AbstractFloat2ShortMap.java @@ -157,6 +157,39 @@ public short computeShort(float key, FloatShortUnaryOperator mappingFunction) { return newValue; } + @Override + public short computeShortIfAbsent(float key, Float2ShortFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(!containsKey(key)) { + short newValue = mappingFunction.applyAsShort(key); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public short supplyShortIfAbsent(float key, ShortSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + if(!containsKey(key)) { + short newValue = valueProvider.getAsShort(); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public short computeShortIfPresent(float key, FloatShortUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(containsKey(key)) { + short newValue = mappingFunction.applyAsShort(key, get(key)); + put(key, newValue); + return newValue; + } + return getDefaultReturnValue(); + } + @Override public short computeShortNonDefault(float key, FloatShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -173,17 +206,6 @@ public short computeShortNonDefault(float key, FloatShortUnaryOperator mappingFu return newValue; } - @Override - public short computeShortIfAbsent(float key, Float2ShortFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(!containsKey(key)) { - short newValue = mappingFunction.applyAsShort(key); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public short computeShortIfAbsentNonDefault(float key, Float2ShortFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -198,23 +220,12 @@ public short computeShortIfAbsentNonDefault(float key, Float2ShortFunction mappi return value; } - @Override - public short supplyShortIfAbsent(float key, ShortSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - if(!containsKey(key)) { - short newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public short supplyShortIfAbsentNonDefault(float key, ShortSupplier valueProvider) { Objects.requireNonNull(valueProvider); short value; if((value = get(key)) == getDefaultReturnValue() || !containsKey(key)) { - short newValue = valueProvider.getAsInt(); + short newValue = valueProvider.getAsShort(); if(newValue != getDefaultReturnValue()) { put(key, newValue); return newValue; @@ -223,17 +234,6 @@ public short supplyShortIfAbsentNonDefault(float key, ShortSupplier valueProvide return value; } - @Override - public short computeShortIfPresent(float key, FloatShortUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(containsKey(key)) { - short newValue = mappingFunction.applyAsShort(key, get(key)); - put(key, newValue); - return newValue; - } - return getDefaultReturnValue(); - } - @Override public short computeShortIfPresentNonDefault(float key, FloatShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/concurrent/Float2BooleanConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/concurrent/Float2BooleanConcurrentOpenHashMap.java index e2174648..4d78c904 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/concurrent/Float2BooleanConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/concurrent/Float2BooleanConcurrentOpenHashMap.java @@ -438,13 +438,6 @@ public boolean computeBoolean(float key, FloatBooleanUnaryOperator mappingFuncti return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public boolean computeBooleanNonDefault(float key, FloatBooleanUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public boolean computeBooleanIfAbsent(float key, FloatPredicate mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -452,13 +445,6 @@ public boolean computeBooleanIfAbsent(float key, FloatPredicate mappingFunction) return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public boolean computeBooleanIfAbsentNonDefault(float key, FloatPredicate mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public boolean supplyBooleanIfAbsent(float key, BooleanSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -467,17 +453,31 @@ public boolean supplyBooleanIfAbsent(float key, BooleanSupplier valueProvider) { } @Override - public boolean supplyBooleanIfAbsentNonDefault(float key, BooleanSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public boolean computeBooleanIfPresent(float key, FloatBooleanUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); + return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } @Override - public boolean computeBooleanIfPresent(float key, FloatBooleanUnaryOperator mappingFunction) { + public boolean computeBooleanNonDefault(float key, FloatBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).computeIfPresent(hash, key, mappingFunction); + return getSegment(hash).computeNonDefault(hash, key, mappingFunction); + } + + @Override + public boolean computeBooleanIfAbsentNonDefault(float key, FloatPredicate mappingFunction) { + Objects.requireNonNull(mappingFunction); + int hash = getHashCode(key); + return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); + } + + @Override + public boolean supplyBooleanIfAbsentNonDefault(float key, BooleanSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + int hash = getHashCode(key); + return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); } @Override @@ -2032,35 +2032,29 @@ protected boolean compute(int hash, float key, FloatBooleanUnaryOperator mapping } } - protected boolean computeNonDefault(int hash, float key, FloatBooleanUnaryOperator mappingFunction) { + protected boolean computeIfAbsent(int hash, float key, FloatPredicate mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + boolean newValue = mappingFunction.test(key); insert(-index-1, key, newValue); return newValue; } - boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + boolean newValue = values[index]; return newValue; } finally { unlockWrite(stamp); } } - - protected boolean computeIfAbsent(int hash, float key, FloatPredicate mappingFunction) { + + protected boolean supplyIfAbsent(int hash, float key, BooleanSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - boolean newValue = mappingFunction.test(key); + boolean newValue = valueProvider.getAsBoolean(); insert(-index-1, key, newValue); return newValue; } @@ -2071,23 +2065,37 @@ protected boolean computeIfAbsent(int hash, float key, FloatPredicate mappingFun unlockWrite(stamp); } } + + protected boolean computeIfPresent(int hash, float key, FloatBooleanUnaryOperator mappingFunction) { + long stamp = writeLock(); + try { + int index = findIndex(hash, key); + if(index < 0) return getDefaultReturnValue(); + boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); + values[index] = newValue; + return newValue; + } + finally { + unlockWrite(stamp); + } + } - protected boolean computeIfAbsentNonDefault(int hash, float key, FloatPredicate mappingFunction) { + protected boolean computeNonDefault(int hash, float key, FloatBooleanUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - boolean newValue = mappingFunction.test(key); + boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - boolean newValue = values[index]; + boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.test(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } finally { @@ -2095,16 +2103,22 @@ protected boolean computeIfAbsentNonDefault(int hash, float key, FloatPredicate } } - protected boolean supplyIfAbsent(int hash, float key, BooleanSupplier valueProvider) { + protected boolean computeIfAbsentNonDefault(int hash, float key, FloatPredicate mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - boolean newValue = valueProvider.getAsBoolean(); + boolean newValue = mappingFunction.test(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } boolean newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.test(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } finally { @@ -2135,20 +2149,6 @@ protected boolean supplyIfAbsentNonDefault(int hash, float key, BooleanSupplier } } - protected boolean computeIfPresent(int hash, float key, FloatBooleanUnaryOperator mappingFunction) { - long stamp = writeLock(); - try { - int index = findIndex(hash, key); - if(index < 0) return getDefaultReturnValue(); - boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); - values[index] = newValue; - return newValue; - } - finally { - unlockWrite(stamp); - } - } - protected boolean computeIfPresentNonDefault(int hash, float key, FloatBooleanUnaryOperator mappingFunction) { long stamp = writeLock(); try { diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/concurrent/Float2ByteConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/concurrent/Float2ByteConcurrentOpenHashMap.java index 435419cd..50f4f6c9 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/concurrent/Float2ByteConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/concurrent/Float2ByteConcurrentOpenHashMap.java @@ -451,13 +451,6 @@ public byte computeByte(float key, FloatByteUnaryOperator mappingFunction) { return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public byte computeByteNonDefault(float key, FloatByteUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public byte computeByteIfAbsent(float key, Float2ByteFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -465,13 +458,6 @@ public byte computeByteIfAbsent(float key, Float2ByteFunction mappingFunction) { return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public byte computeByteIfAbsentNonDefault(float key, Float2ByteFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public byte supplyByteIfAbsent(float key, ByteSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -480,17 +466,31 @@ public byte supplyByteIfAbsent(float key, ByteSupplier valueProvider) { } @Override - public byte supplyByteIfAbsentNonDefault(float key, ByteSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public byte computeByteIfPresent(float key, FloatByteUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); + return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } @Override - public byte computeByteIfPresent(float key, FloatByteUnaryOperator mappingFunction) { + public byte computeByteNonDefault(float key, FloatByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).computeIfPresent(hash, key, mappingFunction); + return getSegment(hash).computeNonDefault(hash, key, mappingFunction); + } + + @Override + public byte computeByteIfAbsentNonDefault(float key, Float2ByteFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + int hash = getHashCode(key); + return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); + } + + @Override + public byte supplyByteIfAbsentNonDefault(float key, ByteSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + int hash = getHashCode(key); + return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); } @Override @@ -2076,35 +2076,29 @@ protected byte compute(int hash, float key, FloatByteUnaryOperator mappingFuncti } } - protected byte computeNonDefault(int hash, float key, FloatByteUnaryOperator mappingFunction) { + protected byte computeIfAbsent(int hash, float key, Float2ByteFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + byte newValue = mappingFunction.applyAsByte(key); insert(-index-1, key, newValue); return newValue; } - byte newValue = mappingFunction.applyAsByte(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + byte newValue = values[index]; return newValue; } finally { unlockWrite(stamp); } } - - protected byte computeIfAbsent(int hash, float key, Float2ByteFunction mappingFunction) { + + protected byte supplyIfAbsent(int hash, float key, ByteSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = valueProvider.getAsByte(); insert(-index-1, key, newValue); return newValue; } @@ -2115,23 +2109,14 @@ protected byte computeIfAbsent(int hash, float key, Float2ByteFunction mappingFu unlockWrite(stamp); } } - - protected byte computeIfAbsentNonDefault(int hash, float key, Float2ByteFunction mappingFunction) { + + protected byte computeIfPresent(int hash, float key, FloatByteUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key); - if(newValue == getDefaultReturnValue()) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - byte newValue = values[index]; - if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsByte(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; - } + if(index < 0) return getDefaultReturnValue(); + byte newValue = mappingFunction.applyAsByte(key, values[index]); + values[index] = newValue; return newValue; } finally { @@ -2139,16 +2124,22 @@ protected byte computeIfAbsentNonDefault(int hash, float key, Float2ByteFunction } } - protected byte supplyIfAbsent(int hash, float key, ByteSupplier valueProvider) { + protected byte computeNonDefault(int hash, float key, FloatByteUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - byte newValue = valueProvider.getAsInt(); + byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - byte newValue = values[index]; + byte newValue = mappingFunction.applyAsByte(key, values[index]); + if(newValue == getDefaultReturnValue()) { + removeIndex(index); + return newValue; + } + values[index] = newValue; return newValue; } finally { @@ -2156,19 +2147,19 @@ protected byte supplyIfAbsent(int hash, float key, ByteSupplier valueProvider) { } } - protected byte supplyIfAbsentNonDefault(int hash, float key, ByteSupplier valueProvider) { + protected byte computeIfAbsentNonDefault(int hash, float key, Float2ByteFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - byte newValue = valueProvider.getAsInt(); + byte newValue = mappingFunction.applyAsByte(key); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } byte newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = mappingFunction.applyAsByte(key); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } @@ -2179,13 +2170,22 @@ protected byte supplyIfAbsentNonDefault(int hash, float key, ByteSupplier valueP } } - protected byte computeIfPresent(int hash, float key, FloatByteUnaryOperator mappingFunction) { + protected byte supplyIfAbsentNonDefault(int hash, float key, ByteSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0) return getDefaultReturnValue(); - byte newValue = mappingFunction.applyAsByte(key, values[index]); - values[index] = newValue; + if(index < 0) { + byte newValue = valueProvider.getAsByte(); + if(newValue == getDefaultReturnValue()) return newValue; + insert(-index-1, key, newValue); + return newValue; + } + byte newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = valueProvider.getAsByte(); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } finally { diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/concurrent/Float2CharConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/concurrent/Float2CharConcurrentOpenHashMap.java index ed9a5351..768998dd 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/concurrent/Float2CharConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/concurrent/Float2CharConcurrentOpenHashMap.java @@ -451,13 +451,6 @@ public char computeChar(float key, FloatCharUnaryOperator mappingFunction) { return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public char computeCharNonDefault(float key, FloatCharUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public char computeCharIfAbsent(float key, Float2CharFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -465,13 +458,6 @@ public char computeCharIfAbsent(float key, Float2CharFunction mappingFunction) { return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public char computeCharIfAbsentNonDefault(float key, Float2CharFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public char supplyCharIfAbsent(float key, CharSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -480,17 +466,31 @@ public char supplyCharIfAbsent(float key, CharSupplier valueProvider) { } @Override - public char supplyCharIfAbsentNonDefault(float key, CharSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public char computeCharIfPresent(float key, FloatCharUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); + return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } @Override - public char computeCharIfPresent(float key, FloatCharUnaryOperator mappingFunction) { + public char computeCharNonDefault(float key, FloatCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).computeIfPresent(hash, key, mappingFunction); + return getSegment(hash).computeNonDefault(hash, key, mappingFunction); + } + + @Override + public char computeCharIfAbsentNonDefault(float key, Float2CharFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + int hash = getHashCode(key); + return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); + } + + @Override + public char supplyCharIfAbsentNonDefault(float key, CharSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + int hash = getHashCode(key); + return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); } @Override @@ -2076,35 +2076,29 @@ protected char compute(int hash, float key, FloatCharUnaryOperator mappingFuncti } } - protected char computeNonDefault(int hash, float key, FloatCharUnaryOperator mappingFunction) { + protected char computeIfAbsent(int hash, float key, Float2CharFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + char newValue = mappingFunction.applyAsChar(key); insert(-index-1, key, newValue); return newValue; } - char newValue = mappingFunction.applyAsChar(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + char newValue = values[index]; return newValue; } finally { unlockWrite(stamp); } } - - protected char computeIfAbsent(int hash, float key, Float2CharFunction mappingFunction) { + + protected char supplyIfAbsent(int hash, float key, CharSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = valueProvider.getAsChar(); insert(-index-1, key, newValue); return newValue; } @@ -2115,23 +2109,14 @@ protected char computeIfAbsent(int hash, float key, Float2CharFunction mappingFu unlockWrite(stamp); } } - - protected char computeIfAbsentNonDefault(int hash, float key, Float2CharFunction mappingFunction) { + + protected char computeIfPresent(int hash, float key, FloatCharUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0) { - char newValue = mappingFunction.applyAsChar(key); - if(newValue == getDefaultReturnValue()) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - char newValue = values[index]; - if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsChar(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; - } + if(index < 0) return getDefaultReturnValue(); + char newValue = mappingFunction.applyAsChar(key, values[index]); + values[index] = newValue; return newValue; } finally { @@ -2139,16 +2124,22 @@ protected char computeIfAbsentNonDefault(int hash, float key, Float2CharFunction } } - protected char supplyIfAbsent(int hash, float key, CharSupplier valueProvider) { + protected char computeNonDefault(int hash, float key, FloatCharUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - char newValue = valueProvider.getAsInt(); + char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - char newValue = values[index]; + char newValue = mappingFunction.applyAsChar(key, values[index]); + if(newValue == getDefaultReturnValue()) { + removeIndex(index); + return newValue; + } + values[index] = newValue; return newValue; } finally { @@ -2156,19 +2147,19 @@ protected char supplyIfAbsent(int hash, float key, CharSupplier valueProvider) { } } - protected char supplyIfAbsentNonDefault(int hash, float key, CharSupplier valueProvider) { + protected char computeIfAbsentNonDefault(int hash, float key, Float2CharFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - char newValue = valueProvider.getAsInt(); + char newValue = mappingFunction.applyAsChar(key); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } char newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = mappingFunction.applyAsChar(key); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } @@ -2179,13 +2170,22 @@ protected char supplyIfAbsentNonDefault(int hash, float key, CharSupplier valueP } } - protected char computeIfPresent(int hash, float key, FloatCharUnaryOperator mappingFunction) { + protected char supplyIfAbsentNonDefault(int hash, float key, CharSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0) return getDefaultReturnValue(); - char newValue = mappingFunction.applyAsChar(key, values[index]); - values[index] = newValue; + if(index < 0) { + char newValue = valueProvider.getAsChar(); + if(newValue == getDefaultReturnValue()) return newValue; + insert(-index-1, key, newValue); + return newValue; + } + char newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = valueProvider.getAsChar(); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } finally { diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/concurrent/Float2DoubleConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/concurrent/Float2DoubleConcurrentOpenHashMap.java index d7ecf97d..fb173fa7 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/concurrent/Float2DoubleConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/concurrent/Float2DoubleConcurrentOpenHashMap.java @@ -451,13 +451,6 @@ public double computeDouble(float key, FloatDoubleUnaryOperator mappingFunction) return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public double computeDoubleNonDefault(float key, FloatDoubleUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public double computeDoubleIfAbsent(float key, Float2DoubleFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -465,13 +458,6 @@ public double computeDoubleIfAbsent(float key, Float2DoubleFunction mappingFunct return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public double computeDoubleIfAbsentNonDefault(float key, Float2DoubleFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public double supplyDoubleIfAbsent(float key, DoubleSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -480,17 +466,31 @@ public double supplyDoubleIfAbsent(float key, DoubleSupplier valueProvider) { } @Override - public double supplyDoubleIfAbsentNonDefault(float key, DoubleSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public double computeDoubleIfPresent(float key, FloatDoubleUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); + return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } @Override - public double computeDoubleIfPresent(float key, FloatDoubleUnaryOperator mappingFunction) { + public double computeDoubleNonDefault(float key, FloatDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).computeIfPresent(hash, key, mappingFunction); + return getSegment(hash).computeNonDefault(hash, key, mappingFunction); + } + + @Override + public double computeDoubleIfAbsentNonDefault(float key, Float2DoubleFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + int hash = getHashCode(key); + return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); + } + + @Override + public double supplyDoubleIfAbsentNonDefault(float key, DoubleSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + int hash = getHashCode(key); + return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); } @Override @@ -2076,35 +2076,29 @@ protected double compute(int hash, float key, FloatDoubleUnaryOperator mappingFu } } - protected double computeNonDefault(int hash, float key, FloatDoubleUnaryOperator mappingFunction) { + protected double computeIfAbsent(int hash, float key, Float2DoubleFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + double newValue = mappingFunction.applyAsDouble(key); insert(-index-1, key, newValue); return newValue; } - double newValue = mappingFunction.applyAsDouble(key, values[index]); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + double newValue = values[index]; return newValue; } finally { unlockWrite(stamp); } } - - protected double computeIfAbsent(int hash, float key, Float2DoubleFunction mappingFunction) { + + protected double supplyIfAbsent(int hash, float key, DoubleSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = valueProvider.getAsDouble(); insert(-index-1, key, newValue); return newValue; } @@ -2115,23 +2109,37 @@ protected double computeIfAbsent(int hash, float key, Float2DoubleFunction mappi unlockWrite(stamp); } } + + protected double computeIfPresent(int hash, float key, FloatDoubleUnaryOperator mappingFunction) { + long stamp = writeLock(); + try { + int index = findIndex(hash, key); + if(index < 0) return getDefaultReturnValue(); + double newValue = mappingFunction.applyAsDouble(key, values[index]); + values[index] = newValue; + return newValue; + } + finally { + unlockWrite(stamp); + } + } - protected double computeIfAbsentNonDefault(int hash, float key, Float2DoubleFunction mappingFunction) { + protected double computeNonDefault(int hash, float key, FloatDoubleUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } - double newValue = values[index]; + double newValue = mappingFunction.applyAsDouble(key, values[index]); if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - newValue = mappingFunction.applyAsDouble(key); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } finally { @@ -2139,16 +2147,22 @@ protected double computeIfAbsentNonDefault(int hash, float key, Float2DoubleFunc } } - protected double supplyIfAbsent(int hash, float key, DoubleSupplier valueProvider) { + protected double computeIfAbsentNonDefault(int hash, float key, Float2DoubleFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - double newValue = valueProvider.getAsDouble(); + double newValue = mappingFunction.applyAsDouble(key); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } double newValue = values[index]; + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { + newValue = mappingFunction.applyAsDouble(key); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + values[index] = newValue; + } return newValue; } finally { @@ -2179,20 +2193,6 @@ protected double supplyIfAbsentNonDefault(int hash, float key, DoubleSupplier va } } - protected double computeIfPresent(int hash, float key, FloatDoubleUnaryOperator mappingFunction) { - long stamp = writeLock(); - try { - int index = findIndex(hash, key); - if(index < 0) return getDefaultReturnValue(); - double newValue = mappingFunction.applyAsDouble(key, values[index]); - values[index] = newValue; - return newValue; - } - finally { - unlockWrite(stamp); - } - } - protected double computeIfPresentNonDefault(int hash, float key, FloatDoubleUnaryOperator mappingFunction) { long stamp = writeLock(); try { diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/concurrent/Float2FloatConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/concurrent/Float2FloatConcurrentOpenHashMap.java index 615a8289..fe5126c5 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/concurrent/Float2FloatConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/concurrent/Float2FloatConcurrentOpenHashMap.java @@ -444,13 +444,6 @@ public float computeFloat(float key, FloatFloatUnaryOperator mappingFunction) { return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public float computeFloatNonDefault(float key, FloatFloatUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public float computeFloatIfAbsent(float key, FloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -458,13 +451,6 @@ public float computeFloatIfAbsent(float key, FloatUnaryOperator mappingFunction) return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public float computeFloatIfAbsentNonDefault(float key, FloatUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public float supplyFloatIfAbsent(float key, FloatSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -473,17 +459,31 @@ public float supplyFloatIfAbsent(float key, FloatSupplier valueProvider) { } @Override - public float supplyFloatIfAbsentNonDefault(float key, FloatSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public float computeFloatIfPresent(float key, FloatFloatUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); + return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } @Override - public float computeFloatIfPresent(float key, FloatFloatUnaryOperator mappingFunction) { + public float computeFloatNonDefault(float key, FloatFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).computeIfPresent(hash, key, mappingFunction); + return getSegment(hash).computeNonDefault(hash, key, mappingFunction); + } + + @Override + public float computeFloatIfAbsentNonDefault(float key, FloatUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int hash = getHashCode(key); + return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); + } + + @Override + public float supplyFloatIfAbsentNonDefault(float key, FloatSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + int hash = getHashCode(key); + return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); } @Override @@ -2069,35 +2069,29 @@ protected float compute(int hash, float key, FloatFloatUnaryOperator mappingFunc } } - protected float computeNonDefault(int hash, float key, FloatFloatUnaryOperator mappingFunction) { + protected float computeIfAbsent(int hash, float key, FloatUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + float newValue = mappingFunction.applyAsFloat(key); insert(-index-1, key, newValue); return newValue; } - float newValue = mappingFunction.applyAsFloat(key, values[index]); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + float newValue = values[index]; return newValue; } finally { unlockWrite(stamp); } } - - protected float computeIfAbsent(int hash, float key, FloatUnaryOperator mappingFunction) { + + protected float supplyIfAbsent(int hash, float key, FloatSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = valueProvider.getAsFloat(); insert(-index-1, key, newValue); return newValue; } @@ -2108,23 +2102,14 @@ protected float computeIfAbsent(int hash, float key, FloatUnaryOperator mappingF unlockWrite(stamp); } } - - protected float computeIfAbsentNonDefault(int hash, float key, FloatUnaryOperator mappingFunction) { + + protected float computeIfPresent(int hash, float key, FloatFloatUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - float newValue = values[index]; - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - newValue = mappingFunction.applyAsFloat(key); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; - values[index] = newValue; - } + if(index < 0) return getDefaultReturnValue(); + float newValue = mappingFunction.applyAsFloat(key, values[index]); + values[index] = newValue; return newValue; } finally { @@ -2132,16 +2117,22 @@ protected float computeIfAbsentNonDefault(int hash, float key, FloatUnaryOperato } } - protected float supplyIfAbsent(int hash, float key, FloatSupplier valueProvider) { + protected float computeNonDefault(int hash, float key, FloatFloatUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - float newValue = valueProvider.getAsDouble(); + float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } - float newValue = values[index]; + float newValue = mappingFunction.applyAsFloat(key, values[index]); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { + removeIndex(index); + return newValue; + } + values[index] = newValue; return newValue; } finally { @@ -2149,19 +2140,19 @@ protected float supplyIfAbsent(int hash, float key, FloatSupplier valueProvider) } } - protected float supplyIfAbsentNonDefault(int hash, float key, FloatSupplier valueProvider) { + protected float computeIfAbsentNonDefault(int hash, float key, FloatUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - float newValue = valueProvider.getAsDouble(); + float newValue = mappingFunction.applyAsFloat(key); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } float newValue = values[index]; if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - newValue = valueProvider.getAsDouble(); + newValue = mappingFunction.applyAsFloat(key); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; values[index] = newValue; } @@ -2172,13 +2163,22 @@ protected float supplyIfAbsentNonDefault(int hash, float key, FloatSupplier valu } } - protected float computeIfPresent(int hash, float key, FloatFloatUnaryOperator mappingFunction) { + protected float supplyIfAbsentNonDefault(int hash, float key, FloatSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0) return getDefaultReturnValue(); - float newValue = mappingFunction.applyAsFloat(key, values[index]); - values[index] = newValue; + if(index < 0) { + float newValue = valueProvider.getAsFloat(); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + insert(-index-1, key, newValue); + return newValue; + } + float newValue = values[index]; + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { + newValue = valueProvider.getAsFloat(); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + values[index] = newValue; + } return newValue; } finally { diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/concurrent/Float2IntConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/concurrent/Float2IntConcurrentOpenHashMap.java index 85cf4baf..f8f33c19 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/concurrent/Float2IntConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/concurrent/Float2IntConcurrentOpenHashMap.java @@ -451,13 +451,6 @@ public int computeInt(float key, FloatIntUnaryOperator mappingFunction) { return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public int computeIntNonDefault(float key, FloatIntUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public int computeIntIfAbsent(float key, Float2IntFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -465,13 +458,6 @@ public int computeIntIfAbsent(float key, Float2IntFunction mappingFunction) { return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public int computeIntIfAbsentNonDefault(float key, Float2IntFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public int supplyIntIfAbsent(float key, IntSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -480,17 +466,31 @@ public int supplyIntIfAbsent(float key, IntSupplier valueProvider) { } @Override - public int supplyIntIfAbsentNonDefault(float key, IntSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public int computeIntIfPresent(float key, FloatIntUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); + return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } @Override - public int computeIntIfPresent(float key, FloatIntUnaryOperator mappingFunction) { + public int computeIntNonDefault(float key, FloatIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).computeIfPresent(hash, key, mappingFunction); + return getSegment(hash).computeNonDefault(hash, key, mappingFunction); + } + + @Override + public int computeIntIfAbsentNonDefault(float key, Float2IntFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + int hash = getHashCode(key); + return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); + } + + @Override + public int supplyIntIfAbsentNonDefault(float key, IntSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + int hash = getHashCode(key); + return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); } @Override @@ -2076,35 +2076,29 @@ protected int compute(int hash, float key, FloatIntUnaryOperator mappingFunction } } - protected int computeNonDefault(int hash, float key, FloatIntUnaryOperator mappingFunction) { + protected int computeIfAbsent(int hash, float key, Float2IntFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + int newValue = mappingFunction.applyAsInt(key); insert(-index-1, key, newValue); return newValue; } - int newValue = mappingFunction.applyAsInt(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + int newValue = values[index]; return newValue; } finally { unlockWrite(stamp); } } - - protected int computeIfAbsent(int hash, float key, Float2IntFunction mappingFunction) { + + protected int supplyIfAbsent(int hash, float key, IntSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = valueProvider.getAsInt(); insert(-index-1, key, newValue); return newValue; } @@ -2115,23 +2109,37 @@ protected int computeIfAbsent(int hash, float key, Float2IntFunction mappingFunc unlockWrite(stamp); } } + + protected int computeIfPresent(int hash, float key, FloatIntUnaryOperator mappingFunction) { + long stamp = writeLock(); + try { + int index = findIndex(hash, key); + if(index < 0) return getDefaultReturnValue(); + int newValue = mappingFunction.applyAsInt(key, values[index]); + values[index] = newValue; + return newValue; + } + finally { + unlockWrite(stamp); + } + } - protected int computeIfAbsentNonDefault(int hash, float key, Float2IntFunction mappingFunction) { + protected int computeNonDefault(int hash, float key, FloatIntUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - int newValue = values[index]; + int newValue = mappingFunction.applyAsInt(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsInt(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } finally { @@ -2139,16 +2147,22 @@ protected int computeIfAbsentNonDefault(int hash, float key, Float2IntFunction m } } - protected int supplyIfAbsent(int hash, float key, IntSupplier valueProvider) { + protected int computeIfAbsentNonDefault(int hash, float key, Float2IntFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - int newValue = valueProvider.getAsInt(); + int newValue = mappingFunction.applyAsInt(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } int newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsInt(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } finally { @@ -2179,20 +2193,6 @@ protected int supplyIfAbsentNonDefault(int hash, float key, IntSupplier valuePro } } - protected int computeIfPresent(int hash, float key, FloatIntUnaryOperator mappingFunction) { - long stamp = writeLock(); - try { - int index = findIndex(hash, key); - if(index < 0) return getDefaultReturnValue(); - int newValue = mappingFunction.applyAsInt(key, values[index]); - values[index] = newValue; - return newValue; - } - finally { - unlockWrite(stamp); - } - } - protected int computeIfPresentNonDefault(int hash, float key, FloatIntUnaryOperator mappingFunction) { long stamp = writeLock(); try { diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/concurrent/Float2LongConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/concurrent/Float2LongConcurrentOpenHashMap.java index 482186df..2add7a18 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/concurrent/Float2LongConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/concurrent/Float2LongConcurrentOpenHashMap.java @@ -451,13 +451,6 @@ public long computeLong(float key, FloatLongUnaryOperator mappingFunction) { return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public long computeLongNonDefault(float key, FloatLongUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public long computeLongIfAbsent(float key, Float2LongFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -465,13 +458,6 @@ public long computeLongIfAbsent(float key, Float2LongFunction mappingFunction) { return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public long computeLongIfAbsentNonDefault(float key, Float2LongFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public long supplyLongIfAbsent(float key, LongSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -480,17 +466,31 @@ public long supplyLongIfAbsent(float key, LongSupplier valueProvider) { } @Override - public long supplyLongIfAbsentNonDefault(float key, LongSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public long computeLongIfPresent(float key, FloatLongUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); + return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } @Override - public long computeLongIfPresent(float key, FloatLongUnaryOperator mappingFunction) { + public long computeLongNonDefault(float key, FloatLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).computeIfPresent(hash, key, mappingFunction); + return getSegment(hash).computeNonDefault(hash, key, mappingFunction); + } + + @Override + public long computeLongIfAbsentNonDefault(float key, Float2LongFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + int hash = getHashCode(key); + return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); + } + + @Override + public long supplyLongIfAbsentNonDefault(float key, LongSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + int hash = getHashCode(key); + return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); } @Override @@ -2076,35 +2076,29 @@ protected long compute(int hash, float key, FloatLongUnaryOperator mappingFuncti } } - protected long computeNonDefault(int hash, float key, FloatLongUnaryOperator mappingFunction) { + protected long computeIfAbsent(int hash, float key, Float2LongFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + long newValue = mappingFunction.applyAsLong(key); insert(-index-1, key, newValue); return newValue; } - long newValue = mappingFunction.applyAsLong(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + long newValue = values[index]; return newValue; } finally { unlockWrite(stamp); } } - - protected long computeIfAbsent(int hash, float key, Float2LongFunction mappingFunction) { + + protected long supplyIfAbsent(int hash, float key, LongSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = valueProvider.getAsLong(); insert(-index-1, key, newValue); return newValue; } @@ -2115,23 +2109,37 @@ protected long computeIfAbsent(int hash, float key, Float2LongFunction mappingFu unlockWrite(stamp); } } + + protected long computeIfPresent(int hash, float key, FloatLongUnaryOperator mappingFunction) { + long stamp = writeLock(); + try { + int index = findIndex(hash, key); + if(index < 0) return getDefaultReturnValue(); + long newValue = mappingFunction.applyAsLong(key, values[index]); + values[index] = newValue; + return newValue; + } + finally { + unlockWrite(stamp); + } + } - protected long computeIfAbsentNonDefault(int hash, float key, Float2LongFunction mappingFunction) { + protected long computeNonDefault(int hash, float key, FloatLongUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - long newValue = values[index]; + long newValue = mappingFunction.applyAsLong(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsLong(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } finally { @@ -2139,16 +2147,22 @@ protected long computeIfAbsentNonDefault(int hash, float key, Float2LongFunction } } - protected long supplyIfAbsent(int hash, float key, LongSupplier valueProvider) { + protected long computeIfAbsentNonDefault(int hash, float key, Float2LongFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - long newValue = valueProvider.getAsLong(); + long newValue = mappingFunction.applyAsLong(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } long newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsLong(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } finally { @@ -2179,20 +2193,6 @@ protected long supplyIfAbsentNonDefault(int hash, float key, LongSupplier valueP } } - protected long computeIfPresent(int hash, float key, FloatLongUnaryOperator mappingFunction) { - long stamp = writeLock(); - try { - int index = findIndex(hash, key); - if(index < 0) return getDefaultReturnValue(); - long newValue = mappingFunction.applyAsLong(key, values[index]); - values[index] = newValue; - return newValue; - } - finally { - unlockWrite(stamp); - } - } - protected long computeIfPresentNonDefault(int hash, float key, FloatLongUnaryOperator mappingFunction) { long stamp = writeLock(); try { diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/concurrent/Float2ObjectConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/concurrent/Float2ObjectConcurrentOpenHashMap.java index 94669f21..007122b7 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/concurrent/Float2ObjectConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/concurrent/Float2ObjectConcurrentOpenHashMap.java @@ -426,13 +426,6 @@ public V compute(float key, FloatObjectUnaryOperator mappingFunction) { return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public V computeNonDefault(float key, FloatObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public V computeIfAbsent(float key, FloatFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -440,13 +433,6 @@ public V computeIfAbsent(float key, FloatFunction mappingFunction) { return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public V computeIfAbsentNonDefault(float key, FloatFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public V supplyIfAbsent(float key, ObjectSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -454,13 +440,6 @@ public V supplyIfAbsent(float key, ObjectSupplier valueProvider) { return getSegment(hash).supplyIfAbsent(hash, key, valueProvider); } - @Override - public V supplyIfAbsentNonDefault(float key, ObjectSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); - } - @Override public V computeIfPresent(float key, FloatObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -468,13 +447,6 @@ public V computeIfPresent(float key, FloatObjectUnaryOperator mappingFunction return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } - @Override - public V computeIfPresentNonDefault(float key, FloatObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfPresentNonDefault(hash, key, mappingFunction); - } - @Override public V merge(float key, V value, ObjectObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -2011,29 +1983,6 @@ protected V compute(int hash, float key, FloatObjectUnaryOperator mappingFunc } } - protected V computeNonDefault(int hash, float key, FloatObjectUnaryOperator mappingFunction) { - long stamp = writeLock(); - try { - int index = findIndex(hash, key); - if(index < 0) { - V newValue = mappingFunction.apply(key, getDefaultReturnValue()); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = mappingFunction.apply(key, values[index]); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; - return newValue; - } - finally { - unlockWrite(stamp); - } - } - protected V computeIfAbsent(int hash, float key, FloatFunction mappingFunction) { long stamp = writeLock(); try { @@ -2056,30 +2005,7 @@ protected V computeIfAbsent(int hash, float key, FloatFunction mappingFunctio unlockWrite(stamp); } } - - protected V computeIfAbsentNonDefault(int hash, float key, FloatFunction mappingFunction) { - long stamp = writeLock(); - try { - int index = findIndex(hash, key); - if(index < 0) { - V newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = values[index]; - if(Objects.equals(newValue, getDefaultReturnValue())) { - newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - values[index] = newValue; - } - return newValue; - } - finally { - unlockWrite(stamp); - } - } - + protected V supplyIfAbsent(int hash, float key, ObjectSupplier valueProvider) { long stamp = writeLock(); try { @@ -2102,30 +2028,7 @@ protected V supplyIfAbsent(int hash, float key, ObjectSupplier valueProvider) unlockWrite(stamp); } } - - protected V supplyIfAbsentNonDefault(int hash, float key, ObjectSupplier valueProvider) { - long stamp = writeLock(); - try { - int index = findIndex(hash, key); - if(index < 0) { - V newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = values[index]; - if(Objects.equals(newValue, getDefaultReturnValue())) { - newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - values[index] = newValue; - } - return newValue; - } - finally { - unlockWrite(stamp); - } - } - + protected V computeIfPresent(int hash, float key, FloatObjectUnaryOperator mappingFunction) { long stamp = writeLock(); try { @@ -2144,11 +2047,16 @@ protected V computeIfPresent(int hash, float key, FloatObjectUnaryOperator ma } } - protected V computeIfPresentNonDefault(int hash, float key, FloatObjectUnaryOperator mappingFunction) { + protected V computeNonDefault(int hash, float key, FloatObjectUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0 || Objects.equals(values[index], getDefaultReturnValue())) return getDefaultReturnValue(); + if(index < 0) { + V newValue = mappingFunction.apply(key, getDefaultReturnValue()); + if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; + insert(-index-1, key, newValue); + return newValue; + } V newValue = mappingFunction.apply(key, values[index]); if(Objects.equals(newValue, getDefaultReturnValue())) { removeIndex(index); diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/concurrent/Float2ShortConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/concurrent/Float2ShortConcurrentOpenHashMap.java index e6a48c12..ce277390 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/concurrent/Float2ShortConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/concurrent/Float2ShortConcurrentOpenHashMap.java @@ -451,13 +451,6 @@ public short computeShort(float key, FloatShortUnaryOperator mappingFunction) { return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public short computeShortNonDefault(float key, FloatShortUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public short computeShortIfAbsent(float key, Float2ShortFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -465,13 +458,6 @@ public short computeShortIfAbsent(float key, Float2ShortFunction mappingFunction return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public short computeShortIfAbsentNonDefault(float key, Float2ShortFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public short supplyShortIfAbsent(float key, ShortSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -480,17 +466,31 @@ public short supplyShortIfAbsent(float key, ShortSupplier valueProvider) { } @Override - public short supplyShortIfAbsentNonDefault(float key, ShortSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public short computeShortIfPresent(float key, FloatShortUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); + return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } @Override - public short computeShortIfPresent(float key, FloatShortUnaryOperator mappingFunction) { + public short computeShortNonDefault(float key, FloatShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).computeIfPresent(hash, key, mappingFunction); + return getSegment(hash).computeNonDefault(hash, key, mappingFunction); + } + + @Override + public short computeShortIfAbsentNonDefault(float key, Float2ShortFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + int hash = getHashCode(key); + return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); + } + + @Override + public short supplyShortIfAbsentNonDefault(float key, ShortSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + int hash = getHashCode(key); + return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); } @Override @@ -2076,35 +2076,29 @@ protected short compute(int hash, float key, FloatShortUnaryOperator mappingFunc } } - protected short computeNonDefault(int hash, float key, FloatShortUnaryOperator mappingFunction) { + protected short computeIfAbsent(int hash, float key, Float2ShortFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + short newValue = mappingFunction.applyAsShort(key); insert(-index-1, key, newValue); return newValue; } - short newValue = mappingFunction.applyAsShort(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + short newValue = values[index]; return newValue; } finally { unlockWrite(stamp); } } - - protected short computeIfAbsent(int hash, float key, Float2ShortFunction mappingFunction) { + + protected short supplyIfAbsent(int hash, float key, ShortSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = valueProvider.getAsShort(); insert(-index-1, key, newValue); return newValue; } @@ -2115,23 +2109,14 @@ protected short computeIfAbsent(int hash, float key, Float2ShortFunction mapping unlockWrite(stamp); } } - - protected short computeIfAbsentNonDefault(int hash, float key, Float2ShortFunction mappingFunction) { + + protected short computeIfPresent(int hash, float key, FloatShortUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0) { - short newValue = mappingFunction.applyAsShort(key); - if(newValue == getDefaultReturnValue()) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - short newValue = values[index]; - if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsShort(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; - } + if(index < 0) return getDefaultReturnValue(); + short newValue = mappingFunction.applyAsShort(key, values[index]); + values[index] = newValue; return newValue; } finally { @@ -2139,16 +2124,22 @@ protected short computeIfAbsentNonDefault(int hash, float key, Float2ShortFuncti } } - protected short supplyIfAbsent(int hash, float key, ShortSupplier valueProvider) { + protected short computeNonDefault(int hash, float key, FloatShortUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - short newValue = valueProvider.getAsInt(); + short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - short newValue = values[index]; + short newValue = mappingFunction.applyAsShort(key, values[index]); + if(newValue == getDefaultReturnValue()) { + removeIndex(index); + return newValue; + } + values[index] = newValue; return newValue; } finally { @@ -2156,19 +2147,19 @@ protected short supplyIfAbsent(int hash, float key, ShortSupplier valueProvider) } } - protected short supplyIfAbsentNonDefault(int hash, float key, ShortSupplier valueProvider) { + protected short computeIfAbsentNonDefault(int hash, float key, Float2ShortFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - short newValue = valueProvider.getAsInt(); + short newValue = mappingFunction.applyAsShort(key); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } short newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = mappingFunction.applyAsShort(key); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } @@ -2179,13 +2170,22 @@ protected short supplyIfAbsentNonDefault(int hash, float key, ShortSupplier valu } } - protected short computeIfPresent(int hash, float key, FloatShortUnaryOperator mappingFunction) { + protected short supplyIfAbsentNonDefault(int hash, float key, ShortSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0) return getDefaultReturnValue(); - short newValue = mappingFunction.applyAsShort(key, values[index]); - values[index] = newValue; + if(index < 0) { + short newValue = valueProvider.getAsShort(); + if(newValue == getDefaultReturnValue()) return newValue; + insert(-index-1, key, newValue); + return newValue; + } + short newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = valueProvider.getAsShort(); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } finally { diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2BooleanOpenCustomHashMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2BooleanOpenCustomHashMap.java index 9d9e05d4..fcb2d016 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2BooleanOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2BooleanOpenCustomHashMap.java @@ -441,30 +441,24 @@ public boolean computeBoolean(float key, FloatBooleanUnaryOperator mappingFuncti } @Override - public boolean computeBooleanNonDefault(float key, FloatBooleanUnaryOperator mappingFunction) { + public boolean computeBooleanIfAbsent(float key, FloatPredicate mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + boolean newValue = mappingFunction.test(key); insert(-index-1, key, newValue); return newValue; } - boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + boolean newValue = values[index]; return newValue; } - + @Override - public boolean computeBooleanIfAbsent(float key, FloatPredicate mappingFunction) { - Objects.requireNonNull(mappingFunction); + public boolean supplyBooleanIfAbsent(float key, BooleanSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - boolean newValue = mappingFunction.test(key); + boolean newValue = valueProvider.getAsBoolean(); insert(-index-1, key, newValue); return newValue; } @@ -473,34 +467,50 @@ public boolean computeBooleanIfAbsent(float key, FloatPredicate mappingFunction) } @Override - public boolean computeBooleanIfAbsentNonDefault(float key, FloatPredicate mappingFunction) { + public boolean computeBooleanIfPresent(float key, FloatBooleanUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public boolean computeBooleanNonDefault(float key, FloatBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - boolean newValue = mappingFunction.test(key); + boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - boolean newValue = values[index]; + boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.test(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public boolean supplyBooleanIfAbsent(float key, BooleanSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public boolean computeBooleanIfAbsentNonDefault(float key, FloatPredicate mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - boolean newValue = valueProvider.getAsBoolean(); + boolean newValue = mappingFunction.test(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } boolean newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.test(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -523,16 +533,6 @@ public boolean supplyBooleanIfAbsentNonDefault(float key, BooleanSupplier valueP return newValue; } - @Override - public boolean computeBooleanIfPresent(float key, FloatBooleanUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public boolean computeBooleanIfPresentNonDefault(float key, FloatBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2ByteOpenCustomHashMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2ByteOpenCustomHashMap.java index c0a8e946..f0c1bdcc 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2ByteOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2ByteOpenCustomHashMap.java @@ -463,30 +463,24 @@ public byte computeByte(float key, FloatByteUnaryOperator mappingFunction) { } @Override - public byte computeByteNonDefault(float key, FloatByteUnaryOperator mappingFunction) { + public byte computeByteIfAbsent(float key, Float2ByteFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + byte newValue = mappingFunction.applyAsByte(key); insert(-index-1, key, newValue); return newValue; } - byte newValue = mappingFunction.applyAsByte(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + byte newValue = values[index]; return newValue; } - + @Override - public byte computeByteIfAbsent(float key, Float2ByteFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public byte supplyByteIfAbsent(float key, ByteSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = valueProvider.getAsByte(); insert(-index-1, key, newValue); return newValue; } @@ -495,34 +489,50 @@ public byte computeByteIfAbsent(float key, Float2ByteFunction mappingFunction) { } @Override - public byte computeByteIfAbsentNonDefault(float key, Float2ByteFunction mappingFunction) { + public byte computeByteIfPresent(float key, FloatByteUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + byte newValue = mappingFunction.applyAsByte(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public byte computeByteNonDefault(float key, FloatByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - byte newValue = values[index]; + byte newValue = mappingFunction.applyAsByte(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsByte(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public byte supplyByteIfAbsent(float key, ByteSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public byte computeByteIfAbsentNonDefault(float key, Float2ByteFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - byte newValue = valueProvider.getAsInt(); + byte newValue = mappingFunction.applyAsByte(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } byte newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsByte(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -531,30 +541,20 @@ public byte supplyByteIfAbsentNonDefault(float key, ByteSupplier valueProvider) Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - byte newValue = valueProvider.getAsInt(); + byte newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } byte newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public byte computeByteIfPresent(float key, FloatByteUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - byte newValue = mappingFunction.applyAsByte(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public byte computeByteIfPresentNonDefault(float key, FloatByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2CharOpenCustomHashMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2CharOpenCustomHashMap.java index 941ac633..a84890e0 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2CharOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2CharOpenCustomHashMap.java @@ -463,30 +463,24 @@ public char computeChar(float key, FloatCharUnaryOperator mappingFunction) { } @Override - public char computeCharNonDefault(float key, FloatCharUnaryOperator mappingFunction) { + public char computeCharIfAbsent(float key, Float2CharFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + char newValue = mappingFunction.applyAsChar(key); insert(-index-1, key, newValue); return newValue; } - char newValue = mappingFunction.applyAsChar(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + char newValue = values[index]; return newValue; } - + @Override - public char computeCharIfAbsent(float key, Float2CharFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public char supplyCharIfAbsent(float key, CharSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = valueProvider.getAsChar(); insert(-index-1, key, newValue); return newValue; } @@ -495,34 +489,50 @@ public char computeCharIfAbsent(float key, Float2CharFunction mappingFunction) { } @Override - public char computeCharIfAbsentNonDefault(float key, Float2CharFunction mappingFunction) { + public char computeCharIfPresent(float key, FloatCharUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + char newValue = mappingFunction.applyAsChar(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public char computeCharNonDefault(float key, FloatCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - char newValue = values[index]; + char newValue = mappingFunction.applyAsChar(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsChar(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public char supplyCharIfAbsent(float key, CharSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public char computeCharIfAbsentNonDefault(float key, Float2CharFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - char newValue = valueProvider.getAsInt(); + char newValue = mappingFunction.applyAsChar(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } char newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsChar(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -531,30 +541,20 @@ public char supplyCharIfAbsentNonDefault(float key, CharSupplier valueProvider) Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - char newValue = valueProvider.getAsInt(); + char newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } char newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public char computeCharIfPresent(float key, FloatCharUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - char newValue = mappingFunction.applyAsChar(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public char computeCharIfPresentNonDefault(float key, FloatCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2DoubleOpenCustomHashMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2DoubleOpenCustomHashMap.java index 5579e87f..8879ace5 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2DoubleOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2DoubleOpenCustomHashMap.java @@ -463,30 +463,24 @@ public double computeDouble(float key, FloatDoubleUnaryOperator mappingFunction) } @Override - public double computeDoubleNonDefault(float key, FloatDoubleUnaryOperator mappingFunction) { + public double computeDoubleIfAbsent(float key, Float2DoubleFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + double newValue = mappingFunction.applyAsDouble(key); insert(-index-1, key, newValue); return newValue; } - double newValue = mappingFunction.applyAsDouble(key, values[index]); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + double newValue = values[index]; return newValue; } - + @Override - public double computeDoubleIfAbsent(float key, Float2DoubleFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public double supplyDoubleIfAbsent(float key, DoubleSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = valueProvider.getAsDouble(); insert(-index-1, key, newValue); return newValue; } @@ -495,34 +489,50 @@ public double computeDoubleIfAbsent(float key, Float2DoubleFunction mappingFunct } @Override - public double computeDoubleIfAbsentNonDefault(float key, Float2DoubleFunction mappingFunction) { + public double computeDoubleIfPresent(float key, FloatDoubleUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + double newValue = mappingFunction.applyAsDouble(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public double computeDoubleNonDefault(float key, FloatDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } - double newValue = values[index]; + double newValue = mappingFunction.applyAsDouble(key, values[index]); if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - newValue = mappingFunction.applyAsDouble(key); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public double supplyDoubleIfAbsent(float key, DoubleSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public double computeDoubleIfAbsentNonDefault(float key, Float2DoubleFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - double newValue = valueProvider.getAsDouble(); + double newValue = mappingFunction.applyAsDouble(key); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } double newValue = values[index]; + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { + newValue = mappingFunction.applyAsDouble(key); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + values[index] = newValue; + } return newValue; } @@ -545,16 +555,6 @@ public double supplyDoubleIfAbsentNonDefault(float key, DoubleSupplier valueProv return newValue; } - @Override - public double computeDoubleIfPresent(float key, FloatDoubleUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - double newValue = mappingFunction.applyAsDouble(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public double computeDoubleIfPresentNonDefault(float key, FloatDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2FloatOpenCustomHashMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2FloatOpenCustomHashMap.java index f2d63e1c..36ab9ed5 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2FloatOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2FloatOpenCustomHashMap.java @@ -455,30 +455,24 @@ public float computeFloat(float key, FloatFloatUnaryOperator mappingFunction) { } @Override - public float computeFloatNonDefault(float key, FloatFloatUnaryOperator mappingFunction) { + public float computeFloatIfAbsent(float key, FloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + float newValue = mappingFunction.applyAsFloat(key); insert(-index-1, key, newValue); return newValue; } - float newValue = mappingFunction.applyAsFloat(key, values[index]); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + float newValue = values[index]; return newValue; } - + @Override - public float computeFloatIfAbsent(float key, FloatUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); + public float supplyFloatIfAbsent(float key, FloatSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = valueProvider.getAsFloat(); insert(-index-1, key, newValue); return newValue; } @@ -487,34 +481,50 @@ public float computeFloatIfAbsent(float key, FloatUnaryOperator mappingFunction) } @Override - public float computeFloatIfAbsentNonDefault(float key, FloatUnaryOperator mappingFunction) { + public float computeFloatIfPresent(float key, FloatFloatUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + float newValue = mappingFunction.applyAsFloat(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public float computeFloatNonDefault(float key, FloatFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } - float newValue = values[index]; + float newValue = mappingFunction.applyAsFloat(key, values[index]); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - newValue = mappingFunction.applyAsFloat(key); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public float supplyFloatIfAbsent(float key, FloatSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public float computeFloatIfAbsentNonDefault(float key, FloatUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - float newValue = valueProvider.getAsDouble(); + float newValue = mappingFunction.applyAsFloat(key); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } float newValue = values[index]; + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { + newValue = mappingFunction.applyAsFloat(key); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + values[index] = newValue; + } return newValue; } @@ -523,30 +533,20 @@ public float supplyFloatIfAbsentNonDefault(float key, FloatSupplier valueProvide Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - float newValue = valueProvider.getAsDouble(); + float newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } float newValue = values[index]; if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - newValue = valueProvider.getAsDouble(); + newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; values[index] = newValue; } return newValue; } - @Override - public float computeFloatIfPresent(float key, FloatFloatUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - float newValue = mappingFunction.applyAsFloat(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public float computeFloatIfPresentNonDefault(float key, FloatFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2IntOpenCustomHashMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2IntOpenCustomHashMap.java index e67196f5..e149b2e5 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2IntOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2IntOpenCustomHashMap.java @@ -463,30 +463,24 @@ public int computeInt(float key, FloatIntUnaryOperator mappingFunction) { } @Override - public int computeIntNonDefault(float key, FloatIntUnaryOperator mappingFunction) { + public int computeIntIfAbsent(float key, Float2IntFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + int newValue = mappingFunction.applyAsInt(key); insert(-index-1, key, newValue); return newValue; } - int newValue = mappingFunction.applyAsInt(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + int newValue = values[index]; return newValue; } - + @Override - public int computeIntIfAbsent(float key, Float2IntFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public int supplyIntIfAbsent(float key, IntSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = valueProvider.getAsInt(); insert(-index-1, key, newValue); return newValue; } @@ -495,34 +489,50 @@ public int computeIntIfAbsent(float key, Float2IntFunction mappingFunction) { } @Override - public int computeIntIfAbsentNonDefault(float key, Float2IntFunction mappingFunction) { + public int computeIntIfPresent(float key, FloatIntUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + int newValue = mappingFunction.applyAsInt(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public int computeIntNonDefault(float key, FloatIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - int newValue = values[index]; + int newValue = mappingFunction.applyAsInt(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsInt(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public int supplyIntIfAbsent(float key, IntSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public int computeIntIfAbsentNonDefault(float key, Float2IntFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - int newValue = valueProvider.getAsInt(); + int newValue = mappingFunction.applyAsInt(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } int newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsInt(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -545,16 +555,6 @@ public int supplyIntIfAbsentNonDefault(float key, IntSupplier valueProvider) { return newValue; } - @Override - public int computeIntIfPresent(float key, FloatIntUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - int newValue = mappingFunction.applyAsInt(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public int computeIntIfPresentNonDefault(float key, FloatIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2LongOpenCustomHashMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2LongOpenCustomHashMap.java index a3fd9fc7..1ade7fff 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2LongOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2LongOpenCustomHashMap.java @@ -463,30 +463,24 @@ public long computeLong(float key, FloatLongUnaryOperator mappingFunction) { } @Override - public long computeLongNonDefault(float key, FloatLongUnaryOperator mappingFunction) { + public long computeLongIfAbsent(float key, Float2LongFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + long newValue = mappingFunction.applyAsLong(key); insert(-index-1, key, newValue); return newValue; } - long newValue = mappingFunction.applyAsLong(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + long newValue = values[index]; return newValue; } - + @Override - public long computeLongIfAbsent(float key, Float2LongFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public long supplyLongIfAbsent(float key, LongSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = valueProvider.getAsLong(); insert(-index-1, key, newValue); return newValue; } @@ -495,34 +489,50 @@ public long computeLongIfAbsent(float key, Float2LongFunction mappingFunction) { } @Override - public long computeLongIfAbsentNonDefault(float key, Float2LongFunction mappingFunction) { + public long computeLongIfPresent(float key, FloatLongUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + long newValue = mappingFunction.applyAsLong(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public long computeLongNonDefault(float key, FloatLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - long newValue = values[index]; + long newValue = mappingFunction.applyAsLong(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsLong(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public long supplyLongIfAbsent(float key, LongSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public long computeLongIfAbsentNonDefault(float key, Float2LongFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - long newValue = valueProvider.getAsLong(); + long newValue = mappingFunction.applyAsLong(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } long newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsLong(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -545,16 +555,6 @@ public long supplyLongIfAbsentNonDefault(float key, LongSupplier valueProvider) return newValue; } - @Override - public long computeLongIfPresent(float key, FloatLongUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - long newValue = mappingFunction.applyAsLong(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public long computeLongIfPresentNonDefault(float key, FloatLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2ObjectOpenCustomHashMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2ObjectOpenCustomHashMap.java index 64aff4e4..3abe68e3 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2ObjectOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2ObjectOpenCustomHashMap.java @@ -432,25 +432,6 @@ public V compute(float key, FloatObjectUnaryOperator mappingFunction) { return newValue; } - @Override - public V computeNonDefault(float key, FloatObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) { - V newValue = mappingFunction.apply(key, getDefaultReturnValue()); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = mappingFunction.apply(key, values[index]); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; - return newValue; - } - @Override public V computeIfAbsent(float key, FloatFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -469,26 +450,7 @@ public V computeIfAbsent(float key, FloatFunction mappingFunction) { } return newValue; } - - @Override - public V computeIfAbsentNonDefault(float key, FloatFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) { - V newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = values[index]; - if(Objects.equals(newValue, getDefaultReturnValue())) { - newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - values[index] = newValue; - } - return newValue; - } - + @Override public V supplyIfAbsent(float key, ObjectSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -508,25 +470,6 @@ public V supplyIfAbsent(float key, ObjectSupplier valueProvider) { return newValue; } - @Override - public V supplyIfAbsentNonDefault(float key, ObjectSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - int index = findIndex(key); - if(index < 0) { - V newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = values[index]; - if(Objects.equals(newValue, getDefaultReturnValue())) { - newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - values[index] = newValue; - } - return newValue; - } - @Override public V computeIfPresent(float key, FloatObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -541,20 +484,6 @@ public V computeIfPresent(float key, FloatObjectUnaryOperator mappingFunction return newValue; } - @Override - public V computeIfPresentNonDefault(float key, FloatObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0 || Objects.equals(values[index], getDefaultReturnValue())) return getDefaultReturnValue(); - V newValue = mappingFunction.apply(key, values[index]); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; - return newValue; - } - @Override public V merge(float key, V value, ObjectObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2ShortOpenCustomHashMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2ShortOpenCustomHashMap.java index 15a1300e..5272af15 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2ShortOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/customHash/Float2ShortOpenCustomHashMap.java @@ -463,30 +463,24 @@ public short computeShort(float key, FloatShortUnaryOperator mappingFunction) { } @Override - public short computeShortNonDefault(float key, FloatShortUnaryOperator mappingFunction) { + public short computeShortIfAbsent(float key, Float2ShortFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + short newValue = mappingFunction.applyAsShort(key); insert(-index-1, key, newValue); return newValue; } - short newValue = mappingFunction.applyAsShort(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + short newValue = values[index]; return newValue; } - + @Override - public short computeShortIfAbsent(float key, Float2ShortFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public short supplyShortIfAbsent(float key, ShortSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = valueProvider.getAsShort(); insert(-index-1, key, newValue); return newValue; } @@ -495,34 +489,50 @@ public short computeShortIfAbsent(float key, Float2ShortFunction mappingFunction } @Override - public short computeShortIfAbsentNonDefault(float key, Float2ShortFunction mappingFunction) { + public short computeShortIfPresent(float key, FloatShortUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + short newValue = mappingFunction.applyAsShort(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public short computeShortNonDefault(float key, FloatShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - short newValue = values[index]; + short newValue = mappingFunction.applyAsShort(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsShort(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public short supplyShortIfAbsent(float key, ShortSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public short computeShortIfAbsentNonDefault(float key, Float2ShortFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - short newValue = valueProvider.getAsInt(); + short newValue = mappingFunction.applyAsShort(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } short newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsShort(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -531,30 +541,20 @@ public short supplyShortIfAbsentNonDefault(float key, ShortSupplier valueProvide Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - short newValue = valueProvider.getAsInt(); + short newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } short newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public short computeShortIfPresent(float key, FloatShortUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - short newValue = mappingFunction.applyAsShort(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public short computeShortIfPresentNonDefault(float key, FloatShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2BooleanOpenHashMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2BooleanOpenHashMap.java index 65e88160..44cc7127 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2BooleanOpenHashMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2BooleanOpenHashMap.java @@ -408,68 +408,78 @@ public boolean computeBoolean(float key, FloatBooleanUnaryOperator mappingFuncti values[index] = newValue; return newValue; } - + @Override - public boolean computeBooleanNonDefault(float key, FloatBooleanUnaryOperator mappingFunction) { + public boolean computeBooleanIfAbsent(float key, FloatPredicate mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + boolean newValue = mappingFunction.test(key); insert(-index-1, key, newValue); return newValue; } - boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + boolean newValue = values[index]; return newValue; } @Override - public boolean computeBooleanIfAbsent(float key, FloatPredicate mappingFunction) { - Objects.requireNonNull(mappingFunction); + public boolean supplyBooleanIfAbsent(float key, BooleanSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - boolean newValue = mappingFunction.test(key); + boolean newValue = valueProvider.getAsBoolean(); insert(-index-1, key, newValue); return newValue; } boolean newValue = values[index]; return newValue; } + + @Override + public boolean computeBooleanIfPresent(float key, FloatBooleanUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public boolean computeBooleanIfAbsentNonDefault(float key, FloatPredicate mappingFunction) { + public boolean computeBooleanNonDefault(float key, FloatBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - boolean newValue = mappingFunction.test(key); + boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - boolean newValue = values[index]; + boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.test(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public boolean supplyBooleanIfAbsent(float key, BooleanSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public boolean computeBooleanIfAbsentNonDefault(float key, FloatPredicate mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - boolean newValue = valueProvider.getAsBoolean(); + boolean newValue = mappingFunction.test(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } boolean newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.test(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -492,16 +502,6 @@ public boolean supplyBooleanIfAbsentNonDefault(float key, BooleanSupplier valueP return newValue; } - @Override - public boolean computeBooleanIfPresent(float key, FloatBooleanUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public boolean computeBooleanIfPresentNonDefault(float key, FloatBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2ByteOpenHashMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2ByteOpenHashMap.java index afabe212..136f26cc 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2ByteOpenHashMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2ByteOpenHashMap.java @@ -430,68 +430,78 @@ public byte computeByte(float key, FloatByteUnaryOperator mappingFunction) { values[index] = newValue; return newValue; } - + @Override - public byte computeByteNonDefault(float key, FloatByteUnaryOperator mappingFunction) { + public byte computeByteIfAbsent(float key, Float2ByteFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + byte newValue = mappingFunction.applyAsByte(key); insert(-index-1, key, newValue); return newValue; } - byte newValue = mappingFunction.applyAsByte(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + byte newValue = values[index]; return newValue; } @Override - public byte computeByteIfAbsent(float key, Float2ByteFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public byte supplyByteIfAbsent(float key, ByteSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = valueProvider.getAsByte(); insert(-index-1, key, newValue); return newValue; } byte newValue = values[index]; return newValue; } + + @Override + public byte computeByteIfPresent(float key, FloatByteUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + byte newValue = mappingFunction.applyAsByte(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public byte computeByteIfAbsentNonDefault(float key, Float2ByteFunction mappingFunction) { + public byte computeByteNonDefault(float key, FloatByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - byte newValue = values[index]; + byte newValue = mappingFunction.applyAsByte(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsByte(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public byte supplyByteIfAbsent(float key, ByteSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public byte computeByteIfAbsentNonDefault(float key, Float2ByteFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - byte newValue = valueProvider.getAsInt(); + byte newValue = mappingFunction.applyAsByte(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } byte newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsByte(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -500,30 +510,20 @@ public byte supplyByteIfAbsentNonDefault(float key, ByteSupplier valueProvider) Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - byte newValue = valueProvider.getAsInt(); + byte newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } byte newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public byte computeByteIfPresent(float key, FloatByteUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - byte newValue = mappingFunction.applyAsByte(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public byte computeByteIfPresentNonDefault(float key, FloatByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2CharOpenHashMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2CharOpenHashMap.java index 291c5364..998e9a4a 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2CharOpenHashMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2CharOpenHashMap.java @@ -430,68 +430,78 @@ public char computeChar(float key, FloatCharUnaryOperator mappingFunction) { values[index] = newValue; return newValue; } - + @Override - public char computeCharNonDefault(float key, FloatCharUnaryOperator mappingFunction) { + public char computeCharIfAbsent(float key, Float2CharFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + char newValue = mappingFunction.applyAsChar(key); insert(-index-1, key, newValue); return newValue; } - char newValue = mappingFunction.applyAsChar(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + char newValue = values[index]; return newValue; } @Override - public char computeCharIfAbsent(float key, Float2CharFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public char supplyCharIfAbsent(float key, CharSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = valueProvider.getAsChar(); insert(-index-1, key, newValue); return newValue; } char newValue = values[index]; return newValue; } + + @Override + public char computeCharIfPresent(float key, FloatCharUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + char newValue = mappingFunction.applyAsChar(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public char computeCharIfAbsentNonDefault(float key, Float2CharFunction mappingFunction) { + public char computeCharNonDefault(float key, FloatCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - char newValue = values[index]; + char newValue = mappingFunction.applyAsChar(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsChar(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public char supplyCharIfAbsent(float key, CharSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public char computeCharIfAbsentNonDefault(float key, Float2CharFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - char newValue = valueProvider.getAsInt(); + char newValue = mappingFunction.applyAsChar(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } char newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsChar(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -500,30 +510,20 @@ public char supplyCharIfAbsentNonDefault(float key, CharSupplier valueProvider) Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - char newValue = valueProvider.getAsInt(); + char newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } char newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public char computeCharIfPresent(float key, FloatCharUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - char newValue = mappingFunction.applyAsChar(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public char computeCharIfPresentNonDefault(float key, FloatCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2DoubleOpenHashMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2DoubleOpenHashMap.java index b8c95009..32f9ab29 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2DoubleOpenHashMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2DoubleOpenHashMap.java @@ -430,68 +430,78 @@ public double computeDouble(float key, FloatDoubleUnaryOperator mappingFunction) values[index] = newValue; return newValue; } - + @Override - public double computeDoubleNonDefault(float key, FloatDoubleUnaryOperator mappingFunction) { + public double computeDoubleIfAbsent(float key, Float2DoubleFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + double newValue = mappingFunction.applyAsDouble(key); insert(-index-1, key, newValue); return newValue; } - double newValue = mappingFunction.applyAsDouble(key, values[index]); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + double newValue = values[index]; return newValue; } @Override - public double computeDoubleIfAbsent(float key, Float2DoubleFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public double supplyDoubleIfAbsent(float key, DoubleSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = valueProvider.getAsDouble(); insert(-index-1, key, newValue); return newValue; } double newValue = values[index]; return newValue; } + + @Override + public double computeDoubleIfPresent(float key, FloatDoubleUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + double newValue = mappingFunction.applyAsDouble(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public double computeDoubleIfAbsentNonDefault(float key, Float2DoubleFunction mappingFunction) { + public double computeDoubleNonDefault(float key, FloatDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } - double newValue = values[index]; + double newValue = mappingFunction.applyAsDouble(key, values[index]); if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - newValue = mappingFunction.applyAsDouble(key); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public double supplyDoubleIfAbsent(float key, DoubleSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public double computeDoubleIfAbsentNonDefault(float key, Float2DoubleFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - double newValue = valueProvider.getAsDouble(); + double newValue = mappingFunction.applyAsDouble(key); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } double newValue = values[index]; + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { + newValue = mappingFunction.applyAsDouble(key); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + values[index] = newValue; + } return newValue; } @@ -514,16 +524,6 @@ public double supplyDoubleIfAbsentNonDefault(float key, DoubleSupplier valueProv return newValue; } - @Override - public double computeDoubleIfPresent(float key, FloatDoubleUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - double newValue = mappingFunction.applyAsDouble(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public double computeDoubleIfPresentNonDefault(float key, FloatDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2FloatOpenHashMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2FloatOpenHashMap.java index 484e47c1..5e271112 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2FloatOpenHashMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2FloatOpenHashMap.java @@ -424,68 +424,78 @@ public float computeFloat(float key, FloatFloatUnaryOperator mappingFunction) { values[index] = newValue; return newValue; } - + @Override - public float computeFloatNonDefault(float key, FloatFloatUnaryOperator mappingFunction) { + public float computeFloatIfAbsent(float key, FloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + float newValue = mappingFunction.applyAsFloat(key); insert(-index-1, key, newValue); return newValue; } - float newValue = mappingFunction.applyAsFloat(key, values[index]); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + float newValue = values[index]; return newValue; } @Override - public float computeFloatIfAbsent(float key, FloatUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); + public float supplyFloatIfAbsent(float key, FloatSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = valueProvider.getAsFloat(); insert(-index-1, key, newValue); return newValue; } float newValue = values[index]; return newValue; } + + @Override + public float computeFloatIfPresent(float key, FloatFloatUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + float newValue = mappingFunction.applyAsFloat(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public float computeFloatIfAbsentNonDefault(float key, FloatUnaryOperator mappingFunction) { + public float computeFloatNonDefault(float key, FloatFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } - float newValue = values[index]; + float newValue = mappingFunction.applyAsFloat(key, values[index]); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - newValue = mappingFunction.applyAsFloat(key); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public float supplyFloatIfAbsent(float key, FloatSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public float computeFloatIfAbsentNonDefault(float key, FloatUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - float newValue = valueProvider.getAsDouble(); + float newValue = mappingFunction.applyAsFloat(key); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } float newValue = values[index]; + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { + newValue = mappingFunction.applyAsFloat(key); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + values[index] = newValue; + } return newValue; } @@ -494,30 +504,20 @@ public float supplyFloatIfAbsentNonDefault(float key, FloatSupplier valueProvide Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - float newValue = valueProvider.getAsDouble(); + float newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } float newValue = values[index]; if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - newValue = valueProvider.getAsDouble(); + newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; values[index] = newValue; } return newValue; } - @Override - public float computeFloatIfPresent(float key, FloatFloatUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - float newValue = mappingFunction.applyAsFloat(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public float computeFloatIfPresentNonDefault(float key, FloatFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2IntOpenHashMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2IntOpenHashMap.java index 23278fa9..01919571 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2IntOpenHashMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2IntOpenHashMap.java @@ -430,68 +430,78 @@ public int computeInt(float key, FloatIntUnaryOperator mappingFunction) { values[index] = newValue; return newValue; } - + @Override - public int computeIntNonDefault(float key, FloatIntUnaryOperator mappingFunction) { + public int computeIntIfAbsent(float key, Float2IntFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + int newValue = mappingFunction.applyAsInt(key); insert(-index-1, key, newValue); return newValue; } - int newValue = mappingFunction.applyAsInt(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + int newValue = values[index]; return newValue; } @Override - public int computeIntIfAbsent(float key, Float2IntFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public int supplyIntIfAbsent(float key, IntSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = valueProvider.getAsInt(); insert(-index-1, key, newValue); return newValue; } int newValue = values[index]; return newValue; } + + @Override + public int computeIntIfPresent(float key, FloatIntUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + int newValue = mappingFunction.applyAsInt(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public int computeIntIfAbsentNonDefault(float key, Float2IntFunction mappingFunction) { + public int computeIntNonDefault(float key, FloatIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - int newValue = values[index]; + int newValue = mappingFunction.applyAsInt(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsInt(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public int supplyIntIfAbsent(float key, IntSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public int computeIntIfAbsentNonDefault(float key, Float2IntFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - int newValue = valueProvider.getAsInt(); + int newValue = mappingFunction.applyAsInt(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } int newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsInt(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -514,16 +524,6 @@ public int supplyIntIfAbsentNonDefault(float key, IntSupplier valueProvider) { return newValue; } - @Override - public int computeIntIfPresent(float key, FloatIntUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - int newValue = mappingFunction.applyAsInt(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public int computeIntIfPresentNonDefault(float key, FloatIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2LongOpenHashMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2LongOpenHashMap.java index 4144e286..a55f915f 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2LongOpenHashMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2LongOpenHashMap.java @@ -430,68 +430,78 @@ public long computeLong(float key, FloatLongUnaryOperator mappingFunction) { values[index] = newValue; return newValue; } - + @Override - public long computeLongNonDefault(float key, FloatLongUnaryOperator mappingFunction) { + public long computeLongIfAbsent(float key, Float2LongFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + long newValue = mappingFunction.applyAsLong(key); insert(-index-1, key, newValue); return newValue; } - long newValue = mappingFunction.applyAsLong(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + long newValue = values[index]; return newValue; } @Override - public long computeLongIfAbsent(float key, Float2LongFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public long supplyLongIfAbsent(float key, LongSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = valueProvider.getAsLong(); insert(-index-1, key, newValue); return newValue; } long newValue = values[index]; return newValue; } + + @Override + public long computeLongIfPresent(float key, FloatLongUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + long newValue = mappingFunction.applyAsLong(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public long computeLongIfAbsentNonDefault(float key, Float2LongFunction mappingFunction) { + public long computeLongNonDefault(float key, FloatLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - long newValue = values[index]; + long newValue = mappingFunction.applyAsLong(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsLong(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public long supplyLongIfAbsent(float key, LongSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public long computeLongIfAbsentNonDefault(float key, Float2LongFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - long newValue = valueProvider.getAsLong(); + long newValue = mappingFunction.applyAsLong(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } long newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsLong(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -514,16 +524,6 @@ public long supplyLongIfAbsentNonDefault(float key, LongSupplier valueProvider) return newValue; } - @Override - public long computeLongIfPresent(float key, FloatLongUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - long newValue = mappingFunction.applyAsLong(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public long computeLongIfPresentNonDefault(float key, FloatLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2ObjectOpenHashMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2ObjectOpenHashMap.java index 97d2331f..06b429ad 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2ObjectOpenHashMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2ObjectOpenHashMap.java @@ -401,26 +401,7 @@ public V compute(float key, FloatObjectUnaryOperator mappingFunction) { values[index] = newValue; return newValue; } - - @Override - public V computeNonDefault(float key, FloatObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) { - V newValue = mappingFunction.apply(key, getDefaultReturnValue()); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = mappingFunction.apply(key, values[index]); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; - return newValue; - } - + @Override public V computeIfAbsent(float key, FloatFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -440,25 +421,6 @@ public V computeIfAbsent(float key, FloatFunction mappingFunction) { return newValue; } - @Override - public V computeIfAbsentNonDefault(float key, FloatFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) { - V newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = values[index]; - if(Objects.equals(newValue, getDefaultReturnValue())) { - newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - values[index] = newValue; - } - return newValue; - } - @Override public V supplyIfAbsent(float key, ObjectSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -477,26 +439,7 @@ public V supplyIfAbsent(float key, ObjectSupplier valueProvider) { } return newValue; } - - @Override - public V supplyIfAbsentNonDefault(float key, ObjectSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - int index = findIndex(key); - if(index < 0) { - V newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = values[index]; - if(Objects.equals(newValue, getDefaultReturnValue())) { - newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - values[index] = newValue; - } - return newValue; - } - + @Override public V computeIfPresent(float key, FloatObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -511,20 +454,6 @@ public V computeIfPresent(float key, FloatObjectUnaryOperator mappingFunction return newValue; } - @Override - public V computeIfPresentNonDefault(float key, FloatObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0 || Objects.equals(values[index], getDefaultReturnValue())) return getDefaultReturnValue(); - V newValue = mappingFunction.apply(key, values[index]); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; - return newValue; - } - @Override public V merge(float key, V value, ObjectObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2ShortOpenHashMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2ShortOpenHashMap.java index 4f508e16..6a9b71d1 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2ShortOpenHashMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/hash/Float2ShortOpenHashMap.java @@ -430,68 +430,78 @@ public short computeShort(float key, FloatShortUnaryOperator mappingFunction) { values[index] = newValue; return newValue; } - + @Override - public short computeShortNonDefault(float key, FloatShortUnaryOperator mappingFunction) { + public short computeShortIfAbsent(float key, Float2ShortFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + short newValue = mappingFunction.applyAsShort(key); insert(-index-1, key, newValue); return newValue; } - short newValue = mappingFunction.applyAsShort(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + short newValue = values[index]; return newValue; } @Override - public short computeShortIfAbsent(float key, Float2ShortFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public short supplyShortIfAbsent(float key, ShortSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = valueProvider.getAsShort(); insert(-index-1, key, newValue); return newValue; } short newValue = values[index]; return newValue; } + + @Override + public short computeShortIfPresent(float key, FloatShortUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + short newValue = mappingFunction.applyAsShort(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public short computeShortIfAbsentNonDefault(float key, Float2ShortFunction mappingFunction) { + public short computeShortNonDefault(float key, FloatShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - short newValue = values[index]; + short newValue = mappingFunction.applyAsShort(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsShort(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public short supplyShortIfAbsent(float key, ShortSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public short computeShortIfAbsentNonDefault(float key, Float2ShortFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - short newValue = valueProvider.getAsInt(); + short newValue = mappingFunction.applyAsShort(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } short newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsShort(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -500,30 +510,20 @@ public short supplyShortIfAbsentNonDefault(float key, ShortSupplier valueProvide Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - short newValue = valueProvider.getAsInt(); + short newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } short newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public short computeShortIfPresent(float key, FloatShortUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - short newValue = mappingFunction.applyAsShort(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public short computeShortIfPresentNonDefault(float key, FloatShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/immutable/ImmutableFloat2BooleanOpenHashMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/immutable/ImmutableFloat2BooleanOpenHashMap.java index a6177b49..2c228695 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/immutable/ImmutableFloat2BooleanOpenHashMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/immutable/ImmutableFloat2BooleanOpenHashMap.java @@ -413,20 +413,19 @@ public void forEach(FloatBooleanConsumer action) { @Override public boolean computeBoolean(float key, FloatBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanNonDefault(float key, FloatBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean computeBooleanIfAbsent(float key, FloatPredicate mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanIfAbsentNonDefault(float key, FloatPredicate mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean supplyBooleanIfAbsent(float key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public boolean supplyBooleanIfAbsentNonDefault(float key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public boolean computeBooleanIfPresent(float key, FloatBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override + public boolean computeBooleanNonDefault(float key, FloatBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public boolean computeBooleanIfAbsentNonDefault(float key, FloatPredicate mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public boolean supplyBooleanIfAbsentNonDefault(float key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } + @Override public boolean computeBooleanIfPresentNonDefault(float key, FloatBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean mergeBoolean(float key, boolean value, BooleanBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/immutable/ImmutableFloat2ByteOpenHashMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/immutable/ImmutableFloat2ByteOpenHashMap.java index 982ec0ed..36679920 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/immutable/ImmutableFloat2ByteOpenHashMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/immutable/ImmutableFloat2ByteOpenHashMap.java @@ -418,20 +418,19 @@ public void forEach(FloatByteConsumer action) { @Override public byte computeByte(float key, FloatByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteNonDefault(float key, FloatByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte computeByteIfAbsent(float key, Float2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteIfAbsentNonDefault(float key, Float2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte supplyByteIfAbsent(float key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public byte supplyByteIfAbsentNonDefault(float key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public byte computeByteIfPresent(float key, FloatByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override + public byte computeByteNonDefault(float key, FloatByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public byte computeByteIfAbsentNonDefault(float key, Float2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public byte supplyByteIfAbsentNonDefault(float key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } + @Override public byte computeByteIfPresentNonDefault(float key, FloatByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte mergeByte(float key, byte value, ByteByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/immutable/ImmutableFloat2CharOpenHashMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/immutable/ImmutableFloat2CharOpenHashMap.java index b9667ed2..b9795751 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/immutable/ImmutableFloat2CharOpenHashMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/immutable/ImmutableFloat2CharOpenHashMap.java @@ -418,20 +418,19 @@ public void forEach(FloatCharConsumer action) { @Override public char computeChar(float key, FloatCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharNonDefault(float key, FloatCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char computeCharIfAbsent(float key, Float2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharIfAbsentNonDefault(float key, Float2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char supplyCharIfAbsent(float key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public char supplyCharIfAbsentNonDefault(float key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public char computeCharIfPresent(float key, FloatCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override + public char computeCharNonDefault(float key, FloatCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public char computeCharIfAbsentNonDefault(float key, Float2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public char supplyCharIfAbsentNonDefault(float key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } + @Override public char computeCharIfPresentNonDefault(float key, FloatCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char mergeChar(float key, char value, CharCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/immutable/ImmutableFloat2DoubleOpenHashMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/immutable/ImmutableFloat2DoubleOpenHashMap.java index 1057e40f..0da6c777 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/immutable/ImmutableFloat2DoubleOpenHashMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/immutable/ImmutableFloat2DoubleOpenHashMap.java @@ -418,20 +418,19 @@ public void forEach(FloatDoubleConsumer action) { @Override public double computeDouble(float key, FloatDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleNonDefault(float key, FloatDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double computeDoubleIfAbsent(float key, Float2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleIfAbsentNonDefault(float key, Float2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double supplyDoubleIfAbsent(float key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public double supplyDoubleIfAbsentNonDefault(float key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public double computeDoubleIfPresent(float key, FloatDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override + public double computeDoubleNonDefault(float key, FloatDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public double computeDoubleIfAbsentNonDefault(float key, Float2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public double supplyDoubleIfAbsentNonDefault(float key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } + @Override public double computeDoubleIfPresentNonDefault(float key, FloatDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double mergeDouble(float key, double value, DoubleDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/immutable/ImmutableFloat2FloatOpenHashMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/immutable/ImmutableFloat2FloatOpenHashMap.java index ce6209ba..c6d3e747 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/immutable/ImmutableFloat2FloatOpenHashMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/immutable/ImmutableFloat2FloatOpenHashMap.java @@ -409,20 +409,19 @@ public void forEach(FloatFloatConsumer action) { @Override public float computeFloat(float key, FloatFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatNonDefault(float key, FloatFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float computeFloatIfAbsent(float key, FloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatIfAbsentNonDefault(float key, FloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float supplyFloatIfAbsent(float key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public float supplyFloatIfAbsentNonDefault(float key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public float computeFloatIfPresent(float key, FloatFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override + public float computeFloatNonDefault(float key, FloatFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public float computeFloatIfAbsentNonDefault(float key, FloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public float supplyFloatIfAbsentNonDefault(float key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } + @Override public float computeFloatIfPresentNonDefault(float key, FloatFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float mergeFloat(float key, float value, FloatFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/immutable/ImmutableFloat2IntOpenHashMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/immutable/ImmutableFloat2IntOpenHashMap.java index 8d6eb857..6e65c500 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/immutable/ImmutableFloat2IntOpenHashMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/immutable/ImmutableFloat2IntOpenHashMap.java @@ -418,20 +418,19 @@ public void forEach(FloatIntConsumer action) { @Override public int computeInt(float key, FloatIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntNonDefault(float key, FloatIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int computeIntIfAbsent(float key, Float2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntIfAbsentNonDefault(float key, Float2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int supplyIntIfAbsent(float key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public int supplyIntIfAbsentNonDefault(float key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public int computeIntIfPresent(float key, FloatIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override + public int computeIntNonDefault(float key, FloatIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public int computeIntIfAbsentNonDefault(float key, Float2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public int supplyIntIfAbsentNonDefault(float key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } + @Override public int computeIntIfPresentNonDefault(float key, FloatIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int mergeInt(float key, int value, IntIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/immutable/ImmutableFloat2LongOpenHashMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/immutable/ImmutableFloat2LongOpenHashMap.java index 73f175c4..38713bc7 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/immutable/ImmutableFloat2LongOpenHashMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/immutable/ImmutableFloat2LongOpenHashMap.java @@ -418,20 +418,19 @@ public void forEach(FloatLongConsumer action) { @Override public long computeLong(float key, FloatLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongNonDefault(float key, FloatLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long computeLongIfAbsent(float key, Float2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongIfAbsentNonDefault(float key, Float2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long supplyLongIfAbsent(float key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public long supplyLongIfAbsentNonDefault(float key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public long computeLongIfPresent(float key, FloatLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override + public long computeLongNonDefault(float key, FloatLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public long computeLongIfAbsentNonDefault(float key, Float2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public long supplyLongIfAbsentNonDefault(float key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } + @Override public long computeLongIfPresentNonDefault(float key, FloatLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long mergeLong(float key, long value, LongLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/immutable/ImmutableFloat2ObjectOpenHashMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/immutable/ImmutableFloat2ObjectOpenHashMap.java index 7f9844f1..33524a99 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/immutable/ImmutableFloat2ObjectOpenHashMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/immutable/ImmutableFloat2ObjectOpenHashMap.java @@ -397,20 +397,11 @@ public void forEach(FloatObjectConsumer action) { @Override public V compute(float key, FloatObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeNonDefault(float key, FloatObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V computeIfAbsent(float key, FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeIfAbsentNonDefault(float key, FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V supplyIfAbsent(float key, ObjectSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public V supplyIfAbsentNonDefault(float key, ObjectSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public V computeIfPresent(float key, FloatObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override - public V computeIfPresentNonDefault(float key, FloatObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V merge(float key, V value, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/immutable/ImmutableFloat2ShortOpenHashMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/immutable/ImmutableFloat2ShortOpenHashMap.java index 4dc39120..e7bc266c 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/immutable/ImmutableFloat2ShortOpenHashMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/immutable/ImmutableFloat2ShortOpenHashMap.java @@ -418,20 +418,19 @@ public void forEach(FloatShortConsumer action) { @Override public short computeShort(float key, FloatShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortNonDefault(float key, FloatShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short computeShortIfAbsent(float key, Float2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortIfAbsentNonDefault(float key, Float2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short supplyShortIfAbsent(float key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public short supplyShortIfAbsentNonDefault(float key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public short computeShortIfPresent(float key, FloatShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override + public short computeShortNonDefault(float key, FloatShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public short computeShortIfAbsentNonDefault(float key, Float2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public short supplyShortIfAbsentNonDefault(float key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } + @Override public short computeShortIfPresentNonDefault(float key, FloatShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short mergeShort(float key, short value, ShortShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/misc/Float2BooleanArrayMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/misc/Float2BooleanArrayMap.java index 54039303..f5c1ef52 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/misc/Float2BooleanArrayMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/misc/Float2BooleanArrayMap.java @@ -420,66 +420,76 @@ public boolean computeBoolean(float key, FloatBooleanUnaryOperator mappingFuncti } @Override - public boolean computeBooleanNonDefault(float key, FloatBooleanUnaryOperator mappingFunction) { + public boolean computeBooleanIfAbsent(float key, FloatPredicate mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + boolean newValue = mappingFunction.test(key); insertIndex(size++, key, newValue); return newValue; } - boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + boolean newValue = values[index]; return newValue; } - + @Override - public boolean computeBooleanIfAbsent(float key, FloatPredicate mappingFunction) { - Objects.requireNonNull(mappingFunction); + public boolean supplyBooleanIfAbsent(float key, BooleanSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - boolean newValue = mappingFunction.test(key); + boolean newValue = valueProvider.getAsBoolean(); insertIndex(size++, key, newValue); return newValue; } boolean newValue = values[index]; return newValue; } + + @Override + public boolean computeBooleanIfPresent(float key, FloatBooleanUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index == -1) return getDefaultReturnValue(); + boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public boolean computeBooleanIfAbsentNonDefault(float key, FloatPredicate mappingFunction) { + public boolean computeBooleanNonDefault(float key, FloatBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - boolean newValue = mappingFunction.test(key); + boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } - boolean newValue = values[index]; + boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.test(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public boolean supplyBooleanIfAbsent(float key, BooleanSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public boolean computeBooleanIfAbsentNonDefault(float key, FloatPredicate mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - boolean newValue = valueProvider.getAsBoolean(); + boolean newValue = mappingFunction.test(key); + if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } boolean newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.test(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -502,16 +512,6 @@ public boolean supplyBooleanIfAbsentNonDefault(float key, BooleanSupplier valueP return newValue; } - @Override - public boolean computeBooleanIfPresent(float key, FloatBooleanUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) return getDefaultReturnValue(); - boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public boolean computeBooleanIfPresentNonDefault(float key, FloatBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/misc/Float2ByteArrayMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/misc/Float2ByteArrayMap.java index 4fb62910..8071e264 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/misc/Float2ByteArrayMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/misc/Float2ByteArrayMap.java @@ -443,66 +443,76 @@ public byte computeByte(float key, FloatByteUnaryOperator mappingFunction) { } @Override - public byte computeByteNonDefault(float key, FloatByteUnaryOperator mappingFunction) { + public byte computeByteIfAbsent(float key, Float2ByteFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + byte newValue = mappingFunction.applyAsByte(key); insertIndex(size++, key, newValue); return newValue; } - byte newValue = mappingFunction.applyAsByte(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + byte newValue = values[index]; return newValue; } - + @Override - public byte computeByteIfAbsent(float key, Float2ByteFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public byte supplyByteIfAbsent(float key, ByteSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = valueProvider.getAsByte(); insertIndex(size++, key, newValue); return newValue; } byte newValue = values[index]; return newValue; } + + @Override + public byte computeByteIfPresent(float key, FloatByteUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index == -1) return getDefaultReturnValue(); + byte newValue = mappingFunction.applyAsByte(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public byte computeByteIfAbsentNonDefault(float key, Float2ByteFunction mappingFunction) { + public byte computeByteNonDefault(float key, FloatByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } - byte newValue = values[index]; + byte newValue = mappingFunction.applyAsByte(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsByte(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public byte supplyByteIfAbsent(float key, ByteSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public byte computeByteIfAbsentNonDefault(float key, Float2ByteFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - byte newValue = valueProvider.getAsInt(); + byte newValue = mappingFunction.applyAsByte(key); + if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } byte newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsByte(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -511,30 +521,20 @@ public byte supplyByteIfAbsentNonDefault(float key, ByteSupplier valueProvider) Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - byte newValue = valueProvider.getAsInt(); + byte newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } byte newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public byte computeByteIfPresent(float key, FloatByteUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) return getDefaultReturnValue(); - byte newValue = mappingFunction.applyAsByte(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public byte computeByteIfPresentNonDefault(float key, FloatByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/misc/Float2CharArrayMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/misc/Float2CharArrayMap.java index 986ae057..6beed7b3 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/misc/Float2CharArrayMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/misc/Float2CharArrayMap.java @@ -443,66 +443,76 @@ public char computeChar(float key, FloatCharUnaryOperator mappingFunction) { } @Override - public char computeCharNonDefault(float key, FloatCharUnaryOperator mappingFunction) { + public char computeCharIfAbsent(float key, Float2CharFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + char newValue = mappingFunction.applyAsChar(key); insertIndex(size++, key, newValue); return newValue; } - char newValue = mappingFunction.applyAsChar(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + char newValue = values[index]; return newValue; } - + @Override - public char computeCharIfAbsent(float key, Float2CharFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public char supplyCharIfAbsent(float key, CharSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = valueProvider.getAsChar(); insertIndex(size++, key, newValue); return newValue; } char newValue = values[index]; return newValue; } + + @Override + public char computeCharIfPresent(float key, FloatCharUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index == -1) return getDefaultReturnValue(); + char newValue = mappingFunction.applyAsChar(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public char computeCharIfAbsentNonDefault(float key, Float2CharFunction mappingFunction) { + public char computeCharNonDefault(float key, FloatCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } - char newValue = values[index]; + char newValue = mappingFunction.applyAsChar(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsChar(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public char supplyCharIfAbsent(float key, CharSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public char computeCharIfAbsentNonDefault(float key, Float2CharFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - char newValue = valueProvider.getAsInt(); + char newValue = mappingFunction.applyAsChar(key); + if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } char newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsChar(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -511,30 +521,20 @@ public char supplyCharIfAbsentNonDefault(float key, CharSupplier valueProvider) Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - char newValue = valueProvider.getAsInt(); + char newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } char newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public char computeCharIfPresent(float key, FloatCharUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) return getDefaultReturnValue(); - char newValue = mappingFunction.applyAsChar(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public char computeCharIfPresentNonDefault(float key, FloatCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/misc/Float2DoubleArrayMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/misc/Float2DoubleArrayMap.java index 1aa408be..b0203052 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/misc/Float2DoubleArrayMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/misc/Float2DoubleArrayMap.java @@ -443,66 +443,76 @@ public double computeDouble(float key, FloatDoubleUnaryOperator mappingFunction) } @Override - public double computeDoubleNonDefault(float key, FloatDoubleUnaryOperator mappingFunction) { + public double computeDoubleIfAbsent(float key, Float2DoubleFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + double newValue = mappingFunction.applyAsDouble(key); insertIndex(size++, key, newValue); return newValue; } - double newValue = mappingFunction.applyAsDouble(key, values[index]); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + double newValue = values[index]; return newValue; } - + @Override - public double computeDoubleIfAbsent(float key, Float2DoubleFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public double supplyDoubleIfAbsent(float key, DoubleSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = valueProvider.getAsDouble(); insertIndex(size++, key, newValue); return newValue; } double newValue = values[index]; return newValue; } + + @Override + public double computeDoubleIfPresent(float key, FloatDoubleUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index == -1) return getDefaultReturnValue(); + double newValue = mappingFunction.applyAsDouble(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public double computeDoubleIfAbsentNonDefault(float key, Float2DoubleFunction mappingFunction) { + public double computeDoubleNonDefault(float key, FloatDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; insertIndex(size++, key, newValue); return newValue; } - double newValue = values[index]; + double newValue = mappingFunction.applyAsDouble(key, values[index]); if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - newValue = mappingFunction.applyAsDouble(key); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public double supplyDoubleIfAbsent(float key, DoubleSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public double computeDoubleIfAbsentNonDefault(float key, Float2DoubleFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - double newValue = valueProvider.getAsDouble(); + double newValue = mappingFunction.applyAsDouble(key); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; insertIndex(size++, key, newValue); return newValue; } double newValue = values[index]; + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { + newValue = mappingFunction.applyAsDouble(key); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + values[index] = newValue; + } return newValue; } @@ -525,16 +535,6 @@ public double supplyDoubleIfAbsentNonDefault(float key, DoubleSupplier valueProv return newValue; } - @Override - public double computeDoubleIfPresent(float key, FloatDoubleUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) return getDefaultReturnValue(); - double newValue = mappingFunction.applyAsDouble(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public double computeDoubleIfPresentNonDefault(float key, FloatDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/misc/Float2FloatArrayMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/misc/Float2FloatArrayMap.java index ca90a137..65aef8c9 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/misc/Float2FloatArrayMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/misc/Float2FloatArrayMap.java @@ -436,66 +436,76 @@ public float computeFloat(float key, FloatFloatUnaryOperator mappingFunction) { } @Override - public float computeFloatNonDefault(float key, FloatFloatUnaryOperator mappingFunction) { + public float computeFloatIfAbsent(float key, FloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + float newValue = mappingFunction.applyAsFloat(key); insertIndex(size++, key, newValue); return newValue; } - float newValue = mappingFunction.applyAsFloat(key, values[index]); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + float newValue = values[index]; return newValue; } - + @Override - public float computeFloatIfAbsent(float key, FloatUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); + public float supplyFloatIfAbsent(float key, FloatSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = valueProvider.getAsFloat(); insertIndex(size++, key, newValue); return newValue; } float newValue = values[index]; return newValue; } + + @Override + public float computeFloatIfPresent(float key, FloatFloatUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index == -1) return getDefaultReturnValue(); + float newValue = mappingFunction.applyAsFloat(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public float computeFloatIfAbsentNonDefault(float key, FloatUnaryOperator mappingFunction) { + public float computeFloatNonDefault(float key, FloatFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insertIndex(size++, key, newValue); return newValue; } - float newValue = values[index]; + float newValue = mappingFunction.applyAsFloat(key, values[index]); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - newValue = mappingFunction.applyAsFloat(key); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public float supplyFloatIfAbsent(float key, FloatSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public float computeFloatIfAbsentNonDefault(float key, FloatUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - float newValue = valueProvider.getAsDouble(); + float newValue = mappingFunction.applyAsFloat(key); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insertIndex(size++, key, newValue); return newValue; } float newValue = values[index]; + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { + newValue = mappingFunction.applyAsFloat(key); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + values[index] = newValue; + } return newValue; } @@ -504,30 +514,20 @@ public float supplyFloatIfAbsentNonDefault(float key, FloatSupplier valueProvide Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - float newValue = valueProvider.getAsDouble(); + float newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insertIndex(size++, key, newValue); return newValue; } float newValue = values[index]; if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - newValue = valueProvider.getAsDouble(); + newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; values[index] = newValue; } return newValue; } - @Override - public float computeFloatIfPresent(float key, FloatFloatUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) return getDefaultReturnValue(); - float newValue = mappingFunction.applyAsFloat(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public float computeFloatIfPresentNonDefault(float key, FloatFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/misc/Float2IntArrayMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/misc/Float2IntArrayMap.java index 81a54b4d..c3761963 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/misc/Float2IntArrayMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/misc/Float2IntArrayMap.java @@ -443,66 +443,76 @@ public int computeInt(float key, FloatIntUnaryOperator mappingFunction) { } @Override - public int computeIntNonDefault(float key, FloatIntUnaryOperator mappingFunction) { + public int computeIntIfAbsent(float key, Float2IntFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + int newValue = mappingFunction.applyAsInt(key); insertIndex(size++, key, newValue); return newValue; } - int newValue = mappingFunction.applyAsInt(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + int newValue = values[index]; return newValue; } - + @Override - public int computeIntIfAbsent(float key, Float2IntFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public int supplyIntIfAbsent(float key, IntSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = valueProvider.getAsInt(); insertIndex(size++, key, newValue); return newValue; } int newValue = values[index]; return newValue; } + + @Override + public int computeIntIfPresent(float key, FloatIntUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index == -1) return getDefaultReturnValue(); + int newValue = mappingFunction.applyAsInt(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public int computeIntIfAbsentNonDefault(float key, Float2IntFunction mappingFunction) { + public int computeIntNonDefault(float key, FloatIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } - int newValue = values[index]; + int newValue = mappingFunction.applyAsInt(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsInt(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public int supplyIntIfAbsent(float key, IntSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public int computeIntIfAbsentNonDefault(float key, Float2IntFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - int newValue = valueProvider.getAsInt(); + int newValue = mappingFunction.applyAsInt(key); + if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } int newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsInt(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -525,16 +535,6 @@ public int supplyIntIfAbsentNonDefault(float key, IntSupplier valueProvider) { return newValue; } - @Override - public int computeIntIfPresent(float key, FloatIntUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) return getDefaultReturnValue(); - int newValue = mappingFunction.applyAsInt(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public int computeIntIfPresentNonDefault(float key, FloatIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/misc/Float2LongArrayMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/misc/Float2LongArrayMap.java index c78e2440..ecdcaa28 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/misc/Float2LongArrayMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/misc/Float2LongArrayMap.java @@ -443,66 +443,76 @@ public long computeLong(float key, FloatLongUnaryOperator mappingFunction) { } @Override - public long computeLongNonDefault(float key, FloatLongUnaryOperator mappingFunction) { + public long computeLongIfAbsent(float key, Float2LongFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + long newValue = mappingFunction.applyAsLong(key); insertIndex(size++, key, newValue); return newValue; } - long newValue = mappingFunction.applyAsLong(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + long newValue = values[index]; return newValue; } - + @Override - public long computeLongIfAbsent(float key, Float2LongFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public long supplyLongIfAbsent(float key, LongSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = valueProvider.getAsLong(); insertIndex(size++, key, newValue); return newValue; } long newValue = values[index]; return newValue; } + + @Override + public long computeLongIfPresent(float key, FloatLongUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index == -1) return getDefaultReturnValue(); + long newValue = mappingFunction.applyAsLong(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public long computeLongIfAbsentNonDefault(float key, Float2LongFunction mappingFunction) { + public long computeLongNonDefault(float key, FloatLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } - long newValue = values[index]; + long newValue = mappingFunction.applyAsLong(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsLong(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public long supplyLongIfAbsent(float key, LongSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public long computeLongIfAbsentNonDefault(float key, Float2LongFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - long newValue = valueProvider.getAsLong(); + long newValue = mappingFunction.applyAsLong(key); + if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } long newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsLong(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -525,16 +535,6 @@ public long supplyLongIfAbsentNonDefault(float key, LongSupplier valueProvider) return newValue; } - @Override - public long computeLongIfPresent(float key, FloatLongUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) return getDefaultReturnValue(); - long newValue = mappingFunction.applyAsLong(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public long computeLongIfPresentNonDefault(float key, FloatLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/misc/Float2ObjectArrayMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/misc/Float2ObjectArrayMap.java index f41fcdd5..1026f628 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/misc/Float2ObjectArrayMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/misc/Float2ObjectArrayMap.java @@ -415,25 +415,6 @@ public V compute(float key, FloatObjectUnaryOperator mappingFunction) { return newValue; } - @Override - public V computeNonDefault(float key, FloatObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) { - V newValue = mappingFunction.apply(key, getDefaultReturnValue()); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insertIndex(size++, key, newValue); - return newValue; - } - V newValue = mappingFunction.apply(key, values[index]); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; - return newValue; - } - @Override public V computeIfAbsent(float key, FloatFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -452,26 +433,7 @@ public V computeIfAbsent(float key, FloatFunction mappingFunction) { } return newValue; } - - @Override - public V computeIfAbsentNonDefault(float key, FloatFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) { - V newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insertIndex(size++, key, newValue); - return newValue; - } - V newValue = values[index]; - if(Objects.equals(newValue, getDefaultReturnValue())) { - newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - values[index] = newValue; - } - return newValue; - } - + @Override public V supplyIfAbsent(float key, ObjectSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -490,26 +452,7 @@ public V supplyIfAbsent(float key, ObjectSupplier valueProvider) { } return newValue; } - - @Override - public V supplyIfAbsentNonDefault(float key, ObjectSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - int index = findIndex(key); - if(index == -1) { - V newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insertIndex(size++, key, newValue); - return newValue; - } - V newValue = values[index]; - if(Objects.equals(newValue, getDefaultReturnValue())) { - newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - values[index] = newValue; - } - return newValue; - } - + @Override public V computeIfPresent(float key, FloatObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -524,20 +467,6 @@ public V computeIfPresent(float key, FloatObjectUnaryOperator mappingFunction return newValue; } - @Override - public V computeIfPresentNonDefault(float key, FloatObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1 || Objects.equals(values[index], getDefaultReturnValue())) return getDefaultReturnValue(); - V newValue = mappingFunction.apply(key, values[index]); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; - return newValue; - } - @Override public V merge(float key, V value, ObjectObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/misc/Float2ShortArrayMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/misc/Float2ShortArrayMap.java index 34f6c202..1ce69136 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/misc/Float2ShortArrayMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/misc/Float2ShortArrayMap.java @@ -443,66 +443,76 @@ public short computeShort(float key, FloatShortUnaryOperator mappingFunction) { } @Override - public short computeShortNonDefault(float key, FloatShortUnaryOperator mappingFunction) { + public short computeShortIfAbsent(float key, Float2ShortFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + short newValue = mappingFunction.applyAsShort(key); insertIndex(size++, key, newValue); return newValue; } - short newValue = mappingFunction.applyAsShort(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + short newValue = values[index]; return newValue; } - + @Override - public short computeShortIfAbsent(float key, Float2ShortFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public short supplyShortIfAbsent(float key, ShortSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = valueProvider.getAsShort(); insertIndex(size++, key, newValue); return newValue; } short newValue = values[index]; return newValue; } + + @Override + public short computeShortIfPresent(float key, FloatShortUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index == -1) return getDefaultReturnValue(); + short newValue = mappingFunction.applyAsShort(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public short computeShortIfAbsentNonDefault(float key, Float2ShortFunction mappingFunction) { + public short computeShortNonDefault(float key, FloatShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } - short newValue = values[index]; + short newValue = mappingFunction.applyAsShort(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsShort(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public short supplyShortIfAbsent(float key, ShortSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public short computeShortIfAbsentNonDefault(float key, Float2ShortFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - short newValue = valueProvider.getAsInt(); + short newValue = mappingFunction.applyAsShort(key); + if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } short newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsShort(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -511,30 +521,20 @@ public short supplyShortIfAbsentNonDefault(float key, ShortSupplier valueProvide Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - short newValue = valueProvider.getAsInt(); + short newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } short newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public short computeShortIfPresent(float key, FloatShortUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) return getDefaultReturnValue(); - short newValue = mappingFunction.applyAsShort(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public short computeShortIfPresentNonDefault(float key, FloatShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2BooleanAVLTreeMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2BooleanAVLTreeMap.java index 328a10cb..86c27494 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2BooleanAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2BooleanAVLTreeMap.java @@ -396,34 +396,56 @@ public boolean computeBoolean(float key, FloatBooleanUnaryOperator mappingFuncti } @Override - public boolean computeBooleanNonDefault(float key, FloatBooleanUnaryOperator mappingFunction) { + public boolean computeBooleanIfAbsent(float key, FloatPredicate mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + boolean newValue = mappingFunction.test(key); put(key, newValue); return newValue; } - boolean newValue = mappingFunction.applyAsBoolean(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public boolean supplyBooleanIfAbsent(float key, BooleanSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + boolean newValue = valueProvider.getAsBoolean(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public boolean computeBooleanIfPresent(float key, FloatBooleanUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + boolean newValue = mappingFunction.applyAsBoolean(key, entry.value); entry.value = newValue; return newValue; } @Override - public boolean computeBooleanIfAbsent(float key, FloatPredicate mappingFunction) { + public boolean computeBooleanNonDefault(float key, FloatBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - boolean newValue = mappingFunction.test(key); + boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + boolean newValue = mappingFunction.applyAsBoolean(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -444,18 +466,6 @@ public boolean computeBooleanIfAbsentNonDefault(float key, FloatPredicate mappin return entry.value; } - @Override - public boolean supplyBooleanIfAbsent(float key, BooleanSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - boolean newValue = valueProvider.getAsBoolean(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public boolean supplyBooleanIfAbsentNonDefault(float key, BooleanSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -474,16 +484,6 @@ public boolean supplyBooleanIfAbsentNonDefault(float key, BooleanSupplier valueP return entry.value; } - @Override - public boolean computeBooleanIfPresent(float key, FloatBooleanUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - boolean newValue = mappingFunction.applyAsBoolean(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public boolean computeBooleanIfPresentNonDefault(float key, FloatBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1487,14 +1487,9 @@ public boolean computeBooleanIfPresent(float key, FloatBooleanUnaryOperator mapp Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - boolean newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2BooleanRBTreeMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2BooleanRBTreeMap.java index 25b0d334..eb87c051 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2BooleanRBTreeMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2BooleanRBTreeMap.java @@ -395,34 +395,56 @@ public boolean computeBoolean(float key, FloatBooleanUnaryOperator mappingFuncti } @Override - public boolean computeBooleanNonDefault(float key, FloatBooleanUnaryOperator mappingFunction) { + public boolean computeBooleanIfAbsent(float key, FloatPredicate mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + boolean newValue = mappingFunction.test(key); put(key, newValue); return newValue; } - boolean newValue = mappingFunction.applyAsBoolean(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public boolean supplyBooleanIfAbsent(float key, BooleanSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + boolean newValue = valueProvider.getAsBoolean(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public boolean computeBooleanIfPresent(float key, FloatBooleanUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + boolean newValue = mappingFunction.applyAsBoolean(key, entry.value); entry.value = newValue; return newValue; } @Override - public boolean computeBooleanIfAbsent(float key, FloatPredicate mappingFunction) { + public boolean computeBooleanNonDefault(float key, FloatBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - boolean newValue = mappingFunction.test(key); + boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + boolean newValue = mappingFunction.applyAsBoolean(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -443,18 +465,6 @@ public boolean computeBooleanIfAbsentNonDefault(float key, FloatPredicate mappin return entry.value; } - @Override - public boolean supplyBooleanIfAbsent(float key, BooleanSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - boolean newValue = valueProvider.getAsBoolean(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public boolean supplyBooleanIfAbsentNonDefault(float key, BooleanSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -473,16 +483,6 @@ public boolean supplyBooleanIfAbsentNonDefault(float key, BooleanSupplier valueP return entry.value; } - @Override - public boolean computeBooleanIfPresent(float key, FloatBooleanUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - boolean newValue = mappingFunction.applyAsBoolean(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public boolean computeBooleanIfPresentNonDefault(float key, FloatBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1550,14 +1550,9 @@ public boolean computeBooleanIfPresent(float key, FloatBooleanUnaryOperator mapp Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - boolean newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2ByteAVLTreeMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2ByteAVLTreeMap.java index 73e67ea1..1d3c7511 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2ByteAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2ByteAVLTreeMap.java @@ -455,34 +455,56 @@ public byte computeByte(float key, FloatByteUnaryOperator mappingFunction) { } @Override - public byte computeByteNonDefault(float key, FloatByteUnaryOperator mappingFunction) { + public byte computeByteIfAbsent(float key, Float2ByteFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + byte newValue = mappingFunction.applyAsByte(key); put(key, newValue); return newValue; } - byte newValue = mappingFunction.applyAsByte(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public byte supplyByteIfAbsent(float key, ByteSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + byte newValue = valueProvider.getAsByte(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public byte computeByteIfPresent(float key, FloatByteUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + byte newValue = mappingFunction.applyAsByte(key, entry.value); entry.value = newValue; return newValue; } @Override - public byte computeByteIfAbsent(float key, Float2ByteFunction mappingFunction) { + public byte computeByteNonDefault(float key, FloatByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + byte newValue = mappingFunction.applyAsByte(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -503,46 +525,24 @@ public byte computeByteIfAbsentNonDefault(float key, Float2ByteFunction mappingF return entry.value; } - @Override - public byte supplyByteIfAbsent(float key, ByteSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - byte newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public byte supplyByteIfAbsentNonDefault(float key, ByteSupplier valueProvider) { Objects.requireNonNull(valueProvider); Node entry = findNode(key); if(entry == null) { - byte newValue = valueProvider.getAsInt(); + byte newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } if(entry.value == getDefaultReturnValue()) { - byte newValue = valueProvider.getAsInt(); + byte newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; entry.value = newValue; } return entry.value; } - @Override - public byte computeByteIfPresent(float key, FloatByteUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - byte newValue = mappingFunction.applyAsByte(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public byte computeByteIfPresentNonDefault(float key, FloatByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1558,14 +1558,9 @@ public byte computeByteIfPresent(float key, FloatByteUnaryOperator mappingFuncti Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - byte newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2ByteRBTreeMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2ByteRBTreeMap.java index cc48a50b..7f11a448 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2ByteRBTreeMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2ByteRBTreeMap.java @@ -454,34 +454,56 @@ public byte computeByte(float key, FloatByteUnaryOperator mappingFunction) { } @Override - public byte computeByteNonDefault(float key, FloatByteUnaryOperator mappingFunction) { + public byte computeByteIfAbsent(float key, Float2ByteFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + byte newValue = mappingFunction.applyAsByte(key); put(key, newValue); return newValue; } - byte newValue = mappingFunction.applyAsByte(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public byte supplyByteIfAbsent(float key, ByteSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + byte newValue = valueProvider.getAsByte(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public byte computeByteIfPresent(float key, FloatByteUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + byte newValue = mappingFunction.applyAsByte(key, entry.value); entry.value = newValue; return newValue; } @Override - public byte computeByteIfAbsent(float key, Float2ByteFunction mappingFunction) { + public byte computeByteNonDefault(float key, FloatByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + byte newValue = mappingFunction.applyAsByte(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -502,46 +524,24 @@ public byte computeByteIfAbsentNonDefault(float key, Float2ByteFunction mappingF return entry.value; } - @Override - public byte supplyByteIfAbsent(float key, ByteSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - byte newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public byte supplyByteIfAbsentNonDefault(float key, ByteSupplier valueProvider) { Objects.requireNonNull(valueProvider); Node entry = findNode(key); if(entry == null) { - byte newValue = valueProvider.getAsInt(); + byte newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } if(entry.value == getDefaultReturnValue()) { - byte newValue = valueProvider.getAsInt(); + byte newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; entry.value = newValue; } return entry.value; } - @Override - public byte computeByteIfPresent(float key, FloatByteUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - byte newValue = mappingFunction.applyAsByte(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public byte computeByteIfPresentNonDefault(float key, FloatByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1621,14 +1621,9 @@ public byte computeByteIfPresent(float key, FloatByteUnaryOperator mappingFuncti Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - byte newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2CharAVLTreeMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2CharAVLTreeMap.java index 4fac37c7..9a2cc693 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2CharAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2CharAVLTreeMap.java @@ -455,34 +455,56 @@ public char computeChar(float key, FloatCharUnaryOperator mappingFunction) { } @Override - public char computeCharNonDefault(float key, FloatCharUnaryOperator mappingFunction) { + public char computeCharIfAbsent(float key, Float2CharFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + char newValue = mappingFunction.applyAsChar(key); put(key, newValue); return newValue; } - char newValue = mappingFunction.applyAsChar(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public char supplyCharIfAbsent(float key, CharSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + char newValue = valueProvider.getAsChar(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public char computeCharIfPresent(float key, FloatCharUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + char newValue = mappingFunction.applyAsChar(key, entry.value); entry.value = newValue; return newValue; } @Override - public char computeCharIfAbsent(float key, Float2CharFunction mappingFunction) { + public char computeCharNonDefault(float key, FloatCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + char newValue = mappingFunction.applyAsChar(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -503,46 +525,24 @@ public char computeCharIfAbsentNonDefault(float key, Float2CharFunction mappingF return entry.value; } - @Override - public char supplyCharIfAbsent(float key, CharSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - char newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public char supplyCharIfAbsentNonDefault(float key, CharSupplier valueProvider) { Objects.requireNonNull(valueProvider); Node entry = findNode(key); if(entry == null) { - char newValue = valueProvider.getAsInt(); + char newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } if(entry.value == getDefaultReturnValue()) { - char newValue = valueProvider.getAsInt(); + char newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; entry.value = newValue; } return entry.value; } - @Override - public char computeCharIfPresent(float key, FloatCharUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - char newValue = mappingFunction.applyAsChar(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public char computeCharIfPresentNonDefault(float key, FloatCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1558,14 +1558,9 @@ public char computeCharIfPresent(float key, FloatCharUnaryOperator mappingFuncti Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - char newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2CharRBTreeMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2CharRBTreeMap.java index 2787a559..fa584f77 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2CharRBTreeMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2CharRBTreeMap.java @@ -454,34 +454,56 @@ public char computeChar(float key, FloatCharUnaryOperator mappingFunction) { } @Override - public char computeCharNonDefault(float key, FloatCharUnaryOperator mappingFunction) { + public char computeCharIfAbsent(float key, Float2CharFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + char newValue = mappingFunction.applyAsChar(key); put(key, newValue); return newValue; } - char newValue = mappingFunction.applyAsChar(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public char supplyCharIfAbsent(float key, CharSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + char newValue = valueProvider.getAsChar(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public char computeCharIfPresent(float key, FloatCharUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + char newValue = mappingFunction.applyAsChar(key, entry.value); entry.value = newValue; return newValue; } @Override - public char computeCharIfAbsent(float key, Float2CharFunction mappingFunction) { + public char computeCharNonDefault(float key, FloatCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + char newValue = mappingFunction.applyAsChar(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -502,46 +524,24 @@ public char computeCharIfAbsentNonDefault(float key, Float2CharFunction mappingF return entry.value; } - @Override - public char supplyCharIfAbsent(float key, CharSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - char newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public char supplyCharIfAbsentNonDefault(float key, CharSupplier valueProvider) { Objects.requireNonNull(valueProvider); Node entry = findNode(key); if(entry == null) { - char newValue = valueProvider.getAsInt(); + char newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } if(entry.value == getDefaultReturnValue()) { - char newValue = valueProvider.getAsInt(); + char newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; entry.value = newValue; } return entry.value; } - @Override - public char computeCharIfPresent(float key, FloatCharUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - char newValue = mappingFunction.applyAsChar(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public char computeCharIfPresentNonDefault(float key, FloatCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1621,14 +1621,9 @@ public char computeCharIfPresent(float key, FloatCharUnaryOperator mappingFuncti Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - char newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2DoubleAVLTreeMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2DoubleAVLTreeMap.java index c03db0d5..19116382 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2DoubleAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2DoubleAVLTreeMap.java @@ -455,34 +455,56 @@ public double computeDouble(float key, FloatDoubleUnaryOperator mappingFunction) } @Override - public double computeDoubleNonDefault(float key, FloatDoubleUnaryOperator mappingFunction) { + public double computeDoubleIfAbsent(float key, Float2DoubleFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + double newValue = mappingFunction.applyAsDouble(key); put(key, newValue); return newValue; } - double newValue = mappingFunction.applyAsDouble(key, entry.value); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - removeNode(entry); + return entry.value; + } + + @Override + public double supplyDoubleIfAbsent(float key, DoubleSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + double newValue = valueProvider.getAsDouble(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public double computeDoubleIfPresent(float key, FloatDoubleUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + double newValue = mappingFunction.applyAsDouble(key, entry.value); entry.value = newValue; return newValue; } @Override - public double computeDoubleIfAbsent(float key, Float2DoubleFunction mappingFunction) { + public double computeDoubleNonDefault(float key, FloatDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; put(key, newValue); return newValue; } - return entry.value; + double newValue = mappingFunction.applyAsDouble(key, entry.value); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -503,18 +525,6 @@ public double computeDoubleIfAbsentNonDefault(float key, Float2DoubleFunction ma return entry.value; } - @Override - public double supplyDoubleIfAbsent(float key, DoubleSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - double newValue = valueProvider.getAsDouble(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public double supplyDoubleIfAbsentNonDefault(float key, DoubleSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -533,16 +543,6 @@ public double supplyDoubleIfAbsentNonDefault(float key, DoubleSupplier valueProv return entry.value; } - @Override - public double computeDoubleIfPresent(float key, FloatDoubleUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - double newValue = mappingFunction.applyAsDouble(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public double computeDoubleIfPresentNonDefault(float key, FloatDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1558,14 +1558,9 @@ public double computeDoubleIfPresent(float key, FloatDoubleUnaryOperator mapping Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || Double.doubleToLongBits(entry.value) == Double.doubleToLongBits(getDefaultReturnValue())) return getDefaultReturnValue(); - double newValue = mappingFunction.apply(key, entry.value); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2DoubleRBTreeMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2DoubleRBTreeMap.java index 1586e897..41f64a0c 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2DoubleRBTreeMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2DoubleRBTreeMap.java @@ -454,34 +454,56 @@ public double computeDouble(float key, FloatDoubleUnaryOperator mappingFunction) } @Override - public double computeDoubleNonDefault(float key, FloatDoubleUnaryOperator mappingFunction) { + public double computeDoubleIfAbsent(float key, Float2DoubleFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + double newValue = mappingFunction.applyAsDouble(key); put(key, newValue); return newValue; } - double newValue = mappingFunction.applyAsDouble(key, entry.value); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - removeNode(entry); + return entry.value; + } + + @Override + public double supplyDoubleIfAbsent(float key, DoubleSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + double newValue = valueProvider.getAsDouble(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public double computeDoubleIfPresent(float key, FloatDoubleUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + double newValue = mappingFunction.applyAsDouble(key, entry.value); entry.value = newValue; return newValue; } @Override - public double computeDoubleIfAbsent(float key, Float2DoubleFunction mappingFunction) { + public double computeDoubleNonDefault(float key, FloatDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; put(key, newValue); return newValue; } - return entry.value; + double newValue = mappingFunction.applyAsDouble(key, entry.value); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -502,18 +524,6 @@ public double computeDoubleIfAbsentNonDefault(float key, Float2DoubleFunction ma return entry.value; } - @Override - public double supplyDoubleIfAbsent(float key, DoubleSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - double newValue = valueProvider.getAsDouble(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public double supplyDoubleIfAbsentNonDefault(float key, DoubleSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -532,16 +542,6 @@ public double supplyDoubleIfAbsentNonDefault(float key, DoubleSupplier valueProv return entry.value; } - @Override - public double computeDoubleIfPresent(float key, FloatDoubleUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - double newValue = mappingFunction.applyAsDouble(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public double computeDoubleIfPresentNonDefault(float key, FloatDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1621,14 +1621,9 @@ public double computeDoubleIfPresent(float key, FloatDoubleUnaryOperator mapping Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || Double.doubleToLongBits(entry.value) == Double.doubleToLongBits(getDefaultReturnValue())) return getDefaultReturnValue(); - double newValue = mappingFunction.apply(key, entry.value); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2FloatAVLTreeMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2FloatAVLTreeMap.java index 250796ec..c6de83b2 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2FloatAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2FloatAVLTreeMap.java @@ -447,34 +447,56 @@ public float computeFloat(float key, FloatFloatUnaryOperator mappingFunction) { } @Override - public float computeFloatNonDefault(float key, FloatFloatUnaryOperator mappingFunction) { + public float computeFloatIfAbsent(float key, FloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + float newValue = mappingFunction.applyAsFloat(key); put(key, newValue); return newValue; } - float newValue = mappingFunction.applyAsFloat(key, entry.value); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - removeNode(entry); + return entry.value; + } + + @Override + public float supplyFloatIfAbsent(float key, FloatSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + float newValue = valueProvider.getAsFloat(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public float computeFloatIfPresent(float key, FloatFloatUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + float newValue = mappingFunction.applyAsFloat(key, entry.value); entry.value = newValue; return newValue; } @Override - public float computeFloatIfAbsent(float key, FloatUnaryOperator mappingFunction) { + public float computeFloatNonDefault(float key, FloatFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; put(key, newValue); return newValue; } - return entry.value; + float newValue = mappingFunction.applyAsFloat(key, entry.value); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -495,46 +517,24 @@ public float computeFloatIfAbsentNonDefault(float key, FloatUnaryOperator mappin return entry.value; } - @Override - public float supplyFloatIfAbsent(float key, FloatSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - float newValue = valueProvider.getAsDouble(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public float supplyFloatIfAbsentNonDefault(float key, FloatSupplier valueProvider) { Objects.requireNonNull(valueProvider); Node entry = findNode(key); if(entry == null) { - float newValue = valueProvider.getAsDouble(); + float newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; put(key, newValue); return newValue; } if(Float.floatToIntBits(entry.value) == Float.floatToIntBits(getDefaultReturnValue())) { - float newValue = valueProvider.getAsDouble(); + float newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; entry.value = newValue; } return entry.value; } - @Override - public float computeFloatIfPresent(float key, FloatFloatUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - float newValue = mappingFunction.applyAsFloat(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public float computeFloatIfPresentNonDefault(float key, FloatFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1550,14 +1550,9 @@ public float computeFloatIfPresent(float key, FloatFloatUnaryOperator mappingFun Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || Float.floatToIntBits(entry.value) == Float.floatToIntBits(getDefaultReturnValue())) return getDefaultReturnValue(); - float newValue = mappingFunction.apply(key, entry.value); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2FloatRBTreeMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2FloatRBTreeMap.java index 572b508f..52665ced 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2FloatRBTreeMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2FloatRBTreeMap.java @@ -446,34 +446,56 @@ public float computeFloat(float key, FloatFloatUnaryOperator mappingFunction) { } @Override - public float computeFloatNonDefault(float key, FloatFloatUnaryOperator mappingFunction) { + public float computeFloatIfAbsent(float key, FloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + float newValue = mappingFunction.applyAsFloat(key); put(key, newValue); return newValue; } - float newValue = mappingFunction.applyAsFloat(key, entry.value); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - removeNode(entry); + return entry.value; + } + + @Override + public float supplyFloatIfAbsent(float key, FloatSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + float newValue = valueProvider.getAsFloat(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public float computeFloatIfPresent(float key, FloatFloatUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + float newValue = mappingFunction.applyAsFloat(key, entry.value); entry.value = newValue; return newValue; } @Override - public float computeFloatIfAbsent(float key, FloatUnaryOperator mappingFunction) { + public float computeFloatNonDefault(float key, FloatFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; put(key, newValue); return newValue; } - return entry.value; + float newValue = mappingFunction.applyAsFloat(key, entry.value); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -494,46 +516,24 @@ public float computeFloatIfAbsentNonDefault(float key, FloatUnaryOperator mappin return entry.value; } - @Override - public float supplyFloatIfAbsent(float key, FloatSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - float newValue = valueProvider.getAsDouble(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public float supplyFloatIfAbsentNonDefault(float key, FloatSupplier valueProvider) { Objects.requireNonNull(valueProvider); Node entry = findNode(key); if(entry == null) { - float newValue = valueProvider.getAsDouble(); + float newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; put(key, newValue); return newValue; } if(Float.floatToIntBits(entry.value) == Float.floatToIntBits(getDefaultReturnValue())) { - float newValue = valueProvider.getAsDouble(); + float newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; entry.value = newValue; } return entry.value; } - @Override - public float computeFloatIfPresent(float key, FloatFloatUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - float newValue = mappingFunction.applyAsFloat(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public float computeFloatIfPresentNonDefault(float key, FloatFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1613,14 +1613,9 @@ public float computeFloatIfPresent(float key, FloatFloatUnaryOperator mappingFun Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || Float.floatToIntBits(entry.value) == Float.floatToIntBits(getDefaultReturnValue())) return getDefaultReturnValue(); - float newValue = mappingFunction.apply(key, entry.value); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2IntAVLTreeMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2IntAVLTreeMap.java index bfc21ade..c764aeca 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2IntAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2IntAVLTreeMap.java @@ -455,34 +455,56 @@ public int computeInt(float key, FloatIntUnaryOperator mappingFunction) { } @Override - public int computeIntNonDefault(float key, FloatIntUnaryOperator mappingFunction) { + public int computeIntIfAbsent(float key, Float2IntFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + int newValue = mappingFunction.applyAsInt(key); put(key, newValue); return newValue; } - int newValue = mappingFunction.applyAsInt(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public int supplyIntIfAbsent(float key, IntSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + int newValue = valueProvider.getAsInt(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public int computeIntIfPresent(float key, FloatIntUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + int newValue = mappingFunction.applyAsInt(key, entry.value); entry.value = newValue; return newValue; } @Override - public int computeIntIfAbsent(float key, Float2IntFunction mappingFunction) { + public int computeIntNonDefault(float key, FloatIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + int newValue = mappingFunction.applyAsInt(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -503,18 +525,6 @@ public int computeIntIfAbsentNonDefault(float key, Float2IntFunction mappingFunc return entry.value; } - @Override - public int supplyIntIfAbsent(float key, IntSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - int newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public int supplyIntIfAbsentNonDefault(float key, IntSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -533,16 +543,6 @@ public int supplyIntIfAbsentNonDefault(float key, IntSupplier valueProvider) { return entry.value; } - @Override - public int computeIntIfPresent(float key, FloatIntUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - int newValue = mappingFunction.applyAsInt(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public int computeIntIfPresentNonDefault(float key, FloatIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1558,14 +1558,9 @@ public int computeIntIfPresent(float key, FloatIntUnaryOperator mappingFunction) Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - int newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2IntRBTreeMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2IntRBTreeMap.java index efd945c2..b2601943 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2IntRBTreeMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2IntRBTreeMap.java @@ -454,34 +454,56 @@ public int computeInt(float key, FloatIntUnaryOperator mappingFunction) { } @Override - public int computeIntNonDefault(float key, FloatIntUnaryOperator mappingFunction) { + public int computeIntIfAbsent(float key, Float2IntFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + int newValue = mappingFunction.applyAsInt(key); put(key, newValue); return newValue; } - int newValue = mappingFunction.applyAsInt(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public int supplyIntIfAbsent(float key, IntSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + int newValue = valueProvider.getAsInt(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public int computeIntIfPresent(float key, FloatIntUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + int newValue = mappingFunction.applyAsInt(key, entry.value); entry.value = newValue; return newValue; } @Override - public int computeIntIfAbsent(float key, Float2IntFunction mappingFunction) { + public int computeIntNonDefault(float key, FloatIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + int newValue = mappingFunction.applyAsInt(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -502,18 +524,6 @@ public int computeIntIfAbsentNonDefault(float key, Float2IntFunction mappingFunc return entry.value; } - @Override - public int supplyIntIfAbsent(float key, IntSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - int newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public int supplyIntIfAbsentNonDefault(float key, IntSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -532,16 +542,6 @@ public int supplyIntIfAbsentNonDefault(float key, IntSupplier valueProvider) { return entry.value; } - @Override - public int computeIntIfPresent(float key, FloatIntUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - int newValue = mappingFunction.applyAsInt(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public int computeIntIfPresentNonDefault(float key, FloatIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1621,14 +1621,9 @@ public int computeIntIfPresent(float key, FloatIntUnaryOperator mappingFunction) Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - int newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2LongAVLTreeMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2LongAVLTreeMap.java index f24a9910..bd15c14f 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2LongAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2LongAVLTreeMap.java @@ -455,34 +455,56 @@ public long computeLong(float key, FloatLongUnaryOperator mappingFunction) { } @Override - public long computeLongNonDefault(float key, FloatLongUnaryOperator mappingFunction) { + public long computeLongIfAbsent(float key, Float2LongFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + long newValue = mappingFunction.applyAsLong(key); put(key, newValue); return newValue; } - long newValue = mappingFunction.applyAsLong(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public long supplyLongIfAbsent(float key, LongSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + long newValue = valueProvider.getAsLong(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public long computeLongIfPresent(float key, FloatLongUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + long newValue = mappingFunction.applyAsLong(key, entry.value); entry.value = newValue; return newValue; } @Override - public long computeLongIfAbsent(float key, Float2LongFunction mappingFunction) { + public long computeLongNonDefault(float key, FloatLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + long newValue = mappingFunction.applyAsLong(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -503,18 +525,6 @@ public long computeLongIfAbsentNonDefault(float key, Float2LongFunction mappingF return entry.value; } - @Override - public long supplyLongIfAbsent(float key, LongSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - long newValue = valueProvider.getAsLong(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public long supplyLongIfAbsentNonDefault(float key, LongSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -533,16 +543,6 @@ public long supplyLongIfAbsentNonDefault(float key, LongSupplier valueProvider) return entry.value; } - @Override - public long computeLongIfPresent(float key, FloatLongUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - long newValue = mappingFunction.applyAsLong(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public long computeLongIfPresentNonDefault(float key, FloatLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1558,14 +1558,9 @@ public long computeLongIfPresent(float key, FloatLongUnaryOperator mappingFuncti Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - long newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2LongRBTreeMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2LongRBTreeMap.java index 49cb12a9..2cf733e0 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2LongRBTreeMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2LongRBTreeMap.java @@ -454,34 +454,56 @@ public long computeLong(float key, FloatLongUnaryOperator mappingFunction) { } @Override - public long computeLongNonDefault(float key, FloatLongUnaryOperator mappingFunction) { + public long computeLongIfAbsent(float key, Float2LongFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + long newValue = mappingFunction.applyAsLong(key); put(key, newValue); return newValue; } - long newValue = mappingFunction.applyAsLong(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public long supplyLongIfAbsent(float key, LongSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + long newValue = valueProvider.getAsLong(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public long computeLongIfPresent(float key, FloatLongUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + long newValue = mappingFunction.applyAsLong(key, entry.value); entry.value = newValue; return newValue; } @Override - public long computeLongIfAbsent(float key, Float2LongFunction mappingFunction) { + public long computeLongNonDefault(float key, FloatLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + long newValue = mappingFunction.applyAsLong(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -502,18 +524,6 @@ public long computeLongIfAbsentNonDefault(float key, Float2LongFunction mappingF return entry.value; } - @Override - public long supplyLongIfAbsent(float key, LongSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - long newValue = valueProvider.getAsLong(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public long supplyLongIfAbsentNonDefault(float key, LongSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -532,16 +542,6 @@ public long supplyLongIfAbsentNonDefault(float key, LongSupplier valueProvider) return entry.value; } - @Override - public long computeLongIfPresent(float key, FloatLongUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - long newValue = mappingFunction.applyAsLong(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public long computeLongIfPresentNonDefault(float key, FloatLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1621,14 +1621,9 @@ public long computeLongIfPresent(float key, FloatLongUnaryOperator mappingFuncti Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - long newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2ObjectAVLTreeMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2ObjectAVLTreeMap.java index 883d4398..3fba480d 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2ObjectAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2ObjectAVLTreeMap.java @@ -395,25 +395,6 @@ public V compute(float key, FloatObjectUnaryOperator mappingFunction) { return newValue; } - @Override - public V computeNonDefault(float key, FloatObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) { - V newValue = mappingFunction.apply(key, getDefaultReturnValue()); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - put(key, newValue); - return newValue; - } - V newValue = mappingFunction.apply(key, entry.value); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; - } - @Override public V computeIfAbsent(float key, FloatFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -432,24 +413,6 @@ public V computeIfAbsent(float key, FloatFunction mappingFunction) { return entry.value; } - @Override - public V computeIfAbsentNonDefault(float key, FloatFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) { - V newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - put(key, newValue); - return newValue; - } - if(Objects.equals(entry.value, getDefaultReturnValue())) { - V newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - entry.value = newValue; - } - return entry.value; - } - @Override public V supplyIfAbsent(float key, ObjectSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -468,24 +431,6 @@ public V supplyIfAbsent(float key, ObjectSupplier valueProvider) { return entry.value; } - @Override - public V supplyIfAbsentNonDefault(float key, ObjectSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - V newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - put(key, newValue); - return newValue; - } - if(Objects.equals(entry.value, getDefaultReturnValue())) { - V newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - entry.value = newValue; - } - return entry.value; - } - @Override public V computeIfPresent(float key, FloatObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -500,20 +445,6 @@ public V computeIfPresent(float key, FloatObjectUnaryOperator mappingFunction return newValue; } - @Override - public V computeIfPresentNonDefault(float key, FloatObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null || Objects.equals(entry.value, getDefaultReturnValue())) return getDefaultReturnValue(); - V newValue = mappingFunction.apply(key, entry.value); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; - } - @Override public V merge(float key, V value, ObjectObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2ObjectRBTreeMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2ObjectRBTreeMap.java index b026f42e..7ece5d8c 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2ObjectRBTreeMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2ObjectRBTreeMap.java @@ -394,25 +394,6 @@ public V compute(float key, FloatObjectUnaryOperator mappingFunction) { return newValue; } - @Override - public V computeNonDefault(float key, FloatObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) { - V newValue = mappingFunction.apply(key, getDefaultReturnValue()); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - put(key, newValue); - return newValue; - } - V newValue = mappingFunction.apply(key, entry.value); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; - } - @Override public V computeIfAbsent(float key, FloatFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -431,24 +412,6 @@ public V computeIfAbsent(float key, FloatFunction mappingFunction) { return entry.value; } - @Override - public V computeIfAbsentNonDefault(float key, FloatFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) { - V newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - put(key, newValue); - return newValue; - } - if(Objects.equals(entry.value, getDefaultReturnValue())) { - V newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - entry.value = newValue; - } - return entry.value; - } - @Override public V supplyIfAbsent(float key, ObjectSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -467,24 +430,6 @@ public V supplyIfAbsent(float key, ObjectSupplier valueProvider) { return entry.value; } - @Override - public V supplyIfAbsentNonDefault(float key, ObjectSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - V newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - put(key, newValue); - return newValue; - } - if(Objects.equals(entry.value, getDefaultReturnValue())) { - V newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - entry.value = newValue; - } - return entry.value; - } - @Override public V computeIfPresent(float key, FloatObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -499,20 +444,6 @@ public V computeIfPresent(float key, FloatObjectUnaryOperator mappingFunction return newValue; } - @Override - public V computeIfPresentNonDefault(float key, FloatObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null || Objects.equals(entry.value, getDefaultReturnValue())) return getDefaultReturnValue(); - V newValue = mappingFunction.apply(key, entry.value); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; - } - @Override public V merge(float key, V value, ObjectObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2ShortAVLTreeMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2ShortAVLTreeMap.java index f5be883b..127187ef 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2ShortAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2ShortAVLTreeMap.java @@ -455,34 +455,56 @@ public short computeShort(float key, FloatShortUnaryOperator mappingFunction) { } @Override - public short computeShortNonDefault(float key, FloatShortUnaryOperator mappingFunction) { + public short computeShortIfAbsent(float key, Float2ShortFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + short newValue = mappingFunction.applyAsShort(key); put(key, newValue); return newValue; } - short newValue = mappingFunction.applyAsShort(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public short supplyShortIfAbsent(float key, ShortSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + short newValue = valueProvider.getAsShort(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public short computeShortIfPresent(float key, FloatShortUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + short newValue = mappingFunction.applyAsShort(key, entry.value); entry.value = newValue; return newValue; } @Override - public short computeShortIfAbsent(float key, Float2ShortFunction mappingFunction) { + public short computeShortNonDefault(float key, FloatShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + short newValue = mappingFunction.applyAsShort(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -503,46 +525,24 @@ public short computeShortIfAbsentNonDefault(float key, Float2ShortFunction mappi return entry.value; } - @Override - public short supplyShortIfAbsent(float key, ShortSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - short newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public short supplyShortIfAbsentNonDefault(float key, ShortSupplier valueProvider) { Objects.requireNonNull(valueProvider); Node entry = findNode(key); if(entry == null) { - short newValue = valueProvider.getAsInt(); + short newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } if(entry.value == getDefaultReturnValue()) { - short newValue = valueProvider.getAsInt(); + short newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; entry.value = newValue; } return entry.value; } - @Override - public short computeShortIfPresent(float key, FloatShortUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - short newValue = mappingFunction.applyAsShort(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public short computeShortIfPresentNonDefault(float key, FloatShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1558,14 +1558,9 @@ public short computeShortIfPresent(float key, FloatShortUnaryOperator mappingFun Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - short newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2ShortRBTreeMap.java b/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2ShortRBTreeMap.java index c8fe3d56..5da5d2cd 100644 --- a/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2ShortRBTreeMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/impl/tree/Float2ShortRBTreeMap.java @@ -454,34 +454,56 @@ public short computeShort(float key, FloatShortUnaryOperator mappingFunction) { } @Override - public short computeShortNonDefault(float key, FloatShortUnaryOperator mappingFunction) { + public short computeShortIfAbsent(float key, Float2ShortFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + short newValue = mappingFunction.applyAsShort(key); put(key, newValue); return newValue; } - short newValue = mappingFunction.applyAsShort(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public short supplyShortIfAbsent(float key, ShortSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + short newValue = valueProvider.getAsShort(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public short computeShortIfPresent(float key, FloatShortUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + short newValue = mappingFunction.applyAsShort(key, entry.value); entry.value = newValue; return newValue; } @Override - public short computeShortIfAbsent(float key, Float2ShortFunction mappingFunction) { + public short computeShortNonDefault(float key, FloatShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + short newValue = mappingFunction.applyAsShort(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -502,46 +524,24 @@ public short computeShortIfAbsentNonDefault(float key, Float2ShortFunction mappi return entry.value; } - @Override - public short supplyShortIfAbsent(float key, ShortSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - short newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public short supplyShortIfAbsentNonDefault(float key, ShortSupplier valueProvider) { Objects.requireNonNull(valueProvider); Node entry = findNode(key); if(entry == null) { - short newValue = valueProvider.getAsInt(); + short newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } if(entry.value == getDefaultReturnValue()) { - short newValue = valueProvider.getAsInt(); + short newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; entry.value = newValue; } return entry.value; } - @Override - public short computeShortIfPresent(float key, FloatShortUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - short newValue = mappingFunction.applyAsShort(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public short computeShortIfPresentNonDefault(float key, FloatShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1621,14 +1621,9 @@ public short computeShortIfPresent(float key, FloatShortUnaryOperator mappingFun Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - short newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/floats/maps/interfaces/Float2BooleanMap.java b/src/main/java/speiger/src/collections/floats/maps/interfaces/Float2BooleanMap.java index d2fd0e60..8c515f8d 100644 --- a/src/main/java/speiger/src/collections/floats/maps/interfaces/Float2BooleanMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/interfaces/Float2BooleanMap.java @@ -284,41 +284,51 @@ public default boolean remove(Object key, Object value) { */ public boolean computeBoolean(float key, FloatBooleanUnaryOperator mappingFunction); /** - * A Type Specific compute method to reduce boxing/unboxing + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation + * @param mappingFunction the operator that should generate the value if not present + * @return the result of the computed value or present value */ - public boolean computeBooleanNonDefault(float key, FloatBooleanUnaryOperator mappingFunction); + public boolean computeBooleanIfAbsent(float key, FloatPredicate mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present + * @param valueProvider the value if not present * @return the result of the computed value or present value + */ + public boolean supplyBooleanIfAbsent(float key, BooleanSupplier valueProvider); + /** + * A Type Specific compute method to reduce boxing/unboxing + * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". + * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. + * @param key the key that should be computed + * @param mappingFunction the operator that should generate the value if present + * @return the result of the default return value or present value + * @note if not present then compute is not executed */ - public boolean computeBooleanIfAbsent(float key, FloatPredicate mappingFunction); + public boolean computeBooleanIfPresent(float key, FloatBooleanUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value + * @param mappingFunction the operator that should generate the value + * @return the result of the computation */ - public boolean computeBooleanIfAbsentNonDefault(float key, FloatPredicate mappingFunction); + public boolean computeBooleanNonDefault(float key, FloatBooleanUnaryOperator mappingFunction); /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param valueProvider the value if not present + * @param mappingFunction the operator that should generate the value if not present * @return the result of the computed value or present value - */ - public boolean supplyBooleanIfAbsent(float key, BooleanSupplier valueProvider); + */ + public boolean computeBooleanIfAbsentNonDefault(float key, FloatPredicate mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -328,16 +338,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public boolean supplyBooleanIfAbsentNonDefault(float key, BooleanSupplier valueProvider); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public boolean computeBooleanIfPresent(float key, FloatBooleanUnaryOperator mappingFunction); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/floats/maps/interfaces/Float2ByteMap.java b/src/main/java/speiger/src/collections/floats/maps/interfaces/Float2ByteMap.java index 87fcbfd1..ea550036 100644 --- a/src/main/java/speiger/src/collections/floats/maps/interfaces/Float2ByteMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/interfaces/Float2ByteMap.java @@ -309,41 +309,51 @@ public default boolean remove(Object key, Object value) { */ public byte computeByte(float key, FloatByteUnaryOperator mappingFunction); /** - * A Type Specific compute method to reduce boxing/unboxing + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation + * @param mappingFunction the operator that should generate the value if not present + * @return the result of the computed value or present value */ - public byte computeByteNonDefault(float key, FloatByteUnaryOperator mappingFunction); + public byte computeByteIfAbsent(float key, Float2ByteFunction mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present + * @param valueProvider the value if not present * @return the result of the computed value or present value + */ + public byte supplyByteIfAbsent(float key, ByteSupplier valueProvider); + /** + * A Type Specific compute method to reduce boxing/unboxing + * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". + * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. + * @param key the key that should be computed + * @param mappingFunction the operator that should generate the value if present + * @return the result of the default return value or present value + * @note if not present then compute is not executed */ - public byte computeByteIfAbsent(float key, Float2ByteFunction mappingFunction); + public byte computeByteIfPresent(float key, FloatByteUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value + * @param mappingFunction the operator that should generate the value + * @return the result of the computation */ - public byte computeByteIfAbsentNonDefault(float key, Float2ByteFunction mappingFunction); + public byte computeByteNonDefault(float key, FloatByteUnaryOperator mappingFunction); /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param valueProvider the value if not present + * @param mappingFunction the operator that should generate the value if not present * @return the result of the computed value or present value - */ - public byte supplyByteIfAbsent(float key, ByteSupplier valueProvider); + */ + public byte computeByteIfAbsentNonDefault(float key, Float2ByteFunction mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -353,16 +363,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public byte supplyByteIfAbsentNonDefault(float key, ByteSupplier valueProvider); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public byte computeByteIfPresent(float key, FloatByteUnaryOperator mappingFunction); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/floats/maps/interfaces/Float2CharMap.java b/src/main/java/speiger/src/collections/floats/maps/interfaces/Float2CharMap.java index f39cbe1e..711df796 100644 --- a/src/main/java/speiger/src/collections/floats/maps/interfaces/Float2CharMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/interfaces/Float2CharMap.java @@ -309,41 +309,51 @@ public default boolean remove(Object key, Object value) { */ public char computeChar(float key, FloatCharUnaryOperator mappingFunction); /** - * A Type Specific compute method to reduce boxing/unboxing + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation + * @param mappingFunction the operator that should generate the value if not present + * @return the result of the computed value or present value */ - public char computeCharNonDefault(float key, FloatCharUnaryOperator mappingFunction); + public char computeCharIfAbsent(float key, Float2CharFunction mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present + * @param valueProvider the value if not present * @return the result of the computed value or present value + */ + public char supplyCharIfAbsent(float key, CharSupplier valueProvider); + /** + * A Type Specific compute method to reduce boxing/unboxing + * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". + * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. + * @param key the key that should be computed + * @param mappingFunction the operator that should generate the value if present + * @return the result of the default return value or present value + * @note if not present then compute is not executed */ - public char computeCharIfAbsent(float key, Float2CharFunction mappingFunction); + public char computeCharIfPresent(float key, FloatCharUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value + * @param mappingFunction the operator that should generate the value + * @return the result of the computation */ - public char computeCharIfAbsentNonDefault(float key, Float2CharFunction mappingFunction); + public char computeCharNonDefault(float key, FloatCharUnaryOperator mappingFunction); /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param valueProvider the value if not present + * @param mappingFunction the operator that should generate the value if not present * @return the result of the computed value or present value - */ - public char supplyCharIfAbsent(float key, CharSupplier valueProvider); + */ + public char computeCharIfAbsentNonDefault(float key, Float2CharFunction mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -353,16 +363,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public char supplyCharIfAbsentNonDefault(float key, CharSupplier valueProvider); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public char computeCharIfPresent(float key, FloatCharUnaryOperator mappingFunction); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/floats/maps/interfaces/Float2DoubleMap.java b/src/main/java/speiger/src/collections/floats/maps/interfaces/Float2DoubleMap.java index a0b41e36..ccaa4cee 100644 --- a/src/main/java/speiger/src/collections/floats/maps/interfaces/Float2DoubleMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/interfaces/Float2DoubleMap.java @@ -309,41 +309,51 @@ public default boolean remove(Object key, Object value) { */ public double computeDouble(float key, FloatDoubleUnaryOperator mappingFunction); /** - * A Type Specific compute method to reduce boxing/unboxing + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation + * @param mappingFunction the operator that should generate the value if not present + * @return the result of the computed value or present value */ - public double computeDoubleNonDefault(float key, FloatDoubleUnaryOperator mappingFunction); + public double computeDoubleIfAbsent(float key, Float2DoubleFunction mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present + * @param valueProvider the value if not present * @return the result of the computed value or present value + */ + public double supplyDoubleIfAbsent(float key, DoubleSupplier valueProvider); + /** + * A Type Specific compute method to reduce boxing/unboxing + * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". + * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. + * @param key the key that should be computed + * @param mappingFunction the operator that should generate the value if present + * @return the result of the default return value or present value + * @note if not present then compute is not executed */ - public double computeDoubleIfAbsent(float key, Float2DoubleFunction mappingFunction); + public double computeDoubleIfPresent(float key, FloatDoubleUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value + * @param mappingFunction the operator that should generate the value + * @return the result of the computation */ - public double computeDoubleIfAbsentNonDefault(float key, Float2DoubleFunction mappingFunction); + public double computeDoubleNonDefault(float key, FloatDoubleUnaryOperator mappingFunction); /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param valueProvider the value if not present + * @param mappingFunction the operator that should generate the value if not present * @return the result of the computed value or present value - */ - public double supplyDoubleIfAbsent(float key, DoubleSupplier valueProvider); + */ + public double computeDoubleIfAbsentNonDefault(float key, Float2DoubleFunction mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -353,16 +363,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public double supplyDoubleIfAbsentNonDefault(float key, DoubleSupplier valueProvider); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public double computeDoubleIfPresent(float key, FloatDoubleUnaryOperator mappingFunction); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/floats/maps/interfaces/Float2FloatMap.java b/src/main/java/speiger/src/collections/floats/maps/interfaces/Float2FloatMap.java index 0e6a403a..586ef314 100644 --- a/src/main/java/speiger/src/collections/floats/maps/interfaces/Float2FloatMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/interfaces/Float2FloatMap.java @@ -308,41 +308,51 @@ public default boolean remove(Object key, Object value) { */ public float computeFloat(float key, FloatFloatUnaryOperator mappingFunction); /** - * A Type Specific compute method to reduce boxing/unboxing + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation + * @param mappingFunction the operator that should generate the value if not present + * @return the result of the computed value or present value */ - public float computeFloatNonDefault(float key, FloatFloatUnaryOperator mappingFunction); + public float computeFloatIfAbsent(float key, FloatUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present + * @param valueProvider the value if not present * @return the result of the computed value or present value + */ + public float supplyFloatIfAbsent(float key, FloatSupplier valueProvider); + /** + * A Type Specific compute method to reduce boxing/unboxing + * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". + * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. + * @param key the key that should be computed + * @param mappingFunction the operator that should generate the value if present + * @return the result of the default return value or present value + * @note if not present then compute is not executed */ - public float computeFloatIfAbsent(float key, FloatUnaryOperator mappingFunction); + public float computeFloatIfPresent(float key, FloatFloatUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value + * @param mappingFunction the operator that should generate the value + * @return the result of the computation */ - public float computeFloatIfAbsentNonDefault(float key, FloatUnaryOperator mappingFunction); + public float computeFloatNonDefault(float key, FloatFloatUnaryOperator mappingFunction); /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param valueProvider the value if not present + * @param mappingFunction the operator that should generate the value if not present * @return the result of the computed value or present value - */ - public float supplyFloatIfAbsent(float key, FloatSupplier valueProvider); + */ + public float computeFloatIfAbsentNonDefault(float key, FloatUnaryOperator mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -352,16 +362,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public float supplyFloatIfAbsentNonDefault(float key, FloatSupplier valueProvider); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public float computeFloatIfPresent(float key, FloatFloatUnaryOperator mappingFunction); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/floats/maps/interfaces/Float2IntMap.java b/src/main/java/speiger/src/collections/floats/maps/interfaces/Float2IntMap.java index d762dc38..72393583 100644 --- a/src/main/java/speiger/src/collections/floats/maps/interfaces/Float2IntMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/interfaces/Float2IntMap.java @@ -309,41 +309,51 @@ public default boolean remove(Object key, Object value) { */ public int computeInt(float key, FloatIntUnaryOperator mappingFunction); /** - * A Type Specific compute method to reduce boxing/unboxing + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation + * @param mappingFunction the operator that should generate the value if not present + * @return the result of the computed value or present value */ - public int computeIntNonDefault(float key, FloatIntUnaryOperator mappingFunction); + public int computeIntIfAbsent(float key, Float2IntFunction mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present + * @param valueProvider the value if not present * @return the result of the computed value or present value + */ + public int supplyIntIfAbsent(float key, IntSupplier valueProvider); + /** + * A Type Specific compute method to reduce boxing/unboxing + * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". + * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. + * @param key the key that should be computed + * @param mappingFunction the operator that should generate the value if present + * @return the result of the default return value or present value + * @note if not present then compute is not executed */ - public int computeIntIfAbsent(float key, Float2IntFunction mappingFunction); + public int computeIntIfPresent(float key, FloatIntUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value + * @param mappingFunction the operator that should generate the value + * @return the result of the computation */ - public int computeIntIfAbsentNonDefault(float key, Float2IntFunction mappingFunction); + public int computeIntNonDefault(float key, FloatIntUnaryOperator mappingFunction); /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param valueProvider the value if not present + * @param mappingFunction the operator that should generate the value if not present * @return the result of the computed value or present value - */ - public int supplyIntIfAbsent(float key, IntSupplier valueProvider); + */ + public int computeIntIfAbsentNonDefault(float key, Float2IntFunction mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -353,16 +363,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public int supplyIntIfAbsentNonDefault(float key, IntSupplier valueProvider); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public int computeIntIfPresent(float key, FloatIntUnaryOperator mappingFunction); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/floats/maps/interfaces/Float2LongMap.java b/src/main/java/speiger/src/collections/floats/maps/interfaces/Float2LongMap.java index 0e81ae29..48042c98 100644 --- a/src/main/java/speiger/src/collections/floats/maps/interfaces/Float2LongMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/interfaces/Float2LongMap.java @@ -309,41 +309,51 @@ public default boolean remove(Object key, Object value) { */ public long computeLong(float key, FloatLongUnaryOperator mappingFunction); /** - * A Type Specific compute method to reduce boxing/unboxing + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation + * @param mappingFunction the operator that should generate the value if not present + * @return the result of the computed value or present value */ - public long computeLongNonDefault(float key, FloatLongUnaryOperator mappingFunction); + public long computeLongIfAbsent(float key, Float2LongFunction mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present + * @param valueProvider the value if not present * @return the result of the computed value or present value + */ + public long supplyLongIfAbsent(float key, LongSupplier valueProvider); + /** + * A Type Specific compute method to reduce boxing/unboxing + * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". + * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. + * @param key the key that should be computed + * @param mappingFunction the operator that should generate the value if present + * @return the result of the default return value or present value + * @note if not present then compute is not executed */ - public long computeLongIfAbsent(float key, Float2LongFunction mappingFunction); + public long computeLongIfPresent(float key, FloatLongUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value + * @param mappingFunction the operator that should generate the value + * @return the result of the computation */ - public long computeLongIfAbsentNonDefault(float key, Float2LongFunction mappingFunction); + public long computeLongNonDefault(float key, FloatLongUnaryOperator mappingFunction); /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param valueProvider the value if not present + * @param mappingFunction the operator that should generate the value if not present * @return the result of the computed value or present value - */ - public long supplyLongIfAbsent(float key, LongSupplier valueProvider); + */ + public long computeLongIfAbsentNonDefault(float key, Float2LongFunction mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -353,16 +363,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public long supplyLongIfAbsentNonDefault(float key, LongSupplier valueProvider); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public long computeLongIfPresent(float key, FloatLongUnaryOperator mappingFunction); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/floats/maps/interfaces/Float2ObjectMap.java b/src/main/java/speiger/src/collections/floats/maps/interfaces/Float2ObjectMap.java index 137c02f3..32063465 100644 --- a/src/main/java/speiger/src/collections/floats/maps/interfaces/Float2ObjectMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/interfaces/Float2ObjectMap.java @@ -266,15 +266,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computation */ public V compute(float key, FloatObjectUnaryOperator mappingFunction); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation - */ - public V computeNonDefault(float key, FloatObjectUnaryOperator mappingFunction); /** * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -284,15 +275,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public V computeIfAbsent(float key, FloatFunction mappingFunction); - /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value - */ - public V computeIfAbsentNonDefault(float key, FloatFunction mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -302,15 +284,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public V supplyIfAbsent(float key, ObjectSupplier valueProvider); - /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param valueProvider the value if not present - * @return the result of the computed value or present value - */ - public V supplyIfAbsentNonDefault(float key, ObjectSupplier valueProvider); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -321,16 +294,6 @@ public default boolean remove(Object key, Object value) { * @note if not present then compute is not executed */ public V computeIfPresent(float key, FloatObjectUnaryOperator mappingFunction); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public V computeIfPresentNonDefault(float key, FloatObjectUnaryOperator mappingFunction); /** * A Type Specific merge method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/floats/maps/interfaces/Float2ShortMap.java b/src/main/java/speiger/src/collections/floats/maps/interfaces/Float2ShortMap.java index f623b7d9..c6f8a047 100644 --- a/src/main/java/speiger/src/collections/floats/maps/interfaces/Float2ShortMap.java +++ b/src/main/java/speiger/src/collections/floats/maps/interfaces/Float2ShortMap.java @@ -309,41 +309,51 @@ public default boolean remove(Object key, Object value) { */ public short computeShort(float key, FloatShortUnaryOperator mappingFunction); /** - * A Type Specific compute method to reduce boxing/unboxing + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation + * @param mappingFunction the operator that should generate the value if not present + * @return the result of the computed value or present value */ - public short computeShortNonDefault(float key, FloatShortUnaryOperator mappingFunction); + public short computeShortIfAbsent(float key, Float2ShortFunction mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present + * @param valueProvider the value if not present * @return the result of the computed value or present value + */ + public short supplyShortIfAbsent(float key, ShortSupplier valueProvider); + /** + * A Type Specific compute method to reduce boxing/unboxing + * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". + * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. + * @param key the key that should be computed + * @param mappingFunction the operator that should generate the value if present + * @return the result of the default return value or present value + * @note if not present then compute is not executed */ - public short computeShortIfAbsent(float key, Float2ShortFunction mappingFunction); + public short computeShortIfPresent(float key, FloatShortUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value + * @param mappingFunction the operator that should generate the value + * @return the result of the computation */ - public short computeShortIfAbsentNonDefault(float key, Float2ShortFunction mappingFunction); + public short computeShortNonDefault(float key, FloatShortUnaryOperator mappingFunction); /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param valueProvider the value if not present + * @param mappingFunction the operator that should generate the value if not present * @return the result of the computed value or present value - */ - public short supplyShortIfAbsent(float key, ShortSupplier valueProvider); + */ + public short computeShortIfAbsentNonDefault(float key, Float2ShortFunction mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -353,16 +363,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public short supplyShortIfAbsentNonDefault(float key, ShortSupplier valueProvider); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public short computeShortIfPresent(float key, FloatShortUnaryOperator mappingFunction); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/floats/queues/FloatArrayFIFOQueue.java b/src/main/java/speiger/src/collections/floats/queues/FloatArrayFIFOQueue.java index b0410646..1cfb72d5 100644 --- a/src/main/java/speiger/src/collections/floats/queues/FloatArrayFIFOQueue.java +++ b/src/main/java/speiger/src/collections/floats/queues/FloatArrayFIFOQueue.java @@ -146,6 +146,15 @@ public float peek(int index) { return index >= array.length ? array[index-array.length] : array[index]; } + @Override + public boolean contains(float e) { + if(first == last) return false; + for(int i = 0,m=size();i iterator, int repea return new RepeatingIterator(wrap(iterator), repeats); } + /** + * A Helper function that creates a infinitely looping iterator + * @param iterator that should be looping infinitely + * @return a infinitely looping iterator + */ + public static FloatIterator infinite(FloatIterator iterator) { + return new InfiniteIterator(iterator); + } + + /** + * A Helper function that creates a infinitely looping iterator from a Java Iterator + * @param iterator that should be looping infinitely + * @return a infinitely looping iterator + */ + public static FloatIterator infinite(Iterator iterator) { + return new InfiniteIterator(wrap(iterator)); + } + /** * A Helper function that hard limits the Iterator to a specific size * @param iterator that should be limited @@ -841,6 +862,40 @@ public T next() { } } + private static class InfiniteIterator implements FloatIterator + { + FloatIterator iter; + CollectionWrapper looper = FloatCollections.wrapper(); + int index = 0; + + public InfiniteIterator(FloatIterator iter) { + this.iter = iter; + } + + @Override + public boolean hasNext() { + return true; + } + + @Override + public float nextFloat() { + if(iter != null) { + if(iter.hasNext()) { + float value = iter.nextFloat(); + looper.add(value); + return value; + } + else iter = null; + } + return looper.getFloat((index++) % looper.size()); + } + + @Override + public void forEachRemaining(FloatConsumer action) { throw new UnsupportedOperationException("This is a instant deadlock, so unsupported"); } + public void forEachRemaining(Consumer action) { throw new UnsupportedOperationException("This is a instant deadlock, so unsupported"); } + public void forEachRemaining(E input, ObjectFloatConsumer action) { throw new UnsupportedOperationException("This is a instant deadlock, so unsupported"); } + } + private static class RepeatingIterator implements FloatIterator { final int repeats; diff --git a/src/main/java/speiger/src/collections/floats/utils/FloatLists.java b/src/main/java/speiger/src/collections/floats/utils/FloatLists.java index 9ede2583..fad29f81 100644 --- a/src/main/java/speiger/src/collections/floats/utils/FloatLists.java +++ b/src/main/java/speiger/src/collections/floats/utils/FloatLists.java @@ -12,6 +12,7 @@ import speiger.src.collections.floats.functions.FloatConsumer; import speiger.src.collections.floats.lists.AbstractFloatList; import speiger.src.collections.floats.lists.FloatList; +import speiger.src.collections.ints.lists.IntList; import speiger.src.collections.floats.lists.FloatListIterator; import speiger.src.collections.utils.SanityChecks; @@ -317,6 +318,16 @@ public FloatListIterator listIterator(int index) { return l.listIterator(index); } + @Override + public FloatListIterator indexedIterator(int...indecies) { + return l.indexedIterator(indecies); + } + + @Override + public FloatListIterator indexedIterator(IntList indecies) { + return l.indexedIterator(indecies); + } + @Override public FloatList subList(int from, int to) { return FloatLists.synchronize(l.subList(from, to)); @@ -426,6 +437,16 @@ public FloatListIterator listIterator(int index) { return FloatIterators.unmodifiable(l.listIterator(index)); } + @Override + public FloatListIterator indexedIterator(int...indecies) { + return FloatIterators.unmodifiable(l.indexedIterator(indecies)); + } + + @Override + public FloatListIterator indexedIterator(IntList indecies) { + return FloatIterators.unmodifiable(l.indexedIterator(indecies)); + } + @Override public FloatList subList(int from, int to) { return FloatLists.unmodifiable(l.subList(from, to)); @@ -514,6 +535,16 @@ public FloatListIterator listIterator(int index) { return FloatIterators.empty(); } + @Override + public FloatListIterator indexedIterator(int...indecies) { + return FloatIterators.empty(); + } + + @Override + public FloatListIterator indexedIterator(IntList indecies) { + return FloatIterators.empty(); + } + @Override public int hashCode() { return 1; } diff --git a/src/main/java/speiger/src/collections/floats/utils/FloatPriorityQueues.java b/src/main/java/speiger/src/collections/floats/utils/FloatPriorityQueues.java index 8bf0629a..c47e06f3 100644 --- a/src/main/java/speiger/src/collections/floats/utils/FloatPriorityQueues.java +++ b/src/main/java/speiger/src/collections/floats/utils/FloatPriorityQueues.java @@ -89,6 +89,8 @@ protected SynchronizedPriorityQueue(FloatPriorityQueue queue, Object mutex) { @Override public float peek(int index) { synchronized(mutex) { return queue.peek(index); } } @Override + public boolean contains(float e) { synchronized(mutex) { return queue.contains(e); } } + @Override public boolean removeFirst(float e) { synchronized(mutex) { return queue.removeFirst(e); } } @Override public boolean removeLast(float e) { synchronized(mutex) { return queue.removeLast(e); } } diff --git a/src/main/java/speiger/src/collections/floats/utils/maps/Float2BooleanMaps.java b/src/main/java/speiger/src/collections/floats/utils/maps/Float2BooleanMaps.java index 52ec4718..e2fc89c1 100644 --- a/src/main/java/speiger/src/collections/floats/utils/maps/Float2BooleanMaps.java +++ b/src/main/java/speiger/src/collections/floats/utils/maps/Float2BooleanMaps.java @@ -246,18 +246,18 @@ public static class SingletonMap extends AbstractFloat2BooleanMap { @Override public boolean computeBoolean(float key, FloatBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanNonDefault(float key, FloatBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean computeBooleanIfAbsent(float key, FloatPredicate mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanIfAbsentNonDefault(float key, FloatPredicate mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean computeBooleanIfPresent(float key, FloatBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanIfPresentNonDefault(float key, FloatBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean supplyBooleanIfAbsent(float key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public boolean computeBooleanNonDefault(float key, FloatBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public boolean computeBooleanIfAbsentNonDefault(float key, FloatPredicate mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public boolean computeBooleanIfPresentNonDefault(float key, FloatBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public boolean supplyBooleanIfAbsentNonDefault(float key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public boolean mergeBoolean(float key, boolean value, BooleanBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -304,18 +304,18 @@ public static class EmptyMap extends AbstractFloat2BooleanMap { @Override public boolean computeBoolean(float key, FloatBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanNonDefault(float key, FloatBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean computeBooleanIfAbsent(float key, FloatPredicate mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanIfAbsentNonDefault(float key, FloatPredicate mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean computeBooleanIfPresent(float key, FloatBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanIfPresentNonDefault(float key, FloatBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean supplyBooleanIfAbsent(float key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public boolean computeBooleanNonDefault(float key, FloatBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public boolean computeBooleanIfAbsentNonDefault(float key, FloatPredicate mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public boolean computeBooleanIfPresentNonDefault(float key, FloatBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public boolean supplyBooleanIfAbsentNonDefault(float key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public boolean mergeBoolean(float key, boolean value, BooleanBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -535,18 +535,18 @@ public boolean get(float key) { @Override public boolean computeBoolean(float key, FloatBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanNonDefault(float key, FloatBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean computeBooleanIfAbsent(float key, FloatPredicate mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanIfAbsentNonDefault(float key, FloatPredicate mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean computeBooleanIfPresent(float key, FloatBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanIfPresentNonDefault(float key, FloatBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean supplyBooleanIfAbsent(float key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public boolean computeBooleanNonDefault(float key, FloatBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public boolean computeBooleanIfAbsentNonDefault(float key, FloatPredicate mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public boolean computeBooleanIfPresentNonDefault(float key, FloatBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public boolean supplyBooleanIfAbsentNonDefault(float key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public boolean mergeBoolean(float key, boolean value, BooleanBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -938,18 +938,18 @@ public AbstractFloat2BooleanMap setDefaultReturnValue(boolean v) { @Override public boolean computeBoolean(float key, FloatBooleanUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeBoolean(key, mappingFunction); } } @Override - public boolean computeBooleanNonDefault(float key, FloatBooleanUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeBooleanNonDefault(key, mappingFunction); } } - @Override public boolean computeBooleanIfAbsent(float key, FloatPredicate mappingFunction) { synchronized(mutex) { return map.computeBooleanIfAbsent(key, mappingFunction); } } @Override - public boolean computeBooleanIfAbsentNonDefault(float key, FloatPredicate mappingFunction) { synchronized(mutex) { return map.computeBooleanIfAbsentNonDefault(key, mappingFunction); } } - @Override public boolean computeBooleanIfPresent(float key, FloatBooleanUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeBooleanIfPresent(key, mappingFunction); } } @Override - public boolean computeBooleanIfPresentNonDefault(float key, FloatBooleanUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeBooleanIfPresentNonDefault(key, mappingFunction); } } - @Override public boolean supplyBooleanIfAbsent(float key, BooleanSupplier valueProvider) { synchronized(mutex) { return map.supplyBooleanIfAbsent(key, valueProvider); } } @Override + public boolean computeBooleanNonDefault(float key, FloatBooleanUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeBooleanNonDefault(key, mappingFunction); } } + @Override + public boolean computeBooleanIfAbsentNonDefault(float key, FloatPredicate mappingFunction) { synchronized(mutex) { return map.computeBooleanIfAbsentNonDefault(key, mappingFunction); } } + @Override + public boolean computeBooleanIfPresentNonDefault(float key, FloatBooleanUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeBooleanIfPresentNonDefault(key, mappingFunction); } } + @Override public boolean supplyBooleanIfAbsentNonDefault(float key, BooleanSupplier valueProvider) { synchronized(mutex) { return map.supplyBooleanIfAbsentNonDefault(key, valueProvider); } } @Override public boolean mergeBoolean(float key, boolean value, BooleanBooleanUnaryOperator mappingFunction) { synchronized(mutex) { return map.mergeBoolean(key, value, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/floats/utils/maps/Float2ByteMaps.java b/src/main/java/speiger/src/collections/floats/utils/maps/Float2ByteMaps.java index 5b46cf16..4bef7b83 100644 --- a/src/main/java/speiger/src/collections/floats/utils/maps/Float2ByteMaps.java +++ b/src/main/java/speiger/src/collections/floats/utils/maps/Float2ByteMaps.java @@ -250,18 +250,18 @@ public static class SingletonMap extends AbstractFloat2ByteMap { @Override public byte computeByte(float key, FloatByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteNonDefault(float key, FloatByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte computeByteIfAbsent(float key, Float2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteIfAbsentNonDefault(float key, Float2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte computeByteIfPresent(float key, FloatByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteIfPresentNonDefault(float key, FloatByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte supplyByteIfAbsent(float key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public byte computeByteNonDefault(float key, FloatByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public byte computeByteIfAbsentNonDefault(float key, Float2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public byte computeByteIfPresentNonDefault(float key, FloatByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public byte supplyByteIfAbsentNonDefault(float key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public byte mergeByte(float key, byte value, ByteByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -312,18 +312,18 @@ public static class EmptyMap extends AbstractFloat2ByteMap { @Override public byte computeByte(float key, FloatByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteNonDefault(float key, FloatByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte computeByteIfAbsent(float key, Float2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteIfAbsentNonDefault(float key, Float2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte computeByteIfPresent(float key, FloatByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteIfPresentNonDefault(float key, FloatByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte supplyByteIfAbsent(float key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public byte computeByteNonDefault(float key, FloatByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public byte computeByteIfAbsentNonDefault(float key, Float2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public byte computeByteIfPresentNonDefault(float key, FloatByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public byte supplyByteIfAbsentNonDefault(float key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public byte mergeByte(float key, byte value, ByteByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -547,18 +547,18 @@ public byte get(float key) { @Override public byte computeByte(float key, FloatByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteNonDefault(float key, FloatByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte computeByteIfAbsent(float key, Float2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteIfAbsentNonDefault(float key, Float2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte computeByteIfPresent(float key, FloatByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteIfPresentNonDefault(float key, FloatByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte supplyByteIfAbsent(float key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public byte computeByteNonDefault(float key, FloatByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public byte computeByteIfAbsentNonDefault(float key, Float2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public byte computeByteIfPresentNonDefault(float key, FloatByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public byte supplyByteIfAbsentNonDefault(float key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public byte mergeByte(float key, byte value, ByteByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -955,18 +955,18 @@ public AbstractFloat2ByteMap setDefaultReturnValue(byte v) { @Override public byte computeByte(float key, FloatByteUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeByte(key, mappingFunction); } } @Override - public byte computeByteNonDefault(float key, FloatByteUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeByteNonDefault(key, mappingFunction); } } - @Override public byte computeByteIfAbsent(float key, Float2ByteFunction mappingFunction) { synchronized(mutex) { return map.computeByteIfAbsent(key, mappingFunction); } } @Override - public byte computeByteIfAbsentNonDefault(float key, Float2ByteFunction mappingFunction) { synchronized(mutex) { return map.computeByteIfAbsentNonDefault(key, mappingFunction); } } - @Override public byte computeByteIfPresent(float key, FloatByteUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeByteIfPresent(key, mappingFunction); } } @Override - public byte computeByteIfPresentNonDefault(float key, FloatByteUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeByteIfPresentNonDefault(key, mappingFunction); } } - @Override public byte supplyByteIfAbsent(float key, ByteSupplier valueProvider) { synchronized(mutex) { return map.supplyByteIfAbsent(key, valueProvider); } } @Override + public byte computeByteNonDefault(float key, FloatByteUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeByteNonDefault(key, mappingFunction); } } + @Override + public byte computeByteIfAbsentNonDefault(float key, Float2ByteFunction mappingFunction) { synchronized(mutex) { return map.computeByteIfAbsentNonDefault(key, mappingFunction); } } + @Override + public byte computeByteIfPresentNonDefault(float key, FloatByteUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeByteIfPresentNonDefault(key, mappingFunction); } } + @Override public byte supplyByteIfAbsentNonDefault(float key, ByteSupplier valueProvider) { synchronized(mutex) { return map.supplyByteIfAbsentNonDefault(key, valueProvider); } } @Override public byte mergeByte(float key, byte value, ByteByteUnaryOperator mappingFunction) { synchronized(mutex) { return map.mergeByte(key, value, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/floats/utils/maps/Float2CharMaps.java b/src/main/java/speiger/src/collections/floats/utils/maps/Float2CharMaps.java index f92eca67..29c60ed6 100644 --- a/src/main/java/speiger/src/collections/floats/utils/maps/Float2CharMaps.java +++ b/src/main/java/speiger/src/collections/floats/utils/maps/Float2CharMaps.java @@ -250,18 +250,18 @@ public static class SingletonMap extends AbstractFloat2CharMap { @Override public char computeChar(float key, FloatCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharNonDefault(float key, FloatCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char computeCharIfAbsent(float key, Float2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharIfAbsentNonDefault(float key, Float2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char computeCharIfPresent(float key, FloatCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharIfPresentNonDefault(float key, FloatCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char supplyCharIfAbsent(float key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public char computeCharNonDefault(float key, FloatCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public char computeCharIfAbsentNonDefault(float key, Float2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public char computeCharIfPresentNonDefault(float key, FloatCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public char supplyCharIfAbsentNonDefault(float key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public char mergeChar(float key, char value, CharCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -312,18 +312,18 @@ public static class EmptyMap extends AbstractFloat2CharMap { @Override public char computeChar(float key, FloatCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharNonDefault(float key, FloatCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char computeCharIfAbsent(float key, Float2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharIfAbsentNonDefault(float key, Float2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char computeCharIfPresent(float key, FloatCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharIfPresentNonDefault(float key, FloatCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char supplyCharIfAbsent(float key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public char computeCharNonDefault(float key, FloatCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public char computeCharIfAbsentNonDefault(float key, Float2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public char computeCharIfPresentNonDefault(float key, FloatCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public char supplyCharIfAbsentNonDefault(float key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public char mergeChar(float key, char value, CharCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -547,18 +547,18 @@ public char get(float key) { @Override public char computeChar(float key, FloatCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharNonDefault(float key, FloatCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char computeCharIfAbsent(float key, Float2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharIfAbsentNonDefault(float key, Float2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char computeCharIfPresent(float key, FloatCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharIfPresentNonDefault(float key, FloatCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char supplyCharIfAbsent(float key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public char computeCharNonDefault(float key, FloatCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public char computeCharIfAbsentNonDefault(float key, Float2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public char computeCharIfPresentNonDefault(float key, FloatCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public char supplyCharIfAbsentNonDefault(float key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public char mergeChar(float key, char value, CharCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -955,18 +955,18 @@ public AbstractFloat2CharMap setDefaultReturnValue(char v) { @Override public char computeChar(float key, FloatCharUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeChar(key, mappingFunction); } } @Override - public char computeCharNonDefault(float key, FloatCharUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeCharNonDefault(key, mappingFunction); } } - @Override public char computeCharIfAbsent(float key, Float2CharFunction mappingFunction) { synchronized(mutex) { return map.computeCharIfAbsent(key, mappingFunction); } } @Override - public char computeCharIfAbsentNonDefault(float key, Float2CharFunction mappingFunction) { synchronized(mutex) { return map.computeCharIfAbsentNonDefault(key, mappingFunction); } } - @Override public char computeCharIfPresent(float key, FloatCharUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeCharIfPresent(key, mappingFunction); } } @Override - public char computeCharIfPresentNonDefault(float key, FloatCharUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeCharIfPresentNonDefault(key, mappingFunction); } } - @Override public char supplyCharIfAbsent(float key, CharSupplier valueProvider) { synchronized(mutex) { return map.supplyCharIfAbsent(key, valueProvider); } } @Override + public char computeCharNonDefault(float key, FloatCharUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeCharNonDefault(key, mappingFunction); } } + @Override + public char computeCharIfAbsentNonDefault(float key, Float2CharFunction mappingFunction) { synchronized(mutex) { return map.computeCharIfAbsentNonDefault(key, mappingFunction); } } + @Override + public char computeCharIfPresentNonDefault(float key, FloatCharUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeCharIfPresentNonDefault(key, mappingFunction); } } + @Override public char supplyCharIfAbsentNonDefault(float key, CharSupplier valueProvider) { synchronized(mutex) { return map.supplyCharIfAbsentNonDefault(key, valueProvider); } } @Override public char mergeChar(float key, char value, CharCharUnaryOperator mappingFunction) { synchronized(mutex) { return map.mergeChar(key, value, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/floats/utils/maps/Float2DoubleMaps.java b/src/main/java/speiger/src/collections/floats/utils/maps/Float2DoubleMaps.java index 4a3fe4b1..ccfec8eb 100644 --- a/src/main/java/speiger/src/collections/floats/utils/maps/Float2DoubleMaps.java +++ b/src/main/java/speiger/src/collections/floats/utils/maps/Float2DoubleMaps.java @@ -250,18 +250,18 @@ public static class SingletonMap extends AbstractFloat2DoubleMap { @Override public double computeDouble(float key, FloatDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleNonDefault(float key, FloatDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double computeDoubleIfAbsent(float key, Float2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleIfAbsentNonDefault(float key, Float2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double computeDoubleIfPresent(float key, FloatDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleIfPresentNonDefault(float key, FloatDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double supplyDoubleIfAbsent(float key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public double computeDoubleNonDefault(float key, FloatDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public double computeDoubleIfAbsentNonDefault(float key, Float2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public double computeDoubleIfPresentNonDefault(float key, FloatDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public double supplyDoubleIfAbsentNonDefault(float key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public double mergeDouble(float key, double value, DoubleDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -312,18 +312,18 @@ public static class EmptyMap extends AbstractFloat2DoubleMap { @Override public double computeDouble(float key, FloatDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleNonDefault(float key, FloatDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double computeDoubleIfAbsent(float key, Float2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleIfAbsentNonDefault(float key, Float2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double computeDoubleIfPresent(float key, FloatDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleIfPresentNonDefault(float key, FloatDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double supplyDoubleIfAbsent(float key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public double computeDoubleNonDefault(float key, FloatDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public double computeDoubleIfAbsentNonDefault(float key, Float2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public double computeDoubleIfPresentNonDefault(float key, FloatDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public double supplyDoubleIfAbsentNonDefault(float key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public double mergeDouble(float key, double value, DoubleDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -547,18 +547,18 @@ public double get(float key) { @Override public double computeDouble(float key, FloatDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleNonDefault(float key, FloatDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double computeDoubleIfAbsent(float key, Float2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleIfAbsentNonDefault(float key, Float2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double computeDoubleIfPresent(float key, FloatDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleIfPresentNonDefault(float key, FloatDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double supplyDoubleIfAbsent(float key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public double computeDoubleNonDefault(float key, FloatDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public double computeDoubleIfAbsentNonDefault(float key, Float2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public double computeDoubleIfPresentNonDefault(float key, FloatDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public double supplyDoubleIfAbsentNonDefault(float key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public double mergeDouble(float key, double value, DoubleDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -955,18 +955,18 @@ public AbstractFloat2DoubleMap setDefaultReturnValue(double v) { @Override public double computeDouble(float key, FloatDoubleUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeDouble(key, mappingFunction); } } @Override - public double computeDoubleNonDefault(float key, FloatDoubleUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeDoubleNonDefault(key, mappingFunction); } } - @Override public double computeDoubleIfAbsent(float key, Float2DoubleFunction mappingFunction) { synchronized(mutex) { return map.computeDoubleIfAbsent(key, mappingFunction); } } @Override - public double computeDoubleIfAbsentNonDefault(float key, Float2DoubleFunction mappingFunction) { synchronized(mutex) { return map.computeDoubleIfAbsentNonDefault(key, mappingFunction); } } - @Override public double computeDoubleIfPresent(float key, FloatDoubleUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeDoubleIfPresent(key, mappingFunction); } } @Override - public double computeDoubleIfPresentNonDefault(float key, FloatDoubleUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeDoubleIfPresentNonDefault(key, mappingFunction); } } - @Override public double supplyDoubleIfAbsent(float key, DoubleSupplier valueProvider) { synchronized(mutex) { return map.supplyDoubleIfAbsent(key, valueProvider); } } @Override + public double computeDoubleNonDefault(float key, FloatDoubleUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeDoubleNonDefault(key, mappingFunction); } } + @Override + public double computeDoubleIfAbsentNonDefault(float key, Float2DoubleFunction mappingFunction) { synchronized(mutex) { return map.computeDoubleIfAbsentNonDefault(key, mappingFunction); } } + @Override + public double computeDoubleIfPresentNonDefault(float key, FloatDoubleUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeDoubleIfPresentNonDefault(key, mappingFunction); } } + @Override public double supplyDoubleIfAbsentNonDefault(float key, DoubleSupplier valueProvider) { synchronized(mutex) { return map.supplyDoubleIfAbsentNonDefault(key, valueProvider); } } @Override public double mergeDouble(float key, double value, DoubleDoubleUnaryOperator mappingFunction) { synchronized(mutex) { return map.mergeDouble(key, value, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/floats/utils/maps/Float2FloatMaps.java b/src/main/java/speiger/src/collections/floats/utils/maps/Float2FloatMaps.java index 9125dda6..57de78cd 100644 --- a/src/main/java/speiger/src/collections/floats/utils/maps/Float2FloatMaps.java +++ b/src/main/java/speiger/src/collections/floats/utils/maps/Float2FloatMaps.java @@ -249,18 +249,18 @@ public static class SingletonMap extends AbstractFloat2FloatMap { @Override public float computeFloat(float key, FloatFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatNonDefault(float key, FloatFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float computeFloatIfAbsent(float key, FloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatIfAbsentNonDefault(float key, FloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float computeFloatIfPresent(float key, FloatFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatIfPresentNonDefault(float key, FloatFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float supplyFloatIfAbsent(float key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public float computeFloatNonDefault(float key, FloatFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public float computeFloatIfAbsentNonDefault(float key, FloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public float computeFloatIfPresentNonDefault(float key, FloatFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public float supplyFloatIfAbsentNonDefault(float key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public float mergeFloat(float key, float value, FloatFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -311,18 +311,18 @@ public static class EmptyMap extends AbstractFloat2FloatMap { @Override public float computeFloat(float key, FloatFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatNonDefault(float key, FloatFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float computeFloatIfAbsent(float key, FloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatIfAbsentNonDefault(float key, FloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float computeFloatIfPresent(float key, FloatFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatIfPresentNonDefault(float key, FloatFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float supplyFloatIfAbsent(float key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public float computeFloatNonDefault(float key, FloatFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public float computeFloatIfAbsentNonDefault(float key, FloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public float computeFloatIfPresentNonDefault(float key, FloatFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public float supplyFloatIfAbsentNonDefault(float key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public float mergeFloat(float key, float value, FloatFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -546,18 +546,18 @@ public float get(float key) { @Override public float computeFloat(float key, FloatFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatNonDefault(float key, FloatFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float computeFloatIfAbsent(float key, FloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatIfAbsentNonDefault(float key, FloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float computeFloatIfPresent(float key, FloatFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatIfPresentNonDefault(float key, FloatFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float supplyFloatIfAbsent(float key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public float computeFloatNonDefault(float key, FloatFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public float computeFloatIfAbsentNonDefault(float key, FloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public float computeFloatIfPresentNonDefault(float key, FloatFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public float supplyFloatIfAbsentNonDefault(float key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public float mergeFloat(float key, float value, FloatFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -954,18 +954,18 @@ public AbstractFloat2FloatMap setDefaultReturnValue(float v) { @Override public float computeFloat(float key, FloatFloatUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeFloat(key, mappingFunction); } } @Override - public float computeFloatNonDefault(float key, FloatFloatUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeFloatNonDefault(key, mappingFunction); } } - @Override public float computeFloatIfAbsent(float key, FloatUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeFloatIfAbsent(key, mappingFunction); } } @Override - public float computeFloatIfAbsentNonDefault(float key, FloatUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeFloatIfAbsentNonDefault(key, mappingFunction); } } - @Override public float computeFloatIfPresent(float key, FloatFloatUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeFloatIfPresent(key, mappingFunction); } } @Override - public float computeFloatIfPresentNonDefault(float key, FloatFloatUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeFloatIfPresentNonDefault(key, mappingFunction); } } - @Override public float supplyFloatIfAbsent(float key, FloatSupplier valueProvider) { synchronized(mutex) { return map.supplyFloatIfAbsent(key, valueProvider); } } @Override + public float computeFloatNonDefault(float key, FloatFloatUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeFloatNonDefault(key, mappingFunction); } } + @Override + public float computeFloatIfAbsentNonDefault(float key, FloatUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeFloatIfAbsentNonDefault(key, mappingFunction); } } + @Override + public float computeFloatIfPresentNonDefault(float key, FloatFloatUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeFloatIfPresentNonDefault(key, mappingFunction); } } + @Override public float supplyFloatIfAbsentNonDefault(float key, FloatSupplier valueProvider) { synchronized(mutex) { return map.supplyFloatIfAbsentNonDefault(key, valueProvider); } } @Override public float mergeFloat(float key, float value, FloatFloatUnaryOperator mappingFunction) { synchronized(mutex) { return map.mergeFloat(key, value, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/floats/utils/maps/Float2IntMaps.java b/src/main/java/speiger/src/collections/floats/utils/maps/Float2IntMaps.java index c6e388ab..bb198106 100644 --- a/src/main/java/speiger/src/collections/floats/utils/maps/Float2IntMaps.java +++ b/src/main/java/speiger/src/collections/floats/utils/maps/Float2IntMaps.java @@ -250,18 +250,18 @@ public static class SingletonMap extends AbstractFloat2IntMap { @Override public int computeInt(float key, FloatIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntNonDefault(float key, FloatIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int computeIntIfAbsent(float key, Float2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntIfAbsentNonDefault(float key, Float2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int computeIntIfPresent(float key, FloatIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntIfPresentNonDefault(float key, FloatIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int supplyIntIfAbsent(float key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public int computeIntNonDefault(float key, FloatIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public int computeIntIfAbsentNonDefault(float key, Float2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public int computeIntIfPresentNonDefault(float key, FloatIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public int supplyIntIfAbsentNonDefault(float key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public int mergeInt(float key, int value, IntIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -312,18 +312,18 @@ public static class EmptyMap extends AbstractFloat2IntMap { @Override public int computeInt(float key, FloatIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntNonDefault(float key, FloatIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int computeIntIfAbsent(float key, Float2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntIfAbsentNonDefault(float key, Float2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int computeIntIfPresent(float key, FloatIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntIfPresentNonDefault(float key, FloatIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int supplyIntIfAbsent(float key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public int computeIntNonDefault(float key, FloatIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public int computeIntIfAbsentNonDefault(float key, Float2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public int computeIntIfPresentNonDefault(float key, FloatIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public int supplyIntIfAbsentNonDefault(float key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public int mergeInt(float key, int value, IntIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -547,18 +547,18 @@ public int get(float key) { @Override public int computeInt(float key, FloatIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntNonDefault(float key, FloatIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int computeIntIfAbsent(float key, Float2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntIfAbsentNonDefault(float key, Float2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int computeIntIfPresent(float key, FloatIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntIfPresentNonDefault(float key, FloatIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int supplyIntIfAbsent(float key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public int computeIntNonDefault(float key, FloatIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public int computeIntIfAbsentNonDefault(float key, Float2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public int computeIntIfPresentNonDefault(float key, FloatIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public int supplyIntIfAbsentNonDefault(float key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public int mergeInt(float key, int value, IntIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -955,18 +955,18 @@ public AbstractFloat2IntMap setDefaultReturnValue(int v) { @Override public int computeInt(float key, FloatIntUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeInt(key, mappingFunction); } } @Override - public int computeIntNonDefault(float key, FloatIntUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeIntNonDefault(key, mappingFunction); } } - @Override public int computeIntIfAbsent(float key, Float2IntFunction mappingFunction) { synchronized(mutex) { return map.computeIntIfAbsent(key, mappingFunction); } } @Override - public int computeIntIfAbsentNonDefault(float key, Float2IntFunction mappingFunction) { synchronized(mutex) { return map.computeIntIfAbsentNonDefault(key, mappingFunction); } } - @Override public int computeIntIfPresent(float key, FloatIntUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeIntIfPresent(key, mappingFunction); } } @Override - public int computeIntIfPresentNonDefault(float key, FloatIntUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeIntIfPresentNonDefault(key, mappingFunction); } } - @Override public int supplyIntIfAbsent(float key, IntSupplier valueProvider) { synchronized(mutex) { return map.supplyIntIfAbsent(key, valueProvider); } } @Override + public int computeIntNonDefault(float key, FloatIntUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeIntNonDefault(key, mappingFunction); } } + @Override + public int computeIntIfAbsentNonDefault(float key, Float2IntFunction mappingFunction) { synchronized(mutex) { return map.computeIntIfAbsentNonDefault(key, mappingFunction); } } + @Override + public int computeIntIfPresentNonDefault(float key, FloatIntUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeIntIfPresentNonDefault(key, mappingFunction); } } + @Override public int supplyIntIfAbsentNonDefault(float key, IntSupplier valueProvider) { synchronized(mutex) { return map.supplyIntIfAbsentNonDefault(key, valueProvider); } } @Override public int mergeInt(float key, int value, IntIntUnaryOperator mappingFunction) { synchronized(mutex) { return map.mergeInt(key, value, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/floats/utils/maps/Float2LongMaps.java b/src/main/java/speiger/src/collections/floats/utils/maps/Float2LongMaps.java index 90b59d61..32400c32 100644 --- a/src/main/java/speiger/src/collections/floats/utils/maps/Float2LongMaps.java +++ b/src/main/java/speiger/src/collections/floats/utils/maps/Float2LongMaps.java @@ -250,18 +250,18 @@ public static class SingletonMap extends AbstractFloat2LongMap { @Override public long computeLong(float key, FloatLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongNonDefault(float key, FloatLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long computeLongIfAbsent(float key, Float2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongIfAbsentNonDefault(float key, Float2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long computeLongIfPresent(float key, FloatLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongIfPresentNonDefault(float key, FloatLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long supplyLongIfAbsent(float key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public long computeLongNonDefault(float key, FloatLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public long computeLongIfAbsentNonDefault(float key, Float2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public long computeLongIfPresentNonDefault(float key, FloatLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public long supplyLongIfAbsentNonDefault(float key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public long mergeLong(float key, long value, LongLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -312,18 +312,18 @@ public static class EmptyMap extends AbstractFloat2LongMap { @Override public long computeLong(float key, FloatLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongNonDefault(float key, FloatLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long computeLongIfAbsent(float key, Float2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongIfAbsentNonDefault(float key, Float2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long computeLongIfPresent(float key, FloatLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongIfPresentNonDefault(float key, FloatLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long supplyLongIfAbsent(float key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public long computeLongNonDefault(float key, FloatLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public long computeLongIfAbsentNonDefault(float key, Float2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public long computeLongIfPresentNonDefault(float key, FloatLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public long supplyLongIfAbsentNonDefault(float key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public long mergeLong(float key, long value, LongLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -547,18 +547,18 @@ public long get(float key) { @Override public long computeLong(float key, FloatLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongNonDefault(float key, FloatLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long computeLongIfAbsent(float key, Float2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongIfAbsentNonDefault(float key, Float2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long computeLongIfPresent(float key, FloatLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongIfPresentNonDefault(float key, FloatLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long supplyLongIfAbsent(float key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public long computeLongNonDefault(float key, FloatLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public long computeLongIfAbsentNonDefault(float key, Float2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public long computeLongIfPresentNonDefault(float key, FloatLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public long supplyLongIfAbsentNonDefault(float key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public long mergeLong(float key, long value, LongLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -955,18 +955,18 @@ public AbstractFloat2LongMap setDefaultReturnValue(long v) { @Override public long computeLong(float key, FloatLongUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeLong(key, mappingFunction); } } @Override - public long computeLongNonDefault(float key, FloatLongUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeLongNonDefault(key, mappingFunction); } } - @Override public long computeLongIfAbsent(float key, Float2LongFunction mappingFunction) { synchronized(mutex) { return map.computeLongIfAbsent(key, mappingFunction); } } @Override - public long computeLongIfAbsentNonDefault(float key, Float2LongFunction mappingFunction) { synchronized(mutex) { return map.computeLongIfAbsentNonDefault(key, mappingFunction); } } - @Override public long computeLongIfPresent(float key, FloatLongUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeLongIfPresent(key, mappingFunction); } } @Override - public long computeLongIfPresentNonDefault(float key, FloatLongUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeLongIfPresentNonDefault(key, mappingFunction); } } - @Override public long supplyLongIfAbsent(float key, LongSupplier valueProvider) { synchronized(mutex) { return map.supplyLongIfAbsent(key, valueProvider); } } @Override + public long computeLongNonDefault(float key, FloatLongUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeLongNonDefault(key, mappingFunction); } } + @Override + public long computeLongIfAbsentNonDefault(float key, Float2LongFunction mappingFunction) { synchronized(mutex) { return map.computeLongIfAbsentNonDefault(key, mappingFunction); } } + @Override + public long computeLongIfPresentNonDefault(float key, FloatLongUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeLongIfPresentNonDefault(key, mappingFunction); } } + @Override public long supplyLongIfAbsentNonDefault(float key, LongSupplier valueProvider) { synchronized(mutex) { return map.supplyLongIfAbsentNonDefault(key, valueProvider); } } @Override public long mergeLong(float key, long value, LongLongUnaryOperator mappingFunction) { synchronized(mutex) { return map.mergeLong(key, value, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/floats/utils/maps/Float2ObjectMaps.java b/src/main/java/speiger/src/collections/floats/utils/maps/Float2ObjectMaps.java index 7f8dcc07..fc05b5a2 100644 --- a/src/main/java/speiger/src/collections/floats/utils/maps/Float2ObjectMaps.java +++ b/src/main/java/speiger/src/collections/floats/utils/maps/Float2ObjectMaps.java @@ -266,20 +266,12 @@ public static class SingletonMap extends AbstractFloat2ObjectMap { @Override public V compute(float key, FloatObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeNonDefault(float key, FloatObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V computeIfAbsent(float key, FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeIfAbsentNonDefault(float key, FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V computeIfPresent(float key, FloatObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeIfPresentNonDefault(float key, FloatObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V supplyIfAbsent(float key, ObjectSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public V supplyIfAbsentNonDefault(float key, ObjectSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public V merge(float key, V value, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override public void mergeAll(Float2ObjectMap m, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -325,20 +317,12 @@ public static class EmptyMap extends AbstractFloat2ObjectMap { @Override public V compute(float key, FloatObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeNonDefault(float key, FloatObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V computeIfAbsent(float key, FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeIfAbsentNonDefault(float key, FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V computeIfPresent(float key, FloatObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeIfPresentNonDefault(float key, FloatObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V supplyIfAbsent(float key, ObjectSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public V supplyIfAbsentNonDefault(float key, ObjectSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public V merge(float key, V value, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override public void mergeAll(Float2ObjectMap m, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -561,20 +545,12 @@ public V get(float key) { @Override public V compute(float key, FloatObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeNonDefault(float key, FloatObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V computeIfAbsent(float key, FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeIfAbsentNonDefault(float key, FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V computeIfPresent(float key, FloatObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeIfPresentNonDefault(float key, FloatObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V supplyIfAbsent(float key, ObjectSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public V supplyIfAbsentNonDefault(float key, ObjectSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public V merge(float key, V value, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override public void mergeAll(Float2ObjectMap m, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -968,20 +944,12 @@ public AbstractFloat2ObjectMap setDefaultReturnValue(V v) { @Override public V compute(float key, FloatObjectUnaryOperator mappingFunction) { synchronized(mutex) { return map.compute(key, mappingFunction); } } @Override - public V computeNonDefault(float key, FloatObjectUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeNonDefault(key, mappingFunction); } } - @Override public V computeIfAbsent(float key, FloatFunction mappingFunction) { synchronized(mutex) { return map.computeIfAbsent(key, mappingFunction); } } @Override - public V computeIfAbsentNonDefault(float key, FloatFunction mappingFunction) { synchronized(mutex) { return map.computeIfAbsentNonDefault(key, mappingFunction); } } - @Override public V computeIfPresent(float key, FloatObjectUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeIfPresent(key, mappingFunction); } } @Override - public V computeIfPresentNonDefault(float key, FloatObjectUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeIfPresentNonDefault(key, mappingFunction); } } - @Override public V supplyIfAbsent(float key, ObjectSupplier valueProvider) { synchronized(mutex) { return map.supplyIfAbsent(key, valueProvider); } } @Override - public V supplyIfAbsentNonDefault(float key, ObjectSupplier valueProvider) { synchronized(mutex) { return map.supplyIfAbsentNonDefault(key, valueProvider); } } - @Override public V merge(float key, V value, ObjectObjectUnaryOperator mappingFunction) { synchronized(mutex) { return map.merge(key, value, mappingFunction); } } @Override public void mergeAll(Float2ObjectMap m, ObjectObjectUnaryOperator mappingFunction) { synchronized(mutex) { map.mergeAll(m, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/floats/utils/maps/Float2ShortMaps.java b/src/main/java/speiger/src/collections/floats/utils/maps/Float2ShortMaps.java index 9fd0d8b1..18ed15f6 100644 --- a/src/main/java/speiger/src/collections/floats/utils/maps/Float2ShortMaps.java +++ b/src/main/java/speiger/src/collections/floats/utils/maps/Float2ShortMaps.java @@ -250,18 +250,18 @@ public static class SingletonMap extends AbstractFloat2ShortMap { @Override public short computeShort(float key, FloatShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortNonDefault(float key, FloatShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short computeShortIfAbsent(float key, Float2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortIfAbsentNonDefault(float key, Float2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short computeShortIfPresent(float key, FloatShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortIfPresentNonDefault(float key, FloatShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short supplyShortIfAbsent(float key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public short computeShortNonDefault(float key, FloatShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public short computeShortIfAbsentNonDefault(float key, Float2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public short computeShortIfPresentNonDefault(float key, FloatShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public short supplyShortIfAbsentNonDefault(float key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public short mergeShort(float key, short value, ShortShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -312,18 +312,18 @@ public static class EmptyMap extends AbstractFloat2ShortMap { @Override public short computeShort(float key, FloatShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortNonDefault(float key, FloatShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short computeShortIfAbsent(float key, Float2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortIfAbsentNonDefault(float key, Float2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short computeShortIfPresent(float key, FloatShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortIfPresentNonDefault(float key, FloatShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short supplyShortIfAbsent(float key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public short computeShortNonDefault(float key, FloatShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public short computeShortIfAbsentNonDefault(float key, Float2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public short computeShortIfPresentNonDefault(float key, FloatShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public short supplyShortIfAbsentNonDefault(float key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public short mergeShort(float key, short value, ShortShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -547,18 +547,18 @@ public short get(float key) { @Override public short computeShort(float key, FloatShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortNonDefault(float key, FloatShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short computeShortIfAbsent(float key, Float2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortIfAbsentNonDefault(float key, Float2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short computeShortIfPresent(float key, FloatShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortIfPresentNonDefault(float key, FloatShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short supplyShortIfAbsent(float key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public short computeShortNonDefault(float key, FloatShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public short computeShortIfAbsentNonDefault(float key, Float2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public short computeShortIfPresentNonDefault(float key, FloatShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public short supplyShortIfAbsentNonDefault(float key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public short mergeShort(float key, short value, ShortShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -955,18 +955,18 @@ public AbstractFloat2ShortMap setDefaultReturnValue(short v) { @Override public short computeShort(float key, FloatShortUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeShort(key, mappingFunction); } } @Override - public short computeShortNonDefault(float key, FloatShortUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeShortNonDefault(key, mappingFunction); } } - @Override public short computeShortIfAbsent(float key, Float2ShortFunction mappingFunction) { synchronized(mutex) { return map.computeShortIfAbsent(key, mappingFunction); } } @Override - public short computeShortIfAbsentNonDefault(float key, Float2ShortFunction mappingFunction) { synchronized(mutex) { return map.computeShortIfAbsentNonDefault(key, mappingFunction); } } - @Override public short computeShortIfPresent(float key, FloatShortUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeShortIfPresent(key, mappingFunction); } } @Override - public short computeShortIfPresentNonDefault(float key, FloatShortUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeShortIfPresentNonDefault(key, mappingFunction); } } - @Override public short supplyShortIfAbsent(float key, ShortSupplier valueProvider) { synchronized(mutex) { return map.supplyShortIfAbsent(key, valueProvider); } } @Override + public short computeShortNonDefault(float key, FloatShortUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeShortNonDefault(key, mappingFunction); } } + @Override + public short computeShortIfAbsentNonDefault(float key, Float2ShortFunction mappingFunction) { synchronized(mutex) { return map.computeShortIfAbsentNonDefault(key, mappingFunction); } } + @Override + public short computeShortIfPresentNonDefault(float key, FloatShortUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeShortIfPresentNonDefault(key, mappingFunction); } } + @Override public short supplyShortIfAbsentNonDefault(float key, ShortSupplier valueProvider) { synchronized(mutex) { return map.supplyShortIfAbsentNonDefault(key, valueProvider); } } @Override public short mergeShort(float key, short value, ShortShortUnaryOperator mappingFunction) { synchronized(mutex) { return map.mergeShort(key, value, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/ints/lists/AbstractIntList.java b/src/main/java/speiger/src/collections/ints/lists/AbstractIntList.java index 0c9e8aee..e3fbfec4 100644 --- a/src/main/java/speiger/src/collections/ints/lists/AbstractIntList.java +++ b/src/main/java/speiger/src/collections/ints/lists/AbstractIntList.java @@ -205,13 +205,23 @@ public IntIterator iterator() { public IntListIterator listIterator() { return listIterator(0); } - + @Override public IntListIterator listIterator(int index) { if(index < 0 || index > size()) throw new IndexOutOfBoundsException(); return new IntListIter(index); } + @Override + public IntListIterator indexedIterator(int...indecies) { + return new IndexedIterator(indecies); + } + + @Override + public IntListIterator indexedIterator(IntList indecies) { + return new ListIndexedIterator(indecies); + } + @Override public void size(int size) { while(size > size()) add(0); @@ -566,7 +576,153 @@ public int back(int amount) { } } } + + private class ListIndexedIterator implements IntListIterator { + IntList indecies; + int index; + int lastReturned = -1; + + ListIndexedIterator(IntList indecies) { + this.indecies = indecies; + } + + @Override + public boolean hasNext() { + return index < indecies.size(); + } + + @Override + public int nextInt() { + if(!hasNext()) throw new NoSuchElementException(); + int i = index++; + return getInt((lastReturned = indecies.getInt(i))); + } + + @Override + public boolean hasPrevious() { + return index > 0; + } + + @Override + public int previousInt() { + if(!hasPrevious()) throw new NoSuchElementException(); + index--; + return getInt((lastReturned = indecies.getInt(index))); + } + + @Override + public int nextIndex() { + return index; + } + + @Override + public int previousIndex() { + return index-1; + } + + @Override + public void remove() { throw new UnsupportedOperationException(); } + @Override + public void add(int e) { throw new UnsupportedOperationException(); } + + @Override + public void set(int e) { + if(lastReturned == -1) throw new IllegalStateException(); + AbstractIntList.this.set(lastReturned, e); + } + + @Override + public int skip(int amount) { + if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed"); + int steps = Math.min(amount, indecies.size() - index); + index += steps; + if(steps > 0) lastReturned = Math.min(index-1, indecies.size()-1); + return steps; + } + + @Override + public int back(int amount) { + if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed"); + int steps = Math.min(amount, index); + index -= steps; + if(steps > 0) lastReturned = Math.max(index, 0); + return steps; + } + } + + private class IndexedIterator implements IntListIterator { + int[] indecies; + int index; + int lastReturned = -1; + + IndexedIterator(int[] indecies) { + this.indecies = indecies; + } + @Override + public boolean hasNext() { + return index < indecies.length; + } + + @Override + public int nextInt() { + if(!hasNext()) throw new NoSuchElementException(); + int i = index++; + return getInt((lastReturned = indecies[i])); + } + + @Override + public boolean hasPrevious() { + return index > 0; + } + + @Override + public int previousInt() { + if(!hasPrevious()) throw new NoSuchElementException(); + index--; + return getInt((lastReturned = indecies[index])); + } + + @Override + public int nextIndex() { + return index; + } + + @Override + public int previousIndex() { + return index-1; + } + + @Override + public void remove() { throw new UnsupportedOperationException(); } + @Override + public void add(int e) { throw new UnsupportedOperationException(); } + + @Override + public void set(int e) { + if(lastReturned == -1) throw new IllegalStateException(); + AbstractIntList.this.set(lastReturned, e); + } + + @Override + public int skip(int amount) { + if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed"); + int steps = Math.min(amount, indecies.length - index); + index += steps; + if(steps > 0) lastReturned = Math.min(index-1, indecies.length-1); + return steps; + } + + @Override + public int back(int amount) { + if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed"); + int steps = Math.min(amount, index); + index -= steps; + if(steps > 0) lastReturned = Math.max(index, 0); + return steps; + } + } + private class IntListIter implements IntListIterator { int index; int lastReturned = -1; @@ -644,7 +800,7 @@ public int back(int amount) { if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed"); int steps = Math.min(amount, index); index -= steps; - if(steps > 0) lastReturned = Math.min(index, size()-1); + if(steps > 0) lastReturned = Math.max(index, 0); return steps; } } diff --git a/src/main/java/speiger/src/collections/ints/lists/IntList.java b/src/main/java/speiger/src/collections/ints/lists/IntList.java index 8539d472..679ebfad 100644 --- a/src/main/java/speiger/src/collections/ints/lists/IntList.java +++ b/src/main/java/speiger/src/collections/ints/lists/IntList.java @@ -341,6 +341,24 @@ public default void forEachIndexed(IntIntConsumer action) { @Override public IntListIterator listIterator(int index); + /** + * Creates a Iterator that follows the indecies provided.
+ * For example if the Lists Contents is:
-1, 0 1
and the indecies are:
0, 1, 2, 2, 1, 0
+ * then the iterator will return the following values:
-1, 0, 1, 1, 0, -1 + * @param indecies that should be used for the iteration. + * @return a custom indexed iterator + */ + public IntListIterator indexedIterator(int...indecies); + + /** + * Creates a Iterator that follows the indecies provided.
+ * For example if the Lists Contents is:
-1, 0 1
and the indecies are:
0, 1, 2, 2, 1, 0
+ * then the iterator will return the following values:
-1, 0, 1, 1, 0, -1 + * @param indecies that should be used for the iteration. + * @return a custom indexed iterator + */ + public IntListIterator indexedIterator(IntList indecies); + /** * A Type-Specific List of subList * @see java.util.List#subList(int, int) diff --git a/src/main/java/speiger/src/collections/ints/maps/abstracts/AbstractInt2BooleanMap.java b/src/main/java/speiger/src/collections/ints/maps/abstracts/AbstractInt2BooleanMap.java index d973bbce..8bacde0a 100644 --- a/src/main/java/speiger/src/collections/ints/maps/abstracts/AbstractInt2BooleanMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/abstracts/AbstractInt2BooleanMap.java @@ -151,6 +151,39 @@ public boolean computeBoolean(int key, IntBooleanUnaryOperator mappingFunction) return newValue; } + @Override + public boolean computeBooleanIfAbsent(int key, IntPredicate mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(!containsKey(key)) { + boolean newValue = mappingFunction.test(key); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public boolean supplyBooleanIfAbsent(int key, BooleanSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + if(!containsKey(key)) { + boolean newValue = valueProvider.getAsBoolean(); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public boolean computeBooleanIfPresent(int key, IntBooleanUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(containsKey(key)) { + boolean newValue = mappingFunction.applyAsBoolean(key, get(key)); + put(key, newValue); + return newValue; + } + return getDefaultReturnValue(); + } + @Override public boolean computeBooleanNonDefault(int key, IntBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -167,17 +200,6 @@ public boolean computeBooleanNonDefault(int key, IntBooleanUnaryOperator mapping return newValue; } - @Override - public boolean computeBooleanIfAbsent(int key, IntPredicate mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(!containsKey(key)) { - boolean newValue = mappingFunction.test(key); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public boolean computeBooleanIfAbsentNonDefault(int key, IntPredicate mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -192,17 +214,6 @@ public boolean computeBooleanIfAbsentNonDefault(int key, IntPredicate mappingFun return value; } - @Override - public boolean supplyBooleanIfAbsent(int key, BooleanSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - if(!containsKey(key)) { - boolean newValue = valueProvider.getAsBoolean(); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public boolean supplyBooleanIfAbsentNonDefault(int key, BooleanSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -217,17 +228,6 @@ public boolean supplyBooleanIfAbsentNonDefault(int key, BooleanSupplier valuePro return value; } - @Override - public boolean computeBooleanIfPresent(int key, IntBooleanUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(containsKey(key)) { - boolean newValue = mappingFunction.applyAsBoolean(key, get(key)); - put(key, newValue); - return newValue; - } - return getDefaultReturnValue(); - } - @Override public boolean computeBooleanIfPresentNonDefault(int key, IntBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/ints/maps/abstracts/AbstractInt2ByteMap.java b/src/main/java/speiger/src/collections/ints/maps/abstracts/AbstractInt2ByteMap.java index 6a44698a..d872799d 100644 --- a/src/main/java/speiger/src/collections/ints/maps/abstracts/AbstractInt2ByteMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/abstracts/AbstractInt2ByteMap.java @@ -157,6 +157,39 @@ public byte computeByte(int key, IntByteUnaryOperator mappingFunction) { return newValue; } + @Override + public byte computeByteIfAbsent(int key, Int2ByteFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(!containsKey(key)) { + byte newValue = mappingFunction.applyAsByte(key); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public byte supplyByteIfAbsent(int key, ByteSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + if(!containsKey(key)) { + byte newValue = valueProvider.getAsByte(); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public byte computeByteIfPresent(int key, IntByteUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(containsKey(key)) { + byte newValue = mappingFunction.applyAsByte(key, get(key)); + put(key, newValue); + return newValue; + } + return getDefaultReturnValue(); + } + @Override public byte computeByteNonDefault(int key, IntByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -173,17 +206,6 @@ public byte computeByteNonDefault(int key, IntByteUnaryOperator mappingFunction) return newValue; } - @Override - public byte computeByteIfAbsent(int key, Int2ByteFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(!containsKey(key)) { - byte newValue = mappingFunction.applyAsByte(key); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public byte computeByteIfAbsentNonDefault(int key, Int2ByteFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -198,23 +220,12 @@ public byte computeByteIfAbsentNonDefault(int key, Int2ByteFunction mappingFunct return value; } - @Override - public byte supplyByteIfAbsent(int key, ByteSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - if(!containsKey(key)) { - byte newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public byte supplyByteIfAbsentNonDefault(int key, ByteSupplier valueProvider) { Objects.requireNonNull(valueProvider); byte value; if((value = get(key)) == getDefaultReturnValue() || !containsKey(key)) { - byte newValue = valueProvider.getAsInt(); + byte newValue = valueProvider.getAsByte(); if(newValue != getDefaultReturnValue()) { put(key, newValue); return newValue; @@ -223,17 +234,6 @@ public byte supplyByteIfAbsentNonDefault(int key, ByteSupplier valueProvider) { return value; } - @Override - public byte computeByteIfPresent(int key, IntByteUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(containsKey(key)) { - byte newValue = mappingFunction.applyAsByte(key, get(key)); - put(key, newValue); - return newValue; - } - return getDefaultReturnValue(); - } - @Override public byte computeByteIfPresentNonDefault(int key, IntByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/ints/maps/abstracts/AbstractInt2CharMap.java b/src/main/java/speiger/src/collections/ints/maps/abstracts/AbstractInt2CharMap.java index 5cf14b69..7924b561 100644 --- a/src/main/java/speiger/src/collections/ints/maps/abstracts/AbstractInt2CharMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/abstracts/AbstractInt2CharMap.java @@ -157,6 +157,39 @@ public char computeChar(int key, IntCharUnaryOperator mappingFunction) { return newValue; } + @Override + public char computeCharIfAbsent(int key, Int2CharFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(!containsKey(key)) { + char newValue = mappingFunction.applyAsChar(key); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public char supplyCharIfAbsent(int key, CharSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + if(!containsKey(key)) { + char newValue = valueProvider.getAsChar(); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public char computeCharIfPresent(int key, IntCharUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(containsKey(key)) { + char newValue = mappingFunction.applyAsChar(key, get(key)); + put(key, newValue); + return newValue; + } + return getDefaultReturnValue(); + } + @Override public char computeCharNonDefault(int key, IntCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -173,17 +206,6 @@ public char computeCharNonDefault(int key, IntCharUnaryOperator mappingFunction) return newValue; } - @Override - public char computeCharIfAbsent(int key, Int2CharFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(!containsKey(key)) { - char newValue = mappingFunction.applyAsChar(key); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public char computeCharIfAbsentNonDefault(int key, Int2CharFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -198,23 +220,12 @@ public char computeCharIfAbsentNonDefault(int key, Int2CharFunction mappingFunct return value; } - @Override - public char supplyCharIfAbsent(int key, CharSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - if(!containsKey(key)) { - char newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public char supplyCharIfAbsentNonDefault(int key, CharSupplier valueProvider) { Objects.requireNonNull(valueProvider); char value; if((value = get(key)) == getDefaultReturnValue() || !containsKey(key)) { - char newValue = valueProvider.getAsInt(); + char newValue = valueProvider.getAsChar(); if(newValue != getDefaultReturnValue()) { put(key, newValue); return newValue; @@ -223,17 +234,6 @@ public char supplyCharIfAbsentNonDefault(int key, CharSupplier valueProvider) { return value; } - @Override - public char computeCharIfPresent(int key, IntCharUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(containsKey(key)) { - char newValue = mappingFunction.applyAsChar(key, get(key)); - put(key, newValue); - return newValue; - } - return getDefaultReturnValue(); - } - @Override public char computeCharIfPresentNonDefault(int key, IntCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/ints/maps/abstracts/AbstractInt2DoubleMap.java b/src/main/java/speiger/src/collections/ints/maps/abstracts/AbstractInt2DoubleMap.java index a0a7d4fc..3f044b90 100644 --- a/src/main/java/speiger/src/collections/ints/maps/abstracts/AbstractInt2DoubleMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/abstracts/AbstractInt2DoubleMap.java @@ -157,6 +157,39 @@ public double computeDouble(int key, IntDoubleUnaryOperator mappingFunction) { return newValue; } + @Override + public double computeDoubleIfAbsent(int key, Int2DoubleFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(!containsKey(key)) { + double newValue = mappingFunction.applyAsDouble(key); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public double supplyDoubleIfAbsent(int key, DoubleSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + if(!containsKey(key)) { + double newValue = valueProvider.getAsDouble(); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public double computeDoubleIfPresent(int key, IntDoubleUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(containsKey(key)) { + double newValue = mappingFunction.applyAsDouble(key, get(key)); + put(key, newValue); + return newValue; + } + return getDefaultReturnValue(); + } + @Override public double computeDoubleNonDefault(int key, IntDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -173,17 +206,6 @@ public double computeDoubleNonDefault(int key, IntDoubleUnaryOperator mappingFun return newValue; } - @Override - public double computeDoubleIfAbsent(int key, Int2DoubleFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(!containsKey(key)) { - double newValue = mappingFunction.applyAsDouble(key); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public double computeDoubleIfAbsentNonDefault(int key, Int2DoubleFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -198,17 +220,6 @@ public double computeDoubleIfAbsentNonDefault(int key, Int2DoubleFunction mappin return value; } - @Override - public double supplyDoubleIfAbsent(int key, DoubleSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - if(!containsKey(key)) { - double newValue = valueProvider.getAsDouble(); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public double supplyDoubleIfAbsentNonDefault(int key, DoubleSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -223,17 +234,6 @@ public double supplyDoubleIfAbsentNonDefault(int key, DoubleSupplier valueProvid return value; } - @Override - public double computeDoubleIfPresent(int key, IntDoubleUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(containsKey(key)) { - double newValue = mappingFunction.applyAsDouble(key, get(key)); - put(key, newValue); - return newValue; - } - return getDefaultReturnValue(); - } - @Override public double computeDoubleIfPresentNonDefault(int key, IntDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/ints/maps/abstracts/AbstractInt2FloatMap.java b/src/main/java/speiger/src/collections/ints/maps/abstracts/AbstractInt2FloatMap.java index bdb684f4..cbe8cec4 100644 --- a/src/main/java/speiger/src/collections/ints/maps/abstracts/AbstractInt2FloatMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/abstracts/AbstractInt2FloatMap.java @@ -157,6 +157,39 @@ public float computeFloat(int key, IntFloatUnaryOperator mappingFunction) { return newValue; } + @Override + public float computeFloatIfAbsent(int key, Int2FloatFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(!containsKey(key)) { + float newValue = mappingFunction.applyAsFloat(key); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public float supplyFloatIfAbsent(int key, FloatSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + if(!containsKey(key)) { + float newValue = valueProvider.getAsFloat(); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public float computeFloatIfPresent(int key, IntFloatUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(containsKey(key)) { + float newValue = mappingFunction.applyAsFloat(key, get(key)); + put(key, newValue); + return newValue; + } + return getDefaultReturnValue(); + } + @Override public float computeFloatNonDefault(int key, IntFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -173,17 +206,6 @@ public float computeFloatNonDefault(int key, IntFloatUnaryOperator mappingFuncti return newValue; } - @Override - public float computeFloatIfAbsent(int key, Int2FloatFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(!containsKey(key)) { - float newValue = mappingFunction.applyAsFloat(key); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public float computeFloatIfAbsentNonDefault(int key, Int2FloatFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -198,23 +220,12 @@ public float computeFloatIfAbsentNonDefault(int key, Int2FloatFunction mappingFu return value; } - @Override - public float supplyFloatIfAbsent(int key, FloatSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - if(!containsKey(key)) { - float newValue = valueProvider.getAsDouble(); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public float supplyFloatIfAbsentNonDefault(int key, FloatSupplier valueProvider) { Objects.requireNonNull(valueProvider); float value; if((value = get(key)) == getDefaultReturnValue() || !containsKey(key)) { - float newValue = valueProvider.getAsDouble(); + float newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) != Float.floatToIntBits(getDefaultReturnValue())) { put(key, newValue); return newValue; @@ -223,17 +234,6 @@ public float supplyFloatIfAbsentNonDefault(int key, FloatSupplier valueProvider) return value; } - @Override - public float computeFloatIfPresent(int key, IntFloatUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(containsKey(key)) { - float newValue = mappingFunction.applyAsFloat(key, get(key)); - put(key, newValue); - return newValue; - } - return getDefaultReturnValue(); - } - @Override public float computeFloatIfPresentNonDefault(int key, IntFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/ints/maps/abstracts/AbstractInt2IntMap.java b/src/main/java/speiger/src/collections/ints/maps/abstracts/AbstractInt2IntMap.java index eea5a1a4..f761c2d9 100644 --- a/src/main/java/speiger/src/collections/ints/maps/abstracts/AbstractInt2IntMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/abstracts/AbstractInt2IntMap.java @@ -155,6 +155,39 @@ public int computeInt(int key, IntIntUnaryOperator mappingFunction) { return newValue; } + @Override + public int computeIntIfAbsent(int key, IntUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(!containsKey(key)) { + int newValue = mappingFunction.applyAsInt(key); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public int supplyIntIfAbsent(int key, IntSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + if(!containsKey(key)) { + int newValue = valueProvider.getAsInt(); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public int computeIntIfPresent(int key, IntIntUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(containsKey(key)) { + int newValue = mappingFunction.applyAsInt(key, get(key)); + put(key, newValue); + return newValue; + } + return getDefaultReturnValue(); + } + @Override public int computeIntNonDefault(int key, IntIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -171,17 +204,6 @@ public int computeIntNonDefault(int key, IntIntUnaryOperator mappingFunction) { return newValue; } - @Override - public int computeIntIfAbsent(int key, IntUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(!containsKey(key)) { - int newValue = mappingFunction.applyAsInt(key); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public int computeIntIfAbsentNonDefault(int key, IntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -196,17 +218,6 @@ public int computeIntIfAbsentNonDefault(int key, IntUnaryOperator mappingFunctio return value; } - @Override - public int supplyIntIfAbsent(int key, IntSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - if(!containsKey(key)) { - int newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public int supplyIntIfAbsentNonDefault(int key, IntSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -221,17 +232,6 @@ public int supplyIntIfAbsentNonDefault(int key, IntSupplier valueProvider) { return value; } - @Override - public int computeIntIfPresent(int key, IntIntUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(containsKey(key)) { - int newValue = mappingFunction.applyAsInt(key, get(key)); - put(key, newValue); - return newValue; - } - return getDefaultReturnValue(); - } - @Override public int computeIntIfPresentNonDefault(int key, IntIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/ints/maps/abstracts/AbstractInt2LongMap.java b/src/main/java/speiger/src/collections/ints/maps/abstracts/AbstractInt2LongMap.java index 58e7d91a..da57cbed 100644 --- a/src/main/java/speiger/src/collections/ints/maps/abstracts/AbstractInt2LongMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/abstracts/AbstractInt2LongMap.java @@ -157,6 +157,39 @@ public long computeLong(int key, IntLongUnaryOperator mappingFunction) { return newValue; } + @Override + public long computeLongIfAbsent(int key, Int2LongFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(!containsKey(key)) { + long newValue = mappingFunction.applyAsLong(key); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public long supplyLongIfAbsent(int key, LongSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + if(!containsKey(key)) { + long newValue = valueProvider.getAsLong(); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public long computeLongIfPresent(int key, IntLongUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(containsKey(key)) { + long newValue = mappingFunction.applyAsLong(key, get(key)); + put(key, newValue); + return newValue; + } + return getDefaultReturnValue(); + } + @Override public long computeLongNonDefault(int key, IntLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -173,17 +206,6 @@ public long computeLongNonDefault(int key, IntLongUnaryOperator mappingFunction) return newValue; } - @Override - public long computeLongIfAbsent(int key, Int2LongFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(!containsKey(key)) { - long newValue = mappingFunction.applyAsLong(key); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public long computeLongIfAbsentNonDefault(int key, Int2LongFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -198,17 +220,6 @@ public long computeLongIfAbsentNonDefault(int key, Int2LongFunction mappingFunct return value; } - @Override - public long supplyLongIfAbsent(int key, LongSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - if(!containsKey(key)) { - long newValue = valueProvider.getAsLong(); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public long supplyLongIfAbsentNonDefault(int key, LongSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -223,17 +234,6 @@ public long supplyLongIfAbsentNonDefault(int key, LongSupplier valueProvider) { return value; } - @Override - public long computeLongIfPresent(int key, IntLongUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(containsKey(key)) { - long newValue = mappingFunction.applyAsLong(key, get(key)); - put(key, newValue); - return newValue; - } - return getDefaultReturnValue(); - } - @Override public long computeLongIfPresentNonDefault(int key, IntLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/ints/maps/abstracts/AbstractInt2ObjectMap.java b/src/main/java/speiger/src/collections/ints/maps/abstracts/AbstractInt2ObjectMap.java index d49fcaeb..97248248 100644 --- a/src/main/java/speiger/src/collections/ints/maps/abstracts/AbstractInt2ObjectMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/abstracts/AbstractInt2ObjectMap.java @@ -159,22 +159,6 @@ public V compute(int key, IntObjectUnaryOperator mappingFunction) { return newValue; } - @Override - public V computeNonDefault(int key, IntObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - V value = get(key); - V newValue = mappingFunction.apply(key, value); - if(Objects.equals(newValue, getDefaultReturnValue())) { - if(!Objects.equals(value, getDefaultReturnValue()) || containsKey(key)) { - remove(key); - return getDefaultReturnValue(); - } - return getDefaultReturnValue(); - } - put(key, newValue); - return newValue; - } - @Override public V computeIfAbsent(int key, IntFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -189,20 +173,6 @@ public V computeIfAbsent(int key, IntFunction mappingFunction) { return value; } - @Override - public V computeIfAbsentNonDefault(int key, IntFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - V value; - if((value = get(key)) == getDefaultReturnValue() || !containsKey(key)) { - V newValue = mappingFunction.apply(key); - if(!Objects.equals(newValue, getDefaultReturnValue())) { - put(key, newValue); - return newValue; - } - } - return value; - } - @Override public V supplyIfAbsent(int key, ObjectSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -217,20 +187,6 @@ public V supplyIfAbsent(int key, ObjectSupplier valueProvider) { return value; } - @Override - public V supplyIfAbsentNonDefault(int key, ObjectSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - V value; - if((value = get(key)) == getDefaultReturnValue() || !containsKey(key)) { - V newValue = valueProvider.get(); - if(!Objects.equals(newValue, getDefaultReturnValue())) { - put(key, newValue); - return newValue; - } - } - return value; - } - @Override public V computeIfPresent(int key, IntObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -246,21 +202,6 @@ public V computeIfPresent(int key, IntObjectUnaryOperator mappingFunction) { return getDefaultReturnValue(); } - @Override - public V computeIfPresentNonDefault(int key, IntObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - V value; - if(!Objects.equals((value = get(key)), getDefaultReturnValue()) || containsKey(key)) { - V newValue = mappingFunction.apply(key, value); - if(!Objects.equals(newValue, getDefaultReturnValue())) { - put(key, newValue); - return newValue; - } - remove(key); - } - return getDefaultReturnValue(); - } - @Override public V merge(int key, V value, ObjectObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/ints/maps/abstracts/AbstractInt2ShortMap.java b/src/main/java/speiger/src/collections/ints/maps/abstracts/AbstractInt2ShortMap.java index e0511edf..c79dc498 100644 --- a/src/main/java/speiger/src/collections/ints/maps/abstracts/AbstractInt2ShortMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/abstracts/AbstractInt2ShortMap.java @@ -157,6 +157,39 @@ public short computeShort(int key, IntShortUnaryOperator mappingFunction) { return newValue; } + @Override + public short computeShortIfAbsent(int key, Int2ShortFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(!containsKey(key)) { + short newValue = mappingFunction.applyAsShort(key); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public short supplyShortIfAbsent(int key, ShortSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + if(!containsKey(key)) { + short newValue = valueProvider.getAsShort(); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public short computeShortIfPresent(int key, IntShortUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(containsKey(key)) { + short newValue = mappingFunction.applyAsShort(key, get(key)); + put(key, newValue); + return newValue; + } + return getDefaultReturnValue(); + } + @Override public short computeShortNonDefault(int key, IntShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -173,17 +206,6 @@ public short computeShortNonDefault(int key, IntShortUnaryOperator mappingFuncti return newValue; } - @Override - public short computeShortIfAbsent(int key, Int2ShortFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(!containsKey(key)) { - short newValue = mappingFunction.applyAsShort(key); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public short computeShortIfAbsentNonDefault(int key, Int2ShortFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -198,23 +220,12 @@ public short computeShortIfAbsentNonDefault(int key, Int2ShortFunction mappingFu return value; } - @Override - public short supplyShortIfAbsent(int key, ShortSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - if(!containsKey(key)) { - short newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public short supplyShortIfAbsentNonDefault(int key, ShortSupplier valueProvider) { Objects.requireNonNull(valueProvider); short value; if((value = get(key)) == getDefaultReturnValue() || !containsKey(key)) { - short newValue = valueProvider.getAsInt(); + short newValue = valueProvider.getAsShort(); if(newValue != getDefaultReturnValue()) { put(key, newValue); return newValue; @@ -223,17 +234,6 @@ public short supplyShortIfAbsentNonDefault(int key, ShortSupplier valueProvider) return value; } - @Override - public short computeShortIfPresent(int key, IntShortUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(containsKey(key)) { - short newValue = mappingFunction.applyAsShort(key, get(key)); - put(key, newValue); - return newValue; - } - return getDefaultReturnValue(); - } - @Override public short computeShortIfPresentNonDefault(int key, IntShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/concurrent/Int2BooleanConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/concurrent/Int2BooleanConcurrentOpenHashMap.java index 8d4057f8..adeb6926 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/concurrent/Int2BooleanConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/concurrent/Int2BooleanConcurrentOpenHashMap.java @@ -437,13 +437,6 @@ public boolean computeBoolean(int key, IntBooleanUnaryOperator mappingFunction) return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public boolean computeBooleanNonDefault(int key, IntBooleanUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public boolean computeBooleanIfAbsent(int key, IntPredicate mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -451,13 +444,6 @@ public boolean computeBooleanIfAbsent(int key, IntPredicate mappingFunction) { return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public boolean computeBooleanIfAbsentNonDefault(int key, IntPredicate mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public boolean supplyBooleanIfAbsent(int key, BooleanSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -466,17 +452,31 @@ public boolean supplyBooleanIfAbsent(int key, BooleanSupplier valueProvider) { } @Override - public boolean supplyBooleanIfAbsentNonDefault(int key, BooleanSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public boolean computeBooleanIfPresent(int key, IntBooleanUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); + return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } @Override - public boolean computeBooleanIfPresent(int key, IntBooleanUnaryOperator mappingFunction) { + public boolean computeBooleanNonDefault(int key, IntBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).computeIfPresent(hash, key, mappingFunction); + return getSegment(hash).computeNonDefault(hash, key, mappingFunction); + } + + @Override + public boolean computeBooleanIfAbsentNonDefault(int key, IntPredicate mappingFunction) { + Objects.requireNonNull(mappingFunction); + int hash = getHashCode(key); + return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); + } + + @Override + public boolean supplyBooleanIfAbsentNonDefault(int key, BooleanSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + int hash = getHashCode(key); + return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); } @Override @@ -2031,35 +2031,29 @@ protected boolean compute(int hash, int key, IntBooleanUnaryOperator mappingFunc } } - protected boolean computeNonDefault(int hash, int key, IntBooleanUnaryOperator mappingFunction) { + protected boolean computeIfAbsent(int hash, int key, IntPredicate mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + boolean newValue = mappingFunction.test(key); insert(-index-1, key, newValue); return newValue; } - boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + boolean newValue = values[index]; return newValue; } finally { unlockWrite(stamp); } } - - protected boolean computeIfAbsent(int hash, int key, IntPredicate mappingFunction) { + + protected boolean supplyIfAbsent(int hash, int key, BooleanSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - boolean newValue = mappingFunction.test(key); + boolean newValue = valueProvider.getAsBoolean(); insert(-index-1, key, newValue); return newValue; } @@ -2070,23 +2064,37 @@ protected boolean computeIfAbsent(int hash, int key, IntPredicate mappingFunctio unlockWrite(stamp); } } + + protected boolean computeIfPresent(int hash, int key, IntBooleanUnaryOperator mappingFunction) { + long stamp = writeLock(); + try { + int index = findIndex(hash, key); + if(index < 0) return getDefaultReturnValue(); + boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); + values[index] = newValue; + return newValue; + } + finally { + unlockWrite(stamp); + } + } - protected boolean computeIfAbsentNonDefault(int hash, int key, IntPredicate mappingFunction) { + protected boolean computeNonDefault(int hash, int key, IntBooleanUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - boolean newValue = mappingFunction.test(key); + boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - boolean newValue = values[index]; + boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.test(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } finally { @@ -2094,16 +2102,22 @@ protected boolean computeIfAbsentNonDefault(int hash, int key, IntPredicate mapp } } - protected boolean supplyIfAbsent(int hash, int key, BooleanSupplier valueProvider) { + protected boolean computeIfAbsentNonDefault(int hash, int key, IntPredicate mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - boolean newValue = valueProvider.getAsBoolean(); + boolean newValue = mappingFunction.test(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } boolean newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.test(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } finally { @@ -2134,20 +2148,6 @@ protected boolean supplyIfAbsentNonDefault(int hash, int key, BooleanSupplier va } } - protected boolean computeIfPresent(int hash, int key, IntBooleanUnaryOperator mappingFunction) { - long stamp = writeLock(); - try { - int index = findIndex(hash, key); - if(index < 0) return getDefaultReturnValue(); - boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); - values[index] = newValue; - return newValue; - } - finally { - unlockWrite(stamp); - } - } - protected boolean computeIfPresentNonDefault(int hash, int key, IntBooleanUnaryOperator mappingFunction) { long stamp = writeLock(); try { diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/concurrent/Int2ByteConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/concurrent/Int2ByteConcurrentOpenHashMap.java index 2b836cbb..10c47fa2 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/concurrent/Int2ByteConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/concurrent/Int2ByteConcurrentOpenHashMap.java @@ -450,13 +450,6 @@ public byte computeByte(int key, IntByteUnaryOperator mappingFunction) { return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public byte computeByteNonDefault(int key, IntByteUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public byte computeByteIfAbsent(int key, Int2ByteFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -464,13 +457,6 @@ public byte computeByteIfAbsent(int key, Int2ByteFunction mappingFunction) { return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public byte computeByteIfAbsentNonDefault(int key, Int2ByteFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public byte supplyByteIfAbsent(int key, ByteSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -479,17 +465,31 @@ public byte supplyByteIfAbsent(int key, ByteSupplier valueProvider) { } @Override - public byte supplyByteIfAbsentNonDefault(int key, ByteSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public byte computeByteIfPresent(int key, IntByteUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); + return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } @Override - public byte computeByteIfPresent(int key, IntByteUnaryOperator mappingFunction) { + public byte computeByteNonDefault(int key, IntByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).computeIfPresent(hash, key, mappingFunction); + return getSegment(hash).computeNonDefault(hash, key, mappingFunction); + } + + @Override + public byte computeByteIfAbsentNonDefault(int key, Int2ByteFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + int hash = getHashCode(key); + return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); + } + + @Override + public byte supplyByteIfAbsentNonDefault(int key, ByteSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + int hash = getHashCode(key); + return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); } @Override @@ -2075,35 +2075,29 @@ protected byte compute(int hash, int key, IntByteUnaryOperator mappingFunction) } } - protected byte computeNonDefault(int hash, int key, IntByteUnaryOperator mappingFunction) { + protected byte computeIfAbsent(int hash, int key, Int2ByteFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + byte newValue = mappingFunction.applyAsByte(key); insert(-index-1, key, newValue); return newValue; } - byte newValue = mappingFunction.applyAsByte(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + byte newValue = values[index]; return newValue; } finally { unlockWrite(stamp); } } - - protected byte computeIfAbsent(int hash, int key, Int2ByteFunction mappingFunction) { + + protected byte supplyIfAbsent(int hash, int key, ByteSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = valueProvider.getAsByte(); insert(-index-1, key, newValue); return newValue; } @@ -2114,23 +2108,14 @@ protected byte computeIfAbsent(int hash, int key, Int2ByteFunction mappingFuncti unlockWrite(stamp); } } - - protected byte computeIfAbsentNonDefault(int hash, int key, Int2ByteFunction mappingFunction) { + + protected byte computeIfPresent(int hash, int key, IntByteUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key); - if(newValue == getDefaultReturnValue()) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - byte newValue = values[index]; - if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsByte(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; - } + if(index < 0) return getDefaultReturnValue(); + byte newValue = mappingFunction.applyAsByte(key, values[index]); + values[index] = newValue; return newValue; } finally { @@ -2138,16 +2123,22 @@ protected byte computeIfAbsentNonDefault(int hash, int key, Int2ByteFunction map } } - protected byte supplyIfAbsent(int hash, int key, ByteSupplier valueProvider) { + protected byte computeNonDefault(int hash, int key, IntByteUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - byte newValue = valueProvider.getAsInt(); + byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - byte newValue = values[index]; + byte newValue = mappingFunction.applyAsByte(key, values[index]); + if(newValue == getDefaultReturnValue()) { + removeIndex(index); + return newValue; + } + values[index] = newValue; return newValue; } finally { @@ -2155,19 +2146,19 @@ protected byte supplyIfAbsent(int hash, int key, ByteSupplier valueProvider) { } } - protected byte supplyIfAbsentNonDefault(int hash, int key, ByteSupplier valueProvider) { + protected byte computeIfAbsentNonDefault(int hash, int key, Int2ByteFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - byte newValue = valueProvider.getAsInt(); + byte newValue = mappingFunction.applyAsByte(key); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } byte newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = mappingFunction.applyAsByte(key); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } @@ -2178,13 +2169,22 @@ protected byte supplyIfAbsentNonDefault(int hash, int key, ByteSupplier valuePro } } - protected byte computeIfPresent(int hash, int key, IntByteUnaryOperator mappingFunction) { + protected byte supplyIfAbsentNonDefault(int hash, int key, ByteSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0) return getDefaultReturnValue(); - byte newValue = mappingFunction.applyAsByte(key, values[index]); - values[index] = newValue; + if(index < 0) { + byte newValue = valueProvider.getAsByte(); + if(newValue == getDefaultReturnValue()) return newValue; + insert(-index-1, key, newValue); + return newValue; + } + byte newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = valueProvider.getAsByte(); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } finally { diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/concurrent/Int2CharConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/concurrent/Int2CharConcurrentOpenHashMap.java index eae7d767..5564eb41 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/concurrent/Int2CharConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/concurrent/Int2CharConcurrentOpenHashMap.java @@ -450,13 +450,6 @@ public char computeChar(int key, IntCharUnaryOperator mappingFunction) { return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public char computeCharNonDefault(int key, IntCharUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public char computeCharIfAbsent(int key, Int2CharFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -464,13 +457,6 @@ public char computeCharIfAbsent(int key, Int2CharFunction mappingFunction) { return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public char computeCharIfAbsentNonDefault(int key, Int2CharFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public char supplyCharIfAbsent(int key, CharSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -479,17 +465,31 @@ public char supplyCharIfAbsent(int key, CharSupplier valueProvider) { } @Override - public char supplyCharIfAbsentNonDefault(int key, CharSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public char computeCharIfPresent(int key, IntCharUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); + return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } @Override - public char computeCharIfPresent(int key, IntCharUnaryOperator mappingFunction) { + public char computeCharNonDefault(int key, IntCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).computeIfPresent(hash, key, mappingFunction); + return getSegment(hash).computeNonDefault(hash, key, mappingFunction); + } + + @Override + public char computeCharIfAbsentNonDefault(int key, Int2CharFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + int hash = getHashCode(key); + return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); + } + + @Override + public char supplyCharIfAbsentNonDefault(int key, CharSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + int hash = getHashCode(key); + return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); } @Override @@ -2075,35 +2075,29 @@ protected char compute(int hash, int key, IntCharUnaryOperator mappingFunction) } } - protected char computeNonDefault(int hash, int key, IntCharUnaryOperator mappingFunction) { + protected char computeIfAbsent(int hash, int key, Int2CharFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + char newValue = mappingFunction.applyAsChar(key); insert(-index-1, key, newValue); return newValue; } - char newValue = mappingFunction.applyAsChar(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + char newValue = values[index]; return newValue; } finally { unlockWrite(stamp); } } - - protected char computeIfAbsent(int hash, int key, Int2CharFunction mappingFunction) { + + protected char supplyIfAbsent(int hash, int key, CharSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = valueProvider.getAsChar(); insert(-index-1, key, newValue); return newValue; } @@ -2114,23 +2108,14 @@ protected char computeIfAbsent(int hash, int key, Int2CharFunction mappingFuncti unlockWrite(stamp); } } - - protected char computeIfAbsentNonDefault(int hash, int key, Int2CharFunction mappingFunction) { + + protected char computeIfPresent(int hash, int key, IntCharUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0) { - char newValue = mappingFunction.applyAsChar(key); - if(newValue == getDefaultReturnValue()) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - char newValue = values[index]; - if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsChar(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; - } + if(index < 0) return getDefaultReturnValue(); + char newValue = mappingFunction.applyAsChar(key, values[index]); + values[index] = newValue; return newValue; } finally { @@ -2138,16 +2123,22 @@ protected char computeIfAbsentNonDefault(int hash, int key, Int2CharFunction map } } - protected char supplyIfAbsent(int hash, int key, CharSupplier valueProvider) { + protected char computeNonDefault(int hash, int key, IntCharUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - char newValue = valueProvider.getAsInt(); + char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - char newValue = values[index]; + char newValue = mappingFunction.applyAsChar(key, values[index]); + if(newValue == getDefaultReturnValue()) { + removeIndex(index); + return newValue; + } + values[index] = newValue; return newValue; } finally { @@ -2155,19 +2146,19 @@ protected char supplyIfAbsent(int hash, int key, CharSupplier valueProvider) { } } - protected char supplyIfAbsentNonDefault(int hash, int key, CharSupplier valueProvider) { + protected char computeIfAbsentNonDefault(int hash, int key, Int2CharFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - char newValue = valueProvider.getAsInt(); + char newValue = mappingFunction.applyAsChar(key); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } char newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = mappingFunction.applyAsChar(key); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } @@ -2178,13 +2169,22 @@ protected char supplyIfAbsentNonDefault(int hash, int key, CharSupplier valuePro } } - protected char computeIfPresent(int hash, int key, IntCharUnaryOperator mappingFunction) { + protected char supplyIfAbsentNonDefault(int hash, int key, CharSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0) return getDefaultReturnValue(); - char newValue = mappingFunction.applyAsChar(key, values[index]); - values[index] = newValue; + if(index < 0) { + char newValue = valueProvider.getAsChar(); + if(newValue == getDefaultReturnValue()) return newValue; + insert(-index-1, key, newValue); + return newValue; + } + char newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = valueProvider.getAsChar(); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } finally { diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/concurrent/Int2DoubleConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/concurrent/Int2DoubleConcurrentOpenHashMap.java index dfe0dfa9..d33dd53d 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/concurrent/Int2DoubleConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/concurrent/Int2DoubleConcurrentOpenHashMap.java @@ -450,13 +450,6 @@ public double computeDouble(int key, IntDoubleUnaryOperator mappingFunction) { return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public double computeDoubleNonDefault(int key, IntDoubleUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public double computeDoubleIfAbsent(int key, Int2DoubleFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -464,13 +457,6 @@ public double computeDoubleIfAbsent(int key, Int2DoubleFunction mappingFunction) return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public double computeDoubleIfAbsentNonDefault(int key, Int2DoubleFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public double supplyDoubleIfAbsent(int key, DoubleSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -479,17 +465,31 @@ public double supplyDoubleIfAbsent(int key, DoubleSupplier valueProvider) { } @Override - public double supplyDoubleIfAbsentNonDefault(int key, DoubleSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public double computeDoubleIfPresent(int key, IntDoubleUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); + return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } @Override - public double computeDoubleIfPresent(int key, IntDoubleUnaryOperator mappingFunction) { + public double computeDoubleNonDefault(int key, IntDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).computeIfPresent(hash, key, mappingFunction); + return getSegment(hash).computeNonDefault(hash, key, mappingFunction); + } + + @Override + public double computeDoubleIfAbsentNonDefault(int key, Int2DoubleFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + int hash = getHashCode(key); + return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); + } + + @Override + public double supplyDoubleIfAbsentNonDefault(int key, DoubleSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + int hash = getHashCode(key); + return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); } @Override @@ -2075,35 +2075,29 @@ protected double compute(int hash, int key, IntDoubleUnaryOperator mappingFuncti } } - protected double computeNonDefault(int hash, int key, IntDoubleUnaryOperator mappingFunction) { + protected double computeIfAbsent(int hash, int key, Int2DoubleFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + double newValue = mappingFunction.applyAsDouble(key); insert(-index-1, key, newValue); return newValue; } - double newValue = mappingFunction.applyAsDouble(key, values[index]); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + double newValue = values[index]; return newValue; } finally { unlockWrite(stamp); } } - - protected double computeIfAbsent(int hash, int key, Int2DoubleFunction mappingFunction) { + + protected double supplyIfAbsent(int hash, int key, DoubleSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = valueProvider.getAsDouble(); insert(-index-1, key, newValue); return newValue; } @@ -2114,23 +2108,37 @@ protected double computeIfAbsent(int hash, int key, Int2DoubleFunction mappingFu unlockWrite(stamp); } } + + protected double computeIfPresent(int hash, int key, IntDoubleUnaryOperator mappingFunction) { + long stamp = writeLock(); + try { + int index = findIndex(hash, key); + if(index < 0) return getDefaultReturnValue(); + double newValue = mappingFunction.applyAsDouble(key, values[index]); + values[index] = newValue; + return newValue; + } + finally { + unlockWrite(stamp); + } + } - protected double computeIfAbsentNonDefault(int hash, int key, Int2DoubleFunction mappingFunction) { + protected double computeNonDefault(int hash, int key, IntDoubleUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } - double newValue = values[index]; + double newValue = mappingFunction.applyAsDouble(key, values[index]); if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - newValue = mappingFunction.applyAsDouble(key); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } finally { @@ -2138,16 +2146,22 @@ protected double computeIfAbsentNonDefault(int hash, int key, Int2DoubleFunction } } - protected double supplyIfAbsent(int hash, int key, DoubleSupplier valueProvider) { + protected double computeIfAbsentNonDefault(int hash, int key, Int2DoubleFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - double newValue = valueProvider.getAsDouble(); + double newValue = mappingFunction.applyAsDouble(key); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } double newValue = values[index]; + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { + newValue = mappingFunction.applyAsDouble(key); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + values[index] = newValue; + } return newValue; } finally { @@ -2178,20 +2192,6 @@ protected double supplyIfAbsentNonDefault(int hash, int key, DoubleSupplier valu } } - protected double computeIfPresent(int hash, int key, IntDoubleUnaryOperator mappingFunction) { - long stamp = writeLock(); - try { - int index = findIndex(hash, key); - if(index < 0) return getDefaultReturnValue(); - double newValue = mappingFunction.applyAsDouble(key, values[index]); - values[index] = newValue; - return newValue; - } - finally { - unlockWrite(stamp); - } - } - protected double computeIfPresentNonDefault(int hash, int key, IntDoubleUnaryOperator mappingFunction) { long stamp = writeLock(); try { diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/concurrent/Int2FloatConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/concurrent/Int2FloatConcurrentOpenHashMap.java index 8cf4c3dd..41badbfc 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/concurrent/Int2FloatConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/concurrent/Int2FloatConcurrentOpenHashMap.java @@ -450,13 +450,6 @@ public float computeFloat(int key, IntFloatUnaryOperator mappingFunction) { return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public float computeFloatNonDefault(int key, IntFloatUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public float computeFloatIfAbsent(int key, Int2FloatFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -464,13 +457,6 @@ public float computeFloatIfAbsent(int key, Int2FloatFunction mappingFunction) { return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public float computeFloatIfAbsentNonDefault(int key, Int2FloatFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public float supplyFloatIfAbsent(int key, FloatSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -479,17 +465,31 @@ public float supplyFloatIfAbsent(int key, FloatSupplier valueProvider) { } @Override - public float supplyFloatIfAbsentNonDefault(int key, FloatSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public float computeFloatIfPresent(int key, IntFloatUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); + return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } @Override - public float computeFloatIfPresent(int key, IntFloatUnaryOperator mappingFunction) { + public float computeFloatNonDefault(int key, IntFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).computeIfPresent(hash, key, mappingFunction); + return getSegment(hash).computeNonDefault(hash, key, mappingFunction); + } + + @Override + public float computeFloatIfAbsentNonDefault(int key, Int2FloatFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + int hash = getHashCode(key); + return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); + } + + @Override + public float supplyFloatIfAbsentNonDefault(int key, FloatSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + int hash = getHashCode(key); + return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); } @Override @@ -2075,35 +2075,29 @@ protected float compute(int hash, int key, IntFloatUnaryOperator mappingFunction } } - protected float computeNonDefault(int hash, int key, IntFloatUnaryOperator mappingFunction) { + protected float computeIfAbsent(int hash, int key, Int2FloatFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + float newValue = mappingFunction.applyAsFloat(key); insert(-index-1, key, newValue); return newValue; } - float newValue = mappingFunction.applyAsFloat(key, values[index]); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + float newValue = values[index]; return newValue; } finally { unlockWrite(stamp); } } - - protected float computeIfAbsent(int hash, int key, Int2FloatFunction mappingFunction) { + + protected float supplyIfAbsent(int hash, int key, FloatSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = valueProvider.getAsFloat(); insert(-index-1, key, newValue); return newValue; } @@ -2114,23 +2108,14 @@ protected float computeIfAbsent(int hash, int key, Int2FloatFunction mappingFunc unlockWrite(stamp); } } - - protected float computeIfAbsentNonDefault(int hash, int key, Int2FloatFunction mappingFunction) { + + protected float computeIfPresent(int hash, int key, IntFloatUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - float newValue = values[index]; - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - newValue = mappingFunction.applyAsFloat(key); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; - values[index] = newValue; - } + if(index < 0) return getDefaultReturnValue(); + float newValue = mappingFunction.applyAsFloat(key, values[index]); + values[index] = newValue; return newValue; } finally { @@ -2138,16 +2123,22 @@ protected float computeIfAbsentNonDefault(int hash, int key, Int2FloatFunction m } } - protected float supplyIfAbsent(int hash, int key, FloatSupplier valueProvider) { + protected float computeNonDefault(int hash, int key, IntFloatUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - float newValue = valueProvider.getAsDouble(); + float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } - float newValue = values[index]; + float newValue = mappingFunction.applyAsFloat(key, values[index]); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { + removeIndex(index); + return newValue; + } + values[index] = newValue; return newValue; } finally { @@ -2155,19 +2146,19 @@ protected float supplyIfAbsent(int hash, int key, FloatSupplier valueProvider) { } } - protected float supplyIfAbsentNonDefault(int hash, int key, FloatSupplier valueProvider) { + protected float computeIfAbsentNonDefault(int hash, int key, Int2FloatFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - float newValue = valueProvider.getAsDouble(); + float newValue = mappingFunction.applyAsFloat(key); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } float newValue = values[index]; if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - newValue = valueProvider.getAsDouble(); + newValue = mappingFunction.applyAsFloat(key); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; values[index] = newValue; } @@ -2178,13 +2169,22 @@ protected float supplyIfAbsentNonDefault(int hash, int key, FloatSupplier valueP } } - protected float computeIfPresent(int hash, int key, IntFloatUnaryOperator mappingFunction) { + protected float supplyIfAbsentNonDefault(int hash, int key, FloatSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0) return getDefaultReturnValue(); - float newValue = mappingFunction.applyAsFloat(key, values[index]); - values[index] = newValue; + if(index < 0) { + float newValue = valueProvider.getAsFloat(); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + insert(-index-1, key, newValue); + return newValue; + } + float newValue = values[index]; + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { + newValue = valueProvider.getAsFloat(); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + values[index] = newValue; + } return newValue; } finally { diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/concurrent/Int2IntConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/concurrent/Int2IntConcurrentOpenHashMap.java index c4cde2ba..a481eccc 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/concurrent/Int2IntConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/concurrent/Int2IntConcurrentOpenHashMap.java @@ -443,13 +443,6 @@ public int computeInt(int key, IntIntUnaryOperator mappingFunction) { return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public int computeIntNonDefault(int key, IntIntUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public int computeIntIfAbsent(int key, IntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -457,13 +450,6 @@ public int computeIntIfAbsent(int key, IntUnaryOperator mappingFunction) { return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public int computeIntIfAbsentNonDefault(int key, IntUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public int supplyIntIfAbsent(int key, IntSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -472,17 +458,31 @@ public int supplyIntIfAbsent(int key, IntSupplier valueProvider) { } @Override - public int supplyIntIfAbsentNonDefault(int key, IntSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public int computeIntIfPresent(int key, IntIntUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); + return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } @Override - public int computeIntIfPresent(int key, IntIntUnaryOperator mappingFunction) { + public int computeIntNonDefault(int key, IntIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).computeIfPresent(hash, key, mappingFunction); + return getSegment(hash).computeNonDefault(hash, key, mappingFunction); + } + + @Override + public int computeIntIfAbsentNonDefault(int key, IntUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int hash = getHashCode(key); + return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); + } + + @Override + public int supplyIntIfAbsentNonDefault(int key, IntSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + int hash = getHashCode(key); + return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); } @Override @@ -2068,35 +2068,29 @@ protected int compute(int hash, int key, IntIntUnaryOperator mappingFunction) { } } - protected int computeNonDefault(int hash, int key, IntIntUnaryOperator mappingFunction) { + protected int computeIfAbsent(int hash, int key, IntUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + int newValue = mappingFunction.applyAsInt(key); insert(-index-1, key, newValue); return newValue; } - int newValue = mappingFunction.applyAsInt(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + int newValue = values[index]; return newValue; } finally { unlockWrite(stamp); } } - - protected int computeIfAbsent(int hash, int key, IntUnaryOperator mappingFunction) { + + protected int supplyIfAbsent(int hash, int key, IntSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = valueProvider.getAsInt(); insert(-index-1, key, newValue); return newValue; } @@ -2107,23 +2101,37 @@ protected int computeIfAbsent(int hash, int key, IntUnaryOperator mappingFunctio unlockWrite(stamp); } } + + protected int computeIfPresent(int hash, int key, IntIntUnaryOperator mappingFunction) { + long stamp = writeLock(); + try { + int index = findIndex(hash, key); + if(index < 0) return getDefaultReturnValue(); + int newValue = mappingFunction.applyAsInt(key, values[index]); + values[index] = newValue; + return newValue; + } + finally { + unlockWrite(stamp); + } + } - protected int computeIfAbsentNonDefault(int hash, int key, IntUnaryOperator mappingFunction) { + protected int computeNonDefault(int hash, int key, IntIntUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - int newValue = values[index]; + int newValue = mappingFunction.applyAsInt(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsInt(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } finally { @@ -2131,16 +2139,22 @@ protected int computeIfAbsentNonDefault(int hash, int key, IntUnaryOperator mapp } } - protected int supplyIfAbsent(int hash, int key, IntSupplier valueProvider) { + protected int computeIfAbsentNonDefault(int hash, int key, IntUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - int newValue = valueProvider.getAsInt(); + int newValue = mappingFunction.applyAsInt(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } int newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsInt(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } finally { @@ -2171,20 +2185,6 @@ protected int supplyIfAbsentNonDefault(int hash, int key, IntSupplier valueProvi } } - protected int computeIfPresent(int hash, int key, IntIntUnaryOperator mappingFunction) { - long stamp = writeLock(); - try { - int index = findIndex(hash, key); - if(index < 0) return getDefaultReturnValue(); - int newValue = mappingFunction.applyAsInt(key, values[index]); - values[index] = newValue; - return newValue; - } - finally { - unlockWrite(stamp); - } - } - protected int computeIfPresentNonDefault(int hash, int key, IntIntUnaryOperator mappingFunction) { long stamp = writeLock(); try { diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/concurrent/Int2LongConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/concurrent/Int2LongConcurrentOpenHashMap.java index 69eb1573..f9176748 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/concurrent/Int2LongConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/concurrent/Int2LongConcurrentOpenHashMap.java @@ -450,13 +450,6 @@ public long computeLong(int key, IntLongUnaryOperator mappingFunction) { return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public long computeLongNonDefault(int key, IntLongUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public long computeLongIfAbsent(int key, Int2LongFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -464,13 +457,6 @@ public long computeLongIfAbsent(int key, Int2LongFunction mappingFunction) { return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public long computeLongIfAbsentNonDefault(int key, Int2LongFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public long supplyLongIfAbsent(int key, LongSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -479,17 +465,31 @@ public long supplyLongIfAbsent(int key, LongSupplier valueProvider) { } @Override - public long supplyLongIfAbsentNonDefault(int key, LongSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public long computeLongIfPresent(int key, IntLongUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); + return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } @Override - public long computeLongIfPresent(int key, IntLongUnaryOperator mappingFunction) { + public long computeLongNonDefault(int key, IntLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).computeIfPresent(hash, key, mappingFunction); + return getSegment(hash).computeNonDefault(hash, key, mappingFunction); + } + + @Override + public long computeLongIfAbsentNonDefault(int key, Int2LongFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + int hash = getHashCode(key); + return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); + } + + @Override + public long supplyLongIfAbsentNonDefault(int key, LongSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + int hash = getHashCode(key); + return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); } @Override @@ -2075,35 +2075,29 @@ protected long compute(int hash, int key, IntLongUnaryOperator mappingFunction) } } - protected long computeNonDefault(int hash, int key, IntLongUnaryOperator mappingFunction) { + protected long computeIfAbsent(int hash, int key, Int2LongFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + long newValue = mappingFunction.applyAsLong(key); insert(-index-1, key, newValue); return newValue; } - long newValue = mappingFunction.applyAsLong(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + long newValue = values[index]; return newValue; } finally { unlockWrite(stamp); } } - - protected long computeIfAbsent(int hash, int key, Int2LongFunction mappingFunction) { + + protected long supplyIfAbsent(int hash, int key, LongSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = valueProvider.getAsLong(); insert(-index-1, key, newValue); return newValue; } @@ -2114,23 +2108,37 @@ protected long computeIfAbsent(int hash, int key, Int2LongFunction mappingFuncti unlockWrite(stamp); } } + + protected long computeIfPresent(int hash, int key, IntLongUnaryOperator mappingFunction) { + long stamp = writeLock(); + try { + int index = findIndex(hash, key); + if(index < 0) return getDefaultReturnValue(); + long newValue = mappingFunction.applyAsLong(key, values[index]); + values[index] = newValue; + return newValue; + } + finally { + unlockWrite(stamp); + } + } - protected long computeIfAbsentNonDefault(int hash, int key, Int2LongFunction mappingFunction) { + protected long computeNonDefault(int hash, int key, IntLongUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - long newValue = values[index]; + long newValue = mappingFunction.applyAsLong(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsLong(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } finally { @@ -2138,16 +2146,22 @@ protected long computeIfAbsentNonDefault(int hash, int key, Int2LongFunction map } } - protected long supplyIfAbsent(int hash, int key, LongSupplier valueProvider) { + protected long computeIfAbsentNonDefault(int hash, int key, Int2LongFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - long newValue = valueProvider.getAsLong(); + long newValue = mappingFunction.applyAsLong(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } long newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsLong(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } finally { @@ -2178,20 +2192,6 @@ protected long supplyIfAbsentNonDefault(int hash, int key, LongSupplier valuePro } } - protected long computeIfPresent(int hash, int key, IntLongUnaryOperator mappingFunction) { - long stamp = writeLock(); - try { - int index = findIndex(hash, key); - if(index < 0) return getDefaultReturnValue(); - long newValue = mappingFunction.applyAsLong(key, values[index]); - values[index] = newValue; - return newValue; - } - finally { - unlockWrite(stamp); - } - } - protected long computeIfPresentNonDefault(int hash, int key, IntLongUnaryOperator mappingFunction) { long stamp = writeLock(); try { diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/concurrent/Int2ObjectConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/concurrent/Int2ObjectConcurrentOpenHashMap.java index 5f624c73..7079dd74 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/concurrent/Int2ObjectConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/concurrent/Int2ObjectConcurrentOpenHashMap.java @@ -425,13 +425,6 @@ public V compute(int key, IntObjectUnaryOperator mappingFunction) { return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public V computeNonDefault(int key, IntObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public V computeIfAbsent(int key, IntFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -439,13 +432,6 @@ public V computeIfAbsent(int key, IntFunction mappingFunction) { return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public V computeIfAbsentNonDefault(int key, IntFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public V supplyIfAbsent(int key, ObjectSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -453,13 +439,6 @@ public V supplyIfAbsent(int key, ObjectSupplier valueProvider) { return getSegment(hash).supplyIfAbsent(hash, key, valueProvider); } - @Override - public V supplyIfAbsentNonDefault(int key, ObjectSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); - } - @Override public V computeIfPresent(int key, IntObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -467,13 +446,6 @@ public V computeIfPresent(int key, IntObjectUnaryOperator mappingFunction) { return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } - @Override - public V computeIfPresentNonDefault(int key, IntObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfPresentNonDefault(hash, key, mappingFunction); - } - @Override public V merge(int key, V value, ObjectObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -2010,29 +1982,6 @@ protected V compute(int hash, int key, IntObjectUnaryOperator mappingFunction } } - protected V computeNonDefault(int hash, int key, IntObjectUnaryOperator mappingFunction) { - long stamp = writeLock(); - try { - int index = findIndex(hash, key); - if(index < 0) { - V newValue = mappingFunction.apply(key, getDefaultReturnValue()); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = mappingFunction.apply(key, values[index]); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; - return newValue; - } - finally { - unlockWrite(stamp); - } - } - protected V computeIfAbsent(int hash, int key, IntFunction mappingFunction) { long stamp = writeLock(); try { @@ -2055,30 +2004,7 @@ protected V computeIfAbsent(int hash, int key, IntFunction mappingFunction) { unlockWrite(stamp); } } - - protected V computeIfAbsentNonDefault(int hash, int key, IntFunction mappingFunction) { - long stamp = writeLock(); - try { - int index = findIndex(hash, key); - if(index < 0) { - V newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = values[index]; - if(Objects.equals(newValue, getDefaultReturnValue())) { - newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - values[index] = newValue; - } - return newValue; - } - finally { - unlockWrite(stamp); - } - } - + protected V supplyIfAbsent(int hash, int key, ObjectSupplier valueProvider) { long stamp = writeLock(); try { @@ -2101,30 +2027,7 @@ protected V supplyIfAbsent(int hash, int key, ObjectSupplier valueProvider) { unlockWrite(stamp); } } - - protected V supplyIfAbsentNonDefault(int hash, int key, ObjectSupplier valueProvider) { - long stamp = writeLock(); - try { - int index = findIndex(hash, key); - if(index < 0) { - V newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = values[index]; - if(Objects.equals(newValue, getDefaultReturnValue())) { - newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - values[index] = newValue; - } - return newValue; - } - finally { - unlockWrite(stamp); - } - } - + protected V computeIfPresent(int hash, int key, IntObjectUnaryOperator mappingFunction) { long stamp = writeLock(); try { @@ -2143,11 +2046,16 @@ protected V computeIfPresent(int hash, int key, IntObjectUnaryOperator mappin } } - protected V computeIfPresentNonDefault(int hash, int key, IntObjectUnaryOperator mappingFunction) { + protected V computeNonDefault(int hash, int key, IntObjectUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0 || Objects.equals(values[index], getDefaultReturnValue())) return getDefaultReturnValue(); + if(index < 0) { + V newValue = mappingFunction.apply(key, getDefaultReturnValue()); + if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; + insert(-index-1, key, newValue); + return newValue; + } V newValue = mappingFunction.apply(key, values[index]); if(Objects.equals(newValue, getDefaultReturnValue())) { removeIndex(index); diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/concurrent/Int2ShortConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/concurrent/Int2ShortConcurrentOpenHashMap.java index ff2371aa..f507ab24 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/concurrent/Int2ShortConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/concurrent/Int2ShortConcurrentOpenHashMap.java @@ -450,13 +450,6 @@ public short computeShort(int key, IntShortUnaryOperator mappingFunction) { return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public short computeShortNonDefault(int key, IntShortUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public short computeShortIfAbsent(int key, Int2ShortFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -464,13 +457,6 @@ public short computeShortIfAbsent(int key, Int2ShortFunction mappingFunction) { return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public short computeShortIfAbsentNonDefault(int key, Int2ShortFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public short supplyShortIfAbsent(int key, ShortSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -479,17 +465,31 @@ public short supplyShortIfAbsent(int key, ShortSupplier valueProvider) { } @Override - public short supplyShortIfAbsentNonDefault(int key, ShortSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public short computeShortIfPresent(int key, IntShortUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); + return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } @Override - public short computeShortIfPresent(int key, IntShortUnaryOperator mappingFunction) { + public short computeShortNonDefault(int key, IntShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).computeIfPresent(hash, key, mappingFunction); + return getSegment(hash).computeNonDefault(hash, key, mappingFunction); + } + + @Override + public short computeShortIfAbsentNonDefault(int key, Int2ShortFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + int hash = getHashCode(key); + return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); + } + + @Override + public short supplyShortIfAbsentNonDefault(int key, ShortSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + int hash = getHashCode(key); + return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); } @Override @@ -2075,35 +2075,29 @@ protected short compute(int hash, int key, IntShortUnaryOperator mappingFunction } } - protected short computeNonDefault(int hash, int key, IntShortUnaryOperator mappingFunction) { + protected short computeIfAbsent(int hash, int key, Int2ShortFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + short newValue = mappingFunction.applyAsShort(key); insert(-index-1, key, newValue); return newValue; } - short newValue = mappingFunction.applyAsShort(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + short newValue = values[index]; return newValue; } finally { unlockWrite(stamp); } } - - protected short computeIfAbsent(int hash, int key, Int2ShortFunction mappingFunction) { + + protected short supplyIfAbsent(int hash, int key, ShortSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = valueProvider.getAsShort(); insert(-index-1, key, newValue); return newValue; } @@ -2114,23 +2108,14 @@ protected short computeIfAbsent(int hash, int key, Int2ShortFunction mappingFunc unlockWrite(stamp); } } - - protected short computeIfAbsentNonDefault(int hash, int key, Int2ShortFunction mappingFunction) { + + protected short computeIfPresent(int hash, int key, IntShortUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0) { - short newValue = mappingFunction.applyAsShort(key); - if(newValue == getDefaultReturnValue()) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - short newValue = values[index]; - if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsShort(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; - } + if(index < 0) return getDefaultReturnValue(); + short newValue = mappingFunction.applyAsShort(key, values[index]); + values[index] = newValue; return newValue; } finally { @@ -2138,16 +2123,22 @@ protected short computeIfAbsentNonDefault(int hash, int key, Int2ShortFunction m } } - protected short supplyIfAbsent(int hash, int key, ShortSupplier valueProvider) { + protected short computeNonDefault(int hash, int key, IntShortUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - short newValue = valueProvider.getAsInt(); + short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - short newValue = values[index]; + short newValue = mappingFunction.applyAsShort(key, values[index]); + if(newValue == getDefaultReturnValue()) { + removeIndex(index); + return newValue; + } + values[index] = newValue; return newValue; } finally { @@ -2155,19 +2146,19 @@ protected short supplyIfAbsent(int hash, int key, ShortSupplier valueProvider) { } } - protected short supplyIfAbsentNonDefault(int hash, int key, ShortSupplier valueProvider) { + protected short computeIfAbsentNonDefault(int hash, int key, Int2ShortFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - short newValue = valueProvider.getAsInt(); + short newValue = mappingFunction.applyAsShort(key); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } short newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = mappingFunction.applyAsShort(key); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } @@ -2178,13 +2169,22 @@ protected short supplyIfAbsentNonDefault(int hash, int key, ShortSupplier valueP } } - protected short computeIfPresent(int hash, int key, IntShortUnaryOperator mappingFunction) { + protected short supplyIfAbsentNonDefault(int hash, int key, ShortSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0) return getDefaultReturnValue(); - short newValue = mappingFunction.applyAsShort(key, values[index]); - values[index] = newValue; + if(index < 0) { + short newValue = valueProvider.getAsShort(); + if(newValue == getDefaultReturnValue()) return newValue; + insert(-index-1, key, newValue); + return newValue; + } + short newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = valueProvider.getAsShort(); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } finally { diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2BooleanOpenCustomHashMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2BooleanOpenCustomHashMap.java index ba3c8c87..d22984b4 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2BooleanOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2BooleanOpenCustomHashMap.java @@ -440,30 +440,24 @@ public boolean computeBoolean(int key, IntBooleanUnaryOperator mappingFunction) } @Override - public boolean computeBooleanNonDefault(int key, IntBooleanUnaryOperator mappingFunction) { + public boolean computeBooleanIfAbsent(int key, IntPredicate mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + boolean newValue = mappingFunction.test(key); insert(-index-1, key, newValue); return newValue; } - boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + boolean newValue = values[index]; return newValue; } - + @Override - public boolean computeBooleanIfAbsent(int key, IntPredicate mappingFunction) { - Objects.requireNonNull(mappingFunction); + public boolean supplyBooleanIfAbsent(int key, BooleanSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - boolean newValue = mappingFunction.test(key); + boolean newValue = valueProvider.getAsBoolean(); insert(-index-1, key, newValue); return newValue; } @@ -472,34 +466,50 @@ public boolean computeBooleanIfAbsent(int key, IntPredicate mappingFunction) { } @Override - public boolean computeBooleanIfAbsentNonDefault(int key, IntPredicate mappingFunction) { + public boolean computeBooleanIfPresent(int key, IntBooleanUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public boolean computeBooleanNonDefault(int key, IntBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - boolean newValue = mappingFunction.test(key); + boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - boolean newValue = values[index]; + boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.test(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public boolean supplyBooleanIfAbsent(int key, BooleanSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public boolean computeBooleanIfAbsentNonDefault(int key, IntPredicate mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - boolean newValue = valueProvider.getAsBoolean(); + boolean newValue = mappingFunction.test(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } boolean newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.test(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -522,16 +532,6 @@ public boolean supplyBooleanIfAbsentNonDefault(int key, BooleanSupplier valuePro return newValue; } - @Override - public boolean computeBooleanIfPresent(int key, IntBooleanUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public boolean computeBooleanIfPresentNonDefault(int key, IntBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2ByteOpenCustomHashMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2ByteOpenCustomHashMap.java index 1a67b0c4..9a31c732 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2ByteOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2ByteOpenCustomHashMap.java @@ -462,30 +462,24 @@ public byte computeByte(int key, IntByteUnaryOperator mappingFunction) { } @Override - public byte computeByteNonDefault(int key, IntByteUnaryOperator mappingFunction) { + public byte computeByteIfAbsent(int key, Int2ByteFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + byte newValue = mappingFunction.applyAsByte(key); insert(-index-1, key, newValue); return newValue; } - byte newValue = mappingFunction.applyAsByte(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + byte newValue = values[index]; return newValue; } - + @Override - public byte computeByteIfAbsent(int key, Int2ByteFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public byte supplyByteIfAbsent(int key, ByteSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = valueProvider.getAsByte(); insert(-index-1, key, newValue); return newValue; } @@ -494,34 +488,50 @@ public byte computeByteIfAbsent(int key, Int2ByteFunction mappingFunction) { } @Override - public byte computeByteIfAbsentNonDefault(int key, Int2ByteFunction mappingFunction) { + public byte computeByteIfPresent(int key, IntByteUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + byte newValue = mappingFunction.applyAsByte(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public byte computeByteNonDefault(int key, IntByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - byte newValue = values[index]; + byte newValue = mappingFunction.applyAsByte(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsByte(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public byte supplyByteIfAbsent(int key, ByteSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public byte computeByteIfAbsentNonDefault(int key, Int2ByteFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - byte newValue = valueProvider.getAsInt(); + byte newValue = mappingFunction.applyAsByte(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } byte newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsByte(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -530,30 +540,20 @@ public byte supplyByteIfAbsentNonDefault(int key, ByteSupplier valueProvider) { Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - byte newValue = valueProvider.getAsInt(); + byte newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } byte newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public byte computeByteIfPresent(int key, IntByteUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - byte newValue = mappingFunction.applyAsByte(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public byte computeByteIfPresentNonDefault(int key, IntByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2CharOpenCustomHashMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2CharOpenCustomHashMap.java index 0968c846..c41498ed 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2CharOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2CharOpenCustomHashMap.java @@ -462,30 +462,24 @@ public char computeChar(int key, IntCharUnaryOperator mappingFunction) { } @Override - public char computeCharNonDefault(int key, IntCharUnaryOperator mappingFunction) { + public char computeCharIfAbsent(int key, Int2CharFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + char newValue = mappingFunction.applyAsChar(key); insert(-index-1, key, newValue); return newValue; } - char newValue = mappingFunction.applyAsChar(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + char newValue = values[index]; return newValue; } - + @Override - public char computeCharIfAbsent(int key, Int2CharFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public char supplyCharIfAbsent(int key, CharSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = valueProvider.getAsChar(); insert(-index-1, key, newValue); return newValue; } @@ -494,34 +488,50 @@ public char computeCharIfAbsent(int key, Int2CharFunction mappingFunction) { } @Override - public char computeCharIfAbsentNonDefault(int key, Int2CharFunction mappingFunction) { + public char computeCharIfPresent(int key, IntCharUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + char newValue = mappingFunction.applyAsChar(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public char computeCharNonDefault(int key, IntCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - char newValue = values[index]; + char newValue = mappingFunction.applyAsChar(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsChar(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public char supplyCharIfAbsent(int key, CharSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public char computeCharIfAbsentNonDefault(int key, Int2CharFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - char newValue = valueProvider.getAsInt(); + char newValue = mappingFunction.applyAsChar(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } char newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsChar(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -530,30 +540,20 @@ public char supplyCharIfAbsentNonDefault(int key, CharSupplier valueProvider) { Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - char newValue = valueProvider.getAsInt(); + char newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } char newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public char computeCharIfPresent(int key, IntCharUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - char newValue = mappingFunction.applyAsChar(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public char computeCharIfPresentNonDefault(int key, IntCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2DoubleOpenCustomHashMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2DoubleOpenCustomHashMap.java index b5fc27c1..b5e8e24a 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2DoubleOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2DoubleOpenCustomHashMap.java @@ -462,30 +462,24 @@ public double computeDouble(int key, IntDoubleUnaryOperator mappingFunction) { } @Override - public double computeDoubleNonDefault(int key, IntDoubleUnaryOperator mappingFunction) { + public double computeDoubleIfAbsent(int key, Int2DoubleFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + double newValue = mappingFunction.applyAsDouble(key); insert(-index-1, key, newValue); return newValue; } - double newValue = mappingFunction.applyAsDouble(key, values[index]); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + double newValue = values[index]; return newValue; } - + @Override - public double computeDoubleIfAbsent(int key, Int2DoubleFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public double supplyDoubleIfAbsent(int key, DoubleSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = valueProvider.getAsDouble(); insert(-index-1, key, newValue); return newValue; } @@ -494,34 +488,50 @@ public double computeDoubleIfAbsent(int key, Int2DoubleFunction mappingFunction) } @Override - public double computeDoubleIfAbsentNonDefault(int key, Int2DoubleFunction mappingFunction) { + public double computeDoubleIfPresent(int key, IntDoubleUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + double newValue = mappingFunction.applyAsDouble(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public double computeDoubleNonDefault(int key, IntDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } - double newValue = values[index]; + double newValue = mappingFunction.applyAsDouble(key, values[index]); if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - newValue = mappingFunction.applyAsDouble(key); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public double supplyDoubleIfAbsent(int key, DoubleSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public double computeDoubleIfAbsentNonDefault(int key, Int2DoubleFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - double newValue = valueProvider.getAsDouble(); + double newValue = mappingFunction.applyAsDouble(key); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } double newValue = values[index]; + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { + newValue = mappingFunction.applyAsDouble(key); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + values[index] = newValue; + } return newValue; } @@ -544,16 +554,6 @@ public double supplyDoubleIfAbsentNonDefault(int key, DoubleSupplier valueProvid return newValue; } - @Override - public double computeDoubleIfPresent(int key, IntDoubleUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - double newValue = mappingFunction.applyAsDouble(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public double computeDoubleIfPresentNonDefault(int key, IntDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2FloatOpenCustomHashMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2FloatOpenCustomHashMap.java index 3fd3f32f..d4542c21 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2FloatOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2FloatOpenCustomHashMap.java @@ -462,30 +462,24 @@ public float computeFloat(int key, IntFloatUnaryOperator mappingFunction) { } @Override - public float computeFloatNonDefault(int key, IntFloatUnaryOperator mappingFunction) { + public float computeFloatIfAbsent(int key, Int2FloatFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + float newValue = mappingFunction.applyAsFloat(key); insert(-index-1, key, newValue); return newValue; } - float newValue = mappingFunction.applyAsFloat(key, values[index]); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + float newValue = values[index]; return newValue; } - + @Override - public float computeFloatIfAbsent(int key, Int2FloatFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public float supplyFloatIfAbsent(int key, FloatSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = valueProvider.getAsFloat(); insert(-index-1, key, newValue); return newValue; } @@ -494,34 +488,50 @@ public float computeFloatIfAbsent(int key, Int2FloatFunction mappingFunction) { } @Override - public float computeFloatIfAbsentNonDefault(int key, Int2FloatFunction mappingFunction) { + public float computeFloatIfPresent(int key, IntFloatUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + float newValue = mappingFunction.applyAsFloat(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public float computeFloatNonDefault(int key, IntFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } - float newValue = values[index]; + float newValue = mappingFunction.applyAsFloat(key, values[index]); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - newValue = mappingFunction.applyAsFloat(key); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public float supplyFloatIfAbsent(int key, FloatSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public float computeFloatIfAbsentNonDefault(int key, Int2FloatFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - float newValue = valueProvider.getAsDouble(); + float newValue = mappingFunction.applyAsFloat(key); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } float newValue = values[index]; + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { + newValue = mappingFunction.applyAsFloat(key); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + values[index] = newValue; + } return newValue; } @@ -530,30 +540,20 @@ public float supplyFloatIfAbsentNonDefault(int key, FloatSupplier valueProvider) Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - float newValue = valueProvider.getAsDouble(); + float newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } float newValue = values[index]; if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - newValue = valueProvider.getAsDouble(); + newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; values[index] = newValue; } return newValue; } - @Override - public float computeFloatIfPresent(int key, IntFloatUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - float newValue = mappingFunction.applyAsFloat(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public float computeFloatIfPresentNonDefault(int key, IntFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2IntOpenCustomHashMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2IntOpenCustomHashMap.java index d816420a..3e11e172 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2IntOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2IntOpenCustomHashMap.java @@ -454,30 +454,24 @@ public int computeInt(int key, IntIntUnaryOperator mappingFunction) { } @Override - public int computeIntNonDefault(int key, IntIntUnaryOperator mappingFunction) { + public int computeIntIfAbsent(int key, IntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + int newValue = mappingFunction.applyAsInt(key); insert(-index-1, key, newValue); return newValue; } - int newValue = mappingFunction.applyAsInt(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + int newValue = values[index]; return newValue; } - + @Override - public int computeIntIfAbsent(int key, IntUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); + public int supplyIntIfAbsent(int key, IntSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = valueProvider.getAsInt(); insert(-index-1, key, newValue); return newValue; } @@ -486,34 +480,50 @@ public int computeIntIfAbsent(int key, IntUnaryOperator mappingFunction) { } @Override - public int computeIntIfAbsentNonDefault(int key, IntUnaryOperator mappingFunction) { + public int computeIntIfPresent(int key, IntIntUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + int newValue = mappingFunction.applyAsInt(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public int computeIntNonDefault(int key, IntIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - int newValue = values[index]; + int newValue = mappingFunction.applyAsInt(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsInt(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public int supplyIntIfAbsent(int key, IntSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public int computeIntIfAbsentNonDefault(int key, IntUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - int newValue = valueProvider.getAsInt(); + int newValue = mappingFunction.applyAsInt(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } int newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsInt(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -536,16 +546,6 @@ public int supplyIntIfAbsentNonDefault(int key, IntSupplier valueProvider) { return newValue; } - @Override - public int computeIntIfPresent(int key, IntIntUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - int newValue = mappingFunction.applyAsInt(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public int computeIntIfPresentNonDefault(int key, IntIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2LongOpenCustomHashMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2LongOpenCustomHashMap.java index 82e7481a..f813d92a 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2LongOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2LongOpenCustomHashMap.java @@ -462,30 +462,24 @@ public long computeLong(int key, IntLongUnaryOperator mappingFunction) { } @Override - public long computeLongNonDefault(int key, IntLongUnaryOperator mappingFunction) { + public long computeLongIfAbsent(int key, Int2LongFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + long newValue = mappingFunction.applyAsLong(key); insert(-index-1, key, newValue); return newValue; } - long newValue = mappingFunction.applyAsLong(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + long newValue = values[index]; return newValue; } - + @Override - public long computeLongIfAbsent(int key, Int2LongFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public long supplyLongIfAbsent(int key, LongSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = valueProvider.getAsLong(); insert(-index-1, key, newValue); return newValue; } @@ -494,34 +488,50 @@ public long computeLongIfAbsent(int key, Int2LongFunction mappingFunction) { } @Override - public long computeLongIfAbsentNonDefault(int key, Int2LongFunction mappingFunction) { + public long computeLongIfPresent(int key, IntLongUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + long newValue = mappingFunction.applyAsLong(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public long computeLongNonDefault(int key, IntLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - long newValue = values[index]; + long newValue = mappingFunction.applyAsLong(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsLong(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public long supplyLongIfAbsent(int key, LongSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public long computeLongIfAbsentNonDefault(int key, Int2LongFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - long newValue = valueProvider.getAsLong(); + long newValue = mappingFunction.applyAsLong(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } long newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsLong(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -544,16 +554,6 @@ public long supplyLongIfAbsentNonDefault(int key, LongSupplier valueProvider) { return newValue; } - @Override - public long computeLongIfPresent(int key, IntLongUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - long newValue = mappingFunction.applyAsLong(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public long computeLongIfPresentNonDefault(int key, IntLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2ObjectOpenCustomHashMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2ObjectOpenCustomHashMap.java index b19a5718..c09cb152 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2ObjectOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2ObjectOpenCustomHashMap.java @@ -431,25 +431,6 @@ public V compute(int key, IntObjectUnaryOperator mappingFunction) { return newValue; } - @Override - public V computeNonDefault(int key, IntObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) { - V newValue = mappingFunction.apply(key, getDefaultReturnValue()); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = mappingFunction.apply(key, values[index]); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; - return newValue; - } - @Override public V computeIfAbsent(int key, IntFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -468,26 +449,7 @@ public V computeIfAbsent(int key, IntFunction mappingFunction) { } return newValue; } - - @Override - public V computeIfAbsentNonDefault(int key, IntFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) { - V newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = values[index]; - if(Objects.equals(newValue, getDefaultReturnValue())) { - newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - values[index] = newValue; - } - return newValue; - } - + @Override public V supplyIfAbsent(int key, ObjectSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -507,25 +469,6 @@ public V supplyIfAbsent(int key, ObjectSupplier valueProvider) { return newValue; } - @Override - public V supplyIfAbsentNonDefault(int key, ObjectSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - int index = findIndex(key); - if(index < 0) { - V newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = values[index]; - if(Objects.equals(newValue, getDefaultReturnValue())) { - newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - values[index] = newValue; - } - return newValue; - } - @Override public V computeIfPresent(int key, IntObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -540,20 +483,6 @@ public V computeIfPresent(int key, IntObjectUnaryOperator mappingFunction) { return newValue; } - @Override - public V computeIfPresentNonDefault(int key, IntObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0 || Objects.equals(values[index], getDefaultReturnValue())) return getDefaultReturnValue(); - V newValue = mappingFunction.apply(key, values[index]); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; - return newValue; - } - @Override public V merge(int key, V value, ObjectObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2ShortOpenCustomHashMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2ShortOpenCustomHashMap.java index 0b7d5194..2e1029d0 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2ShortOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/customHash/Int2ShortOpenCustomHashMap.java @@ -462,30 +462,24 @@ public short computeShort(int key, IntShortUnaryOperator mappingFunction) { } @Override - public short computeShortNonDefault(int key, IntShortUnaryOperator mappingFunction) { + public short computeShortIfAbsent(int key, Int2ShortFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + short newValue = mappingFunction.applyAsShort(key); insert(-index-1, key, newValue); return newValue; } - short newValue = mappingFunction.applyAsShort(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + short newValue = values[index]; return newValue; } - + @Override - public short computeShortIfAbsent(int key, Int2ShortFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public short supplyShortIfAbsent(int key, ShortSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = valueProvider.getAsShort(); insert(-index-1, key, newValue); return newValue; } @@ -494,34 +488,50 @@ public short computeShortIfAbsent(int key, Int2ShortFunction mappingFunction) { } @Override - public short computeShortIfAbsentNonDefault(int key, Int2ShortFunction mappingFunction) { + public short computeShortIfPresent(int key, IntShortUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + short newValue = mappingFunction.applyAsShort(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public short computeShortNonDefault(int key, IntShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - short newValue = values[index]; + short newValue = mappingFunction.applyAsShort(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsShort(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public short supplyShortIfAbsent(int key, ShortSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public short computeShortIfAbsentNonDefault(int key, Int2ShortFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - short newValue = valueProvider.getAsInt(); + short newValue = mappingFunction.applyAsShort(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } short newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsShort(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -530,30 +540,20 @@ public short supplyShortIfAbsentNonDefault(int key, ShortSupplier valueProvider) Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - short newValue = valueProvider.getAsInt(); + short newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } short newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public short computeShortIfPresent(int key, IntShortUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - short newValue = mappingFunction.applyAsShort(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public short computeShortIfPresentNonDefault(int key, IntShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2BooleanOpenHashMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2BooleanOpenHashMap.java index db27053e..fec92346 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2BooleanOpenHashMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2BooleanOpenHashMap.java @@ -407,68 +407,78 @@ public boolean computeBoolean(int key, IntBooleanUnaryOperator mappingFunction) values[index] = newValue; return newValue; } - + @Override - public boolean computeBooleanNonDefault(int key, IntBooleanUnaryOperator mappingFunction) { + public boolean computeBooleanIfAbsent(int key, IntPredicate mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + boolean newValue = mappingFunction.test(key); insert(-index-1, key, newValue); return newValue; } - boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + boolean newValue = values[index]; return newValue; } @Override - public boolean computeBooleanIfAbsent(int key, IntPredicate mappingFunction) { - Objects.requireNonNull(mappingFunction); + public boolean supplyBooleanIfAbsent(int key, BooleanSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - boolean newValue = mappingFunction.test(key); + boolean newValue = valueProvider.getAsBoolean(); insert(-index-1, key, newValue); return newValue; } boolean newValue = values[index]; return newValue; } + + @Override + public boolean computeBooleanIfPresent(int key, IntBooleanUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public boolean computeBooleanIfAbsentNonDefault(int key, IntPredicate mappingFunction) { + public boolean computeBooleanNonDefault(int key, IntBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - boolean newValue = mappingFunction.test(key); + boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - boolean newValue = values[index]; + boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.test(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public boolean supplyBooleanIfAbsent(int key, BooleanSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public boolean computeBooleanIfAbsentNonDefault(int key, IntPredicate mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - boolean newValue = valueProvider.getAsBoolean(); + boolean newValue = mappingFunction.test(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } boolean newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.test(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -491,16 +501,6 @@ public boolean supplyBooleanIfAbsentNonDefault(int key, BooleanSupplier valuePro return newValue; } - @Override - public boolean computeBooleanIfPresent(int key, IntBooleanUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public boolean computeBooleanIfPresentNonDefault(int key, IntBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2ByteOpenHashMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2ByteOpenHashMap.java index 4aaf17ff..1b18c500 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2ByteOpenHashMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2ByteOpenHashMap.java @@ -429,68 +429,78 @@ public byte computeByte(int key, IntByteUnaryOperator mappingFunction) { values[index] = newValue; return newValue; } - + @Override - public byte computeByteNonDefault(int key, IntByteUnaryOperator mappingFunction) { + public byte computeByteIfAbsent(int key, Int2ByteFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + byte newValue = mappingFunction.applyAsByte(key); insert(-index-1, key, newValue); return newValue; } - byte newValue = mappingFunction.applyAsByte(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + byte newValue = values[index]; return newValue; } @Override - public byte computeByteIfAbsent(int key, Int2ByteFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public byte supplyByteIfAbsent(int key, ByteSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = valueProvider.getAsByte(); insert(-index-1, key, newValue); return newValue; } byte newValue = values[index]; return newValue; } + + @Override + public byte computeByteIfPresent(int key, IntByteUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + byte newValue = mappingFunction.applyAsByte(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public byte computeByteIfAbsentNonDefault(int key, Int2ByteFunction mappingFunction) { + public byte computeByteNonDefault(int key, IntByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - byte newValue = values[index]; + byte newValue = mappingFunction.applyAsByte(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsByte(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public byte supplyByteIfAbsent(int key, ByteSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public byte computeByteIfAbsentNonDefault(int key, Int2ByteFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - byte newValue = valueProvider.getAsInt(); + byte newValue = mappingFunction.applyAsByte(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } byte newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsByte(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -499,30 +509,20 @@ public byte supplyByteIfAbsentNonDefault(int key, ByteSupplier valueProvider) { Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - byte newValue = valueProvider.getAsInt(); + byte newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } byte newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public byte computeByteIfPresent(int key, IntByteUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - byte newValue = mappingFunction.applyAsByte(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public byte computeByteIfPresentNonDefault(int key, IntByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2CharOpenHashMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2CharOpenHashMap.java index f2ab45c4..ac2e07c2 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2CharOpenHashMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2CharOpenHashMap.java @@ -429,68 +429,78 @@ public char computeChar(int key, IntCharUnaryOperator mappingFunction) { values[index] = newValue; return newValue; } - + @Override - public char computeCharNonDefault(int key, IntCharUnaryOperator mappingFunction) { + public char computeCharIfAbsent(int key, Int2CharFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + char newValue = mappingFunction.applyAsChar(key); insert(-index-1, key, newValue); return newValue; } - char newValue = mappingFunction.applyAsChar(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + char newValue = values[index]; return newValue; } @Override - public char computeCharIfAbsent(int key, Int2CharFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public char supplyCharIfAbsent(int key, CharSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = valueProvider.getAsChar(); insert(-index-1, key, newValue); return newValue; } char newValue = values[index]; return newValue; } + + @Override + public char computeCharIfPresent(int key, IntCharUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + char newValue = mappingFunction.applyAsChar(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public char computeCharIfAbsentNonDefault(int key, Int2CharFunction mappingFunction) { + public char computeCharNonDefault(int key, IntCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - char newValue = values[index]; + char newValue = mappingFunction.applyAsChar(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsChar(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public char supplyCharIfAbsent(int key, CharSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public char computeCharIfAbsentNonDefault(int key, Int2CharFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - char newValue = valueProvider.getAsInt(); + char newValue = mappingFunction.applyAsChar(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } char newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsChar(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -499,30 +509,20 @@ public char supplyCharIfAbsentNonDefault(int key, CharSupplier valueProvider) { Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - char newValue = valueProvider.getAsInt(); + char newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } char newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public char computeCharIfPresent(int key, IntCharUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - char newValue = mappingFunction.applyAsChar(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public char computeCharIfPresentNonDefault(int key, IntCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2DoubleOpenHashMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2DoubleOpenHashMap.java index f6e49cbe..268326ab 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2DoubleOpenHashMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2DoubleOpenHashMap.java @@ -429,68 +429,78 @@ public double computeDouble(int key, IntDoubleUnaryOperator mappingFunction) { values[index] = newValue; return newValue; } - + @Override - public double computeDoubleNonDefault(int key, IntDoubleUnaryOperator mappingFunction) { + public double computeDoubleIfAbsent(int key, Int2DoubleFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + double newValue = mappingFunction.applyAsDouble(key); insert(-index-1, key, newValue); return newValue; } - double newValue = mappingFunction.applyAsDouble(key, values[index]); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + double newValue = values[index]; return newValue; } @Override - public double computeDoubleIfAbsent(int key, Int2DoubleFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public double supplyDoubleIfAbsent(int key, DoubleSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = valueProvider.getAsDouble(); insert(-index-1, key, newValue); return newValue; } double newValue = values[index]; return newValue; } + + @Override + public double computeDoubleIfPresent(int key, IntDoubleUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + double newValue = mappingFunction.applyAsDouble(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public double computeDoubleIfAbsentNonDefault(int key, Int2DoubleFunction mappingFunction) { + public double computeDoubleNonDefault(int key, IntDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } - double newValue = values[index]; + double newValue = mappingFunction.applyAsDouble(key, values[index]); if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - newValue = mappingFunction.applyAsDouble(key); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public double supplyDoubleIfAbsent(int key, DoubleSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public double computeDoubleIfAbsentNonDefault(int key, Int2DoubleFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - double newValue = valueProvider.getAsDouble(); + double newValue = mappingFunction.applyAsDouble(key); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } double newValue = values[index]; + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { + newValue = mappingFunction.applyAsDouble(key); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + values[index] = newValue; + } return newValue; } @@ -513,16 +523,6 @@ public double supplyDoubleIfAbsentNonDefault(int key, DoubleSupplier valueProvid return newValue; } - @Override - public double computeDoubleIfPresent(int key, IntDoubleUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - double newValue = mappingFunction.applyAsDouble(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public double computeDoubleIfPresentNonDefault(int key, IntDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2FloatOpenHashMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2FloatOpenHashMap.java index 74c7ad29..ce2a7636 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2FloatOpenHashMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2FloatOpenHashMap.java @@ -429,68 +429,78 @@ public float computeFloat(int key, IntFloatUnaryOperator mappingFunction) { values[index] = newValue; return newValue; } - + @Override - public float computeFloatNonDefault(int key, IntFloatUnaryOperator mappingFunction) { + public float computeFloatIfAbsent(int key, Int2FloatFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + float newValue = mappingFunction.applyAsFloat(key); insert(-index-1, key, newValue); return newValue; } - float newValue = mappingFunction.applyAsFloat(key, values[index]); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + float newValue = values[index]; return newValue; } @Override - public float computeFloatIfAbsent(int key, Int2FloatFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public float supplyFloatIfAbsent(int key, FloatSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = valueProvider.getAsFloat(); insert(-index-1, key, newValue); return newValue; } float newValue = values[index]; return newValue; } + + @Override + public float computeFloatIfPresent(int key, IntFloatUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + float newValue = mappingFunction.applyAsFloat(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public float computeFloatIfAbsentNonDefault(int key, Int2FloatFunction mappingFunction) { + public float computeFloatNonDefault(int key, IntFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } - float newValue = values[index]; + float newValue = mappingFunction.applyAsFloat(key, values[index]); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - newValue = mappingFunction.applyAsFloat(key); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public float supplyFloatIfAbsent(int key, FloatSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public float computeFloatIfAbsentNonDefault(int key, Int2FloatFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - float newValue = valueProvider.getAsDouble(); + float newValue = mappingFunction.applyAsFloat(key); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } float newValue = values[index]; + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { + newValue = mappingFunction.applyAsFloat(key); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + values[index] = newValue; + } return newValue; } @@ -499,30 +509,20 @@ public float supplyFloatIfAbsentNonDefault(int key, FloatSupplier valueProvider) Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - float newValue = valueProvider.getAsDouble(); + float newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } float newValue = values[index]; if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - newValue = valueProvider.getAsDouble(); + newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; values[index] = newValue; } return newValue; } - @Override - public float computeFloatIfPresent(int key, IntFloatUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - float newValue = mappingFunction.applyAsFloat(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public float computeFloatIfPresentNonDefault(int key, IntFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2IntOpenHashMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2IntOpenHashMap.java index 983efa38..cd235ce9 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2IntOpenHashMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2IntOpenHashMap.java @@ -423,68 +423,78 @@ public int computeInt(int key, IntIntUnaryOperator mappingFunction) { values[index] = newValue; return newValue; } - + @Override - public int computeIntNonDefault(int key, IntIntUnaryOperator mappingFunction) { + public int computeIntIfAbsent(int key, IntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + int newValue = mappingFunction.applyAsInt(key); insert(-index-1, key, newValue); return newValue; } - int newValue = mappingFunction.applyAsInt(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + int newValue = values[index]; return newValue; } @Override - public int computeIntIfAbsent(int key, IntUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); + public int supplyIntIfAbsent(int key, IntSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = valueProvider.getAsInt(); insert(-index-1, key, newValue); return newValue; } int newValue = values[index]; return newValue; } + + @Override + public int computeIntIfPresent(int key, IntIntUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + int newValue = mappingFunction.applyAsInt(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public int computeIntIfAbsentNonDefault(int key, IntUnaryOperator mappingFunction) { + public int computeIntNonDefault(int key, IntIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - int newValue = values[index]; + int newValue = mappingFunction.applyAsInt(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsInt(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public int supplyIntIfAbsent(int key, IntSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public int computeIntIfAbsentNonDefault(int key, IntUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - int newValue = valueProvider.getAsInt(); + int newValue = mappingFunction.applyAsInt(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } int newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsInt(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -507,16 +517,6 @@ public int supplyIntIfAbsentNonDefault(int key, IntSupplier valueProvider) { return newValue; } - @Override - public int computeIntIfPresent(int key, IntIntUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - int newValue = mappingFunction.applyAsInt(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public int computeIntIfPresentNonDefault(int key, IntIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2LongOpenHashMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2LongOpenHashMap.java index 6651d4f5..b5d9524e 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2LongOpenHashMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2LongOpenHashMap.java @@ -429,68 +429,78 @@ public long computeLong(int key, IntLongUnaryOperator mappingFunction) { values[index] = newValue; return newValue; } - + @Override - public long computeLongNonDefault(int key, IntLongUnaryOperator mappingFunction) { + public long computeLongIfAbsent(int key, Int2LongFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + long newValue = mappingFunction.applyAsLong(key); insert(-index-1, key, newValue); return newValue; } - long newValue = mappingFunction.applyAsLong(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + long newValue = values[index]; return newValue; } @Override - public long computeLongIfAbsent(int key, Int2LongFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public long supplyLongIfAbsent(int key, LongSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = valueProvider.getAsLong(); insert(-index-1, key, newValue); return newValue; } long newValue = values[index]; return newValue; } + + @Override + public long computeLongIfPresent(int key, IntLongUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + long newValue = mappingFunction.applyAsLong(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public long computeLongIfAbsentNonDefault(int key, Int2LongFunction mappingFunction) { + public long computeLongNonDefault(int key, IntLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - long newValue = values[index]; + long newValue = mappingFunction.applyAsLong(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsLong(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public long supplyLongIfAbsent(int key, LongSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public long computeLongIfAbsentNonDefault(int key, Int2LongFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - long newValue = valueProvider.getAsLong(); + long newValue = mappingFunction.applyAsLong(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } long newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsLong(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -513,16 +523,6 @@ public long supplyLongIfAbsentNonDefault(int key, LongSupplier valueProvider) { return newValue; } - @Override - public long computeLongIfPresent(int key, IntLongUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - long newValue = mappingFunction.applyAsLong(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public long computeLongIfPresentNonDefault(int key, IntLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2ObjectOpenHashMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2ObjectOpenHashMap.java index 14582d6d..17d07cff 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2ObjectOpenHashMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2ObjectOpenHashMap.java @@ -400,26 +400,7 @@ public V compute(int key, IntObjectUnaryOperator mappingFunction) { values[index] = newValue; return newValue; } - - @Override - public V computeNonDefault(int key, IntObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) { - V newValue = mappingFunction.apply(key, getDefaultReturnValue()); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = mappingFunction.apply(key, values[index]); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; - return newValue; - } - + @Override public V computeIfAbsent(int key, IntFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -439,25 +420,6 @@ public V computeIfAbsent(int key, IntFunction mappingFunction) { return newValue; } - @Override - public V computeIfAbsentNonDefault(int key, IntFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) { - V newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = values[index]; - if(Objects.equals(newValue, getDefaultReturnValue())) { - newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - values[index] = newValue; - } - return newValue; - } - @Override public V supplyIfAbsent(int key, ObjectSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -476,26 +438,7 @@ public V supplyIfAbsent(int key, ObjectSupplier valueProvider) { } return newValue; } - - @Override - public V supplyIfAbsentNonDefault(int key, ObjectSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - int index = findIndex(key); - if(index < 0) { - V newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = values[index]; - if(Objects.equals(newValue, getDefaultReturnValue())) { - newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - values[index] = newValue; - } - return newValue; - } - + @Override public V computeIfPresent(int key, IntObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -510,20 +453,6 @@ public V computeIfPresent(int key, IntObjectUnaryOperator mappingFunction) { return newValue; } - @Override - public V computeIfPresentNonDefault(int key, IntObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0 || Objects.equals(values[index], getDefaultReturnValue())) return getDefaultReturnValue(); - V newValue = mappingFunction.apply(key, values[index]); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; - return newValue; - } - @Override public V merge(int key, V value, ObjectObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2ShortOpenHashMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2ShortOpenHashMap.java index 8c6d2658..50ac2392 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2ShortOpenHashMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/hash/Int2ShortOpenHashMap.java @@ -429,68 +429,78 @@ public short computeShort(int key, IntShortUnaryOperator mappingFunction) { values[index] = newValue; return newValue; } - + @Override - public short computeShortNonDefault(int key, IntShortUnaryOperator mappingFunction) { + public short computeShortIfAbsent(int key, Int2ShortFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + short newValue = mappingFunction.applyAsShort(key); insert(-index-1, key, newValue); return newValue; } - short newValue = mappingFunction.applyAsShort(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + short newValue = values[index]; return newValue; } @Override - public short computeShortIfAbsent(int key, Int2ShortFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public short supplyShortIfAbsent(int key, ShortSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = valueProvider.getAsShort(); insert(-index-1, key, newValue); return newValue; } short newValue = values[index]; return newValue; } + + @Override + public short computeShortIfPresent(int key, IntShortUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + short newValue = mappingFunction.applyAsShort(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public short computeShortIfAbsentNonDefault(int key, Int2ShortFunction mappingFunction) { + public short computeShortNonDefault(int key, IntShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - short newValue = values[index]; + short newValue = mappingFunction.applyAsShort(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsShort(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public short supplyShortIfAbsent(int key, ShortSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public short computeShortIfAbsentNonDefault(int key, Int2ShortFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - short newValue = valueProvider.getAsInt(); + short newValue = mappingFunction.applyAsShort(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } short newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsShort(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -499,30 +509,20 @@ public short supplyShortIfAbsentNonDefault(int key, ShortSupplier valueProvider) Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - short newValue = valueProvider.getAsInt(); + short newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } short newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public short computeShortIfPresent(int key, IntShortUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - short newValue = mappingFunction.applyAsShort(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public short computeShortIfPresentNonDefault(int key, IntShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/immutable/ImmutableInt2BooleanOpenHashMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/immutable/ImmutableInt2BooleanOpenHashMap.java index c0677860..a737fed4 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/immutable/ImmutableInt2BooleanOpenHashMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/immutable/ImmutableInt2BooleanOpenHashMap.java @@ -412,20 +412,19 @@ public void forEach(IntBooleanConsumer action) { @Override public boolean computeBoolean(int key, IntBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanNonDefault(int key, IntBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean computeBooleanIfAbsent(int key, IntPredicate mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanIfAbsentNonDefault(int key, IntPredicate mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean supplyBooleanIfAbsent(int key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public boolean supplyBooleanIfAbsentNonDefault(int key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public boolean computeBooleanIfPresent(int key, IntBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override + public boolean computeBooleanNonDefault(int key, IntBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public boolean computeBooleanIfAbsentNonDefault(int key, IntPredicate mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public boolean supplyBooleanIfAbsentNonDefault(int key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } + @Override public boolean computeBooleanIfPresentNonDefault(int key, IntBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean mergeBoolean(int key, boolean value, BooleanBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/immutable/ImmutableInt2ByteOpenHashMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/immutable/ImmutableInt2ByteOpenHashMap.java index fec320df..03acab0e 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/immutable/ImmutableInt2ByteOpenHashMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/immutable/ImmutableInt2ByteOpenHashMap.java @@ -417,20 +417,19 @@ public void forEach(IntByteConsumer action) { @Override public byte computeByte(int key, IntByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteNonDefault(int key, IntByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte computeByteIfAbsent(int key, Int2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteIfAbsentNonDefault(int key, Int2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte supplyByteIfAbsent(int key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public byte supplyByteIfAbsentNonDefault(int key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public byte computeByteIfPresent(int key, IntByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override + public byte computeByteNonDefault(int key, IntByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public byte computeByteIfAbsentNonDefault(int key, Int2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public byte supplyByteIfAbsentNonDefault(int key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } + @Override public byte computeByteIfPresentNonDefault(int key, IntByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte mergeByte(int key, byte value, ByteByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/immutable/ImmutableInt2CharOpenHashMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/immutable/ImmutableInt2CharOpenHashMap.java index 4ecfb6f7..c814033e 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/immutable/ImmutableInt2CharOpenHashMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/immutable/ImmutableInt2CharOpenHashMap.java @@ -417,20 +417,19 @@ public void forEach(IntCharConsumer action) { @Override public char computeChar(int key, IntCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharNonDefault(int key, IntCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char computeCharIfAbsent(int key, Int2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharIfAbsentNonDefault(int key, Int2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char supplyCharIfAbsent(int key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public char supplyCharIfAbsentNonDefault(int key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public char computeCharIfPresent(int key, IntCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override + public char computeCharNonDefault(int key, IntCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public char computeCharIfAbsentNonDefault(int key, Int2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public char supplyCharIfAbsentNonDefault(int key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } + @Override public char computeCharIfPresentNonDefault(int key, IntCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char mergeChar(int key, char value, CharCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/immutable/ImmutableInt2DoubleOpenHashMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/immutable/ImmutableInt2DoubleOpenHashMap.java index 372a2a0a..518af429 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/immutable/ImmutableInt2DoubleOpenHashMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/immutable/ImmutableInt2DoubleOpenHashMap.java @@ -417,20 +417,19 @@ public void forEach(IntDoubleConsumer action) { @Override public double computeDouble(int key, IntDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleNonDefault(int key, IntDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double computeDoubleIfAbsent(int key, Int2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleIfAbsentNonDefault(int key, Int2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double supplyDoubleIfAbsent(int key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public double supplyDoubleIfAbsentNonDefault(int key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public double computeDoubleIfPresent(int key, IntDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override + public double computeDoubleNonDefault(int key, IntDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public double computeDoubleIfAbsentNonDefault(int key, Int2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public double supplyDoubleIfAbsentNonDefault(int key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } + @Override public double computeDoubleIfPresentNonDefault(int key, IntDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double mergeDouble(int key, double value, DoubleDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/immutable/ImmutableInt2FloatOpenHashMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/immutable/ImmutableInt2FloatOpenHashMap.java index 7853a986..7edc2c21 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/immutable/ImmutableInt2FloatOpenHashMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/immutable/ImmutableInt2FloatOpenHashMap.java @@ -417,20 +417,19 @@ public void forEach(IntFloatConsumer action) { @Override public float computeFloat(int key, IntFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatNonDefault(int key, IntFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float computeFloatIfAbsent(int key, Int2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatIfAbsentNonDefault(int key, Int2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float supplyFloatIfAbsent(int key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public float supplyFloatIfAbsentNonDefault(int key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public float computeFloatIfPresent(int key, IntFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override + public float computeFloatNonDefault(int key, IntFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public float computeFloatIfAbsentNonDefault(int key, Int2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public float supplyFloatIfAbsentNonDefault(int key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } + @Override public float computeFloatIfPresentNonDefault(int key, IntFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float mergeFloat(int key, float value, FloatFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/immutable/ImmutableInt2IntOpenHashMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/immutable/ImmutableInt2IntOpenHashMap.java index 2ceb3681..a487b3fd 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/immutable/ImmutableInt2IntOpenHashMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/immutable/ImmutableInt2IntOpenHashMap.java @@ -408,20 +408,19 @@ public void forEach(IntIntConsumer action) { @Override public int computeInt(int key, IntIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntNonDefault(int key, IntIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int computeIntIfAbsent(int key, IntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntIfAbsentNonDefault(int key, IntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int supplyIntIfAbsent(int key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public int supplyIntIfAbsentNonDefault(int key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public int computeIntIfPresent(int key, IntIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override + public int computeIntNonDefault(int key, IntIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public int computeIntIfAbsentNonDefault(int key, IntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public int supplyIntIfAbsentNonDefault(int key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } + @Override public int computeIntIfPresentNonDefault(int key, IntIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int mergeInt(int key, int value, IntIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/immutable/ImmutableInt2LongOpenHashMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/immutable/ImmutableInt2LongOpenHashMap.java index 89cf633a..17a53a10 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/immutable/ImmutableInt2LongOpenHashMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/immutable/ImmutableInt2LongOpenHashMap.java @@ -417,20 +417,19 @@ public void forEach(IntLongConsumer action) { @Override public long computeLong(int key, IntLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongNonDefault(int key, IntLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long computeLongIfAbsent(int key, Int2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongIfAbsentNonDefault(int key, Int2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long supplyLongIfAbsent(int key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public long supplyLongIfAbsentNonDefault(int key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public long computeLongIfPresent(int key, IntLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override + public long computeLongNonDefault(int key, IntLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public long computeLongIfAbsentNonDefault(int key, Int2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public long supplyLongIfAbsentNonDefault(int key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } + @Override public long computeLongIfPresentNonDefault(int key, IntLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long mergeLong(int key, long value, LongLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/immutable/ImmutableInt2ObjectOpenHashMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/immutable/ImmutableInt2ObjectOpenHashMap.java index df61e108..5556e87f 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/immutable/ImmutableInt2ObjectOpenHashMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/immutable/ImmutableInt2ObjectOpenHashMap.java @@ -396,20 +396,11 @@ public void forEach(IntObjectConsumer action) { @Override public V compute(int key, IntObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeNonDefault(int key, IntObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V computeIfAbsent(int key, IntFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeIfAbsentNonDefault(int key, IntFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V supplyIfAbsent(int key, ObjectSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public V supplyIfAbsentNonDefault(int key, ObjectSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public V computeIfPresent(int key, IntObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override - public V computeIfPresentNonDefault(int key, IntObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V merge(int key, V value, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/immutable/ImmutableInt2ShortOpenHashMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/immutable/ImmutableInt2ShortOpenHashMap.java index 5626046a..60975d5f 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/immutable/ImmutableInt2ShortOpenHashMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/immutable/ImmutableInt2ShortOpenHashMap.java @@ -417,20 +417,19 @@ public void forEach(IntShortConsumer action) { @Override public short computeShort(int key, IntShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortNonDefault(int key, IntShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short computeShortIfAbsent(int key, Int2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortIfAbsentNonDefault(int key, Int2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short supplyShortIfAbsent(int key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public short supplyShortIfAbsentNonDefault(int key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public short computeShortIfPresent(int key, IntShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override + public short computeShortNonDefault(int key, IntShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public short computeShortIfAbsentNonDefault(int key, Int2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public short supplyShortIfAbsentNonDefault(int key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } + @Override public short computeShortIfPresentNonDefault(int key, IntShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short mergeShort(int key, short value, ShortShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/misc/Int2BooleanArrayMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/misc/Int2BooleanArrayMap.java index 11ed01b3..1c1a14ec 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/misc/Int2BooleanArrayMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/misc/Int2BooleanArrayMap.java @@ -419,66 +419,76 @@ public boolean computeBoolean(int key, IntBooleanUnaryOperator mappingFunction) } @Override - public boolean computeBooleanNonDefault(int key, IntBooleanUnaryOperator mappingFunction) { + public boolean computeBooleanIfAbsent(int key, IntPredicate mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + boolean newValue = mappingFunction.test(key); insertIndex(size++, key, newValue); return newValue; } - boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + boolean newValue = values[index]; return newValue; } - + @Override - public boolean computeBooleanIfAbsent(int key, IntPredicate mappingFunction) { - Objects.requireNonNull(mappingFunction); + public boolean supplyBooleanIfAbsent(int key, BooleanSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - boolean newValue = mappingFunction.test(key); + boolean newValue = valueProvider.getAsBoolean(); insertIndex(size++, key, newValue); return newValue; } boolean newValue = values[index]; return newValue; } + + @Override + public boolean computeBooleanIfPresent(int key, IntBooleanUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index == -1) return getDefaultReturnValue(); + boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public boolean computeBooleanIfAbsentNonDefault(int key, IntPredicate mappingFunction) { + public boolean computeBooleanNonDefault(int key, IntBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - boolean newValue = mappingFunction.test(key); + boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } - boolean newValue = values[index]; + boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.test(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public boolean supplyBooleanIfAbsent(int key, BooleanSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public boolean computeBooleanIfAbsentNonDefault(int key, IntPredicate mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - boolean newValue = valueProvider.getAsBoolean(); + boolean newValue = mappingFunction.test(key); + if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } boolean newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.test(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -501,16 +511,6 @@ public boolean supplyBooleanIfAbsentNonDefault(int key, BooleanSupplier valuePro return newValue; } - @Override - public boolean computeBooleanIfPresent(int key, IntBooleanUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) return getDefaultReturnValue(); - boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public boolean computeBooleanIfPresentNonDefault(int key, IntBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/misc/Int2ByteArrayMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/misc/Int2ByteArrayMap.java index 42912575..7df3f1fa 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/misc/Int2ByteArrayMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/misc/Int2ByteArrayMap.java @@ -442,66 +442,76 @@ public byte computeByte(int key, IntByteUnaryOperator mappingFunction) { } @Override - public byte computeByteNonDefault(int key, IntByteUnaryOperator mappingFunction) { + public byte computeByteIfAbsent(int key, Int2ByteFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + byte newValue = mappingFunction.applyAsByte(key); insertIndex(size++, key, newValue); return newValue; } - byte newValue = mappingFunction.applyAsByte(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + byte newValue = values[index]; return newValue; } - + @Override - public byte computeByteIfAbsent(int key, Int2ByteFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public byte supplyByteIfAbsent(int key, ByteSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = valueProvider.getAsByte(); insertIndex(size++, key, newValue); return newValue; } byte newValue = values[index]; return newValue; } + + @Override + public byte computeByteIfPresent(int key, IntByteUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index == -1) return getDefaultReturnValue(); + byte newValue = mappingFunction.applyAsByte(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public byte computeByteIfAbsentNonDefault(int key, Int2ByteFunction mappingFunction) { + public byte computeByteNonDefault(int key, IntByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } - byte newValue = values[index]; + byte newValue = mappingFunction.applyAsByte(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsByte(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public byte supplyByteIfAbsent(int key, ByteSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public byte computeByteIfAbsentNonDefault(int key, Int2ByteFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - byte newValue = valueProvider.getAsInt(); + byte newValue = mappingFunction.applyAsByte(key); + if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } byte newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsByte(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -510,30 +520,20 @@ public byte supplyByteIfAbsentNonDefault(int key, ByteSupplier valueProvider) { Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - byte newValue = valueProvider.getAsInt(); + byte newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } byte newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public byte computeByteIfPresent(int key, IntByteUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) return getDefaultReturnValue(); - byte newValue = mappingFunction.applyAsByte(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public byte computeByteIfPresentNonDefault(int key, IntByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/misc/Int2CharArrayMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/misc/Int2CharArrayMap.java index b952c5a4..9a42945b 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/misc/Int2CharArrayMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/misc/Int2CharArrayMap.java @@ -442,66 +442,76 @@ public char computeChar(int key, IntCharUnaryOperator mappingFunction) { } @Override - public char computeCharNonDefault(int key, IntCharUnaryOperator mappingFunction) { + public char computeCharIfAbsent(int key, Int2CharFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + char newValue = mappingFunction.applyAsChar(key); insertIndex(size++, key, newValue); return newValue; } - char newValue = mappingFunction.applyAsChar(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + char newValue = values[index]; return newValue; } - + @Override - public char computeCharIfAbsent(int key, Int2CharFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public char supplyCharIfAbsent(int key, CharSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = valueProvider.getAsChar(); insertIndex(size++, key, newValue); return newValue; } char newValue = values[index]; return newValue; } + + @Override + public char computeCharIfPresent(int key, IntCharUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index == -1) return getDefaultReturnValue(); + char newValue = mappingFunction.applyAsChar(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public char computeCharIfAbsentNonDefault(int key, Int2CharFunction mappingFunction) { + public char computeCharNonDefault(int key, IntCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } - char newValue = values[index]; + char newValue = mappingFunction.applyAsChar(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsChar(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public char supplyCharIfAbsent(int key, CharSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public char computeCharIfAbsentNonDefault(int key, Int2CharFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - char newValue = valueProvider.getAsInt(); + char newValue = mappingFunction.applyAsChar(key); + if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } char newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsChar(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -510,30 +520,20 @@ public char supplyCharIfAbsentNonDefault(int key, CharSupplier valueProvider) { Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - char newValue = valueProvider.getAsInt(); + char newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } char newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public char computeCharIfPresent(int key, IntCharUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) return getDefaultReturnValue(); - char newValue = mappingFunction.applyAsChar(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public char computeCharIfPresentNonDefault(int key, IntCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/misc/Int2DoubleArrayMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/misc/Int2DoubleArrayMap.java index 88b96dd5..61917f53 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/misc/Int2DoubleArrayMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/misc/Int2DoubleArrayMap.java @@ -442,66 +442,76 @@ public double computeDouble(int key, IntDoubleUnaryOperator mappingFunction) { } @Override - public double computeDoubleNonDefault(int key, IntDoubleUnaryOperator mappingFunction) { + public double computeDoubleIfAbsent(int key, Int2DoubleFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + double newValue = mappingFunction.applyAsDouble(key); insertIndex(size++, key, newValue); return newValue; } - double newValue = mappingFunction.applyAsDouble(key, values[index]); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + double newValue = values[index]; return newValue; } - + @Override - public double computeDoubleIfAbsent(int key, Int2DoubleFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public double supplyDoubleIfAbsent(int key, DoubleSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = valueProvider.getAsDouble(); insertIndex(size++, key, newValue); return newValue; } double newValue = values[index]; return newValue; } + + @Override + public double computeDoubleIfPresent(int key, IntDoubleUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index == -1) return getDefaultReturnValue(); + double newValue = mappingFunction.applyAsDouble(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public double computeDoubleIfAbsentNonDefault(int key, Int2DoubleFunction mappingFunction) { + public double computeDoubleNonDefault(int key, IntDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; insertIndex(size++, key, newValue); return newValue; } - double newValue = values[index]; + double newValue = mappingFunction.applyAsDouble(key, values[index]); if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - newValue = mappingFunction.applyAsDouble(key); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public double supplyDoubleIfAbsent(int key, DoubleSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public double computeDoubleIfAbsentNonDefault(int key, Int2DoubleFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - double newValue = valueProvider.getAsDouble(); + double newValue = mappingFunction.applyAsDouble(key); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; insertIndex(size++, key, newValue); return newValue; } double newValue = values[index]; + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { + newValue = mappingFunction.applyAsDouble(key); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + values[index] = newValue; + } return newValue; } @@ -524,16 +534,6 @@ public double supplyDoubleIfAbsentNonDefault(int key, DoubleSupplier valueProvid return newValue; } - @Override - public double computeDoubleIfPresent(int key, IntDoubleUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) return getDefaultReturnValue(); - double newValue = mappingFunction.applyAsDouble(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public double computeDoubleIfPresentNonDefault(int key, IntDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/misc/Int2FloatArrayMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/misc/Int2FloatArrayMap.java index f05cf138..6beb9a90 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/misc/Int2FloatArrayMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/misc/Int2FloatArrayMap.java @@ -442,66 +442,76 @@ public float computeFloat(int key, IntFloatUnaryOperator mappingFunction) { } @Override - public float computeFloatNonDefault(int key, IntFloatUnaryOperator mappingFunction) { + public float computeFloatIfAbsent(int key, Int2FloatFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + float newValue = mappingFunction.applyAsFloat(key); insertIndex(size++, key, newValue); return newValue; } - float newValue = mappingFunction.applyAsFloat(key, values[index]); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + float newValue = values[index]; return newValue; } - + @Override - public float computeFloatIfAbsent(int key, Int2FloatFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public float supplyFloatIfAbsent(int key, FloatSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = valueProvider.getAsFloat(); insertIndex(size++, key, newValue); return newValue; } float newValue = values[index]; return newValue; } + + @Override + public float computeFloatIfPresent(int key, IntFloatUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index == -1) return getDefaultReturnValue(); + float newValue = mappingFunction.applyAsFloat(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public float computeFloatIfAbsentNonDefault(int key, Int2FloatFunction mappingFunction) { + public float computeFloatNonDefault(int key, IntFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insertIndex(size++, key, newValue); return newValue; } - float newValue = values[index]; + float newValue = mappingFunction.applyAsFloat(key, values[index]); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - newValue = mappingFunction.applyAsFloat(key); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public float supplyFloatIfAbsent(int key, FloatSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public float computeFloatIfAbsentNonDefault(int key, Int2FloatFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - float newValue = valueProvider.getAsDouble(); + float newValue = mappingFunction.applyAsFloat(key); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insertIndex(size++, key, newValue); return newValue; } float newValue = values[index]; + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { + newValue = mappingFunction.applyAsFloat(key); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + values[index] = newValue; + } return newValue; } @@ -510,30 +520,20 @@ public float supplyFloatIfAbsentNonDefault(int key, FloatSupplier valueProvider) Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - float newValue = valueProvider.getAsDouble(); + float newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insertIndex(size++, key, newValue); return newValue; } float newValue = values[index]; if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - newValue = valueProvider.getAsDouble(); + newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; values[index] = newValue; } return newValue; } - @Override - public float computeFloatIfPresent(int key, IntFloatUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) return getDefaultReturnValue(); - float newValue = mappingFunction.applyAsFloat(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public float computeFloatIfPresentNonDefault(int key, IntFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/misc/Int2IntArrayMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/misc/Int2IntArrayMap.java index eadb227b..ce199c72 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/misc/Int2IntArrayMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/misc/Int2IntArrayMap.java @@ -435,66 +435,76 @@ public int computeInt(int key, IntIntUnaryOperator mappingFunction) { } @Override - public int computeIntNonDefault(int key, IntIntUnaryOperator mappingFunction) { + public int computeIntIfAbsent(int key, IntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + int newValue = mappingFunction.applyAsInt(key); insertIndex(size++, key, newValue); return newValue; } - int newValue = mappingFunction.applyAsInt(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + int newValue = values[index]; return newValue; } - + @Override - public int computeIntIfAbsent(int key, IntUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); + public int supplyIntIfAbsent(int key, IntSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = valueProvider.getAsInt(); insertIndex(size++, key, newValue); return newValue; } int newValue = values[index]; return newValue; } + + @Override + public int computeIntIfPresent(int key, IntIntUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index == -1) return getDefaultReturnValue(); + int newValue = mappingFunction.applyAsInt(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public int computeIntIfAbsentNonDefault(int key, IntUnaryOperator mappingFunction) { + public int computeIntNonDefault(int key, IntIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } - int newValue = values[index]; + int newValue = mappingFunction.applyAsInt(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsInt(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public int supplyIntIfAbsent(int key, IntSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public int computeIntIfAbsentNonDefault(int key, IntUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - int newValue = valueProvider.getAsInt(); + int newValue = mappingFunction.applyAsInt(key); + if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } int newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsInt(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -517,16 +527,6 @@ public int supplyIntIfAbsentNonDefault(int key, IntSupplier valueProvider) { return newValue; } - @Override - public int computeIntIfPresent(int key, IntIntUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) return getDefaultReturnValue(); - int newValue = mappingFunction.applyAsInt(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public int computeIntIfPresentNonDefault(int key, IntIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/misc/Int2LongArrayMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/misc/Int2LongArrayMap.java index 5d3de12e..679fb0cc 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/misc/Int2LongArrayMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/misc/Int2LongArrayMap.java @@ -442,66 +442,76 @@ public long computeLong(int key, IntLongUnaryOperator mappingFunction) { } @Override - public long computeLongNonDefault(int key, IntLongUnaryOperator mappingFunction) { + public long computeLongIfAbsent(int key, Int2LongFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + long newValue = mappingFunction.applyAsLong(key); insertIndex(size++, key, newValue); return newValue; } - long newValue = mappingFunction.applyAsLong(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + long newValue = values[index]; return newValue; } - + @Override - public long computeLongIfAbsent(int key, Int2LongFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public long supplyLongIfAbsent(int key, LongSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = valueProvider.getAsLong(); insertIndex(size++, key, newValue); return newValue; } long newValue = values[index]; return newValue; } + + @Override + public long computeLongIfPresent(int key, IntLongUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index == -1) return getDefaultReturnValue(); + long newValue = mappingFunction.applyAsLong(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public long computeLongIfAbsentNonDefault(int key, Int2LongFunction mappingFunction) { + public long computeLongNonDefault(int key, IntLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } - long newValue = values[index]; + long newValue = mappingFunction.applyAsLong(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsLong(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public long supplyLongIfAbsent(int key, LongSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public long computeLongIfAbsentNonDefault(int key, Int2LongFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - long newValue = valueProvider.getAsLong(); + long newValue = mappingFunction.applyAsLong(key); + if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } long newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsLong(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -524,16 +534,6 @@ public long supplyLongIfAbsentNonDefault(int key, LongSupplier valueProvider) { return newValue; } - @Override - public long computeLongIfPresent(int key, IntLongUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) return getDefaultReturnValue(); - long newValue = mappingFunction.applyAsLong(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public long computeLongIfPresentNonDefault(int key, IntLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/misc/Int2ObjectArrayMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/misc/Int2ObjectArrayMap.java index 4b1e53d1..2ab9da09 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/misc/Int2ObjectArrayMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/misc/Int2ObjectArrayMap.java @@ -414,25 +414,6 @@ public V compute(int key, IntObjectUnaryOperator mappingFunction) { return newValue; } - @Override - public V computeNonDefault(int key, IntObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) { - V newValue = mappingFunction.apply(key, getDefaultReturnValue()); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insertIndex(size++, key, newValue); - return newValue; - } - V newValue = mappingFunction.apply(key, values[index]); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; - return newValue; - } - @Override public V computeIfAbsent(int key, IntFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -451,26 +432,7 @@ public V computeIfAbsent(int key, IntFunction mappingFunction) { } return newValue; } - - @Override - public V computeIfAbsentNonDefault(int key, IntFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) { - V newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insertIndex(size++, key, newValue); - return newValue; - } - V newValue = values[index]; - if(Objects.equals(newValue, getDefaultReturnValue())) { - newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - values[index] = newValue; - } - return newValue; - } - + @Override public V supplyIfAbsent(int key, ObjectSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -489,26 +451,7 @@ public V supplyIfAbsent(int key, ObjectSupplier valueProvider) { } return newValue; } - - @Override - public V supplyIfAbsentNonDefault(int key, ObjectSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - int index = findIndex(key); - if(index == -1) { - V newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insertIndex(size++, key, newValue); - return newValue; - } - V newValue = values[index]; - if(Objects.equals(newValue, getDefaultReturnValue())) { - newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - values[index] = newValue; - } - return newValue; - } - + @Override public V computeIfPresent(int key, IntObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -523,20 +466,6 @@ public V computeIfPresent(int key, IntObjectUnaryOperator mappingFunction) { return newValue; } - @Override - public V computeIfPresentNonDefault(int key, IntObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1 || Objects.equals(values[index], getDefaultReturnValue())) return getDefaultReturnValue(); - V newValue = mappingFunction.apply(key, values[index]); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; - return newValue; - } - @Override public V merge(int key, V value, ObjectObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/misc/Int2ShortArrayMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/misc/Int2ShortArrayMap.java index 58400ac9..60451743 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/misc/Int2ShortArrayMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/misc/Int2ShortArrayMap.java @@ -442,66 +442,76 @@ public short computeShort(int key, IntShortUnaryOperator mappingFunction) { } @Override - public short computeShortNonDefault(int key, IntShortUnaryOperator mappingFunction) { + public short computeShortIfAbsent(int key, Int2ShortFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + short newValue = mappingFunction.applyAsShort(key); insertIndex(size++, key, newValue); return newValue; } - short newValue = mappingFunction.applyAsShort(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + short newValue = values[index]; return newValue; } - + @Override - public short computeShortIfAbsent(int key, Int2ShortFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public short supplyShortIfAbsent(int key, ShortSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = valueProvider.getAsShort(); insertIndex(size++, key, newValue); return newValue; } short newValue = values[index]; return newValue; } + + @Override + public short computeShortIfPresent(int key, IntShortUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index == -1) return getDefaultReturnValue(); + short newValue = mappingFunction.applyAsShort(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public short computeShortIfAbsentNonDefault(int key, Int2ShortFunction mappingFunction) { + public short computeShortNonDefault(int key, IntShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } - short newValue = values[index]; + short newValue = mappingFunction.applyAsShort(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsShort(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public short supplyShortIfAbsent(int key, ShortSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public short computeShortIfAbsentNonDefault(int key, Int2ShortFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - short newValue = valueProvider.getAsInt(); + short newValue = mappingFunction.applyAsShort(key); + if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } short newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsShort(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -510,30 +520,20 @@ public short supplyShortIfAbsentNonDefault(int key, ShortSupplier valueProvider) Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - short newValue = valueProvider.getAsInt(); + short newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } short newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public short computeShortIfPresent(int key, IntShortUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) return getDefaultReturnValue(); - short newValue = mappingFunction.applyAsShort(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public short computeShortIfPresentNonDefault(int key, IntShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2BooleanAVLTreeMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2BooleanAVLTreeMap.java index 51ba5730..fd5f2d4f 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2BooleanAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2BooleanAVLTreeMap.java @@ -395,34 +395,56 @@ public boolean computeBoolean(int key, IntBooleanUnaryOperator mappingFunction) } @Override - public boolean computeBooleanNonDefault(int key, IntBooleanUnaryOperator mappingFunction) { + public boolean computeBooleanIfAbsent(int key, IntPredicate mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + boolean newValue = mappingFunction.test(key); put(key, newValue); return newValue; } - boolean newValue = mappingFunction.applyAsBoolean(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public boolean supplyBooleanIfAbsent(int key, BooleanSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + boolean newValue = valueProvider.getAsBoolean(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public boolean computeBooleanIfPresent(int key, IntBooleanUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + boolean newValue = mappingFunction.applyAsBoolean(key, entry.value); entry.value = newValue; return newValue; } @Override - public boolean computeBooleanIfAbsent(int key, IntPredicate mappingFunction) { + public boolean computeBooleanNonDefault(int key, IntBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - boolean newValue = mappingFunction.test(key); + boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + boolean newValue = mappingFunction.applyAsBoolean(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -443,18 +465,6 @@ public boolean computeBooleanIfAbsentNonDefault(int key, IntPredicate mappingFun return entry.value; } - @Override - public boolean supplyBooleanIfAbsent(int key, BooleanSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - boolean newValue = valueProvider.getAsBoolean(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public boolean supplyBooleanIfAbsentNonDefault(int key, BooleanSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -473,16 +483,6 @@ public boolean supplyBooleanIfAbsentNonDefault(int key, BooleanSupplier valuePro return entry.value; } - @Override - public boolean computeBooleanIfPresent(int key, IntBooleanUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - boolean newValue = mappingFunction.applyAsBoolean(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public boolean computeBooleanIfPresentNonDefault(int key, IntBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1486,14 +1486,9 @@ public boolean computeBooleanIfPresent(int key, IntBooleanUnaryOperator mappingF Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - boolean newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2BooleanRBTreeMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2BooleanRBTreeMap.java index c45cb1ed..b1c568b4 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2BooleanRBTreeMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2BooleanRBTreeMap.java @@ -394,34 +394,56 @@ public boolean computeBoolean(int key, IntBooleanUnaryOperator mappingFunction) } @Override - public boolean computeBooleanNonDefault(int key, IntBooleanUnaryOperator mappingFunction) { + public boolean computeBooleanIfAbsent(int key, IntPredicate mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + boolean newValue = mappingFunction.test(key); put(key, newValue); return newValue; } - boolean newValue = mappingFunction.applyAsBoolean(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public boolean supplyBooleanIfAbsent(int key, BooleanSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + boolean newValue = valueProvider.getAsBoolean(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public boolean computeBooleanIfPresent(int key, IntBooleanUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + boolean newValue = mappingFunction.applyAsBoolean(key, entry.value); entry.value = newValue; return newValue; } @Override - public boolean computeBooleanIfAbsent(int key, IntPredicate mappingFunction) { + public boolean computeBooleanNonDefault(int key, IntBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - boolean newValue = mappingFunction.test(key); + boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + boolean newValue = mappingFunction.applyAsBoolean(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -442,18 +464,6 @@ public boolean computeBooleanIfAbsentNonDefault(int key, IntPredicate mappingFun return entry.value; } - @Override - public boolean supplyBooleanIfAbsent(int key, BooleanSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - boolean newValue = valueProvider.getAsBoolean(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public boolean supplyBooleanIfAbsentNonDefault(int key, BooleanSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -472,16 +482,6 @@ public boolean supplyBooleanIfAbsentNonDefault(int key, BooleanSupplier valuePro return entry.value; } - @Override - public boolean computeBooleanIfPresent(int key, IntBooleanUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - boolean newValue = mappingFunction.applyAsBoolean(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public boolean computeBooleanIfPresentNonDefault(int key, IntBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1549,14 +1549,9 @@ public boolean computeBooleanIfPresent(int key, IntBooleanUnaryOperator mappingF Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - boolean newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2ByteAVLTreeMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2ByteAVLTreeMap.java index fa73b2b0..0e91dbf2 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2ByteAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2ByteAVLTreeMap.java @@ -454,34 +454,56 @@ public byte computeByte(int key, IntByteUnaryOperator mappingFunction) { } @Override - public byte computeByteNonDefault(int key, IntByteUnaryOperator mappingFunction) { + public byte computeByteIfAbsent(int key, Int2ByteFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + byte newValue = mappingFunction.applyAsByte(key); put(key, newValue); return newValue; } - byte newValue = mappingFunction.applyAsByte(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public byte supplyByteIfAbsent(int key, ByteSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + byte newValue = valueProvider.getAsByte(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public byte computeByteIfPresent(int key, IntByteUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + byte newValue = mappingFunction.applyAsByte(key, entry.value); entry.value = newValue; return newValue; } @Override - public byte computeByteIfAbsent(int key, Int2ByteFunction mappingFunction) { + public byte computeByteNonDefault(int key, IntByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + byte newValue = mappingFunction.applyAsByte(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -502,46 +524,24 @@ public byte computeByteIfAbsentNonDefault(int key, Int2ByteFunction mappingFunct return entry.value; } - @Override - public byte supplyByteIfAbsent(int key, ByteSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - byte newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public byte supplyByteIfAbsentNonDefault(int key, ByteSupplier valueProvider) { Objects.requireNonNull(valueProvider); Node entry = findNode(key); if(entry == null) { - byte newValue = valueProvider.getAsInt(); + byte newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } if(entry.value == getDefaultReturnValue()) { - byte newValue = valueProvider.getAsInt(); + byte newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; entry.value = newValue; } return entry.value; } - @Override - public byte computeByteIfPresent(int key, IntByteUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - byte newValue = mappingFunction.applyAsByte(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public byte computeByteIfPresentNonDefault(int key, IntByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1557,14 +1557,9 @@ public byte computeByteIfPresent(int key, IntByteUnaryOperator mappingFunction) Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - byte newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2ByteRBTreeMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2ByteRBTreeMap.java index 7b4a3657..fa84284c 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2ByteRBTreeMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2ByteRBTreeMap.java @@ -453,34 +453,56 @@ public byte computeByte(int key, IntByteUnaryOperator mappingFunction) { } @Override - public byte computeByteNonDefault(int key, IntByteUnaryOperator mappingFunction) { + public byte computeByteIfAbsent(int key, Int2ByteFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + byte newValue = mappingFunction.applyAsByte(key); put(key, newValue); return newValue; } - byte newValue = mappingFunction.applyAsByte(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public byte supplyByteIfAbsent(int key, ByteSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + byte newValue = valueProvider.getAsByte(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public byte computeByteIfPresent(int key, IntByteUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + byte newValue = mappingFunction.applyAsByte(key, entry.value); entry.value = newValue; return newValue; } @Override - public byte computeByteIfAbsent(int key, Int2ByteFunction mappingFunction) { + public byte computeByteNonDefault(int key, IntByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + byte newValue = mappingFunction.applyAsByte(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -501,46 +523,24 @@ public byte computeByteIfAbsentNonDefault(int key, Int2ByteFunction mappingFunct return entry.value; } - @Override - public byte supplyByteIfAbsent(int key, ByteSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - byte newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public byte supplyByteIfAbsentNonDefault(int key, ByteSupplier valueProvider) { Objects.requireNonNull(valueProvider); Node entry = findNode(key); if(entry == null) { - byte newValue = valueProvider.getAsInt(); + byte newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } if(entry.value == getDefaultReturnValue()) { - byte newValue = valueProvider.getAsInt(); + byte newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; entry.value = newValue; } return entry.value; } - @Override - public byte computeByteIfPresent(int key, IntByteUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - byte newValue = mappingFunction.applyAsByte(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public byte computeByteIfPresentNonDefault(int key, IntByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1620,14 +1620,9 @@ public byte computeByteIfPresent(int key, IntByteUnaryOperator mappingFunction) Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - byte newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2CharAVLTreeMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2CharAVLTreeMap.java index 40ef7f9a..1ed98d4a 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2CharAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2CharAVLTreeMap.java @@ -454,34 +454,56 @@ public char computeChar(int key, IntCharUnaryOperator mappingFunction) { } @Override - public char computeCharNonDefault(int key, IntCharUnaryOperator mappingFunction) { + public char computeCharIfAbsent(int key, Int2CharFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + char newValue = mappingFunction.applyAsChar(key); put(key, newValue); return newValue; } - char newValue = mappingFunction.applyAsChar(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public char supplyCharIfAbsent(int key, CharSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + char newValue = valueProvider.getAsChar(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public char computeCharIfPresent(int key, IntCharUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + char newValue = mappingFunction.applyAsChar(key, entry.value); entry.value = newValue; return newValue; } @Override - public char computeCharIfAbsent(int key, Int2CharFunction mappingFunction) { + public char computeCharNonDefault(int key, IntCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + char newValue = mappingFunction.applyAsChar(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -502,46 +524,24 @@ public char computeCharIfAbsentNonDefault(int key, Int2CharFunction mappingFunct return entry.value; } - @Override - public char supplyCharIfAbsent(int key, CharSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - char newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public char supplyCharIfAbsentNonDefault(int key, CharSupplier valueProvider) { Objects.requireNonNull(valueProvider); Node entry = findNode(key); if(entry == null) { - char newValue = valueProvider.getAsInt(); + char newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } if(entry.value == getDefaultReturnValue()) { - char newValue = valueProvider.getAsInt(); + char newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; entry.value = newValue; } return entry.value; } - @Override - public char computeCharIfPresent(int key, IntCharUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - char newValue = mappingFunction.applyAsChar(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public char computeCharIfPresentNonDefault(int key, IntCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1557,14 +1557,9 @@ public char computeCharIfPresent(int key, IntCharUnaryOperator mappingFunction) Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - char newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2CharRBTreeMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2CharRBTreeMap.java index 103b4aa4..d595de79 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2CharRBTreeMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2CharRBTreeMap.java @@ -453,34 +453,56 @@ public char computeChar(int key, IntCharUnaryOperator mappingFunction) { } @Override - public char computeCharNonDefault(int key, IntCharUnaryOperator mappingFunction) { + public char computeCharIfAbsent(int key, Int2CharFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + char newValue = mappingFunction.applyAsChar(key); put(key, newValue); return newValue; } - char newValue = mappingFunction.applyAsChar(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public char supplyCharIfAbsent(int key, CharSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + char newValue = valueProvider.getAsChar(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public char computeCharIfPresent(int key, IntCharUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + char newValue = mappingFunction.applyAsChar(key, entry.value); entry.value = newValue; return newValue; } @Override - public char computeCharIfAbsent(int key, Int2CharFunction mappingFunction) { + public char computeCharNonDefault(int key, IntCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + char newValue = mappingFunction.applyAsChar(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -501,46 +523,24 @@ public char computeCharIfAbsentNonDefault(int key, Int2CharFunction mappingFunct return entry.value; } - @Override - public char supplyCharIfAbsent(int key, CharSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - char newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public char supplyCharIfAbsentNonDefault(int key, CharSupplier valueProvider) { Objects.requireNonNull(valueProvider); Node entry = findNode(key); if(entry == null) { - char newValue = valueProvider.getAsInt(); + char newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } if(entry.value == getDefaultReturnValue()) { - char newValue = valueProvider.getAsInt(); + char newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; entry.value = newValue; } return entry.value; } - @Override - public char computeCharIfPresent(int key, IntCharUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - char newValue = mappingFunction.applyAsChar(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public char computeCharIfPresentNonDefault(int key, IntCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1620,14 +1620,9 @@ public char computeCharIfPresent(int key, IntCharUnaryOperator mappingFunction) Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - char newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2DoubleAVLTreeMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2DoubleAVLTreeMap.java index c08415fe..d2724dc7 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2DoubleAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2DoubleAVLTreeMap.java @@ -454,34 +454,56 @@ public double computeDouble(int key, IntDoubleUnaryOperator mappingFunction) { } @Override - public double computeDoubleNonDefault(int key, IntDoubleUnaryOperator mappingFunction) { + public double computeDoubleIfAbsent(int key, Int2DoubleFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + double newValue = mappingFunction.applyAsDouble(key); put(key, newValue); return newValue; } - double newValue = mappingFunction.applyAsDouble(key, entry.value); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - removeNode(entry); + return entry.value; + } + + @Override + public double supplyDoubleIfAbsent(int key, DoubleSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + double newValue = valueProvider.getAsDouble(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public double computeDoubleIfPresent(int key, IntDoubleUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + double newValue = mappingFunction.applyAsDouble(key, entry.value); entry.value = newValue; return newValue; } @Override - public double computeDoubleIfAbsent(int key, Int2DoubleFunction mappingFunction) { + public double computeDoubleNonDefault(int key, IntDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; put(key, newValue); return newValue; } - return entry.value; + double newValue = mappingFunction.applyAsDouble(key, entry.value); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -502,18 +524,6 @@ public double computeDoubleIfAbsentNonDefault(int key, Int2DoubleFunction mappin return entry.value; } - @Override - public double supplyDoubleIfAbsent(int key, DoubleSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - double newValue = valueProvider.getAsDouble(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public double supplyDoubleIfAbsentNonDefault(int key, DoubleSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -532,16 +542,6 @@ public double supplyDoubleIfAbsentNonDefault(int key, DoubleSupplier valueProvid return entry.value; } - @Override - public double computeDoubleIfPresent(int key, IntDoubleUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - double newValue = mappingFunction.applyAsDouble(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public double computeDoubleIfPresentNonDefault(int key, IntDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1557,14 +1557,9 @@ public double computeDoubleIfPresent(int key, IntDoubleUnaryOperator mappingFunc Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || Double.doubleToLongBits(entry.value) == Double.doubleToLongBits(getDefaultReturnValue())) return getDefaultReturnValue(); - double newValue = mappingFunction.apply(key, entry.value); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2DoubleRBTreeMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2DoubleRBTreeMap.java index a3dee17b..4fdbc565 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2DoubleRBTreeMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2DoubleRBTreeMap.java @@ -453,34 +453,56 @@ public double computeDouble(int key, IntDoubleUnaryOperator mappingFunction) { } @Override - public double computeDoubleNonDefault(int key, IntDoubleUnaryOperator mappingFunction) { + public double computeDoubleIfAbsent(int key, Int2DoubleFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + double newValue = mappingFunction.applyAsDouble(key); put(key, newValue); return newValue; } - double newValue = mappingFunction.applyAsDouble(key, entry.value); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - removeNode(entry); + return entry.value; + } + + @Override + public double supplyDoubleIfAbsent(int key, DoubleSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + double newValue = valueProvider.getAsDouble(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public double computeDoubleIfPresent(int key, IntDoubleUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + double newValue = mappingFunction.applyAsDouble(key, entry.value); entry.value = newValue; return newValue; } @Override - public double computeDoubleIfAbsent(int key, Int2DoubleFunction mappingFunction) { + public double computeDoubleNonDefault(int key, IntDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; put(key, newValue); return newValue; } - return entry.value; + double newValue = mappingFunction.applyAsDouble(key, entry.value); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -501,18 +523,6 @@ public double computeDoubleIfAbsentNonDefault(int key, Int2DoubleFunction mappin return entry.value; } - @Override - public double supplyDoubleIfAbsent(int key, DoubleSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - double newValue = valueProvider.getAsDouble(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public double supplyDoubleIfAbsentNonDefault(int key, DoubleSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -531,16 +541,6 @@ public double supplyDoubleIfAbsentNonDefault(int key, DoubleSupplier valueProvid return entry.value; } - @Override - public double computeDoubleIfPresent(int key, IntDoubleUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - double newValue = mappingFunction.applyAsDouble(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public double computeDoubleIfPresentNonDefault(int key, IntDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1620,14 +1620,9 @@ public double computeDoubleIfPresent(int key, IntDoubleUnaryOperator mappingFunc Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || Double.doubleToLongBits(entry.value) == Double.doubleToLongBits(getDefaultReturnValue())) return getDefaultReturnValue(); - double newValue = mappingFunction.apply(key, entry.value); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2FloatAVLTreeMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2FloatAVLTreeMap.java index 95c74a77..eb228e3e 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2FloatAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2FloatAVLTreeMap.java @@ -454,34 +454,56 @@ public float computeFloat(int key, IntFloatUnaryOperator mappingFunction) { } @Override - public float computeFloatNonDefault(int key, IntFloatUnaryOperator mappingFunction) { + public float computeFloatIfAbsent(int key, Int2FloatFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + float newValue = mappingFunction.applyAsFloat(key); put(key, newValue); return newValue; } - float newValue = mappingFunction.applyAsFloat(key, entry.value); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - removeNode(entry); + return entry.value; + } + + @Override + public float supplyFloatIfAbsent(int key, FloatSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + float newValue = valueProvider.getAsFloat(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public float computeFloatIfPresent(int key, IntFloatUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + float newValue = mappingFunction.applyAsFloat(key, entry.value); entry.value = newValue; return newValue; } @Override - public float computeFloatIfAbsent(int key, Int2FloatFunction mappingFunction) { + public float computeFloatNonDefault(int key, IntFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; put(key, newValue); return newValue; } - return entry.value; + float newValue = mappingFunction.applyAsFloat(key, entry.value); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -502,46 +524,24 @@ public float computeFloatIfAbsentNonDefault(int key, Int2FloatFunction mappingFu return entry.value; } - @Override - public float supplyFloatIfAbsent(int key, FloatSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - float newValue = valueProvider.getAsDouble(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public float supplyFloatIfAbsentNonDefault(int key, FloatSupplier valueProvider) { Objects.requireNonNull(valueProvider); Node entry = findNode(key); if(entry == null) { - float newValue = valueProvider.getAsDouble(); + float newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; put(key, newValue); return newValue; } if(Float.floatToIntBits(entry.value) == Float.floatToIntBits(getDefaultReturnValue())) { - float newValue = valueProvider.getAsDouble(); + float newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; entry.value = newValue; } return entry.value; } - @Override - public float computeFloatIfPresent(int key, IntFloatUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - float newValue = mappingFunction.applyAsFloat(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public float computeFloatIfPresentNonDefault(int key, IntFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1557,14 +1557,9 @@ public float computeFloatIfPresent(int key, IntFloatUnaryOperator mappingFunctio Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || Float.floatToIntBits(entry.value) == Float.floatToIntBits(getDefaultReturnValue())) return getDefaultReturnValue(); - float newValue = mappingFunction.apply(key, entry.value); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2FloatRBTreeMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2FloatRBTreeMap.java index 0180ef86..084f78cf 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2FloatRBTreeMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2FloatRBTreeMap.java @@ -453,34 +453,56 @@ public float computeFloat(int key, IntFloatUnaryOperator mappingFunction) { } @Override - public float computeFloatNonDefault(int key, IntFloatUnaryOperator mappingFunction) { + public float computeFloatIfAbsent(int key, Int2FloatFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + float newValue = mappingFunction.applyAsFloat(key); put(key, newValue); return newValue; } - float newValue = mappingFunction.applyAsFloat(key, entry.value); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - removeNode(entry); + return entry.value; + } + + @Override + public float supplyFloatIfAbsent(int key, FloatSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + float newValue = valueProvider.getAsFloat(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public float computeFloatIfPresent(int key, IntFloatUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + float newValue = mappingFunction.applyAsFloat(key, entry.value); entry.value = newValue; return newValue; } @Override - public float computeFloatIfAbsent(int key, Int2FloatFunction mappingFunction) { + public float computeFloatNonDefault(int key, IntFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; put(key, newValue); return newValue; } - return entry.value; + float newValue = mappingFunction.applyAsFloat(key, entry.value); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -501,46 +523,24 @@ public float computeFloatIfAbsentNonDefault(int key, Int2FloatFunction mappingFu return entry.value; } - @Override - public float supplyFloatIfAbsent(int key, FloatSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - float newValue = valueProvider.getAsDouble(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public float supplyFloatIfAbsentNonDefault(int key, FloatSupplier valueProvider) { Objects.requireNonNull(valueProvider); Node entry = findNode(key); if(entry == null) { - float newValue = valueProvider.getAsDouble(); + float newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; put(key, newValue); return newValue; } if(Float.floatToIntBits(entry.value) == Float.floatToIntBits(getDefaultReturnValue())) { - float newValue = valueProvider.getAsDouble(); + float newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; entry.value = newValue; } return entry.value; } - @Override - public float computeFloatIfPresent(int key, IntFloatUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - float newValue = mappingFunction.applyAsFloat(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public float computeFloatIfPresentNonDefault(int key, IntFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1620,14 +1620,9 @@ public float computeFloatIfPresent(int key, IntFloatUnaryOperator mappingFunctio Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || Float.floatToIntBits(entry.value) == Float.floatToIntBits(getDefaultReturnValue())) return getDefaultReturnValue(); - float newValue = mappingFunction.apply(key, entry.value); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2IntAVLTreeMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2IntAVLTreeMap.java index 902882ef..ebcf788c 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2IntAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2IntAVLTreeMap.java @@ -446,34 +446,56 @@ public int computeInt(int key, IntIntUnaryOperator mappingFunction) { } @Override - public int computeIntNonDefault(int key, IntIntUnaryOperator mappingFunction) { + public int computeIntIfAbsent(int key, IntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + int newValue = mappingFunction.applyAsInt(key); put(key, newValue); return newValue; } - int newValue = mappingFunction.applyAsInt(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public int supplyIntIfAbsent(int key, IntSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + int newValue = valueProvider.getAsInt(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public int computeIntIfPresent(int key, IntIntUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + int newValue = mappingFunction.applyAsInt(key, entry.value); entry.value = newValue; return newValue; } @Override - public int computeIntIfAbsent(int key, IntUnaryOperator mappingFunction) { + public int computeIntNonDefault(int key, IntIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + int newValue = mappingFunction.applyAsInt(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -494,18 +516,6 @@ public int computeIntIfAbsentNonDefault(int key, IntUnaryOperator mappingFunctio return entry.value; } - @Override - public int supplyIntIfAbsent(int key, IntSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - int newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public int supplyIntIfAbsentNonDefault(int key, IntSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -524,16 +534,6 @@ public int supplyIntIfAbsentNonDefault(int key, IntSupplier valueProvider) { return entry.value; } - @Override - public int computeIntIfPresent(int key, IntIntUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - int newValue = mappingFunction.applyAsInt(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public int computeIntIfPresentNonDefault(int key, IntIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1549,14 +1549,9 @@ public int computeIntIfPresent(int key, IntIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - int newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2IntRBTreeMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2IntRBTreeMap.java index 8c2cd35b..9dc79324 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2IntRBTreeMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2IntRBTreeMap.java @@ -445,34 +445,56 @@ public int computeInt(int key, IntIntUnaryOperator mappingFunction) { } @Override - public int computeIntNonDefault(int key, IntIntUnaryOperator mappingFunction) { + public int computeIntIfAbsent(int key, IntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + int newValue = mappingFunction.applyAsInt(key); put(key, newValue); return newValue; } - int newValue = mappingFunction.applyAsInt(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public int supplyIntIfAbsent(int key, IntSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + int newValue = valueProvider.getAsInt(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public int computeIntIfPresent(int key, IntIntUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + int newValue = mappingFunction.applyAsInt(key, entry.value); entry.value = newValue; return newValue; } @Override - public int computeIntIfAbsent(int key, IntUnaryOperator mappingFunction) { + public int computeIntNonDefault(int key, IntIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + int newValue = mappingFunction.applyAsInt(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -493,18 +515,6 @@ public int computeIntIfAbsentNonDefault(int key, IntUnaryOperator mappingFunctio return entry.value; } - @Override - public int supplyIntIfAbsent(int key, IntSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - int newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public int supplyIntIfAbsentNonDefault(int key, IntSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -523,16 +533,6 @@ public int supplyIntIfAbsentNonDefault(int key, IntSupplier valueProvider) { return entry.value; } - @Override - public int computeIntIfPresent(int key, IntIntUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - int newValue = mappingFunction.applyAsInt(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public int computeIntIfPresentNonDefault(int key, IntIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1612,14 +1612,9 @@ public int computeIntIfPresent(int key, IntIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - int newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2LongAVLTreeMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2LongAVLTreeMap.java index c48768bb..48bbcfe9 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2LongAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2LongAVLTreeMap.java @@ -454,34 +454,56 @@ public long computeLong(int key, IntLongUnaryOperator mappingFunction) { } @Override - public long computeLongNonDefault(int key, IntLongUnaryOperator mappingFunction) { + public long computeLongIfAbsent(int key, Int2LongFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + long newValue = mappingFunction.applyAsLong(key); put(key, newValue); return newValue; } - long newValue = mappingFunction.applyAsLong(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public long supplyLongIfAbsent(int key, LongSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + long newValue = valueProvider.getAsLong(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public long computeLongIfPresent(int key, IntLongUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + long newValue = mappingFunction.applyAsLong(key, entry.value); entry.value = newValue; return newValue; } @Override - public long computeLongIfAbsent(int key, Int2LongFunction mappingFunction) { + public long computeLongNonDefault(int key, IntLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + long newValue = mappingFunction.applyAsLong(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -502,18 +524,6 @@ public long computeLongIfAbsentNonDefault(int key, Int2LongFunction mappingFunct return entry.value; } - @Override - public long supplyLongIfAbsent(int key, LongSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - long newValue = valueProvider.getAsLong(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public long supplyLongIfAbsentNonDefault(int key, LongSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -532,16 +542,6 @@ public long supplyLongIfAbsentNonDefault(int key, LongSupplier valueProvider) { return entry.value; } - @Override - public long computeLongIfPresent(int key, IntLongUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - long newValue = mappingFunction.applyAsLong(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public long computeLongIfPresentNonDefault(int key, IntLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1557,14 +1557,9 @@ public long computeLongIfPresent(int key, IntLongUnaryOperator mappingFunction) Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - long newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2LongRBTreeMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2LongRBTreeMap.java index c1ab9a16..1fb48c8e 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2LongRBTreeMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2LongRBTreeMap.java @@ -453,34 +453,56 @@ public long computeLong(int key, IntLongUnaryOperator mappingFunction) { } @Override - public long computeLongNonDefault(int key, IntLongUnaryOperator mappingFunction) { + public long computeLongIfAbsent(int key, Int2LongFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + long newValue = mappingFunction.applyAsLong(key); put(key, newValue); return newValue; } - long newValue = mappingFunction.applyAsLong(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public long supplyLongIfAbsent(int key, LongSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + long newValue = valueProvider.getAsLong(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public long computeLongIfPresent(int key, IntLongUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + long newValue = mappingFunction.applyAsLong(key, entry.value); entry.value = newValue; return newValue; } @Override - public long computeLongIfAbsent(int key, Int2LongFunction mappingFunction) { + public long computeLongNonDefault(int key, IntLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + long newValue = mappingFunction.applyAsLong(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -501,18 +523,6 @@ public long computeLongIfAbsentNonDefault(int key, Int2LongFunction mappingFunct return entry.value; } - @Override - public long supplyLongIfAbsent(int key, LongSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - long newValue = valueProvider.getAsLong(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public long supplyLongIfAbsentNonDefault(int key, LongSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -531,16 +541,6 @@ public long supplyLongIfAbsentNonDefault(int key, LongSupplier valueProvider) { return entry.value; } - @Override - public long computeLongIfPresent(int key, IntLongUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - long newValue = mappingFunction.applyAsLong(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public long computeLongIfPresentNonDefault(int key, IntLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1620,14 +1620,9 @@ public long computeLongIfPresent(int key, IntLongUnaryOperator mappingFunction) Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - long newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2ObjectAVLTreeMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2ObjectAVLTreeMap.java index 08352874..2d594135 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2ObjectAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2ObjectAVLTreeMap.java @@ -394,25 +394,6 @@ public V compute(int key, IntObjectUnaryOperator mappingFunction) { return newValue; } - @Override - public V computeNonDefault(int key, IntObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) { - V newValue = mappingFunction.apply(key, getDefaultReturnValue()); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - put(key, newValue); - return newValue; - } - V newValue = mappingFunction.apply(key, entry.value); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; - } - @Override public V computeIfAbsent(int key, IntFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -431,24 +412,6 @@ public V computeIfAbsent(int key, IntFunction mappingFunction) { return entry.value; } - @Override - public V computeIfAbsentNonDefault(int key, IntFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) { - V newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - put(key, newValue); - return newValue; - } - if(Objects.equals(entry.value, getDefaultReturnValue())) { - V newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - entry.value = newValue; - } - return entry.value; - } - @Override public V supplyIfAbsent(int key, ObjectSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -467,24 +430,6 @@ public V supplyIfAbsent(int key, ObjectSupplier valueProvider) { return entry.value; } - @Override - public V supplyIfAbsentNonDefault(int key, ObjectSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - V newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - put(key, newValue); - return newValue; - } - if(Objects.equals(entry.value, getDefaultReturnValue())) { - V newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - entry.value = newValue; - } - return entry.value; - } - @Override public V computeIfPresent(int key, IntObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -499,20 +444,6 @@ public V computeIfPresent(int key, IntObjectUnaryOperator mappingFunction) { return newValue; } - @Override - public V computeIfPresentNonDefault(int key, IntObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null || Objects.equals(entry.value, getDefaultReturnValue())) return getDefaultReturnValue(); - V newValue = mappingFunction.apply(key, entry.value); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; - } - @Override public V merge(int key, V value, ObjectObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2ObjectRBTreeMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2ObjectRBTreeMap.java index d3adb112..a301ddea 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2ObjectRBTreeMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2ObjectRBTreeMap.java @@ -393,25 +393,6 @@ public V compute(int key, IntObjectUnaryOperator mappingFunction) { return newValue; } - @Override - public V computeNonDefault(int key, IntObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) { - V newValue = mappingFunction.apply(key, getDefaultReturnValue()); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - put(key, newValue); - return newValue; - } - V newValue = mappingFunction.apply(key, entry.value); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; - } - @Override public V computeIfAbsent(int key, IntFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -430,24 +411,6 @@ public V computeIfAbsent(int key, IntFunction mappingFunction) { return entry.value; } - @Override - public V computeIfAbsentNonDefault(int key, IntFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) { - V newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - put(key, newValue); - return newValue; - } - if(Objects.equals(entry.value, getDefaultReturnValue())) { - V newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - entry.value = newValue; - } - return entry.value; - } - @Override public V supplyIfAbsent(int key, ObjectSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -466,24 +429,6 @@ public V supplyIfAbsent(int key, ObjectSupplier valueProvider) { return entry.value; } - @Override - public V supplyIfAbsentNonDefault(int key, ObjectSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - V newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - put(key, newValue); - return newValue; - } - if(Objects.equals(entry.value, getDefaultReturnValue())) { - V newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - entry.value = newValue; - } - return entry.value; - } - @Override public V computeIfPresent(int key, IntObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -498,20 +443,6 @@ public V computeIfPresent(int key, IntObjectUnaryOperator mappingFunction) { return newValue; } - @Override - public V computeIfPresentNonDefault(int key, IntObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null || Objects.equals(entry.value, getDefaultReturnValue())) return getDefaultReturnValue(); - V newValue = mappingFunction.apply(key, entry.value); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; - } - @Override public V merge(int key, V value, ObjectObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2ShortAVLTreeMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2ShortAVLTreeMap.java index ad8955b6..ec895755 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2ShortAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2ShortAVLTreeMap.java @@ -454,34 +454,56 @@ public short computeShort(int key, IntShortUnaryOperator mappingFunction) { } @Override - public short computeShortNonDefault(int key, IntShortUnaryOperator mappingFunction) { + public short computeShortIfAbsent(int key, Int2ShortFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + short newValue = mappingFunction.applyAsShort(key); put(key, newValue); return newValue; } - short newValue = mappingFunction.applyAsShort(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public short supplyShortIfAbsent(int key, ShortSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + short newValue = valueProvider.getAsShort(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public short computeShortIfPresent(int key, IntShortUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + short newValue = mappingFunction.applyAsShort(key, entry.value); entry.value = newValue; return newValue; } @Override - public short computeShortIfAbsent(int key, Int2ShortFunction mappingFunction) { + public short computeShortNonDefault(int key, IntShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + short newValue = mappingFunction.applyAsShort(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -502,46 +524,24 @@ public short computeShortIfAbsentNonDefault(int key, Int2ShortFunction mappingFu return entry.value; } - @Override - public short supplyShortIfAbsent(int key, ShortSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - short newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public short supplyShortIfAbsentNonDefault(int key, ShortSupplier valueProvider) { Objects.requireNonNull(valueProvider); Node entry = findNode(key); if(entry == null) { - short newValue = valueProvider.getAsInt(); + short newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } if(entry.value == getDefaultReturnValue()) { - short newValue = valueProvider.getAsInt(); + short newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; entry.value = newValue; } return entry.value; } - @Override - public short computeShortIfPresent(int key, IntShortUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - short newValue = mappingFunction.applyAsShort(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public short computeShortIfPresentNonDefault(int key, IntShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1557,14 +1557,9 @@ public short computeShortIfPresent(int key, IntShortUnaryOperator mappingFunctio Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - short newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2ShortRBTreeMap.java b/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2ShortRBTreeMap.java index 2df30c3c..aba819ce 100644 --- a/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2ShortRBTreeMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/impl/tree/Int2ShortRBTreeMap.java @@ -453,34 +453,56 @@ public short computeShort(int key, IntShortUnaryOperator mappingFunction) { } @Override - public short computeShortNonDefault(int key, IntShortUnaryOperator mappingFunction) { + public short computeShortIfAbsent(int key, Int2ShortFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + short newValue = mappingFunction.applyAsShort(key); put(key, newValue); return newValue; } - short newValue = mappingFunction.applyAsShort(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public short supplyShortIfAbsent(int key, ShortSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + short newValue = valueProvider.getAsShort(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public short computeShortIfPresent(int key, IntShortUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + short newValue = mappingFunction.applyAsShort(key, entry.value); entry.value = newValue; return newValue; } @Override - public short computeShortIfAbsent(int key, Int2ShortFunction mappingFunction) { + public short computeShortNonDefault(int key, IntShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + short newValue = mappingFunction.applyAsShort(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -501,46 +523,24 @@ public short computeShortIfAbsentNonDefault(int key, Int2ShortFunction mappingFu return entry.value; } - @Override - public short supplyShortIfAbsent(int key, ShortSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - short newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public short supplyShortIfAbsentNonDefault(int key, ShortSupplier valueProvider) { Objects.requireNonNull(valueProvider); Node entry = findNode(key); if(entry == null) { - short newValue = valueProvider.getAsInt(); + short newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } if(entry.value == getDefaultReturnValue()) { - short newValue = valueProvider.getAsInt(); + short newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; entry.value = newValue; } return entry.value; } - @Override - public short computeShortIfPresent(int key, IntShortUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - short newValue = mappingFunction.applyAsShort(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public short computeShortIfPresentNonDefault(int key, IntShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1620,14 +1620,9 @@ public short computeShortIfPresent(int key, IntShortUnaryOperator mappingFunctio Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - short newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/ints/maps/interfaces/Int2BooleanMap.java b/src/main/java/speiger/src/collections/ints/maps/interfaces/Int2BooleanMap.java index 27f7d666..1563e52a 100644 --- a/src/main/java/speiger/src/collections/ints/maps/interfaces/Int2BooleanMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/interfaces/Int2BooleanMap.java @@ -284,41 +284,51 @@ public default boolean remove(Object key, Object value) { */ public boolean computeBoolean(int key, IntBooleanUnaryOperator mappingFunction); /** - * A Type Specific compute method to reduce boxing/unboxing + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation + * @param mappingFunction the operator that should generate the value if not present + * @return the result of the computed value or present value */ - public boolean computeBooleanNonDefault(int key, IntBooleanUnaryOperator mappingFunction); + public boolean computeBooleanIfAbsent(int key, IntPredicate mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present + * @param valueProvider the value if not present * @return the result of the computed value or present value + */ + public boolean supplyBooleanIfAbsent(int key, BooleanSupplier valueProvider); + /** + * A Type Specific compute method to reduce boxing/unboxing + * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". + * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. + * @param key the key that should be computed + * @param mappingFunction the operator that should generate the value if present + * @return the result of the default return value or present value + * @note if not present then compute is not executed */ - public boolean computeBooleanIfAbsent(int key, IntPredicate mappingFunction); + public boolean computeBooleanIfPresent(int key, IntBooleanUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value + * @param mappingFunction the operator that should generate the value + * @return the result of the computation */ - public boolean computeBooleanIfAbsentNonDefault(int key, IntPredicate mappingFunction); + public boolean computeBooleanNonDefault(int key, IntBooleanUnaryOperator mappingFunction); /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param valueProvider the value if not present + * @param mappingFunction the operator that should generate the value if not present * @return the result of the computed value or present value - */ - public boolean supplyBooleanIfAbsent(int key, BooleanSupplier valueProvider); + */ + public boolean computeBooleanIfAbsentNonDefault(int key, IntPredicate mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -328,16 +338,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public boolean supplyBooleanIfAbsentNonDefault(int key, BooleanSupplier valueProvider); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public boolean computeBooleanIfPresent(int key, IntBooleanUnaryOperator mappingFunction); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/ints/maps/interfaces/Int2ByteMap.java b/src/main/java/speiger/src/collections/ints/maps/interfaces/Int2ByteMap.java index be9d544d..dc684ac2 100644 --- a/src/main/java/speiger/src/collections/ints/maps/interfaces/Int2ByteMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/interfaces/Int2ByteMap.java @@ -309,41 +309,51 @@ public default boolean remove(Object key, Object value) { */ public byte computeByte(int key, IntByteUnaryOperator mappingFunction); /** - * A Type Specific compute method to reduce boxing/unboxing + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation + * @param mappingFunction the operator that should generate the value if not present + * @return the result of the computed value or present value */ - public byte computeByteNonDefault(int key, IntByteUnaryOperator mappingFunction); + public byte computeByteIfAbsent(int key, Int2ByteFunction mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present + * @param valueProvider the value if not present * @return the result of the computed value or present value + */ + public byte supplyByteIfAbsent(int key, ByteSupplier valueProvider); + /** + * A Type Specific compute method to reduce boxing/unboxing + * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". + * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. + * @param key the key that should be computed + * @param mappingFunction the operator that should generate the value if present + * @return the result of the default return value or present value + * @note if not present then compute is not executed */ - public byte computeByteIfAbsent(int key, Int2ByteFunction mappingFunction); + public byte computeByteIfPresent(int key, IntByteUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value + * @param mappingFunction the operator that should generate the value + * @return the result of the computation */ - public byte computeByteIfAbsentNonDefault(int key, Int2ByteFunction mappingFunction); + public byte computeByteNonDefault(int key, IntByteUnaryOperator mappingFunction); /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param valueProvider the value if not present + * @param mappingFunction the operator that should generate the value if not present * @return the result of the computed value or present value - */ - public byte supplyByteIfAbsent(int key, ByteSupplier valueProvider); + */ + public byte computeByteIfAbsentNonDefault(int key, Int2ByteFunction mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -353,16 +363,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public byte supplyByteIfAbsentNonDefault(int key, ByteSupplier valueProvider); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public byte computeByteIfPresent(int key, IntByteUnaryOperator mappingFunction); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/ints/maps/interfaces/Int2CharMap.java b/src/main/java/speiger/src/collections/ints/maps/interfaces/Int2CharMap.java index 53c0699b..e693300d 100644 --- a/src/main/java/speiger/src/collections/ints/maps/interfaces/Int2CharMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/interfaces/Int2CharMap.java @@ -309,41 +309,51 @@ public default boolean remove(Object key, Object value) { */ public char computeChar(int key, IntCharUnaryOperator mappingFunction); /** - * A Type Specific compute method to reduce boxing/unboxing + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation + * @param mappingFunction the operator that should generate the value if not present + * @return the result of the computed value or present value */ - public char computeCharNonDefault(int key, IntCharUnaryOperator mappingFunction); + public char computeCharIfAbsent(int key, Int2CharFunction mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present + * @param valueProvider the value if not present * @return the result of the computed value or present value + */ + public char supplyCharIfAbsent(int key, CharSupplier valueProvider); + /** + * A Type Specific compute method to reduce boxing/unboxing + * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". + * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. + * @param key the key that should be computed + * @param mappingFunction the operator that should generate the value if present + * @return the result of the default return value or present value + * @note if not present then compute is not executed */ - public char computeCharIfAbsent(int key, Int2CharFunction mappingFunction); + public char computeCharIfPresent(int key, IntCharUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value + * @param mappingFunction the operator that should generate the value + * @return the result of the computation */ - public char computeCharIfAbsentNonDefault(int key, Int2CharFunction mappingFunction); + public char computeCharNonDefault(int key, IntCharUnaryOperator mappingFunction); /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param valueProvider the value if not present + * @param mappingFunction the operator that should generate the value if not present * @return the result of the computed value or present value - */ - public char supplyCharIfAbsent(int key, CharSupplier valueProvider); + */ + public char computeCharIfAbsentNonDefault(int key, Int2CharFunction mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -353,16 +363,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public char supplyCharIfAbsentNonDefault(int key, CharSupplier valueProvider); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public char computeCharIfPresent(int key, IntCharUnaryOperator mappingFunction); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/ints/maps/interfaces/Int2DoubleMap.java b/src/main/java/speiger/src/collections/ints/maps/interfaces/Int2DoubleMap.java index 52df359b..bc34d34f 100644 --- a/src/main/java/speiger/src/collections/ints/maps/interfaces/Int2DoubleMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/interfaces/Int2DoubleMap.java @@ -309,41 +309,51 @@ public default boolean remove(Object key, Object value) { */ public double computeDouble(int key, IntDoubleUnaryOperator mappingFunction); /** - * A Type Specific compute method to reduce boxing/unboxing + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation + * @param mappingFunction the operator that should generate the value if not present + * @return the result of the computed value or present value */ - public double computeDoubleNonDefault(int key, IntDoubleUnaryOperator mappingFunction); + public double computeDoubleIfAbsent(int key, Int2DoubleFunction mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present + * @param valueProvider the value if not present * @return the result of the computed value or present value + */ + public double supplyDoubleIfAbsent(int key, DoubleSupplier valueProvider); + /** + * A Type Specific compute method to reduce boxing/unboxing + * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". + * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. + * @param key the key that should be computed + * @param mappingFunction the operator that should generate the value if present + * @return the result of the default return value or present value + * @note if not present then compute is not executed */ - public double computeDoubleIfAbsent(int key, Int2DoubleFunction mappingFunction); + public double computeDoubleIfPresent(int key, IntDoubleUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value + * @param mappingFunction the operator that should generate the value + * @return the result of the computation */ - public double computeDoubleIfAbsentNonDefault(int key, Int2DoubleFunction mappingFunction); + public double computeDoubleNonDefault(int key, IntDoubleUnaryOperator mappingFunction); /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param valueProvider the value if not present + * @param mappingFunction the operator that should generate the value if not present * @return the result of the computed value or present value - */ - public double supplyDoubleIfAbsent(int key, DoubleSupplier valueProvider); + */ + public double computeDoubleIfAbsentNonDefault(int key, Int2DoubleFunction mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -353,16 +363,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public double supplyDoubleIfAbsentNonDefault(int key, DoubleSupplier valueProvider); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public double computeDoubleIfPresent(int key, IntDoubleUnaryOperator mappingFunction); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/ints/maps/interfaces/Int2FloatMap.java b/src/main/java/speiger/src/collections/ints/maps/interfaces/Int2FloatMap.java index 8d6f621a..9f6def3f 100644 --- a/src/main/java/speiger/src/collections/ints/maps/interfaces/Int2FloatMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/interfaces/Int2FloatMap.java @@ -309,41 +309,51 @@ public default boolean remove(Object key, Object value) { */ public float computeFloat(int key, IntFloatUnaryOperator mappingFunction); /** - * A Type Specific compute method to reduce boxing/unboxing + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation + * @param mappingFunction the operator that should generate the value if not present + * @return the result of the computed value or present value */ - public float computeFloatNonDefault(int key, IntFloatUnaryOperator mappingFunction); + public float computeFloatIfAbsent(int key, Int2FloatFunction mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present + * @param valueProvider the value if not present * @return the result of the computed value or present value + */ + public float supplyFloatIfAbsent(int key, FloatSupplier valueProvider); + /** + * A Type Specific compute method to reduce boxing/unboxing + * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". + * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. + * @param key the key that should be computed + * @param mappingFunction the operator that should generate the value if present + * @return the result of the default return value or present value + * @note if not present then compute is not executed */ - public float computeFloatIfAbsent(int key, Int2FloatFunction mappingFunction); + public float computeFloatIfPresent(int key, IntFloatUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value + * @param mappingFunction the operator that should generate the value + * @return the result of the computation */ - public float computeFloatIfAbsentNonDefault(int key, Int2FloatFunction mappingFunction); + public float computeFloatNonDefault(int key, IntFloatUnaryOperator mappingFunction); /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param valueProvider the value if not present + * @param mappingFunction the operator that should generate the value if not present * @return the result of the computed value or present value - */ - public float supplyFloatIfAbsent(int key, FloatSupplier valueProvider); + */ + public float computeFloatIfAbsentNonDefault(int key, Int2FloatFunction mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -353,16 +363,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public float supplyFloatIfAbsentNonDefault(int key, FloatSupplier valueProvider); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public float computeFloatIfPresent(int key, IntFloatUnaryOperator mappingFunction); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/ints/maps/interfaces/Int2IntMap.java b/src/main/java/speiger/src/collections/ints/maps/interfaces/Int2IntMap.java index 472413ae..9bfae1a9 100644 --- a/src/main/java/speiger/src/collections/ints/maps/interfaces/Int2IntMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/interfaces/Int2IntMap.java @@ -308,41 +308,51 @@ public default boolean remove(Object key, Object value) { */ public int computeInt(int key, IntIntUnaryOperator mappingFunction); /** - * A Type Specific compute method to reduce boxing/unboxing + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation + * @param mappingFunction the operator that should generate the value if not present + * @return the result of the computed value or present value */ - public int computeIntNonDefault(int key, IntIntUnaryOperator mappingFunction); + public int computeIntIfAbsent(int key, IntUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present + * @param valueProvider the value if not present * @return the result of the computed value or present value + */ + public int supplyIntIfAbsent(int key, IntSupplier valueProvider); + /** + * A Type Specific compute method to reduce boxing/unboxing + * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". + * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. + * @param key the key that should be computed + * @param mappingFunction the operator that should generate the value if present + * @return the result of the default return value or present value + * @note if not present then compute is not executed */ - public int computeIntIfAbsent(int key, IntUnaryOperator mappingFunction); + public int computeIntIfPresent(int key, IntIntUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value + * @param mappingFunction the operator that should generate the value + * @return the result of the computation */ - public int computeIntIfAbsentNonDefault(int key, IntUnaryOperator mappingFunction); + public int computeIntNonDefault(int key, IntIntUnaryOperator mappingFunction); /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param valueProvider the value if not present + * @param mappingFunction the operator that should generate the value if not present * @return the result of the computed value or present value - */ - public int supplyIntIfAbsent(int key, IntSupplier valueProvider); + */ + public int computeIntIfAbsentNonDefault(int key, IntUnaryOperator mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -352,16 +362,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public int supplyIntIfAbsentNonDefault(int key, IntSupplier valueProvider); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public int computeIntIfPresent(int key, IntIntUnaryOperator mappingFunction); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/ints/maps/interfaces/Int2LongMap.java b/src/main/java/speiger/src/collections/ints/maps/interfaces/Int2LongMap.java index 5f3722c1..375503df 100644 --- a/src/main/java/speiger/src/collections/ints/maps/interfaces/Int2LongMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/interfaces/Int2LongMap.java @@ -309,41 +309,51 @@ public default boolean remove(Object key, Object value) { */ public long computeLong(int key, IntLongUnaryOperator mappingFunction); /** - * A Type Specific compute method to reduce boxing/unboxing + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation + * @param mappingFunction the operator that should generate the value if not present + * @return the result of the computed value or present value */ - public long computeLongNonDefault(int key, IntLongUnaryOperator mappingFunction); + public long computeLongIfAbsent(int key, Int2LongFunction mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present + * @param valueProvider the value if not present * @return the result of the computed value or present value + */ + public long supplyLongIfAbsent(int key, LongSupplier valueProvider); + /** + * A Type Specific compute method to reduce boxing/unboxing + * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". + * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. + * @param key the key that should be computed + * @param mappingFunction the operator that should generate the value if present + * @return the result of the default return value or present value + * @note if not present then compute is not executed */ - public long computeLongIfAbsent(int key, Int2LongFunction mappingFunction); + public long computeLongIfPresent(int key, IntLongUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value + * @param mappingFunction the operator that should generate the value + * @return the result of the computation */ - public long computeLongIfAbsentNonDefault(int key, Int2LongFunction mappingFunction); + public long computeLongNonDefault(int key, IntLongUnaryOperator mappingFunction); /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param valueProvider the value if not present + * @param mappingFunction the operator that should generate the value if not present * @return the result of the computed value or present value - */ - public long supplyLongIfAbsent(int key, LongSupplier valueProvider); + */ + public long computeLongIfAbsentNonDefault(int key, Int2LongFunction mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -353,16 +363,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public long supplyLongIfAbsentNonDefault(int key, LongSupplier valueProvider); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public long computeLongIfPresent(int key, IntLongUnaryOperator mappingFunction); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/ints/maps/interfaces/Int2ObjectMap.java b/src/main/java/speiger/src/collections/ints/maps/interfaces/Int2ObjectMap.java index a6a55674..3ed30dab 100644 --- a/src/main/java/speiger/src/collections/ints/maps/interfaces/Int2ObjectMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/interfaces/Int2ObjectMap.java @@ -266,15 +266,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computation */ public V compute(int key, IntObjectUnaryOperator mappingFunction); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation - */ - public V computeNonDefault(int key, IntObjectUnaryOperator mappingFunction); /** * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -284,15 +275,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public V computeIfAbsent(int key, IntFunction mappingFunction); - /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value - */ - public V computeIfAbsentNonDefault(int key, IntFunction mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -302,15 +284,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public V supplyIfAbsent(int key, ObjectSupplier valueProvider); - /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param valueProvider the value if not present - * @return the result of the computed value or present value - */ - public V supplyIfAbsentNonDefault(int key, ObjectSupplier valueProvider); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -321,16 +294,6 @@ public default boolean remove(Object key, Object value) { * @note if not present then compute is not executed */ public V computeIfPresent(int key, IntObjectUnaryOperator mappingFunction); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public V computeIfPresentNonDefault(int key, IntObjectUnaryOperator mappingFunction); /** * A Type Specific merge method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/ints/maps/interfaces/Int2ShortMap.java b/src/main/java/speiger/src/collections/ints/maps/interfaces/Int2ShortMap.java index 27e22e24..3dafdcec 100644 --- a/src/main/java/speiger/src/collections/ints/maps/interfaces/Int2ShortMap.java +++ b/src/main/java/speiger/src/collections/ints/maps/interfaces/Int2ShortMap.java @@ -309,41 +309,51 @@ public default boolean remove(Object key, Object value) { */ public short computeShort(int key, IntShortUnaryOperator mappingFunction); /** - * A Type Specific compute method to reduce boxing/unboxing + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation + * @param mappingFunction the operator that should generate the value if not present + * @return the result of the computed value or present value */ - public short computeShortNonDefault(int key, IntShortUnaryOperator mappingFunction); + public short computeShortIfAbsent(int key, Int2ShortFunction mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present + * @param valueProvider the value if not present * @return the result of the computed value or present value + */ + public short supplyShortIfAbsent(int key, ShortSupplier valueProvider); + /** + * A Type Specific compute method to reduce boxing/unboxing + * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". + * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. + * @param key the key that should be computed + * @param mappingFunction the operator that should generate the value if present + * @return the result of the default return value or present value + * @note if not present then compute is not executed */ - public short computeShortIfAbsent(int key, Int2ShortFunction mappingFunction); + public short computeShortIfPresent(int key, IntShortUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value + * @param mappingFunction the operator that should generate the value + * @return the result of the computation */ - public short computeShortIfAbsentNonDefault(int key, Int2ShortFunction mappingFunction); + public short computeShortNonDefault(int key, IntShortUnaryOperator mappingFunction); /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param valueProvider the value if not present + * @param mappingFunction the operator that should generate the value if not present * @return the result of the computed value or present value - */ - public short supplyShortIfAbsent(int key, ShortSupplier valueProvider); + */ + public short computeShortIfAbsentNonDefault(int key, Int2ShortFunction mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -353,16 +363,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public short supplyShortIfAbsentNonDefault(int key, ShortSupplier valueProvider); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public short computeShortIfPresent(int key, IntShortUnaryOperator mappingFunction); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/ints/queues/IntArrayFIFOQueue.java b/src/main/java/speiger/src/collections/ints/queues/IntArrayFIFOQueue.java index 8347c092..7003d206 100644 --- a/src/main/java/speiger/src/collections/ints/queues/IntArrayFIFOQueue.java +++ b/src/main/java/speiger/src/collections/ints/queues/IntArrayFIFOQueue.java @@ -146,6 +146,15 @@ public int peek(int index) { return index >= array.length ? array[index-array.length] : array[index]; } + @Override + public boolean contains(int e) { + if(first == last) return false; + for(int i = 0,m=size();i iterator, int repea return new RepeatingIterator(wrap(iterator), repeats); } + /** + * A Helper function that creates a infinitely looping iterator + * @param iterator that should be looping infinitely + * @return a infinitely looping iterator + */ + public static IntIterator infinite(IntIterator iterator) { + return new InfiniteIterator(iterator); + } + + /** + * A Helper function that creates a infinitely looping iterator from a Java Iterator + * @param iterator that should be looping infinitely + * @return a infinitely looping iterator + */ + public static IntIterator infinite(Iterator iterator) { + return new InfiniteIterator(wrap(iterator)); + } + /** * A Helper function that hard limits the Iterator to a specific size * @param iterator that should be limited @@ -841,6 +862,40 @@ public T next() { } } + private static class InfiniteIterator implements IntIterator + { + IntIterator iter; + CollectionWrapper looper = IntCollections.wrapper(); + int index = 0; + + public InfiniteIterator(IntIterator iter) { + this.iter = iter; + } + + @Override + public boolean hasNext() { + return true; + } + + @Override + public int nextInt() { + if(iter != null) { + if(iter.hasNext()) { + int value = iter.nextInt(); + looper.add(value); + return value; + } + else iter = null; + } + return looper.getInt((index++) % looper.size()); + } + + @Override + public void forEachRemaining(IntConsumer action) { throw new UnsupportedOperationException("This is a instant deadlock, so unsupported"); } + public void forEachRemaining(Consumer action) { throw new UnsupportedOperationException("This is a instant deadlock, so unsupported"); } + public void forEachRemaining(E input, ObjectIntConsumer action) { throw new UnsupportedOperationException("This is a instant deadlock, so unsupported"); } + } + private static class RepeatingIterator implements IntIterator { final int repeats; diff --git a/src/main/java/speiger/src/collections/ints/utils/IntLists.java b/src/main/java/speiger/src/collections/ints/utils/IntLists.java index b75418b2..cde1333e 100644 --- a/src/main/java/speiger/src/collections/ints/utils/IntLists.java +++ b/src/main/java/speiger/src/collections/ints/utils/IntLists.java @@ -317,6 +317,16 @@ public IntListIterator listIterator(int index) { return l.listIterator(index); } + @Override + public IntListIterator indexedIterator(int...indecies) { + return l.indexedIterator(indecies); + } + + @Override + public IntListIterator indexedIterator(IntList indecies) { + return l.indexedIterator(indecies); + } + @Override public IntList subList(int from, int to) { return IntLists.synchronize(l.subList(from, to)); @@ -426,6 +436,16 @@ public IntListIterator listIterator(int index) { return IntIterators.unmodifiable(l.listIterator(index)); } + @Override + public IntListIterator indexedIterator(int...indecies) { + return IntIterators.unmodifiable(l.indexedIterator(indecies)); + } + + @Override + public IntListIterator indexedIterator(IntList indecies) { + return IntIterators.unmodifiable(l.indexedIterator(indecies)); + } + @Override public IntList subList(int from, int to) { return IntLists.unmodifiable(l.subList(from, to)); @@ -514,6 +534,16 @@ public IntListIterator listIterator(int index) { return IntIterators.empty(); } + @Override + public IntListIterator indexedIterator(int...indecies) { + return IntIterators.empty(); + } + + @Override + public IntListIterator indexedIterator(IntList indecies) { + return IntIterators.empty(); + } + @Override public int hashCode() { return 1; } diff --git a/src/main/java/speiger/src/collections/ints/utils/IntPriorityQueues.java b/src/main/java/speiger/src/collections/ints/utils/IntPriorityQueues.java index 954066f2..3cc8bb48 100644 --- a/src/main/java/speiger/src/collections/ints/utils/IntPriorityQueues.java +++ b/src/main/java/speiger/src/collections/ints/utils/IntPriorityQueues.java @@ -89,6 +89,8 @@ protected SynchronizedPriorityQueue(IntPriorityQueue queue, Object mutex) { @Override public int peek(int index) { synchronized(mutex) { return queue.peek(index); } } @Override + public boolean contains(int e) { synchronized(mutex) { return queue.contains(e); } } + @Override public boolean removeFirst(int e) { synchronized(mutex) { return queue.removeFirst(e); } } @Override public boolean removeLast(int e) { synchronized(mutex) { return queue.removeLast(e); } } diff --git a/src/main/java/speiger/src/collections/ints/utils/maps/Int2BooleanMaps.java b/src/main/java/speiger/src/collections/ints/utils/maps/Int2BooleanMaps.java index 2d3efa96..22135099 100644 --- a/src/main/java/speiger/src/collections/ints/utils/maps/Int2BooleanMaps.java +++ b/src/main/java/speiger/src/collections/ints/utils/maps/Int2BooleanMaps.java @@ -246,18 +246,18 @@ public static class SingletonMap extends AbstractInt2BooleanMap { @Override public boolean computeBoolean(int key, IntBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanNonDefault(int key, IntBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean computeBooleanIfAbsent(int key, IntPredicate mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanIfAbsentNonDefault(int key, IntPredicate mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean computeBooleanIfPresent(int key, IntBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanIfPresentNonDefault(int key, IntBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean supplyBooleanIfAbsent(int key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public boolean computeBooleanNonDefault(int key, IntBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public boolean computeBooleanIfAbsentNonDefault(int key, IntPredicate mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public boolean computeBooleanIfPresentNonDefault(int key, IntBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public boolean supplyBooleanIfAbsentNonDefault(int key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public boolean mergeBoolean(int key, boolean value, BooleanBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -304,18 +304,18 @@ public static class EmptyMap extends AbstractInt2BooleanMap { @Override public boolean computeBoolean(int key, IntBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanNonDefault(int key, IntBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean computeBooleanIfAbsent(int key, IntPredicate mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanIfAbsentNonDefault(int key, IntPredicate mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean computeBooleanIfPresent(int key, IntBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanIfPresentNonDefault(int key, IntBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean supplyBooleanIfAbsent(int key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public boolean computeBooleanNonDefault(int key, IntBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public boolean computeBooleanIfAbsentNonDefault(int key, IntPredicate mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public boolean computeBooleanIfPresentNonDefault(int key, IntBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public boolean supplyBooleanIfAbsentNonDefault(int key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public boolean mergeBoolean(int key, boolean value, BooleanBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -535,18 +535,18 @@ public boolean get(int key) { @Override public boolean computeBoolean(int key, IntBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanNonDefault(int key, IntBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean computeBooleanIfAbsent(int key, IntPredicate mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanIfAbsentNonDefault(int key, IntPredicate mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean computeBooleanIfPresent(int key, IntBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanIfPresentNonDefault(int key, IntBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean supplyBooleanIfAbsent(int key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public boolean computeBooleanNonDefault(int key, IntBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public boolean computeBooleanIfAbsentNonDefault(int key, IntPredicate mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public boolean computeBooleanIfPresentNonDefault(int key, IntBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public boolean supplyBooleanIfAbsentNonDefault(int key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public boolean mergeBoolean(int key, boolean value, BooleanBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -938,18 +938,18 @@ public AbstractInt2BooleanMap setDefaultReturnValue(boolean v) { @Override public boolean computeBoolean(int key, IntBooleanUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeBoolean(key, mappingFunction); } } @Override - public boolean computeBooleanNonDefault(int key, IntBooleanUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeBooleanNonDefault(key, mappingFunction); } } - @Override public boolean computeBooleanIfAbsent(int key, IntPredicate mappingFunction) { synchronized(mutex) { return map.computeBooleanIfAbsent(key, mappingFunction); } } @Override - public boolean computeBooleanIfAbsentNonDefault(int key, IntPredicate mappingFunction) { synchronized(mutex) { return map.computeBooleanIfAbsentNonDefault(key, mappingFunction); } } - @Override public boolean computeBooleanIfPresent(int key, IntBooleanUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeBooleanIfPresent(key, mappingFunction); } } @Override - public boolean computeBooleanIfPresentNonDefault(int key, IntBooleanUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeBooleanIfPresentNonDefault(key, mappingFunction); } } - @Override public boolean supplyBooleanIfAbsent(int key, BooleanSupplier valueProvider) { synchronized(mutex) { return map.supplyBooleanIfAbsent(key, valueProvider); } } @Override + public boolean computeBooleanNonDefault(int key, IntBooleanUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeBooleanNonDefault(key, mappingFunction); } } + @Override + public boolean computeBooleanIfAbsentNonDefault(int key, IntPredicate mappingFunction) { synchronized(mutex) { return map.computeBooleanIfAbsentNonDefault(key, mappingFunction); } } + @Override + public boolean computeBooleanIfPresentNonDefault(int key, IntBooleanUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeBooleanIfPresentNonDefault(key, mappingFunction); } } + @Override public boolean supplyBooleanIfAbsentNonDefault(int key, BooleanSupplier valueProvider) { synchronized(mutex) { return map.supplyBooleanIfAbsentNonDefault(key, valueProvider); } } @Override public boolean mergeBoolean(int key, boolean value, BooleanBooleanUnaryOperator mappingFunction) { synchronized(mutex) { return map.mergeBoolean(key, value, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/ints/utils/maps/Int2ByteMaps.java b/src/main/java/speiger/src/collections/ints/utils/maps/Int2ByteMaps.java index 08ff2f66..fe794e5d 100644 --- a/src/main/java/speiger/src/collections/ints/utils/maps/Int2ByteMaps.java +++ b/src/main/java/speiger/src/collections/ints/utils/maps/Int2ByteMaps.java @@ -250,18 +250,18 @@ public static class SingletonMap extends AbstractInt2ByteMap { @Override public byte computeByte(int key, IntByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteNonDefault(int key, IntByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte computeByteIfAbsent(int key, Int2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteIfAbsentNonDefault(int key, Int2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte computeByteIfPresent(int key, IntByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteIfPresentNonDefault(int key, IntByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte supplyByteIfAbsent(int key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public byte computeByteNonDefault(int key, IntByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public byte computeByteIfAbsentNonDefault(int key, Int2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public byte computeByteIfPresentNonDefault(int key, IntByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public byte supplyByteIfAbsentNonDefault(int key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public byte mergeByte(int key, byte value, ByteByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -312,18 +312,18 @@ public static class EmptyMap extends AbstractInt2ByteMap { @Override public byte computeByte(int key, IntByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteNonDefault(int key, IntByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte computeByteIfAbsent(int key, Int2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteIfAbsentNonDefault(int key, Int2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte computeByteIfPresent(int key, IntByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteIfPresentNonDefault(int key, IntByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte supplyByteIfAbsent(int key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public byte computeByteNonDefault(int key, IntByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public byte computeByteIfAbsentNonDefault(int key, Int2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public byte computeByteIfPresentNonDefault(int key, IntByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public byte supplyByteIfAbsentNonDefault(int key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public byte mergeByte(int key, byte value, ByteByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -547,18 +547,18 @@ public byte get(int key) { @Override public byte computeByte(int key, IntByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteNonDefault(int key, IntByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte computeByteIfAbsent(int key, Int2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteIfAbsentNonDefault(int key, Int2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte computeByteIfPresent(int key, IntByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteIfPresentNonDefault(int key, IntByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte supplyByteIfAbsent(int key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public byte computeByteNonDefault(int key, IntByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public byte computeByteIfAbsentNonDefault(int key, Int2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public byte computeByteIfPresentNonDefault(int key, IntByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public byte supplyByteIfAbsentNonDefault(int key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public byte mergeByte(int key, byte value, ByteByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -955,18 +955,18 @@ public AbstractInt2ByteMap setDefaultReturnValue(byte v) { @Override public byte computeByte(int key, IntByteUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeByte(key, mappingFunction); } } @Override - public byte computeByteNonDefault(int key, IntByteUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeByteNonDefault(key, mappingFunction); } } - @Override public byte computeByteIfAbsent(int key, Int2ByteFunction mappingFunction) { synchronized(mutex) { return map.computeByteIfAbsent(key, mappingFunction); } } @Override - public byte computeByteIfAbsentNonDefault(int key, Int2ByteFunction mappingFunction) { synchronized(mutex) { return map.computeByteIfAbsentNonDefault(key, mappingFunction); } } - @Override public byte computeByteIfPresent(int key, IntByteUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeByteIfPresent(key, mappingFunction); } } @Override - public byte computeByteIfPresentNonDefault(int key, IntByteUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeByteIfPresentNonDefault(key, mappingFunction); } } - @Override public byte supplyByteIfAbsent(int key, ByteSupplier valueProvider) { synchronized(mutex) { return map.supplyByteIfAbsent(key, valueProvider); } } @Override + public byte computeByteNonDefault(int key, IntByteUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeByteNonDefault(key, mappingFunction); } } + @Override + public byte computeByteIfAbsentNonDefault(int key, Int2ByteFunction mappingFunction) { synchronized(mutex) { return map.computeByteIfAbsentNonDefault(key, mappingFunction); } } + @Override + public byte computeByteIfPresentNonDefault(int key, IntByteUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeByteIfPresentNonDefault(key, mappingFunction); } } + @Override public byte supplyByteIfAbsentNonDefault(int key, ByteSupplier valueProvider) { synchronized(mutex) { return map.supplyByteIfAbsentNonDefault(key, valueProvider); } } @Override public byte mergeByte(int key, byte value, ByteByteUnaryOperator mappingFunction) { synchronized(mutex) { return map.mergeByte(key, value, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/ints/utils/maps/Int2CharMaps.java b/src/main/java/speiger/src/collections/ints/utils/maps/Int2CharMaps.java index 5a2180d7..ccef037b 100644 --- a/src/main/java/speiger/src/collections/ints/utils/maps/Int2CharMaps.java +++ b/src/main/java/speiger/src/collections/ints/utils/maps/Int2CharMaps.java @@ -250,18 +250,18 @@ public static class SingletonMap extends AbstractInt2CharMap { @Override public char computeChar(int key, IntCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharNonDefault(int key, IntCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char computeCharIfAbsent(int key, Int2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharIfAbsentNonDefault(int key, Int2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char computeCharIfPresent(int key, IntCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharIfPresentNonDefault(int key, IntCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char supplyCharIfAbsent(int key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public char computeCharNonDefault(int key, IntCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public char computeCharIfAbsentNonDefault(int key, Int2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public char computeCharIfPresentNonDefault(int key, IntCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public char supplyCharIfAbsentNonDefault(int key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public char mergeChar(int key, char value, CharCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -312,18 +312,18 @@ public static class EmptyMap extends AbstractInt2CharMap { @Override public char computeChar(int key, IntCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharNonDefault(int key, IntCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char computeCharIfAbsent(int key, Int2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharIfAbsentNonDefault(int key, Int2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char computeCharIfPresent(int key, IntCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharIfPresentNonDefault(int key, IntCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char supplyCharIfAbsent(int key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public char computeCharNonDefault(int key, IntCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public char computeCharIfAbsentNonDefault(int key, Int2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public char computeCharIfPresentNonDefault(int key, IntCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public char supplyCharIfAbsentNonDefault(int key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public char mergeChar(int key, char value, CharCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -547,18 +547,18 @@ public char get(int key) { @Override public char computeChar(int key, IntCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharNonDefault(int key, IntCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char computeCharIfAbsent(int key, Int2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharIfAbsentNonDefault(int key, Int2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char computeCharIfPresent(int key, IntCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharIfPresentNonDefault(int key, IntCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char supplyCharIfAbsent(int key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public char computeCharNonDefault(int key, IntCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public char computeCharIfAbsentNonDefault(int key, Int2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public char computeCharIfPresentNonDefault(int key, IntCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public char supplyCharIfAbsentNonDefault(int key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public char mergeChar(int key, char value, CharCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -955,18 +955,18 @@ public AbstractInt2CharMap setDefaultReturnValue(char v) { @Override public char computeChar(int key, IntCharUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeChar(key, mappingFunction); } } @Override - public char computeCharNonDefault(int key, IntCharUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeCharNonDefault(key, mappingFunction); } } - @Override public char computeCharIfAbsent(int key, Int2CharFunction mappingFunction) { synchronized(mutex) { return map.computeCharIfAbsent(key, mappingFunction); } } @Override - public char computeCharIfAbsentNonDefault(int key, Int2CharFunction mappingFunction) { synchronized(mutex) { return map.computeCharIfAbsentNonDefault(key, mappingFunction); } } - @Override public char computeCharIfPresent(int key, IntCharUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeCharIfPresent(key, mappingFunction); } } @Override - public char computeCharIfPresentNonDefault(int key, IntCharUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeCharIfPresentNonDefault(key, mappingFunction); } } - @Override public char supplyCharIfAbsent(int key, CharSupplier valueProvider) { synchronized(mutex) { return map.supplyCharIfAbsent(key, valueProvider); } } @Override + public char computeCharNonDefault(int key, IntCharUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeCharNonDefault(key, mappingFunction); } } + @Override + public char computeCharIfAbsentNonDefault(int key, Int2CharFunction mappingFunction) { synchronized(mutex) { return map.computeCharIfAbsentNonDefault(key, mappingFunction); } } + @Override + public char computeCharIfPresentNonDefault(int key, IntCharUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeCharIfPresentNonDefault(key, mappingFunction); } } + @Override public char supplyCharIfAbsentNonDefault(int key, CharSupplier valueProvider) { synchronized(mutex) { return map.supplyCharIfAbsentNonDefault(key, valueProvider); } } @Override public char mergeChar(int key, char value, CharCharUnaryOperator mappingFunction) { synchronized(mutex) { return map.mergeChar(key, value, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/ints/utils/maps/Int2DoubleMaps.java b/src/main/java/speiger/src/collections/ints/utils/maps/Int2DoubleMaps.java index 0853ef2f..9853a789 100644 --- a/src/main/java/speiger/src/collections/ints/utils/maps/Int2DoubleMaps.java +++ b/src/main/java/speiger/src/collections/ints/utils/maps/Int2DoubleMaps.java @@ -250,18 +250,18 @@ public static class SingletonMap extends AbstractInt2DoubleMap { @Override public double computeDouble(int key, IntDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleNonDefault(int key, IntDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double computeDoubleIfAbsent(int key, Int2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleIfAbsentNonDefault(int key, Int2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double computeDoubleIfPresent(int key, IntDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleIfPresentNonDefault(int key, IntDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double supplyDoubleIfAbsent(int key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public double computeDoubleNonDefault(int key, IntDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public double computeDoubleIfAbsentNonDefault(int key, Int2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public double computeDoubleIfPresentNonDefault(int key, IntDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public double supplyDoubleIfAbsentNonDefault(int key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public double mergeDouble(int key, double value, DoubleDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -312,18 +312,18 @@ public static class EmptyMap extends AbstractInt2DoubleMap { @Override public double computeDouble(int key, IntDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleNonDefault(int key, IntDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double computeDoubleIfAbsent(int key, Int2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleIfAbsentNonDefault(int key, Int2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double computeDoubleIfPresent(int key, IntDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleIfPresentNonDefault(int key, IntDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double supplyDoubleIfAbsent(int key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public double computeDoubleNonDefault(int key, IntDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public double computeDoubleIfAbsentNonDefault(int key, Int2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public double computeDoubleIfPresentNonDefault(int key, IntDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public double supplyDoubleIfAbsentNonDefault(int key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public double mergeDouble(int key, double value, DoubleDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -547,18 +547,18 @@ public double get(int key) { @Override public double computeDouble(int key, IntDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleNonDefault(int key, IntDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double computeDoubleIfAbsent(int key, Int2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleIfAbsentNonDefault(int key, Int2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double computeDoubleIfPresent(int key, IntDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleIfPresentNonDefault(int key, IntDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double supplyDoubleIfAbsent(int key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public double computeDoubleNonDefault(int key, IntDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public double computeDoubleIfAbsentNonDefault(int key, Int2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public double computeDoubleIfPresentNonDefault(int key, IntDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public double supplyDoubleIfAbsentNonDefault(int key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public double mergeDouble(int key, double value, DoubleDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -955,18 +955,18 @@ public AbstractInt2DoubleMap setDefaultReturnValue(double v) { @Override public double computeDouble(int key, IntDoubleUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeDouble(key, mappingFunction); } } @Override - public double computeDoubleNonDefault(int key, IntDoubleUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeDoubleNonDefault(key, mappingFunction); } } - @Override public double computeDoubleIfAbsent(int key, Int2DoubleFunction mappingFunction) { synchronized(mutex) { return map.computeDoubleIfAbsent(key, mappingFunction); } } @Override - public double computeDoubleIfAbsentNonDefault(int key, Int2DoubleFunction mappingFunction) { synchronized(mutex) { return map.computeDoubleIfAbsentNonDefault(key, mappingFunction); } } - @Override public double computeDoubleIfPresent(int key, IntDoubleUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeDoubleIfPresent(key, mappingFunction); } } @Override - public double computeDoubleIfPresentNonDefault(int key, IntDoubleUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeDoubleIfPresentNonDefault(key, mappingFunction); } } - @Override public double supplyDoubleIfAbsent(int key, DoubleSupplier valueProvider) { synchronized(mutex) { return map.supplyDoubleIfAbsent(key, valueProvider); } } @Override + public double computeDoubleNonDefault(int key, IntDoubleUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeDoubleNonDefault(key, mappingFunction); } } + @Override + public double computeDoubleIfAbsentNonDefault(int key, Int2DoubleFunction mappingFunction) { synchronized(mutex) { return map.computeDoubleIfAbsentNonDefault(key, mappingFunction); } } + @Override + public double computeDoubleIfPresentNonDefault(int key, IntDoubleUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeDoubleIfPresentNonDefault(key, mappingFunction); } } + @Override public double supplyDoubleIfAbsentNonDefault(int key, DoubleSupplier valueProvider) { synchronized(mutex) { return map.supplyDoubleIfAbsentNonDefault(key, valueProvider); } } @Override public double mergeDouble(int key, double value, DoubleDoubleUnaryOperator mappingFunction) { synchronized(mutex) { return map.mergeDouble(key, value, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/ints/utils/maps/Int2FloatMaps.java b/src/main/java/speiger/src/collections/ints/utils/maps/Int2FloatMaps.java index 87829bb8..d7a416c1 100644 --- a/src/main/java/speiger/src/collections/ints/utils/maps/Int2FloatMaps.java +++ b/src/main/java/speiger/src/collections/ints/utils/maps/Int2FloatMaps.java @@ -250,18 +250,18 @@ public static class SingletonMap extends AbstractInt2FloatMap { @Override public float computeFloat(int key, IntFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatNonDefault(int key, IntFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float computeFloatIfAbsent(int key, Int2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatIfAbsentNonDefault(int key, Int2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float computeFloatIfPresent(int key, IntFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatIfPresentNonDefault(int key, IntFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float supplyFloatIfAbsent(int key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public float computeFloatNonDefault(int key, IntFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public float computeFloatIfAbsentNonDefault(int key, Int2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public float computeFloatIfPresentNonDefault(int key, IntFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public float supplyFloatIfAbsentNonDefault(int key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public float mergeFloat(int key, float value, FloatFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -312,18 +312,18 @@ public static class EmptyMap extends AbstractInt2FloatMap { @Override public float computeFloat(int key, IntFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatNonDefault(int key, IntFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float computeFloatIfAbsent(int key, Int2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatIfAbsentNonDefault(int key, Int2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float computeFloatIfPresent(int key, IntFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatIfPresentNonDefault(int key, IntFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float supplyFloatIfAbsent(int key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public float computeFloatNonDefault(int key, IntFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public float computeFloatIfAbsentNonDefault(int key, Int2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public float computeFloatIfPresentNonDefault(int key, IntFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public float supplyFloatIfAbsentNonDefault(int key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public float mergeFloat(int key, float value, FloatFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -547,18 +547,18 @@ public float get(int key) { @Override public float computeFloat(int key, IntFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatNonDefault(int key, IntFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float computeFloatIfAbsent(int key, Int2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatIfAbsentNonDefault(int key, Int2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float computeFloatIfPresent(int key, IntFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatIfPresentNonDefault(int key, IntFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float supplyFloatIfAbsent(int key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public float computeFloatNonDefault(int key, IntFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public float computeFloatIfAbsentNonDefault(int key, Int2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public float computeFloatIfPresentNonDefault(int key, IntFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public float supplyFloatIfAbsentNonDefault(int key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public float mergeFloat(int key, float value, FloatFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -955,18 +955,18 @@ public AbstractInt2FloatMap setDefaultReturnValue(float v) { @Override public float computeFloat(int key, IntFloatUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeFloat(key, mappingFunction); } } @Override - public float computeFloatNonDefault(int key, IntFloatUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeFloatNonDefault(key, mappingFunction); } } - @Override public float computeFloatIfAbsent(int key, Int2FloatFunction mappingFunction) { synchronized(mutex) { return map.computeFloatIfAbsent(key, mappingFunction); } } @Override - public float computeFloatIfAbsentNonDefault(int key, Int2FloatFunction mappingFunction) { synchronized(mutex) { return map.computeFloatIfAbsentNonDefault(key, mappingFunction); } } - @Override public float computeFloatIfPresent(int key, IntFloatUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeFloatIfPresent(key, mappingFunction); } } @Override - public float computeFloatIfPresentNonDefault(int key, IntFloatUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeFloatIfPresentNonDefault(key, mappingFunction); } } - @Override public float supplyFloatIfAbsent(int key, FloatSupplier valueProvider) { synchronized(mutex) { return map.supplyFloatIfAbsent(key, valueProvider); } } @Override + public float computeFloatNonDefault(int key, IntFloatUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeFloatNonDefault(key, mappingFunction); } } + @Override + public float computeFloatIfAbsentNonDefault(int key, Int2FloatFunction mappingFunction) { synchronized(mutex) { return map.computeFloatIfAbsentNonDefault(key, mappingFunction); } } + @Override + public float computeFloatIfPresentNonDefault(int key, IntFloatUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeFloatIfPresentNonDefault(key, mappingFunction); } } + @Override public float supplyFloatIfAbsentNonDefault(int key, FloatSupplier valueProvider) { synchronized(mutex) { return map.supplyFloatIfAbsentNonDefault(key, valueProvider); } } @Override public float mergeFloat(int key, float value, FloatFloatUnaryOperator mappingFunction) { synchronized(mutex) { return map.mergeFloat(key, value, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/ints/utils/maps/Int2IntMaps.java b/src/main/java/speiger/src/collections/ints/utils/maps/Int2IntMaps.java index ef9a493e..becac88e 100644 --- a/src/main/java/speiger/src/collections/ints/utils/maps/Int2IntMaps.java +++ b/src/main/java/speiger/src/collections/ints/utils/maps/Int2IntMaps.java @@ -249,18 +249,18 @@ public static class SingletonMap extends AbstractInt2IntMap { @Override public int computeInt(int key, IntIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntNonDefault(int key, IntIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int computeIntIfAbsent(int key, IntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntIfAbsentNonDefault(int key, IntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int computeIntIfPresent(int key, IntIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntIfPresentNonDefault(int key, IntIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int supplyIntIfAbsent(int key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public int computeIntNonDefault(int key, IntIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public int computeIntIfAbsentNonDefault(int key, IntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public int computeIntIfPresentNonDefault(int key, IntIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public int supplyIntIfAbsentNonDefault(int key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public int mergeInt(int key, int value, IntIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -311,18 +311,18 @@ public static class EmptyMap extends AbstractInt2IntMap { @Override public int computeInt(int key, IntIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntNonDefault(int key, IntIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int computeIntIfAbsent(int key, IntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntIfAbsentNonDefault(int key, IntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int computeIntIfPresent(int key, IntIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntIfPresentNonDefault(int key, IntIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int supplyIntIfAbsent(int key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public int computeIntNonDefault(int key, IntIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public int computeIntIfAbsentNonDefault(int key, IntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public int computeIntIfPresentNonDefault(int key, IntIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public int supplyIntIfAbsentNonDefault(int key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public int mergeInt(int key, int value, IntIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -546,18 +546,18 @@ public int get(int key) { @Override public int computeInt(int key, IntIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntNonDefault(int key, IntIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int computeIntIfAbsent(int key, IntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntIfAbsentNonDefault(int key, IntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int computeIntIfPresent(int key, IntIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntIfPresentNonDefault(int key, IntIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int supplyIntIfAbsent(int key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public int computeIntNonDefault(int key, IntIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public int computeIntIfAbsentNonDefault(int key, IntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public int computeIntIfPresentNonDefault(int key, IntIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public int supplyIntIfAbsentNonDefault(int key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public int mergeInt(int key, int value, IntIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -954,18 +954,18 @@ public AbstractInt2IntMap setDefaultReturnValue(int v) { @Override public int computeInt(int key, IntIntUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeInt(key, mappingFunction); } } @Override - public int computeIntNonDefault(int key, IntIntUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeIntNonDefault(key, mappingFunction); } } - @Override public int computeIntIfAbsent(int key, IntUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeIntIfAbsent(key, mappingFunction); } } @Override - public int computeIntIfAbsentNonDefault(int key, IntUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeIntIfAbsentNonDefault(key, mappingFunction); } } - @Override public int computeIntIfPresent(int key, IntIntUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeIntIfPresent(key, mappingFunction); } } @Override - public int computeIntIfPresentNonDefault(int key, IntIntUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeIntIfPresentNonDefault(key, mappingFunction); } } - @Override public int supplyIntIfAbsent(int key, IntSupplier valueProvider) { synchronized(mutex) { return map.supplyIntIfAbsent(key, valueProvider); } } @Override + public int computeIntNonDefault(int key, IntIntUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeIntNonDefault(key, mappingFunction); } } + @Override + public int computeIntIfAbsentNonDefault(int key, IntUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeIntIfAbsentNonDefault(key, mappingFunction); } } + @Override + public int computeIntIfPresentNonDefault(int key, IntIntUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeIntIfPresentNonDefault(key, mappingFunction); } } + @Override public int supplyIntIfAbsentNonDefault(int key, IntSupplier valueProvider) { synchronized(mutex) { return map.supplyIntIfAbsentNonDefault(key, valueProvider); } } @Override public int mergeInt(int key, int value, IntIntUnaryOperator mappingFunction) { synchronized(mutex) { return map.mergeInt(key, value, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/ints/utils/maps/Int2LongMaps.java b/src/main/java/speiger/src/collections/ints/utils/maps/Int2LongMaps.java index 59945a19..824d5d50 100644 --- a/src/main/java/speiger/src/collections/ints/utils/maps/Int2LongMaps.java +++ b/src/main/java/speiger/src/collections/ints/utils/maps/Int2LongMaps.java @@ -250,18 +250,18 @@ public static class SingletonMap extends AbstractInt2LongMap { @Override public long computeLong(int key, IntLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongNonDefault(int key, IntLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long computeLongIfAbsent(int key, Int2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongIfAbsentNonDefault(int key, Int2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long computeLongIfPresent(int key, IntLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongIfPresentNonDefault(int key, IntLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long supplyLongIfAbsent(int key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public long computeLongNonDefault(int key, IntLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public long computeLongIfAbsentNonDefault(int key, Int2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public long computeLongIfPresentNonDefault(int key, IntLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public long supplyLongIfAbsentNonDefault(int key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public long mergeLong(int key, long value, LongLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -312,18 +312,18 @@ public static class EmptyMap extends AbstractInt2LongMap { @Override public long computeLong(int key, IntLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongNonDefault(int key, IntLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long computeLongIfAbsent(int key, Int2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongIfAbsentNonDefault(int key, Int2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long computeLongIfPresent(int key, IntLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongIfPresentNonDefault(int key, IntLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long supplyLongIfAbsent(int key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public long computeLongNonDefault(int key, IntLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public long computeLongIfAbsentNonDefault(int key, Int2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public long computeLongIfPresentNonDefault(int key, IntLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public long supplyLongIfAbsentNonDefault(int key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public long mergeLong(int key, long value, LongLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -547,18 +547,18 @@ public long get(int key) { @Override public long computeLong(int key, IntLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongNonDefault(int key, IntLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long computeLongIfAbsent(int key, Int2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongIfAbsentNonDefault(int key, Int2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long computeLongIfPresent(int key, IntLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongIfPresentNonDefault(int key, IntLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long supplyLongIfAbsent(int key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public long computeLongNonDefault(int key, IntLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public long computeLongIfAbsentNonDefault(int key, Int2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public long computeLongIfPresentNonDefault(int key, IntLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public long supplyLongIfAbsentNonDefault(int key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public long mergeLong(int key, long value, LongLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -955,18 +955,18 @@ public AbstractInt2LongMap setDefaultReturnValue(long v) { @Override public long computeLong(int key, IntLongUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeLong(key, mappingFunction); } } @Override - public long computeLongNonDefault(int key, IntLongUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeLongNonDefault(key, mappingFunction); } } - @Override public long computeLongIfAbsent(int key, Int2LongFunction mappingFunction) { synchronized(mutex) { return map.computeLongIfAbsent(key, mappingFunction); } } @Override - public long computeLongIfAbsentNonDefault(int key, Int2LongFunction mappingFunction) { synchronized(mutex) { return map.computeLongIfAbsentNonDefault(key, mappingFunction); } } - @Override public long computeLongIfPresent(int key, IntLongUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeLongIfPresent(key, mappingFunction); } } @Override - public long computeLongIfPresentNonDefault(int key, IntLongUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeLongIfPresentNonDefault(key, mappingFunction); } } - @Override public long supplyLongIfAbsent(int key, LongSupplier valueProvider) { synchronized(mutex) { return map.supplyLongIfAbsent(key, valueProvider); } } @Override + public long computeLongNonDefault(int key, IntLongUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeLongNonDefault(key, mappingFunction); } } + @Override + public long computeLongIfAbsentNonDefault(int key, Int2LongFunction mappingFunction) { synchronized(mutex) { return map.computeLongIfAbsentNonDefault(key, mappingFunction); } } + @Override + public long computeLongIfPresentNonDefault(int key, IntLongUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeLongIfPresentNonDefault(key, mappingFunction); } } + @Override public long supplyLongIfAbsentNonDefault(int key, LongSupplier valueProvider) { synchronized(mutex) { return map.supplyLongIfAbsentNonDefault(key, valueProvider); } } @Override public long mergeLong(int key, long value, LongLongUnaryOperator mappingFunction) { synchronized(mutex) { return map.mergeLong(key, value, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/ints/utils/maps/Int2ObjectMaps.java b/src/main/java/speiger/src/collections/ints/utils/maps/Int2ObjectMaps.java index 9c3cc384..845c626b 100644 --- a/src/main/java/speiger/src/collections/ints/utils/maps/Int2ObjectMaps.java +++ b/src/main/java/speiger/src/collections/ints/utils/maps/Int2ObjectMaps.java @@ -266,20 +266,12 @@ public static class SingletonMap extends AbstractInt2ObjectMap { @Override public V compute(int key, IntObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeNonDefault(int key, IntObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V computeIfAbsent(int key, IntFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeIfAbsentNonDefault(int key, IntFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V computeIfPresent(int key, IntObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeIfPresentNonDefault(int key, IntObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V supplyIfAbsent(int key, ObjectSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public V supplyIfAbsentNonDefault(int key, ObjectSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public V merge(int key, V value, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override public void mergeAll(Int2ObjectMap m, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -325,20 +317,12 @@ public static class EmptyMap extends AbstractInt2ObjectMap { @Override public V compute(int key, IntObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeNonDefault(int key, IntObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V computeIfAbsent(int key, IntFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeIfAbsentNonDefault(int key, IntFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V computeIfPresent(int key, IntObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeIfPresentNonDefault(int key, IntObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V supplyIfAbsent(int key, ObjectSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public V supplyIfAbsentNonDefault(int key, ObjectSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public V merge(int key, V value, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override public void mergeAll(Int2ObjectMap m, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -561,20 +545,12 @@ public V get(int key) { @Override public V compute(int key, IntObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeNonDefault(int key, IntObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V computeIfAbsent(int key, IntFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeIfAbsentNonDefault(int key, IntFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V computeIfPresent(int key, IntObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeIfPresentNonDefault(int key, IntObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V supplyIfAbsent(int key, ObjectSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public V supplyIfAbsentNonDefault(int key, ObjectSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public V merge(int key, V value, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override public void mergeAll(Int2ObjectMap m, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -968,20 +944,12 @@ public AbstractInt2ObjectMap setDefaultReturnValue(V v) { @Override public V compute(int key, IntObjectUnaryOperator mappingFunction) { synchronized(mutex) { return map.compute(key, mappingFunction); } } @Override - public V computeNonDefault(int key, IntObjectUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeNonDefault(key, mappingFunction); } } - @Override public V computeIfAbsent(int key, IntFunction mappingFunction) { synchronized(mutex) { return map.computeIfAbsent(key, mappingFunction); } } @Override - public V computeIfAbsentNonDefault(int key, IntFunction mappingFunction) { synchronized(mutex) { return map.computeIfAbsentNonDefault(key, mappingFunction); } } - @Override public V computeIfPresent(int key, IntObjectUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeIfPresent(key, mappingFunction); } } @Override - public V computeIfPresentNonDefault(int key, IntObjectUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeIfPresentNonDefault(key, mappingFunction); } } - @Override public V supplyIfAbsent(int key, ObjectSupplier valueProvider) { synchronized(mutex) { return map.supplyIfAbsent(key, valueProvider); } } @Override - public V supplyIfAbsentNonDefault(int key, ObjectSupplier valueProvider) { synchronized(mutex) { return map.supplyIfAbsentNonDefault(key, valueProvider); } } - @Override public V merge(int key, V value, ObjectObjectUnaryOperator mappingFunction) { synchronized(mutex) { return map.merge(key, value, mappingFunction); } } @Override public void mergeAll(Int2ObjectMap m, ObjectObjectUnaryOperator mappingFunction) { synchronized(mutex) { map.mergeAll(m, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/ints/utils/maps/Int2ShortMaps.java b/src/main/java/speiger/src/collections/ints/utils/maps/Int2ShortMaps.java index a1143d1d..7b7a92ff 100644 --- a/src/main/java/speiger/src/collections/ints/utils/maps/Int2ShortMaps.java +++ b/src/main/java/speiger/src/collections/ints/utils/maps/Int2ShortMaps.java @@ -250,18 +250,18 @@ public static class SingletonMap extends AbstractInt2ShortMap { @Override public short computeShort(int key, IntShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortNonDefault(int key, IntShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short computeShortIfAbsent(int key, Int2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortIfAbsentNonDefault(int key, Int2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short computeShortIfPresent(int key, IntShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortIfPresentNonDefault(int key, IntShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short supplyShortIfAbsent(int key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public short computeShortNonDefault(int key, IntShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public short computeShortIfAbsentNonDefault(int key, Int2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public short computeShortIfPresentNonDefault(int key, IntShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public short supplyShortIfAbsentNonDefault(int key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public short mergeShort(int key, short value, ShortShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -312,18 +312,18 @@ public static class EmptyMap extends AbstractInt2ShortMap { @Override public short computeShort(int key, IntShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortNonDefault(int key, IntShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short computeShortIfAbsent(int key, Int2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortIfAbsentNonDefault(int key, Int2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short computeShortIfPresent(int key, IntShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortIfPresentNonDefault(int key, IntShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short supplyShortIfAbsent(int key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public short computeShortNonDefault(int key, IntShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public short computeShortIfAbsentNonDefault(int key, Int2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public short computeShortIfPresentNonDefault(int key, IntShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public short supplyShortIfAbsentNonDefault(int key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public short mergeShort(int key, short value, ShortShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -547,18 +547,18 @@ public short get(int key) { @Override public short computeShort(int key, IntShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortNonDefault(int key, IntShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short computeShortIfAbsent(int key, Int2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortIfAbsentNonDefault(int key, Int2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short computeShortIfPresent(int key, IntShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortIfPresentNonDefault(int key, IntShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short supplyShortIfAbsent(int key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public short computeShortNonDefault(int key, IntShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public short computeShortIfAbsentNonDefault(int key, Int2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public short computeShortIfPresentNonDefault(int key, IntShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public short supplyShortIfAbsentNonDefault(int key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public short mergeShort(int key, short value, ShortShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -955,18 +955,18 @@ public AbstractInt2ShortMap setDefaultReturnValue(short v) { @Override public short computeShort(int key, IntShortUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeShort(key, mappingFunction); } } @Override - public short computeShortNonDefault(int key, IntShortUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeShortNonDefault(key, mappingFunction); } } - @Override public short computeShortIfAbsent(int key, Int2ShortFunction mappingFunction) { synchronized(mutex) { return map.computeShortIfAbsent(key, mappingFunction); } } @Override - public short computeShortIfAbsentNonDefault(int key, Int2ShortFunction mappingFunction) { synchronized(mutex) { return map.computeShortIfAbsentNonDefault(key, mappingFunction); } } - @Override public short computeShortIfPresent(int key, IntShortUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeShortIfPresent(key, mappingFunction); } } @Override - public short computeShortIfPresentNonDefault(int key, IntShortUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeShortIfPresentNonDefault(key, mappingFunction); } } - @Override public short supplyShortIfAbsent(int key, ShortSupplier valueProvider) { synchronized(mutex) { return map.supplyShortIfAbsent(key, valueProvider); } } @Override + public short computeShortNonDefault(int key, IntShortUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeShortNonDefault(key, mappingFunction); } } + @Override + public short computeShortIfAbsentNonDefault(int key, Int2ShortFunction mappingFunction) { synchronized(mutex) { return map.computeShortIfAbsentNonDefault(key, mappingFunction); } } + @Override + public short computeShortIfPresentNonDefault(int key, IntShortUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeShortIfPresentNonDefault(key, mappingFunction); } } + @Override public short supplyShortIfAbsentNonDefault(int key, ShortSupplier valueProvider) { synchronized(mutex) { return map.supplyShortIfAbsentNonDefault(key, valueProvider); } } @Override public short mergeShort(int key, short value, ShortShortUnaryOperator mappingFunction) { synchronized(mutex) { return map.mergeShort(key, value, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/longs/lists/AbstractLongList.java b/src/main/java/speiger/src/collections/longs/lists/AbstractLongList.java index 858992ab..7eaad531 100644 --- a/src/main/java/speiger/src/collections/longs/lists/AbstractLongList.java +++ b/src/main/java/speiger/src/collections/longs/lists/AbstractLongList.java @@ -12,6 +12,7 @@ import speiger.src.collections.longs.collections.LongCollection; import speiger.src.collections.longs.collections.LongIterator; import speiger.src.collections.longs.collections.LongSplititerator; +import speiger.src.collections.ints.lists.IntList; import speiger.src.collections.longs.utils.LongSplititerators; import speiger.src.collections.utils.SanityChecks; @@ -205,13 +206,23 @@ public LongIterator iterator() { public LongListIterator listIterator() { return listIterator(0); } - + @Override public LongListIterator listIterator(int index) { if(index < 0 || index > size()) throw new IndexOutOfBoundsException(); return new LongListIter(index); } + @Override + public LongListIterator indexedIterator(int...indecies) { + return new IndexedIterator(indecies); + } + + @Override + public LongListIterator indexedIterator(IntList indecies) { + return new ListIndexedIterator(indecies); + } + @Override public void size(int size) { while(size > size()) add(0L); @@ -566,7 +577,153 @@ public int back(int amount) { } } } + + private class ListIndexedIterator implements LongListIterator { + IntList indecies; + int index; + int lastReturned = -1; + + ListIndexedIterator(IntList indecies) { + this.indecies = indecies; + } + + @Override + public boolean hasNext() { + return index < indecies.size(); + } + + @Override + public long nextLong() { + if(!hasNext()) throw new NoSuchElementException(); + int i = index++; + return getLong((lastReturned = indecies.getInt(i))); + } + + @Override + public boolean hasPrevious() { + return index > 0; + } + + @Override + public long previousLong() { + if(!hasPrevious()) throw new NoSuchElementException(); + index--; + return getLong((lastReturned = indecies.getInt(index))); + } + + @Override + public int nextIndex() { + return index; + } + + @Override + public int previousIndex() { + return index-1; + } + + @Override + public void remove() { throw new UnsupportedOperationException(); } + @Override + public void add(long e) { throw new UnsupportedOperationException(); } + + @Override + public void set(long e) { + if(lastReturned == -1) throw new IllegalStateException(); + AbstractLongList.this.set(lastReturned, e); + } + + @Override + public int skip(int amount) { + if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed"); + int steps = Math.min(amount, indecies.size() - index); + index += steps; + if(steps > 0) lastReturned = Math.min(index-1, indecies.size()-1); + return steps; + } + + @Override + public int back(int amount) { + if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed"); + int steps = Math.min(amount, index); + index -= steps; + if(steps > 0) lastReturned = Math.max(index, 0); + return steps; + } + } + + private class IndexedIterator implements LongListIterator { + int[] indecies; + int index; + int lastReturned = -1; + + IndexedIterator(int[] indecies) { + this.indecies = indecies; + } + @Override + public boolean hasNext() { + return index < indecies.length; + } + + @Override + public long nextLong() { + if(!hasNext()) throw new NoSuchElementException(); + int i = index++; + return getLong((lastReturned = indecies[i])); + } + + @Override + public boolean hasPrevious() { + return index > 0; + } + + @Override + public long previousLong() { + if(!hasPrevious()) throw new NoSuchElementException(); + index--; + return getLong((lastReturned = indecies[index])); + } + + @Override + public int nextIndex() { + return index; + } + + @Override + public int previousIndex() { + return index-1; + } + + @Override + public void remove() { throw new UnsupportedOperationException(); } + @Override + public void add(long e) { throw new UnsupportedOperationException(); } + + @Override + public void set(long e) { + if(lastReturned == -1) throw new IllegalStateException(); + AbstractLongList.this.set(lastReturned, e); + } + + @Override + public int skip(int amount) { + if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed"); + int steps = Math.min(amount, indecies.length - index); + index += steps; + if(steps > 0) lastReturned = Math.min(index-1, indecies.length-1); + return steps; + } + + @Override + public int back(int amount) { + if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed"); + int steps = Math.min(amount, index); + index -= steps; + if(steps > 0) lastReturned = Math.max(index, 0); + return steps; + } + } + private class LongListIter implements LongListIterator { int index; int lastReturned = -1; @@ -644,7 +801,7 @@ public int back(int amount) { if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed"); int steps = Math.min(amount, index); index -= steps; - if(steps > 0) lastReturned = Math.min(index, size()-1); + if(steps > 0) lastReturned = Math.max(index, 0); return steps; } } diff --git a/src/main/java/speiger/src/collections/longs/lists/LongList.java b/src/main/java/speiger/src/collections/longs/lists/LongList.java index 40bc4036..084424d1 100644 --- a/src/main/java/speiger/src/collections/longs/lists/LongList.java +++ b/src/main/java/speiger/src/collections/longs/lists/LongList.java @@ -14,6 +14,7 @@ import speiger.src.collections.longs.functions.LongComparator; import speiger.src.collections.longs.utils.LongArrays; import speiger.src.collections.longs.utils.LongLists; +import speiger.src.collections.ints.lists.IntList; import speiger.src.collections.longs.utils.LongSplititerators; /** @@ -341,6 +342,24 @@ public default void forEachIndexed(IntLongConsumer action) { @Override public LongListIterator listIterator(int index); + /** + * Creates a Iterator that follows the indecies provided.
+ * For example if the Lists Contents is:
-1, 0 1
and the indecies are:
0, 1, 2, 2, 1, 0
+ * then the iterator will return the following values:
-1, 0, 1, 1, 0, -1 + * @param indecies that should be used for the iteration. + * @return a custom indexed iterator + */ + public LongListIterator indexedIterator(int...indecies); + + /** + * Creates a Iterator that follows the indecies provided.
+ * For example if the Lists Contents is:
-1, 0 1
and the indecies are:
0, 1, 2, 2, 1, 0
+ * then the iterator will return the following values:
-1, 0, 1, 1, 0, -1 + * @param indecies that should be used for the iteration. + * @return a custom indexed iterator + */ + public LongListIterator indexedIterator(IntList indecies); + /** * A Type-Specific List of subList * @see java.util.List#subList(int, int) diff --git a/src/main/java/speiger/src/collections/longs/maps/abstracts/AbstractLong2BooleanMap.java b/src/main/java/speiger/src/collections/longs/maps/abstracts/AbstractLong2BooleanMap.java index 1402a497..b2c51bd2 100644 --- a/src/main/java/speiger/src/collections/longs/maps/abstracts/AbstractLong2BooleanMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/abstracts/AbstractLong2BooleanMap.java @@ -151,6 +151,39 @@ public boolean computeBoolean(long key, LongBooleanUnaryOperator mappingFunction return newValue; } + @Override + public boolean computeBooleanIfAbsent(long key, LongPredicate mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(!containsKey(key)) { + boolean newValue = mappingFunction.test(key); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public boolean supplyBooleanIfAbsent(long key, BooleanSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + if(!containsKey(key)) { + boolean newValue = valueProvider.getAsBoolean(); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public boolean computeBooleanIfPresent(long key, LongBooleanUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(containsKey(key)) { + boolean newValue = mappingFunction.applyAsBoolean(key, get(key)); + put(key, newValue); + return newValue; + } + return getDefaultReturnValue(); + } + @Override public boolean computeBooleanNonDefault(long key, LongBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -167,17 +200,6 @@ public boolean computeBooleanNonDefault(long key, LongBooleanUnaryOperator mappi return newValue; } - @Override - public boolean computeBooleanIfAbsent(long key, LongPredicate mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(!containsKey(key)) { - boolean newValue = mappingFunction.test(key); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public boolean computeBooleanIfAbsentNonDefault(long key, LongPredicate mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -192,17 +214,6 @@ public boolean computeBooleanIfAbsentNonDefault(long key, LongPredicate mappingF return value; } - @Override - public boolean supplyBooleanIfAbsent(long key, BooleanSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - if(!containsKey(key)) { - boolean newValue = valueProvider.getAsBoolean(); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public boolean supplyBooleanIfAbsentNonDefault(long key, BooleanSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -217,17 +228,6 @@ public boolean supplyBooleanIfAbsentNonDefault(long key, BooleanSupplier valuePr return value; } - @Override - public boolean computeBooleanIfPresent(long key, LongBooleanUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(containsKey(key)) { - boolean newValue = mappingFunction.applyAsBoolean(key, get(key)); - put(key, newValue); - return newValue; - } - return getDefaultReturnValue(); - } - @Override public boolean computeBooleanIfPresentNonDefault(long key, LongBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/longs/maps/abstracts/AbstractLong2ByteMap.java b/src/main/java/speiger/src/collections/longs/maps/abstracts/AbstractLong2ByteMap.java index b3f3b832..cd4b188a 100644 --- a/src/main/java/speiger/src/collections/longs/maps/abstracts/AbstractLong2ByteMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/abstracts/AbstractLong2ByteMap.java @@ -157,6 +157,39 @@ public byte computeByte(long key, LongByteUnaryOperator mappingFunction) { return newValue; } + @Override + public byte computeByteIfAbsent(long key, Long2ByteFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(!containsKey(key)) { + byte newValue = mappingFunction.applyAsByte(key); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public byte supplyByteIfAbsent(long key, ByteSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + if(!containsKey(key)) { + byte newValue = valueProvider.getAsByte(); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public byte computeByteIfPresent(long key, LongByteUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(containsKey(key)) { + byte newValue = mappingFunction.applyAsByte(key, get(key)); + put(key, newValue); + return newValue; + } + return getDefaultReturnValue(); + } + @Override public byte computeByteNonDefault(long key, LongByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -173,17 +206,6 @@ public byte computeByteNonDefault(long key, LongByteUnaryOperator mappingFunctio return newValue; } - @Override - public byte computeByteIfAbsent(long key, Long2ByteFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(!containsKey(key)) { - byte newValue = mappingFunction.applyAsByte(key); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public byte computeByteIfAbsentNonDefault(long key, Long2ByteFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -198,23 +220,12 @@ public byte computeByteIfAbsentNonDefault(long key, Long2ByteFunction mappingFun return value; } - @Override - public byte supplyByteIfAbsent(long key, ByteSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - if(!containsKey(key)) { - byte newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public byte supplyByteIfAbsentNonDefault(long key, ByteSupplier valueProvider) { Objects.requireNonNull(valueProvider); byte value; if((value = get(key)) == getDefaultReturnValue() || !containsKey(key)) { - byte newValue = valueProvider.getAsInt(); + byte newValue = valueProvider.getAsByte(); if(newValue != getDefaultReturnValue()) { put(key, newValue); return newValue; @@ -223,17 +234,6 @@ public byte supplyByteIfAbsentNonDefault(long key, ByteSupplier valueProvider) { return value; } - @Override - public byte computeByteIfPresent(long key, LongByteUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(containsKey(key)) { - byte newValue = mappingFunction.applyAsByte(key, get(key)); - put(key, newValue); - return newValue; - } - return getDefaultReturnValue(); - } - @Override public byte computeByteIfPresentNonDefault(long key, LongByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/longs/maps/abstracts/AbstractLong2CharMap.java b/src/main/java/speiger/src/collections/longs/maps/abstracts/AbstractLong2CharMap.java index 2fbcc136..a1d9393f 100644 --- a/src/main/java/speiger/src/collections/longs/maps/abstracts/AbstractLong2CharMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/abstracts/AbstractLong2CharMap.java @@ -157,6 +157,39 @@ public char computeChar(long key, LongCharUnaryOperator mappingFunction) { return newValue; } + @Override + public char computeCharIfAbsent(long key, Long2CharFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(!containsKey(key)) { + char newValue = mappingFunction.applyAsChar(key); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public char supplyCharIfAbsent(long key, CharSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + if(!containsKey(key)) { + char newValue = valueProvider.getAsChar(); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public char computeCharIfPresent(long key, LongCharUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(containsKey(key)) { + char newValue = mappingFunction.applyAsChar(key, get(key)); + put(key, newValue); + return newValue; + } + return getDefaultReturnValue(); + } + @Override public char computeCharNonDefault(long key, LongCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -173,17 +206,6 @@ public char computeCharNonDefault(long key, LongCharUnaryOperator mappingFunctio return newValue; } - @Override - public char computeCharIfAbsent(long key, Long2CharFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(!containsKey(key)) { - char newValue = mappingFunction.applyAsChar(key); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public char computeCharIfAbsentNonDefault(long key, Long2CharFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -198,23 +220,12 @@ public char computeCharIfAbsentNonDefault(long key, Long2CharFunction mappingFun return value; } - @Override - public char supplyCharIfAbsent(long key, CharSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - if(!containsKey(key)) { - char newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public char supplyCharIfAbsentNonDefault(long key, CharSupplier valueProvider) { Objects.requireNonNull(valueProvider); char value; if((value = get(key)) == getDefaultReturnValue() || !containsKey(key)) { - char newValue = valueProvider.getAsInt(); + char newValue = valueProvider.getAsChar(); if(newValue != getDefaultReturnValue()) { put(key, newValue); return newValue; @@ -223,17 +234,6 @@ public char supplyCharIfAbsentNonDefault(long key, CharSupplier valueProvider) { return value; } - @Override - public char computeCharIfPresent(long key, LongCharUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(containsKey(key)) { - char newValue = mappingFunction.applyAsChar(key, get(key)); - put(key, newValue); - return newValue; - } - return getDefaultReturnValue(); - } - @Override public char computeCharIfPresentNonDefault(long key, LongCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/longs/maps/abstracts/AbstractLong2DoubleMap.java b/src/main/java/speiger/src/collections/longs/maps/abstracts/AbstractLong2DoubleMap.java index a628fda8..3c5b1ff7 100644 --- a/src/main/java/speiger/src/collections/longs/maps/abstracts/AbstractLong2DoubleMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/abstracts/AbstractLong2DoubleMap.java @@ -157,6 +157,39 @@ public double computeDouble(long key, LongDoubleUnaryOperator mappingFunction) { return newValue; } + @Override + public double computeDoubleIfAbsent(long key, Long2DoubleFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(!containsKey(key)) { + double newValue = mappingFunction.applyAsDouble(key); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public double supplyDoubleIfAbsent(long key, DoubleSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + if(!containsKey(key)) { + double newValue = valueProvider.getAsDouble(); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public double computeDoubleIfPresent(long key, LongDoubleUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(containsKey(key)) { + double newValue = mappingFunction.applyAsDouble(key, get(key)); + put(key, newValue); + return newValue; + } + return getDefaultReturnValue(); + } + @Override public double computeDoubleNonDefault(long key, LongDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -173,17 +206,6 @@ public double computeDoubleNonDefault(long key, LongDoubleUnaryOperator mappingF return newValue; } - @Override - public double computeDoubleIfAbsent(long key, Long2DoubleFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(!containsKey(key)) { - double newValue = mappingFunction.applyAsDouble(key); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public double computeDoubleIfAbsentNonDefault(long key, Long2DoubleFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -198,17 +220,6 @@ public double computeDoubleIfAbsentNonDefault(long key, Long2DoubleFunction mapp return value; } - @Override - public double supplyDoubleIfAbsent(long key, DoubleSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - if(!containsKey(key)) { - double newValue = valueProvider.getAsDouble(); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public double supplyDoubleIfAbsentNonDefault(long key, DoubleSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -223,17 +234,6 @@ public double supplyDoubleIfAbsentNonDefault(long key, DoubleSupplier valueProvi return value; } - @Override - public double computeDoubleIfPresent(long key, LongDoubleUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(containsKey(key)) { - double newValue = mappingFunction.applyAsDouble(key, get(key)); - put(key, newValue); - return newValue; - } - return getDefaultReturnValue(); - } - @Override public double computeDoubleIfPresentNonDefault(long key, LongDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/longs/maps/abstracts/AbstractLong2FloatMap.java b/src/main/java/speiger/src/collections/longs/maps/abstracts/AbstractLong2FloatMap.java index 2507b495..80889828 100644 --- a/src/main/java/speiger/src/collections/longs/maps/abstracts/AbstractLong2FloatMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/abstracts/AbstractLong2FloatMap.java @@ -157,6 +157,39 @@ public float computeFloat(long key, LongFloatUnaryOperator mappingFunction) { return newValue; } + @Override + public float computeFloatIfAbsent(long key, Long2FloatFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(!containsKey(key)) { + float newValue = mappingFunction.applyAsFloat(key); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public float supplyFloatIfAbsent(long key, FloatSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + if(!containsKey(key)) { + float newValue = valueProvider.getAsFloat(); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public float computeFloatIfPresent(long key, LongFloatUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(containsKey(key)) { + float newValue = mappingFunction.applyAsFloat(key, get(key)); + put(key, newValue); + return newValue; + } + return getDefaultReturnValue(); + } + @Override public float computeFloatNonDefault(long key, LongFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -173,17 +206,6 @@ public float computeFloatNonDefault(long key, LongFloatUnaryOperator mappingFunc return newValue; } - @Override - public float computeFloatIfAbsent(long key, Long2FloatFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(!containsKey(key)) { - float newValue = mappingFunction.applyAsFloat(key); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public float computeFloatIfAbsentNonDefault(long key, Long2FloatFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -198,23 +220,12 @@ public float computeFloatIfAbsentNonDefault(long key, Long2FloatFunction mapping return value; } - @Override - public float supplyFloatIfAbsent(long key, FloatSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - if(!containsKey(key)) { - float newValue = valueProvider.getAsDouble(); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public float supplyFloatIfAbsentNonDefault(long key, FloatSupplier valueProvider) { Objects.requireNonNull(valueProvider); float value; if((value = get(key)) == getDefaultReturnValue() || !containsKey(key)) { - float newValue = valueProvider.getAsDouble(); + float newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) != Float.floatToIntBits(getDefaultReturnValue())) { put(key, newValue); return newValue; @@ -223,17 +234,6 @@ public float supplyFloatIfAbsentNonDefault(long key, FloatSupplier valueProvider return value; } - @Override - public float computeFloatIfPresent(long key, LongFloatUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(containsKey(key)) { - float newValue = mappingFunction.applyAsFloat(key, get(key)); - put(key, newValue); - return newValue; - } - return getDefaultReturnValue(); - } - @Override public float computeFloatIfPresentNonDefault(long key, LongFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/longs/maps/abstracts/AbstractLong2IntMap.java b/src/main/java/speiger/src/collections/longs/maps/abstracts/AbstractLong2IntMap.java index 706d0fd0..6c0262db 100644 --- a/src/main/java/speiger/src/collections/longs/maps/abstracts/AbstractLong2IntMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/abstracts/AbstractLong2IntMap.java @@ -157,6 +157,39 @@ public int computeInt(long key, LongIntUnaryOperator mappingFunction) { return newValue; } + @Override + public int computeIntIfAbsent(long key, Long2IntFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(!containsKey(key)) { + int newValue = mappingFunction.applyAsInt(key); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public int supplyIntIfAbsent(long key, IntSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + if(!containsKey(key)) { + int newValue = valueProvider.getAsInt(); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public int computeIntIfPresent(long key, LongIntUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(containsKey(key)) { + int newValue = mappingFunction.applyAsInt(key, get(key)); + put(key, newValue); + return newValue; + } + return getDefaultReturnValue(); + } + @Override public int computeIntNonDefault(long key, LongIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -173,17 +206,6 @@ public int computeIntNonDefault(long key, LongIntUnaryOperator mappingFunction) return newValue; } - @Override - public int computeIntIfAbsent(long key, Long2IntFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(!containsKey(key)) { - int newValue = mappingFunction.applyAsInt(key); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public int computeIntIfAbsentNonDefault(long key, Long2IntFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -198,17 +220,6 @@ public int computeIntIfAbsentNonDefault(long key, Long2IntFunction mappingFuncti return value; } - @Override - public int supplyIntIfAbsent(long key, IntSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - if(!containsKey(key)) { - int newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public int supplyIntIfAbsentNonDefault(long key, IntSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -223,17 +234,6 @@ public int supplyIntIfAbsentNonDefault(long key, IntSupplier valueProvider) { return value; } - @Override - public int computeIntIfPresent(long key, LongIntUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(containsKey(key)) { - int newValue = mappingFunction.applyAsInt(key, get(key)); - put(key, newValue); - return newValue; - } - return getDefaultReturnValue(); - } - @Override public int computeIntIfPresentNonDefault(long key, LongIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/longs/maps/abstracts/AbstractLong2LongMap.java b/src/main/java/speiger/src/collections/longs/maps/abstracts/AbstractLong2LongMap.java index e7a3ac40..57394238 100644 --- a/src/main/java/speiger/src/collections/longs/maps/abstracts/AbstractLong2LongMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/abstracts/AbstractLong2LongMap.java @@ -155,6 +155,39 @@ public long computeLong(long key, LongLongUnaryOperator mappingFunction) { return newValue; } + @Override + public long computeLongIfAbsent(long key, LongUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(!containsKey(key)) { + long newValue = mappingFunction.applyAsLong(key); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public long supplyLongIfAbsent(long key, LongSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + if(!containsKey(key)) { + long newValue = valueProvider.getAsLong(); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public long computeLongIfPresent(long key, LongLongUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(containsKey(key)) { + long newValue = mappingFunction.applyAsLong(key, get(key)); + put(key, newValue); + return newValue; + } + return getDefaultReturnValue(); + } + @Override public long computeLongNonDefault(long key, LongLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -171,17 +204,6 @@ public long computeLongNonDefault(long key, LongLongUnaryOperator mappingFunctio return newValue; } - @Override - public long computeLongIfAbsent(long key, LongUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(!containsKey(key)) { - long newValue = mappingFunction.applyAsLong(key); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public long computeLongIfAbsentNonDefault(long key, LongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -196,17 +218,6 @@ public long computeLongIfAbsentNonDefault(long key, LongUnaryOperator mappingFun return value; } - @Override - public long supplyLongIfAbsent(long key, LongSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - if(!containsKey(key)) { - long newValue = valueProvider.getAsLong(); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public long supplyLongIfAbsentNonDefault(long key, LongSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -221,17 +232,6 @@ public long supplyLongIfAbsentNonDefault(long key, LongSupplier valueProvider) { return value; } - @Override - public long computeLongIfPresent(long key, LongLongUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(containsKey(key)) { - long newValue = mappingFunction.applyAsLong(key, get(key)); - put(key, newValue); - return newValue; - } - return getDefaultReturnValue(); - } - @Override public long computeLongIfPresentNonDefault(long key, LongLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/longs/maps/abstracts/AbstractLong2ObjectMap.java b/src/main/java/speiger/src/collections/longs/maps/abstracts/AbstractLong2ObjectMap.java index 1d4c8195..bb862ffd 100644 --- a/src/main/java/speiger/src/collections/longs/maps/abstracts/AbstractLong2ObjectMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/abstracts/AbstractLong2ObjectMap.java @@ -159,22 +159,6 @@ public V compute(long key, LongObjectUnaryOperator mappingFunction) { return newValue; } - @Override - public V computeNonDefault(long key, LongObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - V value = get(key); - V newValue = mappingFunction.apply(key, value); - if(Objects.equals(newValue, getDefaultReturnValue())) { - if(!Objects.equals(value, getDefaultReturnValue()) || containsKey(key)) { - remove(key); - return getDefaultReturnValue(); - } - return getDefaultReturnValue(); - } - put(key, newValue); - return newValue; - } - @Override public V computeIfAbsent(long key, LongFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -189,20 +173,6 @@ public V computeIfAbsent(long key, LongFunction mappingFunction) { return value; } - @Override - public V computeIfAbsentNonDefault(long key, LongFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - V value; - if((value = get(key)) == getDefaultReturnValue() || !containsKey(key)) { - V newValue = mappingFunction.apply(key); - if(!Objects.equals(newValue, getDefaultReturnValue())) { - put(key, newValue); - return newValue; - } - } - return value; - } - @Override public V supplyIfAbsent(long key, ObjectSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -217,20 +187,6 @@ public V supplyIfAbsent(long key, ObjectSupplier valueProvider) { return value; } - @Override - public V supplyIfAbsentNonDefault(long key, ObjectSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - V value; - if((value = get(key)) == getDefaultReturnValue() || !containsKey(key)) { - V newValue = valueProvider.get(); - if(!Objects.equals(newValue, getDefaultReturnValue())) { - put(key, newValue); - return newValue; - } - } - return value; - } - @Override public V computeIfPresent(long key, LongObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -246,21 +202,6 @@ public V computeIfPresent(long key, LongObjectUnaryOperator mappingFunction) return getDefaultReturnValue(); } - @Override - public V computeIfPresentNonDefault(long key, LongObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - V value; - if(!Objects.equals((value = get(key)), getDefaultReturnValue()) || containsKey(key)) { - V newValue = mappingFunction.apply(key, value); - if(!Objects.equals(newValue, getDefaultReturnValue())) { - put(key, newValue); - return newValue; - } - remove(key); - } - return getDefaultReturnValue(); - } - @Override public V merge(long key, V value, ObjectObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/longs/maps/abstracts/AbstractLong2ShortMap.java b/src/main/java/speiger/src/collections/longs/maps/abstracts/AbstractLong2ShortMap.java index 5b009866..cb420280 100644 --- a/src/main/java/speiger/src/collections/longs/maps/abstracts/AbstractLong2ShortMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/abstracts/AbstractLong2ShortMap.java @@ -157,6 +157,39 @@ public short computeShort(long key, LongShortUnaryOperator mappingFunction) { return newValue; } + @Override + public short computeShortIfAbsent(long key, Long2ShortFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(!containsKey(key)) { + short newValue = mappingFunction.applyAsShort(key); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public short supplyShortIfAbsent(long key, ShortSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + if(!containsKey(key)) { + short newValue = valueProvider.getAsShort(); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public short computeShortIfPresent(long key, LongShortUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(containsKey(key)) { + short newValue = mappingFunction.applyAsShort(key, get(key)); + put(key, newValue); + return newValue; + } + return getDefaultReturnValue(); + } + @Override public short computeShortNonDefault(long key, LongShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -173,17 +206,6 @@ public short computeShortNonDefault(long key, LongShortUnaryOperator mappingFunc return newValue; } - @Override - public short computeShortIfAbsent(long key, Long2ShortFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(!containsKey(key)) { - short newValue = mappingFunction.applyAsShort(key); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public short computeShortIfAbsentNonDefault(long key, Long2ShortFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -198,23 +220,12 @@ public short computeShortIfAbsentNonDefault(long key, Long2ShortFunction mapping return value; } - @Override - public short supplyShortIfAbsent(long key, ShortSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - if(!containsKey(key)) { - short newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public short supplyShortIfAbsentNonDefault(long key, ShortSupplier valueProvider) { Objects.requireNonNull(valueProvider); short value; if((value = get(key)) == getDefaultReturnValue() || !containsKey(key)) { - short newValue = valueProvider.getAsInt(); + short newValue = valueProvider.getAsShort(); if(newValue != getDefaultReturnValue()) { put(key, newValue); return newValue; @@ -223,17 +234,6 @@ public short supplyShortIfAbsentNonDefault(long key, ShortSupplier valueProvider return value; } - @Override - public short computeShortIfPresent(long key, LongShortUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(containsKey(key)) { - short newValue = mappingFunction.applyAsShort(key, get(key)); - put(key, newValue); - return newValue; - } - return getDefaultReturnValue(); - } - @Override public short computeShortIfPresentNonDefault(long key, LongShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/concurrent/Long2BooleanConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/concurrent/Long2BooleanConcurrentOpenHashMap.java index aa991c80..1ae81a1b 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/concurrent/Long2BooleanConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/concurrent/Long2BooleanConcurrentOpenHashMap.java @@ -438,13 +438,6 @@ public boolean computeBoolean(long key, LongBooleanUnaryOperator mappingFunction return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public boolean computeBooleanNonDefault(long key, LongBooleanUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public boolean computeBooleanIfAbsent(long key, LongPredicate mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -452,13 +445,6 @@ public boolean computeBooleanIfAbsent(long key, LongPredicate mappingFunction) { return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public boolean computeBooleanIfAbsentNonDefault(long key, LongPredicate mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public boolean supplyBooleanIfAbsent(long key, BooleanSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -467,17 +453,31 @@ public boolean supplyBooleanIfAbsent(long key, BooleanSupplier valueProvider) { } @Override - public boolean supplyBooleanIfAbsentNonDefault(long key, BooleanSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public boolean computeBooleanIfPresent(long key, LongBooleanUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); + return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } @Override - public boolean computeBooleanIfPresent(long key, LongBooleanUnaryOperator mappingFunction) { + public boolean computeBooleanNonDefault(long key, LongBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).computeIfPresent(hash, key, mappingFunction); + return getSegment(hash).computeNonDefault(hash, key, mappingFunction); + } + + @Override + public boolean computeBooleanIfAbsentNonDefault(long key, LongPredicate mappingFunction) { + Objects.requireNonNull(mappingFunction); + int hash = getHashCode(key); + return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); + } + + @Override + public boolean supplyBooleanIfAbsentNonDefault(long key, BooleanSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + int hash = getHashCode(key); + return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); } @Override @@ -2032,35 +2032,29 @@ protected boolean compute(int hash, long key, LongBooleanUnaryOperator mappingFu } } - protected boolean computeNonDefault(int hash, long key, LongBooleanUnaryOperator mappingFunction) { + protected boolean computeIfAbsent(int hash, long key, LongPredicate mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + boolean newValue = mappingFunction.test(key); insert(-index-1, key, newValue); return newValue; } - boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + boolean newValue = values[index]; return newValue; } finally { unlockWrite(stamp); } } - - protected boolean computeIfAbsent(int hash, long key, LongPredicate mappingFunction) { + + protected boolean supplyIfAbsent(int hash, long key, BooleanSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - boolean newValue = mappingFunction.test(key); + boolean newValue = valueProvider.getAsBoolean(); insert(-index-1, key, newValue); return newValue; } @@ -2071,23 +2065,37 @@ protected boolean computeIfAbsent(int hash, long key, LongPredicate mappingFunct unlockWrite(stamp); } } + + protected boolean computeIfPresent(int hash, long key, LongBooleanUnaryOperator mappingFunction) { + long stamp = writeLock(); + try { + int index = findIndex(hash, key); + if(index < 0) return getDefaultReturnValue(); + boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); + values[index] = newValue; + return newValue; + } + finally { + unlockWrite(stamp); + } + } - protected boolean computeIfAbsentNonDefault(int hash, long key, LongPredicate mappingFunction) { + protected boolean computeNonDefault(int hash, long key, LongBooleanUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - boolean newValue = mappingFunction.test(key); + boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - boolean newValue = values[index]; + boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.test(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } finally { @@ -2095,16 +2103,22 @@ protected boolean computeIfAbsentNonDefault(int hash, long key, LongPredicate ma } } - protected boolean supplyIfAbsent(int hash, long key, BooleanSupplier valueProvider) { + protected boolean computeIfAbsentNonDefault(int hash, long key, LongPredicate mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - boolean newValue = valueProvider.getAsBoolean(); + boolean newValue = mappingFunction.test(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } boolean newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.test(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } finally { @@ -2135,20 +2149,6 @@ protected boolean supplyIfAbsentNonDefault(int hash, long key, BooleanSupplier v } } - protected boolean computeIfPresent(int hash, long key, LongBooleanUnaryOperator mappingFunction) { - long stamp = writeLock(); - try { - int index = findIndex(hash, key); - if(index < 0) return getDefaultReturnValue(); - boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); - values[index] = newValue; - return newValue; - } - finally { - unlockWrite(stamp); - } - } - protected boolean computeIfPresentNonDefault(int hash, long key, LongBooleanUnaryOperator mappingFunction) { long stamp = writeLock(); try { diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/concurrent/Long2ByteConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/concurrent/Long2ByteConcurrentOpenHashMap.java index 975966cf..c27e0147 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/concurrent/Long2ByteConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/concurrent/Long2ByteConcurrentOpenHashMap.java @@ -451,13 +451,6 @@ public byte computeByte(long key, LongByteUnaryOperator mappingFunction) { return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public byte computeByteNonDefault(long key, LongByteUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public byte computeByteIfAbsent(long key, Long2ByteFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -465,13 +458,6 @@ public byte computeByteIfAbsent(long key, Long2ByteFunction mappingFunction) { return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public byte computeByteIfAbsentNonDefault(long key, Long2ByteFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public byte supplyByteIfAbsent(long key, ByteSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -480,17 +466,31 @@ public byte supplyByteIfAbsent(long key, ByteSupplier valueProvider) { } @Override - public byte supplyByteIfAbsentNonDefault(long key, ByteSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public byte computeByteIfPresent(long key, LongByteUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); + return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } @Override - public byte computeByteIfPresent(long key, LongByteUnaryOperator mappingFunction) { + public byte computeByteNonDefault(long key, LongByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).computeIfPresent(hash, key, mappingFunction); + return getSegment(hash).computeNonDefault(hash, key, mappingFunction); + } + + @Override + public byte computeByteIfAbsentNonDefault(long key, Long2ByteFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + int hash = getHashCode(key); + return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); + } + + @Override + public byte supplyByteIfAbsentNonDefault(long key, ByteSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + int hash = getHashCode(key); + return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); } @Override @@ -2076,35 +2076,29 @@ protected byte compute(int hash, long key, LongByteUnaryOperator mappingFunction } } - protected byte computeNonDefault(int hash, long key, LongByteUnaryOperator mappingFunction) { + protected byte computeIfAbsent(int hash, long key, Long2ByteFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + byte newValue = mappingFunction.applyAsByte(key); insert(-index-1, key, newValue); return newValue; } - byte newValue = mappingFunction.applyAsByte(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + byte newValue = values[index]; return newValue; } finally { unlockWrite(stamp); } } - - protected byte computeIfAbsent(int hash, long key, Long2ByteFunction mappingFunction) { + + protected byte supplyIfAbsent(int hash, long key, ByteSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = valueProvider.getAsByte(); insert(-index-1, key, newValue); return newValue; } @@ -2115,23 +2109,14 @@ protected byte computeIfAbsent(int hash, long key, Long2ByteFunction mappingFunc unlockWrite(stamp); } } - - protected byte computeIfAbsentNonDefault(int hash, long key, Long2ByteFunction mappingFunction) { + + protected byte computeIfPresent(int hash, long key, LongByteUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key); - if(newValue == getDefaultReturnValue()) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - byte newValue = values[index]; - if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsByte(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; - } + if(index < 0) return getDefaultReturnValue(); + byte newValue = mappingFunction.applyAsByte(key, values[index]); + values[index] = newValue; return newValue; } finally { @@ -2139,16 +2124,22 @@ protected byte computeIfAbsentNonDefault(int hash, long key, Long2ByteFunction m } } - protected byte supplyIfAbsent(int hash, long key, ByteSupplier valueProvider) { + protected byte computeNonDefault(int hash, long key, LongByteUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - byte newValue = valueProvider.getAsInt(); + byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - byte newValue = values[index]; + byte newValue = mappingFunction.applyAsByte(key, values[index]); + if(newValue == getDefaultReturnValue()) { + removeIndex(index); + return newValue; + } + values[index] = newValue; return newValue; } finally { @@ -2156,19 +2147,19 @@ protected byte supplyIfAbsent(int hash, long key, ByteSupplier valueProvider) { } } - protected byte supplyIfAbsentNonDefault(int hash, long key, ByteSupplier valueProvider) { + protected byte computeIfAbsentNonDefault(int hash, long key, Long2ByteFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - byte newValue = valueProvider.getAsInt(); + byte newValue = mappingFunction.applyAsByte(key); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } byte newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = mappingFunction.applyAsByte(key); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } @@ -2179,13 +2170,22 @@ protected byte supplyIfAbsentNonDefault(int hash, long key, ByteSupplier valuePr } } - protected byte computeIfPresent(int hash, long key, LongByteUnaryOperator mappingFunction) { + protected byte supplyIfAbsentNonDefault(int hash, long key, ByteSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0) return getDefaultReturnValue(); - byte newValue = mappingFunction.applyAsByte(key, values[index]); - values[index] = newValue; + if(index < 0) { + byte newValue = valueProvider.getAsByte(); + if(newValue == getDefaultReturnValue()) return newValue; + insert(-index-1, key, newValue); + return newValue; + } + byte newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = valueProvider.getAsByte(); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } finally { diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/concurrent/Long2CharConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/concurrent/Long2CharConcurrentOpenHashMap.java index 6076cabf..a52938ab 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/concurrent/Long2CharConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/concurrent/Long2CharConcurrentOpenHashMap.java @@ -451,13 +451,6 @@ public char computeChar(long key, LongCharUnaryOperator mappingFunction) { return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public char computeCharNonDefault(long key, LongCharUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public char computeCharIfAbsent(long key, Long2CharFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -465,13 +458,6 @@ public char computeCharIfAbsent(long key, Long2CharFunction mappingFunction) { return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public char computeCharIfAbsentNonDefault(long key, Long2CharFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public char supplyCharIfAbsent(long key, CharSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -480,17 +466,31 @@ public char supplyCharIfAbsent(long key, CharSupplier valueProvider) { } @Override - public char supplyCharIfAbsentNonDefault(long key, CharSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public char computeCharIfPresent(long key, LongCharUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); + return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } @Override - public char computeCharIfPresent(long key, LongCharUnaryOperator mappingFunction) { + public char computeCharNonDefault(long key, LongCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).computeIfPresent(hash, key, mappingFunction); + return getSegment(hash).computeNonDefault(hash, key, mappingFunction); + } + + @Override + public char computeCharIfAbsentNonDefault(long key, Long2CharFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + int hash = getHashCode(key); + return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); + } + + @Override + public char supplyCharIfAbsentNonDefault(long key, CharSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + int hash = getHashCode(key); + return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); } @Override @@ -2076,35 +2076,29 @@ protected char compute(int hash, long key, LongCharUnaryOperator mappingFunction } } - protected char computeNonDefault(int hash, long key, LongCharUnaryOperator mappingFunction) { + protected char computeIfAbsent(int hash, long key, Long2CharFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + char newValue = mappingFunction.applyAsChar(key); insert(-index-1, key, newValue); return newValue; } - char newValue = mappingFunction.applyAsChar(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + char newValue = values[index]; return newValue; } finally { unlockWrite(stamp); } } - - protected char computeIfAbsent(int hash, long key, Long2CharFunction mappingFunction) { + + protected char supplyIfAbsent(int hash, long key, CharSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = valueProvider.getAsChar(); insert(-index-1, key, newValue); return newValue; } @@ -2115,23 +2109,14 @@ protected char computeIfAbsent(int hash, long key, Long2CharFunction mappingFunc unlockWrite(stamp); } } - - protected char computeIfAbsentNonDefault(int hash, long key, Long2CharFunction mappingFunction) { + + protected char computeIfPresent(int hash, long key, LongCharUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0) { - char newValue = mappingFunction.applyAsChar(key); - if(newValue == getDefaultReturnValue()) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - char newValue = values[index]; - if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsChar(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; - } + if(index < 0) return getDefaultReturnValue(); + char newValue = mappingFunction.applyAsChar(key, values[index]); + values[index] = newValue; return newValue; } finally { @@ -2139,16 +2124,22 @@ protected char computeIfAbsentNonDefault(int hash, long key, Long2CharFunction m } } - protected char supplyIfAbsent(int hash, long key, CharSupplier valueProvider) { + protected char computeNonDefault(int hash, long key, LongCharUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - char newValue = valueProvider.getAsInt(); + char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - char newValue = values[index]; + char newValue = mappingFunction.applyAsChar(key, values[index]); + if(newValue == getDefaultReturnValue()) { + removeIndex(index); + return newValue; + } + values[index] = newValue; return newValue; } finally { @@ -2156,19 +2147,19 @@ protected char supplyIfAbsent(int hash, long key, CharSupplier valueProvider) { } } - protected char supplyIfAbsentNonDefault(int hash, long key, CharSupplier valueProvider) { + protected char computeIfAbsentNonDefault(int hash, long key, Long2CharFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - char newValue = valueProvider.getAsInt(); + char newValue = mappingFunction.applyAsChar(key); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } char newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = mappingFunction.applyAsChar(key); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } @@ -2179,13 +2170,22 @@ protected char supplyIfAbsentNonDefault(int hash, long key, CharSupplier valuePr } } - protected char computeIfPresent(int hash, long key, LongCharUnaryOperator mappingFunction) { + protected char supplyIfAbsentNonDefault(int hash, long key, CharSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0) return getDefaultReturnValue(); - char newValue = mappingFunction.applyAsChar(key, values[index]); - values[index] = newValue; + if(index < 0) { + char newValue = valueProvider.getAsChar(); + if(newValue == getDefaultReturnValue()) return newValue; + insert(-index-1, key, newValue); + return newValue; + } + char newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = valueProvider.getAsChar(); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } finally { diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/concurrent/Long2DoubleConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/concurrent/Long2DoubleConcurrentOpenHashMap.java index f93d3ac5..4b7c51aa 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/concurrent/Long2DoubleConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/concurrent/Long2DoubleConcurrentOpenHashMap.java @@ -451,13 +451,6 @@ public double computeDouble(long key, LongDoubleUnaryOperator mappingFunction) { return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public double computeDoubleNonDefault(long key, LongDoubleUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public double computeDoubleIfAbsent(long key, Long2DoubleFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -465,13 +458,6 @@ public double computeDoubleIfAbsent(long key, Long2DoubleFunction mappingFunctio return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public double computeDoubleIfAbsentNonDefault(long key, Long2DoubleFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public double supplyDoubleIfAbsent(long key, DoubleSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -480,17 +466,31 @@ public double supplyDoubleIfAbsent(long key, DoubleSupplier valueProvider) { } @Override - public double supplyDoubleIfAbsentNonDefault(long key, DoubleSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public double computeDoubleIfPresent(long key, LongDoubleUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); + return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } @Override - public double computeDoubleIfPresent(long key, LongDoubleUnaryOperator mappingFunction) { + public double computeDoubleNonDefault(long key, LongDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).computeIfPresent(hash, key, mappingFunction); + return getSegment(hash).computeNonDefault(hash, key, mappingFunction); + } + + @Override + public double computeDoubleIfAbsentNonDefault(long key, Long2DoubleFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + int hash = getHashCode(key); + return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); + } + + @Override + public double supplyDoubleIfAbsentNonDefault(long key, DoubleSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + int hash = getHashCode(key); + return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); } @Override @@ -2076,35 +2076,29 @@ protected double compute(int hash, long key, LongDoubleUnaryOperator mappingFunc } } - protected double computeNonDefault(int hash, long key, LongDoubleUnaryOperator mappingFunction) { + protected double computeIfAbsent(int hash, long key, Long2DoubleFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + double newValue = mappingFunction.applyAsDouble(key); insert(-index-1, key, newValue); return newValue; } - double newValue = mappingFunction.applyAsDouble(key, values[index]); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + double newValue = values[index]; return newValue; } finally { unlockWrite(stamp); } } - - protected double computeIfAbsent(int hash, long key, Long2DoubleFunction mappingFunction) { + + protected double supplyIfAbsent(int hash, long key, DoubleSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = valueProvider.getAsDouble(); insert(-index-1, key, newValue); return newValue; } @@ -2115,23 +2109,37 @@ protected double computeIfAbsent(int hash, long key, Long2DoubleFunction mapping unlockWrite(stamp); } } + + protected double computeIfPresent(int hash, long key, LongDoubleUnaryOperator mappingFunction) { + long stamp = writeLock(); + try { + int index = findIndex(hash, key); + if(index < 0) return getDefaultReturnValue(); + double newValue = mappingFunction.applyAsDouble(key, values[index]); + values[index] = newValue; + return newValue; + } + finally { + unlockWrite(stamp); + } + } - protected double computeIfAbsentNonDefault(int hash, long key, Long2DoubleFunction mappingFunction) { + protected double computeNonDefault(int hash, long key, LongDoubleUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } - double newValue = values[index]; + double newValue = mappingFunction.applyAsDouble(key, values[index]); if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - newValue = mappingFunction.applyAsDouble(key); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } finally { @@ -2139,16 +2147,22 @@ protected double computeIfAbsentNonDefault(int hash, long key, Long2DoubleFuncti } } - protected double supplyIfAbsent(int hash, long key, DoubleSupplier valueProvider) { + protected double computeIfAbsentNonDefault(int hash, long key, Long2DoubleFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - double newValue = valueProvider.getAsDouble(); + double newValue = mappingFunction.applyAsDouble(key); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } double newValue = values[index]; + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { + newValue = mappingFunction.applyAsDouble(key); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + values[index] = newValue; + } return newValue; } finally { @@ -2179,20 +2193,6 @@ protected double supplyIfAbsentNonDefault(int hash, long key, DoubleSupplier val } } - protected double computeIfPresent(int hash, long key, LongDoubleUnaryOperator mappingFunction) { - long stamp = writeLock(); - try { - int index = findIndex(hash, key); - if(index < 0) return getDefaultReturnValue(); - double newValue = mappingFunction.applyAsDouble(key, values[index]); - values[index] = newValue; - return newValue; - } - finally { - unlockWrite(stamp); - } - } - protected double computeIfPresentNonDefault(int hash, long key, LongDoubleUnaryOperator mappingFunction) { long stamp = writeLock(); try { diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/concurrent/Long2FloatConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/concurrent/Long2FloatConcurrentOpenHashMap.java index 694dc6bc..d4cdfd3b 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/concurrent/Long2FloatConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/concurrent/Long2FloatConcurrentOpenHashMap.java @@ -451,13 +451,6 @@ public float computeFloat(long key, LongFloatUnaryOperator mappingFunction) { return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public float computeFloatNonDefault(long key, LongFloatUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public float computeFloatIfAbsent(long key, Long2FloatFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -465,13 +458,6 @@ public float computeFloatIfAbsent(long key, Long2FloatFunction mappingFunction) return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public float computeFloatIfAbsentNonDefault(long key, Long2FloatFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public float supplyFloatIfAbsent(long key, FloatSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -480,17 +466,31 @@ public float supplyFloatIfAbsent(long key, FloatSupplier valueProvider) { } @Override - public float supplyFloatIfAbsentNonDefault(long key, FloatSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public float computeFloatIfPresent(long key, LongFloatUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); + return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } @Override - public float computeFloatIfPresent(long key, LongFloatUnaryOperator mappingFunction) { + public float computeFloatNonDefault(long key, LongFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).computeIfPresent(hash, key, mappingFunction); + return getSegment(hash).computeNonDefault(hash, key, mappingFunction); + } + + @Override + public float computeFloatIfAbsentNonDefault(long key, Long2FloatFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + int hash = getHashCode(key); + return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); + } + + @Override + public float supplyFloatIfAbsentNonDefault(long key, FloatSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + int hash = getHashCode(key); + return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); } @Override @@ -2076,35 +2076,29 @@ protected float compute(int hash, long key, LongFloatUnaryOperator mappingFuncti } } - protected float computeNonDefault(int hash, long key, LongFloatUnaryOperator mappingFunction) { + protected float computeIfAbsent(int hash, long key, Long2FloatFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + float newValue = mappingFunction.applyAsFloat(key); insert(-index-1, key, newValue); return newValue; } - float newValue = mappingFunction.applyAsFloat(key, values[index]); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + float newValue = values[index]; return newValue; } finally { unlockWrite(stamp); } } - - protected float computeIfAbsent(int hash, long key, Long2FloatFunction mappingFunction) { + + protected float supplyIfAbsent(int hash, long key, FloatSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = valueProvider.getAsFloat(); insert(-index-1, key, newValue); return newValue; } @@ -2115,23 +2109,14 @@ protected float computeIfAbsent(int hash, long key, Long2FloatFunction mappingFu unlockWrite(stamp); } } - - protected float computeIfAbsentNonDefault(int hash, long key, Long2FloatFunction mappingFunction) { + + protected float computeIfPresent(int hash, long key, LongFloatUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - float newValue = values[index]; - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - newValue = mappingFunction.applyAsFloat(key); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; - values[index] = newValue; - } + if(index < 0) return getDefaultReturnValue(); + float newValue = mappingFunction.applyAsFloat(key, values[index]); + values[index] = newValue; return newValue; } finally { @@ -2139,16 +2124,22 @@ protected float computeIfAbsentNonDefault(int hash, long key, Long2FloatFunction } } - protected float supplyIfAbsent(int hash, long key, FloatSupplier valueProvider) { + protected float computeNonDefault(int hash, long key, LongFloatUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - float newValue = valueProvider.getAsDouble(); + float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } - float newValue = values[index]; + float newValue = mappingFunction.applyAsFloat(key, values[index]); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { + removeIndex(index); + return newValue; + } + values[index] = newValue; return newValue; } finally { @@ -2156,19 +2147,19 @@ protected float supplyIfAbsent(int hash, long key, FloatSupplier valueProvider) } } - protected float supplyIfAbsentNonDefault(int hash, long key, FloatSupplier valueProvider) { + protected float computeIfAbsentNonDefault(int hash, long key, Long2FloatFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - float newValue = valueProvider.getAsDouble(); + float newValue = mappingFunction.applyAsFloat(key); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } float newValue = values[index]; if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - newValue = valueProvider.getAsDouble(); + newValue = mappingFunction.applyAsFloat(key); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; values[index] = newValue; } @@ -2179,13 +2170,22 @@ protected float supplyIfAbsentNonDefault(int hash, long key, FloatSupplier value } } - protected float computeIfPresent(int hash, long key, LongFloatUnaryOperator mappingFunction) { + protected float supplyIfAbsentNonDefault(int hash, long key, FloatSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0) return getDefaultReturnValue(); - float newValue = mappingFunction.applyAsFloat(key, values[index]); - values[index] = newValue; + if(index < 0) { + float newValue = valueProvider.getAsFloat(); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + insert(-index-1, key, newValue); + return newValue; + } + float newValue = values[index]; + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { + newValue = valueProvider.getAsFloat(); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + values[index] = newValue; + } return newValue; } finally { diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/concurrent/Long2IntConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/concurrent/Long2IntConcurrentOpenHashMap.java index 19a3ba77..879503c3 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/concurrent/Long2IntConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/concurrent/Long2IntConcurrentOpenHashMap.java @@ -451,13 +451,6 @@ public int computeInt(long key, LongIntUnaryOperator mappingFunction) { return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public int computeIntNonDefault(long key, LongIntUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public int computeIntIfAbsent(long key, Long2IntFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -465,13 +458,6 @@ public int computeIntIfAbsent(long key, Long2IntFunction mappingFunction) { return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public int computeIntIfAbsentNonDefault(long key, Long2IntFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public int supplyIntIfAbsent(long key, IntSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -480,17 +466,31 @@ public int supplyIntIfAbsent(long key, IntSupplier valueProvider) { } @Override - public int supplyIntIfAbsentNonDefault(long key, IntSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public int computeIntIfPresent(long key, LongIntUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); + return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } @Override - public int computeIntIfPresent(long key, LongIntUnaryOperator mappingFunction) { + public int computeIntNonDefault(long key, LongIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).computeIfPresent(hash, key, mappingFunction); + return getSegment(hash).computeNonDefault(hash, key, mappingFunction); + } + + @Override + public int computeIntIfAbsentNonDefault(long key, Long2IntFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + int hash = getHashCode(key); + return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); + } + + @Override + public int supplyIntIfAbsentNonDefault(long key, IntSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + int hash = getHashCode(key); + return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); } @Override @@ -2076,35 +2076,29 @@ protected int compute(int hash, long key, LongIntUnaryOperator mappingFunction) } } - protected int computeNonDefault(int hash, long key, LongIntUnaryOperator mappingFunction) { + protected int computeIfAbsent(int hash, long key, Long2IntFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + int newValue = mappingFunction.applyAsInt(key); insert(-index-1, key, newValue); return newValue; } - int newValue = mappingFunction.applyAsInt(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + int newValue = values[index]; return newValue; } finally { unlockWrite(stamp); } } - - protected int computeIfAbsent(int hash, long key, Long2IntFunction mappingFunction) { + + protected int supplyIfAbsent(int hash, long key, IntSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = valueProvider.getAsInt(); insert(-index-1, key, newValue); return newValue; } @@ -2115,23 +2109,37 @@ protected int computeIfAbsent(int hash, long key, Long2IntFunction mappingFuncti unlockWrite(stamp); } } + + protected int computeIfPresent(int hash, long key, LongIntUnaryOperator mappingFunction) { + long stamp = writeLock(); + try { + int index = findIndex(hash, key); + if(index < 0) return getDefaultReturnValue(); + int newValue = mappingFunction.applyAsInt(key, values[index]); + values[index] = newValue; + return newValue; + } + finally { + unlockWrite(stamp); + } + } - protected int computeIfAbsentNonDefault(int hash, long key, Long2IntFunction mappingFunction) { + protected int computeNonDefault(int hash, long key, LongIntUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - int newValue = values[index]; + int newValue = mappingFunction.applyAsInt(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsInt(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } finally { @@ -2139,16 +2147,22 @@ protected int computeIfAbsentNonDefault(int hash, long key, Long2IntFunction map } } - protected int supplyIfAbsent(int hash, long key, IntSupplier valueProvider) { + protected int computeIfAbsentNonDefault(int hash, long key, Long2IntFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - int newValue = valueProvider.getAsInt(); + int newValue = mappingFunction.applyAsInt(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } int newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsInt(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } finally { @@ -2179,20 +2193,6 @@ protected int supplyIfAbsentNonDefault(int hash, long key, IntSupplier valueProv } } - protected int computeIfPresent(int hash, long key, LongIntUnaryOperator mappingFunction) { - long stamp = writeLock(); - try { - int index = findIndex(hash, key); - if(index < 0) return getDefaultReturnValue(); - int newValue = mappingFunction.applyAsInt(key, values[index]); - values[index] = newValue; - return newValue; - } - finally { - unlockWrite(stamp); - } - } - protected int computeIfPresentNonDefault(int hash, long key, LongIntUnaryOperator mappingFunction) { long stamp = writeLock(); try { diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/concurrent/Long2LongConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/concurrent/Long2LongConcurrentOpenHashMap.java index 5d743780..3a093548 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/concurrent/Long2LongConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/concurrent/Long2LongConcurrentOpenHashMap.java @@ -444,13 +444,6 @@ public long computeLong(long key, LongLongUnaryOperator mappingFunction) { return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public long computeLongNonDefault(long key, LongLongUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public long computeLongIfAbsent(long key, LongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -458,13 +451,6 @@ public long computeLongIfAbsent(long key, LongUnaryOperator mappingFunction) { return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public long computeLongIfAbsentNonDefault(long key, LongUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public long supplyLongIfAbsent(long key, LongSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -473,17 +459,31 @@ public long supplyLongIfAbsent(long key, LongSupplier valueProvider) { } @Override - public long supplyLongIfAbsentNonDefault(long key, LongSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public long computeLongIfPresent(long key, LongLongUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); + return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } @Override - public long computeLongIfPresent(long key, LongLongUnaryOperator mappingFunction) { + public long computeLongNonDefault(long key, LongLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).computeIfPresent(hash, key, mappingFunction); + return getSegment(hash).computeNonDefault(hash, key, mappingFunction); + } + + @Override + public long computeLongIfAbsentNonDefault(long key, LongUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int hash = getHashCode(key); + return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); + } + + @Override + public long supplyLongIfAbsentNonDefault(long key, LongSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + int hash = getHashCode(key); + return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); } @Override @@ -2069,35 +2069,29 @@ protected long compute(int hash, long key, LongLongUnaryOperator mappingFunction } } - protected long computeNonDefault(int hash, long key, LongLongUnaryOperator mappingFunction) { + protected long computeIfAbsent(int hash, long key, LongUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + long newValue = mappingFunction.applyAsLong(key); insert(-index-1, key, newValue); return newValue; } - long newValue = mappingFunction.applyAsLong(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + long newValue = values[index]; return newValue; } finally { unlockWrite(stamp); } } - - protected long computeIfAbsent(int hash, long key, LongUnaryOperator mappingFunction) { + + protected long supplyIfAbsent(int hash, long key, LongSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = valueProvider.getAsLong(); insert(-index-1, key, newValue); return newValue; } @@ -2108,23 +2102,37 @@ protected long computeIfAbsent(int hash, long key, LongUnaryOperator mappingFunc unlockWrite(stamp); } } + + protected long computeIfPresent(int hash, long key, LongLongUnaryOperator mappingFunction) { + long stamp = writeLock(); + try { + int index = findIndex(hash, key); + if(index < 0) return getDefaultReturnValue(); + long newValue = mappingFunction.applyAsLong(key, values[index]); + values[index] = newValue; + return newValue; + } + finally { + unlockWrite(stamp); + } + } - protected long computeIfAbsentNonDefault(int hash, long key, LongUnaryOperator mappingFunction) { + protected long computeNonDefault(int hash, long key, LongLongUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - long newValue = values[index]; + long newValue = mappingFunction.applyAsLong(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsLong(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } finally { @@ -2132,16 +2140,22 @@ protected long computeIfAbsentNonDefault(int hash, long key, LongUnaryOperator m } } - protected long supplyIfAbsent(int hash, long key, LongSupplier valueProvider) { + protected long computeIfAbsentNonDefault(int hash, long key, LongUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - long newValue = valueProvider.getAsLong(); + long newValue = mappingFunction.applyAsLong(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } long newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsLong(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } finally { @@ -2172,20 +2186,6 @@ protected long supplyIfAbsentNonDefault(int hash, long key, LongSupplier valuePr } } - protected long computeIfPresent(int hash, long key, LongLongUnaryOperator mappingFunction) { - long stamp = writeLock(); - try { - int index = findIndex(hash, key); - if(index < 0) return getDefaultReturnValue(); - long newValue = mappingFunction.applyAsLong(key, values[index]); - values[index] = newValue; - return newValue; - } - finally { - unlockWrite(stamp); - } - } - protected long computeIfPresentNonDefault(int hash, long key, LongLongUnaryOperator mappingFunction) { long stamp = writeLock(); try { diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/concurrent/Long2ObjectConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/concurrent/Long2ObjectConcurrentOpenHashMap.java index 6277983c..a0d8021e 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/concurrent/Long2ObjectConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/concurrent/Long2ObjectConcurrentOpenHashMap.java @@ -426,13 +426,6 @@ public V compute(long key, LongObjectUnaryOperator mappingFunction) { return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public V computeNonDefault(long key, LongObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public V computeIfAbsent(long key, LongFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -440,13 +433,6 @@ public V computeIfAbsent(long key, LongFunction mappingFunction) { return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public V computeIfAbsentNonDefault(long key, LongFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public V supplyIfAbsent(long key, ObjectSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -454,13 +440,6 @@ public V supplyIfAbsent(long key, ObjectSupplier valueProvider) { return getSegment(hash).supplyIfAbsent(hash, key, valueProvider); } - @Override - public V supplyIfAbsentNonDefault(long key, ObjectSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); - } - @Override public V computeIfPresent(long key, LongObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -468,13 +447,6 @@ public V computeIfPresent(long key, LongObjectUnaryOperator mappingFunction) return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } - @Override - public V computeIfPresentNonDefault(long key, LongObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfPresentNonDefault(hash, key, mappingFunction); - } - @Override public V merge(long key, V value, ObjectObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -2011,29 +1983,6 @@ protected V compute(int hash, long key, LongObjectUnaryOperator mappingFuncti } } - protected V computeNonDefault(int hash, long key, LongObjectUnaryOperator mappingFunction) { - long stamp = writeLock(); - try { - int index = findIndex(hash, key); - if(index < 0) { - V newValue = mappingFunction.apply(key, getDefaultReturnValue()); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = mappingFunction.apply(key, values[index]); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; - return newValue; - } - finally { - unlockWrite(stamp); - } - } - protected V computeIfAbsent(int hash, long key, LongFunction mappingFunction) { long stamp = writeLock(); try { @@ -2056,30 +2005,7 @@ protected V computeIfAbsent(int hash, long key, LongFunction mappingFunction) unlockWrite(stamp); } } - - protected V computeIfAbsentNonDefault(int hash, long key, LongFunction mappingFunction) { - long stamp = writeLock(); - try { - int index = findIndex(hash, key); - if(index < 0) { - V newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = values[index]; - if(Objects.equals(newValue, getDefaultReturnValue())) { - newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - values[index] = newValue; - } - return newValue; - } - finally { - unlockWrite(stamp); - } - } - + protected V supplyIfAbsent(int hash, long key, ObjectSupplier valueProvider) { long stamp = writeLock(); try { @@ -2102,30 +2028,7 @@ protected V supplyIfAbsent(int hash, long key, ObjectSupplier valueProvider) unlockWrite(stamp); } } - - protected V supplyIfAbsentNonDefault(int hash, long key, ObjectSupplier valueProvider) { - long stamp = writeLock(); - try { - int index = findIndex(hash, key); - if(index < 0) { - V newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = values[index]; - if(Objects.equals(newValue, getDefaultReturnValue())) { - newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - values[index] = newValue; - } - return newValue; - } - finally { - unlockWrite(stamp); - } - } - + protected V computeIfPresent(int hash, long key, LongObjectUnaryOperator mappingFunction) { long stamp = writeLock(); try { @@ -2144,11 +2047,16 @@ protected V computeIfPresent(int hash, long key, LongObjectUnaryOperator mapp } } - protected V computeIfPresentNonDefault(int hash, long key, LongObjectUnaryOperator mappingFunction) { + protected V computeNonDefault(int hash, long key, LongObjectUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0 || Objects.equals(values[index], getDefaultReturnValue())) return getDefaultReturnValue(); + if(index < 0) { + V newValue = mappingFunction.apply(key, getDefaultReturnValue()); + if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; + insert(-index-1, key, newValue); + return newValue; + } V newValue = mappingFunction.apply(key, values[index]); if(Objects.equals(newValue, getDefaultReturnValue())) { removeIndex(index); diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/concurrent/Long2ShortConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/concurrent/Long2ShortConcurrentOpenHashMap.java index c16f7720..1638b432 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/concurrent/Long2ShortConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/concurrent/Long2ShortConcurrentOpenHashMap.java @@ -451,13 +451,6 @@ public short computeShort(long key, LongShortUnaryOperator mappingFunction) { return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public short computeShortNonDefault(long key, LongShortUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public short computeShortIfAbsent(long key, Long2ShortFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -465,13 +458,6 @@ public short computeShortIfAbsent(long key, Long2ShortFunction mappingFunction) return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public short computeShortIfAbsentNonDefault(long key, Long2ShortFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public short supplyShortIfAbsent(long key, ShortSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -480,17 +466,31 @@ public short supplyShortIfAbsent(long key, ShortSupplier valueProvider) { } @Override - public short supplyShortIfAbsentNonDefault(long key, ShortSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public short computeShortIfPresent(long key, LongShortUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); + return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } @Override - public short computeShortIfPresent(long key, LongShortUnaryOperator mappingFunction) { + public short computeShortNonDefault(long key, LongShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).computeIfPresent(hash, key, mappingFunction); + return getSegment(hash).computeNonDefault(hash, key, mappingFunction); + } + + @Override + public short computeShortIfAbsentNonDefault(long key, Long2ShortFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + int hash = getHashCode(key); + return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); + } + + @Override + public short supplyShortIfAbsentNonDefault(long key, ShortSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + int hash = getHashCode(key); + return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); } @Override @@ -2076,35 +2076,29 @@ protected short compute(int hash, long key, LongShortUnaryOperator mappingFuncti } } - protected short computeNonDefault(int hash, long key, LongShortUnaryOperator mappingFunction) { + protected short computeIfAbsent(int hash, long key, Long2ShortFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + short newValue = mappingFunction.applyAsShort(key); insert(-index-1, key, newValue); return newValue; } - short newValue = mappingFunction.applyAsShort(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + short newValue = values[index]; return newValue; } finally { unlockWrite(stamp); } } - - protected short computeIfAbsent(int hash, long key, Long2ShortFunction mappingFunction) { + + protected short supplyIfAbsent(int hash, long key, ShortSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = valueProvider.getAsShort(); insert(-index-1, key, newValue); return newValue; } @@ -2115,23 +2109,14 @@ protected short computeIfAbsent(int hash, long key, Long2ShortFunction mappingFu unlockWrite(stamp); } } - - protected short computeIfAbsentNonDefault(int hash, long key, Long2ShortFunction mappingFunction) { + + protected short computeIfPresent(int hash, long key, LongShortUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0) { - short newValue = mappingFunction.applyAsShort(key); - if(newValue == getDefaultReturnValue()) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - short newValue = values[index]; - if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsShort(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; - } + if(index < 0) return getDefaultReturnValue(); + short newValue = mappingFunction.applyAsShort(key, values[index]); + values[index] = newValue; return newValue; } finally { @@ -2139,16 +2124,22 @@ protected short computeIfAbsentNonDefault(int hash, long key, Long2ShortFunction } } - protected short supplyIfAbsent(int hash, long key, ShortSupplier valueProvider) { + protected short computeNonDefault(int hash, long key, LongShortUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - short newValue = valueProvider.getAsInt(); + short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - short newValue = values[index]; + short newValue = mappingFunction.applyAsShort(key, values[index]); + if(newValue == getDefaultReturnValue()) { + removeIndex(index); + return newValue; + } + values[index] = newValue; return newValue; } finally { @@ -2156,19 +2147,19 @@ protected short supplyIfAbsent(int hash, long key, ShortSupplier valueProvider) } } - protected short supplyIfAbsentNonDefault(int hash, long key, ShortSupplier valueProvider) { + protected short computeIfAbsentNonDefault(int hash, long key, Long2ShortFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - short newValue = valueProvider.getAsInt(); + short newValue = mappingFunction.applyAsShort(key); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } short newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = mappingFunction.applyAsShort(key); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } @@ -2179,13 +2170,22 @@ protected short supplyIfAbsentNonDefault(int hash, long key, ShortSupplier value } } - protected short computeIfPresent(int hash, long key, LongShortUnaryOperator mappingFunction) { + protected short supplyIfAbsentNonDefault(int hash, long key, ShortSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0) return getDefaultReturnValue(); - short newValue = mappingFunction.applyAsShort(key, values[index]); - values[index] = newValue; + if(index < 0) { + short newValue = valueProvider.getAsShort(); + if(newValue == getDefaultReturnValue()) return newValue; + insert(-index-1, key, newValue); + return newValue; + } + short newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = valueProvider.getAsShort(); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } finally { diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2BooleanOpenCustomHashMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2BooleanOpenCustomHashMap.java index 23825bf8..f9dab5fa 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2BooleanOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2BooleanOpenCustomHashMap.java @@ -441,30 +441,24 @@ public boolean computeBoolean(long key, LongBooleanUnaryOperator mappingFunction } @Override - public boolean computeBooleanNonDefault(long key, LongBooleanUnaryOperator mappingFunction) { + public boolean computeBooleanIfAbsent(long key, LongPredicate mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + boolean newValue = mappingFunction.test(key); insert(-index-1, key, newValue); return newValue; } - boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + boolean newValue = values[index]; return newValue; } - + @Override - public boolean computeBooleanIfAbsent(long key, LongPredicate mappingFunction) { - Objects.requireNonNull(mappingFunction); + public boolean supplyBooleanIfAbsent(long key, BooleanSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - boolean newValue = mappingFunction.test(key); + boolean newValue = valueProvider.getAsBoolean(); insert(-index-1, key, newValue); return newValue; } @@ -473,34 +467,50 @@ public boolean computeBooleanIfAbsent(long key, LongPredicate mappingFunction) { } @Override - public boolean computeBooleanIfAbsentNonDefault(long key, LongPredicate mappingFunction) { + public boolean computeBooleanIfPresent(long key, LongBooleanUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public boolean computeBooleanNonDefault(long key, LongBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - boolean newValue = mappingFunction.test(key); + boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - boolean newValue = values[index]; + boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.test(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public boolean supplyBooleanIfAbsent(long key, BooleanSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public boolean computeBooleanIfAbsentNonDefault(long key, LongPredicate mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - boolean newValue = valueProvider.getAsBoolean(); + boolean newValue = mappingFunction.test(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } boolean newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.test(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -523,16 +533,6 @@ public boolean supplyBooleanIfAbsentNonDefault(long key, BooleanSupplier valuePr return newValue; } - @Override - public boolean computeBooleanIfPresent(long key, LongBooleanUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public boolean computeBooleanIfPresentNonDefault(long key, LongBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2ByteOpenCustomHashMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2ByteOpenCustomHashMap.java index 54a98fef..71d93f16 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2ByteOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2ByteOpenCustomHashMap.java @@ -463,30 +463,24 @@ public byte computeByte(long key, LongByteUnaryOperator mappingFunction) { } @Override - public byte computeByteNonDefault(long key, LongByteUnaryOperator mappingFunction) { + public byte computeByteIfAbsent(long key, Long2ByteFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + byte newValue = mappingFunction.applyAsByte(key); insert(-index-1, key, newValue); return newValue; } - byte newValue = mappingFunction.applyAsByte(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + byte newValue = values[index]; return newValue; } - + @Override - public byte computeByteIfAbsent(long key, Long2ByteFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public byte supplyByteIfAbsent(long key, ByteSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = valueProvider.getAsByte(); insert(-index-1, key, newValue); return newValue; } @@ -495,34 +489,50 @@ public byte computeByteIfAbsent(long key, Long2ByteFunction mappingFunction) { } @Override - public byte computeByteIfAbsentNonDefault(long key, Long2ByteFunction mappingFunction) { + public byte computeByteIfPresent(long key, LongByteUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + byte newValue = mappingFunction.applyAsByte(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public byte computeByteNonDefault(long key, LongByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - byte newValue = values[index]; + byte newValue = mappingFunction.applyAsByte(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsByte(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public byte supplyByteIfAbsent(long key, ByteSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public byte computeByteIfAbsentNonDefault(long key, Long2ByteFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - byte newValue = valueProvider.getAsInt(); + byte newValue = mappingFunction.applyAsByte(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } byte newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsByte(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -531,30 +541,20 @@ public byte supplyByteIfAbsentNonDefault(long key, ByteSupplier valueProvider) { Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - byte newValue = valueProvider.getAsInt(); + byte newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } byte newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public byte computeByteIfPresent(long key, LongByteUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - byte newValue = mappingFunction.applyAsByte(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public byte computeByteIfPresentNonDefault(long key, LongByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2CharOpenCustomHashMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2CharOpenCustomHashMap.java index 233aeae2..3c6dd5b9 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2CharOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2CharOpenCustomHashMap.java @@ -463,30 +463,24 @@ public char computeChar(long key, LongCharUnaryOperator mappingFunction) { } @Override - public char computeCharNonDefault(long key, LongCharUnaryOperator mappingFunction) { + public char computeCharIfAbsent(long key, Long2CharFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + char newValue = mappingFunction.applyAsChar(key); insert(-index-1, key, newValue); return newValue; } - char newValue = mappingFunction.applyAsChar(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + char newValue = values[index]; return newValue; } - + @Override - public char computeCharIfAbsent(long key, Long2CharFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public char supplyCharIfAbsent(long key, CharSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = valueProvider.getAsChar(); insert(-index-1, key, newValue); return newValue; } @@ -495,34 +489,50 @@ public char computeCharIfAbsent(long key, Long2CharFunction mappingFunction) { } @Override - public char computeCharIfAbsentNonDefault(long key, Long2CharFunction mappingFunction) { + public char computeCharIfPresent(long key, LongCharUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + char newValue = mappingFunction.applyAsChar(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public char computeCharNonDefault(long key, LongCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - char newValue = values[index]; + char newValue = mappingFunction.applyAsChar(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsChar(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public char supplyCharIfAbsent(long key, CharSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public char computeCharIfAbsentNonDefault(long key, Long2CharFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - char newValue = valueProvider.getAsInt(); + char newValue = mappingFunction.applyAsChar(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } char newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsChar(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -531,30 +541,20 @@ public char supplyCharIfAbsentNonDefault(long key, CharSupplier valueProvider) { Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - char newValue = valueProvider.getAsInt(); + char newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } char newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public char computeCharIfPresent(long key, LongCharUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - char newValue = mappingFunction.applyAsChar(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public char computeCharIfPresentNonDefault(long key, LongCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2DoubleOpenCustomHashMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2DoubleOpenCustomHashMap.java index cddad7cc..8e8fe03e 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2DoubleOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2DoubleOpenCustomHashMap.java @@ -463,30 +463,24 @@ public double computeDouble(long key, LongDoubleUnaryOperator mappingFunction) { } @Override - public double computeDoubleNonDefault(long key, LongDoubleUnaryOperator mappingFunction) { + public double computeDoubleIfAbsent(long key, Long2DoubleFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + double newValue = mappingFunction.applyAsDouble(key); insert(-index-1, key, newValue); return newValue; } - double newValue = mappingFunction.applyAsDouble(key, values[index]); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + double newValue = values[index]; return newValue; } - + @Override - public double computeDoubleIfAbsent(long key, Long2DoubleFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public double supplyDoubleIfAbsent(long key, DoubleSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = valueProvider.getAsDouble(); insert(-index-1, key, newValue); return newValue; } @@ -495,34 +489,50 @@ public double computeDoubleIfAbsent(long key, Long2DoubleFunction mappingFunctio } @Override - public double computeDoubleIfAbsentNonDefault(long key, Long2DoubleFunction mappingFunction) { + public double computeDoubleIfPresent(long key, LongDoubleUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + double newValue = mappingFunction.applyAsDouble(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public double computeDoubleNonDefault(long key, LongDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } - double newValue = values[index]; + double newValue = mappingFunction.applyAsDouble(key, values[index]); if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - newValue = mappingFunction.applyAsDouble(key); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public double supplyDoubleIfAbsent(long key, DoubleSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public double computeDoubleIfAbsentNonDefault(long key, Long2DoubleFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - double newValue = valueProvider.getAsDouble(); + double newValue = mappingFunction.applyAsDouble(key); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } double newValue = values[index]; + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { + newValue = mappingFunction.applyAsDouble(key); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + values[index] = newValue; + } return newValue; } @@ -545,16 +555,6 @@ public double supplyDoubleIfAbsentNonDefault(long key, DoubleSupplier valueProvi return newValue; } - @Override - public double computeDoubleIfPresent(long key, LongDoubleUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - double newValue = mappingFunction.applyAsDouble(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public double computeDoubleIfPresentNonDefault(long key, LongDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2FloatOpenCustomHashMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2FloatOpenCustomHashMap.java index 4463a7f1..c61bd147 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2FloatOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2FloatOpenCustomHashMap.java @@ -463,30 +463,24 @@ public float computeFloat(long key, LongFloatUnaryOperator mappingFunction) { } @Override - public float computeFloatNonDefault(long key, LongFloatUnaryOperator mappingFunction) { + public float computeFloatIfAbsent(long key, Long2FloatFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + float newValue = mappingFunction.applyAsFloat(key); insert(-index-1, key, newValue); return newValue; } - float newValue = mappingFunction.applyAsFloat(key, values[index]); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + float newValue = values[index]; return newValue; } - + @Override - public float computeFloatIfAbsent(long key, Long2FloatFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public float supplyFloatIfAbsent(long key, FloatSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = valueProvider.getAsFloat(); insert(-index-1, key, newValue); return newValue; } @@ -495,34 +489,50 @@ public float computeFloatIfAbsent(long key, Long2FloatFunction mappingFunction) } @Override - public float computeFloatIfAbsentNonDefault(long key, Long2FloatFunction mappingFunction) { + public float computeFloatIfPresent(long key, LongFloatUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + float newValue = mappingFunction.applyAsFloat(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public float computeFloatNonDefault(long key, LongFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } - float newValue = values[index]; + float newValue = mappingFunction.applyAsFloat(key, values[index]); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - newValue = mappingFunction.applyAsFloat(key); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public float supplyFloatIfAbsent(long key, FloatSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public float computeFloatIfAbsentNonDefault(long key, Long2FloatFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - float newValue = valueProvider.getAsDouble(); + float newValue = mappingFunction.applyAsFloat(key); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } float newValue = values[index]; + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { + newValue = mappingFunction.applyAsFloat(key); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + values[index] = newValue; + } return newValue; } @@ -531,30 +541,20 @@ public float supplyFloatIfAbsentNonDefault(long key, FloatSupplier valueProvider Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - float newValue = valueProvider.getAsDouble(); + float newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } float newValue = values[index]; if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - newValue = valueProvider.getAsDouble(); + newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; values[index] = newValue; } return newValue; } - @Override - public float computeFloatIfPresent(long key, LongFloatUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - float newValue = mappingFunction.applyAsFloat(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public float computeFloatIfPresentNonDefault(long key, LongFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2IntOpenCustomHashMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2IntOpenCustomHashMap.java index 1d6ec411..b8e8376c 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2IntOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2IntOpenCustomHashMap.java @@ -463,30 +463,24 @@ public int computeInt(long key, LongIntUnaryOperator mappingFunction) { } @Override - public int computeIntNonDefault(long key, LongIntUnaryOperator mappingFunction) { + public int computeIntIfAbsent(long key, Long2IntFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + int newValue = mappingFunction.applyAsInt(key); insert(-index-1, key, newValue); return newValue; } - int newValue = mappingFunction.applyAsInt(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + int newValue = values[index]; return newValue; } - + @Override - public int computeIntIfAbsent(long key, Long2IntFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public int supplyIntIfAbsent(long key, IntSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = valueProvider.getAsInt(); insert(-index-1, key, newValue); return newValue; } @@ -495,34 +489,50 @@ public int computeIntIfAbsent(long key, Long2IntFunction mappingFunction) { } @Override - public int computeIntIfAbsentNonDefault(long key, Long2IntFunction mappingFunction) { + public int computeIntIfPresent(long key, LongIntUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + int newValue = mappingFunction.applyAsInt(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public int computeIntNonDefault(long key, LongIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - int newValue = values[index]; + int newValue = mappingFunction.applyAsInt(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsInt(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public int supplyIntIfAbsent(long key, IntSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public int computeIntIfAbsentNonDefault(long key, Long2IntFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - int newValue = valueProvider.getAsInt(); + int newValue = mappingFunction.applyAsInt(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } int newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsInt(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -545,16 +555,6 @@ public int supplyIntIfAbsentNonDefault(long key, IntSupplier valueProvider) { return newValue; } - @Override - public int computeIntIfPresent(long key, LongIntUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - int newValue = mappingFunction.applyAsInt(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public int computeIntIfPresentNonDefault(long key, LongIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2LongOpenCustomHashMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2LongOpenCustomHashMap.java index ceb6008c..5e806bfa 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2LongOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2LongOpenCustomHashMap.java @@ -455,30 +455,24 @@ public long computeLong(long key, LongLongUnaryOperator mappingFunction) { } @Override - public long computeLongNonDefault(long key, LongLongUnaryOperator mappingFunction) { + public long computeLongIfAbsent(long key, LongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + long newValue = mappingFunction.applyAsLong(key); insert(-index-1, key, newValue); return newValue; } - long newValue = mappingFunction.applyAsLong(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + long newValue = values[index]; return newValue; } - + @Override - public long computeLongIfAbsent(long key, LongUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); + public long supplyLongIfAbsent(long key, LongSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = valueProvider.getAsLong(); insert(-index-1, key, newValue); return newValue; } @@ -487,34 +481,50 @@ public long computeLongIfAbsent(long key, LongUnaryOperator mappingFunction) { } @Override - public long computeLongIfAbsentNonDefault(long key, LongUnaryOperator mappingFunction) { + public long computeLongIfPresent(long key, LongLongUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + long newValue = mappingFunction.applyAsLong(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public long computeLongNonDefault(long key, LongLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - long newValue = values[index]; + long newValue = mappingFunction.applyAsLong(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsLong(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public long supplyLongIfAbsent(long key, LongSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public long computeLongIfAbsentNonDefault(long key, LongUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - long newValue = valueProvider.getAsLong(); + long newValue = mappingFunction.applyAsLong(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } long newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsLong(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -537,16 +547,6 @@ public long supplyLongIfAbsentNonDefault(long key, LongSupplier valueProvider) { return newValue; } - @Override - public long computeLongIfPresent(long key, LongLongUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - long newValue = mappingFunction.applyAsLong(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public long computeLongIfPresentNonDefault(long key, LongLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2ObjectOpenCustomHashMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2ObjectOpenCustomHashMap.java index 6e6a31bb..9dcae599 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2ObjectOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2ObjectOpenCustomHashMap.java @@ -432,25 +432,6 @@ public V compute(long key, LongObjectUnaryOperator mappingFunction) { return newValue; } - @Override - public V computeNonDefault(long key, LongObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) { - V newValue = mappingFunction.apply(key, getDefaultReturnValue()); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = mappingFunction.apply(key, values[index]); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; - return newValue; - } - @Override public V computeIfAbsent(long key, LongFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -469,26 +450,7 @@ public V computeIfAbsent(long key, LongFunction mappingFunction) { } return newValue; } - - @Override - public V computeIfAbsentNonDefault(long key, LongFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) { - V newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = values[index]; - if(Objects.equals(newValue, getDefaultReturnValue())) { - newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - values[index] = newValue; - } - return newValue; - } - + @Override public V supplyIfAbsent(long key, ObjectSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -508,25 +470,6 @@ public V supplyIfAbsent(long key, ObjectSupplier valueProvider) { return newValue; } - @Override - public V supplyIfAbsentNonDefault(long key, ObjectSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - int index = findIndex(key); - if(index < 0) { - V newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = values[index]; - if(Objects.equals(newValue, getDefaultReturnValue())) { - newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - values[index] = newValue; - } - return newValue; - } - @Override public V computeIfPresent(long key, LongObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -541,20 +484,6 @@ public V computeIfPresent(long key, LongObjectUnaryOperator mappingFunction) return newValue; } - @Override - public V computeIfPresentNonDefault(long key, LongObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0 || Objects.equals(values[index], getDefaultReturnValue())) return getDefaultReturnValue(); - V newValue = mappingFunction.apply(key, values[index]); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; - return newValue; - } - @Override public V merge(long key, V value, ObjectObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2ShortOpenCustomHashMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2ShortOpenCustomHashMap.java index 88178550..244d63ae 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2ShortOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/customHash/Long2ShortOpenCustomHashMap.java @@ -463,30 +463,24 @@ public short computeShort(long key, LongShortUnaryOperator mappingFunction) { } @Override - public short computeShortNonDefault(long key, LongShortUnaryOperator mappingFunction) { + public short computeShortIfAbsent(long key, Long2ShortFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + short newValue = mappingFunction.applyAsShort(key); insert(-index-1, key, newValue); return newValue; } - short newValue = mappingFunction.applyAsShort(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + short newValue = values[index]; return newValue; } - + @Override - public short computeShortIfAbsent(long key, Long2ShortFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public short supplyShortIfAbsent(long key, ShortSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = valueProvider.getAsShort(); insert(-index-1, key, newValue); return newValue; } @@ -495,34 +489,50 @@ public short computeShortIfAbsent(long key, Long2ShortFunction mappingFunction) } @Override - public short computeShortIfAbsentNonDefault(long key, Long2ShortFunction mappingFunction) { + public short computeShortIfPresent(long key, LongShortUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + short newValue = mappingFunction.applyAsShort(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public short computeShortNonDefault(long key, LongShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - short newValue = values[index]; + short newValue = mappingFunction.applyAsShort(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsShort(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public short supplyShortIfAbsent(long key, ShortSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public short computeShortIfAbsentNonDefault(long key, Long2ShortFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - short newValue = valueProvider.getAsInt(); + short newValue = mappingFunction.applyAsShort(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } short newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsShort(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -531,30 +541,20 @@ public short supplyShortIfAbsentNonDefault(long key, ShortSupplier valueProvider Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - short newValue = valueProvider.getAsInt(); + short newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } short newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public short computeShortIfPresent(long key, LongShortUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - short newValue = mappingFunction.applyAsShort(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public short computeShortIfPresentNonDefault(long key, LongShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2BooleanOpenHashMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2BooleanOpenHashMap.java index 61ead340..a74edb38 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2BooleanOpenHashMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2BooleanOpenHashMap.java @@ -408,68 +408,78 @@ public boolean computeBoolean(long key, LongBooleanUnaryOperator mappingFunction values[index] = newValue; return newValue; } - + @Override - public boolean computeBooleanNonDefault(long key, LongBooleanUnaryOperator mappingFunction) { + public boolean computeBooleanIfAbsent(long key, LongPredicate mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + boolean newValue = mappingFunction.test(key); insert(-index-1, key, newValue); return newValue; } - boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + boolean newValue = values[index]; return newValue; } @Override - public boolean computeBooleanIfAbsent(long key, LongPredicate mappingFunction) { - Objects.requireNonNull(mappingFunction); + public boolean supplyBooleanIfAbsent(long key, BooleanSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - boolean newValue = mappingFunction.test(key); + boolean newValue = valueProvider.getAsBoolean(); insert(-index-1, key, newValue); return newValue; } boolean newValue = values[index]; return newValue; } + + @Override + public boolean computeBooleanIfPresent(long key, LongBooleanUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public boolean computeBooleanIfAbsentNonDefault(long key, LongPredicate mappingFunction) { + public boolean computeBooleanNonDefault(long key, LongBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - boolean newValue = mappingFunction.test(key); + boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - boolean newValue = values[index]; + boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.test(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public boolean supplyBooleanIfAbsent(long key, BooleanSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public boolean computeBooleanIfAbsentNonDefault(long key, LongPredicate mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - boolean newValue = valueProvider.getAsBoolean(); + boolean newValue = mappingFunction.test(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } boolean newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.test(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -492,16 +502,6 @@ public boolean supplyBooleanIfAbsentNonDefault(long key, BooleanSupplier valuePr return newValue; } - @Override - public boolean computeBooleanIfPresent(long key, LongBooleanUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public boolean computeBooleanIfPresentNonDefault(long key, LongBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2ByteOpenHashMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2ByteOpenHashMap.java index 7cc853c7..4426acde 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2ByteOpenHashMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2ByteOpenHashMap.java @@ -430,68 +430,78 @@ public byte computeByte(long key, LongByteUnaryOperator mappingFunction) { values[index] = newValue; return newValue; } - + @Override - public byte computeByteNonDefault(long key, LongByteUnaryOperator mappingFunction) { + public byte computeByteIfAbsent(long key, Long2ByteFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + byte newValue = mappingFunction.applyAsByte(key); insert(-index-1, key, newValue); return newValue; } - byte newValue = mappingFunction.applyAsByte(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + byte newValue = values[index]; return newValue; } @Override - public byte computeByteIfAbsent(long key, Long2ByteFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public byte supplyByteIfAbsent(long key, ByteSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = valueProvider.getAsByte(); insert(-index-1, key, newValue); return newValue; } byte newValue = values[index]; return newValue; } + + @Override + public byte computeByteIfPresent(long key, LongByteUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + byte newValue = mappingFunction.applyAsByte(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public byte computeByteIfAbsentNonDefault(long key, Long2ByteFunction mappingFunction) { + public byte computeByteNonDefault(long key, LongByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - byte newValue = values[index]; + byte newValue = mappingFunction.applyAsByte(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsByte(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public byte supplyByteIfAbsent(long key, ByteSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public byte computeByteIfAbsentNonDefault(long key, Long2ByteFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - byte newValue = valueProvider.getAsInt(); + byte newValue = mappingFunction.applyAsByte(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } byte newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsByte(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -500,30 +510,20 @@ public byte supplyByteIfAbsentNonDefault(long key, ByteSupplier valueProvider) { Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - byte newValue = valueProvider.getAsInt(); + byte newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } byte newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public byte computeByteIfPresent(long key, LongByteUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - byte newValue = mappingFunction.applyAsByte(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public byte computeByteIfPresentNonDefault(long key, LongByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2CharOpenHashMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2CharOpenHashMap.java index 44b35ec2..0a40b2a9 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2CharOpenHashMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2CharOpenHashMap.java @@ -430,68 +430,78 @@ public char computeChar(long key, LongCharUnaryOperator mappingFunction) { values[index] = newValue; return newValue; } - + @Override - public char computeCharNonDefault(long key, LongCharUnaryOperator mappingFunction) { + public char computeCharIfAbsent(long key, Long2CharFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + char newValue = mappingFunction.applyAsChar(key); insert(-index-1, key, newValue); return newValue; } - char newValue = mappingFunction.applyAsChar(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + char newValue = values[index]; return newValue; } @Override - public char computeCharIfAbsent(long key, Long2CharFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public char supplyCharIfAbsent(long key, CharSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = valueProvider.getAsChar(); insert(-index-1, key, newValue); return newValue; } char newValue = values[index]; return newValue; } + + @Override + public char computeCharIfPresent(long key, LongCharUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + char newValue = mappingFunction.applyAsChar(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public char computeCharIfAbsentNonDefault(long key, Long2CharFunction mappingFunction) { + public char computeCharNonDefault(long key, LongCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - char newValue = values[index]; + char newValue = mappingFunction.applyAsChar(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsChar(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public char supplyCharIfAbsent(long key, CharSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public char computeCharIfAbsentNonDefault(long key, Long2CharFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - char newValue = valueProvider.getAsInt(); + char newValue = mappingFunction.applyAsChar(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } char newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsChar(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -500,30 +510,20 @@ public char supplyCharIfAbsentNonDefault(long key, CharSupplier valueProvider) { Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - char newValue = valueProvider.getAsInt(); + char newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } char newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public char computeCharIfPresent(long key, LongCharUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - char newValue = mappingFunction.applyAsChar(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public char computeCharIfPresentNonDefault(long key, LongCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2DoubleOpenHashMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2DoubleOpenHashMap.java index afffa94d..41214585 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2DoubleOpenHashMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2DoubleOpenHashMap.java @@ -430,68 +430,78 @@ public double computeDouble(long key, LongDoubleUnaryOperator mappingFunction) { values[index] = newValue; return newValue; } - + @Override - public double computeDoubleNonDefault(long key, LongDoubleUnaryOperator mappingFunction) { + public double computeDoubleIfAbsent(long key, Long2DoubleFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + double newValue = mappingFunction.applyAsDouble(key); insert(-index-1, key, newValue); return newValue; } - double newValue = mappingFunction.applyAsDouble(key, values[index]); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + double newValue = values[index]; return newValue; } @Override - public double computeDoubleIfAbsent(long key, Long2DoubleFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public double supplyDoubleIfAbsent(long key, DoubleSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = valueProvider.getAsDouble(); insert(-index-1, key, newValue); return newValue; } double newValue = values[index]; return newValue; } + + @Override + public double computeDoubleIfPresent(long key, LongDoubleUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + double newValue = mappingFunction.applyAsDouble(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public double computeDoubleIfAbsentNonDefault(long key, Long2DoubleFunction mappingFunction) { + public double computeDoubleNonDefault(long key, LongDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } - double newValue = values[index]; + double newValue = mappingFunction.applyAsDouble(key, values[index]); if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - newValue = mappingFunction.applyAsDouble(key); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public double supplyDoubleIfAbsent(long key, DoubleSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public double computeDoubleIfAbsentNonDefault(long key, Long2DoubleFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - double newValue = valueProvider.getAsDouble(); + double newValue = mappingFunction.applyAsDouble(key); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } double newValue = values[index]; + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { + newValue = mappingFunction.applyAsDouble(key); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + values[index] = newValue; + } return newValue; } @@ -514,16 +524,6 @@ public double supplyDoubleIfAbsentNonDefault(long key, DoubleSupplier valueProvi return newValue; } - @Override - public double computeDoubleIfPresent(long key, LongDoubleUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - double newValue = mappingFunction.applyAsDouble(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public double computeDoubleIfPresentNonDefault(long key, LongDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2FloatOpenHashMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2FloatOpenHashMap.java index 8490d39e..6766d65d 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2FloatOpenHashMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2FloatOpenHashMap.java @@ -430,68 +430,78 @@ public float computeFloat(long key, LongFloatUnaryOperator mappingFunction) { values[index] = newValue; return newValue; } - + @Override - public float computeFloatNonDefault(long key, LongFloatUnaryOperator mappingFunction) { + public float computeFloatIfAbsent(long key, Long2FloatFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + float newValue = mappingFunction.applyAsFloat(key); insert(-index-1, key, newValue); return newValue; } - float newValue = mappingFunction.applyAsFloat(key, values[index]); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + float newValue = values[index]; return newValue; } @Override - public float computeFloatIfAbsent(long key, Long2FloatFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public float supplyFloatIfAbsent(long key, FloatSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = valueProvider.getAsFloat(); insert(-index-1, key, newValue); return newValue; } float newValue = values[index]; return newValue; } + + @Override + public float computeFloatIfPresent(long key, LongFloatUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + float newValue = mappingFunction.applyAsFloat(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public float computeFloatIfAbsentNonDefault(long key, Long2FloatFunction mappingFunction) { + public float computeFloatNonDefault(long key, LongFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } - float newValue = values[index]; + float newValue = mappingFunction.applyAsFloat(key, values[index]); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - newValue = mappingFunction.applyAsFloat(key); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public float supplyFloatIfAbsent(long key, FloatSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public float computeFloatIfAbsentNonDefault(long key, Long2FloatFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - float newValue = valueProvider.getAsDouble(); + float newValue = mappingFunction.applyAsFloat(key); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } float newValue = values[index]; + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { + newValue = mappingFunction.applyAsFloat(key); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + values[index] = newValue; + } return newValue; } @@ -500,30 +510,20 @@ public float supplyFloatIfAbsentNonDefault(long key, FloatSupplier valueProvider Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - float newValue = valueProvider.getAsDouble(); + float newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } float newValue = values[index]; if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - newValue = valueProvider.getAsDouble(); + newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; values[index] = newValue; } return newValue; } - @Override - public float computeFloatIfPresent(long key, LongFloatUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - float newValue = mappingFunction.applyAsFloat(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public float computeFloatIfPresentNonDefault(long key, LongFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2IntOpenHashMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2IntOpenHashMap.java index 52754224..ae711f81 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2IntOpenHashMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2IntOpenHashMap.java @@ -430,68 +430,78 @@ public int computeInt(long key, LongIntUnaryOperator mappingFunction) { values[index] = newValue; return newValue; } - + @Override - public int computeIntNonDefault(long key, LongIntUnaryOperator mappingFunction) { + public int computeIntIfAbsent(long key, Long2IntFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + int newValue = mappingFunction.applyAsInt(key); insert(-index-1, key, newValue); return newValue; } - int newValue = mappingFunction.applyAsInt(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + int newValue = values[index]; return newValue; } @Override - public int computeIntIfAbsent(long key, Long2IntFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public int supplyIntIfAbsent(long key, IntSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = valueProvider.getAsInt(); insert(-index-1, key, newValue); return newValue; } int newValue = values[index]; return newValue; } + + @Override + public int computeIntIfPresent(long key, LongIntUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + int newValue = mappingFunction.applyAsInt(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public int computeIntIfAbsentNonDefault(long key, Long2IntFunction mappingFunction) { + public int computeIntNonDefault(long key, LongIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - int newValue = values[index]; + int newValue = mappingFunction.applyAsInt(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsInt(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public int supplyIntIfAbsent(long key, IntSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public int computeIntIfAbsentNonDefault(long key, Long2IntFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - int newValue = valueProvider.getAsInt(); + int newValue = mappingFunction.applyAsInt(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } int newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsInt(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -514,16 +524,6 @@ public int supplyIntIfAbsentNonDefault(long key, IntSupplier valueProvider) { return newValue; } - @Override - public int computeIntIfPresent(long key, LongIntUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - int newValue = mappingFunction.applyAsInt(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public int computeIntIfPresentNonDefault(long key, LongIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2LongOpenHashMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2LongOpenHashMap.java index 2af5c017..6321015d 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2LongOpenHashMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2LongOpenHashMap.java @@ -424,68 +424,78 @@ public long computeLong(long key, LongLongUnaryOperator mappingFunction) { values[index] = newValue; return newValue; } - + @Override - public long computeLongNonDefault(long key, LongLongUnaryOperator mappingFunction) { + public long computeLongIfAbsent(long key, LongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + long newValue = mappingFunction.applyAsLong(key); insert(-index-1, key, newValue); return newValue; } - long newValue = mappingFunction.applyAsLong(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + long newValue = values[index]; return newValue; } @Override - public long computeLongIfAbsent(long key, LongUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); + public long supplyLongIfAbsent(long key, LongSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = valueProvider.getAsLong(); insert(-index-1, key, newValue); return newValue; } long newValue = values[index]; return newValue; } + + @Override + public long computeLongIfPresent(long key, LongLongUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + long newValue = mappingFunction.applyAsLong(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public long computeLongIfAbsentNonDefault(long key, LongUnaryOperator mappingFunction) { + public long computeLongNonDefault(long key, LongLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - long newValue = values[index]; + long newValue = mappingFunction.applyAsLong(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsLong(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public long supplyLongIfAbsent(long key, LongSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public long computeLongIfAbsentNonDefault(long key, LongUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - long newValue = valueProvider.getAsLong(); + long newValue = mappingFunction.applyAsLong(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } long newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsLong(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -508,16 +518,6 @@ public long supplyLongIfAbsentNonDefault(long key, LongSupplier valueProvider) { return newValue; } - @Override - public long computeLongIfPresent(long key, LongLongUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - long newValue = mappingFunction.applyAsLong(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public long computeLongIfPresentNonDefault(long key, LongLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2ObjectOpenHashMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2ObjectOpenHashMap.java index db53aa21..6adb62b4 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2ObjectOpenHashMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2ObjectOpenHashMap.java @@ -401,26 +401,7 @@ public V compute(long key, LongObjectUnaryOperator mappingFunction) { values[index] = newValue; return newValue; } - - @Override - public V computeNonDefault(long key, LongObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) { - V newValue = mappingFunction.apply(key, getDefaultReturnValue()); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = mappingFunction.apply(key, values[index]); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; - return newValue; - } - + @Override public V computeIfAbsent(long key, LongFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -440,25 +421,6 @@ public V computeIfAbsent(long key, LongFunction mappingFunction) { return newValue; } - @Override - public V computeIfAbsentNonDefault(long key, LongFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) { - V newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = values[index]; - if(Objects.equals(newValue, getDefaultReturnValue())) { - newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - values[index] = newValue; - } - return newValue; - } - @Override public V supplyIfAbsent(long key, ObjectSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -477,26 +439,7 @@ public V supplyIfAbsent(long key, ObjectSupplier valueProvider) { } return newValue; } - - @Override - public V supplyIfAbsentNonDefault(long key, ObjectSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - int index = findIndex(key); - if(index < 0) { - V newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = values[index]; - if(Objects.equals(newValue, getDefaultReturnValue())) { - newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - values[index] = newValue; - } - return newValue; - } - + @Override public V computeIfPresent(long key, LongObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -511,20 +454,6 @@ public V computeIfPresent(long key, LongObjectUnaryOperator mappingFunction) return newValue; } - @Override - public V computeIfPresentNonDefault(long key, LongObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0 || Objects.equals(values[index], getDefaultReturnValue())) return getDefaultReturnValue(); - V newValue = mappingFunction.apply(key, values[index]); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; - return newValue; - } - @Override public V merge(long key, V value, ObjectObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2ShortOpenHashMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2ShortOpenHashMap.java index a6435318..bbc5a824 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2ShortOpenHashMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/hash/Long2ShortOpenHashMap.java @@ -430,68 +430,78 @@ public short computeShort(long key, LongShortUnaryOperator mappingFunction) { values[index] = newValue; return newValue; } - + @Override - public short computeShortNonDefault(long key, LongShortUnaryOperator mappingFunction) { + public short computeShortIfAbsent(long key, Long2ShortFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + short newValue = mappingFunction.applyAsShort(key); insert(-index-1, key, newValue); return newValue; } - short newValue = mappingFunction.applyAsShort(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + short newValue = values[index]; return newValue; } @Override - public short computeShortIfAbsent(long key, Long2ShortFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public short supplyShortIfAbsent(long key, ShortSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = valueProvider.getAsShort(); insert(-index-1, key, newValue); return newValue; } short newValue = values[index]; return newValue; } + + @Override + public short computeShortIfPresent(long key, LongShortUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + short newValue = mappingFunction.applyAsShort(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public short computeShortIfAbsentNonDefault(long key, Long2ShortFunction mappingFunction) { + public short computeShortNonDefault(long key, LongShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - short newValue = values[index]; + short newValue = mappingFunction.applyAsShort(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsShort(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public short supplyShortIfAbsent(long key, ShortSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public short computeShortIfAbsentNonDefault(long key, Long2ShortFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - short newValue = valueProvider.getAsInt(); + short newValue = mappingFunction.applyAsShort(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } short newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsShort(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -500,30 +510,20 @@ public short supplyShortIfAbsentNonDefault(long key, ShortSupplier valueProvider Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - short newValue = valueProvider.getAsInt(); + short newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } short newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public short computeShortIfPresent(long key, LongShortUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - short newValue = mappingFunction.applyAsShort(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public short computeShortIfPresentNonDefault(long key, LongShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/immutable/ImmutableLong2BooleanOpenHashMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/immutable/ImmutableLong2BooleanOpenHashMap.java index 52e318fa..e15f55d0 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/immutable/ImmutableLong2BooleanOpenHashMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/immutable/ImmutableLong2BooleanOpenHashMap.java @@ -413,20 +413,19 @@ public void forEach(LongBooleanConsumer action) { @Override public boolean computeBoolean(long key, LongBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanNonDefault(long key, LongBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean computeBooleanIfAbsent(long key, LongPredicate mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanIfAbsentNonDefault(long key, LongPredicate mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean supplyBooleanIfAbsent(long key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public boolean supplyBooleanIfAbsentNonDefault(long key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public boolean computeBooleanIfPresent(long key, LongBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override + public boolean computeBooleanNonDefault(long key, LongBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public boolean computeBooleanIfAbsentNonDefault(long key, LongPredicate mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public boolean supplyBooleanIfAbsentNonDefault(long key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } + @Override public boolean computeBooleanIfPresentNonDefault(long key, LongBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean mergeBoolean(long key, boolean value, BooleanBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/immutable/ImmutableLong2ByteOpenHashMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/immutable/ImmutableLong2ByteOpenHashMap.java index 8000a4c0..216e7ff4 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/immutable/ImmutableLong2ByteOpenHashMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/immutable/ImmutableLong2ByteOpenHashMap.java @@ -418,20 +418,19 @@ public void forEach(LongByteConsumer action) { @Override public byte computeByte(long key, LongByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteNonDefault(long key, LongByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte computeByteIfAbsent(long key, Long2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteIfAbsentNonDefault(long key, Long2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte supplyByteIfAbsent(long key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public byte supplyByteIfAbsentNonDefault(long key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public byte computeByteIfPresent(long key, LongByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override + public byte computeByteNonDefault(long key, LongByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public byte computeByteIfAbsentNonDefault(long key, Long2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public byte supplyByteIfAbsentNonDefault(long key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } + @Override public byte computeByteIfPresentNonDefault(long key, LongByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte mergeByte(long key, byte value, ByteByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/immutable/ImmutableLong2CharOpenHashMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/immutable/ImmutableLong2CharOpenHashMap.java index 10e135d8..0f0697c2 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/immutable/ImmutableLong2CharOpenHashMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/immutable/ImmutableLong2CharOpenHashMap.java @@ -418,20 +418,19 @@ public void forEach(LongCharConsumer action) { @Override public char computeChar(long key, LongCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharNonDefault(long key, LongCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char computeCharIfAbsent(long key, Long2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharIfAbsentNonDefault(long key, Long2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char supplyCharIfAbsent(long key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public char supplyCharIfAbsentNonDefault(long key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public char computeCharIfPresent(long key, LongCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override + public char computeCharNonDefault(long key, LongCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public char computeCharIfAbsentNonDefault(long key, Long2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public char supplyCharIfAbsentNonDefault(long key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } + @Override public char computeCharIfPresentNonDefault(long key, LongCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char mergeChar(long key, char value, CharCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/immutable/ImmutableLong2DoubleOpenHashMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/immutable/ImmutableLong2DoubleOpenHashMap.java index 352ecc09..daeb3138 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/immutable/ImmutableLong2DoubleOpenHashMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/immutable/ImmutableLong2DoubleOpenHashMap.java @@ -418,20 +418,19 @@ public void forEach(LongDoubleConsumer action) { @Override public double computeDouble(long key, LongDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleNonDefault(long key, LongDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double computeDoubleIfAbsent(long key, Long2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleIfAbsentNonDefault(long key, Long2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double supplyDoubleIfAbsent(long key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public double supplyDoubleIfAbsentNonDefault(long key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public double computeDoubleIfPresent(long key, LongDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override + public double computeDoubleNonDefault(long key, LongDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public double computeDoubleIfAbsentNonDefault(long key, Long2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public double supplyDoubleIfAbsentNonDefault(long key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } + @Override public double computeDoubleIfPresentNonDefault(long key, LongDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double mergeDouble(long key, double value, DoubleDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/immutable/ImmutableLong2FloatOpenHashMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/immutable/ImmutableLong2FloatOpenHashMap.java index 4e5b705a..31f3de18 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/immutable/ImmutableLong2FloatOpenHashMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/immutable/ImmutableLong2FloatOpenHashMap.java @@ -418,20 +418,19 @@ public void forEach(LongFloatConsumer action) { @Override public float computeFloat(long key, LongFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatNonDefault(long key, LongFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float computeFloatIfAbsent(long key, Long2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatIfAbsentNonDefault(long key, Long2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float supplyFloatIfAbsent(long key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public float supplyFloatIfAbsentNonDefault(long key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public float computeFloatIfPresent(long key, LongFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override + public float computeFloatNonDefault(long key, LongFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public float computeFloatIfAbsentNonDefault(long key, Long2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public float supplyFloatIfAbsentNonDefault(long key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } + @Override public float computeFloatIfPresentNonDefault(long key, LongFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float mergeFloat(long key, float value, FloatFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/immutable/ImmutableLong2IntOpenHashMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/immutable/ImmutableLong2IntOpenHashMap.java index 2e58bc05..f4e6e035 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/immutable/ImmutableLong2IntOpenHashMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/immutable/ImmutableLong2IntOpenHashMap.java @@ -418,20 +418,19 @@ public void forEach(LongIntConsumer action) { @Override public int computeInt(long key, LongIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntNonDefault(long key, LongIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int computeIntIfAbsent(long key, Long2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntIfAbsentNonDefault(long key, Long2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int supplyIntIfAbsent(long key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public int supplyIntIfAbsentNonDefault(long key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public int computeIntIfPresent(long key, LongIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override + public int computeIntNonDefault(long key, LongIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public int computeIntIfAbsentNonDefault(long key, Long2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public int supplyIntIfAbsentNonDefault(long key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } + @Override public int computeIntIfPresentNonDefault(long key, LongIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int mergeInt(long key, int value, IntIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/immutable/ImmutableLong2LongOpenHashMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/immutable/ImmutableLong2LongOpenHashMap.java index fcfb942e..bcb3bd36 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/immutable/ImmutableLong2LongOpenHashMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/immutable/ImmutableLong2LongOpenHashMap.java @@ -409,20 +409,19 @@ public void forEach(LongLongConsumer action) { @Override public long computeLong(long key, LongLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongNonDefault(long key, LongLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long computeLongIfAbsent(long key, LongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongIfAbsentNonDefault(long key, LongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long supplyLongIfAbsent(long key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public long supplyLongIfAbsentNonDefault(long key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public long computeLongIfPresent(long key, LongLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override + public long computeLongNonDefault(long key, LongLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public long computeLongIfAbsentNonDefault(long key, LongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public long supplyLongIfAbsentNonDefault(long key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } + @Override public long computeLongIfPresentNonDefault(long key, LongLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long mergeLong(long key, long value, LongLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/immutable/ImmutableLong2ObjectOpenHashMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/immutable/ImmutableLong2ObjectOpenHashMap.java index a406eee8..ed9c4cff 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/immutable/ImmutableLong2ObjectOpenHashMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/immutable/ImmutableLong2ObjectOpenHashMap.java @@ -397,20 +397,11 @@ public void forEach(LongObjectConsumer action) { @Override public V compute(long key, LongObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeNonDefault(long key, LongObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V computeIfAbsent(long key, LongFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeIfAbsentNonDefault(long key, LongFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V supplyIfAbsent(long key, ObjectSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public V supplyIfAbsentNonDefault(long key, ObjectSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public V computeIfPresent(long key, LongObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override - public V computeIfPresentNonDefault(long key, LongObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V merge(long key, V value, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/immutable/ImmutableLong2ShortOpenHashMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/immutable/ImmutableLong2ShortOpenHashMap.java index f1f05295..b95b6a8f 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/immutable/ImmutableLong2ShortOpenHashMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/immutable/ImmutableLong2ShortOpenHashMap.java @@ -418,20 +418,19 @@ public void forEach(LongShortConsumer action) { @Override public short computeShort(long key, LongShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortNonDefault(long key, LongShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short computeShortIfAbsent(long key, Long2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortIfAbsentNonDefault(long key, Long2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short supplyShortIfAbsent(long key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public short supplyShortIfAbsentNonDefault(long key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public short computeShortIfPresent(long key, LongShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override + public short computeShortNonDefault(long key, LongShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public short computeShortIfAbsentNonDefault(long key, Long2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public short supplyShortIfAbsentNonDefault(long key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } + @Override public short computeShortIfPresentNonDefault(long key, LongShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short mergeShort(long key, short value, ShortShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/misc/Long2BooleanArrayMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/misc/Long2BooleanArrayMap.java index d293f445..d3f06a65 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/misc/Long2BooleanArrayMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/misc/Long2BooleanArrayMap.java @@ -420,66 +420,76 @@ public boolean computeBoolean(long key, LongBooleanUnaryOperator mappingFunction } @Override - public boolean computeBooleanNonDefault(long key, LongBooleanUnaryOperator mappingFunction) { + public boolean computeBooleanIfAbsent(long key, LongPredicate mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + boolean newValue = mappingFunction.test(key); insertIndex(size++, key, newValue); return newValue; } - boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + boolean newValue = values[index]; return newValue; } - + @Override - public boolean computeBooleanIfAbsent(long key, LongPredicate mappingFunction) { - Objects.requireNonNull(mappingFunction); + public boolean supplyBooleanIfAbsent(long key, BooleanSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - boolean newValue = mappingFunction.test(key); + boolean newValue = valueProvider.getAsBoolean(); insertIndex(size++, key, newValue); return newValue; } boolean newValue = values[index]; return newValue; } + + @Override + public boolean computeBooleanIfPresent(long key, LongBooleanUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index == -1) return getDefaultReturnValue(); + boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public boolean computeBooleanIfAbsentNonDefault(long key, LongPredicate mappingFunction) { + public boolean computeBooleanNonDefault(long key, LongBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - boolean newValue = mappingFunction.test(key); + boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } - boolean newValue = values[index]; + boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.test(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public boolean supplyBooleanIfAbsent(long key, BooleanSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public boolean computeBooleanIfAbsentNonDefault(long key, LongPredicate mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - boolean newValue = valueProvider.getAsBoolean(); + boolean newValue = mappingFunction.test(key); + if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } boolean newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.test(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -502,16 +512,6 @@ public boolean supplyBooleanIfAbsentNonDefault(long key, BooleanSupplier valuePr return newValue; } - @Override - public boolean computeBooleanIfPresent(long key, LongBooleanUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) return getDefaultReturnValue(); - boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public boolean computeBooleanIfPresentNonDefault(long key, LongBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/misc/Long2ByteArrayMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/misc/Long2ByteArrayMap.java index daa71b4d..e065688c 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/misc/Long2ByteArrayMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/misc/Long2ByteArrayMap.java @@ -443,66 +443,76 @@ public byte computeByte(long key, LongByteUnaryOperator mappingFunction) { } @Override - public byte computeByteNonDefault(long key, LongByteUnaryOperator mappingFunction) { + public byte computeByteIfAbsent(long key, Long2ByteFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + byte newValue = mappingFunction.applyAsByte(key); insertIndex(size++, key, newValue); return newValue; } - byte newValue = mappingFunction.applyAsByte(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + byte newValue = values[index]; return newValue; } - + @Override - public byte computeByteIfAbsent(long key, Long2ByteFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public byte supplyByteIfAbsent(long key, ByteSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = valueProvider.getAsByte(); insertIndex(size++, key, newValue); return newValue; } byte newValue = values[index]; return newValue; } + + @Override + public byte computeByteIfPresent(long key, LongByteUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index == -1) return getDefaultReturnValue(); + byte newValue = mappingFunction.applyAsByte(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public byte computeByteIfAbsentNonDefault(long key, Long2ByteFunction mappingFunction) { + public byte computeByteNonDefault(long key, LongByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } - byte newValue = values[index]; + byte newValue = mappingFunction.applyAsByte(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsByte(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public byte supplyByteIfAbsent(long key, ByteSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public byte computeByteIfAbsentNonDefault(long key, Long2ByteFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - byte newValue = valueProvider.getAsInt(); + byte newValue = mappingFunction.applyAsByte(key); + if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } byte newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsByte(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -511,30 +521,20 @@ public byte supplyByteIfAbsentNonDefault(long key, ByteSupplier valueProvider) { Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - byte newValue = valueProvider.getAsInt(); + byte newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } byte newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public byte computeByteIfPresent(long key, LongByteUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) return getDefaultReturnValue(); - byte newValue = mappingFunction.applyAsByte(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public byte computeByteIfPresentNonDefault(long key, LongByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/misc/Long2CharArrayMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/misc/Long2CharArrayMap.java index 6b28354a..78e86296 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/misc/Long2CharArrayMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/misc/Long2CharArrayMap.java @@ -443,66 +443,76 @@ public char computeChar(long key, LongCharUnaryOperator mappingFunction) { } @Override - public char computeCharNonDefault(long key, LongCharUnaryOperator mappingFunction) { + public char computeCharIfAbsent(long key, Long2CharFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + char newValue = mappingFunction.applyAsChar(key); insertIndex(size++, key, newValue); return newValue; } - char newValue = mappingFunction.applyAsChar(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + char newValue = values[index]; return newValue; } - + @Override - public char computeCharIfAbsent(long key, Long2CharFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public char supplyCharIfAbsent(long key, CharSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = valueProvider.getAsChar(); insertIndex(size++, key, newValue); return newValue; } char newValue = values[index]; return newValue; } + + @Override + public char computeCharIfPresent(long key, LongCharUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index == -1) return getDefaultReturnValue(); + char newValue = mappingFunction.applyAsChar(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public char computeCharIfAbsentNonDefault(long key, Long2CharFunction mappingFunction) { + public char computeCharNonDefault(long key, LongCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } - char newValue = values[index]; + char newValue = mappingFunction.applyAsChar(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsChar(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public char supplyCharIfAbsent(long key, CharSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public char computeCharIfAbsentNonDefault(long key, Long2CharFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - char newValue = valueProvider.getAsInt(); + char newValue = mappingFunction.applyAsChar(key); + if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } char newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsChar(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -511,30 +521,20 @@ public char supplyCharIfAbsentNonDefault(long key, CharSupplier valueProvider) { Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - char newValue = valueProvider.getAsInt(); + char newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } char newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public char computeCharIfPresent(long key, LongCharUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) return getDefaultReturnValue(); - char newValue = mappingFunction.applyAsChar(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public char computeCharIfPresentNonDefault(long key, LongCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/misc/Long2DoubleArrayMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/misc/Long2DoubleArrayMap.java index a934e77b..699fc3c1 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/misc/Long2DoubleArrayMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/misc/Long2DoubleArrayMap.java @@ -443,66 +443,76 @@ public double computeDouble(long key, LongDoubleUnaryOperator mappingFunction) { } @Override - public double computeDoubleNonDefault(long key, LongDoubleUnaryOperator mappingFunction) { + public double computeDoubleIfAbsent(long key, Long2DoubleFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + double newValue = mappingFunction.applyAsDouble(key); insertIndex(size++, key, newValue); return newValue; } - double newValue = mappingFunction.applyAsDouble(key, values[index]); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + double newValue = values[index]; return newValue; } - + @Override - public double computeDoubleIfAbsent(long key, Long2DoubleFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public double supplyDoubleIfAbsent(long key, DoubleSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = valueProvider.getAsDouble(); insertIndex(size++, key, newValue); return newValue; } double newValue = values[index]; return newValue; } + + @Override + public double computeDoubleIfPresent(long key, LongDoubleUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index == -1) return getDefaultReturnValue(); + double newValue = mappingFunction.applyAsDouble(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public double computeDoubleIfAbsentNonDefault(long key, Long2DoubleFunction mappingFunction) { + public double computeDoubleNonDefault(long key, LongDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; insertIndex(size++, key, newValue); return newValue; } - double newValue = values[index]; + double newValue = mappingFunction.applyAsDouble(key, values[index]); if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - newValue = mappingFunction.applyAsDouble(key); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public double supplyDoubleIfAbsent(long key, DoubleSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public double computeDoubleIfAbsentNonDefault(long key, Long2DoubleFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - double newValue = valueProvider.getAsDouble(); + double newValue = mappingFunction.applyAsDouble(key); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; insertIndex(size++, key, newValue); return newValue; } double newValue = values[index]; + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { + newValue = mappingFunction.applyAsDouble(key); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + values[index] = newValue; + } return newValue; } @@ -525,16 +535,6 @@ public double supplyDoubleIfAbsentNonDefault(long key, DoubleSupplier valueProvi return newValue; } - @Override - public double computeDoubleIfPresent(long key, LongDoubleUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) return getDefaultReturnValue(); - double newValue = mappingFunction.applyAsDouble(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public double computeDoubleIfPresentNonDefault(long key, LongDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/misc/Long2FloatArrayMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/misc/Long2FloatArrayMap.java index cdb9269a..736b3055 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/misc/Long2FloatArrayMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/misc/Long2FloatArrayMap.java @@ -443,66 +443,76 @@ public float computeFloat(long key, LongFloatUnaryOperator mappingFunction) { } @Override - public float computeFloatNonDefault(long key, LongFloatUnaryOperator mappingFunction) { + public float computeFloatIfAbsent(long key, Long2FloatFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + float newValue = mappingFunction.applyAsFloat(key); insertIndex(size++, key, newValue); return newValue; } - float newValue = mappingFunction.applyAsFloat(key, values[index]); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + float newValue = values[index]; return newValue; } - + @Override - public float computeFloatIfAbsent(long key, Long2FloatFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public float supplyFloatIfAbsent(long key, FloatSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = valueProvider.getAsFloat(); insertIndex(size++, key, newValue); return newValue; } float newValue = values[index]; return newValue; } + + @Override + public float computeFloatIfPresent(long key, LongFloatUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index == -1) return getDefaultReturnValue(); + float newValue = mappingFunction.applyAsFloat(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public float computeFloatIfAbsentNonDefault(long key, Long2FloatFunction mappingFunction) { + public float computeFloatNonDefault(long key, LongFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insertIndex(size++, key, newValue); return newValue; } - float newValue = values[index]; + float newValue = mappingFunction.applyAsFloat(key, values[index]); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - newValue = mappingFunction.applyAsFloat(key); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public float supplyFloatIfAbsent(long key, FloatSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public float computeFloatIfAbsentNonDefault(long key, Long2FloatFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - float newValue = valueProvider.getAsDouble(); + float newValue = mappingFunction.applyAsFloat(key); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insertIndex(size++, key, newValue); return newValue; } float newValue = values[index]; + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { + newValue = mappingFunction.applyAsFloat(key); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + values[index] = newValue; + } return newValue; } @@ -511,30 +521,20 @@ public float supplyFloatIfAbsentNonDefault(long key, FloatSupplier valueProvider Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - float newValue = valueProvider.getAsDouble(); + float newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insertIndex(size++, key, newValue); return newValue; } float newValue = values[index]; if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - newValue = valueProvider.getAsDouble(); + newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; values[index] = newValue; } return newValue; } - @Override - public float computeFloatIfPresent(long key, LongFloatUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) return getDefaultReturnValue(); - float newValue = mappingFunction.applyAsFloat(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public float computeFloatIfPresentNonDefault(long key, LongFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/misc/Long2IntArrayMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/misc/Long2IntArrayMap.java index d2209add..52071b3d 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/misc/Long2IntArrayMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/misc/Long2IntArrayMap.java @@ -443,66 +443,76 @@ public int computeInt(long key, LongIntUnaryOperator mappingFunction) { } @Override - public int computeIntNonDefault(long key, LongIntUnaryOperator mappingFunction) { + public int computeIntIfAbsent(long key, Long2IntFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + int newValue = mappingFunction.applyAsInt(key); insertIndex(size++, key, newValue); return newValue; } - int newValue = mappingFunction.applyAsInt(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + int newValue = values[index]; return newValue; } - + @Override - public int computeIntIfAbsent(long key, Long2IntFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public int supplyIntIfAbsent(long key, IntSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = valueProvider.getAsInt(); insertIndex(size++, key, newValue); return newValue; } int newValue = values[index]; return newValue; } + + @Override + public int computeIntIfPresent(long key, LongIntUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index == -1) return getDefaultReturnValue(); + int newValue = mappingFunction.applyAsInt(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public int computeIntIfAbsentNonDefault(long key, Long2IntFunction mappingFunction) { + public int computeIntNonDefault(long key, LongIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } - int newValue = values[index]; + int newValue = mappingFunction.applyAsInt(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsInt(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public int supplyIntIfAbsent(long key, IntSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public int computeIntIfAbsentNonDefault(long key, Long2IntFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - int newValue = valueProvider.getAsInt(); + int newValue = mappingFunction.applyAsInt(key); + if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } int newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsInt(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -525,16 +535,6 @@ public int supplyIntIfAbsentNonDefault(long key, IntSupplier valueProvider) { return newValue; } - @Override - public int computeIntIfPresent(long key, LongIntUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) return getDefaultReturnValue(); - int newValue = mappingFunction.applyAsInt(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public int computeIntIfPresentNonDefault(long key, LongIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/misc/Long2LongArrayMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/misc/Long2LongArrayMap.java index a19e23d0..360b542d 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/misc/Long2LongArrayMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/misc/Long2LongArrayMap.java @@ -436,66 +436,76 @@ public long computeLong(long key, LongLongUnaryOperator mappingFunction) { } @Override - public long computeLongNonDefault(long key, LongLongUnaryOperator mappingFunction) { + public long computeLongIfAbsent(long key, LongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + long newValue = mappingFunction.applyAsLong(key); insertIndex(size++, key, newValue); return newValue; } - long newValue = mappingFunction.applyAsLong(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + long newValue = values[index]; return newValue; } - + @Override - public long computeLongIfAbsent(long key, LongUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); + public long supplyLongIfAbsent(long key, LongSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = valueProvider.getAsLong(); insertIndex(size++, key, newValue); return newValue; } long newValue = values[index]; return newValue; } + + @Override + public long computeLongIfPresent(long key, LongLongUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index == -1) return getDefaultReturnValue(); + long newValue = mappingFunction.applyAsLong(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public long computeLongIfAbsentNonDefault(long key, LongUnaryOperator mappingFunction) { + public long computeLongNonDefault(long key, LongLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } - long newValue = values[index]; + long newValue = mappingFunction.applyAsLong(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsLong(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public long supplyLongIfAbsent(long key, LongSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public long computeLongIfAbsentNonDefault(long key, LongUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - long newValue = valueProvider.getAsLong(); + long newValue = mappingFunction.applyAsLong(key); + if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } long newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsLong(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -518,16 +528,6 @@ public long supplyLongIfAbsentNonDefault(long key, LongSupplier valueProvider) { return newValue; } - @Override - public long computeLongIfPresent(long key, LongLongUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) return getDefaultReturnValue(); - long newValue = mappingFunction.applyAsLong(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public long computeLongIfPresentNonDefault(long key, LongLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/misc/Long2ObjectArrayMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/misc/Long2ObjectArrayMap.java index fbd308f4..11721db1 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/misc/Long2ObjectArrayMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/misc/Long2ObjectArrayMap.java @@ -415,25 +415,6 @@ public V compute(long key, LongObjectUnaryOperator mappingFunction) { return newValue; } - @Override - public V computeNonDefault(long key, LongObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) { - V newValue = mappingFunction.apply(key, getDefaultReturnValue()); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insertIndex(size++, key, newValue); - return newValue; - } - V newValue = mappingFunction.apply(key, values[index]); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; - return newValue; - } - @Override public V computeIfAbsent(long key, LongFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -452,26 +433,7 @@ public V computeIfAbsent(long key, LongFunction mappingFunction) { } return newValue; } - - @Override - public V computeIfAbsentNonDefault(long key, LongFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) { - V newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insertIndex(size++, key, newValue); - return newValue; - } - V newValue = values[index]; - if(Objects.equals(newValue, getDefaultReturnValue())) { - newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - values[index] = newValue; - } - return newValue; - } - + @Override public V supplyIfAbsent(long key, ObjectSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -490,26 +452,7 @@ public V supplyIfAbsent(long key, ObjectSupplier valueProvider) { } return newValue; } - - @Override - public V supplyIfAbsentNonDefault(long key, ObjectSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - int index = findIndex(key); - if(index == -1) { - V newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insertIndex(size++, key, newValue); - return newValue; - } - V newValue = values[index]; - if(Objects.equals(newValue, getDefaultReturnValue())) { - newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - values[index] = newValue; - } - return newValue; - } - + @Override public V computeIfPresent(long key, LongObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -524,20 +467,6 @@ public V computeIfPresent(long key, LongObjectUnaryOperator mappingFunction) return newValue; } - @Override - public V computeIfPresentNonDefault(long key, LongObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1 || Objects.equals(values[index], getDefaultReturnValue())) return getDefaultReturnValue(); - V newValue = mappingFunction.apply(key, values[index]); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; - return newValue; - } - @Override public V merge(long key, V value, ObjectObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/misc/Long2ShortArrayMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/misc/Long2ShortArrayMap.java index a969c4f3..40bddf85 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/misc/Long2ShortArrayMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/misc/Long2ShortArrayMap.java @@ -443,66 +443,76 @@ public short computeShort(long key, LongShortUnaryOperator mappingFunction) { } @Override - public short computeShortNonDefault(long key, LongShortUnaryOperator mappingFunction) { + public short computeShortIfAbsent(long key, Long2ShortFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + short newValue = mappingFunction.applyAsShort(key); insertIndex(size++, key, newValue); return newValue; } - short newValue = mappingFunction.applyAsShort(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + short newValue = values[index]; return newValue; } - + @Override - public short computeShortIfAbsent(long key, Long2ShortFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public short supplyShortIfAbsent(long key, ShortSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = valueProvider.getAsShort(); insertIndex(size++, key, newValue); return newValue; } short newValue = values[index]; return newValue; } + + @Override + public short computeShortIfPresent(long key, LongShortUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index == -1) return getDefaultReturnValue(); + short newValue = mappingFunction.applyAsShort(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public short computeShortIfAbsentNonDefault(long key, Long2ShortFunction mappingFunction) { + public short computeShortNonDefault(long key, LongShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } - short newValue = values[index]; + short newValue = mappingFunction.applyAsShort(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsShort(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public short supplyShortIfAbsent(long key, ShortSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public short computeShortIfAbsentNonDefault(long key, Long2ShortFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - short newValue = valueProvider.getAsInt(); + short newValue = mappingFunction.applyAsShort(key); + if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } short newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsShort(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -511,30 +521,20 @@ public short supplyShortIfAbsentNonDefault(long key, ShortSupplier valueProvider Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - short newValue = valueProvider.getAsInt(); + short newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } short newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public short computeShortIfPresent(long key, LongShortUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) return getDefaultReturnValue(); - short newValue = mappingFunction.applyAsShort(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public short computeShortIfPresentNonDefault(long key, LongShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2BooleanAVLTreeMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2BooleanAVLTreeMap.java index 11dacd73..c373c47d 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2BooleanAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2BooleanAVLTreeMap.java @@ -396,34 +396,56 @@ public boolean computeBoolean(long key, LongBooleanUnaryOperator mappingFunction } @Override - public boolean computeBooleanNonDefault(long key, LongBooleanUnaryOperator mappingFunction) { + public boolean computeBooleanIfAbsent(long key, LongPredicate mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + boolean newValue = mappingFunction.test(key); put(key, newValue); return newValue; } - boolean newValue = mappingFunction.applyAsBoolean(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public boolean supplyBooleanIfAbsent(long key, BooleanSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + boolean newValue = valueProvider.getAsBoolean(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public boolean computeBooleanIfPresent(long key, LongBooleanUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + boolean newValue = mappingFunction.applyAsBoolean(key, entry.value); entry.value = newValue; return newValue; } @Override - public boolean computeBooleanIfAbsent(long key, LongPredicate mappingFunction) { + public boolean computeBooleanNonDefault(long key, LongBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - boolean newValue = mappingFunction.test(key); + boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + boolean newValue = mappingFunction.applyAsBoolean(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -444,18 +466,6 @@ public boolean computeBooleanIfAbsentNonDefault(long key, LongPredicate mappingF return entry.value; } - @Override - public boolean supplyBooleanIfAbsent(long key, BooleanSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - boolean newValue = valueProvider.getAsBoolean(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public boolean supplyBooleanIfAbsentNonDefault(long key, BooleanSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -474,16 +484,6 @@ public boolean supplyBooleanIfAbsentNonDefault(long key, BooleanSupplier valuePr return entry.value; } - @Override - public boolean computeBooleanIfPresent(long key, LongBooleanUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - boolean newValue = mappingFunction.applyAsBoolean(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public boolean computeBooleanIfPresentNonDefault(long key, LongBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1487,14 +1487,9 @@ public boolean computeBooleanIfPresent(long key, LongBooleanUnaryOperator mappin Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - boolean newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2BooleanRBTreeMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2BooleanRBTreeMap.java index d61f0930..d2b721b9 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2BooleanRBTreeMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2BooleanRBTreeMap.java @@ -395,34 +395,56 @@ public boolean computeBoolean(long key, LongBooleanUnaryOperator mappingFunction } @Override - public boolean computeBooleanNonDefault(long key, LongBooleanUnaryOperator mappingFunction) { + public boolean computeBooleanIfAbsent(long key, LongPredicate mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + boolean newValue = mappingFunction.test(key); put(key, newValue); return newValue; } - boolean newValue = mappingFunction.applyAsBoolean(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public boolean supplyBooleanIfAbsent(long key, BooleanSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + boolean newValue = valueProvider.getAsBoolean(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public boolean computeBooleanIfPresent(long key, LongBooleanUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + boolean newValue = mappingFunction.applyAsBoolean(key, entry.value); entry.value = newValue; return newValue; } @Override - public boolean computeBooleanIfAbsent(long key, LongPredicate mappingFunction) { + public boolean computeBooleanNonDefault(long key, LongBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - boolean newValue = mappingFunction.test(key); + boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + boolean newValue = mappingFunction.applyAsBoolean(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -443,18 +465,6 @@ public boolean computeBooleanIfAbsentNonDefault(long key, LongPredicate mappingF return entry.value; } - @Override - public boolean supplyBooleanIfAbsent(long key, BooleanSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - boolean newValue = valueProvider.getAsBoolean(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public boolean supplyBooleanIfAbsentNonDefault(long key, BooleanSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -473,16 +483,6 @@ public boolean supplyBooleanIfAbsentNonDefault(long key, BooleanSupplier valuePr return entry.value; } - @Override - public boolean computeBooleanIfPresent(long key, LongBooleanUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - boolean newValue = mappingFunction.applyAsBoolean(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public boolean computeBooleanIfPresentNonDefault(long key, LongBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1550,14 +1550,9 @@ public boolean computeBooleanIfPresent(long key, LongBooleanUnaryOperator mappin Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - boolean newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2ByteAVLTreeMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2ByteAVLTreeMap.java index 48a74716..17998200 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2ByteAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2ByteAVLTreeMap.java @@ -455,34 +455,56 @@ public byte computeByte(long key, LongByteUnaryOperator mappingFunction) { } @Override - public byte computeByteNonDefault(long key, LongByteUnaryOperator mappingFunction) { + public byte computeByteIfAbsent(long key, Long2ByteFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + byte newValue = mappingFunction.applyAsByte(key); put(key, newValue); return newValue; } - byte newValue = mappingFunction.applyAsByte(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public byte supplyByteIfAbsent(long key, ByteSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + byte newValue = valueProvider.getAsByte(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public byte computeByteIfPresent(long key, LongByteUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + byte newValue = mappingFunction.applyAsByte(key, entry.value); entry.value = newValue; return newValue; } @Override - public byte computeByteIfAbsent(long key, Long2ByteFunction mappingFunction) { + public byte computeByteNonDefault(long key, LongByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + byte newValue = mappingFunction.applyAsByte(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -503,46 +525,24 @@ public byte computeByteIfAbsentNonDefault(long key, Long2ByteFunction mappingFun return entry.value; } - @Override - public byte supplyByteIfAbsent(long key, ByteSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - byte newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public byte supplyByteIfAbsentNonDefault(long key, ByteSupplier valueProvider) { Objects.requireNonNull(valueProvider); Node entry = findNode(key); if(entry == null) { - byte newValue = valueProvider.getAsInt(); + byte newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } if(entry.value == getDefaultReturnValue()) { - byte newValue = valueProvider.getAsInt(); + byte newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; entry.value = newValue; } return entry.value; } - @Override - public byte computeByteIfPresent(long key, LongByteUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - byte newValue = mappingFunction.applyAsByte(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public byte computeByteIfPresentNonDefault(long key, LongByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1558,14 +1558,9 @@ public byte computeByteIfPresent(long key, LongByteUnaryOperator mappingFunction Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - byte newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2ByteRBTreeMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2ByteRBTreeMap.java index aa3a16e9..bb87ce72 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2ByteRBTreeMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2ByteRBTreeMap.java @@ -454,34 +454,56 @@ public byte computeByte(long key, LongByteUnaryOperator mappingFunction) { } @Override - public byte computeByteNonDefault(long key, LongByteUnaryOperator mappingFunction) { + public byte computeByteIfAbsent(long key, Long2ByteFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + byte newValue = mappingFunction.applyAsByte(key); put(key, newValue); return newValue; } - byte newValue = mappingFunction.applyAsByte(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public byte supplyByteIfAbsent(long key, ByteSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + byte newValue = valueProvider.getAsByte(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public byte computeByteIfPresent(long key, LongByteUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + byte newValue = mappingFunction.applyAsByte(key, entry.value); entry.value = newValue; return newValue; } @Override - public byte computeByteIfAbsent(long key, Long2ByteFunction mappingFunction) { + public byte computeByteNonDefault(long key, LongByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + byte newValue = mappingFunction.applyAsByte(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -502,46 +524,24 @@ public byte computeByteIfAbsentNonDefault(long key, Long2ByteFunction mappingFun return entry.value; } - @Override - public byte supplyByteIfAbsent(long key, ByteSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - byte newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public byte supplyByteIfAbsentNonDefault(long key, ByteSupplier valueProvider) { Objects.requireNonNull(valueProvider); Node entry = findNode(key); if(entry == null) { - byte newValue = valueProvider.getAsInt(); + byte newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } if(entry.value == getDefaultReturnValue()) { - byte newValue = valueProvider.getAsInt(); + byte newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; entry.value = newValue; } return entry.value; } - @Override - public byte computeByteIfPresent(long key, LongByteUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - byte newValue = mappingFunction.applyAsByte(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public byte computeByteIfPresentNonDefault(long key, LongByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1621,14 +1621,9 @@ public byte computeByteIfPresent(long key, LongByteUnaryOperator mappingFunction Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - byte newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2CharAVLTreeMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2CharAVLTreeMap.java index e39e56f9..04b531e0 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2CharAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2CharAVLTreeMap.java @@ -455,34 +455,56 @@ public char computeChar(long key, LongCharUnaryOperator mappingFunction) { } @Override - public char computeCharNonDefault(long key, LongCharUnaryOperator mappingFunction) { + public char computeCharIfAbsent(long key, Long2CharFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + char newValue = mappingFunction.applyAsChar(key); put(key, newValue); return newValue; } - char newValue = mappingFunction.applyAsChar(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public char supplyCharIfAbsent(long key, CharSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + char newValue = valueProvider.getAsChar(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public char computeCharIfPresent(long key, LongCharUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + char newValue = mappingFunction.applyAsChar(key, entry.value); entry.value = newValue; return newValue; } @Override - public char computeCharIfAbsent(long key, Long2CharFunction mappingFunction) { + public char computeCharNonDefault(long key, LongCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + char newValue = mappingFunction.applyAsChar(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -503,46 +525,24 @@ public char computeCharIfAbsentNonDefault(long key, Long2CharFunction mappingFun return entry.value; } - @Override - public char supplyCharIfAbsent(long key, CharSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - char newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public char supplyCharIfAbsentNonDefault(long key, CharSupplier valueProvider) { Objects.requireNonNull(valueProvider); Node entry = findNode(key); if(entry == null) { - char newValue = valueProvider.getAsInt(); + char newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } if(entry.value == getDefaultReturnValue()) { - char newValue = valueProvider.getAsInt(); + char newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; entry.value = newValue; } return entry.value; } - @Override - public char computeCharIfPresent(long key, LongCharUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - char newValue = mappingFunction.applyAsChar(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public char computeCharIfPresentNonDefault(long key, LongCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1558,14 +1558,9 @@ public char computeCharIfPresent(long key, LongCharUnaryOperator mappingFunction Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - char newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2CharRBTreeMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2CharRBTreeMap.java index c408c971..9fdec06b 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2CharRBTreeMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2CharRBTreeMap.java @@ -454,34 +454,56 @@ public char computeChar(long key, LongCharUnaryOperator mappingFunction) { } @Override - public char computeCharNonDefault(long key, LongCharUnaryOperator mappingFunction) { + public char computeCharIfAbsent(long key, Long2CharFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + char newValue = mappingFunction.applyAsChar(key); put(key, newValue); return newValue; } - char newValue = mappingFunction.applyAsChar(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public char supplyCharIfAbsent(long key, CharSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + char newValue = valueProvider.getAsChar(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public char computeCharIfPresent(long key, LongCharUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + char newValue = mappingFunction.applyAsChar(key, entry.value); entry.value = newValue; return newValue; } @Override - public char computeCharIfAbsent(long key, Long2CharFunction mappingFunction) { + public char computeCharNonDefault(long key, LongCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + char newValue = mappingFunction.applyAsChar(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -502,46 +524,24 @@ public char computeCharIfAbsentNonDefault(long key, Long2CharFunction mappingFun return entry.value; } - @Override - public char supplyCharIfAbsent(long key, CharSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - char newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public char supplyCharIfAbsentNonDefault(long key, CharSupplier valueProvider) { Objects.requireNonNull(valueProvider); Node entry = findNode(key); if(entry == null) { - char newValue = valueProvider.getAsInt(); + char newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } if(entry.value == getDefaultReturnValue()) { - char newValue = valueProvider.getAsInt(); + char newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; entry.value = newValue; } return entry.value; } - @Override - public char computeCharIfPresent(long key, LongCharUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - char newValue = mappingFunction.applyAsChar(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public char computeCharIfPresentNonDefault(long key, LongCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1621,14 +1621,9 @@ public char computeCharIfPresent(long key, LongCharUnaryOperator mappingFunction Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - char newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2DoubleAVLTreeMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2DoubleAVLTreeMap.java index 5895301b..c1271958 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2DoubleAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2DoubleAVLTreeMap.java @@ -455,34 +455,56 @@ public double computeDouble(long key, LongDoubleUnaryOperator mappingFunction) { } @Override - public double computeDoubleNonDefault(long key, LongDoubleUnaryOperator mappingFunction) { + public double computeDoubleIfAbsent(long key, Long2DoubleFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + double newValue = mappingFunction.applyAsDouble(key); put(key, newValue); return newValue; } - double newValue = mappingFunction.applyAsDouble(key, entry.value); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - removeNode(entry); + return entry.value; + } + + @Override + public double supplyDoubleIfAbsent(long key, DoubleSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + double newValue = valueProvider.getAsDouble(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public double computeDoubleIfPresent(long key, LongDoubleUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + double newValue = mappingFunction.applyAsDouble(key, entry.value); entry.value = newValue; return newValue; } @Override - public double computeDoubleIfAbsent(long key, Long2DoubleFunction mappingFunction) { + public double computeDoubleNonDefault(long key, LongDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; put(key, newValue); return newValue; } - return entry.value; + double newValue = mappingFunction.applyAsDouble(key, entry.value); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -503,18 +525,6 @@ public double computeDoubleIfAbsentNonDefault(long key, Long2DoubleFunction mapp return entry.value; } - @Override - public double supplyDoubleIfAbsent(long key, DoubleSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - double newValue = valueProvider.getAsDouble(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public double supplyDoubleIfAbsentNonDefault(long key, DoubleSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -533,16 +543,6 @@ public double supplyDoubleIfAbsentNonDefault(long key, DoubleSupplier valueProvi return entry.value; } - @Override - public double computeDoubleIfPresent(long key, LongDoubleUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - double newValue = mappingFunction.applyAsDouble(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public double computeDoubleIfPresentNonDefault(long key, LongDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1558,14 +1558,9 @@ public double computeDoubleIfPresent(long key, LongDoubleUnaryOperator mappingFu Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || Double.doubleToLongBits(entry.value) == Double.doubleToLongBits(getDefaultReturnValue())) return getDefaultReturnValue(); - double newValue = mappingFunction.apply(key, entry.value); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2DoubleRBTreeMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2DoubleRBTreeMap.java index f8802f0d..264f708d 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2DoubleRBTreeMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2DoubleRBTreeMap.java @@ -454,34 +454,56 @@ public double computeDouble(long key, LongDoubleUnaryOperator mappingFunction) { } @Override - public double computeDoubleNonDefault(long key, LongDoubleUnaryOperator mappingFunction) { + public double computeDoubleIfAbsent(long key, Long2DoubleFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + double newValue = mappingFunction.applyAsDouble(key); put(key, newValue); return newValue; } - double newValue = mappingFunction.applyAsDouble(key, entry.value); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - removeNode(entry); + return entry.value; + } + + @Override + public double supplyDoubleIfAbsent(long key, DoubleSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + double newValue = valueProvider.getAsDouble(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public double computeDoubleIfPresent(long key, LongDoubleUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + double newValue = mappingFunction.applyAsDouble(key, entry.value); entry.value = newValue; return newValue; } @Override - public double computeDoubleIfAbsent(long key, Long2DoubleFunction mappingFunction) { + public double computeDoubleNonDefault(long key, LongDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; put(key, newValue); return newValue; } - return entry.value; + double newValue = mappingFunction.applyAsDouble(key, entry.value); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -502,18 +524,6 @@ public double computeDoubleIfAbsentNonDefault(long key, Long2DoubleFunction mapp return entry.value; } - @Override - public double supplyDoubleIfAbsent(long key, DoubleSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - double newValue = valueProvider.getAsDouble(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public double supplyDoubleIfAbsentNonDefault(long key, DoubleSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -532,16 +542,6 @@ public double supplyDoubleIfAbsentNonDefault(long key, DoubleSupplier valueProvi return entry.value; } - @Override - public double computeDoubleIfPresent(long key, LongDoubleUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - double newValue = mappingFunction.applyAsDouble(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public double computeDoubleIfPresentNonDefault(long key, LongDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1621,14 +1621,9 @@ public double computeDoubleIfPresent(long key, LongDoubleUnaryOperator mappingFu Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || Double.doubleToLongBits(entry.value) == Double.doubleToLongBits(getDefaultReturnValue())) return getDefaultReturnValue(); - double newValue = mappingFunction.apply(key, entry.value); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2FloatAVLTreeMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2FloatAVLTreeMap.java index c274940d..db1646da 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2FloatAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2FloatAVLTreeMap.java @@ -455,34 +455,56 @@ public float computeFloat(long key, LongFloatUnaryOperator mappingFunction) { } @Override - public float computeFloatNonDefault(long key, LongFloatUnaryOperator mappingFunction) { + public float computeFloatIfAbsent(long key, Long2FloatFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + float newValue = mappingFunction.applyAsFloat(key); put(key, newValue); return newValue; } - float newValue = mappingFunction.applyAsFloat(key, entry.value); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - removeNode(entry); + return entry.value; + } + + @Override + public float supplyFloatIfAbsent(long key, FloatSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + float newValue = valueProvider.getAsFloat(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public float computeFloatIfPresent(long key, LongFloatUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + float newValue = mappingFunction.applyAsFloat(key, entry.value); entry.value = newValue; return newValue; } @Override - public float computeFloatIfAbsent(long key, Long2FloatFunction mappingFunction) { + public float computeFloatNonDefault(long key, LongFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; put(key, newValue); return newValue; } - return entry.value; + float newValue = mappingFunction.applyAsFloat(key, entry.value); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -503,46 +525,24 @@ public float computeFloatIfAbsentNonDefault(long key, Long2FloatFunction mapping return entry.value; } - @Override - public float supplyFloatIfAbsent(long key, FloatSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - float newValue = valueProvider.getAsDouble(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public float supplyFloatIfAbsentNonDefault(long key, FloatSupplier valueProvider) { Objects.requireNonNull(valueProvider); Node entry = findNode(key); if(entry == null) { - float newValue = valueProvider.getAsDouble(); + float newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; put(key, newValue); return newValue; } if(Float.floatToIntBits(entry.value) == Float.floatToIntBits(getDefaultReturnValue())) { - float newValue = valueProvider.getAsDouble(); + float newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; entry.value = newValue; } return entry.value; } - @Override - public float computeFloatIfPresent(long key, LongFloatUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - float newValue = mappingFunction.applyAsFloat(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public float computeFloatIfPresentNonDefault(long key, LongFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1558,14 +1558,9 @@ public float computeFloatIfPresent(long key, LongFloatUnaryOperator mappingFunct Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || Float.floatToIntBits(entry.value) == Float.floatToIntBits(getDefaultReturnValue())) return getDefaultReturnValue(); - float newValue = mappingFunction.apply(key, entry.value); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2FloatRBTreeMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2FloatRBTreeMap.java index d9e87e54..7b28ce36 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2FloatRBTreeMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2FloatRBTreeMap.java @@ -454,34 +454,56 @@ public float computeFloat(long key, LongFloatUnaryOperator mappingFunction) { } @Override - public float computeFloatNonDefault(long key, LongFloatUnaryOperator mappingFunction) { + public float computeFloatIfAbsent(long key, Long2FloatFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + float newValue = mappingFunction.applyAsFloat(key); put(key, newValue); return newValue; } - float newValue = mappingFunction.applyAsFloat(key, entry.value); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - removeNode(entry); + return entry.value; + } + + @Override + public float supplyFloatIfAbsent(long key, FloatSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + float newValue = valueProvider.getAsFloat(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public float computeFloatIfPresent(long key, LongFloatUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + float newValue = mappingFunction.applyAsFloat(key, entry.value); entry.value = newValue; return newValue; } @Override - public float computeFloatIfAbsent(long key, Long2FloatFunction mappingFunction) { + public float computeFloatNonDefault(long key, LongFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; put(key, newValue); return newValue; } - return entry.value; + float newValue = mappingFunction.applyAsFloat(key, entry.value); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -502,46 +524,24 @@ public float computeFloatIfAbsentNonDefault(long key, Long2FloatFunction mapping return entry.value; } - @Override - public float supplyFloatIfAbsent(long key, FloatSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - float newValue = valueProvider.getAsDouble(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public float supplyFloatIfAbsentNonDefault(long key, FloatSupplier valueProvider) { Objects.requireNonNull(valueProvider); Node entry = findNode(key); if(entry == null) { - float newValue = valueProvider.getAsDouble(); + float newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; put(key, newValue); return newValue; } if(Float.floatToIntBits(entry.value) == Float.floatToIntBits(getDefaultReturnValue())) { - float newValue = valueProvider.getAsDouble(); + float newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; entry.value = newValue; } return entry.value; } - @Override - public float computeFloatIfPresent(long key, LongFloatUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - float newValue = mappingFunction.applyAsFloat(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public float computeFloatIfPresentNonDefault(long key, LongFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1621,14 +1621,9 @@ public float computeFloatIfPresent(long key, LongFloatUnaryOperator mappingFunct Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || Float.floatToIntBits(entry.value) == Float.floatToIntBits(getDefaultReturnValue())) return getDefaultReturnValue(); - float newValue = mappingFunction.apply(key, entry.value); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2IntAVLTreeMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2IntAVLTreeMap.java index 4220485d..d03e1d21 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2IntAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2IntAVLTreeMap.java @@ -455,34 +455,56 @@ public int computeInt(long key, LongIntUnaryOperator mappingFunction) { } @Override - public int computeIntNonDefault(long key, LongIntUnaryOperator mappingFunction) { + public int computeIntIfAbsent(long key, Long2IntFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + int newValue = mappingFunction.applyAsInt(key); put(key, newValue); return newValue; } - int newValue = mappingFunction.applyAsInt(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public int supplyIntIfAbsent(long key, IntSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + int newValue = valueProvider.getAsInt(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public int computeIntIfPresent(long key, LongIntUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + int newValue = mappingFunction.applyAsInt(key, entry.value); entry.value = newValue; return newValue; } @Override - public int computeIntIfAbsent(long key, Long2IntFunction mappingFunction) { + public int computeIntNonDefault(long key, LongIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + int newValue = mappingFunction.applyAsInt(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -503,18 +525,6 @@ public int computeIntIfAbsentNonDefault(long key, Long2IntFunction mappingFuncti return entry.value; } - @Override - public int supplyIntIfAbsent(long key, IntSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - int newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public int supplyIntIfAbsentNonDefault(long key, IntSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -533,16 +543,6 @@ public int supplyIntIfAbsentNonDefault(long key, IntSupplier valueProvider) { return entry.value; } - @Override - public int computeIntIfPresent(long key, LongIntUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - int newValue = mappingFunction.applyAsInt(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public int computeIntIfPresentNonDefault(long key, LongIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1558,14 +1558,9 @@ public int computeIntIfPresent(long key, LongIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - int newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2IntRBTreeMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2IntRBTreeMap.java index be894be6..87b405fe 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2IntRBTreeMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2IntRBTreeMap.java @@ -454,34 +454,56 @@ public int computeInt(long key, LongIntUnaryOperator mappingFunction) { } @Override - public int computeIntNonDefault(long key, LongIntUnaryOperator mappingFunction) { + public int computeIntIfAbsent(long key, Long2IntFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + int newValue = mappingFunction.applyAsInt(key); put(key, newValue); return newValue; } - int newValue = mappingFunction.applyAsInt(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public int supplyIntIfAbsent(long key, IntSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + int newValue = valueProvider.getAsInt(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public int computeIntIfPresent(long key, LongIntUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + int newValue = mappingFunction.applyAsInt(key, entry.value); entry.value = newValue; return newValue; } @Override - public int computeIntIfAbsent(long key, Long2IntFunction mappingFunction) { + public int computeIntNonDefault(long key, LongIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + int newValue = mappingFunction.applyAsInt(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -502,18 +524,6 @@ public int computeIntIfAbsentNonDefault(long key, Long2IntFunction mappingFuncti return entry.value; } - @Override - public int supplyIntIfAbsent(long key, IntSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - int newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public int supplyIntIfAbsentNonDefault(long key, IntSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -532,16 +542,6 @@ public int supplyIntIfAbsentNonDefault(long key, IntSupplier valueProvider) { return entry.value; } - @Override - public int computeIntIfPresent(long key, LongIntUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - int newValue = mappingFunction.applyAsInt(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public int computeIntIfPresentNonDefault(long key, LongIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1621,14 +1621,9 @@ public int computeIntIfPresent(long key, LongIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - int newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2LongAVLTreeMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2LongAVLTreeMap.java index c4333030..d3f86717 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2LongAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2LongAVLTreeMap.java @@ -447,34 +447,56 @@ public long computeLong(long key, LongLongUnaryOperator mappingFunction) { } @Override - public long computeLongNonDefault(long key, LongLongUnaryOperator mappingFunction) { + public long computeLongIfAbsent(long key, LongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + long newValue = mappingFunction.applyAsLong(key); put(key, newValue); return newValue; } - long newValue = mappingFunction.applyAsLong(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public long supplyLongIfAbsent(long key, LongSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + long newValue = valueProvider.getAsLong(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public long computeLongIfPresent(long key, LongLongUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + long newValue = mappingFunction.applyAsLong(key, entry.value); entry.value = newValue; return newValue; } @Override - public long computeLongIfAbsent(long key, LongUnaryOperator mappingFunction) { + public long computeLongNonDefault(long key, LongLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + long newValue = mappingFunction.applyAsLong(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -495,18 +517,6 @@ public long computeLongIfAbsentNonDefault(long key, LongUnaryOperator mappingFun return entry.value; } - @Override - public long supplyLongIfAbsent(long key, LongSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - long newValue = valueProvider.getAsLong(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public long supplyLongIfAbsentNonDefault(long key, LongSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -525,16 +535,6 @@ public long supplyLongIfAbsentNonDefault(long key, LongSupplier valueProvider) { return entry.value; } - @Override - public long computeLongIfPresent(long key, LongLongUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - long newValue = mappingFunction.applyAsLong(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public long computeLongIfPresentNonDefault(long key, LongLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1550,14 +1550,9 @@ public long computeLongIfPresent(long key, LongLongUnaryOperator mappingFunction Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - long newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2LongRBTreeMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2LongRBTreeMap.java index c8e09e4f..737e9357 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2LongRBTreeMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2LongRBTreeMap.java @@ -446,34 +446,56 @@ public long computeLong(long key, LongLongUnaryOperator mappingFunction) { } @Override - public long computeLongNonDefault(long key, LongLongUnaryOperator mappingFunction) { + public long computeLongIfAbsent(long key, LongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + long newValue = mappingFunction.applyAsLong(key); put(key, newValue); return newValue; } - long newValue = mappingFunction.applyAsLong(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public long supplyLongIfAbsent(long key, LongSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + long newValue = valueProvider.getAsLong(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public long computeLongIfPresent(long key, LongLongUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + long newValue = mappingFunction.applyAsLong(key, entry.value); entry.value = newValue; return newValue; } @Override - public long computeLongIfAbsent(long key, LongUnaryOperator mappingFunction) { + public long computeLongNonDefault(long key, LongLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + long newValue = mappingFunction.applyAsLong(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -494,18 +516,6 @@ public long computeLongIfAbsentNonDefault(long key, LongUnaryOperator mappingFun return entry.value; } - @Override - public long supplyLongIfAbsent(long key, LongSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - long newValue = valueProvider.getAsLong(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public long supplyLongIfAbsentNonDefault(long key, LongSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -524,16 +534,6 @@ public long supplyLongIfAbsentNonDefault(long key, LongSupplier valueProvider) { return entry.value; } - @Override - public long computeLongIfPresent(long key, LongLongUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - long newValue = mappingFunction.applyAsLong(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public long computeLongIfPresentNonDefault(long key, LongLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1613,14 +1613,9 @@ public long computeLongIfPresent(long key, LongLongUnaryOperator mappingFunction Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - long newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2ObjectAVLTreeMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2ObjectAVLTreeMap.java index 44c8d6c9..e7d4b3d5 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2ObjectAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2ObjectAVLTreeMap.java @@ -395,25 +395,6 @@ public V compute(long key, LongObjectUnaryOperator mappingFunction) { return newValue; } - @Override - public V computeNonDefault(long key, LongObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) { - V newValue = mappingFunction.apply(key, getDefaultReturnValue()); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - put(key, newValue); - return newValue; - } - V newValue = mappingFunction.apply(key, entry.value); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; - } - @Override public V computeIfAbsent(long key, LongFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -432,24 +413,6 @@ public V computeIfAbsent(long key, LongFunction mappingFunction) { return entry.value; } - @Override - public V computeIfAbsentNonDefault(long key, LongFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) { - V newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - put(key, newValue); - return newValue; - } - if(Objects.equals(entry.value, getDefaultReturnValue())) { - V newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - entry.value = newValue; - } - return entry.value; - } - @Override public V supplyIfAbsent(long key, ObjectSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -468,24 +431,6 @@ public V supplyIfAbsent(long key, ObjectSupplier valueProvider) { return entry.value; } - @Override - public V supplyIfAbsentNonDefault(long key, ObjectSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - V newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - put(key, newValue); - return newValue; - } - if(Objects.equals(entry.value, getDefaultReturnValue())) { - V newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - entry.value = newValue; - } - return entry.value; - } - @Override public V computeIfPresent(long key, LongObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -500,20 +445,6 @@ public V computeIfPresent(long key, LongObjectUnaryOperator mappingFunction) return newValue; } - @Override - public V computeIfPresentNonDefault(long key, LongObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null || Objects.equals(entry.value, getDefaultReturnValue())) return getDefaultReturnValue(); - V newValue = mappingFunction.apply(key, entry.value); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; - } - @Override public V merge(long key, V value, ObjectObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2ObjectRBTreeMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2ObjectRBTreeMap.java index ecdf2e11..4ae07a43 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2ObjectRBTreeMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2ObjectRBTreeMap.java @@ -394,25 +394,6 @@ public V compute(long key, LongObjectUnaryOperator mappingFunction) { return newValue; } - @Override - public V computeNonDefault(long key, LongObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) { - V newValue = mappingFunction.apply(key, getDefaultReturnValue()); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - put(key, newValue); - return newValue; - } - V newValue = mappingFunction.apply(key, entry.value); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; - } - @Override public V computeIfAbsent(long key, LongFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -431,24 +412,6 @@ public V computeIfAbsent(long key, LongFunction mappingFunction) { return entry.value; } - @Override - public V computeIfAbsentNonDefault(long key, LongFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) { - V newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - put(key, newValue); - return newValue; - } - if(Objects.equals(entry.value, getDefaultReturnValue())) { - V newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - entry.value = newValue; - } - return entry.value; - } - @Override public V supplyIfAbsent(long key, ObjectSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -467,24 +430,6 @@ public V supplyIfAbsent(long key, ObjectSupplier valueProvider) { return entry.value; } - @Override - public V supplyIfAbsentNonDefault(long key, ObjectSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - V newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - put(key, newValue); - return newValue; - } - if(Objects.equals(entry.value, getDefaultReturnValue())) { - V newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - entry.value = newValue; - } - return entry.value; - } - @Override public V computeIfPresent(long key, LongObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -499,20 +444,6 @@ public V computeIfPresent(long key, LongObjectUnaryOperator mappingFunction) return newValue; } - @Override - public V computeIfPresentNonDefault(long key, LongObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null || Objects.equals(entry.value, getDefaultReturnValue())) return getDefaultReturnValue(); - V newValue = mappingFunction.apply(key, entry.value); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; - } - @Override public V merge(long key, V value, ObjectObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2ShortAVLTreeMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2ShortAVLTreeMap.java index 322a77de..b40812df 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2ShortAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2ShortAVLTreeMap.java @@ -455,34 +455,56 @@ public short computeShort(long key, LongShortUnaryOperator mappingFunction) { } @Override - public short computeShortNonDefault(long key, LongShortUnaryOperator mappingFunction) { + public short computeShortIfAbsent(long key, Long2ShortFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + short newValue = mappingFunction.applyAsShort(key); put(key, newValue); return newValue; } - short newValue = mappingFunction.applyAsShort(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public short supplyShortIfAbsent(long key, ShortSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + short newValue = valueProvider.getAsShort(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public short computeShortIfPresent(long key, LongShortUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + short newValue = mappingFunction.applyAsShort(key, entry.value); entry.value = newValue; return newValue; } @Override - public short computeShortIfAbsent(long key, Long2ShortFunction mappingFunction) { + public short computeShortNonDefault(long key, LongShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + short newValue = mappingFunction.applyAsShort(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -503,46 +525,24 @@ public short computeShortIfAbsentNonDefault(long key, Long2ShortFunction mapping return entry.value; } - @Override - public short supplyShortIfAbsent(long key, ShortSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - short newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public short supplyShortIfAbsentNonDefault(long key, ShortSupplier valueProvider) { Objects.requireNonNull(valueProvider); Node entry = findNode(key); if(entry == null) { - short newValue = valueProvider.getAsInt(); + short newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } if(entry.value == getDefaultReturnValue()) { - short newValue = valueProvider.getAsInt(); + short newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; entry.value = newValue; } return entry.value; } - @Override - public short computeShortIfPresent(long key, LongShortUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - short newValue = mappingFunction.applyAsShort(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public short computeShortIfPresentNonDefault(long key, LongShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1558,14 +1558,9 @@ public short computeShortIfPresent(long key, LongShortUnaryOperator mappingFunct Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - short newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2ShortRBTreeMap.java b/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2ShortRBTreeMap.java index 72b13b2f..80373e39 100644 --- a/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2ShortRBTreeMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/impl/tree/Long2ShortRBTreeMap.java @@ -454,34 +454,56 @@ public short computeShort(long key, LongShortUnaryOperator mappingFunction) { } @Override - public short computeShortNonDefault(long key, LongShortUnaryOperator mappingFunction) { + public short computeShortIfAbsent(long key, Long2ShortFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + short newValue = mappingFunction.applyAsShort(key); put(key, newValue); return newValue; } - short newValue = mappingFunction.applyAsShort(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public short supplyShortIfAbsent(long key, ShortSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + short newValue = valueProvider.getAsShort(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public short computeShortIfPresent(long key, LongShortUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + short newValue = mappingFunction.applyAsShort(key, entry.value); entry.value = newValue; return newValue; } @Override - public short computeShortIfAbsent(long key, Long2ShortFunction mappingFunction) { + public short computeShortNonDefault(long key, LongShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + short newValue = mappingFunction.applyAsShort(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -502,46 +524,24 @@ public short computeShortIfAbsentNonDefault(long key, Long2ShortFunction mapping return entry.value; } - @Override - public short supplyShortIfAbsent(long key, ShortSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - short newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public short supplyShortIfAbsentNonDefault(long key, ShortSupplier valueProvider) { Objects.requireNonNull(valueProvider); Node entry = findNode(key); if(entry == null) { - short newValue = valueProvider.getAsInt(); + short newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } if(entry.value == getDefaultReturnValue()) { - short newValue = valueProvider.getAsInt(); + short newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; entry.value = newValue; } return entry.value; } - @Override - public short computeShortIfPresent(long key, LongShortUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - short newValue = mappingFunction.applyAsShort(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public short computeShortIfPresentNonDefault(long key, LongShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1621,14 +1621,9 @@ public short computeShortIfPresent(long key, LongShortUnaryOperator mappingFunct Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - short newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/longs/maps/interfaces/Long2BooleanMap.java b/src/main/java/speiger/src/collections/longs/maps/interfaces/Long2BooleanMap.java index 480203b5..97f1e07e 100644 --- a/src/main/java/speiger/src/collections/longs/maps/interfaces/Long2BooleanMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/interfaces/Long2BooleanMap.java @@ -284,41 +284,51 @@ public default boolean remove(Object key, Object value) { */ public boolean computeBoolean(long key, LongBooleanUnaryOperator mappingFunction); /** - * A Type Specific compute method to reduce boxing/unboxing + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation + * @param mappingFunction the operator that should generate the value if not present + * @return the result of the computed value or present value */ - public boolean computeBooleanNonDefault(long key, LongBooleanUnaryOperator mappingFunction); + public boolean computeBooleanIfAbsent(long key, LongPredicate mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present + * @param valueProvider the value if not present * @return the result of the computed value or present value + */ + public boolean supplyBooleanIfAbsent(long key, BooleanSupplier valueProvider); + /** + * A Type Specific compute method to reduce boxing/unboxing + * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". + * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. + * @param key the key that should be computed + * @param mappingFunction the operator that should generate the value if present + * @return the result of the default return value or present value + * @note if not present then compute is not executed */ - public boolean computeBooleanIfAbsent(long key, LongPredicate mappingFunction); + public boolean computeBooleanIfPresent(long key, LongBooleanUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value + * @param mappingFunction the operator that should generate the value + * @return the result of the computation */ - public boolean computeBooleanIfAbsentNonDefault(long key, LongPredicate mappingFunction); + public boolean computeBooleanNonDefault(long key, LongBooleanUnaryOperator mappingFunction); /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param valueProvider the value if not present + * @param mappingFunction the operator that should generate the value if not present * @return the result of the computed value or present value - */ - public boolean supplyBooleanIfAbsent(long key, BooleanSupplier valueProvider); + */ + public boolean computeBooleanIfAbsentNonDefault(long key, LongPredicate mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -328,16 +338,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public boolean supplyBooleanIfAbsentNonDefault(long key, BooleanSupplier valueProvider); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public boolean computeBooleanIfPresent(long key, LongBooleanUnaryOperator mappingFunction); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/longs/maps/interfaces/Long2ByteMap.java b/src/main/java/speiger/src/collections/longs/maps/interfaces/Long2ByteMap.java index e16a131e..d059c04f 100644 --- a/src/main/java/speiger/src/collections/longs/maps/interfaces/Long2ByteMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/interfaces/Long2ByteMap.java @@ -309,41 +309,51 @@ public default boolean remove(Object key, Object value) { */ public byte computeByte(long key, LongByteUnaryOperator mappingFunction); /** - * A Type Specific compute method to reduce boxing/unboxing + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation + * @param mappingFunction the operator that should generate the value if not present + * @return the result of the computed value or present value */ - public byte computeByteNonDefault(long key, LongByteUnaryOperator mappingFunction); + public byte computeByteIfAbsent(long key, Long2ByteFunction mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present + * @param valueProvider the value if not present * @return the result of the computed value or present value + */ + public byte supplyByteIfAbsent(long key, ByteSupplier valueProvider); + /** + * A Type Specific compute method to reduce boxing/unboxing + * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". + * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. + * @param key the key that should be computed + * @param mappingFunction the operator that should generate the value if present + * @return the result of the default return value or present value + * @note if not present then compute is not executed */ - public byte computeByteIfAbsent(long key, Long2ByteFunction mappingFunction); + public byte computeByteIfPresent(long key, LongByteUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value + * @param mappingFunction the operator that should generate the value + * @return the result of the computation */ - public byte computeByteIfAbsentNonDefault(long key, Long2ByteFunction mappingFunction); + public byte computeByteNonDefault(long key, LongByteUnaryOperator mappingFunction); /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param valueProvider the value if not present + * @param mappingFunction the operator that should generate the value if not present * @return the result of the computed value or present value - */ - public byte supplyByteIfAbsent(long key, ByteSupplier valueProvider); + */ + public byte computeByteIfAbsentNonDefault(long key, Long2ByteFunction mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -353,16 +363,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public byte supplyByteIfAbsentNonDefault(long key, ByteSupplier valueProvider); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public byte computeByteIfPresent(long key, LongByteUnaryOperator mappingFunction); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/longs/maps/interfaces/Long2CharMap.java b/src/main/java/speiger/src/collections/longs/maps/interfaces/Long2CharMap.java index 17e59768..19796cb0 100644 --- a/src/main/java/speiger/src/collections/longs/maps/interfaces/Long2CharMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/interfaces/Long2CharMap.java @@ -309,41 +309,51 @@ public default boolean remove(Object key, Object value) { */ public char computeChar(long key, LongCharUnaryOperator mappingFunction); /** - * A Type Specific compute method to reduce boxing/unboxing + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation + * @param mappingFunction the operator that should generate the value if not present + * @return the result of the computed value or present value */ - public char computeCharNonDefault(long key, LongCharUnaryOperator mappingFunction); + public char computeCharIfAbsent(long key, Long2CharFunction mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present + * @param valueProvider the value if not present * @return the result of the computed value or present value + */ + public char supplyCharIfAbsent(long key, CharSupplier valueProvider); + /** + * A Type Specific compute method to reduce boxing/unboxing + * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". + * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. + * @param key the key that should be computed + * @param mappingFunction the operator that should generate the value if present + * @return the result of the default return value or present value + * @note if not present then compute is not executed */ - public char computeCharIfAbsent(long key, Long2CharFunction mappingFunction); + public char computeCharIfPresent(long key, LongCharUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value + * @param mappingFunction the operator that should generate the value + * @return the result of the computation */ - public char computeCharIfAbsentNonDefault(long key, Long2CharFunction mappingFunction); + public char computeCharNonDefault(long key, LongCharUnaryOperator mappingFunction); /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param valueProvider the value if not present + * @param mappingFunction the operator that should generate the value if not present * @return the result of the computed value or present value - */ - public char supplyCharIfAbsent(long key, CharSupplier valueProvider); + */ + public char computeCharIfAbsentNonDefault(long key, Long2CharFunction mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -353,16 +363,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public char supplyCharIfAbsentNonDefault(long key, CharSupplier valueProvider); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public char computeCharIfPresent(long key, LongCharUnaryOperator mappingFunction); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/longs/maps/interfaces/Long2DoubleMap.java b/src/main/java/speiger/src/collections/longs/maps/interfaces/Long2DoubleMap.java index 9a6bdfb9..59d3b70b 100644 --- a/src/main/java/speiger/src/collections/longs/maps/interfaces/Long2DoubleMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/interfaces/Long2DoubleMap.java @@ -309,41 +309,51 @@ public default boolean remove(Object key, Object value) { */ public double computeDouble(long key, LongDoubleUnaryOperator mappingFunction); /** - * A Type Specific compute method to reduce boxing/unboxing + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation + * @param mappingFunction the operator that should generate the value if not present + * @return the result of the computed value or present value */ - public double computeDoubleNonDefault(long key, LongDoubleUnaryOperator mappingFunction); + public double computeDoubleIfAbsent(long key, Long2DoubleFunction mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present + * @param valueProvider the value if not present * @return the result of the computed value or present value + */ + public double supplyDoubleIfAbsent(long key, DoubleSupplier valueProvider); + /** + * A Type Specific compute method to reduce boxing/unboxing + * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". + * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. + * @param key the key that should be computed + * @param mappingFunction the operator that should generate the value if present + * @return the result of the default return value or present value + * @note if not present then compute is not executed */ - public double computeDoubleIfAbsent(long key, Long2DoubleFunction mappingFunction); + public double computeDoubleIfPresent(long key, LongDoubleUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value + * @param mappingFunction the operator that should generate the value + * @return the result of the computation */ - public double computeDoubleIfAbsentNonDefault(long key, Long2DoubleFunction mappingFunction); + public double computeDoubleNonDefault(long key, LongDoubleUnaryOperator mappingFunction); /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param valueProvider the value if not present + * @param mappingFunction the operator that should generate the value if not present * @return the result of the computed value or present value - */ - public double supplyDoubleIfAbsent(long key, DoubleSupplier valueProvider); + */ + public double computeDoubleIfAbsentNonDefault(long key, Long2DoubleFunction mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -353,16 +363,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public double supplyDoubleIfAbsentNonDefault(long key, DoubleSupplier valueProvider); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public double computeDoubleIfPresent(long key, LongDoubleUnaryOperator mappingFunction); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/longs/maps/interfaces/Long2FloatMap.java b/src/main/java/speiger/src/collections/longs/maps/interfaces/Long2FloatMap.java index d89c802d..fc653cbf 100644 --- a/src/main/java/speiger/src/collections/longs/maps/interfaces/Long2FloatMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/interfaces/Long2FloatMap.java @@ -309,41 +309,51 @@ public default boolean remove(Object key, Object value) { */ public float computeFloat(long key, LongFloatUnaryOperator mappingFunction); /** - * A Type Specific compute method to reduce boxing/unboxing + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation + * @param mappingFunction the operator that should generate the value if not present + * @return the result of the computed value or present value */ - public float computeFloatNonDefault(long key, LongFloatUnaryOperator mappingFunction); + public float computeFloatIfAbsent(long key, Long2FloatFunction mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present + * @param valueProvider the value if not present * @return the result of the computed value or present value + */ + public float supplyFloatIfAbsent(long key, FloatSupplier valueProvider); + /** + * A Type Specific compute method to reduce boxing/unboxing + * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". + * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. + * @param key the key that should be computed + * @param mappingFunction the operator that should generate the value if present + * @return the result of the default return value or present value + * @note if not present then compute is not executed */ - public float computeFloatIfAbsent(long key, Long2FloatFunction mappingFunction); + public float computeFloatIfPresent(long key, LongFloatUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value + * @param mappingFunction the operator that should generate the value + * @return the result of the computation */ - public float computeFloatIfAbsentNonDefault(long key, Long2FloatFunction mappingFunction); + public float computeFloatNonDefault(long key, LongFloatUnaryOperator mappingFunction); /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param valueProvider the value if not present + * @param mappingFunction the operator that should generate the value if not present * @return the result of the computed value or present value - */ - public float supplyFloatIfAbsent(long key, FloatSupplier valueProvider); + */ + public float computeFloatIfAbsentNonDefault(long key, Long2FloatFunction mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -353,16 +363,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public float supplyFloatIfAbsentNonDefault(long key, FloatSupplier valueProvider); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public float computeFloatIfPresent(long key, LongFloatUnaryOperator mappingFunction); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/longs/maps/interfaces/Long2IntMap.java b/src/main/java/speiger/src/collections/longs/maps/interfaces/Long2IntMap.java index a57ddce2..4e20d93d 100644 --- a/src/main/java/speiger/src/collections/longs/maps/interfaces/Long2IntMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/interfaces/Long2IntMap.java @@ -309,41 +309,51 @@ public default boolean remove(Object key, Object value) { */ public int computeInt(long key, LongIntUnaryOperator mappingFunction); /** - * A Type Specific compute method to reduce boxing/unboxing + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation + * @param mappingFunction the operator that should generate the value if not present + * @return the result of the computed value or present value */ - public int computeIntNonDefault(long key, LongIntUnaryOperator mappingFunction); + public int computeIntIfAbsent(long key, Long2IntFunction mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present + * @param valueProvider the value if not present * @return the result of the computed value or present value + */ + public int supplyIntIfAbsent(long key, IntSupplier valueProvider); + /** + * A Type Specific compute method to reduce boxing/unboxing + * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". + * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. + * @param key the key that should be computed + * @param mappingFunction the operator that should generate the value if present + * @return the result of the default return value or present value + * @note if not present then compute is not executed */ - public int computeIntIfAbsent(long key, Long2IntFunction mappingFunction); + public int computeIntIfPresent(long key, LongIntUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value + * @param mappingFunction the operator that should generate the value + * @return the result of the computation */ - public int computeIntIfAbsentNonDefault(long key, Long2IntFunction mappingFunction); + public int computeIntNonDefault(long key, LongIntUnaryOperator mappingFunction); /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param valueProvider the value if not present + * @param mappingFunction the operator that should generate the value if not present * @return the result of the computed value or present value - */ - public int supplyIntIfAbsent(long key, IntSupplier valueProvider); + */ + public int computeIntIfAbsentNonDefault(long key, Long2IntFunction mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -353,16 +363,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public int supplyIntIfAbsentNonDefault(long key, IntSupplier valueProvider); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public int computeIntIfPresent(long key, LongIntUnaryOperator mappingFunction); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/longs/maps/interfaces/Long2LongMap.java b/src/main/java/speiger/src/collections/longs/maps/interfaces/Long2LongMap.java index 87a663aa..e718d46a 100644 --- a/src/main/java/speiger/src/collections/longs/maps/interfaces/Long2LongMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/interfaces/Long2LongMap.java @@ -308,41 +308,51 @@ public default boolean remove(Object key, Object value) { */ public long computeLong(long key, LongLongUnaryOperator mappingFunction); /** - * A Type Specific compute method to reduce boxing/unboxing + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation + * @param mappingFunction the operator that should generate the value if not present + * @return the result of the computed value or present value */ - public long computeLongNonDefault(long key, LongLongUnaryOperator mappingFunction); + public long computeLongIfAbsent(long key, LongUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present + * @param valueProvider the value if not present * @return the result of the computed value or present value + */ + public long supplyLongIfAbsent(long key, LongSupplier valueProvider); + /** + * A Type Specific compute method to reduce boxing/unboxing + * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". + * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. + * @param key the key that should be computed + * @param mappingFunction the operator that should generate the value if present + * @return the result of the default return value or present value + * @note if not present then compute is not executed */ - public long computeLongIfAbsent(long key, LongUnaryOperator mappingFunction); + public long computeLongIfPresent(long key, LongLongUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value + * @param mappingFunction the operator that should generate the value + * @return the result of the computation */ - public long computeLongIfAbsentNonDefault(long key, LongUnaryOperator mappingFunction); + public long computeLongNonDefault(long key, LongLongUnaryOperator mappingFunction); /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param valueProvider the value if not present + * @param mappingFunction the operator that should generate the value if not present * @return the result of the computed value or present value - */ - public long supplyLongIfAbsent(long key, LongSupplier valueProvider); + */ + public long computeLongIfAbsentNonDefault(long key, LongUnaryOperator mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -352,16 +362,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public long supplyLongIfAbsentNonDefault(long key, LongSupplier valueProvider); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public long computeLongIfPresent(long key, LongLongUnaryOperator mappingFunction); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/longs/maps/interfaces/Long2ObjectMap.java b/src/main/java/speiger/src/collections/longs/maps/interfaces/Long2ObjectMap.java index 7a8f87d2..72488400 100644 --- a/src/main/java/speiger/src/collections/longs/maps/interfaces/Long2ObjectMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/interfaces/Long2ObjectMap.java @@ -266,15 +266,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computation */ public V compute(long key, LongObjectUnaryOperator mappingFunction); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation - */ - public V computeNonDefault(long key, LongObjectUnaryOperator mappingFunction); /** * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -284,15 +275,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public V computeIfAbsent(long key, LongFunction mappingFunction); - /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value - */ - public V computeIfAbsentNonDefault(long key, LongFunction mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -302,15 +284,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public V supplyIfAbsent(long key, ObjectSupplier valueProvider); - /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param valueProvider the value if not present - * @return the result of the computed value or present value - */ - public V supplyIfAbsentNonDefault(long key, ObjectSupplier valueProvider); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -321,16 +294,6 @@ public default boolean remove(Object key, Object value) { * @note if not present then compute is not executed */ public V computeIfPresent(long key, LongObjectUnaryOperator mappingFunction); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public V computeIfPresentNonDefault(long key, LongObjectUnaryOperator mappingFunction); /** * A Type Specific merge method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/longs/maps/interfaces/Long2ShortMap.java b/src/main/java/speiger/src/collections/longs/maps/interfaces/Long2ShortMap.java index 1a36b6ef..012d79e5 100644 --- a/src/main/java/speiger/src/collections/longs/maps/interfaces/Long2ShortMap.java +++ b/src/main/java/speiger/src/collections/longs/maps/interfaces/Long2ShortMap.java @@ -309,41 +309,51 @@ public default boolean remove(Object key, Object value) { */ public short computeShort(long key, LongShortUnaryOperator mappingFunction); /** - * A Type Specific compute method to reduce boxing/unboxing + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation + * @param mappingFunction the operator that should generate the value if not present + * @return the result of the computed value or present value */ - public short computeShortNonDefault(long key, LongShortUnaryOperator mappingFunction); + public short computeShortIfAbsent(long key, Long2ShortFunction mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present + * @param valueProvider the value if not present * @return the result of the computed value or present value + */ + public short supplyShortIfAbsent(long key, ShortSupplier valueProvider); + /** + * A Type Specific compute method to reduce boxing/unboxing + * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". + * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. + * @param key the key that should be computed + * @param mappingFunction the operator that should generate the value if present + * @return the result of the default return value or present value + * @note if not present then compute is not executed */ - public short computeShortIfAbsent(long key, Long2ShortFunction mappingFunction); + public short computeShortIfPresent(long key, LongShortUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value + * @param mappingFunction the operator that should generate the value + * @return the result of the computation */ - public short computeShortIfAbsentNonDefault(long key, Long2ShortFunction mappingFunction); + public short computeShortNonDefault(long key, LongShortUnaryOperator mappingFunction); /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param valueProvider the value if not present + * @param mappingFunction the operator that should generate the value if not present * @return the result of the computed value or present value - */ - public short supplyShortIfAbsent(long key, ShortSupplier valueProvider); + */ + public short computeShortIfAbsentNonDefault(long key, Long2ShortFunction mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -353,16 +363,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public short supplyShortIfAbsentNonDefault(long key, ShortSupplier valueProvider); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public short computeShortIfPresent(long key, LongShortUnaryOperator mappingFunction); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/longs/queues/LongArrayFIFOQueue.java b/src/main/java/speiger/src/collections/longs/queues/LongArrayFIFOQueue.java index cfaba7fb..6dbb1475 100644 --- a/src/main/java/speiger/src/collections/longs/queues/LongArrayFIFOQueue.java +++ b/src/main/java/speiger/src/collections/longs/queues/LongArrayFIFOQueue.java @@ -146,6 +146,15 @@ public long peek(int index) { return index >= array.length ? array[index-array.length] : array[index]; } + @Override + public boolean contains(long e) { + if(first == last) return false; + for(int i = 0,m=size();i iterator, int repeats return new RepeatingIterator(wrap(iterator), repeats); } + /** + * A Helper function that creates a infinitely looping iterator + * @param iterator that should be looping infinitely + * @return a infinitely looping iterator + */ + public static LongIterator infinite(LongIterator iterator) { + return new InfiniteIterator(iterator); + } + + /** + * A Helper function that creates a infinitely looping iterator from a Java Iterator + * @param iterator that should be looping infinitely + * @return a infinitely looping iterator + */ + public static LongIterator infinite(Iterator iterator) { + return new InfiniteIterator(wrap(iterator)); + } + /** * A Helper function that hard limits the Iterator to a specific size * @param iterator that should be limited @@ -841,6 +862,40 @@ public T next() { } } + private static class InfiniteIterator implements LongIterator + { + LongIterator iter; + CollectionWrapper looper = LongCollections.wrapper(); + int index = 0; + + public InfiniteIterator(LongIterator iter) { + this.iter = iter; + } + + @Override + public boolean hasNext() { + return true; + } + + @Override + public long nextLong() { + if(iter != null) { + if(iter.hasNext()) { + long value = iter.nextLong(); + looper.add(value); + return value; + } + else iter = null; + } + return looper.getLong((index++) % looper.size()); + } + + @Override + public void forEachRemaining(LongConsumer action) { throw new UnsupportedOperationException("This is a instant deadlock, so unsupported"); } + public void forEachRemaining(Consumer action) { throw new UnsupportedOperationException("This is a instant deadlock, so unsupported"); } + public void forEachRemaining(E input, ObjectLongConsumer action) { throw new UnsupportedOperationException("This is a instant deadlock, so unsupported"); } + } + private static class RepeatingIterator implements LongIterator { final int repeats; diff --git a/src/main/java/speiger/src/collections/longs/utils/LongLists.java b/src/main/java/speiger/src/collections/longs/utils/LongLists.java index efcb5a78..7602481d 100644 --- a/src/main/java/speiger/src/collections/longs/utils/LongLists.java +++ b/src/main/java/speiger/src/collections/longs/utils/LongLists.java @@ -12,6 +12,7 @@ import speiger.src.collections.longs.functions.LongConsumer; import speiger.src.collections.longs.lists.AbstractLongList; import speiger.src.collections.longs.lists.LongList; +import speiger.src.collections.ints.lists.IntList; import speiger.src.collections.longs.lists.LongListIterator; import speiger.src.collections.utils.SanityChecks; @@ -317,6 +318,16 @@ public LongListIterator listIterator(int index) { return l.listIterator(index); } + @Override + public LongListIterator indexedIterator(int...indecies) { + return l.indexedIterator(indecies); + } + + @Override + public LongListIterator indexedIterator(IntList indecies) { + return l.indexedIterator(indecies); + } + @Override public LongList subList(int from, int to) { return LongLists.synchronize(l.subList(from, to)); @@ -426,6 +437,16 @@ public LongListIterator listIterator(int index) { return LongIterators.unmodifiable(l.listIterator(index)); } + @Override + public LongListIterator indexedIterator(int...indecies) { + return LongIterators.unmodifiable(l.indexedIterator(indecies)); + } + + @Override + public LongListIterator indexedIterator(IntList indecies) { + return LongIterators.unmodifiable(l.indexedIterator(indecies)); + } + @Override public LongList subList(int from, int to) { return LongLists.unmodifiable(l.subList(from, to)); @@ -514,6 +535,16 @@ public LongListIterator listIterator(int index) { return LongIterators.empty(); } + @Override + public LongListIterator indexedIterator(int...indecies) { + return LongIterators.empty(); + } + + @Override + public LongListIterator indexedIterator(IntList indecies) { + return LongIterators.empty(); + } + @Override public int hashCode() { return 1; } diff --git a/src/main/java/speiger/src/collections/longs/utils/LongPriorityQueues.java b/src/main/java/speiger/src/collections/longs/utils/LongPriorityQueues.java index 622a5a57..c739a1e2 100644 --- a/src/main/java/speiger/src/collections/longs/utils/LongPriorityQueues.java +++ b/src/main/java/speiger/src/collections/longs/utils/LongPriorityQueues.java @@ -89,6 +89,8 @@ protected SynchronizedPriorityQueue(LongPriorityQueue queue, Object mutex) { @Override public long peek(int index) { synchronized(mutex) { return queue.peek(index); } } @Override + public boolean contains(long e) { synchronized(mutex) { return queue.contains(e); } } + @Override public boolean removeFirst(long e) { synchronized(mutex) { return queue.removeFirst(e); } } @Override public boolean removeLast(long e) { synchronized(mutex) { return queue.removeLast(e); } } diff --git a/src/main/java/speiger/src/collections/longs/utils/maps/Long2BooleanMaps.java b/src/main/java/speiger/src/collections/longs/utils/maps/Long2BooleanMaps.java index 2c2d1c39..37d36419 100644 --- a/src/main/java/speiger/src/collections/longs/utils/maps/Long2BooleanMaps.java +++ b/src/main/java/speiger/src/collections/longs/utils/maps/Long2BooleanMaps.java @@ -246,18 +246,18 @@ public static class SingletonMap extends AbstractLong2BooleanMap { @Override public boolean computeBoolean(long key, LongBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanNonDefault(long key, LongBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean computeBooleanIfAbsent(long key, LongPredicate mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanIfAbsentNonDefault(long key, LongPredicate mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean computeBooleanIfPresent(long key, LongBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanIfPresentNonDefault(long key, LongBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean supplyBooleanIfAbsent(long key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public boolean computeBooleanNonDefault(long key, LongBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public boolean computeBooleanIfAbsentNonDefault(long key, LongPredicate mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public boolean computeBooleanIfPresentNonDefault(long key, LongBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public boolean supplyBooleanIfAbsentNonDefault(long key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public boolean mergeBoolean(long key, boolean value, BooleanBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -304,18 +304,18 @@ public static class EmptyMap extends AbstractLong2BooleanMap { @Override public boolean computeBoolean(long key, LongBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanNonDefault(long key, LongBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean computeBooleanIfAbsent(long key, LongPredicate mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanIfAbsentNonDefault(long key, LongPredicate mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean computeBooleanIfPresent(long key, LongBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanIfPresentNonDefault(long key, LongBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean supplyBooleanIfAbsent(long key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public boolean computeBooleanNonDefault(long key, LongBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public boolean computeBooleanIfAbsentNonDefault(long key, LongPredicate mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public boolean computeBooleanIfPresentNonDefault(long key, LongBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public boolean supplyBooleanIfAbsentNonDefault(long key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public boolean mergeBoolean(long key, boolean value, BooleanBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -535,18 +535,18 @@ public boolean get(long key) { @Override public boolean computeBoolean(long key, LongBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanNonDefault(long key, LongBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean computeBooleanIfAbsent(long key, LongPredicate mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanIfAbsentNonDefault(long key, LongPredicate mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean computeBooleanIfPresent(long key, LongBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanIfPresentNonDefault(long key, LongBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean supplyBooleanIfAbsent(long key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public boolean computeBooleanNonDefault(long key, LongBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public boolean computeBooleanIfAbsentNonDefault(long key, LongPredicate mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public boolean computeBooleanIfPresentNonDefault(long key, LongBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public boolean supplyBooleanIfAbsentNonDefault(long key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public boolean mergeBoolean(long key, boolean value, BooleanBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -938,18 +938,18 @@ public AbstractLong2BooleanMap setDefaultReturnValue(boolean v) { @Override public boolean computeBoolean(long key, LongBooleanUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeBoolean(key, mappingFunction); } } @Override - public boolean computeBooleanNonDefault(long key, LongBooleanUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeBooleanNonDefault(key, mappingFunction); } } - @Override public boolean computeBooleanIfAbsent(long key, LongPredicate mappingFunction) { synchronized(mutex) { return map.computeBooleanIfAbsent(key, mappingFunction); } } @Override - public boolean computeBooleanIfAbsentNonDefault(long key, LongPredicate mappingFunction) { synchronized(mutex) { return map.computeBooleanIfAbsentNonDefault(key, mappingFunction); } } - @Override public boolean computeBooleanIfPresent(long key, LongBooleanUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeBooleanIfPresent(key, mappingFunction); } } @Override - public boolean computeBooleanIfPresentNonDefault(long key, LongBooleanUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeBooleanIfPresentNonDefault(key, mappingFunction); } } - @Override public boolean supplyBooleanIfAbsent(long key, BooleanSupplier valueProvider) { synchronized(mutex) { return map.supplyBooleanIfAbsent(key, valueProvider); } } @Override + public boolean computeBooleanNonDefault(long key, LongBooleanUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeBooleanNonDefault(key, mappingFunction); } } + @Override + public boolean computeBooleanIfAbsentNonDefault(long key, LongPredicate mappingFunction) { synchronized(mutex) { return map.computeBooleanIfAbsentNonDefault(key, mappingFunction); } } + @Override + public boolean computeBooleanIfPresentNonDefault(long key, LongBooleanUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeBooleanIfPresentNonDefault(key, mappingFunction); } } + @Override public boolean supplyBooleanIfAbsentNonDefault(long key, BooleanSupplier valueProvider) { synchronized(mutex) { return map.supplyBooleanIfAbsentNonDefault(key, valueProvider); } } @Override public boolean mergeBoolean(long key, boolean value, BooleanBooleanUnaryOperator mappingFunction) { synchronized(mutex) { return map.mergeBoolean(key, value, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/longs/utils/maps/Long2ByteMaps.java b/src/main/java/speiger/src/collections/longs/utils/maps/Long2ByteMaps.java index c2271a49..23d163a3 100644 --- a/src/main/java/speiger/src/collections/longs/utils/maps/Long2ByteMaps.java +++ b/src/main/java/speiger/src/collections/longs/utils/maps/Long2ByteMaps.java @@ -250,18 +250,18 @@ public static class SingletonMap extends AbstractLong2ByteMap { @Override public byte computeByte(long key, LongByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteNonDefault(long key, LongByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte computeByteIfAbsent(long key, Long2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteIfAbsentNonDefault(long key, Long2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte computeByteIfPresent(long key, LongByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteIfPresentNonDefault(long key, LongByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte supplyByteIfAbsent(long key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public byte computeByteNonDefault(long key, LongByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public byte computeByteIfAbsentNonDefault(long key, Long2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public byte computeByteIfPresentNonDefault(long key, LongByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public byte supplyByteIfAbsentNonDefault(long key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public byte mergeByte(long key, byte value, ByteByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -312,18 +312,18 @@ public static class EmptyMap extends AbstractLong2ByteMap { @Override public byte computeByte(long key, LongByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteNonDefault(long key, LongByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte computeByteIfAbsent(long key, Long2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteIfAbsentNonDefault(long key, Long2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte computeByteIfPresent(long key, LongByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteIfPresentNonDefault(long key, LongByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte supplyByteIfAbsent(long key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public byte computeByteNonDefault(long key, LongByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public byte computeByteIfAbsentNonDefault(long key, Long2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public byte computeByteIfPresentNonDefault(long key, LongByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public byte supplyByteIfAbsentNonDefault(long key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public byte mergeByte(long key, byte value, ByteByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -547,18 +547,18 @@ public byte get(long key) { @Override public byte computeByte(long key, LongByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteNonDefault(long key, LongByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte computeByteIfAbsent(long key, Long2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteIfAbsentNonDefault(long key, Long2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte computeByteIfPresent(long key, LongByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteIfPresentNonDefault(long key, LongByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte supplyByteIfAbsent(long key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public byte computeByteNonDefault(long key, LongByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public byte computeByteIfAbsentNonDefault(long key, Long2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public byte computeByteIfPresentNonDefault(long key, LongByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public byte supplyByteIfAbsentNonDefault(long key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public byte mergeByte(long key, byte value, ByteByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -955,18 +955,18 @@ public AbstractLong2ByteMap setDefaultReturnValue(byte v) { @Override public byte computeByte(long key, LongByteUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeByte(key, mappingFunction); } } @Override - public byte computeByteNonDefault(long key, LongByteUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeByteNonDefault(key, mappingFunction); } } - @Override public byte computeByteIfAbsent(long key, Long2ByteFunction mappingFunction) { synchronized(mutex) { return map.computeByteIfAbsent(key, mappingFunction); } } @Override - public byte computeByteIfAbsentNonDefault(long key, Long2ByteFunction mappingFunction) { synchronized(mutex) { return map.computeByteIfAbsentNonDefault(key, mappingFunction); } } - @Override public byte computeByteIfPresent(long key, LongByteUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeByteIfPresent(key, mappingFunction); } } @Override - public byte computeByteIfPresentNonDefault(long key, LongByteUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeByteIfPresentNonDefault(key, mappingFunction); } } - @Override public byte supplyByteIfAbsent(long key, ByteSupplier valueProvider) { synchronized(mutex) { return map.supplyByteIfAbsent(key, valueProvider); } } @Override + public byte computeByteNonDefault(long key, LongByteUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeByteNonDefault(key, mappingFunction); } } + @Override + public byte computeByteIfAbsentNonDefault(long key, Long2ByteFunction mappingFunction) { synchronized(mutex) { return map.computeByteIfAbsentNonDefault(key, mappingFunction); } } + @Override + public byte computeByteIfPresentNonDefault(long key, LongByteUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeByteIfPresentNonDefault(key, mappingFunction); } } + @Override public byte supplyByteIfAbsentNonDefault(long key, ByteSupplier valueProvider) { synchronized(mutex) { return map.supplyByteIfAbsentNonDefault(key, valueProvider); } } @Override public byte mergeByte(long key, byte value, ByteByteUnaryOperator mappingFunction) { synchronized(mutex) { return map.mergeByte(key, value, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/longs/utils/maps/Long2CharMaps.java b/src/main/java/speiger/src/collections/longs/utils/maps/Long2CharMaps.java index 3d6de41e..145d798f 100644 --- a/src/main/java/speiger/src/collections/longs/utils/maps/Long2CharMaps.java +++ b/src/main/java/speiger/src/collections/longs/utils/maps/Long2CharMaps.java @@ -250,18 +250,18 @@ public static class SingletonMap extends AbstractLong2CharMap { @Override public char computeChar(long key, LongCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharNonDefault(long key, LongCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char computeCharIfAbsent(long key, Long2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharIfAbsentNonDefault(long key, Long2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char computeCharIfPresent(long key, LongCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharIfPresentNonDefault(long key, LongCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char supplyCharIfAbsent(long key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public char computeCharNonDefault(long key, LongCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public char computeCharIfAbsentNonDefault(long key, Long2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public char computeCharIfPresentNonDefault(long key, LongCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public char supplyCharIfAbsentNonDefault(long key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public char mergeChar(long key, char value, CharCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -312,18 +312,18 @@ public static class EmptyMap extends AbstractLong2CharMap { @Override public char computeChar(long key, LongCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharNonDefault(long key, LongCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char computeCharIfAbsent(long key, Long2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharIfAbsentNonDefault(long key, Long2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char computeCharIfPresent(long key, LongCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharIfPresentNonDefault(long key, LongCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char supplyCharIfAbsent(long key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public char computeCharNonDefault(long key, LongCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public char computeCharIfAbsentNonDefault(long key, Long2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public char computeCharIfPresentNonDefault(long key, LongCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public char supplyCharIfAbsentNonDefault(long key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public char mergeChar(long key, char value, CharCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -547,18 +547,18 @@ public char get(long key) { @Override public char computeChar(long key, LongCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharNonDefault(long key, LongCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char computeCharIfAbsent(long key, Long2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharIfAbsentNonDefault(long key, Long2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char computeCharIfPresent(long key, LongCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharIfPresentNonDefault(long key, LongCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char supplyCharIfAbsent(long key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public char computeCharNonDefault(long key, LongCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public char computeCharIfAbsentNonDefault(long key, Long2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public char computeCharIfPresentNonDefault(long key, LongCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public char supplyCharIfAbsentNonDefault(long key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public char mergeChar(long key, char value, CharCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -955,18 +955,18 @@ public AbstractLong2CharMap setDefaultReturnValue(char v) { @Override public char computeChar(long key, LongCharUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeChar(key, mappingFunction); } } @Override - public char computeCharNonDefault(long key, LongCharUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeCharNonDefault(key, mappingFunction); } } - @Override public char computeCharIfAbsent(long key, Long2CharFunction mappingFunction) { synchronized(mutex) { return map.computeCharIfAbsent(key, mappingFunction); } } @Override - public char computeCharIfAbsentNonDefault(long key, Long2CharFunction mappingFunction) { synchronized(mutex) { return map.computeCharIfAbsentNonDefault(key, mappingFunction); } } - @Override public char computeCharIfPresent(long key, LongCharUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeCharIfPresent(key, mappingFunction); } } @Override - public char computeCharIfPresentNonDefault(long key, LongCharUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeCharIfPresentNonDefault(key, mappingFunction); } } - @Override public char supplyCharIfAbsent(long key, CharSupplier valueProvider) { synchronized(mutex) { return map.supplyCharIfAbsent(key, valueProvider); } } @Override + public char computeCharNonDefault(long key, LongCharUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeCharNonDefault(key, mappingFunction); } } + @Override + public char computeCharIfAbsentNonDefault(long key, Long2CharFunction mappingFunction) { synchronized(mutex) { return map.computeCharIfAbsentNonDefault(key, mappingFunction); } } + @Override + public char computeCharIfPresentNonDefault(long key, LongCharUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeCharIfPresentNonDefault(key, mappingFunction); } } + @Override public char supplyCharIfAbsentNonDefault(long key, CharSupplier valueProvider) { synchronized(mutex) { return map.supplyCharIfAbsentNonDefault(key, valueProvider); } } @Override public char mergeChar(long key, char value, CharCharUnaryOperator mappingFunction) { synchronized(mutex) { return map.mergeChar(key, value, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/longs/utils/maps/Long2DoubleMaps.java b/src/main/java/speiger/src/collections/longs/utils/maps/Long2DoubleMaps.java index f9e518ca..45c1ab9b 100644 --- a/src/main/java/speiger/src/collections/longs/utils/maps/Long2DoubleMaps.java +++ b/src/main/java/speiger/src/collections/longs/utils/maps/Long2DoubleMaps.java @@ -250,18 +250,18 @@ public static class SingletonMap extends AbstractLong2DoubleMap { @Override public double computeDouble(long key, LongDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleNonDefault(long key, LongDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double computeDoubleIfAbsent(long key, Long2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleIfAbsentNonDefault(long key, Long2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double computeDoubleIfPresent(long key, LongDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleIfPresentNonDefault(long key, LongDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double supplyDoubleIfAbsent(long key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public double computeDoubleNonDefault(long key, LongDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public double computeDoubleIfAbsentNonDefault(long key, Long2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public double computeDoubleIfPresentNonDefault(long key, LongDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public double supplyDoubleIfAbsentNonDefault(long key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public double mergeDouble(long key, double value, DoubleDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -312,18 +312,18 @@ public static class EmptyMap extends AbstractLong2DoubleMap { @Override public double computeDouble(long key, LongDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleNonDefault(long key, LongDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double computeDoubleIfAbsent(long key, Long2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleIfAbsentNonDefault(long key, Long2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double computeDoubleIfPresent(long key, LongDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleIfPresentNonDefault(long key, LongDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double supplyDoubleIfAbsent(long key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public double computeDoubleNonDefault(long key, LongDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public double computeDoubleIfAbsentNonDefault(long key, Long2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public double computeDoubleIfPresentNonDefault(long key, LongDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public double supplyDoubleIfAbsentNonDefault(long key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public double mergeDouble(long key, double value, DoubleDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -547,18 +547,18 @@ public double get(long key) { @Override public double computeDouble(long key, LongDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleNonDefault(long key, LongDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double computeDoubleIfAbsent(long key, Long2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleIfAbsentNonDefault(long key, Long2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double computeDoubleIfPresent(long key, LongDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleIfPresentNonDefault(long key, LongDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double supplyDoubleIfAbsent(long key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public double computeDoubleNonDefault(long key, LongDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public double computeDoubleIfAbsentNonDefault(long key, Long2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public double computeDoubleIfPresentNonDefault(long key, LongDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public double supplyDoubleIfAbsentNonDefault(long key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public double mergeDouble(long key, double value, DoubleDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -955,18 +955,18 @@ public AbstractLong2DoubleMap setDefaultReturnValue(double v) { @Override public double computeDouble(long key, LongDoubleUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeDouble(key, mappingFunction); } } @Override - public double computeDoubleNonDefault(long key, LongDoubleUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeDoubleNonDefault(key, mappingFunction); } } - @Override public double computeDoubleIfAbsent(long key, Long2DoubleFunction mappingFunction) { synchronized(mutex) { return map.computeDoubleIfAbsent(key, mappingFunction); } } @Override - public double computeDoubleIfAbsentNonDefault(long key, Long2DoubleFunction mappingFunction) { synchronized(mutex) { return map.computeDoubleIfAbsentNonDefault(key, mappingFunction); } } - @Override public double computeDoubleIfPresent(long key, LongDoubleUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeDoubleIfPresent(key, mappingFunction); } } @Override - public double computeDoubleIfPresentNonDefault(long key, LongDoubleUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeDoubleIfPresentNonDefault(key, mappingFunction); } } - @Override public double supplyDoubleIfAbsent(long key, DoubleSupplier valueProvider) { synchronized(mutex) { return map.supplyDoubleIfAbsent(key, valueProvider); } } @Override + public double computeDoubleNonDefault(long key, LongDoubleUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeDoubleNonDefault(key, mappingFunction); } } + @Override + public double computeDoubleIfAbsentNonDefault(long key, Long2DoubleFunction mappingFunction) { synchronized(mutex) { return map.computeDoubleIfAbsentNonDefault(key, mappingFunction); } } + @Override + public double computeDoubleIfPresentNonDefault(long key, LongDoubleUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeDoubleIfPresentNonDefault(key, mappingFunction); } } + @Override public double supplyDoubleIfAbsentNonDefault(long key, DoubleSupplier valueProvider) { synchronized(mutex) { return map.supplyDoubleIfAbsentNonDefault(key, valueProvider); } } @Override public double mergeDouble(long key, double value, DoubleDoubleUnaryOperator mappingFunction) { synchronized(mutex) { return map.mergeDouble(key, value, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/longs/utils/maps/Long2FloatMaps.java b/src/main/java/speiger/src/collections/longs/utils/maps/Long2FloatMaps.java index 66e52118..9f28f22d 100644 --- a/src/main/java/speiger/src/collections/longs/utils/maps/Long2FloatMaps.java +++ b/src/main/java/speiger/src/collections/longs/utils/maps/Long2FloatMaps.java @@ -250,18 +250,18 @@ public static class SingletonMap extends AbstractLong2FloatMap { @Override public float computeFloat(long key, LongFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatNonDefault(long key, LongFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float computeFloatIfAbsent(long key, Long2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatIfAbsentNonDefault(long key, Long2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float computeFloatIfPresent(long key, LongFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatIfPresentNonDefault(long key, LongFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float supplyFloatIfAbsent(long key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public float computeFloatNonDefault(long key, LongFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public float computeFloatIfAbsentNonDefault(long key, Long2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public float computeFloatIfPresentNonDefault(long key, LongFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public float supplyFloatIfAbsentNonDefault(long key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public float mergeFloat(long key, float value, FloatFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -312,18 +312,18 @@ public static class EmptyMap extends AbstractLong2FloatMap { @Override public float computeFloat(long key, LongFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatNonDefault(long key, LongFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float computeFloatIfAbsent(long key, Long2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatIfAbsentNonDefault(long key, Long2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float computeFloatIfPresent(long key, LongFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatIfPresentNonDefault(long key, LongFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float supplyFloatIfAbsent(long key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public float computeFloatNonDefault(long key, LongFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public float computeFloatIfAbsentNonDefault(long key, Long2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public float computeFloatIfPresentNonDefault(long key, LongFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public float supplyFloatIfAbsentNonDefault(long key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public float mergeFloat(long key, float value, FloatFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -547,18 +547,18 @@ public float get(long key) { @Override public float computeFloat(long key, LongFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatNonDefault(long key, LongFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float computeFloatIfAbsent(long key, Long2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatIfAbsentNonDefault(long key, Long2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float computeFloatIfPresent(long key, LongFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatIfPresentNonDefault(long key, LongFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float supplyFloatIfAbsent(long key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public float computeFloatNonDefault(long key, LongFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public float computeFloatIfAbsentNonDefault(long key, Long2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public float computeFloatIfPresentNonDefault(long key, LongFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public float supplyFloatIfAbsentNonDefault(long key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public float mergeFloat(long key, float value, FloatFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -955,18 +955,18 @@ public AbstractLong2FloatMap setDefaultReturnValue(float v) { @Override public float computeFloat(long key, LongFloatUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeFloat(key, mappingFunction); } } @Override - public float computeFloatNonDefault(long key, LongFloatUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeFloatNonDefault(key, mappingFunction); } } - @Override public float computeFloatIfAbsent(long key, Long2FloatFunction mappingFunction) { synchronized(mutex) { return map.computeFloatIfAbsent(key, mappingFunction); } } @Override - public float computeFloatIfAbsentNonDefault(long key, Long2FloatFunction mappingFunction) { synchronized(mutex) { return map.computeFloatIfAbsentNonDefault(key, mappingFunction); } } - @Override public float computeFloatIfPresent(long key, LongFloatUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeFloatIfPresent(key, mappingFunction); } } @Override - public float computeFloatIfPresentNonDefault(long key, LongFloatUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeFloatIfPresentNonDefault(key, mappingFunction); } } - @Override public float supplyFloatIfAbsent(long key, FloatSupplier valueProvider) { synchronized(mutex) { return map.supplyFloatIfAbsent(key, valueProvider); } } @Override + public float computeFloatNonDefault(long key, LongFloatUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeFloatNonDefault(key, mappingFunction); } } + @Override + public float computeFloatIfAbsentNonDefault(long key, Long2FloatFunction mappingFunction) { synchronized(mutex) { return map.computeFloatIfAbsentNonDefault(key, mappingFunction); } } + @Override + public float computeFloatIfPresentNonDefault(long key, LongFloatUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeFloatIfPresentNonDefault(key, mappingFunction); } } + @Override public float supplyFloatIfAbsentNonDefault(long key, FloatSupplier valueProvider) { synchronized(mutex) { return map.supplyFloatIfAbsentNonDefault(key, valueProvider); } } @Override public float mergeFloat(long key, float value, FloatFloatUnaryOperator mappingFunction) { synchronized(mutex) { return map.mergeFloat(key, value, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/longs/utils/maps/Long2IntMaps.java b/src/main/java/speiger/src/collections/longs/utils/maps/Long2IntMaps.java index d9387ea6..3214c6ab 100644 --- a/src/main/java/speiger/src/collections/longs/utils/maps/Long2IntMaps.java +++ b/src/main/java/speiger/src/collections/longs/utils/maps/Long2IntMaps.java @@ -250,18 +250,18 @@ public static class SingletonMap extends AbstractLong2IntMap { @Override public int computeInt(long key, LongIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntNonDefault(long key, LongIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int computeIntIfAbsent(long key, Long2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntIfAbsentNonDefault(long key, Long2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int computeIntIfPresent(long key, LongIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntIfPresentNonDefault(long key, LongIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int supplyIntIfAbsent(long key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public int computeIntNonDefault(long key, LongIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public int computeIntIfAbsentNonDefault(long key, Long2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public int computeIntIfPresentNonDefault(long key, LongIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public int supplyIntIfAbsentNonDefault(long key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public int mergeInt(long key, int value, IntIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -312,18 +312,18 @@ public static class EmptyMap extends AbstractLong2IntMap { @Override public int computeInt(long key, LongIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntNonDefault(long key, LongIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int computeIntIfAbsent(long key, Long2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntIfAbsentNonDefault(long key, Long2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int computeIntIfPresent(long key, LongIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntIfPresentNonDefault(long key, LongIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int supplyIntIfAbsent(long key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public int computeIntNonDefault(long key, LongIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public int computeIntIfAbsentNonDefault(long key, Long2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public int computeIntIfPresentNonDefault(long key, LongIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public int supplyIntIfAbsentNonDefault(long key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public int mergeInt(long key, int value, IntIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -547,18 +547,18 @@ public int get(long key) { @Override public int computeInt(long key, LongIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntNonDefault(long key, LongIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int computeIntIfAbsent(long key, Long2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntIfAbsentNonDefault(long key, Long2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int computeIntIfPresent(long key, LongIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntIfPresentNonDefault(long key, LongIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int supplyIntIfAbsent(long key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public int computeIntNonDefault(long key, LongIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public int computeIntIfAbsentNonDefault(long key, Long2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public int computeIntIfPresentNonDefault(long key, LongIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public int supplyIntIfAbsentNonDefault(long key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public int mergeInt(long key, int value, IntIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -955,18 +955,18 @@ public AbstractLong2IntMap setDefaultReturnValue(int v) { @Override public int computeInt(long key, LongIntUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeInt(key, mappingFunction); } } @Override - public int computeIntNonDefault(long key, LongIntUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeIntNonDefault(key, mappingFunction); } } - @Override public int computeIntIfAbsent(long key, Long2IntFunction mappingFunction) { synchronized(mutex) { return map.computeIntIfAbsent(key, mappingFunction); } } @Override - public int computeIntIfAbsentNonDefault(long key, Long2IntFunction mappingFunction) { synchronized(mutex) { return map.computeIntIfAbsentNonDefault(key, mappingFunction); } } - @Override public int computeIntIfPresent(long key, LongIntUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeIntIfPresent(key, mappingFunction); } } @Override - public int computeIntIfPresentNonDefault(long key, LongIntUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeIntIfPresentNonDefault(key, mappingFunction); } } - @Override public int supplyIntIfAbsent(long key, IntSupplier valueProvider) { synchronized(mutex) { return map.supplyIntIfAbsent(key, valueProvider); } } @Override + public int computeIntNonDefault(long key, LongIntUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeIntNonDefault(key, mappingFunction); } } + @Override + public int computeIntIfAbsentNonDefault(long key, Long2IntFunction mappingFunction) { synchronized(mutex) { return map.computeIntIfAbsentNonDefault(key, mappingFunction); } } + @Override + public int computeIntIfPresentNonDefault(long key, LongIntUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeIntIfPresentNonDefault(key, mappingFunction); } } + @Override public int supplyIntIfAbsentNonDefault(long key, IntSupplier valueProvider) { synchronized(mutex) { return map.supplyIntIfAbsentNonDefault(key, valueProvider); } } @Override public int mergeInt(long key, int value, IntIntUnaryOperator mappingFunction) { synchronized(mutex) { return map.mergeInt(key, value, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/longs/utils/maps/Long2LongMaps.java b/src/main/java/speiger/src/collections/longs/utils/maps/Long2LongMaps.java index 28f3f897..94731827 100644 --- a/src/main/java/speiger/src/collections/longs/utils/maps/Long2LongMaps.java +++ b/src/main/java/speiger/src/collections/longs/utils/maps/Long2LongMaps.java @@ -249,18 +249,18 @@ public static class SingletonMap extends AbstractLong2LongMap { @Override public long computeLong(long key, LongLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongNonDefault(long key, LongLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long computeLongIfAbsent(long key, LongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongIfAbsentNonDefault(long key, LongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long computeLongIfPresent(long key, LongLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongIfPresentNonDefault(long key, LongLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long supplyLongIfAbsent(long key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public long computeLongNonDefault(long key, LongLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public long computeLongIfAbsentNonDefault(long key, LongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public long computeLongIfPresentNonDefault(long key, LongLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public long supplyLongIfAbsentNonDefault(long key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public long mergeLong(long key, long value, LongLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -311,18 +311,18 @@ public static class EmptyMap extends AbstractLong2LongMap { @Override public long computeLong(long key, LongLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongNonDefault(long key, LongLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long computeLongIfAbsent(long key, LongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongIfAbsentNonDefault(long key, LongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long computeLongIfPresent(long key, LongLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongIfPresentNonDefault(long key, LongLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long supplyLongIfAbsent(long key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public long computeLongNonDefault(long key, LongLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public long computeLongIfAbsentNonDefault(long key, LongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public long computeLongIfPresentNonDefault(long key, LongLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public long supplyLongIfAbsentNonDefault(long key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public long mergeLong(long key, long value, LongLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -546,18 +546,18 @@ public long get(long key) { @Override public long computeLong(long key, LongLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongNonDefault(long key, LongLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long computeLongIfAbsent(long key, LongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongIfAbsentNonDefault(long key, LongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long computeLongIfPresent(long key, LongLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongIfPresentNonDefault(long key, LongLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long supplyLongIfAbsent(long key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public long computeLongNonDefault(long key, LongLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public long computeLongIfAbsentNonDefault(long key, LongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public long computeLongIfPresentNonDefault(long key, LongLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public long supplyLongIfAbsentNonDefault(long key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public long mergeLong(long key, long value, LongLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -954,18 +954,18 @@ public AbstractLong2LongMap setDefaultReturnValue(long v) { @Override public long computeLong(long key, LongLongUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeLong(key, mappingFunction); } } @Override - public long computeLongNonDefault(long key, LongLongUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeLongNonDefault(key, mappingFunction); } } - @Override public long computeLongIfAbsent(long key, LongUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeLongIfAbsent(key, mappingFunction); } } @Override - public long computeLongIfAbsentNonDefault(long key, LongUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeLongIfAbsentNonDefault(key, mappingFunction); } } - @Override public long computeLongIfPresent(long key, LongLongUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeLongIfPresent(key, mappingFunction); } } @Override - public long computeLongIfPresentNonDefault(long key, LongLongUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeLongIfPresentNonDefault(key, mappingFunction); } } - @Override public long supplyLongIfAbsent(long key, LongSupplier valueProvider) { synchronized(mutex) { return map.supplyLongIfAbsent(key, valueProvider); } } @Override + public long computeLongNonDefault(long key, LongLongUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeLongNonDefault(key, mappingFunction); } } + @Override + public long computeLongIfAbsentNonDefault(long key, LongUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeLongIfAbsentNonDefault(key, mappingFunction); } } + @Override + public long computeLongIfPresentNonDefault(long key, LongLongUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeLongIfPresentNonDefault(key, mappingFunction); } } + @Override public long supplyLongIfAbsentNonDefault(long key, LongSupplier valueProvider) { synchronized(mutex) { return map.supplyLongIfAbsentNonDefault(key, valueProvider); } } @Override public long mergeLong(long key, long value, LongLongUnaryOperator mappingFunction) { synchronized(mutex) { return map.mergeLong(key, value, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/longs/utils/maps/Long2ObjectMaps.java b/src/main/java/speiger/src/collections/longs/utils/maps/Long2ObjectMaps.java index 3aade014..7e8ed8c6 100644 --- a/src/main/java/speiger/src/collections/longs/utils/maps/Long2ObjectMaps.java +++ b/src/main/java/speiger/src/collections/longs/utils/maps/Long2ObjectMaps.java @@ -266,20 +266,12 @@ public static class SingletonMap extends AbstractLong2ObjectMap { @Override public V compute(long key, LongObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeNonDefault(long key, LongObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V computeIfAbsent(long key, LongFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeIfAbsentNonDefault(long key, LongFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V computeIfPresent(long key, LongObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeIfPresentNonDefault(long key, LongObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V supplyIfAbsent(long key, ObjectSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public V supplyIfAbsentNonDefault(long key, ObjectSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public V merge(long key, V value, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override public void mergeAll(Long2ObjectMap m, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -325,20 +317,12 @@ public static class EmptyMap extends AbstractLong2ObjectMap { @Override public V compute(long key, LongObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeNonDefault(long key, LongObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V computeIfAbsent(long key, LongFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeIfAbsentNonDefault(long key, LongFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V computeIfPresent(long key, LongObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeIfPresentNonDefault(long key, LongObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V supplyIfAbsent(long key, ObjectSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public V supplyIfAbsentNonDefault(long key, ObjectSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public V merge(long key, V value, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override public void mergeAll(Long2ObjectMap m, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -561,20 +545,12 @@ public V get(long key) { @Override public V compute(long key, LongObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeNonDefault(long key, LongObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V computeIfAbsent(long key, LongFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeIfAbsentNonDefault(long key, LongFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V computeIfPresent(long key, LongObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeIfPresentNonDefault(long key, LongObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V supplyIfAbsent(long key, ObjectSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public V supplyIfAbsentNonDefault(long key, ObjectSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public V merge(long key, V value, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override public void mergeAll(Long2ObjectMap m, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -968,20 +944,12 @@ public AbstractLong2ObjectMap setDefaultReturnValue(V v) { @Override public V compute(long key, LongObjectUnaryOperator mappingFunction) { synchronized(mutex) { return map.compute(key, mappingFunction); } } @Override - public V computeNonDefault(long key, LongObjectUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeNonDefault(key, mappingFunction); } } - @Override public V computeIfAbsent(long key, LongFunction mappingFunction) { synchronized(mutex) { return map.computeIfAbsent(key, mappingFunction); } } @Override - public V computeIfAbsentNonDefault(long key, LongFunction mappingFunction) { synchronized(mutex) { return map.computeIfAbsentNonDefault(key, mappingFunction); } } - @Override public V computeIfPresent(long key, LongObjectUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeIfPresent(key, mappingFunction); } } @Override - public V computeIfPresentNonDefault(long key, LongObjectUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeIfPresentNonDefault(key, mappingFunction); } } - @Override public V supplyIfAbsent(long key, ObjectSupplier valueProvider) { synchronized(mutex) { return map.supplyIfAbsent(key, valueProvider); } } @Override - public V supplyIfAbsentNonDefault(long key, ObjectSupplier valueProvider) { synchronized(mutex) { return map.supplyIfAbsentNonDefault(key, valueProvider); } } - @Override public V merge(long key, V value, ObjectObjectUnaryOperator mappingFunction) { synchronized(mutex) { return map.merge(key, value, mappingFunction); } } @Override public void mergeAll(Long2ObjectMap m, ObjectObjectUnaryOperator mappingFunction) { synchronized(mutex) { map.mergeAll(m, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/longs/utils/maps/Long2ShortMaps.java b/src/main/java/speiger/src/collections/longs/utils/maps/Long2ShortMaps.java index e59f1146..67aa431d 100644 --- a/src/main/java/speiger/src/collections/longs/utils/maps/Long2ShortMaps.java +++ b/src/main/java/speiger/src/collections/longs/utils/maps/Long2ShortMaps.java @@ -250,18 +250,18 @@ public static class SingletonMap extends AbstractLong2ShortMap { @Override public short computeShort(long key, LongShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortNonDefault(long key, LongShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short computeShortIfAbsent(long key, Long2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortIfAbsentNonDefault(long key, Long2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short computeShortIfPresent(long key, LongShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortIfPresentNonDefault(long key, LongShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short supplyShortIfAbsent(long key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public short computeShortNonDefault(long key, LongShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public short computeShortIfAbsentNonDefault(long key, Long2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public short computeShortIfPresentNonDefault(long key, LongShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public short supplyShortIfAbsentNonDefault(long key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public short mergeShort(long key, short value, ShortShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -312,18 +312,18 @@ public static class EmptyMap extends AbstractLong2ShortMap { @Override public short computeShort(long key, LongShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortNonDefault(long key, LongShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short computeShortIfAbsent(long key, Long2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortIfAbsentNonDefault(long key, Long2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short computeShortIfPresent(long key, LongShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortIfPresentNonDefault(long key, LongShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short supplyShortIfAbsent(long key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public short computeShortNonDefault(long key, LongShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public short computeShortIfAbsentNonDefault(long key, Long2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public short computeShortIfPresentNonDefault(long key, LongShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public short supplyShortIfAbsentNonDefault(long key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public short mergeShort(long key, short value, ShortShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -547,18 +547,18 @@ public short get(long key) { @Override public short computeShort(long key, LongShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortNonDefault(long key, LongShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short computeShortIfAbsent(long key, Long2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortIfAbsentNonDefault(long key, Long2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short computeShortIfPresent(long key, LongShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortIfPresentNonDefault(long key, LongShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short supplyShortIfAbsent(long key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public short computeShortNonDefault(long key, LongShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public short computeShortIfAbsentNonDefault(long key, Long2ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public short computeShortIfPresentNonDefault(long key, LongShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public short supplyShortIfAbsentNonDefault(long key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public short mergeShort(long key, short value, ShortShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -955,18 +955,18 @@ public AbstractLong2ShortMap setDefaultReturnValue(short v) { @Override public short computeShort(long key, LongShortUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeShort(key, mappingFunction); } } @Override - public short computeShortNonDefault(long key, LongShortUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeShortNonDefault(key, mappingFunction); } } - @Override public short computeShortIfAbsent(long key, Long2ShortFunction mappingFunction) { synchronized(mutex) { return map.computeShortIfAbsent(key, mappingFunction); } } @Override - public short computeShortIfAbsentNonDefault(long key, Long2ShortFunction mappingFunction) { synchronized(mutex) { return map.computeShortIfAbsentNonDefault(key, mappingFunction); } } - @Override public short computeShortIfPresent(long key, LongShortUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeShortIfPresent(key, mappingFunction); } } @Override - public short computeShortIfPresentNonDefault(long key, LongShortUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeShortIfPresentNonDefault(key, mappingFunction); } } - @Override public short supplyShortIfAbsent(long key, ShortSupplier valueProvider) { synchronized(mutex) { return map.supplyShortIfAbsent(key, valueProvider); } } @Override + public short computeShortNonDefault(long key, LongShortUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeShortNonDefault(key, mappingFunction); } } + @Override + public short computeShortIfAbsentNonDefault(long key, Long2ShortFunction mappingFunction) { synchronized(mutex) { return map.computeShortIfAbsentNonDefault(key, mappingFunction); } } + @Override + public short computeShortIfPresentNonDefault(long key, LongShortUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeShortIfPresentNonDefault(key, mappingFunction); } } + @Override public short supplyShortIfAbsentNonDefault(long key, ShortSupplier valueProvider) { synchronized(mutex) { return map.supplyShortIfAbsentNonDefault(key, valueProvider); } } @Override public short mergeShort(long key, short value, ShortShortUnaryOperator mappingFunction) { synchronized(mutex) { return map.mergeShort(key, value, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/objects/collections/ObjectIterable.java b/src/main/java/speiger/src/collections/objects/collections/ObjectIterable.java index 86278741..11209e4d 100644 --- a/src/main/java/speiger/src/collections/objects/collections/ObjectIterable.java +++ b/src/main/java/speiger/src/collections/objects/collections/ObjectIterable.java @@ -8,6 +8,19 @@ import java.util.function.IntFunction; import java.util.Comparator; +import speiger.src.collections.booleans.collections.BooleanIterable; +import speiger.src.collections.objects.functions.function.ToByteFunction; +import speiger.src.collections.bytes.collections.ByteIterable; +import speiger.src.collections.objects.functions.function.ToShortFunction; +import speiger.src.collections.shorts.collections.ShortIterable; +import speiger.src.collections.objects.functions.function.ToIntFunction; +import speiger.src.collections.ints.collections.IntIterable; +import speiger.src.collections.objects.functions.function.ToLongFunction; +import speiger.src.collections.longs.collections.LongIterable; +import speiger.src.collections.objects.functions.function.ToFloatFunction; +import speiger.src.collections.floats.collections.FloatIterable; +import speiger.src.collections.objects.functions.function.ToDoubleFunction; +import speiger.src.collections.doubles.collections.DoubleIterable; import speiger.src.collections.objects.functions.function.UnaryOperator; import speiger.src.collections.ints.functions.consumer.IntObjectConsumer; import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer; @@ -87,6 +100,69 @@ default ObjectIterable map(UnaryOperator mapper) { return ObjectIterables.map(this, mapper); } + /** + * A Helper function to reduce the usage of Streams and allows to convert a Iterable to something else. + * @param mapper the mapping function + * @return a new Iterable that returns the desired result + */ + default BooleanIterable mapToBoolean(Predicate mapper) { + return ObjectIterables.mapToBoolean(this, mapper); + } + + /** + * A Helper function to reduce the usage of Streams and allows to convert a Iterable to something else. + * @param mapper the mapping function + * @return a new Iterable that returns the desired result + */ + default ByteIterable mapToByte(ToByteFunction mapper) { + return ObjectIterables.mapToByte(this, mapper); + } + + /** + * A Helper function to reduce the usage of Streams and allows to convert a Iterable to something else. + * @param mapper the mapping function + * @return a new Iterable that returns the desired result + */ + default ShortIterable mapToShort(ToShortFunction mapper) { + return ObjectIterables.mapToShort(this, mapper); + } + + /** + * A Helper function to reduce the usage of Streams and allows to convert a Iterable to something else. + * @param mapper the mapping function + * @return a new Iterable that returns the desired result + */ + default IntIterable mapToInt(ToIntFunction mapper) { + return ObjectIterables.mapToInt(this, mapper); + } + + /** + * A Helper function to reduce the usage of Streams and allows to convert a Iterable to something else. + * @param mapper the mapping function + * @return a new Iterable that returns the desired result + */ + default LongIterable mapToLong(ToLongFunction mapper) { + return ObjectIterables.mapToLong(this, mapper); + } + + /** + * A Helper function to reduce the usage of Streams and allows to convert a Iterable to something else. + * @param mapper the mapping function + * @return a new Iterable that returns the desired result + */ + default FloatIterable mapToFloat(ToFloatFunction mapper) { + return ObjectIterables.mapToFloat(this, mapper); + } + + /** + * A Helper function to reduce the usage of Streams and allows to convert a Iterable to something else. + * @param mapper the mapping function + * @return a new Iterable that returns the desired result + */ + default DoubleIterable mapToDouble(ToDoubleFunction mapper) { + return ObjectIterables.mapToDouble(this, mapper); + } + /** * A Helper function to reduce the usage of Streams and allows to convert a Iterable to something else. * @param mapper the flatMapping function diff --git a/src/main/java/speiger/src/collections/objects/lists/AbstractObjectList.java b/src/main/java/speiger/src/collections/objects/lists/AbstractObjectList.java index a3292da2..3f56c128 100644 --- a/src/main/java/speiger/src/collections/objects/lists/AbstractObjectList.java +++ b/src/main/java/speiger/src/collections/objects/lists/AbstractObjectList.java @@ -12,6 +12,7 @@ import speiger.src.collections.objects.collections.ObjectCollection; import speiger.src.collections.objects.collections.ObjectIterator; import speiger.src.collections.objects.collections.ObjectSplititerator; +import speiger.src.collections.ints.lists.IntList; import speiger.src.collections.objects.utils.ObjectSplititerators; import speiger.src.collections.utils.SanityChecks; @@ -166,13 +167,23 @@ public ObjectIterator iterator() { public ObjectListIterator listIterator() { return listIterator(0); } - + @Override public ObjectListIterator listIterator(int index) { if(index < 0 || index > size()) throw new IndexOutOfBoundsException(); return new ObjectListIter(index); } + @Override + public ObjectListIterator indexedIterator(int...indecies) { + return new IndexedIterator(indecies); + } + + @Override + public ObjectListIterator indexedIterator(IntList indecies) { + return new ListIndexedIterator(indecies); + } + @Override public void size(int size) { while(size > size()) add(null); @@ -526,7 +537,153 @@ public int back(int amount) { } } } + + private class ListIndexedIterator implements ObjectListIterator { + IntList indecies; + int index; + int lastReturned = -1; + + ListIndexedIterator(IntList indecies) { + this.indecies = indecies; + } + + @Override + public boolean hasNext() { + return index < indecies.size(); + } + + @Override + public T next() { + if(!hasNext()) throw new NoSuchElementException(); + int i = index++; + return get((lastReturned = indecies.getInt(i))); + } + + @Override + public boolean hasPrevious() { + return index > 0; + } + + @Override + public T previous() { + if(!hasPrevious()) throw new NoSuchElementException(); + index--; + return get((lastReturned = indecies.getInt(index))); + } + + @Override + public int nextIndex() { + return index; + } + + @Override + public int previousIndex() { + return index-1; + } + + @Override + public void remove() { throw new UnsupportedOperationException(); } + @Override + public void add(T e) { throw new UnsupportedOperationException(); } + + @Override + public void set(T e) { + if(lastReturned == -1) throw new IllegalStateException(); + AbstractObjectList.this.set(lastReturned, e); + } + + @Override + public int skip(int amount) { + if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed"); + int steps = Math.min(amount, indecies.size() - index); + index += steps; + if(steps > 0) lastReturned = Math.min(index-1, indecies.size()-1); + return steps; + } + + @Override + public int back(int amount) { + if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed"); + int steps = Math.min(amount, index); + index -= steps; + if(steps > 0) lastReturned = Math.max(index, 0); + return steps; + } + } + + private class IndexedIterator implements ObjectListIterator { + int[] indecies; + int index; + int lastReturned = -1; + + IndexedIterator(int[] indecies) { + this.indecies = indecies; + } + @Override + public boolean hasNext() { + return index < indecies.length; + } + + @Override + public T next() { + if(!hasNext()) throw new NoSuchElementException(); + int i = index++; + return get((lastReturned = indecies[i])); + } + + @Override + public boolean hasPrevious() { + return index > 0; + } + + @Override + public T previous() { + if(!hasPrevious()) throw new NoSuchElementException(); + index--; + return get((lastReturned = indecies[index])); + } + + @Override + public int nextIndex() { + return index; + } + + @Override + public int previousIndex() { + return index-1; + } + + @Override + public void remove() { throw new UnsupportedOperationException(); } + @Override + public void add(T e) { throw new UnsupportedOperationException(); } + + @Override + public void set(T e) { + if(lastReturned == -1) throw new IllegalStateException(); + AbstractObjectList.this.set(lastReturned, e); + } + + @Override + public int skip(int amount) { + if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed"); + int steps = Math.min(amount, indecies.length - index); + index += steps; + if(steps > 0) lastReturned = Math.min(index-1, indecies.length-1); + return steps; + } + + @Override + public int back(int amount) { + if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed"); + int steps = Math.min(amount, index); + index -= steps; + if(steps > 0) lastReturned = Math.max(index, 0); + return steps; + } + } + private class ObjectListIter implements ObjectListIterator { int index; int lastReturned = -1; @@ -604,7 +761,7 @@ public int back(int amount) { if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed"); int steps = Math.min(amount, index); index -= steps; - if(steps > 0) lastReturned = Math.min(index, size()-1); + if(steps > 0) lastReturned = Math.max(index, 0); return steps; } } diff --git a/src/main/java/speiger/src/collections/objects/lists/ObjectList.java b/src/main/java/speiger/src/collections/objects/lists/ObjectList.java index 285282be..17fb7874 100644 --- a/src/main/java/speiger/src/collections/objects/lists/ObjectList.java +++ b/src/main/java/speiger/src/collections/objects/lists/ObjectList.java @@ -11,6 +11,7 @@ import speiger.src.collections.ints.functions.consumer.IntObjectConsumer; import speiger.src.collections.objects.utils.ObjectArrays; import speiger.src.collections.objects.utils.ObjectLists; +import speiger.src.collections.ints.lists.IntList; import speiger.src.collections.objects.utils.ObjectSplititerators; /** @@ -253,6 +254,24 @@ public default void forEachIndexed(IntObjectConsumer action) { @Override public ObjectListIterator listIterator(int index); + /** + * Creates a Iterator that follows the indecies provided.
+ * For example if the Lists Contents is:
-1, 0 1
and the indecies are:
0, 1, 2, 2, 1, 0
+ * then the iterator will return the following values:
-1, 0, 1, 1, 0, -1 + * @param indecies that should be used for the iteration. + * @return a custom indexed iterator + */ + public ObjectListIterator indexedIterator(int...indecies); + + /** + * Creates a Iterator that follows the indecies provided.
+ * For example if the Lists Contents is:
-1, 0 1
and the indecies are:
0, 1, 2, 2, 1, 0
+ * then the iterator will return the following values:
-1, 0, 1, 1, 0, -1 + * @param indecies that should be used for the iteration. + * @return a custom indexed iterator + */ + public ObjectListIterator indexedIterator(IntList indecies); + /** * A Type-Specific List of subList * @see java.util.List#subList(int, int) diff --git a/src/main/java/speiger/src/collections/objects/maps/abstracts/AbstractObject2BooleanMap.java b/src/main/java/speiger/src/collections/objects/maps/abstracts/AbstractObject2BooleanMap.java index 6f37f3db..4381c53c 100644 --- a/src/main/java/speiger/src/collections/objects/maps/abstracts/AbstractObject2BooleanMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/abstracts/AbstractObject2BooleanMap.java @@ -150,6 +150,39 @@ public boolean computeBoolean(T key, ObjectBooleanUnaryOperator mappingFuncti return newValue; } + @Override + public boolean computeBooleanIfAbsent(T key, Predicate mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(!containsKey(key)) { + boolean newValue = mappingFunction.test(key); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public boolean supplyBooleanIfAbsent(T key, BooleanSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + if(!containsKey(key)) { + boolean newValue = valueProvider.getAsBoolean(); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public boolean computeBooleanIfPresent(T key, ObjectBooleanUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(containsKey(key)) { + boolean newValue = mappingFunction.applyAsBoolean(key, getBoolean(key)); + put(key, newValue); + return newValue; + } + return getDefaultReturnValue(); + } + @Override public boolean computeBooleanNonDefault(T key, ObjectBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -166,17 +199,6 @@ public boolean computeBooleanNonDefault(T key, ObjectBooleanUnaryOperator map return newValue; } - @Override - public boolean computeBooleanIfAbsent(T key, Predicate mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(!containsKey(key)) { - boolean newValue = mappingFunction.test(key); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public boolean computeBooleanIfAbsentNonDefault(T key, Predicate mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -191,17 +213,6 @@ public boolean computeBooleanIfAbsentNonDefault(T key, Predicate mappingFunct return value; } - @Override - public boolean supplyBooleanIfAbsent(T key, BooleanSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - if(!containsKey(key)) { - boolean newValue = valueProvider.getAsBoolean(); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public boolean supplyBooleanIfAbsentNonDefault(T key, BooleanSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -216,17 +227,6 @@ public boolean supplyBooleanIfAbsentNonDefault(T key, BooleanSupplier valueProvi return value; } - @Override - public boolean computeBooleanIfPresent(T key, ObjectBooleanUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(containsKey(key)) { - boolean newValue = mappingFunction.applyAsBoolean(key, getBoolean(key)); - put(key, newValue); - return newValue; - } - return getDefaultReturnValue(); - } - @Override public boolean computeBooleanIfPresentNonDefault(T key, ObjectBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/objects/maps/abstracts/AbstractObject2ByteMap.java b/src/main/java/speiger/src/collections/objects/maps/abstracts/AbstractObject2ByteMap.java index ee5df6ce..71996ce6 100644 --- a/src/main/java/speiger/src/collections/objects/maps/abstracts/AbstractObject2ByteMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/abstracts/AbstractObject2ByteMap.java @@ -156,6 +156,39 @@ public byte computeByte(T key, ObjectByteUnaryOperator mappingFunction) { return newValue; } + @Override + public byte computeByteIfAbsent(T key, ToByteFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(!containsKey(key)) { + byte newValue = mappingFunction.applyAsByte(key); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public byte supplyByteIfAbsent(T key, ByteSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + if(!containsKey(key)) { + byte newValue = valueProvider.getAsByte(); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public byte computeByteIfPresent(T key, ObjectByteUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(containsKey(key)) { + byte newValue = mappingFunction.applyAsByte(key, getByte(key)); + put(key, newValue); + return newValue; + } + return getDefaultReturnValue(); + } + @Override public byte computeByteNonDefault(T key, ObjectByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -172,17 +205,6 @@ public byte computeByteNonDefault(T key, ObjectByteUnaryOperator mappingFunct return newValue; } - @Override - public byte computeByteIfAbsent(T key, ToByteFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(!containsKey(key)) { - byte newValue = mappingFunction.applyAsByte(key); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public byte computeByteIfAbsentNonDefault(T key, ToByteFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -197,23 +219,12 @@ public byte computeByteIfAbsentNonDefault(T key, ToByteFunction mappingFuncti return value; } - @Override - public byte supplyByteIfAbsent(T key, ByteSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - if(!containsKey(key)) { - byte newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public byte supplyByteIfAbsentNonDefault(T key, ByteSupplier valueProvider) { Objects.requireNonNull(valueProvider); byte value; if((value = getByte(key)) == getDefaultReturnValue() || !containsKey(key)) { - byte newValue = valueProvider.getAsInt(); + byte newValue = valueProvider.getAsByte(); if(newValue != getDefaultReturnValue()) { put(key, newValue); return newValue; @@ -222,17 +233,6 @@ public byte supplyByteIfAbsentNonDefault(T key, ByteSupplier valueProvider) { return value; } - @Override - public byte computeByteIfPresent(T key, ObjectByteUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(containsKey(key)) { - byte newValue = mappingFunction.applyAsByte(key, getByte(key)); - put(key, newValue); - return newValue; - } - return getDefaultReturnValue(); - } - @Override public byte computeByteIfPresentNonDefault(T key, ObjectByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/objects/maps/abstracts/AbstractObject2CharMap.java b/src/main/java/speiger/src/collections/objects/maps/abstracts/AbstractObject2CharMap.java index 3f639f02..a323c743 100644 --- a/src/main/java/speiger/src/collections/objects/maps/abstracts/AbstractObject2CharMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/abstracts/AbstractObject2CharMap.java @@ -156,6 +156,39 @@ public char computeChar(T key, ObjectCharUnaryOperator mappingFunction) { return newValue; } + @Override + public char computeCharIfAbsent(T key, ToCharFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(!containsKey(key)) { + char newValue = mappingFunction.applyAsChar(key); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public char supplyCharIfAbsent(T key, CharSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + if(!containsKey(key)) { + char newValue = valueProvider.getAsChar(); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public char computeCharIfPresent(T key, ObjectCharUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(containsKey(key)) { + char newValue = mappingFunction.applyAsChar(key, getChar(key)); + put(key, newValue); + return newValue; + } + return getDefaultReturnValue(); + } + @Override public char computeCharNonDefault(T key, ObjectCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -172,17 +205,6 @@ public char computeCharNonDefault(T key, ObjectCharUnaryOperator mappingFunct return newValue; } - @Override - public char computeCharIfAbsent(T key, ToCharFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(!containsKey(key)) { - char newValue = mappingFunction.applyAsChar(key); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public char computeCharIfAbsentNonDefault(T key, ToCharFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -197,23 +219,12 @@ public char computeCharIfAbsentNonDefault(T key, ToCharFunction mappingFuncti return value; } - @Override - public char supplyCharIfAbsent(T key, CharSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - if(!containsKey(key)) { - char newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public char supplyCharIfAbsentNonDefault(T key, CharSupplier valueProvider) { Objects.requireNonNull(valueProvider); char value; if((value = getChar(key)) == getDefaultReturnValue() || !containsKey(key)) { - char newValue = valueProvider.getAsInt(); + char newValue = valueProvider.getAsChar(); if(newValue != getDefaultReturnValue()) { put(key, newValue); return newValue; @@ -222,17 +233,6 @@ public char supplyCharIfAbsentNonDefault(T key, CharSupplier valueProvider) { return value; } - @Override - public char computeCharIfPresent(T key, ObjectCharUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(containsKey(key)) { - char newValue = mappingFunction.applyAsChar(key, getChar(key)); - put(key, newValue); - return newValue; - } - return getDefaultReturnValue(); - } - @Override public char computeCharIfPresentNonDefault(T key, ObjectCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/objects/maps/abstracts/AbstractObject2DoubleMap.java b/src/main/java/speiger/src/collections/objects/maps/abstracts/AbstractObject2DoubleMap.java index 5e39d562..4c268658 100644 --- a/src/main/java/speiger/src/collections/objects/maps/abstracts/AbstractObject2DoubleMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/abstracts/AbstractObject2DoubleMap.java @@ -156,6 +156,39 @@ public double computeDouble(T key, ObjectDoubleUnaryOperator mappingFunction) return newValue; } + @Override + public double computeDoubleIfAbsent(T key, ToDoubleFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(!containsKey(key)) { + double newValue = mappingFunction.applyAsDouble(key); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public double supplyDoubleIfAbsent(T key, DoubleSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + if(!containsKey(key)) { + double newValue = valueProvider.getAsDouble(); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public double computeDoubleIfPresent(T key, ObjectDoubleUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(containsKey(key)) { + double newValue = mappingFunction.applyAsDouble(key, getDouble(key)); + put(key, newValue); + return newValue; + } + return getDefaultReturnValue(); + } + @Override public double computeDoubleNonDefault(T key, ObjectDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -172,17 +205,6 @@ public double computeDoubleNonDefault(T key, ObjectDoubleUnaryOperator mappin return newValue; } - @Override - public double computeDoubleIfAbsent(T key, ToDoubleFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(!containsKey(key)) { - double newValue = mappingFunction.applyAsDouble(key); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public double computeDoubleIfAbsentNonDefault(T key, ToDoubleFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -197,17 +219,6 @@ public double computeDoubleIfAbsentNonDefault(T key, ToDoubleFunction mapping return value; } - @Override - public double supplyDoubleIfAbsent(T key, DoubleSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - if(!containsKey(key)) { - double newValue = valueProvider.getAsDouble(); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public double supplyDoubleIfAbsentNonDefault(T key, DoubleSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -222,17 +233,6 @@ public double supplyDoubleIfAbsentNonDefault(T key, DoubleSupplier valueProvider return value; } - @Override - public double computeDoubleIfPresent(T key, ObjectDoubleUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(containsKey(key)) { - double newValue = mappingFunction.applyAsDouble(key, getDouble(key)); - put(key, newValue); - return newValue; - } - return getDefaultReturnValue(); - } - @Override public double computeDoubleIfPresentNonDefault(T key, ObjectDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/objects/maps/abstracts/AbstractObject2FloatMap.java b/src/main/java/speiger/src/collections/objects/maps/abstracts/AbstractObject2FloatMap.java index 0fdc6ec6..ed86fe7a 100644 --- a/src/main/java/speiger/src/collections/objects/maps/abstracts/AbstractObject2FloatMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/abstracts/AbstractObject2FloatMap.java @@ -156,6 +156,39 @@ public float computeFloat(T key, ObjectFloatUnaryOperator mappingFunction) { return newValue; } + @Override + public float computeFloatIfAbsent(T key, ToFloatFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(!containsKey(key)) { + float newValue = mappingFunction.applyAsFloat(key); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public float supplyFloatIfAbsent(T key, FloatSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + if(!containsKey(key)) { + float newValue = valueProvider.getAsFloat(); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public float computeFloatIfPresent(T key, ObjectFloatUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(containsKey(key)) { + float newValue = mappingFunction.applyAsFloat(key, getFloat(key)); + put(key, newValue); + return newValue; + } + return getDefaultReturnValue(); + } + @Override public float computeFloatNonDefault(T key, ObjectFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -172,17 +205,6 @@ public float computeFloatNonDefault(T key, ObjectFloatUnaryOperator mappingFu return newValue; } - @Override - public float computeFloatIfAbsent(T key, ToFloatFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(!containsKey(key)) { - float newValue = mappingFunction.applyAsFloat(key); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public float computeFloatIfAbsentNonDefault(T key, ToFloatFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -197,23 +219,12 @@ public float computeFloatIfAbsentNonDefault(T key, ToFloatFunction mappingFun return value; } - @Override - public float supplyFloatIfAbsent(T key, FloatSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - if(!containsKey(key)) { - float newValue = valueProvider.getAsDouble(); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public float supplyFloatIfAbsentNonDefault(T key, FloatSupplier valueProvider) { Objects.requireNonNull(valueProvider); float value; if((value = getFloat(key)) == getDefaultReturnValue() || !containsKey(key)) { - float newValue = valueProvider.getAsDouble(); + float newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) != Float.floatToIntBits(getDefaultReturnValue())) { put(key, newValue); return newValue; @@ -222,17 +233,6 @@ public float supplyFloatIfAbsentNonDefault(T key, FloatSupplier valueProvider) { return value; } - @Override - public float computeFloatIfPresent(T key, ObjectFloatUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(containsKey(key)) { - float newValue = mappingFunction.applyAsFloat(key, getFloat(key)); - put(key, newValue); - return newValue; - } - return getDefaultReturnValue(); - } - @Override public float computeFloatIfPresentNonDefault(T key, ObjectFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/objects/maps/abstracts/AbstractObject2IntMap.java b/src/main/java/speiger/src/collections/objects/maps/abstracts/AbstractObject2IntMap.java index b06b23c9..8da08245 100644 --- a/src/main/java/speiger/src/collections/objects/maps/abstracts/AbstractObject2IntMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/abstracts/AbstractObject2IntMap.java @@ -156,6 +156,39 @@ public int computeInt(T key, ObjectIntUnaryOperator mappingFunction) { return newValue; } + @Override + public int computeIntIfAbsent(T key, ToIntFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(!containsKey(key)) { + int newValue = mappingFunction.applyAsInt(key); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public int supplyIntIfAbsent(T key, IntSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + if(!containsKey(key)) { + int newValue = valueProvider.getAsInt(); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public int computeIntIfPresent(T key, ObjectIntUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(containsKey(key)) { + int newValue = mappingFunction.applyAsInt(key, getInt(key)); + put(key, newValue); + return newValue; + } + return getDefaultReturnValue(); + } + @Override public int computeIntNonDefault(T key, ObjectIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -172,17 +205,6 @@ public int computeIntNonDefault(T key, ObjectIntUnaryOperator mappingFunction return newValue; } - @Override - public int computeIntIfAbsent(T key, ToIntFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(!containsKey(key)) { - int newValue = mappingFunction.applyAsInt(key); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public int computeIntIfAbsentNonDefault(T key, ToIntFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -197,17 +219,6 @@ public int computeIntIfAbsentNonDefault(T key, ToIntFunction mappingFunction) return value; } - @Override - public int supplyIntIfAbsent(T key, IntSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - if(!containsKey(key)) { - int newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public int supplyIntIfAbsentNonDefault(T key, IntSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -222,17 +233,6 @@ public int supplyIntIfAbsentNonDefault(T key, IntSupplier valueProvider) { return value; } - @Override - public int computeIntIfPresent(T key, ObjectIntUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(containsKey(key)) { - int newValue = mappingFunction.applyAsInt(key, getInt(key)); - put(key, newValue); - return newValue; - } - return getDefaultReturnValue(); - } - @Override public int computeIntIfPresentNonDefault(T key, ObjectIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/objects/maps/abstracts/AbstractObject2LongMap.java b/src/main/java/speiger/src/collections/objects/maps/abstracts/AbstractObject2LongMap.java index e19d6c7a..02a034d3 100644 --- a/src/main/java/speiger/src/collections/objects/maps/abstracts/AbstractObject2LongMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/abstracts/AbstractObject2LongMap.java @@ -156,6 +156,39 @@ public long computeLong(T key, ObjectLongUnaryOperator mappingFunction) { return newValue; } + @Override + public long computeLongIfAbsent(T key, ToLongFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(!containsKey(key)) { + long newValue = mappingFunction.applyAsLong(key); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public long supplyLongIfAbsent(T key, LongSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + if(!containsKey(key)) { + long newValue = valueProvider.getAsLong(); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public long computeLongIfPresent(T key, ObjectLongUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(containsKey(key)) { + long newValue = mappingFunction.applyAsLong(key, getLong(key)); + put(key, newValue); + return newValue; + } + return getDefaultReturnValue(); + } + @Override public long computeLongNonDefault(T key, ObjectLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -172,17 +205,6 @@ public long computeLongNonDefault(T key, ObjectLongUnaryOperator mappingFunct return newValue; } - @Override - public long computeLongIfAbsent(T key, ToLongFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(!containsKey(key)) { - long newValue = mappingFunction.applyAsLong(key); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public long computeLongIfAbsentNonDefault(T key, ToLongFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -197,17 +219,6 @@ public long computeLongIfAbsentNonDefault(T key, ToLongFunction mappingFuncti return value; } - @Override - public long supplyLongIfAbsent(T key, LongSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - if(!containsKey(key)) { - long newValue = valueProvider.getAsLong(); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public long supplyLongIfAbsentNonDefault(T key, LongSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -222,17 +233,6 @@ public long supplyLongIfAbsentNonDefault(T key, LongSupplier valueProvider) { return value; } - @Override - public long computeLongIfPresent(T key, ObjectLongUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(containsKey(key)) { - long newValue = mappingFunction.applyAsLong(key, getLong(key)); - put(key, newValue); - return newValue; - } - return getDefaultReturnValue(); - } - @Override public long computeLongIfPresentNonDefault(T key, ObjectLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/objects/maps/abstracts/AbstractObject2ObjectMap.java b/src/main/java/speiger/src/collections/objects/maps/abstracts/AbstractObject2ObjectMap.java index faf933e9..aa866e4e 100644 --- a/src/main/java/speiger/src/collections/objects/maps/abstracts/AbstractObject2ObjectMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/abstracts/AbstractObject2ObjectMap.java @@ -144,22 +144,6 @@ public V compute(T key, ObjectObjectUnaryOperator mappingFunction) { return newValue; } - @Override - public V computeNonDefault(T key, ObjectObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - V value = getObject(key); - V newValue = mappingFunction.apply(key, value); - if(Objects.equals(newValue, getDefaultReturnValue())) { - if(!Objects.equals(value, getDefaultReturnValue()) || containsKey(key)) { - remove(key); - return getDefaultReturnValue(); - } - return getDefaultReturnValue(); - } - put(key, newValue); - return newValue; - } - @Override public V computeIfAbsent(T key, UnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -174,20 +158,6 @@ public V computeIfAbsent(T key, UnaryOperator mappingFunction) { return value; } - @Override - public V computeIfAbsentNonDefault(T key, UnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - V value; - if((value = getObject(key)) == getDefaultReturnValue() || !containsKey(key)) { - V newValue = mappingFunction.apply(key); - if(!Objects.equals(newValue, getDefaultReturnValue())) { - put(key, newValue); - return newValue; - } - } - return value; - } - @Override public V supplyIfAbsent(T key, ObjectSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -202,20 +172,6 @@ public V supplyIfAbsent(T key, ObjectSupplier valueProvider) { return value; } - @Override - public V supplyIfAbsentNonDefault(T key, ObjectSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - V value; - if((value = getObject(key)) == getDefaultReturnValue() || !containsKey(key)) { - V newValue = valueProvider.get(); - if(!Objects.equals(newValue, getDefaultReturnValue())) { - put(key, newValue); - return newValue; - } - } - return value; - } - @Override public V computeIfPresent(T key, ObjectObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -231,21 +187,6 @@ public V computeIfPresent(T key, ObjectObjectUnaryOperator mappingFunction return getDefaultReturnValue(); } - @Override - public V computeIfPresentNonDefault(T key, ObjectObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - V value; - if(!Objects.equals((value = getObject(key)), getDefaultReturnValue()) || containsKey(key)) { - V newValue = mappingFunction.apply(key, value); - if(!Objects.equals(newValue, getDefaultReturnValue())) { - put(key, newValue); - return newValue; - } - remove(key); - } - return getDefaultReturnValue(); - } - @Override public V merge(T key, V value, ObjectObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/objects/maps/abstracts/AbstractObject2ShortMap.java b/src/main/java/speiger/src/collections/objects/maps/abstracts/AbstractObject2ShortMap.java index 55ca7dfd..852c7c13 100644 --- a/src/main/java/speiger/src/collections/objects/maps/abstracts/AbstractObject2ShortMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/abstracts/AbstractObject2ShortMap.java @@ -156,6 +156,39 @@ public short computeShort(T key, ObjectShortUnaryOperator mappingFunction) { return newValue; } + @Override + public short computeShortIfAbsent(T key, ToShortFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(!containsKey(key)) { + short newValue = mappingFunction.applyAsShort(key); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public short supplyShortIfAbsent(T key, ShortSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + if(!containsKey(key)) { + short newValue = valueProvider.getAsShort(); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public short computeShortIfPresent(T key, ObjectShortUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(containsKey(key)) { + short newValue = mappingFunction.applyAsShort(key, getShort(key)); + put(key, newValue); + return newValue; + } + return getDefaultReturnValue(); + } + @Override public short computeShortNonDefault(T key, ObjectShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -172,17 +205,6 @@ public short computeShortNonDefault(T key, ObjectShortUnaryOperator mappingFu return newValue; } - @Override - public short computeShortIfAbsent(T key, ToShortFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(!containsKey(key)) { - short newValue = mappingFunction.applyAsShort(key); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public short computeShortIfAbsentNonDefault(T key, ToShortFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -197,23 +219,12 @@ public short computeShortIfAbsentNonDefault(T key, ToShortFunction mappingFun return value; } - @Override - public short supplyShortIfAbsent(T key, ShortSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - if(!containsKey(key)) { - short newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public short supplyShortIfAbsentNonDefault(T key, ShortSupplier valueProvider) { Objects.requireNonNull(valueProvider); short value; if((value = getShort(key)) == getDefaultReturnValue() || !containsKey(key)) { - short newValue = valueProvider.getAsInt(); + short newValue = valueProvider.getAsShort(); if(newValue != getDefaultReturnValue()) { put(key, newValue); return newValue; @@ -222,17 +233,6 @@ public short supplyShortIfAbsentNonDefault(T key, ShortSupplier valueProvider) { return value; } - @Override - public short computeShortIfPresent(T key, ObjectShortUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(containsKey(key)) { - short newValue = mappingFunction.applyAsShort(key, getShort(key)); - put(key, newValue); - return newValue; - } - return getDefaultReturnValue(); - } - @Override public short computeShortIfPresentNonDefault(T key, ObjectShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/concurrent/Object2BooleanConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/concurrent/Object2BooleanConcurrentOpenHashMap.java index 13522d04..bc5d0811 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/concurrent/Object2BooleanConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/concurrent/Object2BooleanConcurrentOpenHashMap.java @@ -426,13 +426,6 @@ public boolean computeBoolean(T key, ObjectBooleanUnaryOperator mappingFuncti return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public boolean computeBooleanNonDefault(T key, ObjectBooleanUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public boolean computeBooleanIfAbsent(T key, Predicate mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -440,13 +433,6 @@ public boolean computeBooleanIfAbsent(T key, Predicate mappingFunction) { return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public boolean computeBooleanIfAbsentNonDefault(T key, Predicate mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public boolean supplyBooleanIfAbsent(T key, BooleanSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -455,17 +441,31 @@ public boolean supplyBooleanIfAbsent(T key, BooleanSupplier valueProvider) { } @Override - public boolean supplyBooleanIfAbsentNonDefault(T key, BooleanSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public boolean computeBooleanIfPresent(T key, ObjectBooleanUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); + return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } @Override - public boolean computeBooleanIfPresent(T key, ObjectBooleanUnaryOperator mappingFunction) { + public boolean computeBooleanNonDefault(T key, ObjectBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).computeIfPresent(hash, key, mappingFunction); + return getSegment(hash).computeNonDefault(hash, key, mappingFunction); + } + + @Override + public boolean computeBooleanIfAbsentNonDefault(T key, Predicate mappingFunction) { + Objects.requireNonNull(mappingFunction); + int hash = getHashCode(key); + return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); + } + + @Override + public boolean supplyBooleanIfAbsentNonDefault(T key, BooleanSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + int hash = getHashCode(key); + return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); } @Override @@ -1984,35 +1984,29 @@ protected boolean compute(int hash, T key, ObjectBooleanUnaryOperator mapping } } - protected boolean computeNonDefault(int hash, T key, ObjectBooleanUnaryOperator mappingFunction) { + protected boolean computeIfAbsent(int hash, T key, Predicate mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + boolean newValue = mappingFunction.test(key); insert(-index-1, key, newValue); return newValue; } - boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + boolean newValue = values[index]; return newValue; } finally { unlockWrite(stamp); } } - - protected boolean computeIfAbsent(int hash, T key, Predicate mappingFunction) { + + protected boolean supplyIfAbsent(int hash, T key, BooleanSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - boolean newValue = mappingFunction.test(key); + boolean newValue = valueProvider.getAsBoolean(); insert(-index-1, key, newValue); return newValue; } @@ -2023,23 +2017,37 @@ protected boolean computeIfAbsent(int hash, T key, Predicate mappingFunction) unlockWrite(stamp); } } + + protected boolean computeIfPresent(int hash, T key, ObjectBooleanUnaryOperator mappingFunction) { + long stamp = writeLock(); + try { + int index = findIndex(hash, key); + if(index < 0) return getDefaultReturnValue(); + boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); + values[index] = newValue; + return newValue; + } + finally { + unlockWrite(stamp); + } + } - protected boolean computeIfAbsentNonDefault(int hash, T key, Predicate mappingFunction) { + protected boolean computeNonDefault(int hash, T key, ObjectBooleanUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - boolean newValue = mappingFunction.test(key); + boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - boolean newValue = values[index]; + boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.test(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } finally { @@ -2047,16 +2055,22 @@ protected boolean computeIfAbsentNonDefault(int hash, T key, Predicate mappin } } - protected boolean supplyIfAbsent(int hash, T key, BooleanSupplier valueProvider) { + protected boolean computeIfAbsentNonDefault(int hash, T key, Predicate mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - boolean newValue = valueProvider.getAsBoolean(); + boolean newValue = mappingFunction.test(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } boolean newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.test(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } finally { @@ -2087,20 +2101,6 @@ protected boolean supplyIfAbsentNonDefault(int hash, T key, BooleanSupplier valu } } - protected boolean computeIfPresent(int hash, T key, ObjectBooleanUnaryOperator mappingFunction) { - long stamp = writeLock(); - try { - int index = findIndex(hash, key); - if(index < 0) return getDefaultReturnValue(); - boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); - values[index] = newValue; - return newValue; - } - finally { - unlockWrite(stamp); - } - } - protected boolean computeIfPresentNonDefault(int hash, T key, ObjectBooleanUnaryOperator mappingFunction) { long stamp = writeLock(); try { diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/concurrent/Object2ByteConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/concurrent/Object2ByteConcurrentOpenHashMap.java index 6788f04e..968741ef 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/concurrent/Object2ByteConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/concurrent/Object2ByteConcurrentOpenHashMap.java @@ -439,13 +439,6 @@ public byte computeByte(T key, ObjectByteUnaryOperator mappingFunction) { return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public byte computeByteNonDefault(T key, ObjectByteUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public byte computeByteIfAbsent(T key, ToByteFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -453,13 +446,6 @@ public byte computeByteIfAbsent(T key, ToByteFunction mappingFunction) { return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public byte computeByteIfAbsentNonDefault(T key, ToByteFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public byte supplyByteIfAbsent(T key, ByteSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -468,17 +454,31 @@ public byte supplyByteIfAbsent(T key, ByteSupplier valueProvider) { } @Override - public byte supplyByteIfAbsentNonDefault(T key, ByteSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public byte computeByteIfPresent(T key, ObjectByteUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); + return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } @Override - public byte computeByteIfPresent(T key, ObjectByteUnaryOperator mappingFunction) { + public byte computeByteNonDefault(T key, ObjectByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).computeIfPresent(hash, key, mappingFunction); + return getSegment(hash).computeNonDefault(hash, key, mappingFunction); + } + + @Override + public byte computeByteIfAbsentNonDefault(T key, ToByteFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + int hash = getHashCode(key); + return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); + } + + @Override + public byte supplyByteIfAbsentNonDefault(T key, ByteSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + int hash = getHashCode(key); + return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); } @Override @@ -2028,35 +2028,29 @@ protected byte compute(int hash, T key, ObjectByteUnaryOperator mappingFuncti } } - protected byte computeNonDefault(int hash, T key, ObjectByteUnaryOperator mappingFunction) { + protected byte computeIfAbsent(int hash, T key, ToByteFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + byte newValue = mappingFunction.applyAsByte(key); insert(-index-1, key, newValue); return newValue; } - byte newValue = mappingFunction.applyAsByte(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + byte newValue = values[index]; return newValue; } finally { unlockWrite(stamp); } } - - protected byte computeIfAbsent(int hash, T key, ToByteFunction mappingFunction) { + + protected byte supplyIfAbsent(int hash, T key, ByteSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = valueProvider.getAsByte(); insert(-index-1, key, newValue); return newValue; } @@ -2067,23 +2061,14 @@ protected byte computeIfAbsent(int hash, T key, ToByteFunction mappingFunctio unlockWrite(stamp); } } - - protected byte computeIfAbsentNonDefault(int hash, T key, ToByteFunction mappingFunction) { + + protected byte computeIfPresent(int hash, T key, ObjectByteUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key); - if(newValue == getDefaultReturnValue()) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - byte newValue = values[index]; - if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsByte(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; - } + if(index < 0) return getDefaultReturnValue(); + byte newValue = mappingFunction.applyAsByte(key, values[index]); + values[index] = newValue; return newValue; } finally { @@ -2091,16 +2076,22 @@ protected byte computeIfAbsentNonDefault(int hash, T key, ToByteFunction mapp } } - protected byte supplyIfAbsent(int hash, T key, ByteSupplier valueProvider) { + protected byte computeNonDefault(int hash, T key, ObjectByteUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - byte newValue = valueProvider.getAsInt(); + byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - byte newValue = values[index]; + byte newValue = mappingFunction.applyAsByte(key, values[index]); + if(newValue == getDefaultReturnValue()) { + removeIndex(index); + return newValue; + } + values[index] = newValue; return newValue; } finally { @@ -2108,19 +2099,19 @@ protected byte supplyIfAbsent(int hash, T key, ByteSupplier valueProvider) { } } - protected byte supplyIfAbsentNonDefault(int hash, T key, ByteSupplier valueProvider) { + protected byte computeIfAbsentNonDefault(int hash, T key, ToByteFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - byte newValue = valueProvider.getAsInt(); + byte newValue = mappingFunction.applyAsByte(key); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } byte newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = mappingFunction.applyAsByte(key); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } @@ -2131,13 +2122,22 @@ protected byte supplyIfAbsentNonDefault(int hash, T key, ByteSupplier valueProvi } } - protected byte computeIfPresent(int hash, T key, ObjectByteUnaryOperator mappingFunction) { + protected byte supplyIfAbsentNonDefault(int hash, T key, ByteSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0) return getDefaultReturnValue(); - byte newValue = mappingFunction.applyAsByte(key, values[index]); - values[index] = newValue; + if(index < 0) { + byte newValue = valueProvider.getAsByte(); + if(newValue == getDefaultReturnValue()) return newValue; + insert(-index-1, key, newValue); + return newValue; + } + byte newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = valueProvider.getAsByte(); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } finally { diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/concurrent/Object2CharConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/concurrent/Object2CharConcurrentOpenHashMap.java index 72aac2b2..48815169 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/concurrent/Object2CharConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/concurrent/Object2CharConcurrentOpenHashMap.java @@ -439,13 +439,6 @@ public char computeChar(T key, ObjectCharUnaryOperator mappingFunction) { return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public char computeCharNonDefault(T key, ObjectCharUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public char computeCharIfAbsent(T key, ToCharFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -453,13 +446,6 @@ public char computeCharIfAbsent(T key, ToCharFunction mappingFunction) { return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public char computeCharIfAbsentNonDefault(T key, ToCharFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public char supplyCharIfAbsent(T key, CharSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -468,17 +454,31 @@ public char supplyCharIfAbsent(T key, CharSupplier valueProvider) { } @Override - public char supplyCharIfAbsentNonDefault(T key, CharSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public char computeCharIfPresent(T key, ObjectCharUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); + return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } @Override - public char computeCharIfPresent(T key, ObjectCharUnaryOperator mappingFunction) { + public char computeCharNonDefault(T key, ObjectCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).computeIfPresent(hash, key, mappingFunction); + return getSegment(hash).computeNonDefault(hash, key, mappingFunction); + } + + @Override + public char computeCharIfAbsentNonDefault(T key, ToCharFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + int hash = getHashCode(key); + return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); + } + + @Override + public char supplyCharIfAbsentNonDefault(T key, CharSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + int hash = getHashCode(key); + return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); } @Override @@ -2028,35 +2028,29 @@ protected char compute(int hash, T key, ObjectCharUnaryOperator mappingFuncti } } - protected char computeNonDefault(int hash, T key, ObjectCharUnaryOperator mappingFunction) { + protected char computeIfAbsent(int hash, T key, ToCharFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + char newValue = mappingFunction.applyAsChar(key); insert(-index-1, key, newValue); return newValue; } - char newValue = mappingFunction.applyAsChar(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + char newValue = values[index]; return newValue; } finally { unlockWrite(stamp); } } - - protected char computeIfAbsent(int hash, T key, ToCharFunction mappingFunction) { + + protected char supplyIfAbsent(int hash, T key, CharSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = valueProvider.getAsChar(); insert(-index-1, key, newValue); return newValue; } @@ -2067,23 +2061,14 @@ protected char computeIfAbsent(int hash, T key, ToCharFunction mappingFunctio unlockWrite(stamp); } } - - protected char computeIfAbsentNonDefault(int hash, T key, ToCharFunction mappingFunction) { + + protected char computeIfPresent(int hash, T key, ObjectCharUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0) { - char newValue = mappingFunction.applyAsChar(key); - if(newValue == getDefaultReturnValue()) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - char newValue = values[index]; - if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsChar(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; - } + if(index < 0) return getDefaultReturnValue(); + char newValue = mappingFunction.applyAsChar(key, values[index]); + values[index] = newValue; return newValue; } finally { @@ -2091,16 +2076,22 @@ protected char computeIfAbsentNonDefault(int hash, T key, ToCharFunction mapp } } - protected char supplyIfAbsent(int hash, T key, CharSupplier valueProvider) { + protected char computeNonDefault(int hash, T key, ObjectCharUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - char newValue = valueProvider.getAsInt(); + char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - char newValue = values[index]; + char newValue = mappingFunction.applyAsChar(key, values[index]); + if(newValue == getDefaultReturnValue()) { + removeIndex(index); + return newValue; + } + values[index] = newValue; return newValue; } finally { @@ -2108,19 +2099,19 @@ protected char supplyIfAbsent(int hash, T key, CharSupplier valueProvider) { } } - protected char supplyIfAbsentNonDefault(int hash, T key, CharSupplier valueProvider) { + protected char computeIfAbsentNonDefault(int hash, T key, ToCharFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - char newValue = valueProvider.getAsInt(); + char newValue = mappingFunction.applyAsChar(key); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } char newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = mappingFunction.applyAsChar(key); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } @@ -2131,13 +2122,22 @@ protected char supplyIfAbsentNonDefault(int hash, T key, CharSupplier valueProvi } } - protected char computeIfPresent(int hash, T key, ObjectCharUnaryOperator mappingFunction) { + protected char supplyIfAbsentNonDefault(int hash, T key, CharSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0) return getDefaultReturnValue(); - char newValue = mappingFunction.applyAsChar(key, values[index]); - values[index] = newValue; + if(index < 0) { + char newValue = valueProvider.getAsChar(); + if(newValue == getDefaultReturnValue()) return newValue; + insert(-index-1, key, newValue); + return newValue; + } + char newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = valueProvider.getAsChar(); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } finally { diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/concurrent/Object2DoubleConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/concurrent/Object2DoubleConcurrentOpenHashMap.java index 8f4cbb21..2e987762 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/concurrent/Object2DoubleConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/concurrent/Object2DoubleConcurrentOpenHashMap.java @@ -439,13 +439,6 @@ public double computeDouble(T key, ObjectDoubleUnaryOperator mappingFunction) return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public double computeDoubleNonDefault(T key, ObjectDoubleUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public double computeDoubleIfAbsent(T key, ToDoubleFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -453,13 +446,6 @@ public double computeDoubleIfAbsent(T key, ToDoubleFunction mappingFunction) return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public double computeDoubleIfAbsentNonDefault(T key, ToDoubleFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public double supplyDoubleIfAbsent(T key, DoubleSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -468,17 +454,31 @@ public double supplyDoubleIfAbsent(T key, DoubleSupplier valueProvider) { } @Override - public double supplyDoubleIfAbsentNonDefault(T key, DoubleSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public double computeDoubleIfPresent(T key, ObjectDoubleUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); + return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } @Override - public double computeDoubleIfPresent(T key, ObjectDoubleUnaryOperator mappingFunction) { + public double computeDoubleNonDefault(T key, ObjectDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).computeIfPresent(hash, key, mappingFunction); + return getSegment(hash).computeNonDefault(hash, key, mappingFunction); + } + + @Override + public double computeDoubleIfAbsentNonDefault(T key, ToDoubleFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + int hash = getHashCode(key); + return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); + } + + @Override + public double supplyDoubleIfAbsentNonDefault(T key, DoubleSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + int hash = getHashCode(key); + return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); } @Override @@ -2028,35 +2028,29 @@ protected double compute(int hash, T key, ObjectDoubleUnaryOperator mappingFu } } - protected double computeNonDefault(int hash, T key, ObjectDoubleUnaryOperator mappingFunction) { + protected double computeIfAbsent(int hash, T key, ToDoubleFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + double newValue = mappingFunction.applyAsDouble(key); insert(-index-1, key, newValue); return newValue; } - double newValue = mappingFunction.applyAsDouble(key, values[index]); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + double newValue = values[index]; return newValue; } finally { unlockWrite(stamp); } } - - protected double computeIfAbsent(int hash, T key, ToDoubleFunction mappingFunction) { + + protected double supplyIfAbsent(int hash, T key, DoubleSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = valueProvider.getAsDouble(); insert(-index-1, key, newValue); return newValue; } @@ -2067,23 +2061,37 @@ protected double computeIfAbsent(int hash, T key, ToDoubleFunction mappingFun unlockWrite(stamp); } } + + protected double computeIfPresent(int hash, T key, ObjectDoubleUnaryOperator mappingFunction) { + long stamp = writeLock(); + try { + int index = findIndex(hash, key); + if(index < 0) return getDefaultReturnValue(); + double newValue = mappingFunction.applyAsDouble(key, values[index]); + values[index] = newValue; + return newValue; + } + finally { + unlockWrite(stamp); + } + } - protected double computeIfAbsentNonDefault(int hash, T key, ToDoubleFunction mappingFunction) { + protected double computeNonDefault(int hash, T key, ObjectDoubleUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } - double newValue = values[index]; + double newValue = mappingFunction.applyAsDouble(key, values[index]); if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - newValue = mappingFunction.applyAsDouble(key); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } finally { @@ -2091,16 +2099,22 @@ protected double computeIfAbsentNonDefault(int hash, T key, ToDoubleFunction } } - protected double supplyIfAbsent(int hash, T key, DoubleSupplier valueProvider) { + protected double computeIfAbsentNonDefault(int hash, T key, ToDoubleFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - double newValue = valueProvider.getAsDouble(); + double newValue = mappingFunction.applyAsDouble(key); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } double newValue = values[index]; + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { + newValue = mappingFunction.applyAsDouble(key); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + values[index] = newValue; + } return newValue; } finally { @@ -2131,20 +2145,6 @@ protected double supplyIfAbsentNonDefault(int hash, T key, DoubleSupplier valueP } } - protected double computeIfPresent(int hash, T key, ObjectDoubleUnaryOperator mappingFunction) { - long stamp = writeLock(); - try { - int index = findIndex(hash, key); - if(index < 0) return getDefaultReturnValue(); - double newValue = mappingFunction.applyAsDouble(key, values[index]); - values[index] = newValue; - return newValue; - } - finally { - unlockWrite(stamp); - } - } - protected double computeIfPresentNonDefault(int hash, T key, ObjectDoubleUnaryOperator mappingFunction) { long stamp = writeLock(); try { diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/concurrent/Object2FloatConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/concurrent/Object2FloatConcurrentOpenHashMap.java index 9319024e..4e79d12d 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/concurrent/Object2FloatConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/concurrent/Object2FloatConcurrentOpenHashMap.java @@ -439,13 +439,6 @@ public float computeFloat(T key, ObjectFloatUnaryOperator mappingFunction) { return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public float computeFloatNonDefault(T key, ObjectFloatUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public float computeFloatIfAbsent(T key, ToFloatFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -453,13 +446,6 @@ public float computeFloatIfAbsent(T key, ToFloatFunction mappingFunction) { return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public float computeFloatIfAbsentNonDefault(T key, ToFloatFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public float supplyFloatIfAbsent(T key, FloatSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -468,17 +454,31 @@ public float supplyFloatIfAbsent(T key, FloatSupplier valueProvider) { } @Override - public float supplyFloatIfAbsentNonDefault(T key, FloatSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public float computeFloatIfPresent(T key, ObjectFloatUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); + return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } @Override - public float computeFloatIfPresent(T key, ObjectFloatUnaryOperator mappingFunction) { + public float computeFloatNonDefault(T key, ObjectFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).computeIfPresent(hash, key, mappingFunction); + return getSegment(hash).computeNonDefault(hash, key, mappingFunction); + } + + @Override + public float computeFloatIfAbsentNonDefault(T key, ToFloatFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + int hash = getHashCode(key); + return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); + } + + @Override + public float supplyFloatIfAbsentNonDefault(T key, FloatSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + int hash = getHashCode(key); + return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); } @Override @@ -2028,35 +2028,29 @@ protected float compute(int hash, T key, ObjectFloatUnaryOperator mappingFunc } } - protected float computeNonDefault(int hash, T key, ObjectFloatUnaryOperator mappingFunction) { + protected float computeIfAbsent(int hash, T key, ToFloatFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + float newValue = mappingFunction.applyAsFloat(key); insert(-index-1, key, newValue); return newValue; } - float newValue = mappingFunction.applyAsFloat(key, values[index]); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + float newValue = values[index]; return newValue; } finally { unlockWrite(stamp); } } - - protected float computeIfAbsent(int hash, T key, ToFloatFunction mappingFunction) { + + protected float supplyIfAbsent(int hash, T key, FloatSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = valueProvider.getAsFloat(); insert(-index-1, key, newValue); return newValue; } @@ -2067,23 +2061,14 @@ protected float computeIfAbsent(int hash, T key, ToFloatFunction mappingFunct unlockWrite(stamp); } } - - protected float computeIfAbsentNonDefault(int hash, T key, ToFloatFunction mappingFunction) { + + protected float computeIfPresent(int hash, T key, ObjectFloatUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - float newValue = values[index]; - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - newValue = mappingFunction.applyAsFloat(key); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; - values[index] = newValue; - } + if(index < 0) return getDefaultReturnValue(); + float newValue = mappingFunction.applyAsFloat(key, values[index]); + values[index] = newValue; return newValue; } finally { @@ -2091,16 +2076,22 @@ protected float computeIfAbsentNonDefault(int hash, T key, ToFloatFunction ma } } - protected float supplyIfAbsent(int hash, T key, FloatSupplier valueProvider) { + protected float computeNonDefault(int hash, T key, ObjectFloatUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - float newValue = valueProvider.getAsDouble(); + float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } - float newValue = values[index]; + float newValue = mappingFunction.applyAsFloat(key, values[index]); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { + removeIndex(index); + return newValue; + } + values[index] = newValue; return newValue; } finally { @@ -2108,19 +2099,19 @@ protected float supplyIfAbsent(int hash, T key, FloatSupplier valueProvider) { } } - protected float supplyIfAbsentNonDefault(int hash, T key, FloatSupplier valueProvider) { + protected float computeIfAbsentNonDefault(int hash, T key, ToFloatFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - float newValue = valueProvider.getAsDouble(); + float newValue = mappingFunction.applyAsFloat(key); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } float newValue = values[index]; if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - newValue = valueProvider.getAsDouble(); + newValue = mappingFunction.applyAsFloat(key); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; values[index] = newValue; } @@ -2131,13 +2122,22 @@ protected float supplyIfAbsentNonDefault(int hash, T key, FloatSupplier valuePro } } - protected float computeIfPresent(int hash, T key, ObjectFloatUnaryOperator mappingFunction) { + protected float supplyIfAbsentNonDefault(int hash, T key, FloatSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0) return getDefaultReturnValue(); - float newValue = mappingFunction.applyAsFloat(key, values[index]); - values[index] = newValue; + if(index < 0) { + float newValue = valueProvider.getAsFloat(); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + insert(-index-1, key, newValue); + return newValue; + } + float newValue = values[index]; + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { + newValue = valueProvider.getAsFloat(); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + values[index] = newValue; + } return newValue; } finally { diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/concurrent/Object2IntConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/concurrent/Object2IntConcurrentOpenHashMap.java index 0ff9797a..b51ad7b6 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/concurrent/Object2IntConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/concurrent/Object2IntConcurrentOpenHashMap.java @@ -439,13 +439,6 @@ public int computeInt(T key, ObjectIntUnaryOperator mappingFunction) { return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public int computeIntNonDefault(T key, ObjectIntUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public int computeIntIfAbsent(T key, ToIntFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -453,13 +446,6 @@ public int computeIntIfAbsent(T key, ToIntFunction mappingFunction) { return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public int computeIntIfAbsentNonDefault(T key, ToIntFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public int supplyIntIfAbsent(T key, IntSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -468,17 +454,31 @@ public int supplyIntIfAbsent(T key, IntSupplier valueProvider) { } @Override - public int supplyIntIfAbsentNonDefault(T key, IntSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public int computeIntIfPresent(T key, ObjectIntUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); + return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } @Override - public int computeIntIfPresent(T key, ObjectIntUnaryOperator mappingFunction) { + public int computeIntNonDefault(T key, ObjectIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).computeIfPresent(hash, key, mappingFunction); + return getSegment(hash).computeNonDefault(hash, key, mappingFunction); + } + + @Override + public int computeIntIfAbsentNonDefault(T key, ToIntFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + int hash = getHashCode(key); + return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); + } + + @Override + public int supplyIntIfAbsentNonDefault(T key, IntSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + int hash = getHashCode(key); + return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); } @Override @@ -2028,35 +2028,29 @@ protected int compute(int hash, T key, ObjectIntUnaryOperator mappingFunction } } - protected int computeNonDefault(int hash, T key, ObjectIntUnaryOperator mappingFunction) { + protected int computeIfAbsent(int hash, T key, ToIntFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + int newValue = mappingFunction.applyAsInt(key); insert(-index-1, key, newValue); return newValue; } - int newValue = mappingFunction.applyAsInt(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + int newValue = values[index]; return newValue; } finally { unlockWrite(stamp); } } - - protected int computeIfAbsent(int hash, T key, ToIntFunction mappingFunction) { + + protected int supplyIfAbsent(int hash, T key, IntSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = valueProvider.getAsInt(); insert(-index-1, key, newValue); return newValue; } @@ -2067,23 +2061,37 @@ protected int computeIfAbsent(int hash, T key, ToIntFunction mappingFunction) unlockWrite(stamp); } } + + protected int computeIfPresent(int hash, T key, ObjectIntUnaryOperator mappingFunction) { + long stamp = writeLock(); + try { + int index = findIndex(hash, key); + if(index < 0) return getDefaultReturnValue(); + int newValue = mappingFunction.applyAsInt(key, values[index]); + values[index] = newValue; + return newValue; + } + finally { + unlockWrite(stamp); + } + } - protected int computeIfAbsentNonDefault(int hash, T key, ToIntFunction mappingFunction) { + protected int computeNonDefault(int hash, T key, ObjectIntUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - int newValue = values[index]; + int newValue = mappingFunction.applyAsInt(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsInt(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } finally { @@ -2091,16 +2099,22 @@ protected int computeIfAbsentNonDefault(int hash, T key, ToIntFunction mappin } } - protected int supplyIfAbsent(int hash, T key, IntSupplier valueProvider) { + protected int computeIfAbsentNonDefault(int hash, T key, ToIntFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - int newValue = valueProvider.getAsInt(); + int newValue = mappingFunction.applyAsInt(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } int newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsInt(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } finally { @@ -2131,20 +2145,6 @@ protected int supplyIfAbsentNonDefault(int hash, T key, IntSupplier valueProvide } } - protected int computeIfPresent(int hash, T key, ObjectIntUnaryOperator mappingFunction) { - long stamp = writeLock(); - try { - int index = findIndex(hash, key); - if(index < 0) return getDefaultReturnValue(); - int newValue = mappingFunction.applyAsInt(key, values[index]); - values[index] = newValue; - return newValue; - } - finally { - unlockWrite(stamp); - } - } - protected int computeIfPresentNonDefault(int hash, T key, ObjectIntUnaryOperator mappingFunction) { long stamp = writeLock(); try { diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/concurrent/Object2LongConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/concurrent/Object2LongConcurrentOpenHashMap.java index 75035be7..35cc3071 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/concurrent/Object2LongConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/concurrent/Object2LongConcurrentOpenHashMap.java @@ -439,13 +439,6 @@ public long computeLong(T key, ObjectLongUnaryOperator mappingFunction) { return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public long computeLongNonDefault(T key, ObjectLongUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public long computeLongIfAbsent(T key, ToLongFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -453,13 +446,6 @@ public long computeLongIfAbsent(T key, ToLongFunction mappingFunction) { return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public long computeLongIfAbsentNonDefault(T key, ToLongFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public long supplyLongIfAbsent(T key, LongSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -468,17 +454,31 @@ public long supplyLongIfAbsent(T key, LongSupplier valueProvider) { } @Override - public long supplyLongIfAbsentNonDefault(T key, LongSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public long computeLongIfPresent(T key, ObjectLongUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); + return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } @Override - public long computeLongIfPresent(T key, ObjectLongUnaryOperator mappingFunction) { + public long computeLongNonDefault(T key, ObjectLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).computeIfPresent(hash, key, mappingFunction); + return getSegment(hash).computeNonDefault(hash, key, mappingFunction); + } + + @Override + public long computeLongIfAbsentNonDefault(T key, ToLongFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + int hash = getHashCode(key); + return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); + } + + @Override + public long supplyLongIfAbsentNonDefault(T key, LongSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + int hash = getHashCode(key); + return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); } @Override @@ -2028,35 +2028,29 @@ protected long compute(int hash, T key, ObjectLongUnaryOperator mappingFuncti } } - protected long computeNonDefault(int hash, T key, ObjectLongUnaryOperator mappingFunction) { + protected long computeIfAbsent(int hash, T key, ToLongFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + long newValue = mappingFunction.applyAsLong(key); insert(-index-1, key, newValue); return newValue; } - long newValue = mappingFunction.applyAsLong(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + long newValue = values[index]; return newValue; } finally { unlockWrite(stamp); } } - - protected long computeIfAbsent(int hash, T key, ToLongFunction mappingFunction) { + + protected long supplyIfAbsent(int hash, T key, LongSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = valueProvider.getAsLong(); insert(-index-1, key, newValue); return newValue; } @@ -2067,23 +2061,37 @@ protected long computeIfAbsent(int hash, T key, ToLongFunction mappingFunctio unlockWrite(stamp); } } + + protected long computeIfPresent(int hash, T key, ObjectLongUnaryOperator mappingFunction) { + long stamp = writeLock(); + try { + int index = findIndex(hash, key); + if(index < 0) return getDefaultReturnValue(); + long newValue = mappingFunction.applyAsLong(key, values[index]); + values[index] = newValue; + return newValue; + } + finally { + unlockWrite(stamp); + } + } - protected long computeIfAbsentNonDefault(int hash, T key, ToLongFunction mappingFunction) { + protected long computeNonDefault(int hash, T key, ObjectLongUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - long newValue = values[index]; + long newValue = mappingFunction.applyAsLong(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsLong(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } finally { @@ -2091,16 +2099,22 @@ protected long computeIfAbsentNonDefault(int hash, T key, ToLongFunction mapp } } - protected long supplyIfAbsent(int hash, T key, LongSupplier valueProvider) { + protected long computeIfAbsentNonDefault(int hash, T key, ToLongFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - long newValue = valueProvider.getAsLong(); + long newValue = mappingFunction.applyAsLong(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } long newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsLong(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } finally { @@ -2131,20 +2145,6 @@ protected long supplyIfAbsentNonDefault(int hash, T key, LongSupplier valueProvi } } - protected long computeIfPresent(int hash, T key, ObjectLongUnaryOperator mappingFunction) { - long stamp = writeLock(); - try { - int index = findIndex(hash, key); - if(index < 0) return getDefaultReturnValue(); - long newValue = mappingFunction.applyAsLong(key, values[index]); - values[index] = newValue; - return newValue; - } - finally { - unlockWrite(stamp); - } - } - protected long computeIfPresentNonDefault(int hash, T key, ObjectLongUnaryOperator mappingFunction) { long stamp = writeLock(); try { diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/concurrent/Object2ObjectConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/concurrent/Object2ObjectConcurrentOpenHashMap.java index f9700176..700b2f55 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/concurrent/Object2ObjectConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/concurrent/Object2ObjectConcurrentOpenHashMap.java @@ -354,13 +354,6 @@ public V compute(T key, ObjectObjectUnaryOperator mappingFunction) { return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public V computeNonDefault(T key, ObjectObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public V computeIfAbsent(T key, UnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -368,13 +361,6 @@ public V computeIfAbsent(T key, UnaryOperator mappingFunction) { return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public V computeIfAbsentNonDefault(T key, UnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public V supplyIfAbsent(T key, ObjectSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -382,13 +368,6 @@ public V supplyIfAbsent(T key, ObjectSupplier valueProvider) { return getSegment(hash).supplyIfAbsent(hash, key, valueProvider); } - @Override - public V supplyIfAbsentNonDefault(T key, ObjectSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); - } - @Override public V computeIfPresent(T key, ObjectObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -396,13 +375,6 @@ public V computeIfPresent(T key, ObjectObjectUnaryOperator mappingFunction return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } - @Override - public V computeIfPresentNonDefault(T key, ObjectObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfPresentNonDefault(hash, key, mappingFunction); - } - @Override public V merge(T key, V value, ObjectObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1873,29 +1845,6 @@ protected V compute(int hash, T key, ObjectObjectUnaryOperator mappingFunc } } - protected V computeNonDefault(int hash, T key, ObjectObjectUnaryOperator mappingFunction) { - long stamp = writeLock(); - try { - int index = findIndex(hash, key); - if(index < 0) { - V newValue = mappingFunction.apply(key, getDefaultReturnValue()); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = mappingFunction.apply(key, values[index]); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; - return newValue; - } - finally { - unlockWrite(stamp); - } - } - protected V computeIfAbsent(int hash, T key, UnaryOperator mappingFunction) { long stamp = writeLock(); try { @@ -1918,30 +1867,7 @@ protected V computeIfAbsent(int hash, T key, UnaryOperator mappingFunction unlockWrite(stamp); } } - - protected V computeIfAbsentNonDefault(int hash, T key, UnaryOperator mappingFunction) { - long stamp = writeLock(); - try { - int index = findIndex(hash, key); - if(index < 0) { - V newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = values[index]; - if(Objects.equals(newValue, getDefaultReturnValue())) { - newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - values[index] = newValue; - } - return newValue; - } - finally { - unlockWrite(stamp); - } - } - + protected V supplyIfAbsent(int hash, T key, ObjectSupplier valueProvider) { long stamp = writeLock(); try { @@ -1964,30 +1890,7 @@ protected V supplyIfAbsent(int hash, T key, ObjectSupplier valueProvider) { unlockWrite(stamp); } } - - protected V supplyIfAbsentNonDefault(int hash, T key, ObjectSupplier valueProvider) { - long stamp = writeLock(); - try { - int index = findIndex(hash, key); - if(index < 0) { - V newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = values[index]; - if(Objects.equals(newValue, getDefaultReturnValue())) { - newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - values[index] = newValue; - } - return newValue; - } - finally { - unlockWrite(stamp); - } - } - + protected V computeIfPresent(int hash, T key, ObjectObjectUnaryOperator mappingFunction) { long stamp = writeLock(); try { @@ -2006,11 +1909,16 @@ protected V computeIfPresent(int hash, T key, ObjectObjectUnaryOperator ma } } - protected V computeIfPresentNonDefault(int hash, T key, ObjectObjectUnaryOperator mappingFunction) { + protected V computeNonDefault(int hash, T key, ObjectObjectUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0 || Objects.equals(values[index], getDefaultReturnValue())) return getDefaultReturnValue(); + if(index < 0) { + V newValue = mappingFunction.apply(key, getDefaultReturnValue()); + if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; + insert(-index-1, key, newValue); + return newValue; + } V newValue = mappingFunction.apply(key, values[index]); if(Objects.equals(newValue, getDefaultReturnValue())) { removeIndex(index); diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/concurrent/Object2ShortConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/concurrent/Object2ShortConcurrentOpenHashMap.java index 06bf8b6a..b06e7252 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/concurrent/Object2ShortConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/concurrent/Object2ShortConcurrentOpenHashMap.java @@ -439,13 +439,6 @@ public short computeShort(T key, ObjectShortUnaryOperator mappingFunction) { return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public short computeShortNonDefault(T key, ObjectShortUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public short computeShortIfAbsent(T key, ToShortFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -453,13 +446,6 @@ public short computeShortIfAbsent(T key, ToShortFunction mappingFunction) { return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public short computeShortIfAbsentNonDefault(T key, ToShortFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public short supplyShortIfAbsent(T key, ShortSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -468,17 +454,31 @@ public short supplyShortIfAbsent(T key, ShortSupplier valueProvider) { } @Override - public short supplyShortIfAbsentNonDefault(T key, ShortSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public short computeShortIfPresent(T key, ObjectShortUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); + return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } @Override - public short computeShortIfPresent(T key, ObjectShortUnaryOperator mappingFunction) { + public short computeShortNonDefault(T key, ObjectShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).computeIfPresent(hash, key, mappingFunction); + return getSegment(hash).computeNonDefault(hash, key, mappingFunction); + } + + @Override + public short computeShortIfAbsentNonDefault(T key, ToShortFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + int hash = getHashCode(key); + return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); + } + + @Override + public short supplyShortIfAbsentNonDefault(T key, ShortSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + int hash = getHashCode(key); + return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); } @Override @@ -2028,35 +2028,29 @@ protected short compute(int hash, T key, ObjectShortUnaryOperator mappingFunc } } - protected short computeNonDefault(int hash, T key, ObjectShortUnaryOperator mappingFunction) { + protected short computeIfAbsent(int hash, T key, ToShortFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + short newValue = mappingFunction.applyAsShort(key); insert(-index-1, key, newValue); return newValue; } - short newValue = mappingFunction.applyAsShort(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + short newValue = values[index]; return newValue; } finally { unlockWrite(stamp); } } - - protected short computeIfAbsent(int hash, T key, ToShortFunction mappingFunction) { + + protected short supplyIfAbsent(int hash, T key, ShortSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = valueProvider.getAsShort(); insert(-index-1, key, newValue); return newValue; } @@ -2067,23 +2061,14 @@ protected short computeIfAbsent(int hash, T key, ToShortFunction mappingFunct unlockWrite(stamp); } } - - protected short computeIfAbsentNonDefault(int hash, T key, ToShortFunction mappingFunction) { + + protected short computeIfPresent(int hash, T key, ObjectShortUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0) { - short newValue = mappingFunction.applyAsShort(key); - if(newValue == getDefaultReturnValue()) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - short newValue = values[index]; - if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsShort(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; - } + if(index < 0) return getDefaultReturnValue(); + short newValue = mappingFunction.applyAsShort(key, values[index]); + values[index] = newValue; return newValue; } finally { @@ -2091,16 +2076,22 @@ protected short computeIfAbsentNonDefault(int hash, T key, ToShortFunction ma } } - protected short supplyIfAbsent(int hash, T key, ShortSupplier valueProvider) { + protected short computeNonDefault(int hash, T key, ObjectShortUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - short newValue = valueProvider.getAsInt(); + short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - short newValue = values[index]; + short newValue = mappingFunction.applyAsShort(key, values[index]); + if(newValue == getDefaultReturnValue()) { + removeIndex(index); + return newValue; + } + values[index] = newValue; return newValue; } finally { @@ -2108,19 +2099,19 @@ protected short supplyIfAbsent(int hash, T key, ShortSupplier valueProvider) { } } - protected short supplyIfAbsentNonDefault(int hash, T key, ShortSupplier valueProvider) { + protected short computeIfAbsentNonDefault(int hash, T key, ToShortFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - short newValue = valueProvider.getAsInt(); + short newValue = mappingFunction.applyAsShort(key); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } short newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = mappingFunction.applyAsShort(key); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } @@ -2131,13 +2122,22 @@ protected short supplyIfAbsentNonDefault(int hash, T key, ShortSupplier valuePro } } - protected short computeIfPresent(int hash, T key, ObjectShortUnaryOperator mappingFunction) { + protected short supplyIfAbsentNonDefault(int hash, T key, ShortSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0) return getDefaultReturnValue(); - short newValue = mappingFunction.applyAsShort(key, values[index]); - values[index] = newValue; + if(index < 0) { + short newValue = valueProvider.getAsShort(); + if(newValue == getDefaultReturnValue()) return newValue; + insert(-index-1, key, newValue); + return newValue; + } + short newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = valueProvider.getAsShort(); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } finally { diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2BooleanOpenCustomHashMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2BooleanOpenCustomHashMap.java index 97c2ef00..df027ead 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2BooleanOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2BooleanOpenCustomHashMap.java @@ -425,30 +425,24 @@ public boolean computeBoolean(T key, ObjectBooleanUnaryOperator mappingFuncti } @Override - public boolean computeBooleanNonDefault(T key, ObjectBooleanUnaryOperator mappingFunction) { + public boolean computeBooleanIfAbsent(T key, Predicate mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + boolean newValue = mappingFunction.test(key); insert(-index-1, key, newValue); return newValue; } - boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + boolean newValue = values[index]; return newValue; } - + @Override - public boolean computeBooleanIfAbsent(T key, Predicate mappingFunction) { - Objects.requireNonNull(mappingFunction); + public boolean supplyBooleanIfAbsent(T key, BooleanSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - boolean newValue = mappingFunction.test(key); + boolean newValue = valueProvider.getAsBoolean(); insert(-index-1, key, newValue); return newValue; } @@ -457,34 +451,50 @@ public boolean computeBooleanIfAbsent(T key, Predicate mappingFunction) { } @Override - public boolean computeBooleanIfAbsentNonDefault(T key, Predicate mappingFunction) { + public boolean computeBooleanIfPresent(T key, ObjectBooleanUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public boolean computeBooleanNonDefault(T key, ObjectBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - boolean newValue = mappingFunction.test(key); + boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - boolean newValue = values[index]; + boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.test(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public boolean supplyBooleanIfAbsent(T key, BooleanSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public boolean computeBooleanIfAbsentNonDefault(T key, Predicate mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - boolean newValue = valueProvider.getAsBoolean(); + boolean newValue = mappingFunction.test(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } boolean newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.test(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -507,16 +517,6 @@ public boolean supplyBooleanIfAbsentNonDefault(T key, BooleanSupplier valueProvi return newValue; } - @Override - public boolean computeBooleanIfPresent(T key, ObjectBooleanUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public boolean computeBooleanIfPresentNonDefault(T key, ObjectBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2ByteOpenCustomHashMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2ByteOpenCustomHashMap.java index 749ef9cd..abbafaf6 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2ByteOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2ByteOpenCustomHashMap.java @@ -447,30 +447,24 @@ public byte computeByte(T key, ObjectByteUnaryOperator mappingFunction) { } @Override - public byte computeByteNonDefault(T key, ObjectByteUnaryOperator mappingFunction) { + public byte computeByteIfAbsent(T key, ToByteFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + byte newValue = mappingFunction.applyAsByte(key); insert(-index-1, key, newValue); return newValue; } - byte newValue = mappingFunction.applyAsByte(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + byte newValue = values[index]; return newValue; } - + @Override - public byte computeByteIfAbsent(T key, ToByteFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public byte supplyByteIfAbsent(T key, ByteSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = valueProvider.getAsByte(); insert(-index-1, key, newValue); return newValue; } @@ -479,34 +473,50 @@ public byte computeByteIfAbsent(T key, ToByteFunction mappingFunction) { } @Override - public byte computeByteIfAbsentNonDefault(T key, ToByteFunction mappingFunction) { + public byte computeByteIfPresent(T key, ObjectByteUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + byte newValue = mappingFunction.applyAsByte(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public byte computeByteNonDefault(T key, ObjectByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - byte newValue = values[index]; + byte newValue = mappingFunction.applyAsByte(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsByte(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public byte supplyByteIfAbsent(T key, ByteSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public byte computeByteIfAbsentNonDefault(T key, ToByteFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - byte newValue = valueProvider.getAsInt(); + byte newValue = mappingFunction.applyAsByte(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } byte newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsByte(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -515,30 +525,20 @@ public byte supplyByteIfAbsentNonDefault(T key, ByteSupplier valueProvider) { Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - byte newValue = valueProvider.getAsInt(); + byte newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } byte newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public byte computeByteIfPresent(T key, ObjectByteUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - byte newValue = mappingFunction.applyAsByte(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public byte computeByteIfPresentNonDefault(T key, ObjectByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2CharOpenCustomHashMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2CharOpenCustomHashMap.java index 1bdd481d..31638241 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2CharOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2CharOpenCustomHashMap.java @@ -447,30 +447,24 @@ public char computeChar(T key, ObjectCharUnaryOperator mappingFunction) { } @Override - public char computeCharNonDefault(T key, ObjectCharUnaryOperator mappingFunction) { + public char computeCharIfAbsent(T key, ToCharFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + char newValue = mappingFunction.applyAsChar(key); insert(-index-1, key, newValue); return newValue; } - char newValue = mappingFunction.applyAsChar(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + char newValue = values[index]; return newValue; } - + @Override - public char computeCharIfAbsent(T key, ToCharFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public char supplyCharIfAbsent(T key, CharSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = valueProvider.getAsChar(); insert(-index-1, key, newValue); return newValue; } @@ -479,34 +473,50 @@ public char computeCharIfAbsent(T key, ToCharFunction mappingFunction) { } @Override - public char computeCharIfAbsentNonDefault(T key, ToCharFunction mappingFunction) { + public char computeCharIfPresent(T key, ObjectCharUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + char newValue = mappingFunction.applyAsChar(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public char computeCharNonDefault(T key, ObjectCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - char newValue = values[index]; + char newValue = mappingFunction.applyAsChar(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsChar(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public char supplyCharIfAbsent(T key, CharSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public char computeCharIfAbsentNonDefault(T key, ToCharFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - char newValue = valueProvider.getAsInt(); + char newValue = mappingFunction.applyAsChar(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } char newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsChar(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -515,30 +525,20 @@ public char supplyCharIfAbsentNonDefault(T key, CharSupplier valueProvider) { Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - char newValue = valueProvider.getAsInt(); + char newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } char newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public char computeCharIfPresent(T key, ObjectCharUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - char newValue = mappingFunction.applyAsChar(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public char computeCharIfPresentNonDefault(T key, ObjectCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2DoubleOpenCustomHashMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2DoubleOpenCustomHashMap.java index e475df9e..281c4d37 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2DoubleOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2DoubleOpenCustomHashMap.java @@ -447,30 +447,24 @@ public double computeDouble(T key, ObjectDoubleUnaryOperator mappingFunction) } @Override - public double computeDoubleNonDefault(T key, ObjectDoubleUnaryOperator mappingFunction) { + public double computeDoubleIfAbsent(T key, ToDoubleFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + double newValue = mappingFunction.applyAsDouble(key); insert(-index-1, key, newValue); return newValue; } - double newValue = mappingFunction.applyAsDouble(key, values[index]); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + double newValue = values[index]; return newValue; } - + @Override - public double computeDoubleIfAbsent(T key, ToDoubleFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public double supplyDoubleIfAbsent(T key, DoubleSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = valueProvider.getAsDouble(); insert(-index-1, key, newValue); return newValue; } @@ -479,34 +473,50 @@ public double computeDoubleIfAbsent(T key, ToDoubleFunction mappingFunction) } @Override - public double computeDoubleIfAbsentNonDefault(T key, ToDoubleFunction mappingFunction) { + public double computeDoubleIfPresent(T key, ObjectDoubleUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + double newValue = mappingFunction.applyAsDouble(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public double computeDoubleNonDefault(T key, ObjectDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } - double newValue = values[index]; + double newValue = mappingFunction.applyAsDouble(key, values[index]); if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - newValue = mappingFunction.applyAsDouble(key); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public double supplyDoubleIfAbsent(T key, DoubleSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public double computeDoubleIfAbsentNonDefault(T key, ToDoubleFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - double newValue = valueProvider.getAsDouble(); + double newValue = mappingFunction.applyAsDouble(key); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } double newValue = values[index]; + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { + newValue = mappingFunction.applyAsDouble(key); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + values[index] = newValue; + } return newValue; } @@ -529,16 +539,6 @@ public double supplyDoubleIfAbsentNonDefault(T key, DoubleSupplier valueProvider return newValue; } - @Override - public double computeDoubleIfPresent(T key, ObjectDoubleUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - double newValue = mappingFunction.applyAsDouble(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public double computeDoubleIfPresentNonDefault(T key, ObjectDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2FloatOpenCustomHashMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2FloatOpenCustomHashMap.java index a07dc01f..741f6726 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2FloatOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2FloatOpenCustomHashMap.java @@ -447,30 +447,24 @@ public float computeFloat(T key, ObjectFloatUnaryOperator mappingFunction) { } @Override - public float computeFloatNonDefault(T key, ObjectFloatUnaryOperator mappingFunction) { + public float computeFloatIfAbsent(T key, ToFloatFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + float newValue = mappingFunction.applyAsFloat(key); insert(-index-1, key, newValue); return newValue; } - float newValue = mappingFunction.applyAsFloat(key, values[index]); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + float newValue = values[index]; return newValue; } - + @Override - public float computeFloatIfAbsent(T key, ToFloatFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public float supplyFloatIfAbsent(T key, FloatSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = valueProvider.getAsFloat(); insert(-index-1, key, newValue); return newValue; } @@ -479,34 +473,50 @@ public float computeFloatIfAbsent(T key, ToFloatFunction mappingFunction) { } @Override - public float computeFloatIfAbsentNonDefault(T key, ToFloatFunction mappingFunction) { + public float computeFloatIfPresent(T key, ObjectFloatUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + float newValue = mappingFunction.applyAsFloat(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public float computeFloatNonDefault(T key, ObjectFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } - float newValue = values[index]; + float newValue = mappingFunction.applyAsFloat(key, values[index]); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - newValue = mappingFunction.applyAsFloat(key); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public float supplyFloatIfAbsent(T key, FloatSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public float computeFloatIfAbsentNonDefault(T key, ToFloatFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - float newValue = valueProvider.getAsDouble(); + float newValue = mappingFunction.applyAsFloat(key); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } float newValue = values[index]; + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { + newValue = mappingFunction.applyAsFloat(key); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + values[index] = newValue; + } return newValue; } @@ -515,30 +525,20 @@ public float supplyFloatIfAbsentNonDefault(T key, FloatSupplier valueProvider) { Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - float newValue = valueProvider.getAsDouble(); + float newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } float newValue = values[index]; if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - newValue = valueProvider.getAsDouble(); + newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; values[index] = newValue; } return newValue; } - @Override - public float computeFloatIfPresent(T key, ObjectFloatUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - float newValue = mappingFunction.applyAsFloat(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public float computeFloatIfPresentNonDefault(T key, ObjectFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2IntOpenCustomHashMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2IntOpenCustomHashMap.java index 4cf3e3c1..84418309 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2IntOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2IntOpenCustomHashMap.java @@ -447,30 +447,24 @@ public int computeInt(T key, ObjectIntUnaryOperator mappingFunction) { } @Override - public int computeIntNonDefault(T key, ObjectIntUnaryOperator mappingFunction) { + public int computeIntIfAbsent(T key, ToIntFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + int newValue = mappingFunction.applyAsInt(key); insert(-index-1, key, newValue); return newValue; } - int newValue = mappingFunction.applyAsInt(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + int newValue = values[index]; return newValue; } - + @Override - public int computeIntIfAbsent(T key, ToIntFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public int supplyIntIfAbsent(T key, IntSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = valueProvider.getAsInt(); insert(-index-1, key, newValue); return newValue; } @@ -479,34 +473,50 @@ public int computeIntIfAbsent(T key, ToIntFunction mappingFunction) { } @Override - public int computeIntIfAbsentNonDefault(T key, ToIntFunction mappingFunction) { + public int computeIntIfPresent(T key, ObjectIntUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + int newValue = mappingFunction.applyAsInt(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public int computeIntNonDefault(T key, ObjectIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - int newValue = values[index]; + int newValue = mappingFunction.applyAsInt(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsInt(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public int supplyIntIfAbsent(T key, IntSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public int computeIntIfAbsentNonDefault(T key, ToIntFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - int newValue = valueProvider.getAsInt(); + int newValue = mappingFunction.applyAsInt(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } int newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsInt(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -529,16 +539,6 @@ public int supplyIntIfAbsentNonDefault(T key, IntSupplier valueProvider) { return newValue; } - @Override - public int computeIntIfPresent(T key, ObjectIntUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - int newValue = mappingFunction.applyAsInt(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public int computeIntIfPresentNonDefault(T key, ObjectIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2LongOpenCustomHashMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2LongOpenCustomHashMap.java index f4c9c45d..f3245eb0 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2LongOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2LongOpenCustomHashMap.java @@ -447,30 +447,24 @@ public long computeLong(T key, ObjectLongUnaryOperator mappingFunction) { } @Override - public long computeLongNonDefault(T key, ObjectLongUnaryOperator mappingFunction) { + public long computeLongIfAbsent(T key, ToLongFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + long newValue = mappingFunction.applyAsLong(key); insert(-index-1, key, newValue); return newValue; } - long newValue = mappingFunction.applyAsLong(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + long newValue = values[index]; return newValue; } - + @Override - public long computeLongIfAbsent(T key, ToLongFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public long supplyLongIfAbsent(T key, LongSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = valueProvider.getAsLong(); insert(-index-1, key, newValue); return newValue; } @@ -479,34 +473,50 @@ public long computeLongIfAbsent(T key, ToLongFunction mappingFunction) { } @Override - public long computeLongIfAbsentNonDefault(T key, ToLongFunction mappingFunction) { + public long computeLongIfPresent(T key, ObjectLongUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + long newValue = mappingFunction.applyAsLong(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public long computeLongNonDefault(T key, ObjectLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - long newValue = values[index]; + long newValue = mappingFunction.applyAsLong(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsLong(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public long supplyLongIfAbsent(T key, LongSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public long computeLongIfAbsentNonDefault(T key, ToLongFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - long newValue = valueProvider.getAsLong(); + long newValue = mappingFunction.applyAsLong(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } long newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsLong(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -529,16 +539,6 @@ public long supplyLongIfAbsentNonDefault(T key, LongSupplier valueProvider) { return newValue; } - @Override - public long computeLongIfPresent(T key, ObjectLongUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - long newValue = mappingFunction.applyAsLong(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public long computeLongIfPresentNonDefault(T key, ObjectLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2ObjectOpenCustomHashMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2ObjectOpenCustomHashMap.java index 0a6c4c30..bb39a870 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2ObjectOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2ObjectOpenCustomHashMap.java @@ -359,25 +359,6 @@ public V compute(T key, ObjectObjectUnaryOperator mappingFunction) { return newValue; } - @Override - public V computeNonDefault(T key, ObjectObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) { - V newValue = mappingFunction.apply(key, getDefaultReturnValue()); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = mappingFunction.apply(key, values[index]); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; - return newValue; - } - @Override public V computeIfAbsent(T key, UnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -396,26 +377,7 @@ public V computeIfAbsent(T key, UnaryOperator mappingFunction) { } return newValue; } - - @Override - public V computeIfAbsentNonDefault(T key, UnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) { - V newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = values[index]; - if(Objects.equals(newValue, getDefaultReturnValue())) { - newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - values[index] = newValue; - } - return newValue; - } - + @Override public V supplyIfAbsent(T key, ObjectSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -435,25 +397,6 @@ public V supplyIfAbsent(T key, ObjectSupplier valueProvider) { return newValue; } - @Override - public V supplyIfAbsentNonDefault(T key, ObjectSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - int index = findIndex(key); - if(index < 0) { - V newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = values[index]; - if(Objects.equals(newValue, getDefaultReturnValue())) { - newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - values[index] = newValue; - } - return newValue; - } - @Override public V computeIfPresent(T key, ObjectObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -468,20 +411,6 @@ public V computeIfPresent(T key, ObjectObjectUnaryOperator mappingFunction return newValue; } - @Override - public V computeIfPresentNonDefault(T key, ObjectObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0 || Objects.equals(values[index], getDefaultReturnValue())) return getDefaultReturnValue(); - V newValue = mappingFunction.apply(key, values[index]); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; - return newValue; - } - @Override public V merge(T key, V value, ObjectObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2ShortOpenCustomHashMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2ShortOpenCustomHashMap.java index 8b134fb5..3359c790 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2ShortOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/customHash/Object2ShortOpenCustomHashMap.java @@ -447,30 +447,24 @@ public short computeShort(T key, ObjectShortUnaryOperator mappingFunction) { } @Override - public short computeShortNonDefault(T key, ObjectShortUnaryOperator mappingFunction) { + public short computeShortIfAbsent(T key, ToShortFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + short newValue = mappingFunction.applyAsShort(key); insert(-index-1, key, newValue); return newValue; } - short newValue = mappingFunction.applyAsShort(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + short newValue = values[index]; return newValue; } - + @Override - public short computeShortIfAbsent(T key, ToShortFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public short supplyShortIfAbsent(T key, ShortSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = valueProvider.getAsShort(); insert(-index-1, key, newValue); return newValue; } @@ -479,34 +473,50 @@ public short computeShortIfAbsent(T key, ToShortFunction mappingFunction) { } @Override - public short computeShortIfAbsentNonDefault(T key, ToShortFunction mappingFunction) { + public short computeShortIfPresent(T key, ObjectShortUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + short newValue = mappingFunction.applyAsShort(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public short computeShortNonDefault(T key, ObjectShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - short newValue = values[index]; + short newValue = mappingFunction.applyAsShort(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsShort(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public short supplyShortIfAbsent(T key, ShortSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public short computeShortIfAbsentNonDefault(T key, ToShortFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - short newValue = valueProvider.getAsInt(); + short newValue = mappingFunction.applyAsShort(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } short newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsShort(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -515,30 +525,20 @@ public short supplyShortIfAbsentNonDefault(T key, ShortSupplier valueProvider) { Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - short newValue = valueProvider.getAsInt(); + short newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } short newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public short computeShortIfPresent(T key, ObjectShortUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - short newValue = mappingFunction.applyAsShort(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public short computeShortIfPresentNonDefault(T key, ObjectShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2BooleanOpenHashMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2BooleanOpenHashMap.java index 2cea87a2..d70a287e 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2BooleanOpenHashMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2BooleanOpenHashMap.java @@ -396,68 +396,78 @@ public boolean computeBoolean(T key, ObjectBooleanUnaryOperator mappingFuncti values[index] = newValue; return newValue; } - + @Override - public boolean computeBooleanNonDefault(T key, ObjectBooleanUnaryOperator mappingFunction) { + public boolean computeBooleanIfAbsent(T key, Predicate mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + boolean newValue = mappingFunction.test(key); insert(-index-1, key, newValue); return newValue; } - boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + boolean newValue = values[index]; return newValue; } @Override - public boolean computeBooleanIfAbsent(T key, Predicate mappingFunction) { - Objects.requireNonNull(mappingFunction); + public boolean supplyBooleanIfAbsent(T key, BooleanSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - boolean newValue = mappingFunction.test(key); + boolean newValue = valueProvider.getAsBoolean(); insert(-index-1, key, newValue); return newValue; } boolean newValue = values[index]; return newValue; } + + @Override + public boolean computeBooleanIfPresent(T key, ObjectBooleanUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public boolean computeBooleanIfAbsentNonDefault(T key, Predicate mappingFunction) { + public boolean computeBooleanNonDefault(T key, ObjectBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - boolean newValue = mappingFunction.test(key); + boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - boolean newValue = values[index]; + boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.test(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public boolean supplyBooleanIfAbsent(T key, BooleanSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public boolean computeBooleanIfAbsentNonDefault(T key, Predicate mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - boolean newValue = valueProvider.getAsBoolean(); + boolean newValue = mappingFunction.test(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } boolean newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.test(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -480,16 +490,6 @@ public boolean supplyBooleanIfAbsentNonDefault(T key, BooleanSupplier valueProvi return newValue; } - @Override - public boolean computeBooleanIfPresent(T key, ObjectBooleanUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public boolean computeBooleanIfPresentNonDefault(T key, ObjectBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2ByteOpenHashMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2ByteOpenHashMap.java index 71398d0d..a5d7f783 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2ByteOpenHashMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2ByteOpenHashMap.java @@ -418,68 +418,78 @@ public byte computeByte(T key, ObjectByteUnaryOperator mappingFunction) { values[index] = newValue; return newValue; } - + @Override - public byte computeByteNonDefault(T key, ObjectByteUnaryOperator mappingFunction) { + public byte computeByteIfAbsent(T key, ToByteFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + byte newValue = mappingFunction.applyAsByte(key); insert(-index-1, key, newValue); return newValue; } - byte newValue = mappingFunction.applyAsByte(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + byte newValue = values[index]; return newValue; } @Override - public byte computeByteIfAbsent(T key, ToByteFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public byte supplyByteIfAbsent(T key, ByteSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = valueProvider.getAsByte(); insert(-index-1, key, newValue); return newValue; } byte newValue = values[index]; return newValue; } + + @Override + public byte computeByteIfPresent(T key, ObjectByteUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + byte newValue = mappingFunction.applyAsByte(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public byte computeByteIfAbsentNonDefault(T key, ToByteFunction mappingFunction) { + public byte computeByteNonDefault(T key, ObjectByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - byte newValue = values[index]; + byte newValue = mappingFunction.applyAsByte(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsByte(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public byte supplyByteIfAbsent(T key, ByteSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public byte computeByteIfAbsentNonDefault(T key, ToByteFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - byte newValue = valueProvider.getAsInt(); + byte newValue = mappingFunction.applyAsByte(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } byte newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsByte(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -488,30 +498,20 @@ public byte supplyByteIfAbsentNonDefault(T key, ByteSupplier valueProvider) { Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - byte newValue = valueProvider.getAsInt(); + byte newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } byte newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public byte computeByteIfPresent(T key, ObjectByteUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - byte newValue = mappingFunction.applyAsByte(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public byte computeByteIfPresentNonDefault(T key, ObjectByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2CharOpenHashMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2CharOpenHashMap.java index 283d46ad..6c921e41 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2CharOpenHashMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2CharOpenHashMap.java @@ -418,68 +418,78 @@ public char computeChar(T key, ObjectCharUnaryOperator mappingFunction) { values[index] = newValue; return newValue; } - + @Override - public char computeCharNonDefault(T key, ObjectCharUnaryOperator mappingFunction) { + public char computeCharIfAbsent(T key, ToCharFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + char newValue = mappingFunction.applyAsChar(key); insert(-index-1, key, newValue); return newValue; } - char newValue = mappingFunction.applyAsChar(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + char newValue = values[index]; return newValue; } @Override - public char computeCharIfAbsent(T key, ToCharFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public char supplyCharIfAbsent(T key, CharSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = valueProvider.getAsChar(); insert(-index-1, key, newValue); return newValue; } char newValue = values[index]; return newValue; } + + @Override + public char computeCharIfPresent(T key, ObjectCharUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + char newValue = mappingFunction.applyAsChar(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public char computeCharIfAbsentNonDefault(T key, ToCharFunction mappingFunction) { + public char computeCharNonDefault(T key, ObjectCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - char newValue = values[index]; + char newValue = mappingFunction.applyAsChar(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsChar(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public char supplyCharIfAbsent(T key, CharSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public char computeCharIfAbsentNonDefault(T key, ToCharFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - char newValue = valueProvider.getAsInt(); + char newValue = mappingFunction.applyAsChar(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } char newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsChar(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -488,30 +498,20 @@ public char supplyCharIfAbsentNonDefault(T key, CharSupplier valueProvider) { Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - char newValue = valueProvider.getAsInt(); + char newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } char newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public char computeCharIfPresent(T key, ObjectCharUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - char newValue = mappingFunction.applyAsChar(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public char computeCharIfPresentNonDefault(T key, ObjectCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2DoubleOpenHashMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2DoubleOpenHashMap.java index a2794929..fde7098f 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2DoubleOpenHashMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2DoubleOpenHashMap.java @@ -418,68 +418,78 @@ public double computeDouble(T key, ObjectDoubleUnaryOperator mappingFunction) values[index] = newValue; return newValue; } - + @Override - public double computeDoubleNonDefault(T key, ObjectDoubleUnaryOperator mappingFunction) { + public double computeDoubleIfAbsent(T key, ToDoubleFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + double newValue = mappingFunction.applyAsDouble(key); insert(-index-1, key, newValue); return newValue; } - double newValue = mappingFunction.applyAsDouble(key, values[index]); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + double newValue = values[index]; return newValue; } @Override - public double computeDoubleIfAbsent(T key, ToDoubleFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public double supplyDoubleIfAbsent(T key, DoubleSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = valueProvider.getAsDouble(); insert(-index-1, key, newValue); return newValue; } double newValue = values[index]; return newValue; } + + @Override + public double computeDoubleIfPresent(T key, ObjectDoubleUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + double newValue = mappingFunction.applyAsDouble(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public double computeDoubleIfAbsentNonDefault(T key, ToDoubleFunction mappingFunction) { + public double computeDoubleNonDefault(T key, ObjectDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } - double newValue = values[index]; + double newValue = mappingFunction.applyAsDouble(key, values[index]); if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - newValue = mappingFunction.applyAsDouble(key); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public double supplyDoubleIfAbsent(T key, DoubleSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public double computeDoubleIfAbsentNonDefault(T key, ToDoubleFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - double newValue = valueProvider.getAsDouble(); + double newValue = mappingFunction.applyAsDouble(key); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } double newValue = values[index]; + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { + newValue = mappingFunction.applyAsDouble(key); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + values[index] = newValue; + } return newValue; } @@ -502,16 +512,6 @@ public double supplyDoubleIfAbsentNonDefault(T key, DoubleSupplier valueProvider return newValue; } - @Override - public double computeDoubleIfPresent(T key, ObjectDoubleUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - double newValue = mappingFunction.applyAsDouble(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public double computeDoubleIfPresentNonDefault(T key, ObjectDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2FloatOpenHashMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2FloatOpenHashMap.java index c5a5edc3..0c9f39b0 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2FloatOpenHashMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2FloatOpenHashMap.java @@ -418,68 +418,78 @@ public float computeFloat(T key, ObjectFloatUnaryOperator mappingFunction) { values[index] = newValue; return newValue; } - + @Override - public float computeFloatNonDefault(T key, ObjectFloatUnaryOperator mappingFunction) { + public float computeFloatIfAbsent(T key, ToFloatFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + float newValue = mappingFunction.applyAsFloat(key); insert(-index-1, key, newValue); return newValue; } - float newValue = mappingFunction.applyAsFloat(key, values[index]); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + float newValue = values[index]; return newValue; } @Override - public float computeFloatIfAbsent(T key, ToFloatFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public float supplyFloatIfAbsent(T key, FloatSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = valueProvider.getAsFloat(); insert(-index-1, key, newValue); return newValue; } float newValue = values[index]; return newValue; } + + @Override + public float computeFloatIfPresent(T key, ObjectFloatUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + float newValue = mappingFunction.applyAsFloat(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public float computeFloatIfAbsentNonDefault(T key, ToFloatFunction mappingFunction) { + public float computeFloatNonDefault(T key, ObjectFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } - float newValue = values[index]; + float newValue = mappingFunction.applyAsFloat(key, values[index]); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - newValue = mappingFunction.applyAsFloat(key); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public float supplyFloatIfAbsent(T key, FloatSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public float computeFloatIfAbsentNonDefault(T key, ToFloatFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - float newValue = valueProvider.getAsDouble(); + float newValue = mappingFunction.applyAsFloat(key); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } float newValue = values[index]; + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { + newValue = mappingFunction.applyAsFloat(key); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + values[index] = newValue; + } return newValue; } @@ -488,30 +498,20 @@ public float supplyFloatIfAbsentNonDefault(T key, FloatSupplier valueProvider) { Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - float newValue = valueProvider.getAsDouble(); + float newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } float newValue = values[index]; if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - newValue = valueProvider.getAsDouble(); + newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; values[index] = newValue; } return newValue; } - @Override - public float computeFloatIfPresent(T key, ObjectFloatUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - float newValue = mappingFunction.applyAsFloat(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public float computeFloatIfPresentNonDefault(T key, ObjectFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2IntOpenHashMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2IntOpenHashMap.java index 9c2a79ad..6b580f36 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2IntOpenHashMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2IntOpenHashMap.java @@ -418,68 +418,78 @@ public int computeInt(T key, ObjectIntUnaryOperator mappingFunction) { values[index] = newValue; return newValue; } - + @Override - public int computeIntNonDefault(T key, ObjectIntUnaryOperator mappingFunction) { + public int computeIntIfAbsent(T key, ToIntFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + int newValue = mappingFunction.applyAsInt(key); insert(-index-1, key, newValue); return newValue; } - int newValue = mappingFunction.applyAsInt(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + int newValue = values[index]; return newValue; } @Override - public int computeIntIfAbsent(T key, ToIntFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public int supplyIntIfAbsent(T key, IntSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = valueProvider.getAsInt(); insert(-index-1, key, newValue); return newValue; } int newValue = values[index]; return newValue; } + + @Override + public int computeIntIfPresent(T key, ObjectIntUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + int newValue = mappingFunction.applyAsInt(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public int computeIntIfAbsentNonDefault(T key, ToIntFunction mappingFunction) { + public int computeIntNonDefault(T key, ObjectIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - int newValue = values[index]; + int newValue = mappingFunction.applyAsInt(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsInt(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public int supplyIntIfAbsent(T key, IntSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public int computeIntIfAbsentNonDefault(T key, ToIntFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - int newValue = valueProvider.getAsInt(); + int newValue = mappingFunction.applyAsInt(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } int newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsInt(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -502,16 +512,6 @@ public int supplyIntIfAbsentNonDefault(T key, IntSupplier valueProvider) { return newValue; } - @Override - public int computeIntIfPresent(T key, ObjectIntUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - int newValue = mappingFunction.applyAsInt(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public int computeIntIfPresentNonDefault(T key, ObjectIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2LongOpenHashMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2LongOpenHashMap.java index 4f631c95..22c1ba5a 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2LongOpenHashMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2LongOpenHashMap.java @@ -418,68 +418,78 @@ public long computeLong(T key, ObjectLongUnaryOperator mappingFunction) { values[index] = newValue; return newValue; } - + @Override - public long computeLongNonDefault(T key, ObjectLongUnaryOperator mappingFunction) { + public long computeLongIfAbsent(T key, ToLongFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + long newValue = mappingFunction.applyAsLong(key); insert(-index-1, key, newValue); return newValue; } - long newValue = mappingFunction.applyAsLong(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + long newValue = values[index]; return newValue; } @Override - public long computeLongIfAbsent(T key, ToLongFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public long supplyLongIfAbsent(T key, LongSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = valueProvider.getAsLong(); insert(-index-1, key, newValue); return newValue; } long newValue = values[index]; return newValue; } + + @Override + public long computeLongIfPresent(T key, ObjectLongUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + long newValue = mappingFunction.applyAsLong(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public long computeLongIfAbsentNonDefault(T key, ToLongFunction mappingFunction) { + public long computeLongNonDefault(T key, ObjectLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - long newValue = values[index]; + long newValue = mappingFunction.applyAsLong(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsLong(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public long supplyLongIfAbsent(T key, LongSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public long computeLongIfAbsentNonDefault(T key, ToLongFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - long newValue = valueProvider.getAsLong(); + long newValue = mappingFunction.applyAsLong(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } long newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsLong(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -502,16 +512,6 @@ public long supplyLongIfAbsentNonDefault(T key, LongSupplier valueProvider) { return newValue; } - @Override - public long computeLongIfPresent(T key, ObjectLongUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - long newValue = mappingFunction.applyAsLong(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public long computeLongIfPresentNonDefault(T key, ObjectLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2ObjectOpenHashMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2ObjectOpenHashMap.java index 911915d3..b0a03cdf 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2ObjectOpenHashMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2ObjectOpenHashMap.java @@ -336,26 +336,7 @@ public V compute(T key, ObjectObjectUnaryOperator mappingFunction) { values[index] = newValue; return newValue; } - - @Override - public V computeNonDefault(T key, ObjectObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) { - V newValue = mappingFunction.apply(key, getDefaultReturnValue()); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = mappingFunction.apply(key, values[index]); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; - return newValue; - } - + @Override public V computeIfAbsent(T key, UnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -375,25 +356,6 @@ public V computeIfAbsent(T key, UnaryOperator mappingFunction) { return newValue; } - @Override - public V computeIfAbsentNonDefault(T key, UnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) { - V newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = values[index]; - if(Objects.equals(newValue, getDefaultReturnValue())) { - newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - values[index] = newValue; - } - return newValue; - } - @Override public V supplyIfAbsent(T key, ObjectSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -412,26 +374,7 @@ public V supplyIfAbsent(T key, ObjectSupplier valueProvider) { } return newValue; } - - @Override - public V supplyIfAbsentNonDefault(T key, ObjectSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - int index = findIndex(key); - if(index < 0) { - V newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = values[index]; - if(Objects.equals(newValue, getDefaultReturnValue())) { - newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - values[index] = newValue; - } - return newValue; - } - + @Override public V computeIfPresent(T key, ObjectObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -446,20 +389,6 @@ public V computeIfPresent(T key, ObjectObjectUnaryOperator mappingFunction return newValue; } - @Override - public V computeIfPresentNonDefault(T key, ObjectObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0 || Objects.equals(values[index], getDefaultReturnValue())) return getDefaultReturnValue(); - V newValue = mappingFunction.apply(key, values[index]); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; - return newValue; - } - @Override public V merge(T key, V value, ObjectObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2ShortOpenHashMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2ShortOpenHashMap.java index edb27a07..9e94053b 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2ShortOpenHashMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/hash/Object2ShortOpenHashMap.java @@ -418,68 +418,78 @@ public short computeShort(T key, ObjectShortUnaryOperator mappingFunction) { values[index] = newValue; return newValue; } - + @Override - public short computeShortNonDefault(T key, ObjectShortUnaryOperator mappingFunction) { + public short computeShortIfAbsent(T key, ToShortFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + short newValue = mappingFunction.applyAsShort(key); insert(-index-1, key, newValue); return newValue; } - short newValue = mappingFunction.applyAsShort(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + short newValue = values[index]; return newValue; } @Override - public short computeShortIfAbsent(T key, ToShortFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public short supplyShortIfAbsent(T key, ShortSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = valueProvider.getAsShort(); insert(-index-1, key, newValue); return newValue; } short newValue = values[index]; return newValue; } + + @Override + public short computeShortIfPresent(T key, ObjectShortUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + short newValue = mappingFunction.applyAsShort(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public short computeShortIfAbsentNonDefault(T key, ToShortFunction mappingFunction) { + public short computeShortNonDefault(T key, ObjectShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - short newValue = values[index]; + short newValue = mappingFunction.applyAsShort(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsShort(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public short supplyShortIfAbsent(T key, ShortSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public short computeShortIfAbsentNonDefault(T key, ToShortFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - short newValue = valueProvider.getAsInt(); + short newValue = mappingFunction.applyAsShort(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } short newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsShort(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -488,30 +498,20 @@ public short supplyShortIfAbsentNonDefault(T key, ShortSupplier valueProvider) { Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - short newValue = valueProvider.getAsInt(); + short newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } short newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public short computeShortIfPresent(T key, ObjectShortUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - short newValue = mappingFunction.applyAsShort(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public short computeShortIfPresentNonDefault(T key, ObjectShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/immutable/ImmutableObject2BooleanOpenHashMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/immutable/ImmutableObject2BooleanOpenHashMap.java index 3f78f8f0..ccbf6c3d 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/immutable/ImmutableObject2BooleanOpenHashMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/immutable/ImmutableObject2BooleanOpenHashMap.java @@ -397,20 +397,19 @@ public void forEach(ObjectBooleanConsumer action) { @Override public boolean computeBoolean(T key, ObjectBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanNonDefault(T key, ObjectBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean computeBooleanIfAbsent(T key, Predicate mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanIfAbsentNonDefault(T key, Predicate mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean supplyBooleanIfAbsent(T key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public boolean supplyBooleanIfAbsentNonDefault(T key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public boolean computeBooleanIfPresent(T key, ObjectBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override + public boolean computeBooleanNonDefault(T key, ObjectBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public boolean computeBooleanIfAbsentNonDefault(T key, Predicate mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public boolean supplyBooleanIfAbsentNonDefault(T key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } + @Override public boolean computeBooleanIfPresentNonDefault(T key, ObjectBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean mergeBoolean(T key, boolean value, BooleanBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/immutable/ImmutableObject2ByteOpenHashMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/immutable/ImmutableObject2ByteOpenHashMap.java index 3dadab3a..0e22bab7 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/immutable/ImmutableObject2ByteOpenHashMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/immutable/ImmutableObject2ByteOpenHashMap.java @@ -402,20 +402,19 @@ public void forEach(ObjectByteConsumer action) { @Override public byte computeByte(T key, ObjectByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteNonDefault(T key, ObjectByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte computeByteIfAbsent(T key, ToByteFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteIfAbsentNonDefault(T key, ToByteFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte supplyByteIfAbsent(T key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public byte supplyByteIfAbsentNonDefault(T key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public byte computeByteIfPresent(T key, ObjectByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override + public byte computeByteNonDefault(T key, ObjectByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public byte computeByteIfAbsentNonDefault(T key, ToByteFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public byte supplyByteIfAbsentNonDefault(T key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } + @Override public byte computeByteIfPresentNonDefault(T key, ObjectByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte mergeByte(T key, byte value, ByteByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/immutable/ImmutableObject2CharOpenHashMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/immutable/ImmutableObject2CharOpenHashMap.java index 94178468..027799ba 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/immutable/ImmutableObject2CharOpenHashMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/immutable/ImmutableObject2CharOpenHashMap.java @@ -402,20 +402,19 @@ public void forEach(ObjectCharConsumer action) { @Override public char computeChar(T key, ObjectCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharNonDefault(T key, ObjectCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char computeCharIfAbsent(T key, ToCharFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharIfAbsentNonDefault(T key, ToCharFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char supplyCharIfAbsent(T key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public char supplyCharIfAbsentNonDefault(T key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public char computeCharIfPresent(T key, ObjectCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override + public char computeCharNonDefault(T key, ObjectCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public char computeCharIfAbsentNonDefault(T key, ToCharFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public char supplyCharIfAbsentNonDefault(T key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } + @Override public char computeCharIfPresentNonDefault(T key, ObjectCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char mergeChar(T key, char value, CharCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/immutable/ImmutableObject2DoubleOpenHashMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/immutable/ImmutableObject2DoubleOpenHashMap.java index 2a32028f..78e4be2b 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/immutable/ImmutableObject2DoubleOpenHashMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/immutable/ImmutableObject2DoubleOpenHashMap.java @@ -402,20 +402,19 @@ public void forEach(ObjectDoubleConsumer action) { @Override public double computeDouble(T key, ObjectDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleNonDefault(T key, ObjectDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double computeDoubleIfAbsent(T key, ToDoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleIfAbsentNonDefault(T key, ToDoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double supplyDoubleIfAbsent(T key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public double supplyDoubleIfAbsentNonDefault(T key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public double computeDoubleIfPresent(T key, ObjectDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override + public double computeDoubleNonDefault(T key, ObjectDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public double computeDoubleIfAbsentNonDefault(T key, ToDoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public double supplyDoubleIfAbsentNonDefault(T key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } + @Override public double computeDoubleIfPresentNonDefault(T key, ObjectDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double mergeDouble(T key, double value, DoubleDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/immutable/ImmutableObject2FloatOpenHashMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/immutable/ImmutableObject2FloatOpenHashMap.java index d000956b..2a99403e 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/immutable/ImmutableObject2FloatOpenHashMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/immutable/ImmutableObject2FloatOpenHashMap.java @@ -402,20 +402,19 @@ public void forEach(ObjectFloatConsumer action) { @Override public float computeFloat(T key, ObjectFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatNonDefault(T key, ObjectFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float computeFloatIfAbsent(T key, ToFloatFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatIfAbsentNonDefault(T key, ToFloatFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float supplyFloatIfAbsent(T key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public float supplyFloatIfAbsentNonDefault(T key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public float computeFloatIfPresent(T key, ObjectFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override + public float computeFloatNonDefault(T key, ObjectFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public float computeFloatIfAbsentNonDefault(T key, ToFloatFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public float supplyFloatIfAbsentNonDefault(T key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } + @Override public float computeFloatIfPresentNonDefault(T key, ObjectFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float mergeFloat(T key, float value, FloatFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/immutable/ImmutableObject2IntOpenHashMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/immutable/ImmutableObject2IntOpenHashMap.java index 7408cfdf..b0ab5b4c 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/immutable/ImmutableObject2IntOpenHashMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/immutable/ImmutableObject2IntOpenHashMap.java @@ -402,20 +402,19 @@ public void forEach(ObjectIntConsumer action) { @Override public int computeInt(T key, ObjectIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntNonDefault(T key, ObjectIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int computeIntIfAbsent(T key, ToIntFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntIfAbsentNonDefault(T key, ToIntFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int supplyIntIfAbsent(T key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public int supplyIntIfAbsentNonDefault(T key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public int computeIntIfPresent(T key, ObjectIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override + public int computeIntNonDefault(T key, ObjectIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public int computeIntIfAbsentNonDefault(T key, ToIntFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public int supplyIntIfAbsentNonDefault(T key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } + @Override public int computeIntIfPresentNonDefault(T key, ObjectIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int mergeInt(T key, int value, IntIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/immutable/ImmutableObject2LongOpenHashMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/immutable/ImmutableObject2LongOpenHashMap.java index 92560a12..c611f80a 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/immutable/ImmutableObject2LongOpenHashMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/immutable/ImmutableObject2LongOpenHashMap.java @@ -402,20 +402,19 @@ public void forEach(ObjectLongConsumer action) { @Override public long computeLong(T key, ObjectLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongNonDefault(T key, ObjectLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long computeLongIfAbsent(T key, ToLongFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongIfAbsentNonDefault(T key, ToLongFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long supplyLongIfAbsent(T key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public long supplyLongIfAbsentNonDefault(T key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public long computeLongIfPresent(T key, ObjectLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override + public long computeLongNonDefault(T key, ObjectLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public long computeLongIfAbsentNonDefault(T key, ToLongFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public long supplyLongIfAbsentNonDefault(T key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } + @Override public long computeLongIfPresentNonDefault(T key, ObjectLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long mergeLong(T key, long value, LongLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/immutable/ImmutableObject2ObjectOpenHashMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/immutable/ImmutableObject2ObjectOpenHashMap.java index ec8ecf4c..6e6aa9ca 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/immutable/ImmutableObject2ObjectOpenHashMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/immutable/ImmutableObject2ObjectOpenHashMap.java @@ -353,20 +353,11 @@ public void forEach(ObjectObjectConsumer action) { @Override public V compute(T key, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeNonDefault(T key, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V computeIfAbsent(T key, UnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeIfAbsentNonDefault(T key, UnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V supplyIfAbsent(T key, ObjectSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public V supplyIfAbsentNonDefault(T key, ObjectSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public V computeIfPresent(T key, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override - public V computeIfPresentNonDefault(T key, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V merge(T key, V value, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/immutable/ImmutableObject2ShortOpenHashMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/immutable/ImmutableObject2ShortOpenHashMap.java index f09c50d3..67dfc259 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/immutable/ImmutableObject2ShortOpenHashMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/immutable/ImmutableObject2ShortOpenHashMap.java @@ -402,20 +402,19 @@ public void forEach(ObjectShortConsumer action) { @Override public short computeShort(T key, ObjectShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortNonDefault(T key, ObjectShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short computeShortIfAbsent(T key, ToShortFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortIfAbsentNonDefault(T key, ToShortFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short supplyShortIfAbsent(T key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public short supplyShortIfAbsentNonDefault(T key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public short computeShortIfPresent(T key, ObjectShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override + public short computeShortNonDefault(T key, ObjectShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public short computeShortIfAbsentNonDefault(T key, ToShortFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public short supplyShortIfAbsentNonDefault(T key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } + @Override public short computeShortIfPresentNonDefault(T key, ObjectShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short mergeShort(T key, short value, ShortShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/misc/Enum2BooleanMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/misc/Enum2BooleanMap.java index 00eeee41..755a940d 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/misc/Enum2BooleanMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/misc/Enum2BooleanMap.java @@ -302,30 +302,23 @@ public boolean computeBoolean(T key, ObjectBooleanUnaryOperator mappingFuncti } @Override - public boolean computeBooleanNonDefault(T key, ObjectBooleanUnaryOperator mappingFunction) { + public boolean computeBooleanIfAbsent(T key, Predicate mappingFunction) { int index = key.ordinal(); if(!isSet(index)) { - boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + boolean newValue = mappingFunction.test(key); set(index); - values[index] = newValue; - return newValue; - } - boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); - if(newValue == getDefaultReturnValue()) { - clear(index); - values[index] = false; + values[index] = newValue; return newValue; } - values[index] = newValue; + boolean newValue = values[index]; return newValue; } - + @Override - public boolean computeBooleanIfAbsent(T key, Predicate mappingFunction) { + public boolean supplyBooleanIfAbsent(T key, BooleanSupplier valueProvider) { int index = key.ordinal(); if(!isSet(index)) { - boolean newValue = mappingFunction.test(key); + boolean newValue = valueProvider.getAsBoolean(); set(index); values[index] = newValue; return newValue; @@ -335,34 +328,50 @@ public boolean computeBooleanIfAbsent(T key, Predicate mappingFunction) { } @Override - public boolean computeBooleanIfAbsentNonDefault(T key, Predicate mappingFunction) { + public boolean computeBooleanIfPresent(T key, ObjectBooleanUnaryOperator mappingFunction) { + int index = key.ordinal(); + if(!isSet(index)) return getDefaultReturnValue(); + boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public boolean computeBooleanNonDefault(T key, ObjectBooleanUnaryOperator mappingFunction) { int index = key.ordinal(); if(!isSet(index)) { - boolean newValue = mappingFunction.test(key); + boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; set(index); - values[index] = newValue; + values[index] = newValue; return newValue; } - boolean newValue = values[index]; + boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.test(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + clear(index); + values[index] = false; + return newValue; } + values[index] = newValue; return newValue; } @Override - public boolean supplyBooleanIfAbsent(T key, BooleanSupplier valueProvider) { + public boolean computeBooleanIfAbsentNonDefault(T key, Predicate mappingFunction) { int index = key.ordinal(); if(!isSet(index)) { - boolean newValue = valueProvider.getAsBoolean(); + boolean newValue = mappingFunction.test(key); + if(newValue == getDefaultReturnValue()) return newValue; set(index); values[index] = newValue; return newValue; } boolean newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.test(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -385,15 +394,6 @@ public boolean supplyBooleanIfAbsentNonDefault(T key, BooleanSupplier valueProvi return newValue; } - @Override - public boolean computeBooleanIfPresent(T key, ObjectBooleanUnaryOperator mappingFunction) { - int index = key.ordinal(); - if(!isSet(index)) return getDefaultReturnValue(); - boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public boolean computeBooleanIfPresentNonDefault(T key, ObjectBooleanUnaryOperator mappingFunction) { int index = key.ordinal(); diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/misc/Enum2ByteMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/misc/Enum2ByteMap.java index c7deb341..ee3132c8 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/misc/Enum2ByteMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/misc/Enum2ByteMap.java @@ -327,30 +327,23 @@ public byte computeByte(T key, ObjectByteUnaryOperator mappingFunction) { } @Override - public byte computeByteNonDefault(T key, ObjectByteUnaryOperator mappingFunction) { + public byte computeByteIfAbsent(T key, ToByteFunction mappingFunction) { int index = key.ordinal(); if(!isSet(index)) { - byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + byte newValue = mappingFunction.applyAsByte(key); set(index); - values[index] = newValue; - return newValue; - } - byte newValue = mappingFunction.applyAsByte(key, values[index]); - if(newValue == getDefaultReturnValue()) { - clear(index); - values[index] = (byte)0; + values[index] = newValue; return newValue; } - values[index] = newValue; + byte newValue = values[index]; return newValue; } - + @Override - public byte computeByteIfAbsent(T key, ToByteFunction mappingFunction) { + public byte supplyByteIfAbsent(T key, ByteSupplier valueProvider) { int index = key.ordinal(); if(!isSet(index)) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = valueProvider.getAsByte(); set(index); values[index] = newValue; return newValue; @@ -360,34 +353,50 @@ public byte computeByteIfAbsent(T key, ToByteFunction mappingFunction) { } @Override - public byte computeByteIfAbsentNonDefault(T key, ToByteFunction mappingFunction) { + public byte computeByteIfPresent(T key, ObjectByteUnaryOperator mappingFunction) { + int index = key.ordinal(); + if(!isSet(index)) return getDefaultReturnValue(); + byte newValue = mappingFunction.applyAsByte(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public byte computeByteNonDefault(T key, ObjectByteUnaryOperator mappingFunction) { int index = key.ordinal(); if(!isSet(index)) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; set(index); - values[index] = newValue; + values[index] = newValue; return newValue; } - byte newValue = values[index]; + byte newValue = mappingFunction.applyAsByte(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsByte(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + clear(index); + values[index] = (byte)0; + return newValue; } + values[index] = newValue; return newValue; } @Override - public byte supplyByteIfAbsent(T key, ByteSupplier valueProvider) { + public byte computeByteIfAbsentNonDefault(T key, ToByteFunction mappingFunction) { int index = key.ordinal(); if(!isSet(index)) { - byte newValue = valueProvider.getAsInt(); + byte newValue = mappingFunction.applyAsByte(key); + if(newValue == getDefaultReturnValue()) return newValue; set(index); values[index] = newValue; return newValue; } byte newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsByte(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -395,7 +404,7 @@ public byte supplyByteIfAbsent(T key, ByteSupplier valueProvider) { public byte supplyByteIfAbsentNonDefault(T key, ByteSupplier valueProvider) { int index = key.ordinal(); if(!isSet(index)) { - byte newValue = valueProvider.getAsInt(); + byte newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; set(index); values[index] = newValue; @@ -403,22 +412,13 @@ public byte supplyByteIfAbsentNonDefault(T key, ByteSupplier valueProvider) { } byte newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public byte computeByteIfPresent(T key, ObjectByteUnaryOperator mappingFunction) { - int index = key.ordinal(); - if(!isSet(index)) return getDefaultReturnValue(); - byte newValue = mappingFunction.applyAsByte(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public byte computeByteIfPresentNonDefault(T key, ObjectByteUnaryOperator mappingFunction) { int index = key.ordinal(); diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/misc/Enum2CharMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/misc/Enum2CharMap.java index 032ac672..a42fa793 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/misc/Enum2CharMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/misc/Enum2CharMap.java @@ -327,30 +327,23 @@ public char computeChar(T key, ObjectCharUnaryOperator mappingFunction) { } @Override - public char computeCharNonDefault(T key, ObjectCharUnaryOperator mappingFunction) { + public char computeCharIfAbsent(T key, ToCharFunction mappingFunction) { int index = key.ordinal(); if(!isSet(index)) { - char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + char newValue = mappingFunction.applyAsChar(key); set(index); - values[index] = newValue; - return newValue; - } - char newValue = mappingFunction.applyAsChar(key, values[index]); - if(newValue == getDefaultReturnValue()) { - clear(index); - values[index] = (char)0; + values[index] = newValue; return newValue; } - values[index] = newValue; + char newValue = values[index]; return newValue; } - + @Override - public char computeCharIfAbsent(T key, ToCharFunction mappingFunction) { + public char supplyCharIfAbsent(T key, CharSupplier valueProvider) { int index = key.ordinal(); if(!isSet(index)) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = valueProvider.getAsChar(); set(index); values[index] = newValue; return newValue; @@ -360,34 +353,50 @@ public char computeCharIfAbsent(T key, ToCharFunction mappingFunction) { } @Override - public char computeCharIfAbsentNonDefault(T key, ToCharFunction mappingFunction) { + public char computeCharIfPresent(T key, ObjectCharUnaryOperator mappingFunction) { + int index = key.ordinal(); + if(!isSet(index)) return getDefaultReturnValue(); + char newValue = mappingFunction.applyAsChar(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public char computeCharNonDefault(T key, ObjectCharUnaryOperator mappingFunction) { int index = key.ordinal(); if(!isSet(index)) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; set(index); - values[index] = newValue; + values[index] = newValue; return newValue; } - char newValue = values[index]; + char newValue = mappingFunction.applyAsChar(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsChar(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + clear(index); + values[index] = (char)0; + return newValue; } + values[index] = newValue; return newValue; } @Override - public char supplyCharIfAbsent(T key, CharSupplier valueProvider) { + public char computeCharIfAbsentNonDefault(T key, ToCharFunction mappingFunction) { int index = key.ordinal(); if(!isSet(index)) { - char newValue = valueProvider.getAsInt(); + char newValue = mappingFunction.applyAsChar(key); + if(newValue == getDefaultReturnValue()) return newValue; set(index); values[index] = newValue; return newValue; } char newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsChar(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -395,7 +404,7 @@ public char supplyCharIfAbsent(T key, CharSupplier valueProvider) { public char supplyCharIfAbsentNonDefault(T key, CharSupplier valueProvider) { int index = key.ordinal(); if(!isSet(index)) { - char newValue = valueProvider.getAsInt(); + char newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; set(index); values[index] = newValue; @@ -403,22 +412,13 @@ public char supplyCharIfAbsentNonDefault(T key, CharSupplier valueProvider) { } char newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public char computeCharIfPresent(T key, ObjectCharUnaryOperator mappingFunction) { - int index = key.ordinal(); - if(!isSet(index)) return getDefaultReturnValue(); - char newValue = mappingFunction.applyAsChar(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public char computeCharIfPresentNonDefault(T key, ObjectCharUnaryOperator mappingFunction) { int index = key.ordinal(); diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/misc/Enum2DoubleMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/misc/Enum2DoubleMap.java index 5b6639fa..1b8af653 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/misc/Enum2DoubleMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/misc/Enum2DoubleMap.java @@ -327,30 +327,23 @@ public double computeDouble(T key, ObjectDoubleUnaryOperator mappingFunction) } @Override - public double computeDoubleNonDefault(T key, ObjectDoubleUnaryOperator mappingFunction) { + public double computeDoubleIfAbsent(T key, ToDoubleFunction mappingFunction) { int index = key.ordinal(); if(!isSet(index)) { - double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + double newValue = mappingFunction.applyAsDouble(key); set(index); - values[index] = newValue; - return newValue; - } - double newValue = mappingFunction.applyAsDouble(key, values[index]); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - clear(index); - values[index] = 0D; + values[index] = newValue; return newValue; } - values[index] = newValue; + double newValue = values[index]; return newValue; } - + @Override - public double computeDoubleIfAbsent(T key, ToDoubleFunction mappingFunction) { + public double supplyDoubleIfAbsent(T key, DoubleSupplier valueProvider) { int index = key.ordinal(); if(!isSet(index)) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = valueProvider.getAsDouble(); set(index); values[index] = newValue; return newValue; @@ -360,34 +353,50 @@ public double computeDoubleIfAbsent(T key, ToDoubleFunction mappingFunction) } @Override - public double computeDoubleIfAbsentNonDefault(T key, ToDoubleFunction mappingFunction) { + public double computeDoubleIfPresent(T key, ObjectDoubleUnaryOperator mappingFunction) { + int index = key.ordinal(); + if(!isSet(index)) return getDefaultReturnValue(); + double newValue = mappingFunction.applyAsDouble(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public double computeDoubleNonDefault(T key, ObjectDoubleUnaryOperator mappingFunction) { int index = key.ordinal(); if(!isSet(index)) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; set(index); - values[index] = newValue; + values[index] = newValue; return newValue; } - double newValue = values[index]; + double newValue = mappingFunction.applyAsDouble(key, values[index]); if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - newValue = mappingFunction.applyAsDouble(key); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; - values[index] = newValue; + clear(index); + values[index] = 0D; + return newValue; } + values[index] = newValue; return newValue; } @Override - public double supplyDoubleIfAbsent(T key, DoubleSupplier valueProvider) { + public double computeDoubleIfAbsentNonDefault(T key, ToDoubleFunction mappingFunction) { int index = key.ordinal(); if(!isSet(index)) { - double newValue = valueProvider.getAsDouble(); + double newValue = mappingFunction.applyAsDouble(key); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; set(index); values[index] = newValue; return newValue; } double newValue = values[index]; + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { + newValue = mappingFunction.applyAsDouble(key); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + values[index] = newValue; + } return newValue; } @@ -410,15 +419,6 @@ public double supplyDoubleIfAbsentNonDefault(T key, DoubleSupplier valueProvider return newValue; } - @Override - public double computeDoubleIfPresent(T key, ObjectDoubleUnaryOperator mappingFunction) { - int index = key.ordinal(); - if(!isSet(index)) return getDefaultReturnValue(); - double newValue = mappingFunction.applyAsDouble(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public double computeDoubleIfPresentNonDefault(T key, ObjectDoubleUnaryOperator mappingFunction) { int index = key.ordinal(); diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/misc/Enum2FloatMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/misc/Enum2FloatMap.java index 5336123f..67fc5dd7 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/misc/Enum2FloatMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/misc/Enum2FloatMap.java @@ -327,30 +327,23 @@ public float computeFloat(T key, ObjectFloatUnaryOperator mappingFunction) { } @Override - public float computeFloatNonDefault(T key, ObjectFloatUnaryOperator mappingFunction) { + public float computeFloatIfAbsent(T key, ToFloatFunction mappingFunction) { int index = key.ordinal(); if(!isSet(index)) { - float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + float newValue = mappingFunction.applyAsFloat(key); set(index); - values[index] = newValue; - return newValue; - } - float newValue = mappingFunction.applyAsFloat(key, values[index]); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - clear(index); - values[index] = 0F; + values[index] = newValue; return newValue; } - values[index] = newValue; + float newValue = values[index]; return newValue; } - + @Override - public float computeFloatIfAbsent(T key, ToFloatFunction mappingFunction) { + public float supplyFloatIfAbsent(T key, FloatSupplier valueProvider) { int index = key.ordinal(); if(!isSet(index)) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = valueProvider.getAsFloat(); set(index); values[index] = newValue; return newValue; @@ -360,34 +353,50 @@ public float computeFloatIfAbsent(T key, ToFloatFunction mappingFunction) { } @Override - public float computeFloatIfAbsentNonDefault(T key, ToFloatFunction mappingFunction) { + public float computeFloatIfPresent(T key, ObjectFloatUnaryOperator mappingFunction) { + int index = key.ordinal(); + if(!isSet(index)) return getDefaultReturnValue(); + float newValue = mappingFunction.applyAsFloat(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public float computeFloatNonDefault(T key, ObjectFloatUnaryOperator mappingFunction) { int index = key.ordinal(); if(!isSet(index)) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; set(index); - values[index] = newValue; + values[index] = newValue; return newValue; } - float newValue = values[index]; + float newValue = mappingFunction.applyAsFloat(key, values[index]); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - newValue = mappingFunction.applyAsFloat(key); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; - values[index] = newValue; + clear(index); + values[index] = 0F; + return newValue; } + values[index] = newValue; return newValue; } @Override - public float supplyFloatIfAbsent(T key, FloatSupplier valueProvider) { + public float computeFloatIfAbsentNonDefault(T key, ToFloatFunction mappingFunction) { int index = key.ordinal(); if(!isSet(index)) { - float newValue = valueProvider.getAsDouble(); + float newValue = mappingFunction.applyAsFloat(key); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; set(index); values[index] = newValue; return newValue; } float newValue = values[index]; + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { + newValue = mappingFunction.applyAsFloat(key); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + values[index] = newValue; + } return newValue; } @@ -395,7 +404,7 @@ public float supplyFloatIfAbsent(T key, FloatSupplier valueProvider) { public float supplyFloatIfAbsentNonDefault(T key, FloatSupplier valueProvider) { int index = key.ordinal(); if(!isSet(index)) { - float newValue = valueProvider.getAsDouble(); + float newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; set(index); values[index] = newValue; @@ -403,22 +412,13 @@ public float supplyFloatIfAbsentNonDefault(T key, FloatSupplier valueProvider) { } float newValue = values[index]; if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - newValue = valueProvider.getAsDouble(); + newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; values[index] = newValue; } return newValue; } - @Override - public float computeFloatIfPresent(T key, ObjectFloatUnaryOperator mappingFunction) { - int index = key.ordinal(); - if(!isSet(index)) return getDefaultReturnValue(); - float newValue = mappingFunction.applyAsFloat(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public float computeFloatIfPresentNonDefault(T key, ObjectFloatUnaryOperator mappingFunction) { int index = key.ordinal(); diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/misc/Enum2IntMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/misc/Enum2IntMap.java index 36d19a51..4c24fe1e 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/misc/Enum2IntMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/misc/Enum2IntMap.java @@ -327,30 +327,23 @@ public int computeInt(T key, ObjectIntUnaryOperator mappingFunction) { } @Override - public int computeIntNonDefault(T key, ObjectIntUnaryOperator mappingFunction) { + public int computeIntIfAbsent(T key, ToIntFunction mappingFunction) { int index = key.ordinal(); if(!isSet(index)) { - int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + int newValue = mappingFunction.applyAsInt(key); set(index); - values[index] = newValue; - return newValue; - } - int newValue = mappingFunction.applyAsInt(key, values[index]); - if(newValue == getDefaultReturnValue()) { - clear(index); - values[index] = 0; + values[index] = newValue; return newValue; } - values[index] = newValue; + int newValue = values[index]; return newValue; } - + @Override - public int computeIntIfAbsent(T key, ToIntFunction mappingFunction) { + public int supplyIntIfAbsent(T key, IntSupplier valueProvider) { int index = key.ordinal(); if(!isSet(index)) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = valueProvider.getAsInt(); set(index); values[index] = newValue; return newValue; @@ -360,34 +353,50 @@ public int computeIntIfAbsent(T key, ToIntFunction mappingFunction) { } @Override - public int computeIntIfAbsentNonDefault(T key, ToIntFunction mappingFunction) { + public int computeIntIfPresent(T key, ObjectIntUnaryOperator mappingFunction) { + int index = key.ordinal(); + if(!isSet(index)) return getDefaultReturnValue(); + int newValue = mappingFunction.applyAsInt(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public int computeIntNonDefault(T key, ObjectIntUnaryOperator mappingFunction) { int index = key.ordinal(); if(!isSet(index)) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; set(index); - values[index] = newValue; + values[index] = newValue; return newValue; } - int newValue = values[index]; + int newValue = mappingFunction.applyAsInt(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsInt(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + clear(index); + values[index] = 0; + return newValue; } + values[index] = newValue; return newValue; } @Override - public int supplyIntIfAbsent(T key, IntSupplier valueProvider) { + public int computeIntIfAbsentNonDefault(T key, ToIntFunction mappingFunction) { int index = key.ordinal(); if(!isSet(index)) { - int newValue = valueProvider.getAsInt(); + int newValue = mappingFunction.applyAsInt(key); + if(newValue == getDefaultReturnValue()) return newValue; set(index); values[index] = newValue; return newValue; } int newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsInt(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -410,15 +419,6 @@ public int supplyIntIfAbsentNonDefault(T key, IntSupplier valueProvider) { return newValue; } - @Override - public int computeIntIfPresent(T key, ObjectIntUnaryOperator mappingFunction) { - int index = key.ordinal(); - if(!isSet(index)) return getDefaultReturnValue(); - int newValue = mappingFunction.applyAsInt(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public int computeIntIfPresentNonDefault(T key, ObjectIntUnaryOperator mappingFunction) { int index = key.ordinal(); diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/misc/Enum2LongMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/misc/Enum2LongMap.java index a9a99e43..21cdcb21 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/misc/Enum2LongMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/misc/Enum2LongMap.java @@ -327,30 +327,23 @@ public long computeLong(T key, ObjectLongUnaryOperator mappingFunction) { } @Override - public long computeLongNonDefault(T key, ObjectLongUnaryOperator mappingFunction) { + public long computeLongIfAbsent(T key, ToLongFunction mappingFunction) { int index = key.ordinal(); if(!isSet(index)) { - long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + long newValue = mappingFunction.applyAsLong(key); set(index); - values[index] = newValue; - return newValue; - } - long newValue = mappingFunction.applyAsLong(key, values[index]); - if(newValue == getDefaultReturnValue()) { - clear(index); - values[index] = 0L; + values[index] = newValue; return newValue; } - values[index] = newValue; + long newValue = values[index]; return newValue; } - + @Override - public long computeLongIfAbsent(T key, ToLongFunction mappingFunction) { + public long supplyLongIfAbsent(T key, LongSupplier valueProvider) { int index = key.ordinal(); if(!isSet(index)) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = valueProvider.getAsLong(); set(index); values[index] = newValue; return newValue; @@ -360,34 +353,50 @@ public long computeLongIfAbsent(T key, ToLongFunction mappingFunction) { } @Override - public long computeLongIfAbsentNonDefault(T key, ToLongFunction mappingFunction) { + public long computeLongIfPresent(T key, ObjectLongUnaryOperator mappingFunction) { + int index = key.ordinal(); + if(!isSet(index)) return getDefaultReturnValue(); + long newValue = mappingFunction.applyAsLong(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public long computeLongNonDefault(T key, ObjectLongUnaryOperator mappingFunction) { int index = key.ordinal(); if(!isSet(index)) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; set(index); - values[index] = newValue; + values[index] = newValue; return newValue; } - long newValue = values[index]; + long newValue = mappingFunction.applyAsLong(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsLong(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + clear(index); + values[index] = 0L; + return newValue; } + values[index] = newValue; return newValue; } @Override - public long supplyLongIfAbsent(T key, LongSupplier valueProvider) { + public long computeLongIfAbsentNonDefault(T key, ToLongFunction mappingFunction) { int index = key.ordinal(); if(!isSet(index)) { - long newValue = valueProvider.getAsLong(); + long newValue = mappingFunction.applyAsLong(key); + if(newValue == getDefaultReturnValue()) return newValue; set(index); values[index] = newValue; return newValue; } long newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsLong(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -410,15 +419,6 @@ public long supplyLongIfAbsentNonDefault(T key, LongSupplier valueProvider) { return newValue; } - @Override - public long computeLongIfPresent(T key, ObjectLongUnaryOperator mappingFunction) { - int index = key.ordinal(); - if(!isSet(index)) return getDefaultReturnValue(); - long newValue = mappingFunction.applyAsLong(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public long computeLongIfPresentNonDefault(T key, ObjectLongUnaryOperator mappingFunction) { int index = key.ordinal(); diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/misc/Enum2ObjectMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/misc/Enum2ObjectMap.java index 1bcd63e7..d8632476 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/misc/Enum2ObjectMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/misc/Enum2ObjectMap.java @@ -290,26 +290,6 @@ public V compute(T key, ObjectObjectUnaryOperator mappingFunction) { return newValue; } - @Override - public V computeNonDefault(T key, ObjectObjectUnaryOperator mappingFunction) { - int index = key.ordinal(); - if(!isSet(index)) { - V newValue = mappingFunction.apply(key, getDefaultReturnValue()); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - set(index); - values[index] = newValue; - return newValue; - } - V newValue = mappingFunction.apply(key, values[index]); - if(Objects.equals(newValue, getDefaultReturnValue())) { - clear(index); - values[index] = null; - return newValue; - } - values[index] = newValue; - return newValue; - } - @Override public V computeIfAbsent(T key, UnaryOperator mappingFunction) { int index = key.ordinal(); @@ -328,26 +308,7 @@ public V computeIfAbsent(T key, UnaryOperator mappingFunction) { } return newValue; } - - @Override - public V computeIfAbsentNonDefault(T key, UnaryOperator mappingFunction) { - int index = key.ordinal(); - if(!isSet(index)) { - V newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - set(index); - values[index] = newValue; - return newValue; - } - V newValue = values[index]; - if(Objects.equals(newValue, getDefaultReturnValue())) { - newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - values[index] = newValue; - } - return newValue; - } - + @Override public V supplyIfAbsent(T key, ObjectSupplier valueProvider) { int index = key.ordinal(); @@ -367,25 +328,6 @@ public V supplyIfAbsent(T key, ObjectSupplier valueProvider) { return newValue; } - @Override - public V supplyIfAbsentNonDefault(T key, ObjectSupplier valueProvider) { - int index = key.ordinal(); - if(!isSet(index)) { - V newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - set(index); - values[index] = newValue; - return newValue; - } - V newValue = values[index]; - if(Objects.equals(newValue, getDefaultReturnValue())) { - newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - values[index] = newValue; - } - return newValue; - } - @Override public V computeIfPresent(T key, ObjectObjectUnaryOperator mappingFunction) { int index = key.ordinal(); @@ -400,20 +342,6 @@ public V computeIfPresent(T key, ObjectObjectUnaryOperator mappingFunction return newValue; } - @Override - public V computeIfPresentNonDefault(T key, ObjectObjectUnaryOperator mappingFunction) { - int index = key.ordinal(); - if(!isSet(index) || Objects.equals(values[index], getDefaultReturnValue())) return getDefaultReturnValue(); - V newValue = mappingFunction.apply(key, values[index]); - if(Objects.equals(newValue, getDefaultReturnValue())) { - clear(index); - values[index] = null; - return newValue; - } - values[index] = newValue; - return newValue; - } - @Override public V merge(T key, V value, ObjectObjectUnaryOperator mappingFunction) { int index = key.ordinal(); diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/misc/Enum2ShortMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/misc/Enum2ShortMap.java index f9fbf660..a862fb0b 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/misc/Enum2ShortMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/misc/Enum2ShortMap.java @@ -327,30 +327,23 @@ public short computeShort(T key, ObjectShortUnaryOperator mappingFunction) { } @Override - public short computeShortNonDefault(T key, ObjectShortUnaryOperator mappingFunction) { + public short computeShortIfAbsent(T key, ToShortFunction mappingFunction) { int index = key.ordinal(); if(!isSet(index)) { - short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + short newValue = mappingFunction.applyAsShort(key); set(index); - values[index] = newValue; - return newValue; - } - short newValue = mappingFunction.applyAsShort(key, values[index]); - if(newValue == getDefaultReturnValue()) { - clear(index); - values[index] = (short)0; + values[index] = newValue; return newValue; } - values[index] = newValue; + short newValue = values[index]; return newValue; } - + @Override - public short computeShortIfAbsent(T key, ToShortFunction mappingFunction) { + public short supplyShortIfAbsent(T key, ShortSupplier valueProvider) { int index = key.ordinal(); if(!isSet(index)) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = valueProvider.getAsShort(); set(index); values[index] = newValue; return newValue; @@ -360,34 +353,50 @@ public short computeShortIfAbsent(T key, ToShortFunction mappingFunction) { } @Override - public short computeShortIfAbsentNonDefault(T key, ToShortFunction mappingFunction) { + public short computeShortIfPresent(T key, ObjectShortUnaryOperator mappingFunction) { + int index = key.ordinal(); + if(!isSet(index)) return getDefaultReturnValue(); + short newValue = mappingFunction.applyAsShort(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public short computeShortNonDefault(T key, ObjectShortUnaryOperator mappingFunction) { int index = key.ordinal(); if(!isSet(index)) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; set(index); - values[index] = newValue; + values[index] = newValue; return newValue; } - short newValue = values[index]; + short newValue = mappingFunction.applyAsShort(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsShort(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + clear(index); + values[index] = (short)0; + return newValue; } + values[index] = newValue; return newValue; } @Override - public short supplyShortIfAbsent(T key, ShortSupplier valueProvider) { + public short computeShortIfAbsentNonDefault(T key, ToShortFunction mappingFunction) { int index = key.ordinal(); if(!isSet(index)) { - short newValue = valueProvider.getAsInt(); + short newValue = mappingFunction.applyAsShort(key); + if(newValue == getDefaultReturnValue()) return newValue; set(index); values[index] = newValue; return newValue; } short newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsShort(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -395,7 +404,7 @@ public short supplyShortIfAbsent(T key, ShortSupplier valueProvider) { public short supplyShortIfAbsentNonDefault(T key, ShortSupplier valueProvider) { int index = key.ordinal(); if(!isSet(index)) { - short newValue = valueProvider.getAsInt(); + short newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; set(index); values[index] = newValue; @@ -403,22 +412,13 @@ public short supplyShortIfAbsentNonDefault(T key, ShortSupplier valueProvider) { } short newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public short computeShortIfPresent(T key, ObjectShortUnaryOperator mappingFunction) { - int index = key.ordinal(); - if(!isSet(index)) return getDefaultReturnValue(); - short newValue = mappingFunction.applyAsShort(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public short computeShortIfPresentNonDefault(T key, ObjectShortUnaryOperator mappingFunction) { int index = key.ordinal(); diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/misc/Object2BooleanArrayMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/misc/Object2BooleanArrayMap.java index 611f502d..a970ee44 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/misc/Object2BooleanArrayMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/misc/Object2BooleanArrayMap.java @@ -407,66 +407,76 @@ public boolean computeBoolean(T key, ObjectBooleanUnaryOperator mappingFuncti } @Override - public boolean computeBooleanNonDefault(T key, ObjectBooleanUnaryOperator mappingFunction) { + public boolean computeBooleanIfAbsent(T key, Predicate mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + boolean newValue = mappingFunction.test(key); insertIndex(size++, key, newValue); return newValue; } - boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + boolean newValue = values[index]; return newValue; } - + @Override - public boolean computeBooleanIfAbsent(T key, Predicate mappingFunction) { - Objects.requireNonNull(mappingFunction); + public boolean supplyBooleanIfAbsent(T key, BooleanSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - boolean newValue = mappingFunction.test(key); + boolean newValue = valueProvider.getAsBoolean(); insertIndex(size++, key, newValue); return newValue; } boolean newValue = values[index]; return newValue; } + + @Override + public boolean computeBooleanIfPresent(T key, ObjectBooleanUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index == -1) return getDefaultReturnValue(); + boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public boolean computeBooleanIfAbsentNonDefault(T key, Predicate mappingFunction) { + public boolean computeBooleanNonDefault(T key, ObjectBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - boolean newValue = mappingFunction.test(key); + boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } - boolean newValue = values[index]; + boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.test(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public boolean supplyBooleanIfAbsent(T key, BooleanSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public boolean computeBooleanIfAbsentNonDefault(T key, Predicate mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - boolean newValue = valueProvider.getAsBoolean(); + boolean newValue = mappingFunction.test(key); + if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } boolean newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.test(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -489,16 +499,6 @@ public boolean supplyBooleanIfAbsentNonDefault(T key, BooleanSupplier valueProvi return newValue; } - @Override - public boolean computeBooleanIfPresent(T key, ObjectBooleanUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) return getDefaultReturnValue(); - boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public boolean computeBooleanIfPresentNonDefault(T key, ObjectBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/misc/Object2ByteArrayMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/misc/Object2ByteArrayMap.java index 4dcf83b3..15bbb789 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/misc/Object2ByteArrayMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/misc/Object2ByteArrayMap.java @@ -430,66 +430,76 @@ public byte computeByte(T key, ObjectByteUnaryOperator mappingFunction) { } @Override - public byte computeByteNonDefault(T key, ObjectByteUnaryOperator mappingFunction) { + public byte computeByteIfAbsent(T key, ToByteFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + byte newValue = mappingFunction.applyAsByte(key); insertIndex(size++, key, newValue); return newValue; } - byte newValue = mappingFunction.applyAsByte(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + byte newValue = values[index]; return newValue; } - + @Override - public byte computeByteIfAbsent(T key, ToByteFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public byte supplyByteIfAbsent(T key, ByteSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = valueProvider.getAsByte(); insertIndex(size++, key, newValue); return newValue; } byte newValue = values[index]; return newValue; } + + @Override + public byte computeByteIfPresent(T key, ObjectByteUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index == -1) return getDefaultReturnValue(); + byte newValue = mappingFunction.applyAsByte(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public byte computeByteIfAbsentNonDefault(T key, ToByteFunction mappingFunction) { + public byte computeByteNonDefault(T key, ObjectByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } - byte newValue = values[index]; + byte newValue = mappingFunction.applyAsByte(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsByte(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public byte supplyByteIfAbsent(T key, ByteSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public byte computeByteIfAbsentNonDefault(T key, ToByteFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - byte newValue = valueProvider.getAsInt(); + byte newValue = mappingFunction.applyAsByte(key); + if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } byte newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsByte(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -498,30 +508,20 @@ public byte supplyByteIfAbsentNonDefault(T key, ByteSupplier valueProvider) { Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - byte newValue = valueProvider.getAsInt(); + byte newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } byte newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public byte computeByteIfPresent(T key, ObjectByteUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) return getDefaultReturnValue(); - byte newValue = mappingFunction.applyAsByte(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public byte computeByteIfPresentNonDefault(T key, ObjectByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/misc/Object2CharArrayMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/misc/Object2CharArrayMap.java index c3921c5d..290796f1 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/misc/Object2CharArrayMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/misc/Object2CharArrayMap.java @@ -430,66 +430,76 @@ public char computeChar(T key, ObjectCharUnaryOperator mappingFunction) { } @Override - public char computeCharNonDefault(T key, ObjectCharUnaryOperator mappingFunction) { + public char computeCharIfAbsent(T key, ToCharFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + char newValue = mappingFunction.applyAsChar(key); insertIndex(size++, key, newValue); return newValue; } - char newValue = mappingFunction.applyAsChar(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + char newValue = values[index]; return newValue; } - + @Override - public char computeCharIfAbsent(T key, ToCharFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public char supplyCharIfAbsent(T key, CharSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = valueProvider.getAsChar(); insertIndex(size++, key, newValue); return newValue; } char newValue = values[index]; return newValue; } + + @Override + public char computeCharIfPresent(T key, ObjectCharUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index == -1) return getDefaultReturnValue(); + char newValue = mappingFunction.applyAsChar(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public char computeCharIfAbsentNonDefault(T key, ToCharFunction mappingFunction) { + public char computeCharNonDefault(T key, ObjectCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } - char newValue = values[index]; + char newValue = mappingFunction.applyAsChar(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsChar(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public char supplyCharIfAbsent(T key, CharSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public char computeCharIfAbsentNonDefault(T key, ToCharFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - char newValue = valueProvider.getAsInt(); + char newValue = mappingFunction.applyAsChar(key); + if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } char newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsChar(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -498,30 +508,20 @@ public char supplyCharIfAbsentNonDefault(T key, CharSupplier valueProvider) { Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - char newValue = valueProvider.getAsInt(); + char newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } char newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public char computeCharIfPresent(T key, ObjectCharUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) return getDefaultReturnValue(); - char newValue = mappingFunction.applyAsChar(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public char computeCharIfPresentNonDefault(T key, ObjectCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/misc/Object2DoubleArrayMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/misc/Object2DoubleArrayMap.java index ed801343..44d9360e 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/misc/Object2DoubleArrayMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/misc/Object2DoubleArrayMap.java @@ -430,66 +430,76 @@ public double computeDouble(T key, ObjectDoubleUnaryOperator mappingFunction) } @Override - public double computeDoubleNonDefault(T key, ObjectDoubleUnaryOperator mappingFunction) { + public double computeDoubleIfAbsent(T key, ToDoubleFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + double newValue = mappingFunction.applyAsDouble(key); insertIndex(size++, key, newValue); return newValue; } - double newValue = mappingFunction.applyAsDouble(key, values[index]); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + double newValue = values[index]; return newValue; } - + @Override - public double computeDoubleIfAbsent(T key, ToDoubleFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public double supplyDoubleIfAbsent(T key, DoubleSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = valueProvider.getAsDouble(); insertIndex(size++, key, newValue); return newValue; } double newValue = values[index]; return newValue; } + + @Override + public double computeDoubleIfPresent(T key, ObjectDoubleUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index == -1) return getDefaultReturnValue(); + double newValue = mappingFunction.applyAsDouble(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public double computeDoubleIfAbsentNonDefault(T key, ToDoubleFunction mappingFunction) { + public double computeDoubleNonDefault(T key, ObjectDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; insertIndex(size++, key, newValue); return newValue; } - double newValue = values[index]; + double newValue = mappingFunction.applyAsDouble(key, values[index]); if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - newValue = mappingFunction.applyAsDouble(key); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public double supplyDoubleIfAbsent(T key, DoubleSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public double computeDoubleIfAbsentNonDefault(T key, ToDoubleFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - double newValue = valueProvider.getAsDouble(); + double newValue = mappingFunction.applyAsDouble(key); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; insertIndex(size++, key, newValue); return newValue; } double newValue = values[index]; + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { + newValue = mappingFunction.applyAsDouble(key); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + values[index] = newValue; + } return newValue; } @@ -512,16 +522,6 @@ public double supplyDoubleIfAbsentNonDefault(T key, DoubleSupplier valueProvider return newValue; } - @Override - public double computeDoubleIfPresent(T key, ObjectDoubleUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) return getDefaultReturnValue(); - double newValue = mappingFunction.applyAsDouble(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public double computeDoubleIfPresentNonDefault(T key, ObjectDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/misc/Object2FloatArrayMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/misc/Object2FloatArrayMap.java index 11261ee8..c1bb770e 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/misc/Object2FloatArrayMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/misc/Object2FloatArrayMap.java @@ -430,66 +430,76 @@ public float computeFloat(T key, ObjectFloatUnaryOperator mappingFunction) { } @Override - public float computeFloatNonDefault(T key, ObjectFloatUnaryOperator mappingFunction) { + public float computeFloatIfAbsent(T key, ToFloatFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + float newValue = mappingFunction.applyAsFloat(key); insertIndex(size++, key, newValue); return newValue; } - float newValue = mappingFunction.applyAsFloat(key, values[index]); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + float newValue = values[index]; return newValue; } - + @Override - public float computeFloatIfAbsent(T key, ToFloatFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public float supplyFloatIfAbsent(T key, FloatSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = valueProvider.getAsFloat(); insertIndex(size++, key, newValue); return newValue; } float newValue = values[index]; return newValue; } + + @Override + public float computeFloatIfPresent(T key, ObjectFloatUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index == -1) return getDefaultReturnValue(); + float newValue = mappingFunction.applyAsFloat(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public float computeFloatIfAbsentNonDefault(T key, ToFloatFunction mappingFunction) { + public float computeFloatNonDefault(T key, ObjectFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insertIndex(size++, key, newValue); return newValue; } - float newValue = values[index]; + float newValue = mappingFunction.applyAsFloat(key, values[index]); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - newValue = mappingFunction.applyAsFloat(key); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public float supplyFloatIfAbsent(T key, FloatSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public float computeFloatIfAbsentNonDefault(T key, ToFloatFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - float newValue = valueProvider.getAsDouble(); + float newValue = mappingFunction.applyAsFloat(key); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insertIndex(size++, key, newValue); return newValue; } float newValue = values[index]; + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { + newValue = mappingFunction.applyAsFloat(key); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + values[index] = newValue; + } return newValue; } @@ -498,30 +508,20 @@ public float supplyFloatIfAbsentNonDefault(T key, FloatSupplier valueProvider) { Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - float newValue = valueProvider.getAsDouble(); + float newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insertIndex(size++, key, newValue); return newValue; } float newValue = values[index]; if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - newValue = valueProvider.getAsDouble(); + newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; values[index] = newValue; } return newValue; } - @Override - public float computeFloatIfPresent(T key, ObjectFloatUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) return getDefaultReturnValue(); - float newValue = mappingFunction.applyAsFloat(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public float computeFloatIfPresentNonDefault(T key, ObjectFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/misc/Object2IntArrayMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/misc/Object2IntArrayMap.java index 1069192b..c0aef88a 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/misc/Object2IntArrayMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/misc/Object2IntArrayMap.java @@ -430,66 +430,76 @@ public int computeInt(T key, ObjectIntUnaryOperator mappingFunction) { } @Override - public int computeIntNonDefault(T key, ObjectIntUnaryOperator mappingFunction) { + public int computeIntIfAbsent(T key, ToIntFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + int newValue = mappingFunction.applyAsInt(key); insertIndex(size++, key, newValue); return newValue; } - int newValue = mappingFunction.applyAsInt(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + int newValue = values[index]; return newValue; } - + @Override - public int computeIntIfAbsent(T key, ToIntFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public int supplyIntIfAbsent(T key, IntSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = valueProvider.getAsInt(); insertIndex(size++, key, newValue); return newValue; } int newValue = values[index]; return newValue; } + + @Override + public int computeIntIfPresent(T key, ObjectIntUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index == -1) return getDefaultReturnValue(); + int newValue = mappingFunction.applyAsInt(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public int computeIntIfAbsentNonDefault(T key, ToIntFunction mappingFunction) { + public int computeIntNonDefault(T key, ObjectIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } - int newValue = values[index]; + int newValue = mappingFunction.applyAsInt(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsInt(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public int supplyIntIfAbsent(T key, IntSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public int computeIntIfAbsentNonDefault(T key, ToIntFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - int newValue = valueProvider.getAsInt(); + int newValue = mappingFunction.applyAsInt(key); + if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } int newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsInt(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -512,16 +522,6 @@ public int supplyIntIfAbsentNonDefault(T key, IntSupplier valueProvider) { return newValue; } - @Override - public int computeIntIfPresent(T key, ObjectIntUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) return getDefaultReturnValue(); - int newValue = mappingFunction.applyAsInt(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public int computeIntIfPresentNonDefault(T key, ObjectIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/misc/Object2LongArrayMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/misc/Object2LongArrayMap.java index a3ea10e8..e560fcea 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/misc/Object2LongArrayMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/misc/Object2LongArrayMap.java @@ -430,66 +430,76 @@ public long computeLong(T key, ObjectLongUnaryOperator mappingFunction) { } @Override - public long computeLongNonDefault(T key, ObjectLongUnaryOperator mappingFunction) { + public long computeLongIfAbsent(T key, ToLongFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + long newValue = mappingFunction.applyAsLong(key); insertIndex(size++, key, newValue); return newValue; } - long newValue = mappingFunction.applyAsLong(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + long newValue = values[index]; return newValue; } - + @Override - public long computeLongIfAbsent(T key, ToLongFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public long supplyLongIfAbsent(T key, LongSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = valueProvider.getAsLong(); insertIndex(size++, key, newValue); return newValue; } long newValue = values[index]; return newValue; } + + @Override + public long computeLongIfPresent(T key, ObjectLongUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index == -1) return getDefaultReturnValue(); + long newValue = mappingFunction.applyAsLong(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public long computeLongIfAbsentNonDefault(T key, ToLongFunction mappingFunction) { + public long computeLongNonDefault(T key, ObjectLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } - long newValue = values[index]; + long newValue = mappingFunction.applyAsLong(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsLong(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public long supplyLongIfAbsent(T key, LongSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public long computeLongIfAbsentNonDefault(T key, ToLongFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - long newValue = valueProvider.getAsLong(); + long newValue = mappingFunction.applyAsLong(key); + if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } long newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsLong(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -512,16 +522,6 @@ public long supplyLongIfAbsentNonDefault(T key, LongSupplier valueProvider) { return newValue; } - @Override - public long computeLongIfPresent(T key, ObjectLongUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) return getDefaultReturnValue(); - long newValue = mappingFunction.applyAsLong(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public long computeLongIfPresentNonDefault(T key, ObjectLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/misc/Object2ObjectArrayMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/misc/Object2ObjectArrayMap.java index 9cda8387..5dc393c4 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/misc/Object2ObjectArrayMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/misc/Object2ObjectArrayMap.java @@ -368,25 +368,6 @@ public V compute(T key, ObjectObjectUnaryOperator mappingFunction) { return newValue; } - @Override - public V computeNonDefault(T key, ObjectObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) { - V newValue = mappingFunction.apply(key, getDefaultReturnValue()); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insertIndex(size++, key, newValue); - return newValue; - } - V newValue = mappingFunction.apply(key, values[index]); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; - return newValue; - } - @Override public V computeIfAbsent(T key, UnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -405,26 +386,7 @@ public V computeIfAbsent(T key, UnaryOperator mappingFunction) { } return newValue; } - - @Override - public V computeIfAbsentNonDefault(T key, UnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) { - V newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insertIndex(size++, key, newValue); - return newValue; - } - V newValue = values[index]; - if(Objects.equals(newValue, getDefaultReturnValue())) { - newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - values[index] = newValue; - } - return newValue; - } - + @Override public V supplyIfAbsent(T key, ObjectSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -443,26 +405,7 @@ public V supplyIfAbsent(T key, ObjectSupplier valueProvider) { } return newValue; } - - @Override - public V supplyIfAbsentNonDefault(T key, ObjectSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - int index = findIndex(key); - if(index == -1) { - V newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insertIndex(size++, key, newValue); - return newValue; - } - V newValue = values[index]; - if(Objects.equals(newValue, getDefaultReturnValue())) { - newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - values[index] = newValue; - } - return newValue; - } - + @Override public V computeIfPresent(T key, ObjectObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -477,20 +420,6 @@ public V computeIfPresent(T key, ObjectObjectUnaryOperator mappingFunction return newValue; } - @Override - public V computeIfPresentNonDefault(T key, ObjectObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1 || Objects.equals(values[index], getDefaultReturnValue())) return getDefaultReturnValue(); - V newValue = mappingFunction.apply(key, values[index]); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; - return newValue; - } - @Override public V merge(T key, V value, ObjectObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/misc/Object2ShortArrayMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/misc/Object2ShortArrayMap.java index bb49175b..c76e08d6 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/misc/Object2ShortArrayMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/misc/Object2ShortArrayMap.java @@ -430,66 +430,76 @@ public short computeShort(T key, ObjectShortUnaryOperator mappingFunction) { } @Override - public short computeShortNonDefault(T key, ObjectShortUnaryOperator mappingFunction) { + public short computeShortIfAbsent(T key, ToShortFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + short newValue = mappingFunction.applyAsShort(key); insertIndex(size++, key, newValue); return newValue; } - short newValue = mappingFunction.applyAsShort(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + short newValue = values[index]; return newValue; } - + @Override - public short computeShortIfAbsent(T key, ToShortFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public short supplyShortIfAbsent(T key, ShortSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = valueProvider.getAsShort(); insertIndex(size++, key, newValue); return newValue; } short newValue = values[index]; return newValue; } + + @Override + public short computeShortIfPresent(T key, ObjectShortUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index == -1) return getDefaultReturnValue(); + short newValue = mappingFunction.applyAsShort(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public short computeShortIfAbsentNonDefault(T key, ToShortFunction mappingFunction) { + public short computeShortNonDefault(T key, ObjectShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } - short newValue = values[index]; + short newValue = mappingFunction.applyAsShort(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsShort(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public short supplyShortIfAbsent(T key, ShortSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public short computeShortIfAbsentNonDefault(T key, ToShortFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - short newValue = valueProvider.getAsInt(); + short newValue = mappingFunction.applyAsShort(key); + if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } short newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsShort(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -498,30 +508,20 @@ public short supplyShortIfAbsentNonDefault(T key, ShortSupplier valueProvider) { Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - short newValue = valueProvider.getAsInt(); + short newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } short newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public short computeShortIfPresent(T key, ObjectShortUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) return getDefaultReturnValue(); - short newValue = mappingFunction.applyAsShort(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public short computeShortIfPresentNonDefault(T key, ObjectShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2BooleanAVLTreeMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2BooleanAVLTreeMap.java index 8087af14..f57ef658 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2BooleanAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2BooleanAVLTreeMap.java @@ -388,36 +388,60 @@ public boolean computeBoolean(T key, ObjectBooleanUnaryOperator mappingFuncti } @Override - public boolean computeBooleanNonDefault(T key, ObjectBooleanUnaryOperator mappingFunction) { + public boolean computeBooleanIfAbsent(T key, Predicate mappingFunction) { Objects.requireNonNull(mappingFunction); validate(key); Node entry = findNode(key); if(entry == null) { - boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + boolean newValue = mappingFunction.test(key); put(key, newValue); return newValue; } - boolean newValue = mappingFunction.applyAsBoolean(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public boolean supplyBooleanIfAbsent(T key, BooleanSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + validate(key); + Node entry = findNode(key); + if(entry == null) { + boolean newValue = valueProvider.getAsBoolean(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public boolean computeBooleanIfPresent(T key, ObjectBooleanUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + validate(key); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + boolean newValue = mappingFunction.applyAsBoolean(key, entry.value); entry.value = newValue; return newValue; } @Override - public boolean computeBooleanIfAbsent(T key, Predicate mappingFunction) { + public boolean computeBooleanNonDefault(T key, ObjectBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); validate(key); Node entry = findNode(key); if(entry == null) { - boolean newValue = mappingFunction.test(key); + boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + boolean newValue = mappingFunction.applyAsBoolean(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -439,19 +463,6 @@ public boolean computeBooleanIfAbsentNonDefault(T key, Predicate mappingFunct return entry.value; } - @Override - public boolean supplyBooleanIfAbsent(T key, BooleanSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - validate(key); - Node entry = findNode(key); - if(entry == null) { - boolean newValue = valueProvider.getAsBoolean(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public boolean supplyBooleanIfAbsentNonDefault(T key, BooleanSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -471,17 +482,6 @@ public boolean supplyBooleanIfAbsentNonDefault(T key, BooleanSupplier valueProvi return entry.value; } - @Override - public boolean computeBooleanIfPresent(T key, ObjectBooleanUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - validate(key); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - boolean newValue = mappingFunction.applyAsBoolean(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public boolean computeBooleanIfPresentNonDefault(T key, ObjectBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1449,14 +1449,9 @@ public boolean computeBooleanIfPresent(T key, ObjectBooleanUnaryOperator mapp map.validate(key); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - boolean newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2BooleanRBTreeMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2BooleanRBTreeMap.java index 4b7319eb..5cb91c16 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2BooleanRBTreeMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2BooleanRBTreeMap.java @@ -387,36 +387,60 @@ public boolean computeBoolean(T key, ObjectBooleanUnaryOperator mappingFuncti } @Override - public boolean computeBooleanNonDefault(T key, ObjectBooleanUnaryOperator mappingFunction) { + public boolean computeBooleanIfAbsent(T key, Predicate mappingFunction) { Objects.requireNonNull(mappingFunction); validate(key); Node entry = findNode(key); if(entry == null) { - boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + boolean newValue = mappingFunction.test(key); put(key, newValue); return newValue; } - boolean newValue = mappingFunction.applyAsBoolean(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public boolean supplyBooleanIfAbsent(T key, BooleanSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + validate(key); + Node entry = findNode(key); + if(entry == null) { + boolean newValue = valueProvider.getAsBoolean(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public boolean computeBooleanIfPresent(T key, ObjectBooleanUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + validate(key); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + boolean newValue = mappingFunction.applyAsBoolean(key, entry.value); entry.value = newValue; return newValue; } @Override - public boolean computeBooleanIfAbsent(T key, Predicate mappingFunction) { + public boolean computeBooleanNonDefault(T key, ObjectBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); validate(key); Node entry = findNode(key); if(entry == null) { - boolean newValue = mappingFunction.test(key); + boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + boolean newValue = mappingFunction.applyAsBoolean(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -438,19 +462,6 @@ public boolean computeBooleanIfAbsentNonDefault(T key, Predicate mappingFunct return entry.value; } - @Override - public boolean supplyBooleanIfAbsent(T key, BooleanSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - validate(key); - Node entry = findNode(key); - if(entry == null) { - boolean newValue = valueProvider.getAsBoolean(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public boolean supplyBooleanIfAbsentNonDefault(T key, BooleanSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -470,17 +481,6 @@ public boolean supplyBooleanIfAbsentNonDefault(T key, BooleanSupplier valueProvi return entry.value; } - @Override - public boolean computeBooleanIfPresent(T key, ObjectBooleanUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - validate(key); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - boolean newValue = mappingFunction.applyAsBoolean(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public boolean computeBooleanIfPresentNonDefault(T key, ObjectBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1512,14 +1512,9 @@ public boolean computeBooleanIfPresent(T key, ObjectBooleanUnaryOperator mapp map.validate(key); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - boolean newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2ByteAVLTreeMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2ByteAVLTreeMap.java index d59cfeee..c3afcf33 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2ByteAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2ByteAVLTreeMap.java @@ -447,36 +447,60 @@ public byte computeByte(T key, ObjectByteUnaryOperator mappingFunction) { } @Override - public byte computeByteNonDefault(T key, ObjectByteUnaryOperator mappingFunction) { + public byte computeByteIfAbsent(T key, ToByteFunction mappingFunction) { Objects.requireNonNull(mappingFunction); validate(key); Node entry = findNode(key); if(entry == null) { - byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + byte newValue = mappingFunction.applyAsByte(key); put(key, newValue); return newValue; } - byte newValue = mappingFunction.applyAsByte(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public byte supplyByteIfAbsent(T key, ByteSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + validate(key); + Node entry = findNode(key); + if(entry == null) { + byte newValue = valueProvider.getAsByte(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public byte computeByteIfPresent(T key, ObjectByteUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + validate(key); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + byte newValue = mappingFunction.applyAsByte(key, entry.value); entry.value = newValue; return newValue; } @Override - public byte computeByteIfAbsent(T key, ToByteFunction mappingFunction) { + public byte computeByteNonDefault(T key, ObjectByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); validate(key); Node entry = findNode(key); if(entry == null) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + byte newValue = mappingFunction.applyAsByte(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -498,49 +522,25 @@ public byte computeByteIfAbsentNonDefault(T key, ToByteFunction mappingFuncti return entry.value; } - @Override - public byte supplyByteIfAbsent(T key, ByteSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - validate(key); - Node entry = findNode(key); - if(entry == null) { - byte newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public byte supplyByteIfAbsentNonDefault(T key, ByteSupplier valueProvider) { Objects.requireNonNull(valueProvider); validate(key); Node entry = findNode(key); if(entry == null) { - byte newValue = valueProvider.getAsInt(); + byte newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } if(entry.value == getDefaultReturnValue()) { - byte newValue = valueProvider.getAsInt(); + byte newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; entry.value = newValue; } return entry.value; } - @Override - public byte computeByteIfPresent(T key, ObjectByteUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - validate(key); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - byte newValue = mappingFunction.applyAsByte(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public byte computeByteIfPresentNonDefault(T key, ObjectByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1520,14 +1520,9 @@ public byte computeByteIfPresent(T key, ObjectByteUnaryOperator mappingFuncti map.validate(key); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - byte newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2ByteRBTreeMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2ByteRBTreeMap.java index ea979a8c..425bb43e 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2ByteRBTreeMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2ByteRBTreeMap.java @@ -447,36 +447,60 @@ public byte computeByte(T key, ObjectByteUnaryOperator mappingFunction) { } @Override - public byte computeByteNonDefault(T key, ObjectByteUnaryOperator mappingFunction) { + public byte computeByteIfAbsent(T key, ToByteFunction mappingFunction) { Objects.requireNonNull(mappingFunction); validate(key); Node entry = findNode(key); if(entry == null) { - byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + byte newValue = mappingFunction.applyAsByte(key); put(key, newValue); return newValue; } - byte newValue = mappingFunction.applyAsByte(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public byte supplyByteIfAbsent(T key, ByteSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + validate(key); + Node entry = findNode(key); + if(entry == null) { + byte newValue = valueProvider.getAsByte(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public byte computeByteIfPresent(T key, ObjectByteUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + validate(key); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + byte newValue = mappingFunction.applyAsByte(key, entry.value); entry.value = newValue; return newValue; } @Override - public byte computeByteIfAbsent(T key, ToByteFunction mappingFunction) { + public byte computeByteNonDefault(T key, ObjectByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); validate(key); Node entry = findNode(key); if(entry == null) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + byte newValue = mappingFunction.applyAsByte(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -498,49 +522,25 @@ public byte computeByteIfAbsentNonDefault(T key, ToByteFunction mappingFuncti return entry.value; } - @Override - public byte supplyByteIfAbsent(T key, ByteSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - validate(key); - Node entry = findNode(key); - if(entry == null) { - byte newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public byte supplyByteIfAbsentNonDefault(T key, ByteSupplier valueProvider) { Objects.requireNonNull(valueProvider); validate(key); Node entry = findNode(key); if(entry == null) { - byte newValue = valueProvider.getAsInt(); + byte newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } if(entry.value == getDefaultReturnValue()) { - byte newValue = valueProvider.getAsInt(); + byte newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; entry.value = newValue; } return entry.value; } - @Override - public byte computeByteIfPresent(T key, ObjectByteUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - validate(key); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - byte newValue = mappingFunction.applyAsByte(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public byte computeByteIfPresentNonDefault(T key, ObjectByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1584,14 +1584,9 @@ public byte computeByteIfPresent(T key, ObjectByteUnaryOperator mappingFuncti map.validate(key); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - byte newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2CharAVLTreeMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2CharAVLTreeMap.java index fcfe8251..19ec9d4f 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2CharAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2CharAVLTreeMap.java @@ -447,36 +447,60 @@ public char computeChar(T key, ObjectCharUnaryOperator mappingFunction) { } @Override - public char computeCharNonDefault(T key, ObjectCharUnaryOperator mappingFunction) { + public char computeCharIfAbsent(T key, ToCharFunction mappingFunction) { Objects.requireNonNull(mappingFunction); validate(key); Node entry = findNode(key); if(entry == null) { - char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + char newValue = mappingFunction.applyAsChar(key); put(key, newValue); return newValue; } - char newValue = mappingFunction.applyAsChar(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public char supplyCharIfAbsent(T key, CharSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + validate(key); + Node entry = findNode(key); + if(entry == null) { + char newValue = valueProvider.getAsChar(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public char computeCharIfPresent(T key, ObjectCharUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + validate(key); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + char newValue = mappingFunction.applyAsChar(key, entry.value); entry.value = newValue; return newValue; } @Override - public char computeCharIfAbsent(T key, ToCharFunction mappingFunction) { + public char computeCharNonDefault(T key, ObjectCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); validate(key); Node entry = findNode(key); if(entry == null) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + char newValue = mappingFunction.applyAsChar(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -498,49 +522,25 @@ public char computeCharIfAbsentNonDefault(T key, ToCharFunction mappingFuncti return entry.value; } - @Override - public char supplyCharIfAbsent(T key, CharSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - validate(key); - Node entry = findNode(key); - if(entry == null) { - char newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public char supplyCharIfAbsentNonDefault(T key, CharSupplier valueProvider) { Objects.requireNonNull(valueProvider); validate(key); Node entry = findNode(key); if(entry == null) { - char newValue = valueProvider.getAsInt(); + char newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } if(entry.value == getDefaultReturnValue()) { - char newValue = valueProvider.getAsInt(); + char newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; entry.value = newValue; } return entry.value; } - @Override - public char computeCharIfPresent(T key, ObjectCharUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - validate(key); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - char newValue = mappingFunction.applyAsChar(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public char computeCharIfPresentNonDefault(T key, ObjectCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1520,14 +1520,9 @@ public char computeCharIfPresent(T key, ObjectCharUnaryOperator mappingFuncti map.validate(key); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - char newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2CharRBTreeMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2CharRBTreeMap.java index 0cb34e12..5cc3c50c 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2CharRBTreeMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2CharRBTreeMap.java @@ -447,36 +447,60 @@ public char computeChar(T key, ObjectCharUnaryOperator mappingFunction) { } @Override - public char computeCharNonDefault(T key, ObjectCharUnaryOperator mappingFunction) { + public char computeCharIfAbsent(T key, ToCharFunction mappingFunction) { Objects.requireNonNull(mappingFunction); validate(key); Node entry = findNode(key); if(entry == null) { - char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + char newValue = mappingFunction.applyAsChar(key); put(key, newValue); return newValue; } - char newValue = mappingFunction.applyAsChar(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public char supplyCharIfAbsent(T key, CharSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + validate(key); + Node entry = findNode(key); + if(entry == null) { + char newValue = valueProvider.getAsChar(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public char computeCharIfPresent(T key, ObjectCharUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + validate(key); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + char newValue = mappingFunction.applyAsChar(key, entry.value); entry.value = newValue; return newValue; } @Override - public char computeCharIfAbsent(T key, ToCharFunction mappingFunction) { + public char computeCharNonDefault(T key, ObjectCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); validate(key); Node entry = findNode(key); if(entry == null) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + char newValue = mappingFunction.applyAsChar(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -498,49 +522,25 @@ public char computeCharIfAbsentNonDefault(T key, ToCharFunction mappingFuncti return entry.value; } - @Override - public char supplyCharIfAbsent(T key, CharSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - validate(key); - Node entry = findNode(key); - if(entry == null) { - char newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public char supplyCharIfAbsentNonDefault(T key, CharSupplier valueProvider) { Objects.requireNonNull(valueProvider); validate(key); Node entry = findNode(key); if(entry == null) { - char newValue = valueProvider.getAsInt(); + char newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } if(entry.value == getDefaultReturnValue()) { - char newValue = valueProvider.getAsInt(); + char newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; entry.value = newValue; } return entry.value; } - @Override - public char computeCharIfPresent(T key, ObjectCharUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - validate(key); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - char newValue = mappingFunction.applyAsChar(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public char computeCharIfPresentNonDefault(T key, ObjectCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1584,14 +1584,9 @@ public char computeCharIfPresent(T key, ObjectCharUnaryOperator mappingFuncti map.validate(key); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - char newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2DoubleAVLTreeMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2DoubleAVLTreeMap.java index 83685baf..b90675f3 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2DoubleAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2DoubleAVLTreeMap.java @@ -447,36 +447,60 @@ public double computeDouble(T key, ObjectDoubleUnaryOperator mappingFunction) } @Override - public double computeDoubleNonDefault(T key, ObjectDoubleUnaryOperator mappingFunction) { + public double computeDoubleIfAbsent(T key, ToDoubleFunction mappingFunction) { Objects.requireNonNull(mappingFunction); validate(key); Node entry = findNode(key); if(entry == null) { - double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + double newValue = mappingFunction.applyAsDouble(key); put(key, newValue); return newValue; } - double newValue = mappingFunction.applyAsDouble(key, entry.value); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - removeNode(entry); + return entry.value; + } + + @Override + public double supplyDoubleIfAbsent(T key, DoubleSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + validate(key); + Node entry = findNode(key); + if(entry == null) { + double newValue = valueProvider.getAsDouble(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public double computeDoubleIfPresent(T key, ObjectDoubleUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + validate(key); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + double newValue = mappingFunction.applyAsDouble(key, entry.value); entry.value = newValue; return newValue; } @Override - public double computeDoubleIfAbsent(T key, ToDoubleFunction mappingFunction) { + public double computeDoubleNonDefault(T key, ObjectDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); validate(key); Node entry = findNode(key); if(entry == null) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; put(key, newValue); return newValue; } - return entry.value; + double newValue = mappingFunction.applyAsDouble(key, entry.value); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -498,19 +522,6 @@ public double computeDoubleIfAbsentNonDefault(T key, ToDoubleFunction mapping return entry.value; } - @Override - public double supplyDoubleIfAbsent(T key, DoubleSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - validate(key); - Node entry = findNode(key); - if(entry == null) { - double newValue = valueProvider.getAsDouble(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public double supplyDoubleIfAbsentNonDefault(T key, DoubleSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -530,17 +541,6 @@ public double supplyDoubleIfAbsentNonDefault(T key, DoubleSupplier valueProvider return entry.value; } - @Override - public double computeDoubleIfPresent(T key, ObjectDoubleUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - validate(key); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - double newValue = mappingFunction.applyAsDouble(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public double computeDoubleIfPresentNonDefault(T key, ObjectDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1520,14 +1520,9 @@ public double computeDoubleIfPresent(T key, ObjectDoubleUnaryOperator mapping map.validate(key); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || Double.doubleToLongBits(entry.value) == Double.doubleToLongBits(getDefaultReturnValue())) return getDefaultReturnValue(); - double newValue = mappingFunction.apply(key, entry.value); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2DoubleRBTreeMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2DoubleRBTreeMap.java index 7ef9f0f0..c66ed1ed 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2DoubleRBTreeMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2DoubleRBTreeMap.java @@ -447,36 +447,60 @@ public double computeDouble(T key, ObjectDoubleUnaryOperator mappingFunction) } @Override - public double computeDoubleNonDefault(T key, ObjectDoubleUnaryOperator mappingFunction) { + public double computeDoubleIfAbsent(T key, ToDoubleFunction mappingFunction) { Objects.requireNonNull(mappingFunction); validate(key); Node entry = findNode(key); if(entry == null) { - double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + double newValue = mappingFunction.applyAsDouble(key); put(key, newValue); return newValue; } - double newValue = mappingFunction.applyAsDouble(key, entry.value); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - removeNode(entry); + return entry.value; + } + + @Override + public double supplyDoubleIfAbsent(T key, DoubleSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + validate(key); + Node entry = findNode(key); + if(entry == null) { + double newValue = valueProvider.getAsDouble(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public double computeDoubleIfPresent(T key, ObjectDoubleUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + validate(key); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + double newValue = mappingFunction.applyAsDouble(key, entry.value); entry.value = newValue; return newValue; } @Override - public double computeDoubleIfAbsent(T key, ToDoubleFunction mappingFunction) { + public double computeDoubleNonDefault(T key, ObjectDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); validate(key); Node entry = findNode(key); if(entry == null) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; put(key, newValue); return newValue; } - return entry.value; + double newValue = mappingFunction.applyAsDouble(key, entry.value); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -498,19 +522,6 @@ public double computeDoubleIfAbsentNonDefault(T key, ToDoubleFunction mapping return entry.value; } - @Override - public double supplyDoubleIfAbsent(T key, DoubleSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - validate(key); - Node entry = findNode(key); - if(entry == null) { - double newValue = valueProvider.getAsDouble(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public double supplyDoubleIfAbsentNonDefault(T key, DoubleSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -530,17 +541,6 @@ public double supplyDoubleIfAbsentNonDefault(T key, DoubleSupplier valueProvider return entry.value; } - @Override - public double computeDoubleIfPresent(T key, ObjectDoubleUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - validate(key); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - double newValue = mappingFunction.applyAsDouble(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public double computeDoubleIfPresentNonDefault(T key, ObjectDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1584,14 +1584,9 @@ public double computeDoubleIfPresent(T key, ObjectDoubleUnaryOperator mapping map.validate(key); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || Double.doubleToLongBits(entry.value) == Double.doubleToLongBits(getDefaultReturnValue())) return getDefaultReturnValue(); - double newValue = mappingFunction.apply(key, entry.value); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2FloatAVLTreeMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2FloatAVLTreeMap.java index 67e5b291..63e27a05 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2FloatAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2FloatAVLTreeMap.java @@ -447,36 +447,60 @@ public float computeFloat(T key, ObjectFloatUnaryOperator mappingFunction) { } @Override - public float computeFloatNonDefault(T key, ObjectFloatUnaryOperator mappingFunction) { + public float computeFloatIfAbsent(T key, ToFloatFunction mappingFunction) { Objects.requireNonNull(mappingFunction); validate(key); Node entry = findNode(key); if(entry == null) { - float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + float newValue = mappingFunction.applyAsFloat(key); put(key, newValue); return newValue; } - float newValue = mappingFunction.applyAsFloat(key, entry.value); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - removeNode(entry); + return entry.value; + } + + @Override + public float supplyFloatIfAbsent(T key, FloatSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + validate(key); + Node entry = findNode(key); + if(entry == null) { + float newValue = valueProvider.getAsFloat(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public float computeFloatIfPresent(T key, ObjectFloatUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + validate(key); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + float newValue = mappingFunction.applyAsFloat(key, entry.value); entry.value = newValue; return newValue; } @Override - public float computeFloatIfAbsent(T key, ToFloatFunction mappingFunction) { + public float computeFloatNonDefault(T key, ObjectFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); validate(key); Node entry = findNode(key); if(entry == null) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; put(key, newValue); return newValue; } - return entry.value; + float newValue = mappingFunction.applyAsFloat(key, entry.value); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -498,49 +522,25 @@ public float computeFloatIfAbsentNonDefault(T key, ToFloatFunction mappingFun return entry.value; } - @Override - public float supplyFloatIfAbsent(T key, FloatSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - validate(key); - Node entry = findNode(key); - if(entry == null) { - float newValue = valueProvider.getAsDouble(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public float supplyFloatIfAbsentNonDefault(T key, FloatSupplier valueProvider) { Objects.requireNonNull(valueProvider); validate(key); Node entry = findNode(key); if(entry == null) { - float newValue = valueProvider.getAsDouble(); + float newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; put(key, newValue); return newValue; } if(Float.floatToIntBits(entry.value) == Float.floatToIntBits(getDefaultReturnValue())) { - float newValue = valueProvider.getAsDouble(); + float newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; entry.value = newValue; } return entry.value; } - @Override - public float computeFloatIfPresent(T key, ObjectFloatUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - validate(key); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - float newValue = mappingFunction.applyAsFloat(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public float computeFloatIfPresentNonDefault(T key, ObjectFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1520,14 +1520,9 @@ public float computeFloatIfPresent(T key, ObjectFloatUnaryOperator mappingFun map.validate(key); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || Float.floatToIntBits(entry.value) == Float.floatToIntBits(getDefaultReturnValue())) return getDefaultReturnValue(); - float newValue = mappingFunction.apply(key, entry.value); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2FloatRBTreeMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2FloatRBTreeMap.java index ce463948..6b20aa98 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2FloatRBTreeMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2FloatRBTreeMap.java @@ -447,36 +447,60 @@ public float computeFloat(T key, ObjectFloatUnaryOperator mappingFunction) { } @Override - public float computeFloatNonDefault(T key, ObjectFloatUnaryOperator mappingFunction) { + public float computeFloatIfAbsent(T key, ToFloatFunction mappingFunction) { Objects.requireNonNull(mappingFunction); validate(key); Node entry = findNode(key); if(entry == null) { - float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + float newValue = mappingFunction.applyAsFloat(key); put(key, newValue); return newValue; } - float newValue = mappingFunction.applyAsFloat(key, entry.value); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - removeNode(entry); + return entry.value; + } + + @Override + public float supplyFloatIfAbsent(T key, FloatSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + validate(key); + Node entry = findNode(key); + if(entry == null) { + float newValue = valueProvider.getAsFloat(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public float computeFloatIfPresent(T key, ObjectFloatUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + validate(key); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + float newValue = mappingFunction.applyAsFloat(key, entry.value); entry.value = newValue; return newValue; } @Override - public float computeFloatIfAbsent(T key, ToFloatFunction mappingFunction) { + public float computeFloatNonDefault(T key, ObjectFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); validate(key); Node entry = findNode(key); if(entry == null) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; put(key, newValue); return newValue; } - return entry.value; + float newValue = mappingFunction.applyAsFloat(key, entry.value); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -498,49 +522,25 @@ public float computeFloatIfAbsentNonDefault(T key, ToFloatFunction mappingFun return entry.value; } - @Override - public float supplyFloatIfAbsent(T key, FloatSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - validate(key); - Node entry = findNode(key); - if(entry == null) { - float newValue = valueProvider.getAsDouble(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public float supplyFloatIfAbsentNonDefault(T key, FloatSupplier valueProvider) { Objects.requireNonNull(valueProvider); validate(key); Node entry = findNode(key); if(entry == null) { - float newValue = valueProvider.getAsDouble(); + float newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; put(key, newValue); return newValue; } if(Float.floatToIntBits(entry.value) == Float.floatToIntBits(getDefaultReturnValue())) { - float newValue = valueProvider.getAsDouble(); + float newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; entry.value = newValue; } return entry.value; } - @Override - public float computeFloatIfPresent(T key, ObjectFloatUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - validate(key); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - float newValue = mappingFunction.applyAsFloat(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public float computeFloatIfPresentNonDefault(T key, ObjectFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1584,14 +1584,9 @@ public float computeFloatIfPresent(T key, ObjectFloatUnaryOperator mappingFun map.validate(key); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || Float.floatToIntBits(entry.value) == Float.floatToIntBits(getDefaultReturnValue())) return getDefaultReturnValue(); - float newValue = mappingFunction.apply(key, entry.value); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2IntAVLTreeMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2IntAVLTreeMap.java index bf0bb8bf..854fa015 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2IntAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2IntAVLTreeMap.java @@ -447,36 +447,60 @@ public int computeInt(T key, ObjectIntUnaryOperator mappingFunction) { } @Override - public int computeIntNonDefault(T key, ObjectIntUnaryOperator mappingFunction) { + public int computeIntIfAbsent(T key, ToIntFunction mappingFunction) { Objects.requireNonNull(mappingFunction); validate(key); Node entry = findNode(key); if(entry == null) { - int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + int newValue = mappingFunction.applyAsInt(key); put(key, newValue); return newValue; } - int newValue = mappingFunction.applyAsInt(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public int supplyIntIfAbsent(T key, IntSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + validate(key); + Node entry = findNode(key); + if(entry == null) { + int newValue = valueProvider.getAsInt(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public int computeIntIfPresent(T key, ObjectIntUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + validate(key); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + int newValue = mappingFunction.applyAsInt(key, entry.value); entry.value = newValue; return newValue; } @Override - public int computeIntIfAbsent(T key, ToIntFunction mappingFunction) { + public int computeIntNonDefault(T key, ObjectIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); validate(key); Node entry = findNode(key); if(entry == null) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + int newValue = mappingFunction.applyAsInt(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -498,19 +522,6 @@ public int computeIntIfAbsentNonDefault(T key, ToIntFunction mappingFunction) return entry.value; } - @Override - public int supplyIntIfAbsent(T key, IntSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - validate(key); - Node entry = findNode(key); - if(entry == null) { - int newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public int supplyIntIfAbsentNonDefault(T key, IntSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -530,17 +541,6 @@ public int supplyIntIfAbsentNonDefault(T key, IntSupplier valueProvider) { return entry.value; } - @Override - public int computeIntIfPresent(T key, ObjectIntUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - validate(key); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - int newValue = mappingFunction.applyAsInt(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public int computeIntIfPresentNonDefault(T key, ObjectIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1520,14 +1520,9 @@ public int computeIntIfPresent(T key, ObjectIntUnaryOperator mappingFunction) map.validate(key); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - int newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2IntRBTreeMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2IntRBTreeMap.java index 1ae54bed..84790465 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2IntRBTreeMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2IntRBTreeMap.java @@ -447,36 +447,60 @@ public int computeInt(T key, ObjectIntUnaryOperator mappingFunction) { } @Override - public int computeIntNonDefault(T key, ObjectIntUnaryOperator mappingFunction) { + public int computeIntIfAbsent(T key, ToIntFunction mappingFunction) { Objects.requireNonNull(mappingFunction); validate(key); Node entry = findNode(key); if(entry == null) { - int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + int newValue = mappingFunction.applyAsInt(key); put(key, newValue); return newValue; } - int newValue = mappingFunction.applyAsInt(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public int supplyIntIfAbsent(T key, IntSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + validate(key); + Node entry = findNode(key); + if(entry == null) { + int newValue = valueProvider.getAsInt(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public int computeIntIfPresent(T key, ObjectIntUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + validate(key); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + int newValue = mappingFunction.applyAsInt(key, entry.value); entry.value = newValue; return newValue; } @Override - public int computeIntIfAbsent(T key, ToIntFunction mappingFunction) { + public int computeIntNonDefault(T key, ObjectIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); validate(key); Node entry = findNode(key); if(entry == null) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + int newValue = mappingFunction.applyAsInt(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -498,19 +522,6 @@ public int computeIntIfAbsentNonDefault(T key, ToIntFunction mappingFunction) return entry.value; } - @Override - public int supplyIntIfAbsent(T key, IntSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - validate(key); - Node entry = findNode(key); - if(entry == null) { - int newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public int supplyIntIfAbsentNonDefault(T key, IntSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -530,17 +541,6 @@ public int supplyIntIfAbsentNonDefault(T key, IntSupplier valueProvider) { return entry.value; } - @Override - public int computeIntIfPresent(T key, ObjectIntUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - validate(key); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - int newValue = mappingFunction.applyAsInt(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public int computeIntIfPresentNonDefault(T key, ObjectIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1584,14 +1584,9 @@ public int computeIntIfPresent(T key, ObjectIntUnaryOperator mappingFunction) map.validate(key); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - int newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2LongAVLTreeMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2LongAVLTreeMap.java index 90d61b38..1d863fb5 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2LongAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2LongAVLTreeMap.java @@ -447,36 +447,60 @@ public long computeLong(T key, ObjectLongUnaryOperator mappingFunction) { } @Override - public long computeLongNonDefault(T key, ObjectLongUnaryOperator mappingFunction) { + public long computeLongIfAbsent(T key, ToLongFunction mappingFunction) { Objects.requireNonNull(mappingFunction); validate(key); Node entry = findNode(key); if(entry == null) { - long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + long newValue = mappingFunction.applyAsLong(key); put(key, newValue); return newValue; } - long newValue = mappingFunction.applyAsLong(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public long supplyLongIfAbsent(T key, LongSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + validate(key); + Node entry = findNode(key); + if(entry == null) { + long newValue = valueProvider.getAsLong(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public long computeLongIfPresent(T key, ObjectLongUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + validate(key); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + long newValue = mappingFunction.applyAsLong(key, entry.value); entry.value = newValue; return newValue; } @Override - public long computeLongIfAbsent(T key, ToLongFunction mappingFunction) { + public long computeLongNonDefault(T key, ObjectLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); validate(key); Node entry = findNode(key); if(entry == null) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + long newValue = mappingFunction.applyAsLong(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -498,19 +522,6 @@ public long computeLongIfAbsentNonDefault(T key, ToLongFunction mappingFuncti return entry.value; } - @Override - public long supplyLongIfAbsent(T key, LongSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - validate(key); - Node entry = findNode(key); - if(entry == null) { - long newValue = valueProvider.getAsLong(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public long supplyLongIfAbsentNonDefault(T key, LongSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -530,17 +541,6 @@ public long supplyLongIfAbsentNonDefault(T key, LongSupplier valueProvider) { return entry.value; } - @Override - public long computeLongIfPresent(T key, ObjectLongUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - validate(key); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - long newValue = mappingFunction.applyAsLong(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public long computeLongIfPresentNonDefault(T key, ObjectLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1520,14 +1520,9 @@ public long computeLongIfPresent(T key, ObjectLongUnaryOperator mappingFuncti map.validate(key); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - long newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2LongRBTreeMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2LongRBTreeMap.java index a733640e..a26d87f3 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2LongRBTreeMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2LongRBTreeMap.java @@ -447,36 +447,60 @@ public long computeLong(T key, ObjectLongUnaryOperator mappingFunction) { } @Override - public long computeLongNonDefault(T key, ObjectLongUnaryOperator mappingFunction) { + public long computeLongIfAbsent(T key, ToLongFunction mappingFunction) { Objects.requireNonNull(mappingFunction); validate(key); Node entry = findNode(key); if(entry == null) { - long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + long newValue = mappingFunction.applyAsLong(key); put(key, newValue); return newValue; } - long newValue = mappingFunction.applyAsLong(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public long supplyLongIfAbsent(T key, LongSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + validate(key); + Node entry = findNode(key); + if(entry == null) { + long newValue = valueProvider.getAsLong(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public long computeLongIfPresent(T key, ObjectLongUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + validate(key); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + long newValue = mappingFunction.applyAsLong(key, entry.value); entry.value = newValue; return newValue; } @Override - public long computeLongIfAbsent(T key, ToLongFunction mappingFunction) { + public long computeLongNonDefault(T key, ObjectLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); validate(key); Node entry = findNode(key); if(entry == null) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + long newValue = mappingFunction.applyAsLong(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -498,19 +522,6 @@ public long computeLongIfAbsentNonDefault(T key, ToLongFunction mappingFuncti return entry.value; } - @Override - public long supplyLongIfAbsent(T key, LongSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - validate(key); - Node entry = findNode(key); - if(entry == null) { - long newValue = valueProvider.getAsLong(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public long supplyLongIfAbsentNonDefault(T key, LongSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -530,17 +541,6 @@ public long supplyLongIfAbsentNonDefault(T key, LongSupplier valueProvider) { return entry.value; } - @Override - public long computeLongIfPresent(T key, ObjectLongUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - validate(key); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - long newValue = mappingFunction.applyAsLong(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public long computeLongIfPresentNonDefault(T key, ObjectLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1584,14 +1584,9 @@ public long computeLongIfPresent(T key, ObjectLongUnaryOperator mappingFuncti map.validate(key); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - long newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2ObjectAVLTreeMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2ObjectAVLTreeMap.java index 7eab9ddb..4f43612e 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2ObjectAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2ObjectAVLTreeMap.java @@ -362,26 +362,6 @@ public V compute(T key, ObjectObjectUnaryOperator mappingFunction) { return newValue; } - @Override - public V computeNonDefault(T key, ObjectObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - validate(key); - Node entry = findNode(key); - if(entry == null) { - V newValue = mappingFunction.apply(key, getDefaultReturnValue()); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - put(key, newValue); - return newValue; - } - V newValue = mappingFunction.apply(key, entry.value); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; - } - @Override public V computeIfAbsent(T key, UnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -401,25 +381,6 @@ public V computeIfAbsent(T key, UnaryOperator mappingFunction) { return entry.value; } - @Override - public V computeIfAbsentNonDefault(T key, UnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - validate(key); - Node entry = findNode(key); - if(entry == null) { - V newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - put(key, newValue); - return newValue; - } - if(Objects.equals(entry.value, getDefaultReturnValue())) { - V newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - entry.value = newValue; - } - return entry.value; - } - @Override public V supplyIfAbsent(T key, ObjectSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -439,25 +400,6 @@ public V supplyIfAbsent(T key, ObjectSupplier valueProvider) { return entry.value; } - @Override - public V supplyIfAbsentNonDefault(T key, ObjectSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - validate(key); - Node entry = findNode(key); - if(entry == null) { - V newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - put(key, newValue); - return newValue; - } - if(Objects.equals(entry.value, getDefaultReturnValue())) { - V newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - entry.value = newValue; - } - return entry.value; - } - @Override public V computeIfPresent(T key, ObjectObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -473,21 +415,6 @@ public V computeIfPresent(T key, ObjectObjectUnaryOperator mappingFunction return newValue; } - @Override - public V computeIfPresentNonDefault(T key, ObjectObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - validate(key); - Node entry = findNode(key); - if(entry == null || Objects.equals(entry.value, getDefaultReturnValue())) return getDefaultReturnValue(); - V newValue = mappingFunction.apply(key, entry.value); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; - } - @Override public V merge(T key, V value, ObjectObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2ObjectRBTreeMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2ObjectRBTreeMap.java index 03fc8387..b940756a 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2ObjectRBTreeMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2ObjectRBTreeMap.java @@ -361,26 +361,6 @@ public V compute(T key, ObjectObjectUnaryOperator mappingFunction) { return newValue; } - @Override - public V computeNonDefault(T key, ObjectObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - validate(key); - Node entry = findNode(key); - if(entry == null) { - V newValue = mappingFunction.apply(key, getDefaultReturnValue()); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - put(key, newValue); - return newValue; - } - V newValue = mappingFunction.apply(key, entry.value); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; - } - @Override public V computeIfAbsent(T key, UnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -400,25 +380,6 @@ public V computeIfAbsent(T key, UnaryOperator mappingFunction) { return entry.value; } - @Override - public V computeIfAbsentNonDefault(T key, UnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - validate(key); - Node entry = findNode(key); - if(entry == null) { - V newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - put(key, newValue); - return newValue; - } - if(Objects.equals(entry.value, getDefaultReturnValue())) { - V newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - entry.value = newValue; - } - return entry.value; - } - @Override public V supplyIfAbsent(T key, ObjectSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -438,25 +399,6 @@ public V supplyIfAbsent(T key, ObjectSupplier valueProvider) { return entry.value; } - @Override - public V supplyIfAbsentNonDefault(T key, ObjectSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - validate(key); - Node entry = findNode(key); - if(entry == null) { - V newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - put(key, newValue); - return newValue; - } - if(Objects.equals(entry.value, getDefaultReturnValue())) { - V newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - entry.value = newValue; - } - return entry.value; - } - @Override public V computeIfPresent(T key, ObjectObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -472,21 +414,6 @@ public V computeIfPresent(T key, ObjectObjectUnaryOperator mappingFunction return newValue; } - @Override - public V computeIfPresentNonDefault(T key, ObjectObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - validate(key); - Node entry = findNode(key); - if(entry == null || Objects.equals(entry.value, getDefaultReturnValue())) return getDefaultReturnValue(); - V newValue = mappingFunction.apply(key, entry.value); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; - } - @Override public V merge(T key, V value, ObjectObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2ShortAVLTreeMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2ShortAVLTreeMap.java index e6eff988..b24f665d 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2ShortAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2ShortAVLTreeMap.java @@ -447,36 +447,60 @@ public short computeShort(T key, ObjectShortUnaryOperator mappingFunction) { } @Override - public short computeShortNonDefault(T key, ObjectShortUnaryOperator mappingFunction) { + public short computeShortIfAbsent(T key, ToShortFunction mappingFunction) { Objects.requireNonNull(mappingFunction); validate(key); Node entry = findNode(key); if(entry == null) { - short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + short newValue = mappingFunction.applyAsShort(key); put(key, newValue); return newValue; } - short newValue = mappingFunction.applyAsShort(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public short supplyShortIfAbsent(T key, ShortSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + validate(key); + Node entry = findNode(key); + if(entry == null) { + short newValue = valueProvider.getAsShort(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public short computeShortIfPresent(T key, ObjectShortUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + validate(key); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + short newValue = mappingFunction.applyAsShort(key, entry.value); entry.value = newValue; return newValue; } @Override - public short computeShortIfAbsent(T key, ToShortFunction mappingFunction) { + public short computeShortNonDefault(T key, ObjectShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); validate(key); Node entry = findNode(key); if(entry == null) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + short newValue = mappingFunction.applyAsShort(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -498,49 +522,25 @@ public short computeShortIfAbsentNonDefault(T key, ToShortFunction mappingFun return entry.value; } - @Override - public short supplyShortIfAbsent(T key, ShortSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - validate(key); - Node entry = findNode(key); - if(entry == null) { - short newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public short supplyShortIfAbsentNonDefault(T key, ShortSupplier valueProvider) { Objects.requireNonNull(valueProvider); validate(key); Node entry = findNode(key); if(entry == null) { - short newValue = valueProvider.getAsInt(); + short newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } if(entry.value == getDefaultReturnValue()) { - short newValue = valueProvider.getAsInt(); + short newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; entry.value = newValue; } return entry.value; } - @Override - public short computeShortIfPresent(T key, ObjectShortUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - validate(key); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - short newValue = mappingFunction.applyAsShort(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public short computeShortIfPresentNonDefault(T key, ObjectShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1520,14 +1520,9 @@ public short computeShortIfPresent(T key, ObjectShortUnaryOperator mappingFun map.validate(key); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - short newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2ShortRBTreeMap.java b/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2ShortRBTreeMap.java index 01c479c5..d6b647ea 100644 --- a/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2ShortRBTreeMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/impl/tree/Object2ShortRBTreeMap.java @@ -447,36 +447,60 @@ public short computeShort(T key, ObjectShortUnaryOperator mappingFunction) { } @Override - public short computeShortNonDefault(T key, ObjectShortUnaryOperator mappingFunction) { + public short computeShortIfAbsent(T key, ToShortFunction mappingFunction) { Objects.requireNonNull(mappingFunction); validate(key); Node entry = findNode(key); if(entry == null) { - short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + short newValue = mappingFunction.applyAsShort(key); put(key, newValue); return newValue; } - short newValue = mappingFunction.applyAsShort(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public short supplyShortIfAbsent(T key, ShortSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + validate(key); + Node entry = findNode(key); + if(entry == null) { + short newValue = valueProvider.getAsShort(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public short computeShortIfPresent(T key, ObjectShortUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + validate(key); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + short newValue = mappingFunction.applyAsShort(key, entry.value); entry.value = newValue; return newValue; } @Override - public short computeShortIfAbsent(T key, ToShortFunction mappingFunction) { + public short computeShortNonDefault(T key, ObjectShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); validate(key); Node entry = findNode(key); if(entry == null) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + short newValue = mappingFunction.applyAsShort(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -498,49 +522,25 @@ public short computeShortIfAbsentNonDefault(T key, ToShortFunction mappingFun return entry.value; } - @Override - public short supplyShortIfAbsent(T key, ShortSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - validate(key); - Node entry = findNode(key); - if(entry == null) { - short newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public short supplyShortIfAbsentNonDefault(T key, ShortSupplier valueProvider) { Objects.requireNonNull(valueProvider); validate(key); Node entry = findNode(key); if(entry == null) { - short newValue = valueProvider.getAsInt(); + short newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } if(entry.value == getDefaultReturnValue()) { - short newValue = valueProvider.getAsInt(); + short newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; entry.value = newValue; } return entry.value; } - @Override - public short computeShortIfPresent(T key, ObjectShortUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - validate(key); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - short newValue = mappingFunction.applyAsShort(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public short computeShortIfPresentNonDefault(T key, ObjectShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1584,14 +1584,9 @@ public short computeShortIfPresent(T key, ObjectShortUnaryOperator mappingFun map.validate(key); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - short newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/objects/maps/interfaces/Object2BooleanMap.java b/src/main/java/speiger/src/collections/objects/maps/interfaces/Object2BooleanMap.java index 5bcb2995..22316bb9 100644 --- a/src/main/java/speiger/src/collections/objects/maps/interfaces/Object2BooleanMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/interfaces/Object2BooleanMap.java @@ -268,41 +268,51 @@ public default boolean remove(Object key, Object value) { */ public boolean computeBoolean(T key, ObjectBooleanUnaryOperator mappingFunction); /** - * A Type Specific compute method to reduce boxing/unboxing + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation + * @param mappingFunction the operator that should generate the value if not present + * @return the result of the computed value or present value */ - public boolean computeBooleanNonDefault(T key, ObjectBooleanUnaryOperator mappingFunction); + public boolean computeBooleanIfAbsent(T key, Predicate mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present + * @param valueProvider the value if not present * @return the result of the computed value or present value + */ + public boolean supplyBooleanIfAbsent(T key, BooleanSupplier valueProvider); + /** + * A Type Specific compute method to reduce boxing/unboxing + * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". + * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. + * @param key the key that should be computed + * @param mappingFunction the operator that should generate the value if present + * @return the result of the default return value or present value + * @note if not present then compute is not executed */ - public boolean computeBooleanIfAbsent(T key, Predicate mappingFunction); + public boolean computeBooleanIfPresent(T key, ObjectBooleanUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value + * @param mappingFunction the operator that should generate the value + * @return the result of the computation */ - public boolean computeBooleanIfAbsentNonDefault(T key, Predicate mappingFunction); + public boolean computeBooleanNonDefault(T key, ObjectBooleanUnaryOperator mappingFunction); /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param valueProvider the value if not present + * @param mappingFunction the operator that should generate the value if not present * @return the result of the computed value or present value - */ - public boolean supplyBooleanIfAbsent(T key, BooleanSupplier valueProvider); + */ + public boolean computeBooleanIfAbsentNonDefault(T key, Predicate mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -312,16 +322,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public boolean supplyBooleanIfAbsentNonDefault(T key, BooleanSupplier valueProvider); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public boolean computeBooleanIfPresent(T key, ObjectBooleanUnaryOperator mappingFunction); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/objects/maps/interfaces/Object2ByteMap.java b/src/main/java/speiger/src/collections/objects/maps/interfaces/Object2ByteMap.java index 12f7845d..e9e2cf1c 100644 --- a/src/main/java/speiger/src/collections/objects/maps/interfaces/Object2ByteMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/interfaces/Object2ByteMap.java @@ -293,41 +293,51 @@ public default boolean remove(Object key, Object value) { */ public byte computeByte(T key, ObjectByteUnaryOperator mappingFunction); /** - * A Type Specific compute method to reduce boxing/unboxing + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation + * @param mappingFunction the operator that should generate the value if not present + * @return the result of the computed value or present value */ - public byte computeByteNonDefault(T key, ObjectByteUnaryOperator mappingFunction); + public byte computeByteIfAbsent(T key, ToByteFunction mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present + * @param valueProvider the value if not present * @return the result of the computed value or present value + */ + public byte supplyByteIfAbsent(T key, ByteSupplier valueProvider); + /** + * A Type Specific compute method to reduce boxing/unboxing + * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". + * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. + * @param key the key that should be computed + * @param mappingFunction the operator that should generate the value if present + * @return the result of the default return value or present value + * @note if not present then compute is not executed */ - public byte computeByteIfAbsent(T key, ToByteFunction mappingFunction); + public byte computeByteIfPresent(T key, ObjectByteUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value + * @param mappingFunction the operator that should generate the value + * @return the result of the computation */ - public byte computeByteIfAbsentNonDefault(T key, ToByteFunction mappingFunction); + public byte computeByteNonDefault(T key, ObjectByteUnaryOperator mappingFunction); /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param valueProvider the value if not present + * @param mappingFunction the operator that should generate the value if not present * @return the result of the computed value or present value - */ - public byte supplyByteIfAbsent(T key, ByteSupplier valueProvider); + */ + public byte computeByteIfAbsentNonDefault(T key, ToByteFunction mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -337,16 +347,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public byte supplyByteIfAbsentNonDefault(T key, ByteSupplier valueProvider); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public byte computeByteIfPresent(T key, ObjectByteUnaryOperator mappingFunction); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/objects/maps/interfaces/Object2CharMap.java b/src/main/java/speiger/src/collections/objects/maps/interfaces/Object2CharMap.java index 20c5650c..9703047b 100644 --- a/src/main/java/speiger/src/collections/objects/maps/interfaces/Object2CharMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/interfaces/Object2CharMap.java @@ -293,41 +293,51 @@ public default boolean remove(Object key, Object value) { */ public char computeChar(T key, ObjectCharUnaryOperator mappingFunction); /** - * A Type Specific compute method to reduce boxing/unboxing + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation + * @param mappingFunction the operator that should generate the value if not present + * @return the result of the computed value or present value */ - public char computeCharNonDefault(T key, ObjectCharUnaryOperator mappingFunction); + public char computeCharIfAbsent(T key, ToCharFunction mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present + * @param valueProvider the value if not present * @return the result of the computed value or present value + */ + public char supplyCharIfAbsent(T key, CharSupplier valueProvider); + /** + * A Type Specific compute method to reduce boxing/unboxing + * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". + * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. + * @param key the key that should be computed + * @param mappingFunction the operator that should generate the value if present + * @return the result of the default return value or present value + * @note if not present then compute is not executed */ - public char computeCharIfAbsent(T key, ToCharFunction mappingFunction); + public char computeCharIfPresent(T key, ObjectCharUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value + * @param mappingFunction the operator that should generate the value + * @return the result of the computation */ - public char computeCharIfAbsentNonDefault(T key, ToCharFunction mappingFunction); + public char computeCharNonDefault(T key, ObjectCharUnaryOperator mappingFunction); /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param valueProvider the value if not present + * @param mappingFunction the operator that should generate the value if not present * @return the result of the computed value or present value - */ - public char supplyCharIfAbsent(T key, CharSupplier valueProvider); + */ + public char computeCharIfAbsentNonDefault(T key, ToCharFunction mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -337,16 +347,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public char supplyCharIfAbsentNonDefault(T key, CharSupplier valueProvider); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public char computeCharIfPresent(T key, ObjectCharUnaryOperator mappingFunction); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/objects/maps/interfaces/Object2DoubleMap.java b/src/main/java/speiger/src/collections/objects/maps/interfaces/Object2DoubleMap.java index f81c8f41..090d645e 100644 --- a/src/main/java/speiger/src/collections/objects/maps/interfaces/Object2DoubleMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/interfaces/Object2DoubleMap.java @@ -293,41 +293,51 @@ public default boolean remove(Object key, Object value) { */ public double computeDouble(T key, ObjectDoubleUnaryOperator mappingFunction); /** - * A Type Specific compute method to reduce boxing/unboxing + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation + * @param mappingFunction the operator that should generate the value if not present + * @return the result of the computed value or present value */ - public double computeDoubleNonDefault(T key, ObjectDoubleUnaryOperator mappingFunction); + public double computeDoubleIfAbsent(T key, ToDoubleFunction mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present + * @param valueProvider the value if not present * @return the result of the computed value or present value + */ + public double supplyDoubleIfAbsent(T key, DoubleSupplier valueProvider); + /** + * A Type Specific compute method to reduce boxing/unboxing + * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". + * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. + * @param key the key that should be computed + * @param mappingFunction the operator that should generate the value if present + * @return the result of the default return value or present value + * @note if not present then compute is not executed */ - public double computeDoubleIfAbsent(T key, ToDoubleFunction mappingFunction); + public double computeDoubleIfPresent(T key, ObjectDoubleUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value + * @param mappingFunction the operator that should generate the value + * @return the result of the computation */ - public double computeDoubleIfAbsentNonDefault(T key, ToDoubleFunction mappingFunction); + public double computeDoubleNonDefault(T key, ObjectDoubleUnaryOperator mappingFunction); /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param valueProvider the value if not present + * @param mappingFunction the operator that should generate the value if not present * @return the result of the computed value or present value - */ - public double supplyDoubleIfAbsent(T key, DoubleSupplier valueProvider); + */ + public double computeDoubleIfAbsentNonDefault(T key, ToDoubleFunction mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -337,16 +347,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public double supplyDoubleIfAbsentNonDefault(T key, DoubleSupplier valueProvider); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public double computeDoubleIfPresent(T key, ObjectDoubleUnaryOperator mappingFunction); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/objects/maps/interfaces/Object2FloatMap.java b/src/main/java/speiger/src/collections/objects/maps/interfaces/Object2FloatMap.java index a7393f80..29b9a8a5 100644 --- a/src/main/java/speiger/src/collections/objects/maps/interfaces/Object2FloatMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/interfaces/Object2FloatMap.java @@ -293,41 +293,51 @@ public default boolean remove(Object key, Object value) { */ public float computeFloat(T key, ObjectFloatUnaryOperator mappingFunction); /** - * A Type Specific compute method to reduce boxing/unboxing + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation + * @param mappingFunction the operator that should generate the value if not present + * @return the result of the computed value or present value */ - public float computeFloatNonDefault(T key, ObjectFloatUnaryOperator mappingFunction); + public float computeFloatIfAbsent(T key, ToFloatFunction mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present + * @param valueProvider the value if not present * @return the result of the computed value or present value + */ + public float supplyFloatIfAbsent(T key, FloatSupplier valueProvider); + /** + * A Type Specific compute method to reduce boxing/unboxing + * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". + * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. + * @param key the key that should be computed + * @param mappingFunction the operator that should generate the value if present + * @return the result of the default return value or present value + * @note if not present then compute is not executed */ - public float computeFloatIfAbsent(T key, ToFloatFunction mappingFunction); + public float computeFloatIfPresent(T key, ObjectFloatUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value + * @param mappingFunction the operator that should generate the value + * @return the result of the computation */ - public float computeFloatIfAbsentNonDefault(T key, ToFloatFunction mappingFunction); + public float computeFloatNonDefault(T key, ObjectFloatUnaryOperator mappingFunction); /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param valueProvider the value if not present + * @param mappingFunction the operator that should generate the value if not present * @return the result of the computed value or present value - */ - public float supplyFloatIfAbsent(T key, FloatSupplier valueProvider); + */ + public float computeFloatIfAbsentNonDefault(T key, ToFloatFunction mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -337,16 +347,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public float supplyFloatIfAbsentNonDefault(T key, FloatSupplier valueProvider); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public float computeFloatIfPresent(T key, ObjectFloatUnaryOperator mappingFunction); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/objects/maps/interfaces/Object2IntMap.java b/src/main/java/speiger/src/collections/objects/maps/interfaces/Object2IntMap.java index c1018f83..c717f927 100644 --- a/src/main/java/speiger/src/collections/objects/maps/interfaces/Object2IntMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/interfaces/Object2IntMap.java @@ -293,41 +293,51 @@ public default boolean remove(Object key, Object value) { */ public int computeInt(T key, ObjectIntUnaryOperator mappingFunction); /** - * A Type Specific compute method to reduce boxing/unboxing + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation + * @param mappingFunction the operator that should generate the value if not present + * @return the result of the computed value or present value */ - public int computeIntNonDefault(T key, ObjectIntUnaryOperator mappingFunction); + public int computeIntIfAbsent(T key, ToIntFunction mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present + * @param valueProvider the value if not present * @return the result of the computed value or present value + */ + public int supplyIntIfAbsent(T key, IntSupplier valueProvider); + /** + * A Type Specific compute method to reduce boxing/unboxing + * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". + * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. + * @param key the key that should be computed + * @param mappingFunction the operator that should generate the value if present + * @return the result of the default return value or present value + * @note if not present then compute is not executed */ - public int computeIntIfAbsent(T key, ToIntFunction mappingFunction); + public int computeIntIfPresent(T key, ObjectIntUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value + * @param mappingFunction the operator that should generate the value + * @return the result of the computation */ - public int computeIntIfAbsentNonDefault(T key, ToIntFunction mappingFunction); + public int computeIntNonDefault(T key, ObjectIntUnaryOperator mappingFunction); /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param valueProvider the value if not present + * @param mappingFunction the operator that should generate the value if not present * @return the result of the computed value or present value - */ - public int supplyIntIfAbsent(T key, IntSupplier valueProvider); + */ + public int computeIntIfAbsentNonDefault(T key, ToIntFunction mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -337,16 +347,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public int supplyIntIfAbsentNonDefault(T key, IntSupplier valueProvider); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public int computeIntIfPresent(T key, ObjectIntUnaryOperator mappingFunction); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/objects/maps/interfaces/Object2LongMap.java b/src/main/java/speiger/src/collections/objects/maps/interfaces/Object2LongMap.java index 7c95a527..9ff04631 100644 --- a/src/main/java/speiger/src/collections/objects/maps/interfaces/Object2LongMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/interfaces/Object2LongMap.java @@ -293,41 +293,51 @@ public default boolean remove(Object key, Object value) { */ public long computeLong(T key, ObjectLongUnaryOperator mappingFunction); /** - * A Type Specific compute method to reduce boxing/unboxing + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation + * @param mappingFunction the operator that should generate the value if not present + * @return the result of the computed value or present value */ - public long computeLongNonDefault(T key, ObjectLongUnaryOperator mappingFunction); + public long computeLongIfAbsent(T key, ToLongFunction mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present + * @param valueProvider the value if not present * @return the result of the computed value or present value + */ + public long supplyLongIfAbsent(T key, LongSupplier valueProvider); + /** + * A Type Specific compute method to reduce boxing/unboxing + * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". + * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. + * @param key the key that should be computed + * @param mappingFunction the operator that should generate the value if present + * @return the result of the default return value or present value + * @note if not present then compute is not executed */ - public long computeLongIfAbsent(T key, ToLongFunction mappingFunction); + public long computeLongIfPresent(T key, ObjectLongUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value + * @param mappingFunction the operator that should generate the value + * @return the result of the computation */ - public long computeLongIfAbsentNonDefault(T key, ToLongFunction mappingFunction); + public long computeLongNonDefault(T key, ObjectLongUnaryOperator mappingFunction); /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param valueProvider the value if not present + * @param mappingFunction the operator that should generate the value if not present * @return the result of the computed value or present value - */ - public long supplyLongIfAbsent(T key, LongSupplier valueProvider); + */ + public long computeLongIfAbsentNonDefault(T key, ToLongFunction mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -337,16 +347,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public long supplyLongIfAbsentNonDefault(T key, LongSupplier valueProvider); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public long computeLongIfPresent(T key, ObjectLongUnaryOperator mappingFunction); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/objects/maps/interfaces/Object2ObjectMap.java b/src/main/java/speiger/src/collections/objects/maps/interfaces/Object2ObjectMap.java index 3069edb5..3f9aeeb0 100644 --- a/src/main/java/speiger/src/collections/objects/maps/interfaces/Object2ObjectMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/interfaces/Object2ObjectMap.java @@ -197,15 +197,6 @@ public default V remove(Object key) { * @return the result of the computation */ public V compute(T key, ObjectObjectUnaryOperator mappingFunction); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation - */ - public V computeNonDefault(T key, ObjectObjectUnaryOperator mappingFunction); /** * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -215,15 +206,6 @@ public default V remove(Object key) { * @return the result of the computed value or present value */ public V computeIfAbsent(T key, UnaryOperator mappingFunction); - /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value - */ - public V computeIfAbsentNonDefault(T key, UnaryOperator mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -233,15 +215,6 @@ public default V remove(Object key) { * @return the result of the computed value or present value */ public V supplyIfAbsent(T key, ObjectSupplier valueProvider); - /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param valueProvider the value if not present - * @return the result of the computed value or present value - */ - public V supplyIfAbsentNonDefault(T key, ObjectSupplier valueProvider); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -252,16 +225,6 @@ public default V remove(Object key) { * @note if not present then compute is not executed */ public V computeIfPresent(T key, ObjectObjectUnaryOperator mappingFunction); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public V computeIfPresentNonDefault(T key, ObjectObjectUnaryOperator mappingFunction); /** * A Type Specific merge method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/objects/maps/interfaces/Object2ShortMap.java b/src/main/java/speiger/src/collections/objects/maps/interfaces/Object2ShortMap.java index 8f7d0017..2d3148fd 100644 --- a/src/main/java/speiger/src/collections/objects/maps/interfaces/Object2ShortMap.java +++ b/src/main/java/speiger/src/collections/objects/maps/interfaces/Object2ShortMap.java @@ -293,41 +293,51 @@ public default boolean remove(Object key, Object value) { */ public short computeShort(T key, ObjectShortUnaryOperator mappingFunction); /** - * A Type Specific compute method to reduce boxing/unboxing + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation + * @param mappingFunction the operator that should generate the value if not present + * @return the result of the computed value or present value */ - public short computeShortNonDefault(T key, ObjectShortUnaryOperator mappingFunction); + public short computeShortIfAbsent(T key, ToShortFunction mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present + * @param valueProvider the value if not present * @return the result of the computed value or present value + */ + public short supplyShortIfAbsent(T key, ShortSupplier valueProvider); + /** + * A Type Specific compute method to reduce boxing/unboxing + * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". + * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. + * @param key the key that should be computed + * @param mappingFunction the operator that should generate the value if present + * @return the result of the default return value or present value + * @note if not present then compute is not executed */ - public short computeShortIfAbsent(T key, ToShortFunction mappingFunction); + public short computeShortIfPresent(T key, ObjectShortUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value + * @param mappingFunction the operator that should generate the value + * @return the result of the computation */ - public short computeShortIfAbsentNonDefault(T key, ToShortFunction mappingFunction); + public short computeShortNonDefault(T key, ObjectShortUnaryOperator mappingFunction); /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param valueProvider the value if not present + * @param mappingFunction the operator that should generate the value if not present * @return the result of the computed value or present value - */ - public short supplyShortIfAbsent(T key, ShortSupplier valueProvider); + */ + public short computeShortIfAbsentNonDefault(T key, ToShortFunction mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -337,16 +347,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public short supplyShortIfAbsentNonDefault(T key, ShortSupplier valueProvider); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public short computeShortIfPresent(T key, ObjectShortUnaryOperator mappingFunction); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/objects/queues/ObjectArrayFIFOQueue.java b/src/main/java/speiger/src/collections/objects/queues/ObjectArrayFIFOQueue.java index 2bf92dca..c72376f4 100644 --- a/src/main/java/speiger/src/collections/objects/queues/ObjectArrayFIFOQueue.java +++ b/src/main/java/speiger/src/collections/objects/queues/ObjectArrayFIFOQueue.java @@ -151,6 +151,15 @@ public T peek(int index) { return index >= array.length ? array[index-array.length] : array[index]; } + @Override + public boolean contains(T e) { + if(first == last) return false; + for(int i = 0,m=size();i c) { */ public default T first() { return peek(0); } + /** + * Method to find out if a element is part of the queue + * @param e the element that is searched for + * @return true if the element is in the queue + */ + public boolean contains(T e); + /** * Removes the first found element in the queue * @param e the element that should be removed diff --git a/src/main/java/speiger/src/collections/objects/utils/ObjectAsyncBuilder.java b/src/main/java/speiger/src/collections/objects/utils/ObjectAsyncBuilder.java index 9e54d39e..67c70dc2 100644 --- a/src/main/java/speiger/src/collections/objects/utils/ObjectAsyncBuilder.java +++ b/src/main/java/speiger/src/collections/objects/utils/ObjectAsyncBuilder.java @@ -11,20 +11,31 @@ import java.util.function.BiFunction; import java.util.Comparator; +import speiger.src.collections.objects.functions.function.Predicate; +import speiger.src.collections.booleans.utils.BooleanAsyncBuilder; +import speiger.src.collections.objects.functions.function.ToByteFunction; +import speiger.src.collections.bytes.utils.ByteAsyncBuilder; +import speiger.src.collections.objects.functions.function.ToShortFunction; +import speiger.src.collections.shorts.utils.ShortAsyncBuilder; +import speiger.src.collections.objects.functions.function.ToIntFunction; +import speiger.src.collections.ints.utils.IntAsyncBuilder; +import speiger.src.collections.objects.functions.function.ToLongFunction; +import speiger.src.collections.longs.utils.LongAsyncBuilder; +import speiger.src.collections.objects.functions.function.ToFloatFunction; +import speiger.src.collections.floats.utils.FloatAsyncBuilder; +import speiger.src.collections.objects.functions.function.ToDoubleFunction; +import speiger.src.collections.doubles.utils.DoubleAsyncBuilder; import speiger.src.collections.objects.collections.ObjectIterable; import speiger.src.collections.objects.collections.ObjectCollection; import speiger.src.collections.objects.collections.ObjectIterator; import speiger.src.collections.objects.functions.ObjectTask; -import speiger.src.collections.objects.functions.function.Predicate; import speiger.src.collections.objects.functions.function.UnaryOperator; import speiger.src.collections.objects.functions.function.ObjectObjectUnaryOperator; import speiger.src.collections.objects.lists.ObjectList; import speiger.src.collections.objects.lists.ObjectArrayList; import speiger.src.collections.objects.sets.ObjectSet; import speiger.src.collections.objects.sets.ObjectLinkedOpenHashSet; -import speiger.src.collections.booleans.utils.BooleanAsyncBuilder; import speiger.src.collections.booleans.utils.BooleanAsyncBuilder.BaseBooleanTask; -import speiger.src.collections.ints.utils.IntAsyncBuilder; import speiger.src.collections.ints.utils.IntAsyncBuilder.BaseIntTask; import speiger.src.collections.utils.ISizeProvider; import speiger.src.collections.utils.SanityChecks; @@ -140,6 +151,69 @@ public ObjectAsyncBuilder arrayflatMap(UnaryOperator mapper) { return new ObjectAsyncBuilder<>(ObjectIterables.arrayFlatMap(iterable, mapper)); } + /** + * Maps the elements to something else + * @param mapper the mapping function + * @return a new Builder Object with the mapped Iterable + */ + public BooleanAsyncBuilder mapToBoolean(Predicate mapper) { + return new BooleanAsyncBuilder(ObjectIterables.mapToBoolean(iterable, mapper)); + } + + /** + * Maps the elements to something else + * @param mapper the mapping function + * @return a new Builder Object with the mapped Iterable + */ + public ByteAsyncBuilder mapToByte(ToByteFunction mapper) { + return new ByteAsyncBuilder(ObjectIterables.mapToByte(iterable, mapper)); + } + + /** + * Maps the elements to something else + * @param mapper the mapping function + * @return a new Builder Object with the mapped Iterable + */ + public ShortAsyncBuilder mapToShort(ToShortFunction mapper) { + return new ShortAsyncBuilder(ObjectIterables.mapToShort(iterable, mapper)); + } + + /** + * Maps the elements to something else + * @param mapper the mapping function + * @return a new Builder Object with the mapped Iterable + */ + public IntAsyncBuilder mapToInt(ToIntFunction mapper) { + return new IntAsyncBuilder(ObjectIterables.mapToInt(iterable, mapper)); + } + + /** + * Maps the elements to something else + * @param mapper the mapping function + * @return a new Builder Object with the mapped Iterable + */ + public LongAsyncBuilder mapToLong(ToLongFunction mapper) { + return new LongAsyncBuilder(ObjectIterables.mapToLong(iterable, mapper)); + } + + /** + * Maps the elements to something else + * @param mapper the mapping function + * @return a new Builder Object with the mapped Iterable + */ + public FloatAsyncBuilder mapToFloat(ToFloatFunction mapper) { + return new FloatAsyncBuilder(ObjectIterables.mapToFloat(iterable, mapper)); + } + + /** + * Maps the elements to something else + * @param mapper the mapping function + * @return a new Builder Object with the mapped Iterable + */ + public DoubleAsyncBuilder mapToDouble(ToDoubleFunction mapper) { + return new DoubleAsyncBuilder(ObjectIterables.mapToDouble(iterable, mapper)); + } + /** * Filters out the unwanted elements out of the Iterable * @param filter the elements that should be kept diff --git a/src/main/java/speiger/src/collections/objects/utils/ObjectIterables.java b/src/main/java/speiger/src/collections/objects/utils/ObjectIterables.java index 374376ec..f1f50653 100644 --- a/src/main/java/speiger/src/collections/objects/utils/ObjectIterables.java +++ b/src/main/java/speiger/src/collections/objects/utils/ObjectIterables.java @@ -8,6 +8,33 @@ import speiger.src.collections.objects.collections.ObjectIterable; import speiger.src.collections.objects.collections.ObjectCollection; +import speiger.src.collections.booleans.functions.BooleanConsumer; +import speiger.src.collections.booleans.collections.BooleanIterable; +import speiger.src.collections.booleans.collections.BooleanIterator; +import speiger.src.collections.bytes.functions.ByteConsumer; +import speiger.src.collections.objects.functions.function.ToByteFunction; +import speiger.src.collections.bytes.collections.ByteIterable; +import speiger.src.collections.bytes.collections.ByteIterator; +import speiger.src.collections.shorts.functions.ShortConsumer; +import speiger.src.collections.objects.functions.function.ToShortFunction; +import speiger.src.collections.shorts.collections.ShortIterable; +import speiger.src.collections.shorts.collections.ShortIterator; +import speiger.src.collections.ints.functions.IntConsumer; +import speiger.src.collections.objects.functions.function.ToIntFunction; +import speiger.src.collections.ints.collections.IntIterable; +import speiger.src.collections.ints.collections.IntIterator; +import speiger.src.collections.longs.functions.LongConsumer; +import speiger.src.collections.objects.functions.function.ToLongFunction; +import speiger.src.collections.longs.collections.LongIterable; +import speiger.src.collections.longs.collections.LongIterator; +import speiger.src.collections.floats.functions.FloatConsumer; +import speiger.src.collections.objects.functions.function.ToFloatFunction; +import speiger.src.collections.floats.collections.FloatIterable; +import speiger.src.collections.floats.collections.FloatIterator; +import speiger.src.collections.doubles.functions.DoubleConsumer; +import speiger.src.collections.objects.functions.function.ToDoubleFunction; +import speiger.src.collections.doubles.collections.DoubleIterable; +import speiger.src.collections.doubles.collections.DoubleIterator; import speiger.src.collections.objects.collections.ObjectIterator; import speiger.src.collections.objects.functions.function.UnaryOperator; import speiger.src.collections.utils.ISizeProvider; @@ -41,6 +68,160 @@ public static ObjectIterable map(ObjectIterable iterable, UnaryOper return new MappedIterable<>(iterable, mapper); } + /** + * A Helper function that maps a Java-Iterable into a new Type. + * @param iterable the iterable that should be mapped + * @param mapper the function that decides what the result turns into. + * @param the keyType of elements maintained by this Collection + * @return a iterable that is mapped to a new result + */ + public static BooleanIterable mapToBoolean(Iterable iterable, Predicate mapper) { + return new MappedBooleanIterable<>(wrap(iterable), mapper); + } + + /** + * A Helper function that maps a Iterable into a new Type. + * @param iterable the iterable that should be mapped + * @param mapper the function that decides what the result turns into. + * @param the keyType of elements maintained by this Collection + * @return a iterable that is mapped to a new result + */ + public static BooleanIterable mapToBoolean(ObjectIterable iterable, Predicate mapper) { + return new MappedBooleanIterable<>(iterable, mapper); + } + + /** + * A Helper function that maps a Java-Iterable into a new Type. + * @param iterable the iterable that should be mapped + * @param mapper the function that decides what the result turns into. + * @param the keyType of elements maintained by this Collection + * @return a iterable that is mapped to a new result + */ + public static ByteIterable mapToByte(Iterable iterable, ToByteFunction mapper) { + return new MappedByteIterable<>(wrap(iterable), mapper); + } + + /** + * A Helper function that maps a Iterable into a new Type. + * @param iterable the iterable that should be mapped + * @param mapper the function that decides what the result turns into. + * @param the keyType of elements maintained by this Collection + * @return a iterable that is mapped to a new result + */ + public static ByteIterable mapToByte(ObjectIterable iterable, ToByteFunction mapper) { + return new MappedByteIterable<>(iterable, mapper); + } + + /** + * A Helper function that maps a Java-Iterable into a new Type. + * @param iterable the iterable that should be mapped + * @param mapper the function that decides what the result turns into. + * @param the keyType of elements maintained by this Collection + * @return a iterable that is mapped to a new result + */ + public static ShortIterable mapToShort(Iterable iterable, ToShortFunction mapper) { + return new MappedShortIterable<>(wrap(iterable), mapper); + } + + /** + * A Helper function that maps a Iterable into a new Type. + * @param iterable the iterable that should be mapped + * @param mapper the function that decides what the result turns into. + * @param the keyType of elements maintained by this Collection + * @return a iterable that is mapped to a new result + */ + public static ShortIterable mapToShort(ObjectIterable iterable, ToShortFunction mapper) { + return new MappedShortIterable<>(iterable, mapper); + } + + /** + * A Helper function that maps a Java-Iterable into a new Type. + * @param iterable the iterable that should be mapped + * @param mapper the function that decides what the result turns into. + * @param the keyType of elements maintained by this Collection + * @return a iterable that is mapped to a new result + */ + public static IntIterable mapToInt(Iterable iterable, ToIntFunction mapper) { + return new MappedIntIterable<>(wrap(iterable), mapper); + } + + /** + * A Helper function that maps a Iterable into a new Type. + * @param iterable the iterable that should be mapped + * @param mapper the function that decides what the result turns into. + * @param the keyType of elements maintained by this Collection + * @return a iterable that is mapped to a new result + */ + public static IntIterable mapToInt(ObjectIterable iterable, ToIntFunction mapper) { + return new MappedIntIterable<>(iterable, mapper); + } + + /** + * A Helper function that maps a Java-Iterable into a new Type. + * @param iterable the iterable that should be mapped + * @param mapper the function that decides what the result turns into. + * @param the keyType of elements maintained by this Collection + * @return a iterable that is mapped to a new result + */ + public static LongIterable mapToLong(Iterable iterable, ToLongFunction mapper) { + return new MappedLongIterable<>(wrap(iterable), mapper); + } + + /** + * A Helper function that maps a Iterable into a new Type. + * @param iterable the iterable that should be mapped + * @param mapper the function that decides what the result turns into. + * @param the keyType of elements maintained by this Collection + * @return a iterable that is mapped to a new result + */ + public static LongIterable mapToLong(ObjectIterable iterable, ToLongFunction mapper) { + return new MappedLongIterable<>(iterable, mapper); + } + + /** + * A Helper function that maps a Java-Iterable into a new Type. + * @param iterable the iterable that should be mapped + * @param mapper the function that decides what the result turns into. + * @param the keyType of elements maintained by this Collection + * @return a iterable that is mapped to a new result + */ + public static FloatIterable mapToFloat(Iterable iterable, ToFloatFunction mapper) { + return new MappedFloatIterable<>(wrap(iterable), mapper); + } + + /** + * A Helper function that maps a Iterable into a new Type. + * @param iterable the iterable that should be mapped + * @param mapper the function that decides what the result turns into. + * @param the keyType of elements maintained by this Collection + * @return a iterable that is mapped to a new result + */ + public static FloatIterable mapToFloat(ObjectIterable iterable, ToFloatFunction mapper) { + return new MappedFloatIterable<>(iterable, mapper); + } + + /** + * A Helper function that maps a Java-Iterable into a new Type. + * @param iterable the iterable that should be mapped + * @param mapper the function that decides what the result turns into. + * @param the keyType of elements maintained by this Collection + * @return a iterable that is mapped to a new result + */ + public static DoubleIterable mapToDouble(Iterable iterable, ToDoubleFunction mapper) { + return new MappedDoubleIterable<>(wrap(iterable), mapper); + } + + /** + * A Helper function that maps a Iterable into a new Type. + * @param iterable the iterable that should be mapped + * @param mapper the function that decides what the result turns into. + * @param the keyType of elements maintained by this Collection + * @return a iterable that is mapped to a new result + */ + public static DoubleIterable mapToDouble(ObjectIterable iterable, ToDoubleFunction mapper) { + return new MappedDoubleIterable<>(iterable, mapper); + } + /** * A Helper function that flatMaps a Java-Iterable into a new Type. * @param iterable the iterable that should be flatMapped @@ -257,6 +438,195 @@ public void forEach(Consumer action) { } } + private static class MappedBooleanIterable implements BooleanIterable, ISizeProvider + { + ObjectIterable iterable; + Predicate mapper; + + MappedBooleanIterable(ObjectIterable iterable, Predicate mapper) { + this.iterable = iterable; + this.mapper = mapper; + } + + public BooleanIterator iterator() { + return ObjectIterators.mapToBoolean(iterable.iterator(), mapper); + } + + @Override + public int size() { + ISizeProvider prov = ISizeProvider.of(this); + return prov == null ? -1 : prov.size(); + } + + @Override + public void forEach(BooleanConsumer action) { + Objects.requireNonNull(action); + iterable.forEach(E -> action.accept(mapper.test(E))); + } + } + + private static class MappedByteIterable implements ByteIterable, ISizeProvider + { + ObjectIterable iterable; + ToByteFunction mapper; + + MappedByteIterable(ObjectIterable iterable, ToByteFunction mapper) { + this.iterable = iterable; + this.mapper = mapper; + } + + public ByteIterator iterator() { + return ObjectIterators.mapToByte(iterable.iterator(), mapper); + } + + @Override + public int size() { + ISizeProvider prov = ISizeProvider.of(this); + return prov == null ? -1 : prov.size(); + } + + @Override + public void forEach(ByteConsumer action) { + Objects.requireNonNull(action); + iterable.forEach(E -> action.accept(mapper.applyAsByte(E))); + } + } + + private static class MappedShortIterable implements ShortIterable, ISizeProvider + { + ObjectIterable iterable; + ToShortFunction mapper; + + MappedShortIterable(ObjectIterable iterable, ToShortFunction mapper) { + this.iterable = iterable; + this.mapper = mapper; + } + + public ShortIterator iterator() { + return ObjectIterators.mapToShort(iterable.iterator(), mapper); + } + + @Override + public int size() { + ISizeProvider prov = ISizeProvider.of(this); + return prov == null ? -1 : prov.size(); + } + + @Override + public void forEach(ShortConsumer action) { + Objects.requireNonNull(action); + iterable.forEach(E -> action.accept(mapper.applyAsShort(E))); + } + } + + private static class MappedIntIterable implements IntIterable, ISizeProvider + { + ObjectIterable iterable; + ToIntFunction mapper; + + MappedIntIterable(ObjectIterable iterable, ToIntFunction mapper) { + this.iterable = iterable; + this.mapper = mapper; + } + + public IntIterator iterator() { + return ObjectIterators.mapToInt(iterable.iterator(), mapper); + } + + @Override + public int size() { + ISizeProvider prov = ISizeProvider.of(this); + return prov == null ? -1 : prov.size(); + } + + @Override + public void forEach(IntConsumer action) { + Objects.requireNonNull(action); + iterable.forEach(E -> action.accept(mapper.applyAsInt(E))); + } + } + + private static class MappedLongIterable implements LongIterable, ISizeProvider + { + ObjectIterable iterable; + ToLongFunction mapper; + + MappedLongIterable(ObjectIterable iterable, ToLongFunction mapper) { + this.iterable = iterable; + this.mapper = mapper; + } + + public LongIterator iterator() { + return ObjectIterators.mapToLong(iterable.iterator(), mapper); + } + + @Override + public int size() { + ISizeProvider prov = ISizeProvider.of(this); + return prov == null ? -1 : prov.size(); + } + + @Override + public void forEach(LongConsumer action) { + Objects.requireNonNull(action); + iterable.forEach(E -> action.accept(mapper.applyAsLong(E))); + } + } + + private static class MappedFloatIterable implements FloatIterable, ISizeProvider + { + ObjectIterable iterable; + ToFloatFunction mapper; + + MappedFloatIterable(ObjectIterable iterable, ToFloatFunction mapper) { + this.iterable = iterable; + this.mapper = mapper; + } + + public FloatIterator iterator() { + return ObjectIterators.mapToFloat(iterable.iterator(), mapper); + } + + @Override + public int size() { + ISizeProvider prov = ISizeProvider.of(this); + return prov == null ? -1 : prov.size(); + } + + @Override + public void forEach(FloatConsumer action) { + Objects.requireNonNull(action); + iterable.forEach(E -> action.accept(mapper.applyAsFloat(E))); + } + } + + private static class MappedDoubleIterable implements DoubleIterable, ISizeProvider + { + ObjectIterable iterable; + ToDoubleFunction mapper; + + MappedDoubleIterable(ObjectIterable iterable, ToDoubleFunction mapper) { + this.iterable = iterable; + this.mapper = mapper; + } + + public DoubleIterator iterator() { + return ObjectIterators.mapToDouble(iterable.iterator(), mapper); + } + + @Override + public int size() { + ISizeProvider prov = ISizeProvider.of(this); + return prov == null ? -1 : prov.size(); + } + + @Override + public void forEach(DoubleConsumer action) { + Objects.requireNonNull(action); + iterable.forEach(E -> action.accept(mapper.applyAsDouble(E))); + } + } + private static class MappedIterable implements ObjectIterable, ISizeProvider { ObjectIterable iterable; diff --git a/src/main/java/speiger/src/collections/objects/utils/ObjectIterators.java b/src/main/java/speiger/src/collections/objects/utils/ObjectIterators.java index 4c71ec87..dac2bcbc 100644 --- a/src/main/java/speiger/src/collections/objects/utils/ObjectIterators.java +++ b/src/main/java/speiger/src/collections/objects/utils/ObjectIterators.java @@ -7,13 +7,28 @@ import java.util.function.Predicate; import speiger.src.collections.objects.collections.ObjectIterator; +import speiger.src.collections.booleans.collections.BooleanIterator; +import speiger.src.collections.objects.functions.function.ToByteFunction; +import speiger.src.collections.bytes.collections.ByteIterator; +import speiger.src.collections.objects.functions.function.ToShortFunction; +import speiger.src.collections.shorts.collections.ShortIterator; +import speiger.src.collections.objects.functions.function.ToIntFunction; +import speiger.src.collections.ints.collections.IntIterator; +import speiger.src.collections.objects.functions.function.ToLongFunction; +import speiger.src.collections.longs.collections.LongIterator; +import speiger.src.collections.objects.functions.function.ToFloatFunction; +import speiger.src.collections.floats.collections.FloatIterator; +import speiger.src.collections.objects.functions.function.ToDoubleFunction; +import speiger.src.collections.doubles.collections.DoubleIterator; import speiger.src.collections.objects.functions.function.UnaryOperator; +import speiger.src.collections.objects.functions.consumer.ObjectObjectConsumer; import speiger.src.collections.objects.lists.ObjectList; import speiger.src.collections.objects.lists.ObjectArrayList; import speiger.src.collections.objects.lists.ObjectListIterator; import speiger.src.collections.objects.collections.ObjectBidirectionalIterator; import speiger.src.collections.objects.collections.ObjectCollection; +import speiger.src.collections.objects.utils.ObjectCollections.CollectionWrapper; /** * A Helper class for Iterators @@ -108,6 +123,160 @@ public static ObjectIterator map(ObjectIterator iterator, UnaryOper return new MappedIterator<>(iterator, mapper); } + /** + * A Helper function that maps a Java-Iterator into a new Type. + * @param iterator that should be mapped + * @param mapper the function that decides what the result turns into. + * @param the keyType of elements maintained by this Collection + * @return a iterator that is mapped to a new result + */ + public static BooleanIterator mapToBoolean(Iterator iterator, Predicate mapper) { + return new MappedBooleanIterator<>(wrap(iterator), mapper); + } + + /** + * A Helper function that maps a Iterator into a new Type. + * @param iterator that should be mapped + * @param mapper the function that decides what the result turns into. + * @param the keyType of elements maintained by this Collection + * @return a iterator that is mapped to a new result + */ + public static BooleanIterator mapToBoolean(ObjectIterator iterator, Predicate mapper) { + return new MappedBooleanIterator<>(iterator, mapper); + } + + /** + * A Helper function that maps a Java-Iterator into a new Type. + * @param iterator that should be mapped + * @param mapper the function that decides what the result turns into. + * @param the keyType of elements maintained by this Collection + * @return a iterator that is mapped to a new result + */ + public static ByteIterator mapToByte(Iterator iterator, ToByteFunction mapper) { + return new MappedByteIterator<>(wrap(iterator), mapper); + } + + /** + * A Helper function that maps a Iterator into a new Type. + * @param iterator that should be mapped + * @param mapper the function that decides what the result turns into. + * @param the keyType of elements maintained by this Collection + * @return a iterator that is mapped to a new result + */ + public static ByteIterator mapToByte(ObjectIterator iterator, ToByteFunction mapper) { + return new MappedByteIterator<>(iterator, mapper); + } + + /** + * A Helper function that maps a Java-Iterator into a new Type. + * @param iterator that should be mapped + * @param mapper the function that decides what the result turns into. + * @param the keyType of elements maintained by this Collection + * @return a iterator that is mapped to a new result + */ + public static ShortIterator mapToShort(Iterator iterator, ToShortFunction mapper) { + return new MappedShortIterator<>(wrap(iterator), mapper); + } + + /** + * A Helper function that maps a Iterator into a new Type. + * @param iterator that should be mapped + * @param mapper the function that decides what the result turns into. + * @param the keyType of elements maintained by this Collection + * @return a iterator that is mapped to a new result + */ + public static ShortIterator mapToShort(ObjectIterator iterator, ToShortFunction mapper) { + return new MappedShortIterator<>(iterator, mapper); + } + + /** + * A Helper function that maps a Java-Iterator into a new Type. + * @param iterator that should be mapped + * @param mapper the function that decides what the result turns into. + * @param the keyType of elements maintained by this Collection + * @return a iterator that is mapped to a new result + */ + public static IntIterator mapToInt(Iterator iterator, ToIntFunction mapper) { + return new MappedIntIterator<>(wrap(iterator), mapper); + } + + /** + * A Helper function that maps a Iterator into a new Type. + * @param iterator that should be mapped + * @param mapper the function that decides what the result turns into. + * @param the keyType of elements maintained by this Collection + * @return a iterator that is mapped to a new result + */ + public static IntIterator mapToInt(ObjectIterator iterator, ToIntFunction mapper) { + return new MappedIntIterator<>(iterator, mapper); + } + + /** + * A Helper function that maps a Java-Iterator into a new Type. + * @param iterator that should be mapped + * @param mapper the function that decides what the result turns into. + * @param the keyType of elements maintained by this Collection + * @return a iterator that is mapped to a new result + */ + public static LongIterator mapToLong(Iterator iterator, ToLongFunction mapper) { + return new MappedLongIterator<>(wrap(iterator), mapper); + } + + /** + * A Helper function that maps a Iterator into a new Type. + * @param iterator that should be mapped + * @param mapper the function that decides what the result turns into. + * @param the keyType of elements maintained by this Collection + * @return a iterator that is mapped to a new result + */ + public static LongIterator mapToLong(ObjectIterator iterator, ToLongFunction mapper) { + return new MappedLongIterator<>(iterator, mapper); + } + + /** + * A Helper function that maps a Java-Iterator into a new Type. + * @param iterator that should be mapped + * @param mapper the function that decides what the result turns into. + * @param the keyType of elements maintained by this Collection + * @return a iterator that is mapped to a new result + */ + public static FloatIterator mapToFloat(Iterator iterator, ToFloatFunction mapper) { + return new MappedFloatIterator<>(wrap(iterator), mapper); + } + + /** + * A Helper function that maps a Iterator into a new Type. + * @param iterator that should be mapped + * @param mapper the function that decides what the result turns into. + * @param the keyType of elements maintained by this Collection + * @return a iterator that is mapped to a new result + */ + public static FloatIterator mapToFloat(ObjectIterator iterator, ToFloatFunction mapper) { + return new MappedFloatIterator<>(iterator, mapper); + } + + /** + * A Helper function that maps a Java-Iterator into a new Type. + * @param iterator that should be mapped + * @param mapper the function that decides what the result turns into. + * @param the keyType of elements maintained by this Collection + * @return a iterator that is mapped to a new result + */ + public static DoubleIterator mapToDouble(Iterator iterator, ToDoubleFunction mapper) { + return new MappedDoubleIterator<>(wrap(iterator), mapper); + } + + /** + * A Helper function that maps a Iterator into a new Type. + * @param iterator that should be mapped + * @param mapper the function that decides what the result turns into. + * @param the keyType of elements maintained by this Collection + * @return a iterator that is mapped to a new result + */ + public static DoubleIterator mapToDouble(ObjectIterator iterator, ToDoubleFunction mapper) { + return new MappedDoubleIterator<>(iterator, mapper); + } + /** * A Helper function that flatMaps a Java-Iterator into a new Type. * @param iterator that should be flatMapped @@ -222,6 +391,26 @@ public static ObjectIterator repeat(Iterator iterator, int r return new RepeatingIterator<>(wrap(iterator), repeats); } + /** + * A Helper function that creates a infinitely looping iterator + * @param iterator that should be looping infinitely + * @param the keyType of elements maintained by this Collection + * @return a infinitely looping iterator + */ + public static ObjectIterator infinite(ObjectIterator iterator) { + return new InfiniteIterator<>(iterator); + } + + /** + * A Helper function that creates a infinitely looping iterator from a Java Iterator + * @param iterator that should be looping infinitely + * @param the keyType of elements maintained by this Collection + * @return a infinitely looping iterator + */ + public static ObjectIterator infinite(Iterator iterator) { + return new InfiniteIterator<>(wrap(iterator)); + } + /** * A Helper function that hard limits the Iterator to a specific size * @param iterator that should be limited @@ -760,6 +949,188 @@ public int skip(int amount) { } } + private static class MappedBooleanIterator implements BooleanIterator + { + ObjectIterator iterator; + Predicate mapper; + + MappedBooleanIterator(ObjectIterator iterator, Predicate mapper) { + this.iterator = iterator; + this.mapper = mapper; + } + + @Override + public boolean hasNext() { + return iterator.hasNext(); + } + + @Override + public boolean nextBoolean() { + return mapper.test(iterator.next()); + } + + @Override + public int skip(int amount) { + return iterator.skip(amount); + } + } + + private static class MappedByteIterator implements ByteIterator + { + ObjectIterator iterator; + ToByteFunction mapper; + + MappedByteIterator(ObjectIterator iterator, ToByteFunction mapper) { + this.iterator = iterator; + this.mapper = mapper; + } + + @Override + public boolean hasNext() { + return iterator.hasNext(); + } + + @Override + public byte nextByte() { + return mapper.applyAsByte(iterator.next()); + } + + @Override + public int skip(int amount) { + return iterator.skip(amount); + } + } + + private static class MappedShortIterator implements ShortIterator + { + ObjectIterator iterator; + ToShortFunction mapper; + + MappedShortIterator(ObjectIterator iterator, ToShortFunction mapper) { + this.iterator = iterator; + this.mapper = mapper; + } + + @Override + public boolean hasNext() { + return iterator.hasNext(); + } + + @Override + public short nextShort() { + return mapper.applyAsShort(iterator.next()); + } + + @Override + public int skip(int amount) { + return iterator.skip(amount); + } + } + + private static class MappedIntIterator implements IntIterator + { + ObjectIterator iterator; + ToIntFunction mapper; + + MappedIntIterator(ObjectIterator iterator, ToIntFunction mapper) { + this.iterator = iterator; + this.mapper = mapper; + } + + @Override + public boolean hasNext() { + return iterator.hasNext(); + } + + @Override + public int nextInt() { + return mapper.applyAsInt(iterator.next()); + } + + @Override + public int skip(int amount) { + return iterator.skip(amount); + } + } + + private static class MappedLongIterator implements LongIterator + { + ObjectIterator iterator; + ToLongFunction mapper; + + MappedLongIterator(ObjectIterator iterator, ToLongFunction mapper) { + this.iterator = iterator; + this.mapper = mapper; + } + + @Override + public boolean hasNext() { + return iterator.hasNext(); + } + + @Override + public long nextLong() { + return mapper.applyAsLong(iterator.next()); + } + + @Override + public int skip(int amount) { + return iterator.skip(amount); + } + } + + private static class MappedFloatIterator implements FloatIterator + { + ObjectIterator iterator; + ToFloatFunction mapper; + + MappedFloatIterator(ObjectIterator iterator, ToFloatFunction mapper) { + this.iterator = iterator; + this.mapper = mapper; + } + + @Override + public boolean hasNext() { + return iterator.hasNext(); + } + + @Override + public float nextFloat() { + return mapper.applyAsFloat(iterator.next()); + } + + @Override + public int skip(int amount) { + return iterator.skip(amount); + } + } + + private static class MappedDoubleIterator implements DoubleIterator + { + ObjectIterator iterator; + ToDoubleFunction mapper; + + MappedDoubleIterator(ObjectIterator iterator, ToDoubleFunction mapper) { + this.iterator = iterator; + this.mapper = mapper; + } + + @Override + public boolean hasNext() { + return iterator.hasNext(); + } + + @Override + public double nextDouble() { + return mapper.applyAsDouble(iterator.next()); + } + + @Override + public int skip(int amount) { + return iterator.skip(amount); + } + } + private static class FlatMappedIterator> implements ObjectIterator { ObjectIterator iterator; @@ -832,6 +1203,38 @@ public T next() { } } + private static class InfiniteIterator implements ObjectIterator + { + ObjectIterator iter; + CollectionWrapper looper = ObjectCollections.wrapper(); + int index = 0; + + public InfiniteIterator(ObjectIterator iter) { + this.iter = iter; + } + + @Override + public boolean hasNext() { + return true; + } + + @Override + public T next() { + if(iter != null) { + if(iter.hasNext()) { + T value = iter.next(); + looper.add(value); + return value; + } + else iter = null; + } + return looper.get((index++) % looper.size()); + } + + public void forEachRemaining(Consumer action) { throw new UnsupportedOperationException("This is a instant deadlock, so unsupported"); } + public void forEachRemaining(E input, ObjectObjectConsumer action) { throw new UnsupportedOperationException("This is a instant deadlock, so unsupported"); } + } + private static class RepeatingIterator implements ObjectIterator { final int repeats; diff --git a/src/main/java/speiger/src/collections/objects/utils/ObjectLists.java b/src/main/java/speiger/src/collections/objects/utils/ObjectLists.java index b8c58f03..ad4eee48 100644 --- a/src/main/java/speiger/src/collections/objects/utils/ObjectLists.java +++ b/src/main/java/speiger/src/collections/objects/utils/ObjectLists.java @@ -10,6 +10,7 @@ import speiger.src.collections.objects.collections.ObjectCollection; import speiger.src.collections.objects.lists.AbstractObjectList; import speiger.src.collections.objects.lists.ObjectList; +import speiger.src.collections.ints.lists.IntList; import speiger.src.collections.objects.lists.ObjectListIterator; import speiger.src.collections.utils.SanityChecks; @@ -324,6 +325,16 @@ public ObjectListIterator listIterator(int index) { return l.listIterator(index); } + @Override + public ObjectListIterator indexedIterator(int...indecies) { + return l.indexedIterator(indecies); + } + + @Override + public ObjectListIterator indexedIterator(IntList indecies) { + return l.indexedIterator(indecies); + } + @Override public ObjectList subList(int from, int to) { return ObjectLists.synchronize(l.subList(from, to)); @@ -420,6 +431,16 @@ public ObjectListIterator listIterator(int index) { return ObjectIterators.unmodifiable(l.listIterator(index)); } + @Override + public ObjectListIterator indexedIterator(int...indecies) { + return ObjectIterators.unmodifiable(l.indexedIterator(indecies)); + } + + @Override + public ObjectListIterator indexedIterator(IntList indecies) { + return ObjectIterators.unmodifiable(l.indexedIterator(indecies)); + } + @Override public ObjectList subList(int from, int to) { return ObjectLists.unmodifiable(l.subList(from, to)); @@ -499,6 +520,16 @@ public ObjectListIterator listIterator(int index) { return ObjectIterators.empty(); } + @Override + public ObjectListIterator indexedIterator(int...indecies) { + return ObjectIterators.empty(); + } + + @Override + public ObjectListIterator indexedIterator(IntList indecies) { + return ObjectIterators.empty(); + } + @Override public int hashCode() { return 1; } diff --git a/src/main/java/speiger/src/collections/objects/utils/ObjectPriorityQueues.java b/src/main/java/speiger/src/collections/objects/utils/ObjectPriorityQueues.java index b14c413a..76e24e54 100644 --- a/src/main/java/speiger/src/collections/objects/utils/ObjectPriorityQueues.java +++ b/src/main/java/speiger/src/collections/objects/utils/ObjectPriorityQueues.java @@ -97,6 +97,8 @@ protected SynchronizedPriorityQueue(ObjectPriorityQueue queue, Object mutex) @Override public T peek(int index) { synchronized(mutex) { return queue.peek(index); } } @Override + public boolean contains(T e) { synchronized(mutex) { return queue.contains(e); } } + @Override public boolean removeFirst(T e) { synchronized(mutex) { return queue.removeFirst(e); } } @Override public boolean removeLast(T e) { synchronized(mutex) { return queue.removeLast(e); } } diff --git a/src/main/java/speiger/src/collections/objects/utils/maps/Object2BooleanMaps.java b/src/main/java/speiger/src/collections/objects/utils/maps/Object2BooleanMaps.java index 01b52c7c..3b995dae 100644 --- a/src/main/java/speiger/src/collections/objects/utils/maps/Object2BooleanMaps.java +++ b/src/main/java/speiger/src/collections/objects/utils/maps/Object2BooleanMaps.java @@ -260,18 +260,18 @@ public static class SingletonMap extends AbstractObject2BooleanMap { @Override public boolean computeBoolean(T key, ObjectBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanNonDefault(T key, ObjectBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean computeBooleanIfAbsent(T key, Predicate mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanIfAbsentNonDefault(T key, Predicate mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean computeBooleanIfPresent(T key, ObjectBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanIfPresentNonDefault(T key, ObjectBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean supplyBooleanIfAbsent(T key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public boolean computeBooleanNonDefault(T key, ObjectBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public boolean computeBooleanIfAbsentNonDefault(T key, Predicate mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public boolean computeBooleanIfPresentNonDefault(T key, ObjectBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public boolean supplyBooleanIfAbsentNonDefault(T key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public boolean mergeBoolean(T key, boolean value, BooleanBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -319,18 +319,18 @@ public static class EmptyMap extends AbstractObject2BooleanMap { @Override public boolean computeBoolean(T key, ObjectBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanNonDefault(T key, ObjectBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean computeBooleanIfAbsent(T key, Predicate mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanIfAbsentNonDefault(T key, Predicate mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean computeBooleanIfPresent(T key, ObjectBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanIfPresentNonDefault(T key, ObjectBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean supplyBooleanIfAbsent(T key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public boolean computeBooleanNonDefault(T key, ObjectBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public boolean computeBooleanIfAbsentNonDefault(T key, Predicate mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public boolean computeBooleanIfPresentNonDefault(T key, ObjectBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public boolean supplyBooleanIfAbsentNonDefault(T key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public boolean mergeBoolean(T key, boolean value, BooleanBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -547,18 +547,18 @@ public boolean getBoolean(T key) { @Override public boolean computeBoolean(T key, ObjectBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanNonDefault(T key, ObjectBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean computeBooleanIfAbsent(T key, Predicate mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanIfAbsentNonDefault(T key, Predicate mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean computeBooleanIfPresent(T key, ObjectBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanIfPresentNonDefault(T key, ObjectBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean supplyBooleanIfAbsent(T key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public boolean computeBooleanNonDefault(T key, ObjectBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public boolean computeBooleanIfAbsentNonDefault(T key, Predicate mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public boolean computeBooleanIfPresentNonDefault(T key, ObjectBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public boolean supplyBooleanIfAbsentNonDefault(T key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public boolean mergeBoolean(T key, boolean value, BooleanBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -889,18 +889,18 @@ public AbstractObject2BooleanMap setDefaultReturnValue(boolean v) { @Override public boolean computeBoolean(T key, ObjectBooleanUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeBoolean(key, mappingFunction); } } @Override - public boolean computeBooleanNonDefault(T key, ObjectBooleanUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeBooleanNonDefault(key, mappingFunction); } } - @Override public boolean computeBooleanIfAbsent(T key, Predicate mappingFunction) { synchronized(mutex) { return map.computeBooleanIfAbsent(key, mappingFunction); } } @Override - public boolean computeBooleanIfAbsentNonDefault(T key, Predicate mappingFunction) { synchronized(mutex) { return map.computeBooleanIfAbsentNonDefault(key, mappingFunction); } } - @Override public boolean computeBooleanIfPresent(T key, ObjectBooleanUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeBooleanIfPresent(key, mappingFunction); } } @Override - public boolean computeBooleanIfPresentNonDefault(T key, ObjectBooleanUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeBooleanIfPresentNonDefault(key, mappingFunction); } } - @Override public boolean supplyBooleanIfAbsent(T key, BooleanSupplier valueProvider) { synchronized(mutex) { return map.supplyBooleanIfAbsent(key, valueProvider); } } @Override + public boolean computeBooleanNonDefault(T key, ObjectBooleanUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeBooleanNonDefault(key, mappingFunction); } } + @Override + public boolean computeBooleanIfAbsentNonDefault(T key, Predicate mappingFunction) { synchronized(mutex) { return map.computeBooleanIfAbsentNonDefault(key, mappingFunction); } } + @Override + public boolean computeBooleanIfPresentNonDefault(T key, ObjectBooleanUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeBooleanIfPresentNonDefault(key, mappingFunction); } } + @Override public boolean supplyBooleanIfAbsentNonDefault(T key, BooleanSupplier valueProvider) { synchronized(mutex) { return map.supplyBooleanIfAbsentNonDefault(key, valueProvider); } } @Override public boolean mergeBoolean(T key, boolean value, BooleanBooleanUnaryOperator mappingFunction) { synchronized(mutex) { return map.mergeBoolean(key, value, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/objects/utils/maps/Object2ByteMaps.java b/src/main/java/speiger/src/collections/objects/utils/maps/Object2ByteMaps.java index a66e2700..670a7782 100644 --- a/src/main/java/speiger/src/collections/objects/utils/maps/Object2ByteMaps.java +++ b/src/main/java/speiger/src/collections/objects/utils/maps/Object2ByteMaps.java @@ -264,18 +264,18 @@ public static class SingletonMap extends AbstractObject2ByteMap { @Override public byte computeByte(T key, ObjectByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteNonDefault(T key, ObjectByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte computeByteIfAbsent(T key, ToByteFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteIfAbsentNonDefault(T key, ToByteFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte computeByteIfPresent(T key, ObjectByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteIfPresentNonDefault(T key, ObjectByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte supplyByteIfAbsent(T key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public byte computeByteNonDefault(T key, ObjectByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public byte computeByteIfAbsentNonDefault(T key, ToByteFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public byte computeByteIfPresentNonDefault(T key, ObjectByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public byte supplyByteIfAbsentNonDefault(T key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public byte mergeByte(T key, byte value, ByteByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -327,18 +327,18 @@ public static class EmptyMap extends AbstractObject2ByteMap { @Override public byte computeByte(T key, ObjectByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteNonDefault(T key, ObjectByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte computeByteIfAbsent(T key, ToByteFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteIfAbsentNonDefault(T key, ToByteFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte computeByteIfPresent(T key, ObjectByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteIfPresentNonDefault(T key, ObjectByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte supplyByteIfAbsent(T key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public byte computeByteNonDefault(T key, ObjectByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public byte computeByteIfAbsentNonDefault(T key, ToByteFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public byte computeByteIfPresentNonDefault(T key, ObjectByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public byte supplyByteIfAbsentNonDefault(T key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public byte mergeByte(T key, byte value, ByteByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -559,18 +559,18 @@ public byte getByte(T key) { @Override public byte computeByte(T key, ObjectByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteNonDefault(T key, ObjectByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte computeByteIfAbsent(T key, ToByteFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteIfAbsentNonDefault(T key, ToByteFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte computeByteIfPresent(T key, ObjectByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteIfPresentNonDefault(T key, ObjectByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte supplyByteIfAbsent(T key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public byte computeByteNonDefault(T key, ObjectByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public byte computeByteIfAbsentNonDefault(T key, ToByteFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public byte computeByteIfPresentNonDefault(T key, ObjectByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public byte supplyByteIfAbsentNonDefault(T key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public byte mergeByte(T key, byte value, ByteByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -906,18 +906,18 @@ public AbstractObject2ByteMap setDefaultReturnValue(byte v) { @Override public byte computeByte(T key, ObjectByteUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeByte(key, mappingFunction); } } @Override - public byte computeByteNonDefault(T key, ObjectByteUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeByteNonDefault(key, mappingFunction); } } - @Override public byte computeByteIfAbsent(T key, ToByteFunction mappingFunction) { synchronized(mutex) { return map.computeByteIfAbsent(key, mappingFunction); } } @Override - public byte computeByteIfAbsentNonDefault(T key, ToByteFunction mappingFunction) { synchronized(mutex) { return map.computeByteIfAbsentNonDefault(key, mappingFunction); } } - @Override public byte computeByteIfPresent(T key, ObjectByteUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeByteIfPresent(key, mappingFunction); } } @Override - public byte computeByteIfPresentNonDefault(T key, ObjectByteUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeByteIfPresentNonDefault(key, mappingFunction); } } - @Override public byte supplyByteIfAbsent(T key, ByteSupplier valueProvider) { synchronized(mutex) { return map.supplyByteIfAbsent(key, valueProvider); } } @Override + public byte computeByteNonDefault(T key, ObjectByteUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeByteNonDefault(key, mappingFunction); } } + @Override + public byte computeByteIfAbsentNonDefault(T key, ToByteFunction mappingFunction) { synchronized(mutex) { return map.computeByteIfAbsentNonDefault(key, mappingFunction); } } + @Override + public byte computeByteIfPresentNonDefault(T key, ObjectByteUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeByteIfPresentNonDefault(key, mappingFunction); } } + @Override public byte supplyByteIfAbsentNonDefault(T key, ByteSupplier valueProvider) { synchronized(mutex) { return map.supplyByteIfAbsentNonDefault(key, valueProvider); } } @Override public byte mergeByte(T key, byte value, ByteByteUnaryOperator mappingFunction) { synchronized(mutex) { return map.mergeByte(key, value, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/objects/utils/maps/Object2CharMaps.java b/src/main/java/speiger/src/collections/objects/utils/maps/Object2CharMaps.java index 757b81d1..9a7d2f71 100644 --- a/src/main/java/speiger/src/collections/objects/utils/maps/Object2CharMaps.java +++ b/src/main/java/speiger/src/collections/objects/utils/maps/Object2CharMaps.java @@ -264,18 +264,18 @@ public static class SingletonMap extends AbstractObject2CharMap { @Override public char computeChar(T key, ObjectCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharNonDefault(T key, ObjectCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char computeCharIfAbsent(T key, ToCharFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharIfAbsentNonDefault(T key, ToCharFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char computeCharIfPresent(T key, ObjectCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharIfPresentNonDefault(T key, ObjectCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char supplyCharIfAbsent(T key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public char computeCharNonDefault(T key, ObjectCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public char computeCharIfAbsentNonDefault(T key, ToCharFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public char computeCharIfPresentNonDefault(T key, ObjectCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public char supplyCharIfAbsentNonDefault(T key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public char mergeChar(T key, char value, CharCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -327,18 +327,18 @@ public static class EmptyMap extends AbstractObject2CharMap { @Override public char computeChar(T key, ObjectCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharNonDefault(T key, ObjectCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char computeCharIfAbsent(T key, ToCharFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharIfAbsentNonDefault(T key, ToCharFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char computeCharIfPresent(T key, ObjectCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharIfPresentNonDefault(T key, ObjectCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char supplyCharIfAbsent(T key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public char computeCharNonDefault(T key, ObjectCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public char computeCharIfAbsentNonDefault(T key, ToCharFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public char computeCharIfPresentNonDefault(T key, ObjectCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public char supplyCharIfAbsentNonDefault(T key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public char mergeChar(T key, char value, CharCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -559,18 +559,18 @@ public char getChar(T key) { @Override public char computeChar(T key, ObjectCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharNonDefault(T key, ObjectCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char computeCharIfAbsent(T key, ToCharFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharIfAbsentNonDefault(T key, ToCharFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char computeCharIfPresent(T key, ObjectCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharIfPresentNonDefault(T key, ObjectCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char supplyCharIfAbsent(T key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public char computeCharNonDefault(T key, ObjectCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public char computeCharIfAbsentNonDefault(T key, ToCharFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public char computeCharIfPresentNonDefault(T key, ObjectCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public char supplyCharIfAbsentNonDefault(T key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public char mergeChar(T key, char value, CharCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -906,18 +906,18 @@ public AbstractObject2CharMap setDefaultReturnValue(char v) { @Override public char computeChar(T key, ObjectCharUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeChar(key, mappingFunction); } } @Override - public char computeCharNonDefault(T key, ObjectCharUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeCharNonDefault(key, mappingFunction); } } - @Override public char computeCharIfAbsent(T key, ToCharFunction mappingFunction) { synchronized(mutex) { return map.computeCharIfAbsent(key, mappingFunction); } } @Override - public char computeCharIfAbsentNonDefault(T key, ToCharFunction mappingFunction) { synchronized(mutex) { return map.computeCharIfAbsentNonDefault(key, mappingFunction); } } - @Override public char computeCharIfPresent(T key, ObjectCharUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeCharIfPresent(key, mappingFunction); } } @Override - public char computeCharIfPresentNonDefault(T key, ObjectCharUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeCharIfPresentNonDefault(key, mappingFunction); } } - @Override public char supplyCharIfAbsent(T key, CharSupplier valueProvider) { synchronized(mutex) { return map.supplyCharIfAbsent(key, valueProvider); } } @Override + public char computeCharNonDefault(T key, ObjectCharUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeCharNonDefault(key, mappingFunction); } } + @Override + public char computeCharIfAbsentNonDefault(T key, ToCharFunction mappingFunction) { synchronized(mutex) { return map.computeCharIfAbsentNonDefault(key, mappingFunction); } } + @Override + public char computeCharIfPresentNonDefault(T key, ObjectCharUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeCharIfPresentNonDefault(key, mappingFunction); } } + @Override public char supplyCharIfAbsentNonDefault(T key, CharSupplier valueProvider) { synchronized(mutex) { return map.supplyCharIfAbsentNonDefault(key, valueProvider); } } @Override public char mergeChar(T key, char value, CharCharUnaryOperator mappingFunction) { synchronized(mutex) { return map.mergeChar(key, value, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/objects/utils/maps/Object2DoubleMaps.java b/src/main/java/speiger/src/collections/objects/utils/maps/Object2DoubleMaps.java index a46cae23..917e2e9d 100644 --- a/src/main/java/speiger/src/collections/objects/utils/maps/Object2DoubleMaps.java +++ b/src/main/java/speiger/src/collections/objects/utils/maps/Object2DoubleMaps.java @@ -264,18 +264,18 @@ public static class SingletonMap extends AbstractObject2DoubleMap { @Override public double computeDouble(T key, ObjectDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleNonDefault(T key, ObjectDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double computeDoubleIfAbsent(T key, ToDoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleIfAbsentNonDefault(T key, ToDoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double computeDoubleIfPresent(T key, ObjectDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleIfPresentNonDefault(T key, ObjectDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double supplyDoubleIfAbsent(T key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public double computeDoubleNonDefault(T key, ObjectDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public double computeDoubleIfAbsentNonDefault(T key, ToDoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public double computeDoubleIfPresentNonDefault(T key, ObjectDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public double supplyDoubleIfAbsentNonDefault(T key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public double mergeDouble(T key, double value, DoubleDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -327,18 +327,18 @@ public static class EmptyMap extends AbstractObject2DoubleMap { @Override public double computeDouble(T key, ObjectDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleNonDefault(T key, ObjectDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double computeDoubleIfAbsent(T key, ToDoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleIfAbsentNonDefault(T key, ToDoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double computeDoubleIfPresent(T key, ObjectDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleIfPresentNonDefault(T key, ObjectDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double supplyDoubleIfAbsent(T key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public double computeDoubleNonDefault(T key, ObjectDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public double computeDoubleIfAbsentNonDefault(T key, ToDoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public double computeDoubleIfPresentNonDefault(T key, ObjectDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public double supplyDoubleIfAbsentNonDefault(T key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public double mergeDouble(T key, double value, DoubleDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -559,18 +559,18 @@ public double getDouble(T key) { @Override public double computeDouble(T key, ObjectDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleNonDefault(T key, ObjectDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double computeDoubleIfAbsent(T key, ToDoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleIfAbsentNonDefault(T key, ToDoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double computeDoubleIfPresent(T key, ObjectDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleIfPresentNonDefault(T key, ObjectDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double supplyDoubleIfAbsent(T key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public double computeDoubleNonDefault(T key, ObjectDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public double computeDoubleIfAbsentNonDefault(T key, ToDoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public double computeDoubleIfPresentNonDefault(T key, ObjectDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public double supplyDoubleIfAbsentNonDefault(T key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public double mergeDouble(T key, double value, DoubleDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -906,18 +906,18 @@ public AbstractObject2DoubleMap setDefaultReturnValue(double v) { @Override public double computeDouble(T key, ObjectDoubleUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeDouble(key, mappingFunction); } } @Override - public double computeDoubleNonDefault(T key, ObjectDoubleUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeDoubleNonDefault(key, mappingFunction); } } - @Override public double computeDoubleIfAbsent(T key, ToDoubleFunction mappingFunction) { synchronized(mutex) { return map.computeDoubleIfAbsent(key, mappingFunction); } } @Override - public double computeDoubleIfAbsentNonDefault(T key, ToDoubleFunction mappingFunction) { synchronized(mutex) { return map.computeDoubleIfAbsentNonDefault(key, mappingFunction); } } - @Override public double computeDoubleIfPresent(T key, ObjectDoubleUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeDoubleIfPresent(key, mappingFunction); } } @Override - public double computeDoubleIfPresentNonDefault(T key, ObjectDoubleUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeDoubleIfPresentNonDefault(key, mappingFunction); } } - @Override public double supplyDoubleIfAbsent(T key, DoubleSupplier valueProvider) { synchronized(mutex) { return map.supplyDoubleIfAbsent(key, valueProvider); } } @Override + public double computeDoubleNonDefault(T key, ObjectDoubleUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeDoubleNonDefault(key, mappingFunction); } } + @Override + public double computeDoubleIfAbsentNonDefault(T key, ToDoubleFunction mappingFunction) { synchronized(mutex) { return map.computeDoubleIfAbsentNonDefault(key, mappingFunction); } } + @Override + public double computeDoubleIfPresentNonDefault(T key, ObjectDoubleUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeDoubleIfPresentNonDefault(key, mappingFunction); } } + @Override public double supplyDoubleIfAbsentNonDefault(T key, DoubleSupplier valueProvider) { synchronized(mutex) { return map.supplyDoubleIfAbsentNonDefault(key, valueProvider); } } @Override public double mergeDouble(T key, double value, DoubleDoubleUnaryOperator mappingFunction) { synchronized(mutex) { return map.mergeDouble(key, value, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/objects/utils/maps/Object2FloatMaps.java b/src/main/java/speiger/src/collections/objects/utils/maps/Object2FloatMaps.java index 30e7fc4c..9ef8cafc 100644 --- a/src/main/java/speiger/src/collections/objects/utils/maps/Object2FloatMaps.java +++ b/src/main/java/speiger/src/collections/objects/utils/maps/Object2FloatMaps.java @@ -264,18 +264,18 @@ public static class SingletonMap extends AbstractObject2FloatMap { @Override public float computeFloat(T key, ObjectFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatNonDefault(T key, ObjectFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float computeFloatIfAbsent(T key, ToFloatFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatIfAbsentNonDefault(T key, ToFloatFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float computeFloatIfPresent(T key, ObjectFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatIfPresentNonDefault(T key, ObjectFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float supplyFloatIfAbsent(T key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public float computeFloatNonDefault(T key, ObjectFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public float computeFloatIfAbsentNonDefault(T key, ToFloatFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public float computeFloatIfPresentNonDefault(T key, ObjectFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public float supplyFloatIfAbsentNonDefault(T key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public float mergeFloat(T key, float value, FloatFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -327,18 +327,18 @@ public static class EmptyMap extends AbstractObject2FloatMap { @Override public float computeFloat(T key, ObjectFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatNonDefault(T key, ObjectFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float computeFloatIfAbsent(T key, ToFloatFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatIfAbsentNonDefault(T key, ToFloatFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float computeFloatIfPresent(T key, ObjectFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatIfPresentNonDefault(T key, ObjectFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float supplyFloatIfAbsent(T key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public float computeFloatNonDefault(T key, ObjectFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public float computeFloatIfAbsentNonDefault(T key, ToFloatFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public float computeFloatIfPresentNonDefault(T key, ObjectFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public float supplyFloatIfAbsentNonDefault(T key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public float mergeFloat(T key, float value, FloatFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -559,18 +559,18 @@ public float getFloat(T key) { @Override public float computeFloat(T key, ObjectFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatNonDefault(T key, ObjectFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float computeFloatIfAbsent(T key, ToFloatFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatIfAbsentNonDefault(T key, ToFloatFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float computeFloatIfPresent(T key, ObjectFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatIfPresentNonDefault(T key, ObjectFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float supplyFloatIfAbsent(T key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public float computeFloatNonDefault(T key, ObjectFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public float computeFloatIfAbsentNonDefault(T key, ToFloatFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public float computeFloatIfPresentNonDefault(T key, ObjectFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public float supplyFloatIfAbsentNonDefault(T key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public float mergeFloat(T key, float value, FloatFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -906,18 +906,18 @@ public AbstractObject2FloatMap setDefaultReturnValue(float v) { @Override public float computeFloat(T key, ObjectFloatUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeFloat(key, mappingFunction); } } @Override - public float computeFloatNonDefault(T key, ObjectFloatUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeFloatNonDefault(key, mappingFunction); } } - @Override public float computeFloatIfAbsent(T key, ToFloatFunction mappingFunction) { synchronized(mutex) { return map.computeFloatIfAbsent(key, mappingFunction); } } @Override - public float computeFloatIfAbsentNonDefault(T key, ToFloatFunction mappingFunction) { synchronized(mutex) { return map.computeFloatIfAbsentNonDefault(key, mappingFunction); } } - @Override public float computeFloatIfPresent(T key, ObjectFloatUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeFloatIfPresent(key, mappingFunction); } } @Override - public float computeFloatIfPresentNonDefault(T key, ObjectFloatUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeFloatIfPresentNonDefault(key, mappingFunction); } } - @Override public float supplyFloatIfAbsent(T key, FloatSupplier valueProvider) { synchronized(mutex) { return map.supplyFloatIfAbsent(key, valueProvider); } } @Override + public float computeFloatNonDefault(T key, ObjectFloatUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeFloatNonDefault(key, mappingFunction); } } + @Override + public float computeFloatIfAbsentNonDefault(T key, ToFloatFunction mappingFunction) { synchronized(mutex) { return map.computeFloatIfAbsentNonDefault(key, mappingFunction); } } + @Override + public float computeFloatIfPresentNonDefault(T key, ObjectFloatUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeFloatIfPresentNonDefault(key, mappingFunction); } } + @Override public float supplyFloatIfAbsentNonDefault(T key, FloatSupplier valueProvider) { synchronized(mutex) { return map.supplyFloatIfAbsentNonDefault(key, valueProvider); } } @Override public float mergeFloat(T key, float value, FloatFloatUnaryOperator mappingFunction) { synchronized(mutex) { return map.mergeFloat(key, value, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/objects/utils/maps/Object2IntMaps.java b/src/main/java/speiger/src/collections/objects/utils/maps/Object2IntMaps.java index 394bdd1e..a1a6d816 100644 --- a/src/main/java/speiger/src/collections/objects/utils/maps/Object2IntMaps.java +++ b/src/main/java/speiger/src/collections/objects/utils/maps/Object2IntMaps.java @@ -264,18 +264,18 @@ public static class SingletonMap extends AbstractObject2IntMap { @Override public int computeInt(T key, ObjectIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntNonDefault(T key, ObjectIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int computeIntIfAbsent(T key, ToIntFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntIfAbsentNonDefault(T key, ToIntFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int computeIntIfPresent(T key, ObjectIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntIfPresentNonDefault(T key, ObjectIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int supplyIntIfAbsent(T key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public int computeIntNonDefault(T key, ObjectIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public int computeIntIfAbsentNonDefault(T key, ToIntFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public int computeIntIfPresentNonDefault(T key, ObjectIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public int supplyIntIfAbsentNonDefault(T key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public int mergeInt(T key, int value, IntIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -327,18 +327,18 @@ public static class EmptyMap extends AbstractObject2IntMap { @Override public int computeInt(T key, ObjectIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntNonDefault(T key, ObjectIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int computeIntIfAbsent(T key, ToIntFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntIfAbsentNonDefault(T key, ToIntFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int computeIntIfPresent(T key, ObjectIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntIfPresentNonDefault(T key, ObjectIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int supplyIntIfAbsent(T key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public int computeIntNonDefault(T key, ObjectIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public int computeIntIfAbsentNonDefault(T key, ToIntFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public int computeIntIfPresentNonDefault(T key, ObjectIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public int supplyIntIfAbsentNonDefault(T key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public int mergeInt(T key, int value, IntIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -559,18 +559,18 @@ public int getInt(T key) { @Override public int computeInt(T key, ObjectIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntNonDefault(T key, ObjectIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int computeIntIfAbsent(T key, ToIntFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntIfAbsentNonDefault(T key, ToIntFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int computeIntIfPresent(T key, ObjectIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntIfPresentNonDefault(T key, ObjectIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int supplyIntIfAbsent(T key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public int computeIntNonDefault(T key, ObjectIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public int computeIntIfAbsentNonDefault(T key, ToIntFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public int computeIntIfPresentNonDefault(T key, ObjectIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public int supplyIntIfAbsentNonDefault(T key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public int mergeInt(T key, int value, IntIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -906,18 +906,18 @@ public AbstractObject2IntMap setDefaultReturnValue(int v) { @Override public int computeInt(T key, ObjectIntUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeInt(key, mappingFunction); } } @Override - public int computeIntNonDefault(T key, ObjectIntUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeIntNonDefault(key, mappingFunction); } } - @Override public int computeIntIfAbsent(T key, ToIntFunction mappingFunction) { synchronized(mutex) { return map.computeIntIfAbsent(key, mappingFunction); } } @Override - public int computeIntIfAbsentNonDefault(T key, ToIntFunction mappingFunction) { synchronized(mutex) { return map.computeIntIfAbsentNonDefault(key, mappingFunction); } } - @Override public int computeIntIfPresent(T key, ObjectIntUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeIntIfPresent(key, mappingFunction); } } @Override - public int computeIntIfPresentNonDefault(T key, ObjectIntUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeIntIfPresentNonDefault(key, mappingFunction); } } - @Override public int supplyIntIfAbsent(T key, IntSupplier valueProvider) { synchronized(mutex) { return map.supplyIntIfAbsent(key, valueProvider); } } @Override + public int computeIntNonDefault(T key, ObjectIntUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeIntNonDefault(key, mappingFunction); } } + @Override + public int computeIntIfAbsentNonDefault(T key, ToIntFunction mappingFunction) { synchronized(mutex) { return map.computeIntIfAbsentNonDefault(key, mappingFunction); } } + @Override + public int computeIntIfPresentNonDefault(T key, ObjectIntUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeIntIfPresentNonDefault(key, mappingFunction); } } + @Override public int supplyIntIfAbsentNonDefault(T key, IntSupplier valueProvider) { synchronized(mutex) { return map.supplyIntIfAbsentNonDefault(key, valueProvider); } } @Override public int mergeInt(T key, int value, IntIntUnaryOperator mappingFunction) { synchronized(mutex) { return map.mergeInt(key, value, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/objects/utils/maps/Object2LongMaps.java b/src/main/java/speiger/src/collections/objects/utils/maps/Object2LongMaps.java index 7cf7d0dc..8b13db2c 100644 --- a/src/main/java/speiger/src/collections/objects/utils/maps/Object2LongMaps.java +++ b/src/main/java/speiger/src/collections/objects/utils/maps/Object2LongMaps.java @@ -264,18 +264,18 @@ public static class SingletonMap extends AbstractObject2LongMap { @Override public long computeLong(T key, ObjectLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongNonDefault(T key, ObjectLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long computeLongIfAbsent(T key, ToLongFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongIfAbsentNonDefault(T key, ToLongFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long computeLongIfPresent(T key, ObjectLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongIfPresentNonDefault(T key, ObjectLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long supplyLongIfAbsent(T key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public long computeLongNonDefault(T key, ObjectLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public long computeLongIfAbsentNonDefault(T key, ToLongFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public long computeLongIfPresentNonDefault(T key, ObjectLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public long supplyLongIfAbsentNonDefault(T key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public long mergeLong(T key, long value, LongLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -327,18 +327,18 @@ public static class EmptyMap extends AbstractObject2LongMap { @Override public long computeLong(T key, ObjectLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongNonDefault(T key, ObjectLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long computeLongIfAbsent(T key, ToLongFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongIfAbsentNonDefault(T key, ToLongFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long computeLongIfPresent(T key, ObjectLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongIfPresentNonDefault(T key, ObjectLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long supplyLongIfAbsent(T key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public long computeLongNonDefault(T key, ObjectLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public long computeLongIfAbsentNonDefault(T key, ToLongFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public long computeLongIfPresentNonDefault(T key, ObjectLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public long supplyLongIfAbsentNonDefault(T key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public long mergeLong(T key, long value, LongLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -559,18 +559,18 @@ public long getLong(T key) { @Override public long computeLong(T key, ObjectLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongNonDefault(T key, ObjectLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long computeLongIfAbsent(T key, ToLongFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongIfAbsentNonDefault(T key, ToLongFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long computeLongIfPresent(T key, ObjectLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongIfPresentNonDefault(T key, ObjectLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long supplyLongIfAbsent(T key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public long computeLongNonDefault(T key, ObjectLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public long computeLongIfAbsentNonDefault(T key, ToLongFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public long computeLongIfPresentNonDefault(T key, ObjectLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public long supplyLongIfAbsentNonDefault(T key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public long mergeLong(T key, long value, LongLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -906,18 +906,18 @@ public AbstractObject2LongMap setDefaultReturnValue(long v) { @Override public long computeLong(T key, ObjectLongUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeLong(key, mappingFunction); } } @Override - public long computeLongNonDefault(T key, ObjectLongUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeLongNonDefault(key, mappingFunction); } } - @Override public long computeLongIfAbsent(T key, ToLongFunction mappingFunction) { synchronized(mutex) { return map.computeLongIfAbsent(key, mappingFunction); } } @Override - public long computeLongIfAbsentNonDefault(T key, ToLongFunction mappingFunction) { synchronized(mutex) { return map.computeLongIfAbsentNonDefault(key, mappingFunction); } } - @Override public long computeLongIfPresent(T key, ObjectLongUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeLongIfPresent(key, mappingFunction); } } @Override - public long computeLongIfPresentNonDefault(T key, ObjectLongUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeLongIfPresentNonDefault(key, mappingFunction); } } - @Override public long supplyLongIfAbsent(T key, LongSupplier valueProvider) { synchronized(mutex) { return map.supplyLongIfAbsent(key, valueProvider); } } @Override + public long computeLongNonDefault(T key, ObjectLongUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeLongNonDefault(key, mappingFunction); } } + @Override + public long computeLongIfAbsentNonDefault(T key, ToLongFunction mappingFunction) { synchronized(mutex) { return map.computeLongIfAbsentNonDefault(key, mappingFunction); } } + @Override + public long computeLongIfPresentNonDefault(T key, ObjectLongUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeLongIfPresentNonDefault(key, mappingFunction); } } + @Override public long supplyLongIfAbsentNonDefault(T key, LongSupplier valueProvider) { synchronized(mutex) { return map.supplyLongIfAbsentNonDefault(key, valueProvider); } } @Override public long mergeLong(T key, long value, LongLongUnaryOperator mappingFunction) { synchronized(mutex) { return map.mergeLong(key, value, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/objects/utils/maps/Object2ObjectMaps.java b/src/main/java/speiger/src/collections/objects/utils/maps/Object2ObjectMaps.java index 8e1678b3..55647be1 100644 --- a/src/main/java/speiger/src/collections/objects/utils/maps/Object2ObjectMaps.java +++ b/src/main/java/speiger/src/collections/objects/utils/maps/Object2ObjectMaps.java @@ -275,20 +275,12 @@ public static class SingletonMap extends AbstractObject2ObjectMap { @Override public V compute(T key, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeNonDefault(T key, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V computeIfAbsent(T key, UnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeIfAbsentNonDefault(T key, UnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V computeIfPresent(T key, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeIfPresentNonDefault(T key, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V supplyIfAbsent(T key, ObjectSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public V supplyIfAbsentNonDefault(T key, ObjectSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public V merge(T key, V value, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override public void mergeAll(Object2ObjectMap m, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -331,20 +323,12 @@ public static class EmptyMap extends AbstractObject2ObjectMap { @Override public V compute(T key, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeNonDefault(T key, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V computeIfAbsent(T key, UnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeIfAbsentNonDefault(T key, UnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V computeIfPresent(T key, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeIfPresentNonDefault(T key, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V supplyIfAbsent(T key, ObjectSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public V supplyIfAbsentNonDefault(T key, ObjectSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public V merge(T key, V value, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override public void mergeAll(Object2ObjectMap m, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -560,20 +544,12 @@ public V getObject(T key) { @Override public V compute(T key, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeNonDefault(T key, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V computeIfAbsent(T key, UnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeIfAbsentNonDefault(T key, UnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V computeIfPresent(T key, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeIfPresentNonDefault(T key, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V supplyIfAbsent(T key, ObjectSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public V supplyIfAbsentNonDefault(T key, ObjectSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public V merge(T key, V value, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override public void mergeAll(Object2ObjectMap m, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -904,20 +880,12 @@ public AbstractObject2ObjectMap setDefaultReturnValue(V v) { @Override public V compute(T key, ObjectObjectUnaryOperator mappingFunction) { synchronized(mutex) { return map.compute(key, mappingFunction); } } @Override - public V computeNonDefault(T key, ObjectObjectUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeNonDefault(key, mappingFunction); } } - @Override public V computeIfAbsent(T key, UnaryOperator mappingFunction) { synchronized(mutex) { return map.computeIfAbsent(key, mappingFunction); } } @Override - public V computeIfAbsentNonDefault(T key, UnaryOperator mappingFunction) { synchronized(mutex) { return map.computeIfAbsentNonDefault(key, mappingFunction); } } - @Override public V computeIfPresent(T key, ObjectObjectUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeIfPresent(key, mappingFunction); } } @Override - public V computeIfPresentNonDefault(T key, ObjectObjectUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeIfPresentNonDefault(key, mappingFunction); } } - @Override public V supplyIfAbsent(T key, ObjectSupplier valueProvider) { synchronized(mutex) { return map.supplyIfAbsent(key, valueProvider); } } @Override - public V supplyIfAbsentNonDefault(T key, ObjectSupplier valueProvider) { synchronized(mutex) { return map.supplyIfAbsentNonDefault(key, valueProvider); } } - @Override public V merge(T key, V value, ObjectObjectUnaryOperator mappingFunction) { synchronized(mutex) { return map.merge(key, value, mappingFunction); } } @Override public void mergeAll(Object2ObjectMap m, ObjectObjectUnaryOperator mappingFunction) { synchronized(mutex) { map.mergeAll(m, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/objects/utils/maps/Object2ShortMaps.java b/src/main/java/speiger/src/collections/objects/utils/maps/Object2ShortMaps.java index 84e038b8..2e90b195 100644 --- a/src/main/java/speiger/src/collections/objects/utils/maps/Object2ShortMaps.java +++ b/src/main/java/speiger/src/collections/objects/utils/maps/Object2ShortMaps.java @@ -264,18 +264,18 @@ public static class SingletonMap extends AbstractObject2ShortMap { @Override public short computeShort(T key, ObjectShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortNonDefault(T key, ObjectShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short computeShortIfAbsent(T key, ToShortFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortIfAbsentNonDefault(T key, ToShortFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short computeShortIfPresent(T key, ObjectShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortIfPresentNonDefault(T key, ObjectShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short supplyShortIfAbsent(T key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public short computeShortNonDefault(T key, ObjectShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public short computeShortIfAbsentNonDefault(T key, ToShortFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public short computeShortIfPresentNonDefault(T key, ObjectShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public short supplyShortIfAbsentNonDefault(T key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public short mergeShort(T key, short value, ShortShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -327,18 +327,18 @@ public static class EmptyMap extends AbstractObject2ShortMap { @Override public short computeShort(T key, ObjectShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortNonDefault(T key, ObjectShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short computeShortIfAbsent(T key, ToShortFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortIfAbsentNonDefault(T key, ToShortFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short computeShortIfPresent(T key, ObjectShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortIfPresentNonDefault(T key, ObjectShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short supplyShortIfAbsent(T key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public short computeShortNonDefault(T key, ObjectShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public short computeShortIfAbsentNonDefault(T key, ToShortFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public short computeShortIfPresentNonDefault(T key, ObjectShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public short supplyShortIfAbsentNonDefault(T key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public short mergeShort(T key, short value, ShortShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -559,18 +559,18 @@ public short getShort(T key) { @Override public short computeShort(T key, ObjectShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortNonDefault(T key, ObjectShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short computeShortIfAbsent(T key, ToShortFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortIfAbsentNonDefault(T key, ToShortFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short computeShortIfPresent(T key, ObjectShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortIfPresentNonDefault(T key, ObjectShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short supplyShortIfAbsent(T key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public short computeShortNonDefault(T key, ObjectShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public short computeShortIfAbsentNonDefault(T key, ToShortFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public short computeShortIfPresentNonDefault(T key, ObjectShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public short supplyShortIfAbsentNonDefault(T key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public short mergeShort(T key, short value, ShortShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -906,18 +906,18 @@ public AbstractObject2ShortMap setDefaultReturnValue(short v) { @Override public short computeShort(T key, ObjectShortUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeShort(key, mappingFunction); } } @Override - public short computeShortNonDefault(T key, ObjectShortUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeShortNonDefault(key, mappingFunction); } } - @Override public short computeShortIfAbsent(T key, ToShortFunction mappingFunction) { synchronized(mutex) { return map.computeShortIfAbsent(key, mappingFunction); } } @Override - public short computeShortIfAbsentNonDefault(T key, ToShortFunction mappingFunction) { synchronized(mutex) { return map.computeShortIfAbsentNonDefault(key, mappingFunction); } } - @Override public short computeShortIfPresent(T key, ObjectShortUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeShortIfPresent(key, mappingFunction); } } @Override - public short computeShortIfPresentNonDefault(T key, ObjectShortUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeShortIfPresentNonDefault(key, mappingFunction); } } - @Override public short supplyShortIfAbsent(T key, ShortSupplier valueProvider) { synchronized(mutex) { return map.supplyShortIfAbsent(key, valueProvider); } } @Override + public short computeShortNonDefault(T key, ObjectShortUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeShortNonDefault(key, mappingFunction); } } + @Override + public short computeShortIfAbsentNonDefault(T key, ToShortFunction mappingFunction) { synchronized(mutex) { return map.computeShortIfAbsentNonDefault(key, mappingFunction); } } + @Override + public short computeShortIfPresentNonDefault(T key, ObjectShortUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeShortIfPresentNonDefault(key, mappingFunction); } } + @Override public short supplyShortIfAbsentNonDefault(T key, ShortSupplier valueProvider) { synchronized(mutex) { return map.supplyShortIfAbsentNonDefault(key, valueProvider); } } @Override public short mergeShort(T key, short value, ShortShortUnaryOperator mappingFunction) { synchronized(mutex) { return map.mergeShort(key, value, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/shorts/functions/ShortSupplier.java b/src/main/java/speiger/src/collections/shorts/functions/ShortSupplier.java index 23dc04d8..fd51e7ea 100644 --- a/src/main/java/speiger/src/collections/shorts/functions/ShortSupplier.java +++ b/src/main/java/speiger/src/collections/shorts/functions/ShortSupplier.java @@ -8,5 +8,5 @@ public interface ShortSupplier /** * @return the supplied value */ - public short getAsInt(); + public short getAsShort(); } \ No newline at end of file diff --git a/src/main/java/speiger/src/collections/shorts/lists/AbstractShortList.java b/src/main/java/speiger/src/collections/shorts/lists/AbstractShortList.java index c00d48ab..bed164c8 100644 --- a/src/main/java/speiger/src/collections/shorts/lists/AbstractShortList.java +++ b/src/main/java/speiger/src/collections/shorts/lists/AbstractShortList.java @@ -12,6 +12,7 @@ import speiger.src.collections.shorts.collections.ShortCollection; import speiger.src.collections.shorts.collections.ShortIterator; import speiger.src.collections.shorts.collections.ShortSplititerator; +import speiger.src.collections.ints.lists.IntList; import speiger.src.collections.shorts.utils.ShortSplititerators; import speiger.src.collections.utils.SanityChecks; @@ -205,13 +206,23 @@ public ShortIterator iterator() { public ShortListIterator listIterator() { return listIterator(0); } - + @Override public ShortListIterator listIterator(int index) { if(index < 0 || index > size()) throw new IndexOutOfBoundsException(); return new ShortListIter(index); } + @Override + public ShortListIterator indexedIterator(int...indecies) { + return new IndexedIterator(indecies); + } + + @Override + public ShortListIterator indexedIterator(IntList indecies) { + return new ListIndexedIterator(indecies); + } + @Override public void size(int size) { while(size > size()) add((short)0); @@ -566,7 +577,153 @@ public int back(int amount) { } } } + + private class ListIndexedIterator implements ShortListIterator { + IntList indecies; + int index; + int lastReturned = -1; + + ListIndexedIterator(IntList indecies) { + this.indecies = indecies; + } + + @Override + public boolean hasNext() { + return index < indecies.size(); + } + + @Override + public short nextShort() { + if(!hasNext()) throw new NoSuchElementException(); + int i = index++; + return getShort((lastReturned = indecies.getInt(i))); + } + + @Override + public boolean hasPrevious() { + return index > 0; + } + + @Override + public short previousShort() { + if(!hasPrevious()) throw new NoSuchElementException(); + index--; + return getShort((lastReturned = indecies.getInt(index))); + } + + @Override + public int nextIndex() { + return index; + } + + @Override + public int previousIndex() { + return index-1; + } + + @Override + public void remove() { throw new UnsupportedOperationException(); } + @Override + public void add(short e) { throw new UnsupportedOperationException(); } + + @Override + public void set(short e) { + if(lastReturned == -1) throw new IllegalStateException(); + AbstractShortList.this.set(lastReturned, e); + } + + @Override + public int skip(int amount) { + if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed"); + int steps = Math.min(amount, indecies.size() - index); + index += steps; + if(steps > 0) lastReturned = Math.min(index-1, indecies.size()-1); + return steps; + } + + @Override + public int back(int amount) { + if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed"); + int steps = Math.min(amount, index); + index -= steps; + if(steps > 0) lastReturned = Math.max(index, 0); + return steps; + } + } + + private class IndexedIterator implements ShortListIterator { + int[] indecies; + int index; + int lastReturned = -1; + + IndexedIterator(int[] indecies) { + this.indecies = indecies; + } + @Override + public boolean hasNext() { + return index < indecies.length; + } + + @Override + public short nextShort() { + if(!hasNext()) throw new NoSuchElementException(); + int i = index++; + return getShort((lastReturned = indecies[i])); + } + + @Override + public boolean hasPrevious() { + return index > 0; + } + + @Override + public short previousShort() { + if(!hasPrevious()) throw new NoSuchElementException(); + index--; + return getShort((lastReturned = indecies[index])); + } + + @Override + public int nextIndex() { + return index; + } + + @Override + public int previousIndex() { + return index-1; + } + + @Override + public void remove() { throw new UnsupportedOperationException(); } + @Override + public void add(short e) { throw new UnsupportedOperationException(); } + + @Override + public void set(short e) { + if(lastReturned == -1) throw new IllegalStateException(); + AbstractShortList.this.set(lastReturned, e); + } + + @Override + public int skip(int amount) { + if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed"); + int steps = Math.min(amount, indecies.length - index); + index += steps; + if(steps > 0) lastReturned = Math.min(index-1, indecies.length-1); + return steps; + } + + @Override + public int back(int amount) { + if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed"); + int steps = Math.min(amount, index); + index -= steps; + if(steps > 0) lastReturned = Math.max(index, 0); + return steps; + } + } + private class ShortListIter implements ShortListIterator { int index; int lastReturned = -1; @@ -644,7 +801,7 @@ public int back(int amount) { if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed"); int steps = Math.min(amount, index); index -= steps; - if(steps > 0) lastReturned = Math.min(index, size()-1); + if(steps > 0) lastReturned = Math.max(index, 0); return steps; } } diff --git a/src/main/java/speiger/src/collections/shorts/lists/ShortList.java b/src/main/java/speiger/src/collections/shorts/lists/ShortList.java index 2b062526..ffc782c3 100644 --- a/src/main/java/speiger/src/collections/shorts/lists/ShortList.java +++ b/src/main/java/speiger/src/collections/shorts/lists/ShortList.java @@ -14,6 +14,7 @@ import speiger.src.collections.shorts.functions.ShortComparator; import speiger.src.collections.shorts.utils.ShortArrays; import speiger.src.collections.shorts.utils.ShortLists; +import speiger.src.collections.ints.lists.IntList; import speiger.src.collections.shorts.utils.ShortSplititerators; import speiger.src.collections.utils.SanityChecks; @@ -342,6 +343,24 @@ public default void forEachIndexed(IntShortConsumer action) { @Override public ShortListIterator listIterator(int index); + /** + * Creates a Iterator that follows the indecies provided.
+ * For example if the Lists Contents is:
-1, 0 1
and the indecies are:
0, 1, 2, 2, 1, 0
+ * then the iterator will return the following values:
-1, 0, 1, 1, 0, -1 + * @param indecies that should be used for the iteration. + * @return a custom indexed iterator + */ + public ShortListIterator indexedIterator(int...indecies); + + /** + * Creates a Iterator that follows the indecies provided.
+ * For example if the Lists Contents is:
-1, 0 1
and the indecies are:
0, 1, 2, 2, 1, 0
+ * then the iterator will return the following values:
-1, 0, 1, 1, 0, -1 + * @param indecies that should be used for the iteration. + * @return a custom indexed iterator + */ + public ShortListIterator indexedIterator(IntList indecies); + /** * A Type-Specific List of subList * @see java.util.List#subList(int, int) diff --git a/src/main/java/speiger/src/collections/shorts/maps/abstracts/AbstractShort2BooleanMap.java b/src/main/java/speiger/src/collections/shorts/maps/abstracts/AbstractShort2BooleanMap.java index 2dc04649..a9863336 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/abstracts/AbstractShort2BooleanMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/abstracts/AbstractShort2BooleanMap.java @@ -151,6 +151,39 @@ public boolean computeBoolean(short key, ShortBooleanUnaryOperator mappingFuncti return newValue; } + @Override + public boolean computeBooleanIfAbsent(short key, ShortPredicate mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(!containsKey(key)) { + boolean newValue = mappingFunction.test(key); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public boolean supplyBooleanIfAbsent(short key, BooleanSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + if(!containsKey(key)) { + boolean newValue = valueProvider.getAsBoolean(); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public boolean computeBooleanIfPresent(short key, ShortBooleanUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(containsKey(key)) { + boolean newValue = mappingFunction.applyAsBoolean(key, get(key)); + put(key, newValue); + return newValue; + } + return getDefaultReturnValue(); + } + @Override public boolean computeBooleanNonDefault(short key, ShortBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -167,17 +200,6 @@ public boolean computeBooleanNonDefault(short key, ShortBooleanUnaryOperator map return newValue; } - @Override - public boolean computeBooleanIfAbsent(short key, ShortPredicate mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(!containsKey(key)) { - boolean newValue = mappingFunction.test(key); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public boolean computeBooleanIfAbsentNonDefault(short key, ShortPredicate mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -192,17 +214,6 @@ public boolean computeBooleanIfAbsentNonDefault(short key, ShortPredicate mappin return value; } - @Override - public boolean supplyBooleanIfAbsent(short key, BooleanSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - if(!containsKey(key)) { - boolean newValue = valueProvider.getAsBoolean(); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public boolean supplyBooleanIfAbsentNonDefault(short key, BooleanSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -217,17 +228,6 @@ public boolean supplyBooleanIfAbsentNonDefault(short key, BooleanSupplier valueP return value; } - @Override - public boolean computeBooleanIfPresent(short key, ShortBooleanUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(containsKey(key)) { - boolean newValue = mappingFunction.applyAsBoolean(key, get(key)); - put(key, newValue); - return newValue; - } - return getDefaultReturnValue(); - } - @Override public boolean computeBooleanIfPresentNonDefault(short key, ShortBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/shorts/maps/abstracts/AbstractShort2ByteMap.java b/src/main/java/speiger/src/collections/shorts/maps/abstracts/AbstractShort2ByteMap.java index 49415616..1bb13e5d 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/abstracts/AbstractShort2ByteMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/abstracts/AbstractShort2ByteMap.java @@ -157,6 +157,39 @@ public byte computeByte(short key, ShortByteUnaryOperator mappingFunction) { return newValue; } + @Override + public byte computeByteIfAbsent(short key, Short2ByteFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(!containsKey(key)) { + byte newValue = mappingFunction.applyAsByte(key); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public byte supplyByteIfAbsent(short key, ByteSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + if(!containsKey(key)) { + byte newValue = valueProvider.getAsByte(); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public byte computeByteIfPresent(short key, ShortByteUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(containsKey(key)) { + byte newValue = mappingFunction.applyAsByte(key, get(key)); + put(key, newValue); + return newValue; + } + return getDefaultReturnValue(); + } + @Override public byte computeByteNonDefault(short key, ShortByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -173,17 +206,6 @@ public byte computeByteNonDefault(short key, ShortByteUnaryOperator mappingFunct return newValue; } - @Override - public byte computeByteIfAbsent(short key, Short2ByteFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(!containsKey(key)) { - byte newValue = mappingFunction.applyAsByte(key); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public byte computeByteIfAbsentNonDefault(short key, Short2ByteFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -198,23 +220,12 @@ public byte computeByteIfAbsentNonDefault(short key, Short2ByteFunction mappingF return value; } - @Override - public byte supplyByteIfAbsent(short key, ByteSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - if(!containsKey(key)) { - byte newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public byte supplyByteIfAbsentNonDefault(short key, ByteSupplier valueProvider) { Objects.requireNonNull(valueProvider); byte value; if((value = get(key)) == getDefaultReturnValue() || !containsKey(key)) { - byte newValue = valueProvider.getAsInt(); + byte newValue = valueProvider.getAsByte(); if(newValue != getDefaultReturnValue()) { put(key, newValue); return newValue; @@ -223,17 +234,6 @@ public byte supplyByteIfAbsentNonDefault(short key, ByteSupplier valueProvider) return value; } - @Override - public byte computeByteIfPresent(short key, ShortByteUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(containsKey(key)) { - byte newValue = mappingFunction.applyAsByte(key, get(key)); - put(key, newValue); - return newValue; - } - return getDefaultReturnValue(); - } - @Override public byte computeByteIfPresentNonDefault(short key, ShortByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/shorts/maps/abstracts/AbstractShort2CharMap.java b/src/main/java/speiger/src/collections/shorts/maps/abstracts/AbstractShort2CharMap.java index 8ded9cc6..4b3a35a4 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/abstracts/AbstractShort2CharMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/abstracts/AbstractShort2CharMap.java @@ -157,6 +157,39 @@ public char computeChar(short key, ShortCharUnaryOperator mappingFunction) { return newValue; } + @Override + public char computeCharIfAbsent(short key, Short2CharFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(!containsKey(key)) { + char newValue = mappingFunction.applyAsChar(key); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public char supplyCharIfAbsent(short key, CharSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + if(!containsKey(key)) { + char newValue = valueProvider.getAsChar(); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public char computeCharIfPresent(short key, ShortCharUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(containsKey(key)) { + char newValue = mappingFunction.applyAsChar(key, get(key)); + put(key, newValue); + return newValue; + } + return getDefaultReturnValue(); + } + @Override public char computeCharNonDefault(short key, ShortCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -173,17 +206,6 @@ public char computeCharNonDefault(short key, ShortCharUnaryOperator mappingFunct return newValue; } - @Override - public char computeCharIfAbsent(short key, Short2CharFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(!containsKey(key)) { - char newValue = mappingFunction.applyAsChar(key); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public char computeCharIfAbsentNonDefault(short key, Short2CharFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -198,23 +220,12 @@ public char computeCharIfAbsentNonDefault(short key, Short2CharFunction mappingF return value; } - @Override - public char supplyCharIfAbsent(short key, CharSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - if(!containsKey(key)) { - char newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public char supplyCharIfAbsentNonDefault(short key, CharSupplier valueProvider) { Objects.requireNonNull(valueProvider); char value; if((value = get(key)) == getDefaultReturnValue() || !containsKey(key)) { - char newValue = valueProvider.getAsInt(); + char newValue = valueProvider.getAsChar(); if(newValue != getDefaultReturnValue()) { put(key, newValue); return newValue; @@ -223,17 +234,6 @@ public char supplyCharIfAbsentNonDefault(short key, CharSupplier valueProvider) return value; } - @Override - public char computeCharIfPresent(short key, ShortCharUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(containsKey(key)) { - char newValue = mappingFunction.applyAsChar(key, get(key)); - put(key, newValue); - return newValue; - } - return getDefaultReturnValue(); - } - @Override public char computeCharIfPresentNonDefault(short key, ShortCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/shorts/maps/abstracts/AbstractShort2DoubleMap.java b/src/main/java/speiger/src/collections/shorts/maps/abstracts/AbstractShort2DoubleMap.java index 29265294..a759bb7e 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/abstracts/AbstractShort2DoubleMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/abstracts/AbstractShort2DoubleMap.java @@ -157,6 +157,39 @@ public double computeDouble(short key, ShortDoubleUnaryOperator mappingFunction) return newValue; } + @Override + public double computeDoubleIfAbsent(short key, Short2DoubleFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(!containsKey(key)) { + double newValue = mappingFunction.applyAsDouble(key); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public double supplyDoubleIfAbsent(short key, DoubleSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + if(!containsKey(key)) { + double newValue = valueProvider.getAsDouble(); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public double computeDoubleIfPresent(short key, ShortDoubleUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(containsKey(key)) { + double newValue = mappingFunction.applyAsDouble(key, get(key)); + put(key, newValue); + return newValue; + } + return getDefaultReturnValue(); + } + @Override public double computeDoubleNonDefault(short key, ShortDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -173,17 +206,6 @@ public double computeDoubleNonDefault(short key, ShortDoubleUnaryOperator mappin return newValue; } - @Override - public double computeDoubleIfAbsent(short key, Short2DoubleFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(!containsKey(key)) { - double newValue = mappingFunction.applyAsDouble(key); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public double computeDoubleIfAbsentNonDefault(short key, Short2DoubleFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -198,17 +220,6 @@ public double computeDoubleIfAbsentNonDefault(short key, Short2DoubleFunction ma return value; } - @Override - public double supplyDoubleIfAbsent(short key, DoubleSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - if(!containsKey(key)) { - double newValue = valueProvider.getAsDouble(); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public double supplyDoubleIfAbsentNonDefault(short key, DoubleSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -223,17 +234,6 @@ public double supplyDoubleIfAbsentNonDefault(short key, DoubleSupplier valueProv return value; } - @Override - public double computeDoubleIfPresent(short key, ShortDoubleUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(containsKey(key)) { - double newValue = mappingFunction.applyAsDouble(key, get(key)); - put(key, newValue); - return newValue; - } - return getDefaultReturnValue(); - } - @Override public double computeDoubleIfPresentNonDefault(short key, ShortDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/shorts/maps/abstracts/AbstractShort2FloatMap.java b/src/main/java/speiger/src/collections/shorts/maps/abstracts/AbstractShort2FloatMap.java index a4cefd23..9ae69ba7 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/abstracts/AbstractShort2FloatMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/abstracts/AbstractShort2FloatMap.java @@ -157,6 +157,39 @@ public float computeFloat(short key, ShortFloatUnaryOperator mappingFunction) { return newValue; } + @Override + public float computeFloatIfAbsent(short key, Short2FloatFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(!containsKey(key)) { + float newValue = mappingFunction.applyAsFloat(key); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public float supplyFloatIfAbsent(short key, FloatSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + if(!containsKey(key)) { + float newValue = valueProvider.getAsFloat(); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public float computeFloatIfPresent(short key, ShortFloatUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(containsKey(key)) { + float newValue = mappingFunction.applyAsFloat(key, get(key)); + put(key, newValue); + return newValue; + } + return getDefaultReturnValue(); + } + @Override public float computeFloatNonDefault(short key, ShortFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -173,17 +206,6 @@ public float computeFloatNonDefault(short key, ShortFloatUnaryOperator mappingFu return newValue; } - @Override - public float computeFloatIfAbsent(short key, Short2FloatFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(!containsKey(key)) { - float newValue = mappingFunction.applyAsFloat(key); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public float computeFloatIfAbsentNonDefault(short key, Short2FloatFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -198,23 +220,12 @@ public float computeFloatIfAbsentNonDefault(short key, Short2FloatFunction mappi return value; } - @Override - public float supplyFloatIfAbsent(short key, FloatSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - if(!containsKey(key)) { - float newValue = valueProvider.getAsDouble(); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public float supplyFloatIfAbsentNonDefault(short key, FloatSupplier valueProvider) { Objects.requireNonNull(valueProvider); float value; if((value = get(key)) == getDefaultReturnValue() || !containsKey(key)) { - float newValue = valueProvider.getAsDouble(); + float newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) != Float.floatToIntBits(getDefaultReturnValue())) { put(key, newValue); return newValue; @@ -223,17 +234,6 @@ public float supplyFloatIfAbsentNonDefault(short key, FloatSupplier valueProvide return value; } - @Override - public float computeFloatIfPresent(short key, ShortFloatUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(containsKey(key)) { - float newValue = mappingFunction.applyAsFloat(key, get(key)); - put(key, newValue); - return newValue; - } - return getDefaultReturnValue(); - } - @Override public float computeFloatIfPresentNonDefault(short key, ShortFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/shorts/maps/abstracts/AbstractShort2IntMap.java b/src/main/java/speiger/src/collections/shorts/maps/abstracts/AbstractShort2IntMap.java index 2459c784..7275dff6 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/abstracts/AbstractShort2IntMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/abstracts/AbstractShort2IntMap.java @@ -157,6 +157,39 @@ public int computeInt(short key, ShortIntUnaryOperator mappingFunction) { return newValue; } + @Override + public int computeIntIfAbsent(short key, Short2IntFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(!containsKey(key)) { + int newValue = mappingFunction.applyAsInt(key); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public int supplyIntIfAbsent(short key, IntSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + if(!containsKey(key)) { + int newValue = valueProvider.getAsInt(); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public int computeIntIfPresent(short key, ShortIntUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(containsKey(key)) { + int newValue = mappingFunction.applyAsInt(key, get(key)); + put(key, newValue); + return newValue; + } + return getDefaultReturnValue(); + } + @Override public int computeIntNonDefault(short key, ShortIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -173,17 +206,6 @@ public int computeIntNonDefault(short key, ShortIntUnaryOperator mappingFunction return newValue; } - @Override - public int computeIntIfAbsent(short key, Short2IntFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(!containsKey(key)) { - int newValue = mappingFunction.applyAsInt(key); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public int computeIntIfAbsentNonDefault(short key, Short2IntFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -198,17 +220,6 @@ public int computeIntIfAbsentNonDefault(short key, Short2IntFunction mappingFunc return value; } - @Override - public int supplyIntIfAbsent(short key, IntSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - if(!containsKey(key)) { - int newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public int supplyIntIfAbsentNonDefault(short key, IntSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -223,17 +234,6 @@ public int supplyIntIfAbsentNonDefault(short key, IntSupplier valueProvider) { return value; } - @Override - public int computeIntIfPresent(short key, ShortIntUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(containsKey(key)) { - int newValue = mappingFunction.applyAsInt(key, get(key)); - put(key, newValue); - return newValue; - } - return getDefaultReturnValue(); - } - @Override public int computeIntIfPresentNonDefault(short key, ShortIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/shorts/maps/abstracts/AbstractShort2LongMap.java b/src/main/java/speiger/src/collections/shorts/maps/abstracts/AbstractShort2LongMap.java index 3d0d863b..c2c17638 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/abstracts/AbstractShort2LongMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/abstracts/AbstractShort2LongMap.java @@ -157,6 +157,39 @@ public long computeLong(short key, ShortLongUnaryOperator mappingFunction) { return newValue; } + @Override + public long computeLongIfAbsent(short key, Short2LongFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(!containsKey(key)) { + long newValue = mappingFunction.applyAsLong(key); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public long supplyLongIfAbsent(short key, LongSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + if(!containsKey(key)) { + long newValue = valueProvider.getAsLong(); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public long computeLongIfPresent(short key, ShortLongUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(containsKey(key)) { + long newValue = mappingFunction.applyAsLong(key, get(key)); + put(key, newValue); + return newValue; + } + return getDefaultReturnValue(); + } + @Override public long computeLongNonDefault(short key, ShortLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -173,17 +206,6 @@ public long computeLongNonDefault(short key, ShortLongUnaryOperator mappingFunct return newValue; } - @Override - public long computeLongIfAbsent(short key, Short2LongFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(!containsKey(key)) { - long newValue = mappingFunction.applyAsLong(key); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public long computeLongIfAbsentNonDefault(short key, Short2LongFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -198,17 +220,6 @@ public long computeLongIfAbsentNonDefault(short key, Short2LongFunction mappingF return value; } - @Override - public long supplyLongIfAbsent(short key, LongSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - if(!containsKey(key)) { - long newValue = valueProvider.getAsLong(); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public long supplyLongIfAbsentNonDefault(short key, LongSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -223,17 +234,6 @@ public long supplyLongIfAbsentNonDefault(short key, LongSupplier valueProvider) return value; } - @Override - public long computeLongIfPresent(short key, ShortLongUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(containsKey(key)) { - long newValue = mappingFunction.applyAsLong(key, get(key)); - put(key, newValue); - return newValue; - } - return getDefaultReturnValue(); - } - @Override public long computeLongIfPresentNonDefault(short key, ShortLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/shorts/maps/abstracts/AbstractShort2ObjectMap.java b/src/main/java/speiger/src/collections/shorts/maps/abstracts/AbstractShort2ObjectMap.java index 5e33f111..58433afe 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/abstracts/AbstractShort2ObjectMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/abstracts/AbstractShort2ObjectMap.java @@ -159,22 +159,6 @@ public V compute(short key, ShortObjectUnaryOperator mappingFunction) { return newValue; } - @Override - public V computeNonDefault(short key, ShortObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - V value = get(key); - V newValue = mappingFunction.apply(key, value); - if(Objects.equals(newValue, getDefaultReturnValue())) { - if(!Objects.equals(value, getDefaultReturnValue()) || containsKey(key)) { - remove(key); - return getDefaultReturnValue(); - } - return getDefaultReturnValue(); - } - put(key, newValue); - return newValue; - } - @Override public V computeIfAbsent(short key, ShortFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -189,20 +173,6 @@ public V computeIfAbsent(short key, ShortFunction mappingFunction) { return value; } - @Override - public V computeIfAbsentNonDefault(short key, ShortFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - V value; - if((value = get(key)) == getDefaultReturnValue() || !containsKey(key)) { - V newValue = mappingFunction.apply(key); - if(!Objects.equals(newValue, getDefaultReturnValue())) { - put(key, newValue); - return newValue; - } - } - return value; - } - @Override public V supplyIfAbsent(short key, ObjectSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -217,20 +187,6 @@ public V supplyIfAbsent(short key, ObjectSupplier valueProvider) { return value; } - @Override - public V supplyIfAbsentNonDefault(short key, ObjectSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - V value; - if((value = get(key)) == getDefaultReturnValue() || !containsKey(key)) { - V newValue = valueProvider.get(); - if(!Objects.equals(newValue, getDefaultReturnValue())) { - put(key, newValue); - return newValue; - } - } - return value; - } - @Override public V computeIfPresent(short key, ShortObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -246,21 +202,6 @@ public V computeIfPresent(short key, ShortObjectUnaryOperator mappingFunction return getDefaultReturnValue(); } - @Override - public V computeIfPresentNonDefault(short key, ShortObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - V value; - if(!Objects.equals((value = get(key)), getDefaultReturnValue()) || containsKey(key)) { - V newValue = mappingFunction.apply(key, value); - if(!Objects.equals(newValue, getDefaultReturnValue())) { - put(key, newValue); - return newValue; - } - remove(key); - } - return getDefaultReturnValue(); - } - @Override public V merge(short key, V value, ObjectObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/shorts/maps/abstracts/AbstractShort2ShortMap.java b/src/main/java/speiger/src/collections/shorts/maps/abstracts/AbstractShort2ShortMap.java index 54b42eb3..100732ce 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/abstracts/AbstractShort2ShortMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/abstracts/AbstractShort2ShortMap.java @@ -155,6 +155,39 @@ public short computeShort(short key, ShortShortUnaryOperator mappingFunction) { return newValue; } + @Override + public short computeShortIfAbsent(short key, ShortUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(!containsKey(key)) { + short newValue = mappingFunction.applyAsShort(key); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public short supplyShortIfAbsent(short key, ShortSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + if(!containsKey(key)) { + short newValue = valueProvider.getAsShort(); + put(key, newValue); + return newValue; + } + return get(key); + } + + @Override + public short computeShortIfPresent(short key, ShortShortUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + if(containsKey(key)) { + short newValue = mappingFunction.applyAsShort(key, get(key)); + put(key, newValue); + return newValue; + } + return getDefaultReturnValue(); + } + @Override public short computeShortNonDefault(short key, ShortShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -171,17 +204,6 @@ public short computeShortNonDefault(short key, ShortShortUnaryOperator mappingFu return newValue; } - @Override - public short computeShortIfAbsent(short key, ShortUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(!containsKey(key)) { - short newValue = mappingFunction.applyAsShort(key); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public short computeShortIfAbsentNonDefault(short key, ShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -196,23 +218,12 @@ public short computeShortIfAbsentNonDefault(short key, ShortUnaryOperator mappin return value; } - @Override - public short supplyShortIfAbsent(short key, ShortSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - if(!containsKey(key)) { - short newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return get(key); - } - @Override public short supplyShortIfAbsentNonDefault(short key, ShortSupplier valueProvider) { Objects.requireNonNull(valueProvider); short value; if((value = get(key)) == getDefaultReturnValue() || !containsKey(key)) { - short newValue = valueProvider.getAsInt(); + short newValue = valueProvider.getAsShort(); if(newValue != getDefaultReturnValue()) { put(key, newValue); return newValue; @@ -221,17 +232,6 @@ public short supplyShortIfAbsentNonDefault(short key, ShortSupplier valueProvide return value; } - @Override - public short computeShortIfPresent(short key, ShortShortUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - if(containsKey(key)) { - short newValue = mappingFunction.applyAsShort(key, get(key)); - put(key, newValue); - return newValue; - } - return getDefaultReturnValue(); - } - @Override public short computeShortIfPresentNonDefault(short key, ShortShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/concurrent/Short2BooleanConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/concurrent/Short2BooleanConcurrentOpenHashMap.java index 68ddacbb..be3ccebf 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/concurrent/Short2BooleanConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/concurrent/Short2BooleanConcurrentOpenHashMap.java @@ -438,13 +438,6 @@ public boolean computeBoolean(short key, ShortBooleanUnaryOperator mappingFuncti return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public boolean computeBooleanNonDefault(short key, ShortBooleanUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public boolean computeBooleanIfAbsent(short key, ShortPredicate mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -452,13 +445,6 @@ public boolean computeBooleanIfAbsent(short key, ShortPredicate mappingFunction) return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public boolean computeBooleanIfAbsentNonDefault(short key, ShortPredicate mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public boolean supplyBooleanIfAbsent(short key, BooleanSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -467,17 +453,31 @@ public boolean supplyBooleanIfAbsent(short key, BooleanSupplier valueProvider) { } @Override - public boolean supplyBooleanIfAbsentNonDefault(short key, BooleanSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public boolean computeBooleanIfPresent(short key, ShortBooleanUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); + return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } @Override - public boolean computeBooleanIfPresent(short key, ShortBooleanUnaryOperator mappingFunction) { + public boolean computeBooleanNonDefault(short key, ShortBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).computeIfPresent(hash, key, mappingFunction); + return getSegment(hash).computeNonDefault(hash, key, mappingFunction); + } + + @Override + public boolean computeBooleanIfAbsentNonDefault(short key, ShortPredicate mappingFunction) { + Objects.requireNonNull(mappingFunction); + int hash = getHashCode(key); + return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); + } + + @Override + public boolean supplyBooleanIfAbsentNonDefault(short key, BooleanSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + int hash = getHashCode(key); + return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); } @Override @@ -2032,35 +2032,29 @@ protected boolean compute(int hash, short key, ShortBooleanUnaryOperator mapping } } - protected boolean computeNonDefault(int hash, short key, ShortBooleanUnaryOperator mappingFunction) { + protected boolean computeIfAbsent(int hash, short key, ShortPredicate mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + boolean newValue = mappingFunction.test(key); insert(-index-1, key, newValue); return newValue; } - boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + boolean newValue = values[index]; return newValue; } finally { unlockWrite(stamp); } } - - protected boolean computeIfAbsent(int hash, short key, ShortPredicate mappingFunction) { + + protected boolean supplyIfAbsent(int hash, short key, BooleanSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - boolean newValue = mappingFunction.test(key); + boolean newValue = valueProvider.getAsBoolean(); insert(-index-1, key, newValue); return newValue; } @@ -2071,23 +2065,37 @@ protected boolean computeIfAbsent(int hash, short key, ShortPredicate mappingFun unlockWrite(stamp); } } + + protected boolean computeIfPresent(int hash, short key, ShortBooleanUnaryOperator mappingFunction) { + long stamp = writeLock(); + try { + int index = findIndex(hash, key); + if(index < 0) return getDefaultReturnValue(); + boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); + values[index] = newValue; + return newValue; + } + finally { + unlockWrite(stamp); + } + } - protected boolean computeIfAbsentNonDefault(int hash, short key, ShortPredicate mappingFunction) { + protected boolean computeNonDefault(int hash, short key, ShortBooleanUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - boolean newValue = mappingFunction.test(key); + boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - boolean newValue = values[index]; + boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.test(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } finally { @@ -2095,16 +2103,22 @@ protected boolean computeIfAbsentNonDefault(int hash, short key, ShortPredicate } } - protected boolean supplyIfAbsent(int hash, short key, BooleanSupplier valueProvider) { + protected boolean computeIfAbsentNonDefault(int hash, short key, ShortPredicate mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - boolean newValue = valueProvider.getAsBoolean(); + boolean newValue = mappingFunction.test(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } boolean newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.test(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } finally { @@ -2135,20 +2149,6 @@ protected boolean supplyIfAbsentNonDefault(int hash, short key, BooleanSupplier } } - protected boolean computeIfPresent(int hash, short key, ShortBooleanUnaryOperator mappingFunction) { - long stamp = writeLock(); - try { - int index = findIndex(hash, key); - if(index < 0) return getDefaultReturnValue(); - boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); - values[index] = newValue; - return newValue; - } - finally { - unlockWrite(stamp); - } - } - protected boolean computeIfPresentNonDefault(int hash, short key, ShortBooleanUnaryOperator mappingFunction) { long stamp = writeLock(); try { diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/concurrent/Short2ByteConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/concurrent/Short2ByteConcurrentOpenHashMap.java index f93accdc..3a88ebba 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/concurrent/Short2ByteConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/concurrent/Short2ByteConcurrentOpenHashMap.java @@ -451,13 +451,6 @@ public byte computeByte(short key, ShortByteUnaryOperator mappingFunction) { return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public byte computeByteNonDefault(short key, ShortByteUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public byte computeByteIfAbsent(short key, Short2ByteFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -465,13 +458,6 @@ public byte computeByteIfAbsent(short key, Short2ByteFunction mappingFunction) { return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public byte computeByteIfAbsentNonDefault(short key, Short2ByteFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public byte supplyByteIfAbsent(short key, ByteSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -480,17 +466,31 @@ public byte supplyByteIfAbsent(short key, ByteSupplier valueProvider) { } @Override - public byte supplyByteIfAbsentNonDefault(short key, ByteSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public byte computeByteIfPresent(short key, ShortByteUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); + return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } @Override - public byte computeByteIfPresent(short key, ShortByteUnaryOperator mappingFunction) { + public byte computeByteNonDefault(short key, ShortByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).computeIfPresent(hash, key, mappingFunction); + return getSegment(hash).computeNonDefault(hash, key, mappingFunction); + } + + @Override + public byte computeByteIfAbsentNonDefault(short key, Short2ByteFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + int hash = getHashCode(key); + return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); + } + + @Override + public byte supplyByteIfAbsentNonDefault(short key, ByteSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + int hash = getHashCode(key); + return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); } @Override @@ -2076,35 +2076,29 @@ protected byte compute(int hash, short key, ShortByteUnaryOperator mappingFuncti } } - protected byte computeNonDefault(int hash, short key, ShortByteUnaryOperator mappingFunction) { + protected byte computeIfAbsent(int hash, short key, Short2ByteFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + byte newValue = mappingFunction.applyAsByte(key); insert(-index-1, key, newValue); return newValue; } - byte newValue = mappingFunction.applyAsByte(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + byte newValue = values[index]; return newValue; } finally { unlockWrite(stamp); } } - - protected byte computeIfAbsent(int hash, short key, Short2ByteFunction mappingFunction) { + + protected byte supplyIfAbsent(int hash, short key, ByteSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = valueProvider.getAsByte(); insert(-index-1, key, newValue); return newValue; } @@ -2115,23 +2109,14 @@ protected byte computeIfAbsent(int hash, short key, Short2ByteFunction mappingFu unlockWrite(stamp); } } - - protected byte computeIfAbsentNonDefault(int hash, short key, Short2ByteFunction mappingFunction) { + + protected byte computeIfPresent(int hash, short key, ShortByteUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key); - if(newValue == getDefaultReturnValue()) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - byte newValue = values[index]; - if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsByte(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; - } + if(index < 0) return getDefaultReturnValue(); + byte newValue = mappingFunction.applyAsByte(key, values[index]); + values[index] = newValue; return newValue; } finally { @@ -2139,16 +2124,22 @@ protected byte computeIfAbsentNonDefault(int hash, short key, Short2ByteFunction } } - protected byte supplyIfAbsent(int hash, short key, ByteSupplier valueProvider) { + protected byte computeNonDefault(int hash, short key, ShortByteUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - byte newValue = valueProvider.getAsInt(); + byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - byte newValue = values[index]; + byte newValue = mappingFunction.applyAsByte(key, values[index]); + if(newValue == getDefaultReturnValue()) { + removeIndex(index); + return newValue; + } + values[index] = newValue; return newValue; } finally { @@ -2156,19 +2147,19 @@ protected byte supplyIfAbsent(int hash, short key, ByteSupplier valueProvider) { } } - protected byte supplyIfAbsentNonDefault(int hash, short key, ByteSupplier valueProvider) { + protected byte computeIfAbsentNonDefault(int hash, short key, Short2ByteFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - byte newValue = valueProvider.getAsInt(); + byte newValue = mappingFunction.applyAsByte(key); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } byte newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = mappingFunction.applyAsByte(key); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } @@ -2179,13 +2170,22 @@ protected byte supplyIfAbsentNonDefault(int hash, short key, ByteSupplier valueP } } - protected byte computeIfPresent(int hash, short key, ShortByteUnaryOperator mappingFunction) { + protected byte supplyIfAbsentNonDefault(int hash, short key, ByteSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0) return getDefaultReturnValue(); - byte newValue = mappingFunction.applyAsByte(key, values[index]); - values[index] = newValue; + if(index < 0) { + byte newValue = valueProvider.getAsByte(); + if(newValue == getDefaultReturnValue()) return newValue; + insert(-index-1, key, newValue); + return newValue; + } + byte newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = valueProvider.getAsByte(); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } finally { diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/concurrent/Short2CharConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/concurrent/Short2CharConcurrentOpenHashMap.java index f53f124a..a73a6c69 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/concurrent/Short2CharConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/concurrent/Short2CharConcurrentOpenHashMap.java @@ -451,13 +451,6 @@ public char computeChar(short key, ShortCharUnaryOperator mappingFunction) { return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public char computeCharNonDefault(short key, ShortCharUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public char computeCharIfAbsent(short key, Short2CharFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -465,13 +458,6 @@ public char computeCharIfAbsent(short key, Short2CharFunction mappingFunction) { return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public char computeCharIfAbsentNonDefault(short key, Short2CharFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public char supplyCharIfAbsent(short key, CharSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -480,17 +466,31 @@ public char supplyCharIfAbsent(short key, CharSupplier valueProvider) { } @Override - public char supplyCharIfAbsentNonDefault(short key, CharSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public char computeCharIfPresent(short key, ShortCharUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); + return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } @Override - public char computeCharIfPresent(short key, ShortCharUnaryOperator mappingFunction) { + public char computeCharNonDefault(short key, ShortCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).computeIfPresent(hash, key, mappingFunction); + return getSegment(hash).computeNonDefault(hash, key, mappingFunction); + } + + @Override + public char computeCharIfAbsentNonDefault(short key, Short2CharFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + int hash = getHashCode(key); + return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); + } + + @Override + public char supplyCharIfAbsentNonDefault(short key, CharSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + int hash = getHashCode(key); + return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); } @Override @@ -2076,35 +2076,29 @@ protected char compute(int hash, short key, ShortCharUnaryOperator mappingFuncti } } - protected char computeNonDefault(int hash, short key, ShortCharUnaryOperator mappingFunction) { + protected char computeIfAbsent(int hash, short key, Short2CharFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + char newValue = mappingFunction.applyAsChar(key); insert(-index-1, key, newValue); return newValue; } - char newValue = mappingFunction.applyAsChar(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + char newValue = values[index]; return newValue; } finally { unlockWrite(stamp); } } - - protected char computeIfAbsent(int hash, short key, Short2CharFunction mappingFunction) { + + protected char supplyIfAbsent(int hash, short key, CharSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = valueProvider.getAsChar(); insert(-index-1, key, newValue); return newValue; } @@ -2115,23 +2109,14 @@ protected char computeIfAbsent(int hash, short key, Short2CharFunction mappingFu unlockWrite(stamp); } } - - protected char computeIfAbsentNonDefault(int hash, short key, Short2CharFunction mappingFunction) { + + protected char computeIfPresent(int hash, short key, ShortCharUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0) { - char newValue = mappingFunction.applyAsChar(key); - if(newValue == getDefaultReturnValue()) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - char newValue = values[index]; - if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsChar(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; - } + if(index < 0) return getDefaultReturnValue(); + char newValue = mappingFunction.applyAsChar(key, values[index]); + values[index] = newValue; return newValue; } finally { @@ -2139,16 +2124,22 @@ protected char computeIfAbsentNonDefault(int hash, short key, Short2CharFunction } } - protected char supplyIfAbsent(int hash, short key, CharSupplier valueProvider) { + protected char computeNonDefault(int hash, short key, ShortCharUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - char newValue = valueProvider.getAsInt(); + char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - char newValue = values[index]; + char newValue = mappingFunction.applyAsChar(key, values[index]); + if(newValue == getDefaultReturnValue()) { + removeIndex(index); + return newValue; + } + values[index] = newValue; return newValue; } finally { @@ -2156,19 +2147,19 @@ protected char supplyIfAbsent(int hash, short key, CharSupplier valueProvider) { } } - protected char supplyIfAbsentNonDefault(int hash, short key, CharSupplier valueProvider) { + protected char computeIfAbsentNonDefault(int hash, short key, Short2CharFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - char newValue = valueProvider.getAsInt(); + char newValue = mappingFunction.applyAsChar(key); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } char newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = mappingFunction.applyAsChar(key); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } @@ -2179,13 +2170,22 @@ protected char supplyIfAbsentNonDefault(int hash, short key, CharSupplier valueP } } - protected char computeIfPresent(int hash, short key, ShortCharUnaryOperator mappingFunction) { + protected char supplyIfAbsentNonDefault(int hash, short key, CharSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0) return getDefaultReturnValue(); - char newValue = mappingFunction.applyAsChar(key, values[index]); - values[index] = newValue; + if(index < 0) { + char newValue = valueProvider.getAsChar(); + if(newValue == getDefaultReturnValue()) return newValue; + insert(-index-1, key, newValue); + return newValue; + } + char newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = valueProvider.getAsChar(); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } finally { diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/concurrent/Short2DoubleConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/concurrent/Short2DoubleConcurrentOpenHashMap.java index c184d207..201bab70 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/concurrent/Short2DoubleConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/concurrent/Short2DoubleConcurrentOpenHashMap.java @@ -451,13 +451,6 @@ public double computeDouble(short key, ShortDoubleUnaryOperator mappingFunction) return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public double computeDoubleNonDefault(short key, ShortDoubleUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public double computeDoubleIfAbsent(short key, Short2DoubleFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -465,13 +458,6 @@ public double computeDoubleIfAbsent(short key, Short2DoubleFunction mappingFunct return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public double computeDoubleIfAbsentNonDefault(short key, Short2DoubleFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public double supplyDoubleIfAbsent(short key, DoubleSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -480,17 +466,31 @@ public double supplyDoubleIfAbsent(short key, DoubleSupplier valueProvider) { } @Override - public double supplyDoubleIfAbsentNonDefault(short key, DoubleSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public double computeDoubleIfPresent(short key, ShortDoubleUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); + return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } @Override - public double computeDoubleIfPresent(short key, ShortDoubleUnaryOperator mappingFunction) { + public double computeDoubleNonDefault(short key, ShortDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).computeIfPresent(hash, key, mappingFunction); + return getSegment(hash).computeNonDefault(hash, key, mappingFunction); + } + + @Override + public double computeDoubleIfAbsentNonDefault(short key, Short2DoubleFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + int hash = getHashCode(key); + return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); + } + + @Override + public double supplyDoubleIfAbsentNonDefault(short key, DoubleSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + int hash = getHashCode(key); + return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); } @Override @@ -2076,35 +2076,29 @@ protected double compute(int hash, short key, ShortDoubleUnaryOperator mappingFu } } - protected double computeNonDefault(int hash, short key, ShortDoubleUnaryOperator mappingFunction) { + protected double computeIfAbsent(int hash, short key, Short2DoubleFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + double newValue = mappingFunction.applyAsDouble(key); insert(-index-1, key, newValue); return newValue; } - double newValue = mappingFunction.applyAsDouble(key, values[index]); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + double newValue = values[index]; return newValue; } finally { unlockWrite(stamp); } } - - protected double computeIfAbsent(int hash, short key, Short2DoubleFunction mappingFunction) { + + protected double supplyIfAbsent(int hash, short key, DoubleSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = valueProvider.getAsDouble(); insert(-index-1, key, newValue); return newValue; } @@ -2115,23 +2109,37 @@ protected double computeIfAbsent(int hash, short key, Short2DoubleFunction mappi unlockWrite(stamp); } } + + protected double computeIfPresent(int hash, short key, ShortDoubleUnaryOperator mappingFunction) { + long stamp = writeLock(); + try { + int index = findIndex(hash, key); + if(index < 0) return getDefaultReturnValue(); + double newValue = mappingFunction.applyAsDouble(key, values[index]); + values[index] = newValue; + return newValue; + } + finally { + unlockWrite(stamp); + } + } - protected double computeIfAbsentNonDefault(int hash, short key, Short2DoubleFunction mappingFunction) { + protected double computeNonDefault(int hash, short key, ShortDoubleUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } - double newValue = values[index]; + double newValue = mappingFunction.applyAsDouble(key, values[index]); if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - newValue = mappingFunction.applyAsDouble(key); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } finally { @@ -2139,16 +2147,22 @@ protected double computeIfAbsentNonDefault(int hash, short key, Short2DoubleFunc } } - protected double supplyIfAbsent(int hash, short key, DoubleSupplier valueProvider) { + protected double computeIfAbsentNonDefault(int hash, short key, Short2DoubleFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - double newValue = valueProvider.getAsDouble(); + double newValue = mappingFunction.applyAsDouble(key); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } double newValue = values[index]; + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { + newValue = mappingFunction.applyAsDouble(key); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + values[index] = newValue; + } return newValue; } finally { @@ -2179,20 +2193,6 @@ protected double supplyIfAbsentNonDefault(int hash, short key, DoubleSupplier va } } - protected double computeIfPresent(int hash, short key, ShortDoubleUnaryOperator mappingFunction) { - long stamp = writeLock(); - try { - int index = findIndex(hash, key); - if(index < 0) return getDefaultReturnValue(); - double newValue = mappingFunction.applyAsDouble(key, values[index]); - values[index] = newValue; - return newValue; - } - finally { - unlockWrite(stamp); - } - } - protected double computeIfPresentNonDefault(int hash, short key, ShortDoubleUnaryOperator mappingFunction) { long stamp = writeLock(); try { diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/concurrent/Short2FloatConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/concurrent/Short2FloatConcurrentOpenHashMap.java index 625bab91..c32ac131 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/concurrent/Short2FloatConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/concurrent/Short2FloatConcurrentOpenHashMap.java @@ -451,13 +451,6 @@ public float computeFloat(short key, ShortFloatUnaryOperator mappingFunction) { return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public float computeFloatNonDefault(short key, ShortFloatUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public float computeFloatIfAbsent(short key, Short2FloatFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -465,13 +458,6 @@ public float computeFloatIfAbsent(short key, Short2FloatFunction mappingFunction return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public float computeFloatIfAbsentNonDefault(short key, Short2FloatFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public float supplyFloatIfAbsent(short key, FloatSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -480,17 +466,31 @@ public float supplyFloatIfAbsent(short key, FloatSupplier valueProvider) { } @Override - public float supplyFloatIfAbsentNonDefault(short key, FloatSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public float computeFloatIfPresent(short key, ShortFloatUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); + return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } @Override - public float computeFloatIfPresent(short key, ShortFloatUnaryOperator mappingFunction) { + public float computeFloatNonDefault(short key, ShortFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).computeIfPresent(hash, key, mappingFunction); + return getSegment(hash).computeNonDefault(hash, key, mappingFunction); + } + + @Override + public float computeFloatIfAbsentNonDefault(short key, Short2FloatFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + int hash = getHashCode(key); + return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); + } + + @Override + public float supplyFloatIfAbsentNonDefault(short key, FloatSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + int hash = getHashCode(key); + return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); } @Override @@ -2076,35 +2076,29 @@ protected float compute(int hash, short key, ShortFloatUnaryOperator mappingFunc } } - protected float computeNonDefault(int hash, short key, ShortFloatUnaryOperator mappingFunction) { + protected float computeIfAbsent(int hash, short key, Short2FloatFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + float newValue = mappingFunction.applyAsFloat(key); insert(-index-1, key, newValue); return newValue; } - float newValue = mappingFunction.applyAsFloat(key, values[index]); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + float newValue = values[index]; return newValue; } finally { unlockWrite(stamp); } } - - protected float computeIfAbsent(int hash, short key, Short2FloatFunction mappingFunction) { + + protected float supplyIfAbsent(int hash, short key, FloatSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = valueProvider.getAsFloat(); insert(-index-1, key, newValue); return newValue; } @@ -2115,23 +2109,14 @@ protected float computeIfAbsent(int hash, short key, Short2FloatFunction mapping unlockWrite(stamp); } } - - protected float computeIfAbsentNonDefault(int hash, short key, Short2FloatFunction mappingFunction) { + + protected float computeIfPresent(int hash, short key, ShortFloatUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - float newValue = values[index]; - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - newValue = mappingFunction.applyAsFloat(key); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; - values[index] = newValue; - } + if(index < 0) return getDefaultReturnValue(); + float newValue = mappingFunction.applyAsFloat(key, values[index]); + values[index] = newValue; return newValue; } finally { @@ -2139,16 +2124,22 @@ protected float computeIfAbsentNonDefault(int hash, short key, Short2FloatFuncti } } - protected float supplyIfAbsent(int hash, short key, FloatSupplier valueProvider) { + protected float computeNonDefault(int hash, short key, ShortFloatUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - float newValue = valueProvider.getAsDouble(); + float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } - float newValue = values[index]; + float newValue = mappingFunction.applyAsFloat(key, values[index]); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { + removeIndex(index); + return newValue; + } + values[index] = newValue; return newValue; } finally { @@ -2156,19 +2147,19 @@ protected float supplyIfAbsent(int hash, short key, FloatSupplier valueProvider) } } - protected float supplyIfAbsentNonDefault(int hash, short key, FloatSupplier valueProvider) { + protected float computeIfAbsentNonDefault(int hash, short key, Short2FloatFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - float newValue = valueProvider.getAsDouble(); + float newValue = mappingFunction.applyAsFloat(key); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } float newValue = values[index]; if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - newValue = valueProvider.getAsDouble(); + newValue = mappingFunction.applyAsFloat(key); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; values[index] = newValue; } @@ -2179,13 +2170,22 @@ protected float supplyIfAbsentNonDefault(int hash, short key, FloatSupplier valu } } - protected float computeIfPresent(int hash, short key, ShortFloatUnaryOperator mappingFunction) { + protected float supplyIfAbsentNonDefault(int hash, short key, FloatSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0) return getDefaultReturnValue(); - float newValue = mappingFunction.applyAsFloat(key, values[index]); - values[index] = newValue; + if(index < 0) { + float newValue = valueProvider.getAsFloat(); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + insert(-index-1, key, newValue); + return newValue; + } + float newValue = values[index]; + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { + newValue = valueProvider.getAsFloat(); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + values[index] = newValue; + } return newValue; } finally { diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/concurrent/Short2IntConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/concurrent/Short2IntConcurrentOpenHashMap.java index 3c95e7c1..2cb66eb6 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/concurrent/Short2IntConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/concurrent/Short2IntConcurrentOpenHashMap.java @@ -451,13 +451,6 @@ public int computeInt(short key, ShortIntUnaryOperator mappingFunction) { return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public int computeIntNonDefault(short key, ShortIntUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public int computeIntIfAbsent(short key, Short2IntFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -465,13 +458,6 @@ public int computeIntIfAbsent(short key, Short2IntFunction mappingFunction) { return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public int computeIntIfAbsentNonDefault(short key, Short2IntFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public int supplyIntIfAbsent(short key, IntSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -480,17 +466,31 @@ public int supplyIntIfAbsent(short key, IntSupplier valueProvider) { } @Override - public int supplyIntIfAbsentNonDefault(short key, IntSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public int computeIntIfPresent(short key, ShortIntUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); + return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } @Override - public int computeIntIfPresent(short key, ShortIntUnaryOperator mappingFunction) { + public int computeIntNonDefault(short key, ShortIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).computeIfPresent(hash, key, mappingFunction); + return getSegment(hash).computeNonDefault(hash, key, mappingFunction); + } + + @Override + public int computeIntIfAbsentNonDefault(short key, Short2IntFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + int hash = getHashCode(key); + return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); + } + + @Override + public int supplyIntIfAbsentNonDefault(short key, IntSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + int hash = getHashCode(key); + return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); } @Override @@ -2076,35 +2076,29 @@ protected int compute(int hash, short key, ShortIntUnaryOperator mappingFunction } } - protected int computeNonDefault(int hash, short key, ShortIntUnaryOperator mappingFunction) { + protected int computeIfAbsent(int hash, short key, Short2IntFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + int newValue = mappingFunction.applyAsInt(key); insert(-index-1, key, newValue); return newValue; } - int newValue = mappingFunction.applyAsInt(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + int newValue = values[index]; return newValue; } finally { unlockWrite(stamp); } } - - protected int computeIfAbsent(int hash, short key, Short2IntFunction mappingFunction) { + + protected int supplyIfAbsent(int hash, short key, IntSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = valueProvider.getAsInt(); insert(-index-1, key, newValue); return newValue; } @@ -2115,23 +2109,37 @@ protected int computeIfAbsent(int hash, short key, Short2IntFunction mappingFunc unlockWrite(stamp); } } + + protected int computeIfPresent(int hash, short key, ShortIntUnaryOperator mappingFunction) { + long stamp = writeLock(); + try { + int index = findIndex(hash, key); + if(index < 0) return getDefaultReturnValue(); + int newValue = mappingFunction.applyAsInt(key, values[index]); + values[index] = newValue; + return newValue; + } + finally { + unlockWrite(stamp); + } + } - protected int computeIfAbsentNonDefault(int hash, short key, Short2IntFunction mappingFunction) { + protected int computeNonDefault(int hash, short key, ShortIntUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - int newValue = values[index]; + int newValue = mappingFunction.applyAsInt(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsInt(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } finally { @@ -2139,16 +2147,22 @@ protected int computeIfAbsentNonDefault(int hash, short key, Short2IntFunction m } } - protected int supplyIfAbsent(int hash, short key, IntSupplier valueProvider) { + protected int computeIfAbsentNonDefault(int hash, short key, Short2IntFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - int newValue = valueProvider.getAsInt(); + int newValue = mappingFunction.applyAsInt(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } int newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsInt(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } finally { @@ -2179,20 +2193,6 @@ protected int supplyIfAbsentNonDefault(int hash, short key, IntSupplier valuePro } } - protected int computeIfPresent(int hash, short key, ShortIntUnaryOperator mappingFunction) { - long stamp = writeLock(); - try { - int index = findIndex(hash, key); - if(index < 0) return getDefaultReturnValue(); - int newValue = mappingFunction.applyAsInt(key, values[index]); - values[index] = newValue; - return newValue; - } - finally { - unlockWrite(stamp); - } - } - protected int computeIfPresentNonDefault(int hash, short key, ShortIntUnaryOperator mappingFunction) { long stamp = writeLock(); try { diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/concurrent/Short2LongConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/concurrent/Short2LongConcurrentOpenHashMap.java index 394718ba..ef8f269c 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/concurrent/Short2LongConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/concurrent/Short2LongConcurrentOpenHashMap.java @@ -451,13 +451,6 @@ public long computeLong(short key, ShortLongUnaryOperator mappingFunction) { return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public long computeLongNonDefault(short key, ShortLongUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public long computeLongIfAbsent(short key, Short2LongFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -465,13 +458,6 @@ public long computeLongIfAbsent(short key, Short2LongFunction mappingFunction) { return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public long computeLongIfAbsentNonDefault(short key, Short2LongFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public long supplyLongIfAbsent(short key, LongSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -480,17 +466,31 @@ public long supplyLongIfAbsent(short key, LongSupplier valueProvider) { } @Override - public long supplyLongIfAbsentNonDefault(short key, LongSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public long computeLongIfPresent(short key, ShortLongUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); + return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } @Override - public long computeLongIfPresent(short key, ShortLongUnaryOperator mappingFunction) { + public long computeLongNonDefault(short key, ShortLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).computeIfPresent(hash, key, mappingFunction); + return getSegment(hash).computeNonDefault(hash, key, mappingFunction); + } + + @Override + public long computeLongIfAbsentNonDefault(short key, Short2LongFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); + int hash = getHashCode(key); + return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); + } + + @Override + public long supplyLongIfAbsentNonDefault(short key, LongSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + int hash = getHashCode(key); + return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); } @Override @@ -2076,35 +2076,29 @@ protected long compute(int hash, short key, ShortLongUnaryOperator mappingFuncti } } - protected long computeNonDefault(int hash, short key, ShortLongUnaryOperator mappingFunction) { + protected long computeIfAbsent(int hash, short key, Short2LongFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + long newValue = mappingFunction.applyAsLong(key); insert(-index-1, key, newValue); return newValue; } - long newValue = mappingFunction.applyAsLong(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + long newValue = values[index]; return newValue; } finally { unlockWrite(stamp); } } - - protected long computeIfAbsent(int hash, short key, Short2LongFunction mappingFunction) { + + protected long supplyIfAbsent(int hash, short key, LongSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = valueProvider.getAsLong(); insert(-index-1, key, newValue); return newValue; } @@ -2115,23 +2109,37 @@ protected long computeIfAbsent(int hash, short key, Short2LongFunction mappingFu unlockWrite(stamp); } } + + protected long computeIfPresent(int hash, short key, ShortLongUnaryOperator mappingFunction) { + long stamp = writeLock(); + try { + int index = findIndex(hash, key); + if(index < 0) return getDefaultReturnValue(); + long newValue = mappingFunction.applyAsLong(key, values[index]); + values[index] = newValue; + return newValue; + } + finally { + unlockWrite(stamp); + } + } - protected long computeIfAbsentNonDefault(int hash, short key, Short2LongFunction mappingFunction) { + protected long computeNonDefault(int hash, short key, ShortLongUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - long newValue = values[index]; + long newValue = mappingFunction.applyAsLong(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsLong(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } finally { @@ -2139,16 +2147,22 @@ protected long computeIfAbsentNonDefault(int hash, short key, Short2LongFunction } } - protected long supplyIfAbsent(int hash, short key, LongSupplier valueProvider) { + protected long computeIfAbsentNonDefault(int hash, short key, Short2LongFunction mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - long newValue = valueProvider.getAsLong(); + long newValue = mappingFunction.applyAsLong(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } long newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsLong(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } finally { @@ -2179,20 +2193,6 @@ protected long supplyIfAbsentNonDefault(int hash, short key, LongSupplier valueP } } - protected long computeIfPresent(int hash, short key, ShortLongUnaryOperator mappingFunction) { - long stamp = writeLock(); - try { - int index = findIndex(hash, key); - if(index < 0) return getDefaultReturnValue(); - long newValue = mappingFunction.applyAsLong(key, values[index]); - values[index] = newValue; - return newValue; - } - finally { - unlockWrite(stamp); - } - } - protected long computeIfPresentNonDefault(int hash, short key, ShortLongUnaryOperator mappingFunction) { long stamp = writeLock(); try { diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/concurrent/Short2ObjectConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/concurrent/Short2ObjectConcurrentOpenHashMap.java index 574470a8..3c43e6c8 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/concurrent/Short2ObjectConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/concurrent/Short2ObjectConcurrentOpenHashMap.java @@ -426,13 +426,6 @@ public V compute(short key, ShortObjectUnaryOperator mappingFunction) { return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public V computeNonDefault(short key, ShortObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public V computeIfAbsent(short key, ShortFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -440,13 +433,6 @@ public V computeIfAbsent(short key, ShortFunction mappingFunction) { return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public V computeIfAbsentNonDefault(short key, ShortFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public V supplyIfAbsent(short key, ObjectSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -454,13 +440,6 @@ public V supplyIfAbsent(short key, ObjectSupplier valueProvider) { return getSegment(hash).supplyIfAbsent(hash, key, valueProvider); } - @Override - public V supplyIfAbsentNonDefault(short key, ObjectSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); - } - @Override public V computeIfPresent(short key, ShortObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -468,13 +447,6 @@ public V computeIfPresent(short key, ShortObjectUnaryOperator mappingFunction return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } - @Override - public V computeIfPresentNonDefault(short key, ShortObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfPresentNonDefault(hash, key, mappingFunction); - } - @Override public V merge(short key, V value, ObjectObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -2011,29 +1983,6 @@ protected V compute(int hash, short key, ShortObjectUnaryOperator mappingFunc } } - protected V computeNonDefault(int hash, short key, ShortObjectUnaryOperator mappingFunction) { - long stamp = writeLock(); - try { - int index = findIndex(hash, key); - if(index < 0) { - V newValue = mappingFunction.apply(key, getDefaultReturnValue()); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = mappingFunction.apply(key, values[index]); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; - return newValue; - } - finally { - unlockWrite(stamp); - } - } - protected V computeIfAbsent(int hash, short key, ShortFunction mappingFunction) { long stamp = writeLock(); try { @@ -2056,30 +2005,7 @@ protected V computeIfAbsent(int hash, short key, ShortFunction mappingFunctio unlockWrite(stamp); } } - - protected V computeIfAbsentNonDefault(int hash, short key, ShortFunction mappingFunction) { - long stamp = writeLock(); - try { - int index = findIndex(hash, key); - if(index < 0) { - V newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = values[index]; - if(Objects.equals(newValue, getDefaultReturnValue())) { - newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - values[index] = newValue; - } - return newValue; - } - finally { - unlockWrite(stamp); - } - } - + protected V supplyIfAbsent(int hash, short key, ObjectSupplier valueProvider) { long stamp = writeLock(); try { @@ -2102,30 +2028,7 @@ protected V supplyIfAbsent(int hash, short key, ObjectSupplier valueProvider) unlockWrite(stamp); } } - - protected V supplyIfAbsentNonDefault(int hash, short key, ObjectSupplier valueProvider) { - long stamp = writeLock(); - try { - int index = findIndex(hash, key); - if(index < 0) { - V newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = values[index]; - if(Objects.equals(newValue, getDefaultReturnValue())) { - newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - values[index] = newValue; - } - return newValue; - } - finally { - unlockWrite(stamp); - } - } - + protected V computeIfPresent(int hash, short key, ShortObjectUnaryOperator mappingFunction) { long stamp = writeLock(); try { @@ -2144,11 +2047,16 @@ protected V computeIfPresent(int hash, short key, ShortObjectUnaryOperator ma } } - protected V computeIfPresentNonDefault(int hash, short key, ShortObjectUnaryOperator mappingFunction) { + protected V computeNonDefault(int hash, short key, ShortObjectUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0 || Objects.equals(values[index], getDefaultReturnValue())) return getDefaultReturnValue(); + if(index < 0) { + V newValue = mappingFunction.apply(key, getDefaultReturnValue()); + if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; + insert(-index-1, key, newValue); + return newValue; + } V newValue = mappingFunction.apply(key, values[index]); if(Objects.equals(newValue, getDefaultReturnValue())) { removeIndex(index); diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/concurrent/Short2ShortConcurrentOpenHashMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/concurrent/Short2ShortConcurrentOpenHashMap.java index 3bdc944e..22467b6c 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/concurrent/Short2ShortConcurrentOpenHashMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/concurrent/Short2ShortConcurrentOpenHashMap.java @@ -444,13 +444,6 @@ public short computeShort(short key, ShortShortUnaryOperator mappingFunction) { return getSegment(hash).compute(hash, key, mappingFunction); } - @Override - public short computeShortNonDefault(short key, ShortShortUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeNonDefault(hash, key, mappingFunction); - } - @Override public short computeShortIfAbsent(short key, ShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -458,13 +451,6 @@ public short computeShortIfAbsent(short key, ShortUnaryOperator mappingFunction) return getSegment(hash).computeIfAbsent(hash, key, mappingFunction); } - @Override - public short computeShortIfAbsentNonDefault(short key, ShortUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int hash = getHashCode(key); - return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); - } - @Override public short supplyShortIfAbsent(short key, ShortSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -473,17 +459,31 @@ public short supplyShortIfAbsent(short key, ShortSupplier valueProvider) { } @Override - public short supplyShortIfAbsentNonDefault(short key, ShortSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public short computeShortIfPresent(short key, ShortShortUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); + return getSegment(hash).computeIfPresent(hash, key, mappingFunction); } @Override - public short computeShortIfPresent(short key, ShortShortUnaryOperator mappingFunction) { + public short computeShortNonDefault(short key, ShortShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int hash = getHashCode(key); - return getSegment(hash).computeIfPresent(hash, key, mappingFunction); + return getSegment(hash).computeNonDefault(hash, key, mappingFunction); + } + + @Override + public short computeShortIfAbsentNonDefault(short key, ShortUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int hash = getHashCode(key); + return getSegment(hash).computeIfAbsentNonDefault(hash, key, mappingFunction); + } + + @Override + public short supplyShortIfAbsentNonDefault(short key, ShortSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + int hash = getHashCode(key); + return getSegment(hash).supplyIfAbsentNonDefault(hash, key, valueProvider); } @Override @@ -2069,35 +2069,29 @@ protected short compute(int hash, short key, ShortShortUnaryOperator mappingFunc } } - protected short computeNonDefault(int hash, short key, ShortShortUnaryOperator mappingFunction) { + protected short computeIfAbsent(int hash, short key, ShortUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + short newValue = mappingFunction.applyAsShort(key); insert(-index-1, key, newValue); return newValue; } - short newValue = mappingFunction.applyAsShort(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + short newValue = values[index]; return newValue; } finally { unlockWrite(stamp); } } - - protected short computeIfAbsent(int hash, short key, ShortUnaryOperator mappingFunction) { + + protected short supplyIfAbsent(int hash, short key, ShortSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = valueProvider.getAsShort(); insert(-index-1, key, newValue); return newValue; } @@ -2108,23 +2102,14 @@ protected short computeIfAbsent(int hash, short key, ShortUnaryOperator mappingF unlockWrite(stamp); } } - - protected short computeIfAbsentNonDefault(int hash, short key, ShortUnaryOperator mappingFunction) { + + protected short computeIfPresent(int hash, short key, ShortShortUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0) { - short newValue = mappingFunction.applyAsShort(key); - if(newValue == getDefaultReturnValue()) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - short newValue = values[index]; - if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsShort(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; - } + if(index < 0) return getDefaultReturnValue(); + short newValue = mappingFunction.applyAsShort(key, values[index]); + values[index] = newValue; return newValue; } finally { @@ -2132,16 +2117,22 @@ protected short computeIfAbsentNonDefault(int hash, short key, ShortUnaryOperato } } - protected short supplyIfAbsent(int hash, short key, ShortSupplier valueProvider) { + protected short computeNonDefault(int hash, short key, ShortShortUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - short newValue = valueProvider.getAsInt(); + short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - short newValue = values[index]; + short newValue = mappingFunction.applyAsShort(key, values[index]); + if(newValue == getDefaultReturnValue()) { + removeIndex(index); + return newValue; + } + values[index] = newValue; return newValue; } finally { @@ -2149,19 +2140,19 @@ protected short supplyIfAbsent(int hash, short key, ShortSupplier valueProvider) } } - protected short supplyIfAbsentNonDefault(int hash, short key, ShortSupplier valueProvider) { + protected short computeIfAbsentNonDefault(int hash, short key, ShortUnaryOperator mappingFunction) { long stamp = writeLock(); try { int index = findIndex(hash, key); if(index < 0) { - short newValue = valueProvider.getAsInt(); + short newValue = mappingFunction.applyAsShort(key); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } short newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = mappingFunction.applyAsShort(key); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } @@ -2172,13 +2163,22 @@ protected short supplyIfAbsentNonDefault(int hash, short key, ShortSupplier valu } } - protected short computeIfPresent(int hash, short key, ShortShortUnaryOperator mappingFunction) { + protected short supplyIfAbsentNonDefault(int hash, short key, ShortSupplier valueProvider) { long stamp = writeLock(); try { int index = findIndex(hash, key); - if(index < 0) return getDefaultReturnValue(); - short newValue = mappingFunction.applyAsShort(key, values[index]); - values[index] = newValue; + if(index < 0) { + short newValue = valueProvider.getAsShort(); + if(newValue == getDefaultReturnValue()) return newValue; + insert(-index-1, key, newValue); + return newValue; + } + short newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = valueProvider.getAsShort(); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } finally { diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2BooleanOpenCustomHashMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2BooleanOpenCustomHashMap.java index cee36ab0..d4919f3a 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2BooleanOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2BooleanOpenCustomHashMap.java @@ -441,30 +441,24 @@ public boolean computeBoolean(short key, ShortBooleanUnaryOperator mappingFuncti } @Override - public boolean computeBooleanNonDefault(short key, ShortBooleanUnaryOperator mappingFunction) { + public boolean computeBooleanIfAbsent(short key, ShortPredicate mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + boolean newValue = mappingFunction.test(key); insert(-index-1, key, newValue); return newValue; } - boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + boolean newValue = values[index]; return newValue; } - + @Override - public boolean computeBooleanIfAbsent(short key, ShortPredicate mappingFunction) { - Objects.requireNonNull(mappingFunction); + public boolean supplyBooleanIfAbsent(short key, BooleanSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - boolean newValue = mappingFunction.test(key); + boolean newValue = valueProvider.getAsBoolean(); insert(-index-1, key, newValue); return newValue; } @@ -473,34 +467,50 @@ public boolean computeBooleanIfAbsent(short key, ShortPredicate mappingFunction) } @Override - public boolean computeBooleanIfAbsentNonDefault(short key, ShortPredicate mappingFunction) { + public boolean computeBooleanIfPresent(short key, ShortBooleanUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public boolean computeBooleanNonDefault(short key, ShortBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - boolean newValue = mappingFunction.test(key); + boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - boolean newValue = values[index]; + boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.test(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public boolean supplyBooleanIfAbsent(short key, BooleanSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public boolean computeBooleanIfAbsentNonDefault(short key, ShortPredicate mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - boolean newValue = valueProvider.getAsBoolean(); + boolean newValue = mappingFunction.test(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } boolean newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.test(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -523,16 +533,6 @@ public boolean supplyBooleanIfAbsentNonDefault(short key, BooleanSupplier valueP return newValue; } - @Override - public boolean computeBooleanIfPresent(short key, ShortBooleanUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public boolean computeBooleanIfPresentNonDefault(short key, ShortBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2ByteOpenCustomHashMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2ByteOpenCustomHashMap.java index 73ef3455..da20618d 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2ByteOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2ByteOpenCustomHashMap.java @@ -463,30 +463,24 @@ public byte computeByte(short key, ShortByteUnaryOperator mappingFunction) { } @Override - public byte computeByteNonDefault(short key, ShortByteUnaryOperator mappingFunction) { + public byte computeByteIfAbsent(short key, Short2ByteFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + byte newValue = mappingFunction.applyAsByte(key); insert(-index-1, key, newValue); return newValue; } - byte newValue = mappingFunction.applyAsByte(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + byte newValue = values[index]; return newValue; } - + @Override - public byte computeByteIfAbsent(short key, Short2ByteFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public byte supplyByteIfAbsent(short key, ByteSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = valueProvider.getAsByte(); insert(-index-1, key, newValue); return newValue; } @@ -495,34 +489,50 @@ public byte computeByteIfAbsent(short key, Short2ByteFunction mappingFunction) { } @Override - public byte computeByteIfAbsentNonDefault(short key, Short2ByteFunction mappingFunction) { + public byte computeByteIfPresent(short key, ShortByteUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + byte newValue = mappingFunction.applyAsByte(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public byte computeByteNonDefault(short key, ShortByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - byte newValue = values[index]; + byte newValue = mappingFunction.applyAsByte(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsByte(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public byte supplyByteIfAbsent(short key, ByteSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public byte computeByteIfAbsentNonDefault(short key, Short2ByteFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - byte newValue = valueProvider.getAsInt(); + byte newValue = mappingFunction.applyAsByte(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } byte newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsByte(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -531,30 +541,20 @@ public byte supplyByteIfAbsentNonDefault(short key, ByteSupplier valueProvider) Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - byte newValue = valueProvider.getAsInt(); + byte newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } byte newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public byte computeByteIfPresent(short key, ShortByteUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - byte newValue = mappingFunction.applyAsByte(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public byte computeByteIfPresentNonDefault(short key, ShortByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2CharOpenCustomHashMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2CharOpenCustomHashMap.java index 74eb0d6a..20889e73 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2CharOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2CharOpenCustomHashMap.java @@ -463,30 +463,24 @@ public char computeChar(short key, ShortCharUnaryOperator mappingFunction) { } @Override - public char computeCharNonDefault(short key, ShortCharUnaryOperator mappingFunction) { + public char computeCharIfAbsent(short key, Short2CharFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + char newValue = mappingFunction.applyAsChar(key); insert(-index-1, key, newValue); return newValue; } - char newValue = mappingFunction.applyAsChar(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + char newValue = values[index]; return newValue; } - + @Override - public char computeCharIfAbsent(short key, Short2CharFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public char supplyCharIfAbsent(short key, CharSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = valueProvider.getAsChar(); insert(-index-1, key, newValue); return newValue; } @@ -495,34 +489,50 @@ public char computeCharIfAbsent(short key, Short2CharFunction mappingFunction) { } @Override - public char computeCharIfAbsentNonDefault(short key, Short2CharFunction mappingFunction) { + public char computeCharIfPresent(short key, ShortCharUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + char newValue = mappingFunction.applyAsChar(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public char computeCharNonDefault(short key, ShortCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - char newValue = values[index]; + char newValue = mappingFunction.applyAsChar(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsChar(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public char supplyCharIfAbsent(short key, CharSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public char computeCharIfAbsentNonDefault(short key, Short2CharFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - char newValue = valueProvider.getAsInt(); + char newValue = mappingFunction.applyAsChar(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } char newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsChar(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -531,30 +541,20 @@ public char supplyCharIfAbsentNonDefault(short key, CharSupplier valueProvider) Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - char newValue = valueProvider.getAsInt(); + char newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } char newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public char computeCharIfPresent(short key, ShortCharUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - char newValue = mappingFunction.applyAsChar(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public char computeCharIfPresentNonDefault(short key, ShortCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2DoubleOpenCustomHashMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2DoubleOpenCustomHashMap.java index edab497d..622c7483 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2DoubleOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2DoubleOpenCustomHashMap.java @@ -463,30 +463,24 @@ public double computeDouble(short key, ShortDoubleUnaryOperator mappingFunction) } @Override - public double computeDoubleNonDefault(short key, ShortDoubleUnaryOperator mappingFunction) { + public double computeDoubleIfAbsent(short key, Short2DoubleFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + double newValue = mappingFunction.applyAsDouble(key); insert(-index-1, key, newValue); return newValue; } - double newValue = mappingFunction.applyAsDouble(key, values[index]); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + double newValue = values[index]; return newValue; } - + @Override - public double computeDoubleIfAbsent(short key, Short2DoubleFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public double supplyDoubleIfAbsent(short key, DoubleSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = valueProvider.getAsDouble(); insert(-index-1, key, newValue); return newValue; } @@ -495,34 +489,50 @@ public double computeDoubleIfAbsent(short key, Short2DoubleFunction mappingFunct } @Override - public double computeDoubleIfAbsentNonDefault(short key, Short2DoubleFunction mappingFunction) { + public double computeDoubleIfPresent(short key, ShortDoubleUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + double newValue = mappingFunction.applyAsDouble(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public double computeDoubleNonDefault(short key, ShortDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } - double newValue = values[index]; + double newValue = mappingFunction.applyAsDouble(key, values[index]); if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - newValue = mappingFunction.applyAsDouble(key); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public double supplyDoubleIfAbsent(short key, DoubleSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public double computeDoubleIfAbsentNonDefault(short key, Short2DoubleFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - double newValue = valueProvider.getAsDouble(); + double newValue = mappingFunction.applyAsDouble(key); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } double newValue = values[index]; + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { + newValue = mappingFunction.applyAsDouble(key); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + values[index] = newValue; + } return newValue; } @@ -545,16 +555,6 @@ public double supplyDoubleIfAbsentNonDefault(short key, DoubleSupplier valueProv return newValue; } - @Override - public double computeDoubleIfPresent(short key, ShortDoubleUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - double newValue = mappingFunction.applyAsDouble(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public double computeDoubleIfPresentNonDefault(short key, ShortDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2FloatOpenCustomHashMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2FloatOpenCustomHashMap.java index 1e2d135f..a1e1bfd4 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2FloatOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2FloatOpenCustomHashMap.java @@ -463,30 +463,24 @@ public float computeFloat(short key, ShortFloatUnaryOperator mappingFunction) { } @Override - public float computeFloatNonDefault(short key, ShortFloatUnaryOperator mappingFunction) { + public float computeFloatIfAbsent(short key, Short2FloatFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + float newValue = mappingFunction.applyAsFloat(key); insert(-index-1, key, newValue); return newValue; } - float newValue = mappingFunction.applyAsFloat(key, values[index]); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + float newValue = values[index]; return newValue; } - + @Override - public float computeFloatIfAbsent(short key, Short2FloatFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public float supplyFloatIfAbsent(short key, FloatSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = valueProvider.getAsFloat(); insert(-index-1, key, newValue); return newValue; } @@ -495,34 +489,50 @@ public float computeFloatIfAbsent(short key, Short2FloatFunction mappingFunction } @Override - public float computeFloatIfAbsentNonDefault(short key, Short2FloatFunction mappingFunction) { + public float computeFloatIfPresent(short key, ShortFloatUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + float newValue = mappingFunction.applyAsFloat(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public float computeFloatNonDefault(short key, ShortFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } - float newValue = values[index]; + float newValue = mappingFunction.applyAsFloat(key, values[index]); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - newValue = mappingFunction.applyAsFloat(key); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public float supplyFloatIfAbsent(short key, FloatSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public float computeFloatIfAbsentNonDefault(short key, Short2FloatFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - float newValue = valueProvider.getAsDouble(); + float newValue = mappingFunction.applyAsFloat(key); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } float newValue = values[index]; + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { + newValue = mappingFunction.applyAsFloat(key); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + values[index] = newValue; + } return newValue; } @@ -531,30 +541,20 @@ public float supplyFloatIfAbsentNonDefault(short key, FloatSupplier valueProvide Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - float newValue = valueProvider.getAsDouble(); + float newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } float newValue = values[index]; if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - newValue = valueProvider.getAsDouble(); + newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; values[index] = newValue; } return newValue; } - @Override - public float computeFloatIfPresent(short key, ShortFloatUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - float newValue = mappingFunction.applyAsFloat(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public float computeFloatIfPresentNonDefault(short key, ShortFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2IntOpenCustomHashMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2IntOpenCustomHashMap.java index c3e795a4..6f13f388 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2IntOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2IntOpenCustomHashMap.java @@ -463,30 +463,24 @@ public int computeInt(short key, ShortIntUnaryOperator mappingFunction) { } @Override - public int computeIntNonDefault(short key, ShortIntUnaryOperator mappingFunction) { + public int computeIntIfAbsent(short key, Short2IntFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + int newValue = mappingFunction.applyAsInt(key); insert(-index-1, key, newValue); return newValue; } - int newValue = mappingFunction.applyAsInt(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + int newValue = values[index]; return newValue; } - + @Override - public int computeIntIfAbsent(short key, Short2IntFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public int supplyIntIfAbsent(short key, IntSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = valueProvider.getAsInt(); insert(-index-1, key, newValue); return newValue; } @@ -495,34 +489,50 @@ public int computeIntIfAbsent(short key, Short2IntFunction mappingFunction) { } @Override - public int computeIntIfAbsentNonDefault(short key, Short2IntFunction mappingFunction) { + public int computeIntIfPresent(short key, ShortIntUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + int newValue = mappingFunction.applyAsInt(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public int computeIntNonDefault(short key, ShortIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - int newValue = values[index]; + int newValue = mappingFunction.applyAsInt(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsInt(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public int supplyIntIfAbsent(short key, IntSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public int computeIntIfAbsentNonDefault(short key, Short2IntFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - int newValue = valueProvider.getAsInt(); + int newValue = mappingFunction.applyAsInt(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } int newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsInt(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -545,16 +555,6 @@ public int supplyIntIfAbsentNonDefault(short key, IntSupplier valueProvider) { return newValue; } - @Override - public int computeIntIfPresent(short key, ShortIntUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - int newValue = mappingFunction.applyAsInt(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public int computeIntIfPresentNonDefault(short key, ShortIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2LongOpenCustomHashMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2LongOpenCustomHashMap.java index 4aa62b30..8bc0edd1 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2LongOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2LongOpenCustomHashMap.java @@ -463,30 +463,24 @@ public long computeLong(short key, ShortLongUnaryOperator mappingFunction) { } @Override - public long computeLongNonDefault(short key, ShortLongUnaryOperator mappingFunction) { + public long computeLongIfAbsent(short key, Short2LongFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + long newValue = mappingFunction.applyAsLong(key); insert(-index-1, key, newValue); return newValue; } - long newValue = mappingFunction.applyAsLong(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + long newValue = values[index]; return newValue; } - + @Override - public long computeLongIfAbsent(short key, Short2LongFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public long supplyLongIfAbsent(short key, LongSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = valueProvider.getAsLong(); insert(-index-1, key, newValue); return newValue; } @@ -495,34 +489,50 @@ public long computeLongIfAbsent(short key, Short2LongFunction mappingFunction) { } @Override - public long computeLongIfAbsentNonDefault(short key, Short2LongFunction mappingFunction) { + public long computeLongIfPresent(short key, ShortLongUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + long newValue = mappingFunction.applyAsLong(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public long computeLongNonDefault(short key, ShortLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - long newValue = values[index]; + long newValue = mappingFunction.applyAsLong(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsLong(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public long supplyLongIfAbsent(short key, LongSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public long computeLongIfAbsentNonDefault(short key, Short2LongFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - long newValue = valueProvider.getAsLong(); + long newValue = mappingFunction.applyAsLong(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } long newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsLong(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -545,16 +555,6 @@ public long supplyLongIfAbsentNonDefault(short key, LongSupplier valueProvider) return newValue; } - @Override - public long computeLongIfPresent(short key, ShortLongUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - long newValue = mappingFunction.applyAsLong(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public long computeLongIfPresentNonDefault(short key, ShortLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2ObjectOpenCustomHashMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2ObjectOpenCustomHashMap.java index 82d52565..98e7a19a 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2ObjectOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2ObjectOpenCustomHashMap.java @@ -432,25 +432,6 @@ public V compute(short key, ShortObjectUnaryOperator mappingFunction) { return newValue; } - @Override - public V computeNonDefault(short key, ShortObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) { - V newValue = mappingFunction.apply(key, getDefaultReturnValue()); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = mappingFunction.apply(key, values[index]); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; - return newValue; - } - @Override public V computeIfAbsent(short key, ShortFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -469,26 +450,7 @@ public V computeIfAbsent(short key, ShortFunction mappingFunction) { } return newValue; } - - @Override - public V computeIfAbsentNonDefault(short key, ShortFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) { - V newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = values[index]; - if(Objects.equals(newValue, getDefaultReturnValue())) { - newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - values[index] = newValue; - } - return newValue; - } - + @Override public V supplyIfAbsent(short key, ObjectSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -508,25 +470,6 @@ public V supplyIfAbsent(short key, ObjectSupplier valueProvider) { return newValue; } - @Override - public V supplyIfAbsentNonDefault(short key, ObjectSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - int index = findIndex(key); - if(index < 0) { - V newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = values[index]; - if(Objects.equals(newValue, getDefaultReturnValue())) { - newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - values[index] = newValue; - } - return newValue; - } - @Override public V computeIfPresent(short key, ShortObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -541,20 +484,6 @@ public V computeIfPresent(short key, ShortObjectUnaryOperator mappingFunction return newValue; } - @Override - public V computeIfPresentNonDefault(short key, ShortObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0 || Objects.equals(values[index], getDefaultReturnValue())) return getDefaultReturnValue(); - V newValue = mappingFunction.apply(key, values[index]); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; - return newValue; - } - @Override public V merge(short key, V value, ObjectObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2ShortOpenCustomHashMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2ShortOpenCustomHashMap.java index 51c79472..61bf567a 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2ShortOpenCustomHashMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/customHash/Short2ShortOpenCustomHashMap.java @@ -455,30 +455,24 @@ public short computeShort(short key, ShortShortUnaryOperator mappingFunction) { } @Override - public short computeShortNonDefault(short key, ShortShortUnaryOperator mappingFunction) { + public short computeShortIfAbsent(short key, ShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + short newValue = mappingFunction.applyAsShort(key); insert(-index-1, key, newValue); return newValue; } - short newValue = mappingFunction.applyAsShort(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + short newValue = values[index]; return newValue; } - + @Override - public short computeShortIfAbsent(short key, ShortUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); + public short supplyShortIfAbsent(short key, ShortSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = valueProvider.getAsShort(); insert(-index-1, key, newValue); return newValue; } @@ -487,34 +481,50 @@ public short computeShortIfAbsent(short key, ShortUnaryOperator mappingFunction) } @Override - public short computeShortIfAbsentNonDefault(short key, ShortUnaryOperator mappingFunction) { + public short computeShortIfPresent(short key, ShortShortUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + short newValue = mappingFunction.applyAsShort(key, values[index]); + values[index] = newValue; + return newValue; + } + + @Override + public short computeShortNonDefault(short key, ShortShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - short newValue = values[index]; + short newValue = mappingFunction.applyAsShort(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsShort(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public short supplyShortIfAbsent(short key, ShortSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public short computeShortIfAbsentNonDefault(short key, ShortUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - short newValue = valueProvider.getAsInt(); + short newValue = mappingFunction.applyAsShort(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } short newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsShort(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -523,30 +533,20 @@ public short supplyShortIfAbsentNonDefault(short key, ShortSupplier valueProvide Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - short newValue = valueProvider.getAsInt(); + short newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } short newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public short computeShortIfPresent(short key, ShortShortUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - short newValue = mappingFunction.applyAsShort(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public short computeShortIfPresentNonDefault(short key, ShortShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2BooleanOpenHashMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2BooleanOpenHashMap.java index 21f7cbd9..051f03fd 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2BooleanOpenHashMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2BooleanOpenHashMap.java @@ -408,68 +408,78 @@ public boolean computeBoolean(short key, ShortBooleanUnaryOperator mappingFuncti values[index] = newValue; return newValue; } - + @Override - public boolean computeBooleanNonDefault(short key, ShortBooleanUnaryOperator mappingFunction) { + public boolean computeBooleanIfAbsent(short key, ShortPredicate mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + boolean newValue = mappingFunction.test(key); insert(-index-1, key, newValue); return newValue; } - boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + boolean newValue = values[index]; return newValue; } @Override - public boolean computeBooleanIfAbsent(short key, ShortPredicate mappingFunction) { - Objects.requireNonNull(mappingFunction); + public boolean supplyBooleanIfAbsent(short key, BooleanSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - boolean newValue = mappingFunction.test(key); + boolean newValue = valueProvider.getAsBoolean(); insert(-index-1, key, newValue); return newValue; } boolean newValue = values[index]; return newValue; } + + @Override + public boolean computeBooleanIfPresent(short key, ShortBooleanUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public boolean computeBooleanIfAbsentNonDefault(short key, ShortPredicate mappingFunction) { + public boolean computeBooleanNonDefault(short key, ShortBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - boolean newValue = mappingFunction.test(key); + boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - boolean newValue = values[index]; + boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.test(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public boolean supplyBooleanIfAbsent(short key, BooleanSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public boolean computeBooleanIfAbsentNonDefault(short key, ShortPredicate mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - boolean newValue = valueProvider.getAsBoolean(); + boolean newValue = mappingFunction.test(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } boolean newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.test(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -492,16 +502,6 @@ public boolean supplyBooleanIfAbsentNonDefault(short key, BooleanSupplier valueP return newValue; } - @Override - public boolean computeBooleanIfPresent(short key, ShortBooleanUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public boolean computeBooleanIfPresentNonDefault(short key, ShortBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2ByteOpenHashMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2ByteOpenHashMap.java index 355734b4..9bc56e19 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2ByteOpenHashMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2ByteOpenHashMap.java @@ -430,68 +430,78 @@ public byte computeByte(short key, ShortByteUnaryOperator mappingFunction) { values[index] = newValue; return newValue; } - + @Override - public byte computeByteNonDefault(short key, ShortByteUnaryOperator mappingFunction) { + public byte computeByteIfAbsent(short key, Short2ByteFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + byte newValue = mappingFunction.applyAsByte(key); insert(-index-1, key, newValue); return newValue; } - byte newValue = mappingFunction.applyAsByte(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + byte newValue = values[index]; return newValue; } @Override - public byte computeByteIfAbsent(short key, Short2ByteFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public byte supplyByteIfAbsent(short key, ByteSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = valueProvider.getAsByte(); insert(-index-1, key, newValue); return newValue; } byte newValue = values[index]; return newValue; } + + @Override + public byte computeByteIfPresent(short key, ShortByteUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + byte newValue = mappingFunction.applyAsByte(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public byte computeByteIfAbsentNonDefault(short key, Short2ByteFunction mappingFunction) { + public byte computeByteNonDefault(short key, ShortByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - byte newValue = values[index]; + byte newValue = mappingFunction.applyAsByte(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsByte(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public byte supplyByteIfAbsent(short key, ByteSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public byte computeByteIfAbsentNonDefault(short key, Short2ByteFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - byte newValue = valueProvider.getAsInt(); + byte newValue = mappingFunction.applyAsByte(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } byte newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsByte(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -500,30 +510,20 @@ public byte supplyByteIfAbsentNonDefault(short key, ByteSupplier valueProvider) Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - byte newValue = valueProvider.getAsInt(); + byte newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } byte newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public byte computeByteIfPresent(short key, ShortByteUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - byte newValue = mappingFunction.applyAsByte(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public byte computeByteIfPresentNonDefault(short key, ShortByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2CharOpenHashMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2CharOpenHashMap.java index 3a441a79..589f37a2 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2CharOpenHashMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2CharOpenHashMap.java @@ -430,68 +430,78 @@ public char computeChar(short key, ShortCharUnaryOperator mappingFunction) { values[index] = newValue; return newValue; } - + @Override - public char computeCharNonDefault(short key, ShortCharUnaryOperator mappingFunction) { + public char computeCharIfAbsent(short key, Short2CharFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + char newValue = mappingFunction.applyAsChar(key); insert(-index-1, key, newValue); return newValue; } - char newValue = mappingFunction.applyAsChar(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + char newValue = values[index]; return newValue; } @Override - public char computeCharIfAbsent(short key, Short2CharFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public char supplyCharIfAbsent(short key, CharSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = valueProvider.getAsChar(); insert(-index-1, key, newValue); return newValue; } char newValue = values[index]; return newValue; } + + @Override + public char computeCharIfPresent(short key, ShortCharUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + char newValue = mappingFunction.applyAsChar(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public char computeCharIfAbsentNonDefault(short key, Short2CharFunction mappingFunction) { + public char computeCharNonDefault(short key, ShortCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - char newValue = values[index]; + char newValue = mappingFunction.applyAsChar(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsChar(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public char supplyCharIfAbsent(short key, CharSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public char computeCharIfAbsentNonDefault(short key, Short2CharFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - char newValue = valueProvider.getAsInt(); + char newValue = mappingFunction.applyAsChar(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } char newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsChar(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -500,30 +510,20 @@ public char supplyCharIfAbsentNonDefault(short key, CharSupplier valueProvider) Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - char newValue = valueProvider.getAsInt(); + char newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } char newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public char computeCharIfPresent(short key, ShortCharUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - char newValue = mappingFunction.applyAsChar(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public char computeCharIfPresentNonDefault(short key, ShortCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2DoubleOpenHashMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2DoubleOpenHashMap.java index 6b32399e..88ad5da9 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2DoubleOpenHashMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2DoubleOpenHashMap.java @@ -430,68 +430,78 @@ public double computeDouble(short key, ShortDoubleUnaryOperator mappingFunction) values[index] = newValue; return newValue; } - + @Override - public double computeDoubleNonDefault(short key, ShortDoubleUnaryOperator mappingFunction) { + public double computeDoubleIfAbsent(short key, Short2DoubleFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + double newValue = mappingFunction.applyAsDouble(key); insert(-index-1, key, newValue); return newValue; } - double newValue = mappingFunction.applyAsDouble(key, values[index]); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + double newValue = values[index]; return newValue; } @Override - public double computeDoubleIfAbsent(short key, Short2DoubleFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public double supplyDoubleIfAbsent(short key, DoubleSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = valueProvider.getAsDouble(); insert(-index-1, key, newValue); return newValue; } double newValue = values[index]; return newValue; } + + @Override + public double computeDoubleIfPresent(short key, ShortDoubleUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + double newValue = mappingFunction.applyAsDouble(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public double computeDoubleIfAbsentNonDefault(short key, Short2DoubleFunction mappingFunction) { + public double computeDoubleNonDefault(short key, ShortDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } - double newValue = values[index]; + double newValue = mappingFunction.applyAsDouble(key, values[index]); if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - newValue = mappingFunction.applyAsDouble(key); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public double supplyDoubleIfAbsent(short key, DoubleSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public double computeDoubleIfAbsentNonDefault(short key, Short2DoubleFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - double newValue = valueProvider.getAsDouble(); + double newValue = mappingFunction.applyAsDouble(key); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } double newValue = values[index]; + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { + newValue = mappingFunction.applyAsDouble(key); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + values[index] = newValue; + } return newValue; } @@ -514,16 +524,6 @@ public double supplyDoubleIfAbsentNonDefault(short key, DoubleSupplier valueProv return newValue; } - @Override - public double computeDoubleIfPresent(short key, ShortDoubleUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - double newValue = mappingFunction.applyAsDouble(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public double computeDoubleIfPresentNonDefault(short key, ShortDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2FloatOpenHashMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2FloatOpenHashMap.java index 70b0a737..3069940b 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2FloatOpenHashMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2FloatOpenHashMap.java @@ -430,68 +430,78 @@ public float computeFloat(short key, ShortFloatUnaryOperator mappingFunction) { values[index] = newValue; return newValue; } - + @Override - public float computeFloatNonDefault(short key, ShortFloatUnaryOperator mappingFunction) { + public float computeFloatIfAbsent(short key, Short2FloatFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + float newValue = mappingFunction.applyAsFloat(key); insert(-index-1, key, newValue); return newValue; } - float newValue = mappingFunction.applyAsFloat(key, values[index]); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + float newValue = values[index]; return newValue; } @Override - public float computeFloatIfAbsent(short key, Short2FloatFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public float supplyFloatIfAbsent(short key, FloatSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = valueProvider.getAsFloat(); insert(-index-1, key, newValue); return newValue; } float newValue = values[index]; return newValue; } + + @Override + public float computeFloatIfPresent(short key, ShortFloatUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + float newValue = mappingFunction.applyAsFloat(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public float computeFloatIfAbsentNonDefault(short key, Short2FloatFunction mappingFunction) { + public float computeFloatNonDefault(short key, ShortFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } - float newValue = values[index]; + float newValue = mappingFunction.applyAsFloat(key, values[index]); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - newValue = mappingFunction.applyAsFloat(key); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public float supplyFloatIfAbsent(short key, FloatSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public float computeFloatIfAbsentNonDefault(short key, Short2FloatFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - float newValue = valueProvider.getAsDouble(); + float newValue = mappingFunction.applyAsFloat(key); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } float newValue = values[index]; + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { + newValue = mappingFunction.applyAsFloat(key); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + values[index] = newValue; + } return newValue; } @@ -500,30 +510,20 @@ public float supplyFloatIfAbsentNonDefault(short key, FloatSupplier valueProvide Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - float newValue = valueProvider.getAsDouble(); + float newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insert(-index-1, key, newValue); return newValue; } float newValue = values[index]; if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - newValue = valueProvider.getAsDouble(); + newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; values[index] = newValue; } return newValue; } - @Override - public float computeFloatIfPresent(short key, ShortFloatUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - float newValue = mappingFunction.applyAsFloat(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public float computeFloatIfPresentNonDefault(short key, ShortFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2IntOpenHashMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2IntOpenHashMap.java index 7992d0b2..9a0012b0 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2IntOpenHashMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2IntOpenHashMap.java @@ -430,68 +430,78 @@ public int computeInt(short key, ShortIntUnaryOperator mappingFunction) { values[index] = newValue; return newValue; } - + @Override - public int computeIntNonDefault(short key, ShortIntUnaryOperator mappingFunction) { + public int computeIntIfAbsent(short key, Short2IntFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + int newValue = mappingFunction.applyAsInt(key); insert(-index-1, key, newValue); return newValue; } - int newValue = mappingFunction.applyAsInt(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + int newValue = values[index]; return newValue; } @Override - public int computeIntIfAbsent(short key, Short2IntFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public int supplyIntIfAbsent(short key, IntSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = valueProvider.getAsInt(); insert(-index-1, key, newValue); return newValue; } int newValue = values[index]; return newValue; } + + @Override + public int computeIntIfPresent(short key, ShortIntUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + int newValue = mappingFunction.applyAsInt(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public int computeIntIfAbsentNonDefault(short key, Short2IntFunction mappingFunction) { + public int computeIntNonDefault(short key, ShortIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - int newValue = values[index]; + int newValue = mappingFunction.applyAsInt(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsInt(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public int supplyIntIfAbsent(short key, IntSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public int computeIntIfAbsentNonDefault(short key, Short2IntFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - int newValue = valueProvider.getAsInt(); + int newValue = mappingFunction.applyAsInt(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } int newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsInt(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -514,16 +524,6 @@ public int supplyIntIfAbsentNonDefault(short key, IntSupplier valueProvider) { return newValue; } - @Override - public int computeIntIfPresent(short key, ShortIntUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - int newValue = mappingFunction.applyAsInt(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public int computeIntIfPresentNonDefault(short key, ShortIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2LongOpenHashMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2LongOpenHashMap.java index e5215f86..26037321 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2LongOpenHashMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2LongOpenHashMap.java @@ -430,68 +430,78 @@ public long computeLong(short key, ShortLongUnaryOperator mappingFunction) { values[index] = newValue; return newValue; } - + @Override - public long computeLongNonDefault(short key, ShortLongUnaryOperator mappingFunction) { + public long computeLongIfAbsent(short key, Short2LongFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + long newValue = mappingFunction.applyAsLong(key); insert(-index-1, key, newValue); return newValue; } - long newValue = mappingFunction.applyAsLong(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + long newValue = values[index]; return newValue; } @Override - public long computeLongIfAbsent(short key, Short2LongFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public long supplyLongIfAbsent(short key, LongSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = valueProvider.getAsLong(); insert(-index-1, key, newValue); return newValue; } long newValue = values[index]; return newValue; } + + @Override + public long computeLongIfPresent(short key, ShortLongUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + long newValue = mappingFunction.applyAsLong(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public long computeLongIfAbsentNonDefault(short key, Short2LongFunction mappingFunction) { + public long computeLongNonDefault(short key, ShortLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - long newValue = values[index]; + long newValue = mappingFunction.applyAsLong(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsLong(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public long supplyLongIfAbsent(short key, LongSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public long computeLongIfAbsentNonDefault(short key, Short2LongFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - long newValue = valueProvider.getAsLong(); + long newValue = mappingFunction.applyAsLong(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } long newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsLong(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -514,16 +524,6 @@ public long supplyLongIfAbsentNonDefault(short key, LongSupplier valueProvider) return newValue; } - @Override - public long computeLongIfPresent(short key, ShortLongUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - long newValue = mappingFunction.applyAsLong(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public long computeLongIfPresentNonDefault(short key, ShortLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2ObjectOpenHashMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2ObjectOpenHashMap.java index c6a0867e..86d1a5b4 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2ObjectOpenHashMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2ObjectOpenHashMap.java @@ -401,26 +401,7 @@ public V compute(short key, ShortObjectUnaryOperator mappingFunction) { values[index] = newValue; return newValue; } - - @Override - public V computeNonDefault(short key, ShortObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) { - V newValue = mappingFunction.apply(key, getDefaultReturnValue()); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = mappingFunction.apply(key, values[index]); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; - return newValue; - } - + @Override public V computeIfAbsent(short key, ShortFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -440,25 +421,6 @@ public V computeIfAbsent(short key, ShortFunction mappingFunction) { return newValue; } - @Override - public V computeIfAbsentNonDefault(short key, ShortFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) { - V newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = values[index]; - if(Objects.equals(newValue, getDefaultReturnValue())) { - newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - values[index] = newValue; - } - return newValue; - } - @Override public V supplyIfAbsent(short key, ObjectSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -477,26 +439,7 @@ public V supplyIfAbsent(short key, ObjectSupplier valueProvider) { } return newValue; } - - @Override - public V supplyIfAbsentNonDefault(short key, ObjectSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - int index = findIndex(key); - if(index < 0) { - V newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insert(-index-1, key, newValue); - return newValue; - } - V newValue = values[index]; - if(Objects.equals(newValue, getDefaultReturnValue())) { - newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - values[index] = newValue; - } - return newValue; - } - + @Override public V computeIfPresent(short key, ShortObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -511,20 +454,6 @@ public V computeIfPresent(short key, ShortObjectUnaryOperator mappingFunction return newValue; } - @Override - public V computeIfPresentNonDefault(short key, ShortObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0 || Objects.equals(values[index], getDefaultReturnValue())) return getDefaultReturnValue(); - V newValue = mappingFunction.apply(key, values[index]); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; - return newValue; - } - @Override public V merge(short key, V value, ObjectObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2ShortOpenHashMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2ShortOpenHashMap.java index 404d15a4..5c532aa0 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2ShortOpenHashMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/hash/Short2ShortOpenHashMap.java @@ -424,68 +424,78 @@ public short computeShort(short key, ShortShortUnaryOperator mappingFunction) { values[index] = newValue; return newValue; } - + @Override - public short computeShortNonDefault(short key, ShortShortUnaryOperator mappingFunction) { + public short computeShortIfAbsent(short key, ShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + short newValue = mappingFunction.applyAsShort(key); insert(-index-1, key, newValue); return newValue; } - short newValue = mappingFunction.applyAsShort(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + short newValue = values[index]; return newValue; } @Override - public short computeShortIfAbsent(short key, ShortUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); + public short supplyShortIfAbsent(short key, ShortSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = valueProvider.getAsShort(); insert(-index-1, key, newValue); return newValue; } short newValue = values[index]; return newValue; } + + @Override + public short computeShortIfPresent(short key, ShortShortUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index < 0) return getDefaultReturnValue(); + short newValue = mappingFunction.applyAsShort(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public short computeShortIfAbsentNonDefault(short key, ShortUnaryOperator mappingFunction) { + public short computeShortNonDefault(short key, ShortShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } - short newValue = values[index]; + short newValue = mappingFunction.applyAsShort(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsShort(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public short supplyShortIfAbsent(short key, ShortSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public short computeShortIfAbsentNonDefault(short key, ShortUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index < 0) { - short newValue = valueProvider.getAsInt(); + short newValue = mappingFunction.applyAsShort(key); + if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } short newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsShort(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -494,30 +504,20 @@ public short supplyShortIfAbsentNonDefault(short key, ShortSupplier valueProvide Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index < 0) { - short newValue = valueProvider.getAsInt(); + short newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; insert(-index-1, key, newValue); return newValue; } short newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public short computeShortIfPresent(short key, ShortShortUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index < 0) return getDefaultReturnValue(); - short newValue = mappingFunction.applyAsShort(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public short computeShortIfPresentNonDefault(short key, ShortShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/immutable/ImmutableShort2BooleanOpenHashMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/immutable/ImmutableShort2BooleanOpenHashMap.java index 27a491fb..115d75e9 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/immutable/ImmutableShort2BooleanOpenHashMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/immutable/ImmutableShort2BooleanOpenHashMap.java @@ -413,20 +413,19 @@ public void forEach(ShortBooleanConsumer action) { @Override public boolean computeBoolean(short key, ShortBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanNonDefault(short key, ShortBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean computeBooleanIfAbsent(short key, ShortPredicate mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanIfAbsentNonDefault(short key, ShortPredicate mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean supplyBooleanIfAbsent(short key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public boolean supplyBooleanIfAbsentNonDefault(short key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public boolean computeBooleanIfPresent(short key, ShortBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override + public boolean computeBooleanNonDefault(short key, ShortBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public boolean computeBooleanIfAbsentNonDefault(short key, ShortPredicate mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public boolean supplyBooleanIfAbsentNonDefault(short key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } + @Override public boolean computeBooleanIfPresentNonDefault(short key, ShortBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean mergeBoolean(short key, boolean value, BooleanBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/immutable/ImmutableShort2ByteOpenHashMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/immutable/ImmutableShort2ByteOpenHashMap.java index 84df5451..537470e5 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/immutable/ImmutableShort2ByteOpenHashMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/immutable/ImmutableShort2ByteOpenHashMap.java @@ -418,20 +418,19 @@ public void forEach(ShortByteConsumer action) { @Override public byte computeByte(short key, ShortByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteNonDefault(short key, ShortByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte computeByteIfAbsent(short key, Short2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteIfAbsentNonDefault(short key, Short2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte supplyByteIfAbsent(short key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public byte supplyByteIfAbsentNonDefault(short key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public byte computeByteIfPresent(short key, ShortByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override + public byte computeByteNonDefault(short key, ShortByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public byte computeByteIfAbsentNonDefault(short key, Short2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public byte supplyByteIfAbsentNonDefault(short key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } + @Override public byte computeByteIfPresentNonDefault(short key, ShortByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte mergeByte(short key, byte value, ByteByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/immutable/ImmutableShort2CharOpenHashMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/immutable/ImmutableShort2CharOpenHashMap.java index fc4e192c..dadecbcb 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/immutable/ImmutableShort2CharOpenHashMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/immutable/ImmutableShort2CharOpenHashMap.java @@ -418,20 +418,19 @@ public void forEach(ShortCharConsumer action) { @Override public char computeChar(short key, ShortCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharNonDefault(short key, ShortCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char computeCharIfAbsent(short key, Short2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharIfAbsentNonDefault(short key, Short2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char supplyCharIfAbsent(short key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public char supplyCharIfAbsentNonDefault(short key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public char computeCharIfPresent(short key, ShortCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override + public char computeCharNonDefault(short key, ShortCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public char computeCharIfAbsentNonDefault(short key, Short2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public char supplyCharIfAbsentNonDefault(short key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } + @Override public char computeCharIfPresentNonDefault(short key, ShortCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char mergeChar(short key, char value, CharCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/immutable/ImmutableShort2DoubleOpenHashMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/immutable/ImmutableShort2DoubleOpenHashMap.java index 412523a5..01c27cc6 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/immutable/ImmutableShort2DoubleOpenHashMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/immutable/ImmutableShort2DoubleOpenHashMap.java @@ -418,20 +418,19 @@ public void forEach(ShortDoubleConsumer action) { @Override public double computeDouble(short key, ShortDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleNonDefault(short key, ShortDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double computeDoubleIfAbsent(short key, Short2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleIfAbsentNonDefault(short key, Short2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double supplyDoubleIfAbsent(short key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public double supplyDoubleIfAbsentNonDefault(short key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public double computeDoubleIfPresent(short key, ShortDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override + public double computeDoubleNonDefault(short key, ShortDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public double computeDoubleIfAbsentNonDefault(short key, Short2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public double supplyDoubleIfAbsentNonDefault(short key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } + @Override public double computeDoubleIfPresentNonDefault(short key, ShortDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double mergeDouble(short key, double value, DoubleDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/immutable/ImmutableShort2FloatOpenHashMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/immutable/ImmutableShort2FloatOpenHashMap.java index 0f9f1f0f..787248ff 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/immutable/ImmutableShort2FloatOpenHashMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/immutable/ImmutableShort2FloatOpenHashMap.java @@ -418,20 +418,19 @@ public void forEach(ShortFloatConsumer action) { @Override public float computeFloat(short key, ShortFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatNonDefault(short key, ShortFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float computeFloatIfAbsent(short key, Short2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatIfAbsentNonDefault(short key, Short2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float supplyFloatIfAbsent(short key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public float supplyFloatIfAbsentNonDefault(short key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public float computeFloatIfPresent(short key, ShortFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override + public float computeFloatNonDefault(short key, ShortFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public float computeFloatIfAbsentNonDefault(short key, Short2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public float supplyFloatIfAbsentNonDefault(short key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } + @Override public float computeFloatIfPresentNonDefault(short key, ShortFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float mergeFloat(short key, float value, FloatFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/immutable/ImmutableShort2IntOpenHashMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/immutable/ImmutableShort2IntOpenHashMap.java index 8d96e77f..da1291cd 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/immutable/ImmutableShort2IntOpenHashMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/immutable/ImmutableShort2IntOpenHashMap.java @@ -418,20 +418,19 @@ public void forEach(ShortIntConsumer action) { @Override public int computeInt(short key, ShortIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntNonDefault(short key, ShortIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int computeIntIfAbsent(short key, Short2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntIfAbsentNonDefault(short key, Short2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int supplyIntIfAbsent(short key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public int supplyIntIfAbsentNonDefault(short key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public int computeIntIfPresent(short key, ShortIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override + public int computeIntNonDefault(short key, ShortIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public int computeIntIfAbsentNonDefault(short key, Short2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public int supplyIntIfAbsentNonDefault(short key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } + @Override public int computeIntIfPresentNonDefault(short key, ShortIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int mergeInt(short key, int value, IntIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/immutable/ImmutableShort2LongOpenHashMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/immutable/ImmutableShort2LongOpenHashMap.java index 1882b4b5..a176f39d 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/immutable/ImmutableShort2LongOpenHashMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/immutable/ImmutableShort2LongOpenHashMap.java @@ -418,20 +418,19 @@ public void forEach(ShortLongConsumer action) { @Override public long computeLong(short key, ShortLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongNonDefault(short key, ShortLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long computeLongIfAbsent(short key, Short2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongIfAbsentNonDefault(short key, Short2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long supplyLongIfAbsent(short key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public long supplyLongIfAbsentNonDefault(short key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public long computeLongIfPresent(short key, ShortLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override + public long computeLongNonDefault(short key, ShortLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public long computeLongIfAbsentNonDefault(short key, Short2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public long supplyLongIfAbsentNonDefault(short key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } + @Override public long computeLongIfPresentNonDefault(short key, ShortLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long mergeLong(short key, long value, LongLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/immutable/ImmutableShort2ObjectOpenHashMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/immutable/ImmutableShort2ObjectOpenHashMap.java index de0f3207..e4bd9b44 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/immutable/ImmutableShort2ObjectOpenHashMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/immutable/ImmutableShort2ObjectOpenHashMap.java @@ -397,20 +397,11 @@ public void forEach(ShortObjectConsumer action) { @Override public V compute(short key, ShortObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeNonDefault(short key, ShortObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V computeIfAbsent(short key, ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeIfAbsentNonDefault(short key, ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V supplyIfAbsent(short key, ObjectSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public V supplyIfAbsentNonDefault(short key, ObjectSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public V computeIfPresent(short key, ShortObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override - public V computeIfPresentNonDefault(short key, ShortObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V merge(short key, V value, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/immutable/ImmutableShort2ShortOpenHashMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/immutable/ImmutableShort2ShortOpenHashMap.java index 220c31de..9ed403e3 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/immutable/ImmutableShort2ShortOpenHashMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/immutable/ImmutableShort2ShortOpenHashMap.java @@ -409,20 +409,19 @@ public void forEach(ShortShortConsumer action) { @Override public short computeShort(short key, ShortShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortNonDefault(short key, ShortShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short computeShortIfAbsent(short key, ShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortIfAbsentNonDefault(short key, ShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short supplyShortIfAbsent(short key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public short supplyShortIfAbsentNonDefault(short key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public short computeShortIfPresent(short key, ShortShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override + public short computeShortNonDefault(short key, ShortShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public short computeShortIfAbsentNonDefault(short key, ShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public short supplyShortIfAbsentNonDefault(short key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } + @Override public short computeShortIfPresentNonDefault(short key, ShortShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short mergeShort(short key, short value, ShortShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/misc/Short2BooleanArrayMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/misc/Short2BooleanArrayMap.java index 61099e98..551da09e 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/misc/Short2BooleanArrayMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/misc/Short2BooleanArrayMap.java @@ -420,66 +420,76 @@ public boolean computeBoolean(short key, ShortBooleanUnaryOperator mappingFuncti } @Override - public boolean computeBooleanNonDefault(short key, ShortBooleanUnaryOperator mappingFunction) { + public boolean computeBooleanIfAbsent(short key, ShortPredicate mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + boolean newValue = mappingFunction.test(key); insertIndex(size++, key, newValue); return newValue; } - boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + boolean newValue = values[index]; return newValue; } - + @Override - public boolean computeBooleanIfAbsent(short key, ShortPredicate mappingFunction) { - Objects.requireNonNull(mappingFunction); + public boolean supplyBooleanIfAbsent(short key, BooleanSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - boolean newValue = mappingFunction.test(key); + boolean newValue = valueProvider.getAsBoolean(); insertIndex(size++, key, newValue); return newValue; } boolean newValue = values[index]; return newValue; } + + @Override + public boolean computeBooleanIfPresent(short key, ShortBooleanUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index == -1) return getDefaultReturnValue(); + boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public boolean computeBooleanIfAbsentNonDefault(short key, ShortPredicate mappingFunction) { + public boolean computeBooleanNonDefault(short key, ShortBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - boolean newValue = mappingFunction.test(key); + boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } - boolean newValue = values[index]; + boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.test(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public boolean supplyBooleanIfAbsent(short key, BooleanSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public boolean computeBooleanIfAbsentNonDefault(short key, ShortPredicate mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - boolean newValue = valueProvider.getAsBoolean(); + boolean newValue = mappingFunction.test(key); + if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } boolean newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.test(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -502,16 +512,6 @@ public boolean supplyBooleanIfAbsentNonDefault(short key, BooleanSupplier valueP return newValue; } - @Override - public boolean computeBooleanIfPresent(short key, ShortBooleanUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) return getDefaultReturnValue(); - boolean newValue = mappingFunction.applyAsBoolean(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public boolean computeBooleanIfPresentNonDefault(short key, ShortBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/misc/Short2ByteArrayMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/misc/Short2ByteArrayMap.java index 1e9c5f45..a88c3068 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/misc/Short2ByteArrayMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/misc/Short2ByteArrayMap.java @@ -443,66 +443,76 @@ public byte computeByte(short key, ShortByteUnaryOperator mappingFunction) { } @Override - public byte computeByteNonDefault(short key, ShortByteUnaryOperator mappingFunction) { + public byte computeByteIfAbsent(short key, Short2ByteFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + byte newValue = mappingFunction.applyAsByte(key); insertIndex(size++, key, newValue); return newValue; } - byte newValue = mappingFunction.applyAsByte(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + byte newValue = values[index]; return newValue; } - + @Override - public byte computeByteIfAbsent(short key, Short2ByteFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public byte supplyByteIfAbsent(short key, ByteSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = valueProvider.getAsByte(); insertIndex(size++, key, newValue); return newValue; } byte newValue = values[index]; return newValue; } + + @Override + public byte computeByteIfPresent(short key, ShortByteUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index == -1) return getDefaultReturnValue(); + byte newValue = mappingFunction.applyAsByte(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public byte computeByteIfAbsentNonDefault(short key, Short2ByteFunction mappingFunction) { + public byte computeByteNonDefault(short key, ShortByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } - byte newValue = values[index]; + byte newValue = mappingFunction.applyAsByte(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsByte(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public byte supplyByteIfAbsent(short key, ByteSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public byte computeByteIfAbsentNonDefault(short key, Short2ByteFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - byte newValue = valueProvider.getAsInt(); + byte newValue = mappingFunction.applyAsByte(key); + if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } byte newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsByte(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -511,30 +521,20 @@ public byte supplyByteIfAbsentNonDefault(short key, ByteSupplier valueProvider) Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - byte newValue = valueProvider.getAsInt(); + byte newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } byte newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public byte computeByteIfPresent(short key, ShortByteUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) return getDefaultReturnValue(); - byte newValue = mappingFunction.applyAsByte(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public byte computeByteIfPresentNonDefault(short key, ShortByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/misc/Short2CharArrayMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/misc/Short2CharArrayMap.java index 2086fa6e..e97000d5 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/misc/Short2CharArrayMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/misc/Short2CharArrayMap.java @@ -443,66 +443,76 @@ public char computeChar(short key, ShortCharUnaryOperator mappingFunction) { } @Override - public char computeCharNonDefault(short key, ShortCharUnaryOperator mappingFunction) { + public char computeCharIfAbsent(short key, Short2CharFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + char newValue = mappingFunction.applyAsChar(key); insertIndex(size++, key, newValue); return newValue; } - char newValue = mappingFunction.applyAsChar(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + char newValue = values[index]; return newValue; } - + @Override - public char computeCharIfAbsent(short key, Short2CharFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public char supplyCharIfAbsent(short key, CharSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = valueProvider.getAsChar(); insertIndex(size++, key, newValue); return newValue; } char newValue = values[index]; return newValue; } + + @Override + public char computeCharIfPresent(short key, ShortCharUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index == -1) return getDefaultReturnValue(); + char newValue = mappingFunction.applyAsChar(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public char computeCharIfAbsentNonDefault(short key, Short2CharFunction mappingFunction) { + public char computeCharNonDefault(short key, ShortCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } - char newValue = values[index]; + char newValue = mappingFunction.applyAsChar(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsChar(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public char supplyCharIfAbsent(short key, CharSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public char computeCharIfAbsentNonDefault(short key, Short2CharFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - char newValue = valueProvider.getAsInt(); + char newValue = mappingFunction.applyAsChar(key); + if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } char newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsChar(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -511,30 +521,20 @@ public char supplyCharIfAbsentNonDefault(short key, CharSupplier valueProvider) Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - char newValue = valueProvider.getAsInt(); + char newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } char newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public char computeCharIfPresent(short key, ShortCharUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) return getDefaultReturnValue(); - char newValue = mappingFunction.applyAsChar(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public char computeCharIfPresentNonDefault(short key, ShortCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/misc/Short2DoubleArrayMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/misc/Short2DoubleArrayMap.java index 870ec5bb..a59d79ac 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/misc/Short2DoubleArrayMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/misc/Short2DoubleArrayMap.java @@ -443,66 +443,76 @@ public double computeDouble(short key, ShortDoubleUnaryOperator mappingFunction) } @Override - public double computeDoubleNonDefault(short key, ShortDoubleUnaryOperator mappingFunction) { + public double computeDoubleIfAbsent(short key, Short2DoubleFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + double newValue = mappingFunction.applyAsDouble(key); insertIndex(size++, key, newValue); return newValue; } - double newValue = mappingFunction.applyAsDouble(key, values[index]); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + double newValue = values[index]; return newValue; } - + @Override - public double computeDoubleIfAbsent(short key, Short2DoubleFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public double supplyDoubleIfAbsent(short key, DoubleSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = valueProvider.getAsDouble(); insertIndex(size++, key, newValue); return newValue; } double newValue = values[index]; return newValue; } + + @Override + public double computeDoubleIfPresent(short key, ShortDoubleUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index == -1) return getDefaultReturnValue(); + double newValue = mappingFunction.applyAsDouble(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public double computeDoubleIfAbsentNonDefault(short key, Short2DoubleFunction mappingFunction) { + public double computeDoubleNonDefault(short key, ShortDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; insertIndex(size++, key, newValue); return newValue; } - double newValue = values[index]; + double newValue = mappingFunction.applyAsDouble(key, values[index]); if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - newValue = mappingFunction.applyAsDouble(key); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public double supplyDoubleIfAbsent(short key, DoubleSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public double computeDoubleIfAbsentNonDefault(short key, Short2DoubleFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - double newValue = valueProvider.getAsDouble(); + double newValue = mappingFunction.applyAsDouble(key); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; insertIndex(size++, key, newValue); return newValue; } double newValue = values[index]; + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { + newValue = mappingFunction.applyAsDouble(key); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + values[index] = newValue; + } return newValue; } @@ -525,16 +535,6 @@ public double supplyDoubleIfAbsentNonDefault(short key, DoubleSupplier valueProv return newValue; } - @Override - public double computeDoubleIfPresent(short key, ShortDoubleUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) return getDefaultReturnValue(); - double newValue = mappingFunction.applyAsDouble(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public double computeDoubleIfPresentNonDefault(short key, ShortDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/misc/Short2FloatArrayMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/misc/Short2FloatArrayMap.java index 7e641913..c5a7b000 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/misc/Short2FloatArrayMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/misc/Short2FloatArrayMap.java @@ -443,66 +443,76 @@ public float computeFloat(short key, ShortFloatUnaryOperator mappingFunction) { } @Override - public float computeFloatNonDefault(short key, ShortFloatUnaryOperator mappingFunction) { + public float computeFloatIfAbsent(short key, Short2FloatFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + float newValue = mappingFunction.applyAsFloat(key); insertIndex(size++, key, newValue); return newValue; } - float newValue = mappingFunction.applyAsFloat(key, values[index]); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + float newValue = values[index]; return newValue; } - + @Override - public float computeFloatIfAbsent(short key, Short2FloatFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public float supplyFloatIfAbsent(short key, FloatSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = valueProvider.getAsFloat(); insertIndex(size++, key, newValue); return newValue; } float newValue = values[index]; return newValue; } + + @Override + public float computeFloatIfPresent(short key, ShortFloatUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index == -1) return getDefaultReturnValue(); + float newValue = mappingFunction.applyAsFloat(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public float computeFloatIfAbsentNonDefault(short key, Short2FloatFunction mappingFunction) { + public float computeFloatNonDefault(short key, ShortFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insertIndex(size++, key, newValue); return newValue; } - float newValue = values[index]; + float newValue = mappingFunction.applyAsFloat(key, values[index]); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - newValue = mappingFunction.applyAsFloat(key); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public float supplyFloatIfAbsent(short key, FloatSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public float computeFloatIfAbsentNonDefault(short key, Short2FloatFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - float newValue = valueProvider.getAsDouble(); + float newValue = mappingFunction.applyAsFloat(key); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insertIndex(size++, key, newValue); return newValue; } float newValue = values[index]; + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { + newValue = mappingFunction.applyAsFloat(key); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + values[index] = newValue; + } return newValue; } @@ -511,30 +521,20 @@ public float supplyFloatIfAbsentNonDefault(short key, FloatSupplier valueProvide Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - float newValue = valueProvider.getAsDouble(); + float newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; insertIndex(size++, key, newValue); return newValue; } float newValue = values[index]; if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - newValue = valueProvider.getAsDouble(); + newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; values[index] = newValue; } return newValue; } - @Override - public float computeFloatIfPresent(short key, ShortFloatUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) return getDefaultReturnValue(); - float newValue = mappingFunction.applyAsFloat(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public float computeFloatIfPresentNonDefault(short key, ShortFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/misc/Short2IntArrayMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/misc/Short2IntArrayMap.java index 50f2d077..5845690f 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/misc/Short2IntArrayMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/misc/Short2IntArrayMap.java @@ -443,66 +443,76 @@ public int computeInt(short key, ShortIntUnaryOperator mappingFunction) { } @Override - public int computeIntNonDefault(short key, ShortIntUnaryOperator mappingFunction) { + public int computeIntIfAbsent(short key, Short2IntFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + int newValue = mappingFunction.applyAsInt(key); insertIndex(size++, key, newValue); return newValue; } - int newValue = mappingFunction.applyAsInt(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + int newValue = values[index]; return newValue; } - + @Override - public int computeIntIfAbsent(short key, Short2IntFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public int supplyIntIfAbsent(short key, IntSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = valueProvider.getAsInt(); insertIndex(size++, key, newValue); return newValue; } int newValue = values[index]; return newValue; } + + @Override + public int computeIntIfPresent(short key, ShortIntUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index == -1) return getDefaultReturnValue(); + int newValue = mappingFunction.applyAsInt(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public int computeIntIfAbsentNonDefault(short key, Short2IntFunction mappingFunction) { + public int computeIntNonDefault(short key, ShortIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } - int newValue = values[index]; + int newValue = mappingFunction.applyAsInt(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsInt(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public int supplyIntIfAbsent(short key, IntSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public int computeIntIfAbsentNonDefault(short key, Short2IntFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - int newValue = valueProvider.getAsInt(); + int newValue = mappingFunction.applyAsInt(key); + if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } int newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsInt(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -525,16 +535,6 @@ public int supplyIntIfAbsentNonDefault(short key, IntSupplier valueProvider) { return newValue; } - @Override - public int computeIntIfPresent(short key, ShortIntUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) return getDefaultReturnValue(); - int newValue = mappingFunction.applyAsInt(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public int computeIntIfPresentNonDefault(short key, ShortIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/misc/Short2LongArrayMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/misc/Short2LongArrayMap.java index 0443cd9b..7080b30b 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/misc/Short2LongArrayMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/misc/Short2LongArrayMap.java @@ -443,66 +443,76 @@ public long computeLong(short key, ShortLongUnaryOperator mappingFunction) { } @Override - public long computeLongNonDefault(short key, ShortLongUnaryOperator mappingFunction) { + public long computeLongIfAbsent(short key, Short2LongFunction mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + long newValue = mappingFunction.applyAsLong(key); insertIndex(size++, key, newValue); return newValue; } - long newValue = mappingFunction.applyAsLong(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + long newValue = values[index]; return newValue; } - + @Override - public long computeLongIfAbsent(short key, Short2LongFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); + public long supplyLongIfAbsent(short key, LongSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = valueProvider.getAsLong(); insertIndex(size++, key, newValue); return newValue; } long newValue = values[index]; return newValue; } + + @Override + public long computeLongIfPresent(short key, ShortLongUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index == -1) return getDefaultReturnValue(); + long newValue = mappingFunction.applyAsLong(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public long computeLongIfAbsentNonDefault(short key, Short2LongFunction mappingFunction) { + public long computeLongNonDefault(short key, ShortLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } - long newValue = values[index]; + long newValue = mappingFunction.applyAsLong(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsLong(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public long supplyLongIfAbsent(short key, LongSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public long computeLongIfAbsentNonDefault(short key, Short2LongFunction mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - long newValue = valueProvider.getAsLong(); + long newValue = mappingFunction.applyAsLong(key); + if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } long newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsLong(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -525,16 +535,6 @@ public long supplyLongIfAbsentNonDefault(short key, LongSupplier valueProvider) return newValue; } - @Override - public long computeLongIfPresent(short key, ShortLongUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) return getDefaultReturnValue(); - long newValue = mappingFunction.applyAsLong(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public long computeLongIfPresentNonDefault(short key, ShortLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/misc/Short2ObjectArrayMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/misc/Short2ObjectArrayMap.java index c12d9e5e..be0d91a1 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/misc/Short2ObjectArrayMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/misc/Short2ObjectArrayMap.java @@ -415,25 +415,6 @@ public V compute(short key, ShortObjectUnaryOperator mappingFunction) { return newValue; } - @Override - public V computeNonDefault(short key, ShortObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) { - V newValue = mappingFunction.apply(key, getDefaultReturnValue()); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insertIndex(size++, key, newValue); - return newValue; - } - V newValue = mappingFunction.apply(key, values[index]); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; - return newValue; - } - @Override public V computeIfAbsent(short key, ShortFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -452,26 +433,7 @@ public V computeIfAbsent(short key, ShortFunction mappingFunction) { } return newValue; } - - @Override - public V computeIfAbsentNonDefault(short key, ShortFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) { - V newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insertIndex(size++, key, newValue); - return newValue; - } - V newValue = values[index]; - if(Objects.equals(newValue, getDefaultReturnValue())) { - newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - values[index] = newValue; - } - return newValue; - } - + @Override public V supplyIfAbsent(short key, ObjectSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -490,26 +452,7 @@ public V supplyIfAbsent(short key, ObjectSupplier valueProvider) { } return newValue; } - - @Override - public V supplyIfAbsentNonDefault(short key, ObjectSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - int index = findIndex(key); - if(index == -1) { - V newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - insertIndex(size++, key, newValue); - return newValue; - } - V newValue = values[index]; - if(Objects.equals(newValue, getDefaultReturnValue())) { - newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - values[index] = newValue; - } - return newValue; - } - + @Override public V computeIfPresent(short key, ShortObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -524,20 +467,6 @@ public V computeIfPresent(short key, ShortObjectUnaryOperator mappingFunction return newValue; } - @Override - public V computeIfPresentNonDefault(short key, ShortObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1 || Objects.equals(values[index], getDefaultReturnValue())) return getDefaultReturnValue(); - V newValue = mappingFunction.apply(key, values[index]); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeIndex(index); - return newValue; - } - values[index] = newValue; - return newValue; - } - @Override public V merge(short key, V value, ObjectObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/misc/Short2ShortArrayMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/misc/Short2ShortArrayMap.java index ba7ee6c9..b9b3bbf9 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/misc/Short2ShortArrayMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/misc/Short2ShortArrayMap.java @@ -436,66 +436,76 @@ public short computeShort(short key, ShortShortUnaryOperator mappingFunction) { } @Override - public short computeShortNonDefault(short key, ShortShortUnaryOperator mappingFunction) { + public short computeShortIfAbsent(short key, ShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + short newValue = mappingFunction.applyAsShort(key); insertIndex(size++, key, newValue); return newValue; } - short newValue = mappingFunction.applyAsShort(key, values[index]); - if(newValue == getDefaultReturnValue()) { - removeIndex(index); - return newValue; - } - values[index] = newValue; + short newValue = values[index]; return newValue; } - + @Override - public short computeShortIfAbsent(short key, ShortUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); + public short supplyShortIfAbsent(short key, ShortSupplier valueProvider) { + Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = valueProvider.getAsShort(); insertIndex(size++, key, newValue); return newValue; } short newValue = values[index]; return newValue; } + + @Override + public short computeShortIfPresent(short key, ShortShortUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + int index = findIndex(key); + if(index == -1) return getDefaultReturnValue(); + short newValue = mappingFunction.applyAsShort(key, values[index]); + values[index] = newValue; + return newValue; + } @Override - public short computeShortIfAbsentNonDefault(short key, ShortUnaryOperator mappingFunction) { + public short computeShortNonDefault(short key, ShortShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } - short newValue = values[index]; + short newValue = mappingFunction.applyAsShort(key, values[index]); if(newValue == getDefaultReturnValue()) { - newValue = mappingFunction.applyAsShort(key); - if(newValue == getDefaultReturnValue()) return newValue; - values[index] = newValue; + removeIndex(index); + return newValue; } + values[index] = newValue; return newValue; } @Override - public short supplyShortIfAbsent(short key, ShortSupplier valueProvider) { - Objects.requireNonNull(valueProvider); + public short computeShortIfAbsentNonDefault(short key, ShortUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); int index = findIndex(key); if(index == -1) { - short newValue = valueProvider.getAsInt(); + short newValue = mappingFunction.applyAsShort(key); + if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } short newValue = values[index]; + if(newValue == getDefaultReturnValue()) { + newValue = mappingFunction.applyAsShort(key); + if(newValue == getDefaultReturnValue()) return newValue; + values[index] = newValue; + } return newValue; } @@ -504,30 +514,20 @@ public short supplyShortIfAbsentNonDefault(short key, ShortSupplier valueProvide Objects.requireNonNull(valueProvider); int index = findIndex(key); if(index == -1) { - short newValue = valueProvider.getAsInt(); + short newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; insertIndex(size++, key, newValue); return newValue; } short newValue = values[index]; if(newValue == getDefaultReturnValue()) { - newValue = valueProvider.getAsInt(); + newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; values[index] = newValue; } return newValue; } - @Override - public short computeShortIfPresent(short key, ShortShortUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - int index = findIndex(key); - if(index == -1) return getDefaultReturnValue(); - short newValue = mappingFunction.applyAsShort(key, values[index]); - values[index] = newValue; - return newValue; - } - @Override public short computeShortIfPresentNonDefault(short key, ShortShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2BooleanAVLTreeMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2BooleanAVLTreeMap.java index 5f36bcb9..0d7a0fda 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2BooleanAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2BooleanAVLTreeMap.java @@ -396,34 +396,56 @@ public boolean computeBoolean(short key, ShortBooleanUnaryOperator mappingFuncti } @Override - public boolean computeBooleanNonDefault(short key, ShortBooleanUnaryOperator mappingFunction) { + public boolean computeBooleanIfAbsent(short key, ShortPredicate mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + boolean newValue = mappingFunction.test(key); put(key, newValue); return newValue; } - boolean newValue = mappingFunction.applyAsBoolean(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public boolean supplyBooleanIfAbsent(short key, BooleanSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + boolean newValue = valueProvider.getAsBoolean(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public boolean computeBooleanIfPresent(short key, ShortBooleanUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + boolean newValue = mappingFunction.applyAsBoolean(key, entry.value); entry.value = newValue; return newValue; } @Override - public boolean computeBooleanIfAbsent(short key, ShortPredicate mappingFunction) { + public boolean computeBooleanNonDefault(short key, ShortBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - boolean newValue = mappingFunction.test(key); + boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + boolean newValue = mappingFunction.applyAsBoolean(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -444,18 +466,6 @@ public boolean computeBooleanIfAbsentNonDefault(short key, ShortPredicate mappin return entry.value; } - @Override - public boolean supplyBooleanIfAbsent(short key, BooleanSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - boolean newValue = valueProvider.getAsBoolean(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public boolean supplyBooleanIfAbsentNonDefault(short key, BooleanSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -474,16 +484,6 @@ public boolean supplyBooleanIfAbsentNonDefault(short key, BooleanSupplier valueP return entry.value; } - @Override - public boolean computeBooleanIfPresent(short key, ShortBooleanUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - boolean newValue = mappingFunction.applyAsBoolean(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public boolean computeBooleanIfPresentNonDefault(short key, ShortBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1487,14 +1487,9 @@ public boolean computeBooleanIfPresent(short key, ShortBooleanUnaryOperator mapp Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - boolean newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2BooleanRBTreeMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2BooleanRBTreeMap.java index 3e6b60cc..14bdd497 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2BooleanRBTreeMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2BooleanRBTreeMap.java @@ -395,34 +395,56 @@ public boolean computeBoolean(short key, ShortBooleanUnaryOperator mappingFuncti } @Override - public boolean computeBooleanNonDefault(short key, ShortBooleanUnaryOperator mappingFunction) { + public boolean computeBooleanIfAbsent(short key, ShortPredicate mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + boolean newValue = mappingFunction.test(key); put(key, newValue); return newValue; } - boolean newValue = mappingFunction.applyAsBoolean(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public boolean supplyBooleanIfAbsent(short key, BooleanSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + boolean newValue = valueProvider.getAsBoolean(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public boolean computeBooleanIfPresent(short key, ShortBooleanUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + boolean newValue = mappingFunction.applyAsBoolean(key, entry.value); entry.value = newValue; return newValue; } @Override - public boolean computeBooleanIfAbsent(short key, ShortPredicate mappingFunction) { + public boolean computeBooleanNonDefault(short key, ShortBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - boolean newValue = mappingFunction.test(key); + boolean newValue = mappingFunction.applyAsBoolean(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + boolean newValue = mappingFunction.applyAsBoolean(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -443,18 +465,6 @@ public boolean computeBooleanIfAbsentNonDefault(short key, ShortPredicate mappin return entry.value; } - @Override - public boolean supplyBooleanIfAbsent(short key, BooleanSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - boolean newValue = valueProvider.getAsBoolean(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public boolean supplyBooleanIfAbsentNonDefault(short key, BooleanSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -473,16 +483,6 @@ public boolean supplyBooleanIfAbsentNonDefault(short key, BooleanSupplier valueP return entry.value; } - @Override - public boolean computeBooleanIfPresent(short key, ShortBooleanUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - boolean newValue = mappingFunction.applyAsBoolean(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public boolean computeBooleanIfPresentNonDefault(short key, ShortBooleanUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1550,14 +1550,9 @@ public boolean computeBooleanIfPresent(short key, ShortBooleanUnaryOperator mapp Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - boolean newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2ByteAVLTreeMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2ByteAVLTreeMap.java index 72dae5ef..64c54a38 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2ByteAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2ByteAVLTreeMap.java @@ -455,34 +455,56 @@ public byte computeByte(short key, ShortByteUnaryOperator mappingFunction) { } @Override - public byte computeByteNonDefault(short key, ShortByteUnaryOperator mappingFunction) { + public byte computeByteIfAbsent(short key, Short2ByteFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + byte newValue = mappingFunction.applyAsByte(key); put(key, newValue); return newValue; } - byte newValue = mappingFunction.applyAsByte(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public byte supplyByteIfAbsent(short key, ByteSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + byte newValue = valueProvider.getAsByte(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public byte computeByteIfPresent(short key, ShortByteUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + byte newValue = mappingFunction.applyAsByte(key, entry.value); entry.value = newValue; return newValue; } @Override - public byte computeByteIfAbsent(short key, Short2ByteFunction mappingFunction) { + public byte computeByteNonDefault(short key, ShortByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + byte newValue = mappingFunction.applyAsByte(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -503,46 +525,24 @@ public byte computeByteIfAbsentNonDefault(short key, Short2ByteFunction mappingF return entry.value; } - @Override - public byte supplyByteIfAbsent(short key, ByteSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - byte newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public byte supplyByteIfAbsentNonDefault(short key, ByteSupplier valueProvider) { Objects.requireNonNull(valueProvider); Node entry = findNode(key); if(entry == null) { - byte newValue = valueProvider.getAsInt(); + byte newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } if(entry.value == getDefaultReturnValue()) { - byte newValue = valueProvider.getAsInt(); + byte newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; entry.value = newValue; } return entry.value; } - @Override - public byte computeByteIfPresent(short key, ShortByteUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - byte newValue = mappingFunction.applyAsByte(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public byte computeByteIfPresentNonDefault(short key, ShortByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1558,14 +1558,9 @@ public byte computeByteIfPresent(short key, ShortByteUnaryOperator mappingFuncti Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - byte newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2ByteRBTreeMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2ByteRBTreeMap.java index 3d133a52..fbd6d938 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2ByteRBTreeMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2ByteRBTreeMap.java @@ -454,34 +454,56 @@ public byte computeByte(short key, ShortByteUnaryOperator mappingFunction) { } @Override - public byte computeByteNonDefault(short key, ShortByteUnaryOperator mappingFunction) { + public byte computeByteIfAbsent(short key, Short2ByteFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + byte newValue = mappingFunction.applyAsByte(key); put(key, newValue); return newValue; } - byte newValue = mappingFunction.applyAsByte(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public byte supplyByteIfAbsent(short key, ByteSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + byte newValue = valueProvider.getAsByte(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public byte computeByteIfPresent(short key, ShortByteUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + byte newValue = mappingFunction.applyAsByte(key, entry.value); entry.value = newValue; return newValue; } @Override - public byte computeByteIfAbsent(short key, Short2ByteFunction mappingFunction) { + public byte computeByteNonDefault(short key, ShortByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - byte newValue = mappingFunction.applyAsByte(key); + byte newValue = mappingFunction.applyAsByte(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + byte newValue = mappingFunction.applyAsByte(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -502,46 +524,24 @@ public byte computeByteIfAbsentNonDefault(short key, Short2ByteFunction mappingF return entry.value; } - @Override - public byte supplyByteIfAbsent(short key, ByteSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - byte newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public byte supplyByteIfAbsentNonDefault(short key, ByteSupplier valueProvider) { Objects.requireNonNull(valueProvider); Node entry = findNode(key); if(entry == null) { - byte newValue = valueProvider.getAsInt(); + byte newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } if(entry.value == getDefaultReturnValue()) { - byte newValue = valueProvider.getAsInt(); + byte newValue = valueProvider.getAsByte(); if(newValue == getDefaultReturnValue()) return newValue; entry.value = newValue; } return entry.value; } - @Override - public byte computeByteIfPresent(short key, ShortByteUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - byte newValue = mappingFunction.applyAsByte(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public byte computeByteIfPresentNonDefault(short key, ShortByteUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1621,14 +1621,9 @@ public byte computeByteIfPresent(short key, ShortByteUnaryOperator mappingFuncti Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - byte newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2CharAVLTreeMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2CharAVLTreeMap.java index b2535f50..b4e0b480 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2CharAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2CharAVLTreeMap.java @@ -455,34 +455,56 @@ public char computeChar(short key, ShortCharUnaryOperator mappingFunction) { } @Override - public char computeCharNonDefault(short key, ShortCharUnaryOperator mappingFunction) { + public char computeCharIfAbsent(short key, Short2CharFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + char newValue = mappingFunction.applyAsChar(key); put(key, newValue); return newValue; } - char newValue = mappingFunction.applyAsChar(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public char supplyCharIfAbsent(short key, CharSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + char newValue = valueProvider.getAsChar(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public char computeCharIfPresent(short key, ShortCharUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + char newValue = mappingFunction.applyAsChar(key, entry.value); entry.value = newValue; return newValue; } @Override - public char computeCharIfAbsent(short key, Short2CharFunction mappingFunction) { + public char computeCharNonDefault(short key, ShortCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + char newValue = mappingFunction.applyAsChar(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -503,46 +525,24 @@ public char computeCharIfAbsentNonDefault(short key, Short2CharFunction mappingF return entry.value; } - @Override - public char supplyCharIfAbsent(short key, CharSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - char newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public char supplyCharIfAbsentNonDefault(short key, CharSupplier valueProvider) { Objects.requireNonNull(valueProvider); Node entry = findNode(key); if(entry == null) { - char newValue = valueProvider.getAsInt(); + char newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } if(entry.value == getDefaultReturnValue()) { - char newValue = valueProvider.getAsInt(); + char newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; entry.value = newValue; } return entry.value; } - @Override - public char computeCharIfPresent(short key, ShortCharUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - char newValue = mappingFunction.applyAsChar(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public char computeCharIfPresentNonDefault(short key, ShortCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1558,14 +1558,9 @@ public char computeCharIfPresent(short key, ShortCharUnaryOperator mappingFuncti Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - char newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2CharRBTreeMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2CharRBTreeMap.java index f0b7d28d..fa5e1d80 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2CharRBTreeMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2CharRBTreeMap.java @@ -454,34 +454,56 @@ public char computeChar(short key, ShortCharUnaryOperator mappingFunction) { } @Override - public char computeCharNonDefault(short key, ShortCharUnaryOperator mappingFunction) { + public char computeCharIfAbsent(short key, Short2CharFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + char newValue = mappingFunction.applyAsChar(key); put(key, newValue); return newValue; } - char newValue = mappingFunction.applyAsChar(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public char supplyCharIfAbsent(short key, CharSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + char newValue = valueProvider.getAsChar(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public char computeCharIfPresent(short key, ShortCharUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + char newValue = mappingFunction.applyAsChar(key, entry.value); entry.value = newValue; return newValue; } @Override - public char computeCharIfAbsent(short key, Short2CharFunction mappingFunction) { + public char computeCharNonDefault(short key, ShortCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - char newValue = mappingFunction.applyAsChar(key); + char newValue = mappingFunction.applyAsChar(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + char newValue = mappingFunction.applyAsChar(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -502,46 +524,24 @@ public char computeCharIfAbsentNonDefault(short key, Short2CharFunction mappingF return entry.value; } - @Override - public char supplyCharIfAbsent(short key, CharSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - char newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public char supplyCharIfAbsentNonDefault(short key, CharSupplier valueProvider) { Objects.requireNonNull(valueProvider); Node entry = findNode(key); if(entry == null) { - char newValue = valueProvider.getAsInt(); + char newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } if(entry.value == getDefaultReturnValue()) { - char newValue = valueProvider.getAsInt(); + char newValue = valueProvider.getAsChar(); if(newValue == getDefaultReturnValue()) return newValue; entry.value = newValue; } return entry.value; } - @Override - public char computeCharIfPresent(short key, ShortCharUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - char newValue = mappingFunction.applyAsChar(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public char computeCharIfPresentNonDefault(short key, ShortCharUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1621,14 +1621,9 @@ public char computeCharIfPresent(short key, ShortCharUnaryOperator mappingFuncti Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - char newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2DoubleAVLTreeMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2DoubleAVLTreeMap.java index a064688e..cee365c0 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2DoubleAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2DoubleAVLTreeMap.java @@ -455,34 +455,56 @@ public double computeDouble(short key, ShortDoubleUnaryOperator mappingFunction) } @Override - public double computeDoubleNonDefault(short key, ShortDoubleUnaryOperator mappingFunction) { + public double computeDoubleIfAbsent(short key, Short2DoubleFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + double newValue = mappingFunction.applyAsDouble(key); put(key, newValue); return newValue; } - double newValue = mappingFunction.applyAsDouble(key, entry.value); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - removeNode(entry); + return entry.value; + } + + @Override + public double supplyDoubleIfAbsent(short key, DoubleSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + double newValue = valueProvider.getAsDouble(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public double computeDoubleIfPresent(short key, ShortDoubleUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + double newValue = mappingFunction.applyAsDouble(key, entry.value); entry.value = newValue; return newValue; } @Override - public double computeDoubleIfAbsent(short key, Short2DoubleFunction mappingFunction) { + public double computeDoubleNonDefault(short key, ShortDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; put(key, newValue); return newValue; } - return entry.value; + double newValue = mappingFunction.applyAsDouble(key, entry.value); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -503,18 +525,6 @@ public double computeDoubleIfAbsentNonDefault(short key, Short2DoubleFunction ma return entry.value; } - @Override - public double supplyDoubleIfAbsent(short key, DoubleSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - double newValue = valueProvider.getAsDouble(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public double supplyDoubleIfAbsentNonDefault(short key, DoubleSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -533,16 +543,6 @@ public double supplyDoubleIfAbsentNonDefault(short key, DoubleSupplier valueProv return entry.value; } - @Override - public double computeDoubleIfPresent(short key, ShortDoubleUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - double newValue = mappingFunction.applyAsDouble(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public double computeDoubleIfPresentNonDefault(short key, ShortDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1558,14 +1558,9 @@ public double computeDoubleIfPresent(short key, ShortDoubleUnaryOperator mapping Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || Double.doubleToLongBits(entry.value) == Double.doubleToLongBits(getDefaultReturnValue())) return getDefaultReturnValue(); - double newValue = mappingFunction.apply(key, entry.value); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2DoubleRBTreeMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2DoubleRBTreeMap.java index c93a483b..2ad3ac9a 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2DoubleRBTreeMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2DoubleRBTreeMap.java @@ -454,34 +454,56 @@ public double computeDouble(short key, ShortDoubleUnaryOperator mappingFunction) } @Override - public double computeDoubleNonDefault(short key, ShortDoubleUnaryOperator mappingFunction) { + public double computeDoubleIfAbsent(short key, Short2DoubleFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; + double newValue = mappingFunction.applyAsDouble(key); put(key, newValue); return newValue; } - double newValue = mappingFunction.applyAsDouble(key, entry.value); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - removeNode(entry); + return entry.value; + } + + @Override + public double supplyDoubleIfAbsent(short key, DoubleSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + double newValue = valueProvider.getAsDouble(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public double computeDoubleIfPresent(short key, ShortDoubleUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + double newValue = mappingFunction.applyAsDouble(key, entry.value); entry.value = newValue; return newValue; } @Override - public double computeDoubleIfAbsent(short key, Short2DoubleFunction mappingFunction) { + public double computeDoubleNonDefault(short key, ShortDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - double newValue = mappingFunction.applyAsDouble(key); + double newValue = mappingFunction.applyAsDouble(key, getDefaultReturnValue()); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) return newValue; put(key, newValue); return newValue; } - return entry.value; + double newValue = mappingFunction.applyAsDouble(key, entry.value); + if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -502,18 +524,6 @@ public double computeDoubleIfAbsentNonDefault(short key, Short2DoubleFunction ma return entry.value; } - @Override - public double supplyDoubleIfAbsent(short key, DoubleSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - double newValue = valueProvider.getAsDouble(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public double supplyDoubleIfAbsentNonDefault(short key, DoubleSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -532,16 +542,6 @@ public double supplyDoubleIfAbsentNonDefault(short key, DoubleSupplier valueProv return entry.value; } - @Override - public double computeDoubleIfPresent(short key, ShortDoubleUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - double newValue = mappingFunction.applyAsDouble(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public double computeDoubleIfPresentNonDefault(short key, ShortDoubleUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1621,14 +1621,9 @@ public double computeDoubleIfPresent(short key, ShortDoubleUnaryOperator mapping Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || Double.doubleToLongBits(entry.value) == Double.doubleToLongBits(getDefaultReturnValue())) return getDefaultReturnValue(); - double newValue = mappingFunction.apply(key, entry.value); - if(Double.doubleToLongBits(newValue) == Double.doubleToLongBits(getDefaultReturnValue())) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2FloatAVLTreeMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2FloatAVLTreeMap.java index fa366775..7a51fdf5 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2FloatAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2FloatAVLTreeMap.java @@ -455,34 +455,56 @@ public float computeFloat(short key, ShortFloatUnaryOperator mappingFunction) { } @Override - public float computeFloatNonDefault(short key, ShortFloatUnaryOperator mappingFunction) { + public float computeFloatIfAbsent(short key, Short2FloatFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + float newValue = mappingFunction.applyAsFloat(key); put(key, newValue); return newValue; } - float newValue = mappingFunction.applyAsFloat(key, entry.value); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - removeNode(entry); + return entry.value; + } + + @Override + public float supplyFloatIfAbsent(short key, FloatSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + float newValue = valueProvider.getAsFloat(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public float computeFloatIfPresent(short key, ShortFloatUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + float newValue = mappingFunction.applyAsFloat(key, entry.value); entry.value = newValue; return newValue; } @Override - public float computeFloatIfAbsent(short key, Short2FloatFunction mappingFunction) { + public float computeFloatNonDefault(short key, ShortFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; put(key, newValue); return newValue; } - return entry.value; + float newValue = mappingFunction.applyAsFloat(key, entry.value); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -503,46 +525,24 @@ public float computeFloatIfAbsentNonDefault(short key, Short2FloatFunction mappi return entry.value; } - @Override - public float supplyFloatIfAbsent(short key, FloatSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - float newValue = valueProvider.getAsDouble(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public float supplyFloatIfAbsentNonDefault(short key, FloatSupplier valueProvider) { Objects.requireNonNull(valueProvider); Node entry = findNode(key); if(entry == null) { - float newValue = valueProvider.getAsDouble(); + float newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; put(key, newValue); return newValue; } if(Float.floatToIntBits(entry.value) == Float.floatToIntBits(getDefaultReturnValue())) { - float newValue = valueProvider.getAsDouble(); + float newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; entry.value = newValue; } return entry.value; } - @Override - public float computeFloatIfPresent(short key, ShortFloatUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - float newValue = mappingFunction.applyAsFloat(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public float computeFloatIfPresentNonDefault(short key, ShortFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1558,14 +1558,9 @@ public float computeFloatIfPresent(short key, ShortFloatUnaryOperator mappingFun Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || Float.floatToIntBits(entry.value) == Float.floatToIntBits(getDefaultReturnValue())) return getDefaultReturnValue(); - float newValue = mappingFunction.apply(key, entry.value); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2FloatRBTreeMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2FloatRBTreeMap.java index 4558ba24..9c98a925 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2FloatRBTreeMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2FloatRBTreeMap.java @@ -454,34 +454,56 @@ public float computeFloat(short key, ShortFloatUnaryOperator mappingFunction) { } @Override - public float computeFloatNonDefault(short key, ShortFloatUnaryOperator mappingFunction) { + public float computeFloatIfAbsent(short key, Short2FloatFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; + float newValue = mappingFunction.applyAsFloat(key); put(key, newValue); return newValue; } - float newValue = mappingFunction.applyAsFloat(key, entry.value); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - removeNode(entry); + return entry.value; + } + + @Override + public float supplyFloatIfAbsent(short key, FloatSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + float newValue = valueProvider.getAsFloat(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public float computeFloatIfPresent(short key, ShortFloatUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + float newValue = mappingFunction.applyAsFloat(key, entry.value); entry.value = newValue; return newValue; } @Override - public float computeFloatIfAbsent(short key, Short2FloatFunction mappingFunction) { + public float computeFloatNonDefault(short key, ShortFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - float newValue = mappingFunction.applyAsFloat(key); + float newValue = mappingFunction.applyAsFloat(key, getDefaultReturnValue()); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; put(key, newValue); return newValue; } - return entry.value; + float newValue = mappingFunction.applyAsFloat(key, entry.value); + if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -502,46 +524,24 @@ public float computeFloatIfAbsentNonDefault(short key, Short2FloatFunction mappi return entry.value; } - @Override - public float supplyFloatIfAbsent(short key, FloatSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - float newValue = valueProvider.getAsDouble(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public float supplyFloatIfAbsentNonDefault(short key, FloatSupplier valueProvider) { Objects.requireNonNull(valueProvider); Node entry = findNode(key); if(entry == null) { - float newValue = valueProvider.getAsDouble(); + float newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; put(key, newValue); return newValue; } if(Float.floatToIntBits(entry.value) == Float.floatToIntBits(getDefaultReturnValue())) { - float newValue = valueProvider.getAsDouble(); + float newValue = valueProvider.getAsFloat(); if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) return newValue; entry.value = newValue; } return entry.value; } - @Override - public float computeFloatIfPresent(short key, ShortFloatUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - float newValue = mappingFunction.applyAsFloat(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public float computeFloatIfPresentNonDefault(short key, ShortFloatUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1621,14 +1621,9 @@ public float computeFloatIfPresent(short key, ShortFloatUnaryOperator mappingFun Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || Float.floatToIntBits(entry.value) == Float.floatToIntBits(getDefaultReturnValue())) return getDefaultReturnValue(); - float newValue = mappingFunction.apply(key, entry.value); - if(Float.floatToIntBits(newValue) == Float.floatToIntBits(getDefaultReturnValue())) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2IntAVLTreeMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2IntAVLTreeMap.java index 2b16f119..b1b561b8 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2IntAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2IntAVLTreeMap.java @@ -455,34 +455,56 @@ public int computeInt(short key, ShortIntUnaryOperator mappingFunction) { } @Override - public int computeIntNonDefault(short key, ShortIntUnaryOperator mappingFunction) { + public int computeIntIfAbsent(short key, Short2IntFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + int newValue = mappingFunction.applyAsInt(key); put(key, newValue); return newValue; } - int newValue = mappingFunction.applyAsInt(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public int supplyIntIfAbsent(short key, IntSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + int newValue = valueProvider.getAsInt(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public int computeIntIfPresent(short key, ShortIntUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + int newValue = mappingFunction.applyAsInt(key, entry.value); entry.value = newValue; return newValue; } @Override - public int computeIntIfAbsent(short key, Short2IntFunction mappingFunction) { + public int computeIntNonDefault(short key, ShortIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + int newValue = mappingFunction.applyAsInt(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -503,18 +525,6 @@ public int computeIntIfAbsentNonDefault(short key, Short2IntFunction mappingFunc return entry.value; } - @Override - public int supplyIntIfAbsent(short key, IntSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - int newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public int supplyIntIfAbsentNonDefault(short key, IntSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -533,16 +543,6 @@ public int supplyIntIfAbsentNonDefault(short key, IntSupplier valueProvider) { return entry.value; } - @Override - public int computeIntIfPresent(short key, ShortIntUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - int newValue = mappingFunction.applyAsInt(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public int computeIntIfPresentNonDefault(short key, ShortIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1558,14 +1558,9 @@ public int computeIntIfPresent(short key, ShortIntUnaryOperator mappingFunction) Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - int newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2IntRBTreeMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2IntRBTreeMap.java index aa7d6c90..b3206ace 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2IntRBTreeMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2IntRBTreeMap.java @@ -454,34 +454,56 @@ public int computeInt(short key, ShortIntUnaryOperator mappingFunction) { } @Override - public int computeIntNonDefault(short key, ShortIntUnaryOperator mappingFunction) { + public int computeIntIfAbsent(short key, Short2IntFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + int newValue = mappingFunction.applyAsInt(key); put(key, newValue); return newValue; } - int newValue = mappingFunction.applyAsInt(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public int supplyIntIfAbsent(short key, IntSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + int newValue = valueProvider.getAsInt(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public int computeIntIfPresent(short key, ShortIntUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + int newValue = mappingFunction.applyAsInt(key, entry.value); entry.value = newValue; return newValue; } @Override - public int computeIntIfAbsent(short key, Short2IntFunction mappingFunction) { + public int computeIntNonDefault(short key, ShortIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - int newValue = mappingFunction.applyAsInt(key); + int newValue = mappingFunction.applyAsInt(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + int newValue = mappingFunction.applyAsInt(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -502,18 +524,6 @@ public int computeIntIfAbsentNonDefault(short key, Short2IntFunction mappingFunc return entry.value; } - @Override - public int supplyIntIfAbsent(short key, IntSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - int newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public int supplyIntIfAbsentNonDefault(short key, IntSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -532,16 +542,6 @@ public int supplyIntIfAbsentNonDefault(short key, IntSupplier valueProvider) { return entry.value; } - @Override - public int computeIntIfPresent(short key, ShortIntUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - int newValue = mappingFunction.applyAsInt(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public int computeIntIfPresentNonDefault(short key, ShortIntUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1621,14 +1621,9 @@ public int computeIntIfPresent(short key, ShortIntUnaryOperator mappingFunction) Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - int newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2LongAVLTreeMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2LongAVLTreeMap.java index 5def5821..4d4f8147 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2LongAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2LongAVLTreeMap.java @@ -455,34 +455,56 @@ public long computeLong(short key, ShortLongUnaryOperator mappingFunction) { } @Override - public long computeLongNonDefault(short key, ShortLongUnaryOperator mappingFunction) { + public long computeLongIfAbsent(short key, Short2LongFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + long newValue = mappingFunction.applyAsLong(key); put(key, newValue); return newValue; } - long newValue = mappingFunction.applyAsLong(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public long supplyLongIfAbsent(short key, LongSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + long newValue = valueProvider.getAsLong(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public long computeLongIfPresent(short key, ShortLongUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + long newValue = mappingFunction.applyAsLong(key, entry.value); entry.value = newValue; return newValue; } @Override - public long computeLongIfAbsent(short key, Short2LongFunction mappingFunction) { + public long computeLongNonDefault(short key, ShortLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + long newValue = mappingFunction.applyAsLong(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -503,18 +525,6 @@ public long computeLongIfAbsentNonDefault(short key, Short2LongFunction mappingF return entry.value; } - @Override - public long supplyLongIfAbsent(short key, LongSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - long newValue = valueProvider.getAsLong(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public long supplyLongIfAbsentNonDefault(short key, LongSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -533,16 +543,6 @@ public long supplyLongIfAbsentNonDefault(short key, LongSupplier valueProvider) return entry.value; } - @Override - public long computeLongIfPresent(short key, ShortLongUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - long newValue = mappingFunction.applyAsLong(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public long computeLongIfPresentNonDefault(short key, ShortLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1558,14 +1558,9 @@ public long computeLongIfPresent(short key, ShortLongUnaryOperator mappingFuncti Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - long newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2LongRBTreeMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2LongRBTreeMap.java index 40f206ee..f9804f08 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2LongRBTreeMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2LongRBTreeMap.java @@ -454,34 +454,56 @@ public long computeLong(short key, ShortLongUnaryOperator mappingFunction) { } @Override - public long computeLongNonDefault(short key, ShortLongUnaryOperator mappingFunction) { + public long computeLongIfAbsent(short key, Short2LongFunction mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + long newValue = mappingFunction.applyAsLong(key); put(key, newValue); return newValue; } - long newValue = mappingFunction.applyAsLong(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public long supplyLongIfAbsent(short key, LongSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + long newValue = valueProvider.getAsLong(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public long computeLongIfPresent(short key, ShortLongUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + long newValue = mappingFunction.applyAsLong(key, entry.value); entry.value = newValue; return newValue; } @Override - public long computeLongIfAbsent(short key, Short2LongFunction mappingFunction) { + public long computeLongNonDefault(short key, ShortLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - long newValue = mappingFunction.applyAsLong(key); + long newValue = mappingFunction.applyAsLong(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + long newValue = mappingFunction.applyAsLong(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -502,18 +524,6 @@ public long computeLongIfAbsentNonDefault(short key, Short2LongFunction mappingF return entry.value; } - @Override - public long supplyLongIfAbsent(short key, LongSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - long newValue = valueProvider.getAsLong(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public long supplyLongIfAbsentNonDefault(short key, LongSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -532,16 +542,6 @@ public long supplyLongIfAbsentNonDefault(short key, LongSupplier valueProvider) return entry.value; } - @Override - public long computeLongIfPresent(short key, ShortLongUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - long newValue = mappingFunction.applyAsLong(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public long computeLongIfPresentNonDefault(short key, ShortLongUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1621,14 +1621,9 @@ public long computeLongIfPresent(short key, ShortLongUnaryOperator mappingFuncti Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - long newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2ObjectAVLTreeMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2ObjectAVLTreeMap.java index 85c31ccc..0fdfe9cf 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2ObjectAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2ObjectAVLTreeMap.java @@ -395,25 +395,6 @@ public V compute(short key, ShortObjectUnaryOperator mappingFunction) { return newValue; } - @Override - public V computeNonDefault(short key, ShortObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) { - V newValue = mappingFunction.apply(key, getDefaultReturnValue()); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - put(key, newValue); - return newValue; - } - V newValue = mappingFunction.apply(key, entry.value); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; - } - @Override public V computeIfAbsent(short key, ShortFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -432,24 +413,6 @@ public V computeIfAbsent(short key, ShortFunction mappingFunction) { return entry.value; } - @Override - public V computeIfAbsentNonDefault(short key, ShortFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) { - V newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - put(key, newValue); - return newValue; - } - if(Objects.equals(entry.value, getDefaultReturnValue())) { - V newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - entry.value = newValue; - } - return entry.value; - } - @Override public V supplyIfAbsent(short key, ObjectSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -468,24 +431,6 @@ public V supplyIfAbsent(short key, ObjectSupplier valueProvider) { return entry.value; } - @Override - public V supplyIfAbsentNonDefault(short key, ObjectSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - V newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - put(key, newValue); - return newValue; - } - if(Objects.equals(entry.value, getDefaultReturnValue())) { - V newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - entry.value = newValue; - } - return entry.value; - } - @Override public V computeIfPresent(short key, ShortObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -500,20 +445,6 @@ public V computeIfPresent(short key, ShortObjectUnaryOperator mappingFunction return newValue; } - @Override - public V computeIfPresentNonDefault(short key, ShortObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null || Objects.equals(entry.value, getDefaultReturnValue())) return getDefaultReturnValue(); - V newValue = mappingFunction.apply(key, entry.value); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; - } - @Override public V merge(short key, V value, ObjectObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2ObjectRBTreeMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2ObjectRBTreeMap.java index f0c8c9c7..7a845fc1 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2ObjectRBTreeMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2ObjectRBTreeMap.java @@ -394,25 +394,6 @@ public V compute(short key, ShortObjectUnaryOperator mappingFunction) { return newValue; } - @Override - public V computeNonDefault(short key, ShortObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) { - V newValue = mappingFunction.apply(key, getDefaultReturnValue()); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - put(key, newValue); - return newValue; - } - V newValue = mappingFunction.apply(key, entry.value); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; - } - @Override public V computeIfAbsent(short key, ShortFunction mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -431,24 +412,6 @@ public V computeIfAbsent(short key, ShortFunction mappingFunction) { return entry.value; } - @Override - public V computeIfAbsentNonDefault(short key, ShortFunction mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) { - V newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - put(key, newValue); - return newValue; - } - if(Objects.equals(entry.value, getDefaultReturnValue())) { - V newValue = mappingFunction.apply(key); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - entry.value = newValue; - } - return entry.value; - } - @Override public V supplyIfAbsent(short key, ObjectSupplier valueProvider) { Objects.requireNonNull(valueProvider); @@ -467,24 +430,6 @@ public V supplyIfAbsent(short key, ObjectSupplier valueProvider) { return entry.value; } - @Override - public V supplyIfAbsentNonDefault(short key, ObjectSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - V newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - put(key, newValue); - return newValue; - } - if(Objects.equals(entry.value, getDefaultReturnValue())) { - V newValue = valueProvider.get(); - if(Objects.equals(newValue, getDefaultReturnValue())) return newValue; - entry.value = newValue; - } - return entry.value; - } - @Override public V computeIfPresent(short key, ShortObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -499,20 +444,6 @@ public V computeIfPresent(short key, ShortObjectUnaryOperator mappingFunction return newValue; } - @Override - public V computeIfPresentNonDefault(short key, ShortObjectUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null || Objects.equals(entry.value, getDefaultReturnValue())) return getDefaultReturnValue(); - V newValue = mappingFunction.apply(key, entry.value); - if(Objects.equals(newValue, getDefaultReturnValue())) { - removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; - } - @Override public V merge(short key, V value, ObjectObjectUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2ShortAVLTreeMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2ShortAVLTreeMap.java index 25535795..84dd0f56 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2ShortAVLTreeMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2ShortAVLTreeMap.java @@ -447,34 +447,56 @@ public short computeShort(short key, ShortShortUnaryOperator mappingFunction) { } @Override - public short computeShortNonDefault(short key, ShortShortUnaryOperator mappingFunction) { + public short computeShortIfAbsent(short key, ShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + short newValue = mappingFunction.applyAsShort(key); put(key, newValue); return newValue; } - short newValue = mappingFunction.applyAsShort(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public short supplyShortIfAbsent(short key, ShortSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + short newValue = valueProvider.getAsShort(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public short computeShortIfPresent(short key, ShortShortUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + short newValue = mappingFunction.applyAsShort(key, entry.value); entry.value = newValue; return newValue; } @Override - public short computeShortIfAbsent(short key, ShortUnaryOperator mappingFunction) { + public short computeShortNonDefault(short key, ShortShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + short newValue = mappingFunction.applyAsShort(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -495,46 +517,24 @@ public short computeShortIfAbsentNonDefault(short key, ShortUnaryOperator mappin return entry.value; } - @Override - public short supplyShortIfAbsent(short key, ShortSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - short newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public short supplyShortIfAbsentNonDefault(short key, ShortSupplier valueProvider) { Objects.requireNonNull(valueProvider); Node entry = findNode(key); if(entry == null) { - short newValue = valueProvider.getAsInt(); + short newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } if(entry.value == getDefaultReturnValue()) { - short newValue = valueProvider.getAsInt(); + short newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; entry.value = newValue; } return entry.value; } - @Override - public short computeShortIfPresent(short key, ShortShortUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - short newValue = mappingFunction.applyAsShort(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public short computeShortIfPresentNonDefault(short key, ShortShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1550,14 +1550,9 @@ public short computeShortIfPresent(short key, ShortShortUnaryOperator mappingFun Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - short newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2ShortRBTreeMap.java b/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2ShortRBTreeMap.java index ab98667d..71544d08 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2ShortRBTreeMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/impl/tree/Short2ShortRBTreeMap.java @@ -446,34 +446,56 @@ public short computeShort(short key, ShortShortUnaryOperator mappingFunction) { } @Override - public short computeShortNonDefault(short key, ShortShortUnaryOperator mappingFunction) { + public short computeShortIfAbsent(short key, ShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); - if(newValue == getDefaultReturnValue()) return newValue; + short newValue = mappingFunction.applyAsShort(key); put(key, newValue); return newValue; } - short newValue = mappingFunction.applyAsShort(key, entry.value); - if(newValue == getDefaultReturnValue()) { - removeNode(entry); + return entry.value; + } + + @Override + public short supplyShortIfAbsent(short key, ShortSupplier valueProvider) { + Objects.requireNonNull(valueProvider); + Node entry = findNode(key); + if(entry == null) { + short newValue = valueProvider.getAsShort(); + put(key, newValue); return newValue; } + return entry.value; + } + + @Override + public short computeShortIfPresent(short key, ShortShortUnaryOperator mappingFunction) { + Objects.requireNonNull(mappingFunction); + Node entry = findNode(key); + if(entry == null) return getDefaultReturnValue(); + short newValue = mappingFunction.applyAsShort(key, entry.value); entry.value = newValue; return newValue; } @Override - public short computeShortIfAbsent(short key, ShortUnaryOperator mappingFunction) { + public short computeShortNonDefault(short key, ShortShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); Node entry = findNode(key); if(entry == null) { - short newValue = mappingFunction.applyAsShort(key); + short newValue = mappingFunction.applyAsShort(key, getDefaultReturnValue()); + if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } - return entry.value; + short newValue = mappingFunction.applyAsShort(key, entry.value); + if(newValue == getDefaultReturnValue()) { + removeNode(entry); + return newValue; + } + entry.value = newValue; + return newValue; } @Override @@ -494,46 +516,24 @@ public short computeShortIfAbsentNonDefault(short key, ShortUnaryOperator mappin return entry.value; } - @Override - public short supplyShortIfAbsent(short key, ShortSupplier valueProvider) { - Objects.requireNonNull(valueProvider); - Node entry = findNode(key); - if(entry == null) { - short newValue = valueProvider.getAsInt(); - put(key, newValue); - return newValue; - } - return entry.value; - } - @Override public short supplyShortIfAbsentNonDefault(short key, ShortSupplier valueProvider) { Objects.requireNonNull(valueProvider); Node entry = findNode(key); if(entry == null) { - short newValue = valueProvider.getAsInt(); + short newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; put(key, newValue); return newValue; } if(entry.value == getDefaultReturnValue()) { - short newValue = valueProvider.getAsInt(); + short newValue = valueProvider.getAsShort(); if(newValue == getDefaultReturnValue()) return newValue; entry.value = newValue; } return entry.value; } - @Override - public short computeShortIfPresent(short key, ShortShortUnaryOperator mappingFunction) { - Objects.requireNonNull(mappingFunction); - Node entry = findNode(key); - if(entry == null) return getDefaultReturnValue(); - short newValue = mappingFunction.applyAsShort(key, entry.value); - entry.value = newValue; - return newValue; - } - @Override public short computeShortIfPresentNonDefault(short key, ShortShortUnaryOperator mappingFunction) { Objects.requireNonNull(mappingFunction); @@ -1613,14 +1613,9 @@ public short computeShortIfPresent(short key, ShortShortUnaryOperator mappingFun Objects.requireNonNull(mappingFunction); if(!inRange(key)) return getDefaultReturnValue(); Node entry = map.findNode(key); - if(entry == null || entry.value == getDefaultReturnValue()) return getDefaultReturnValue(); - short newValue = mappingFunction.apply(key, entry.value); - if(newValue == getDefaultReturnValue()) { - map.removeNode(entry); - return newValue; - } - entry.value = newValue; - return newValue; + if(entry == null) return getDefaultReturnValue(); + entry.value = mappingFunction.apply(key, entry.value); + return entry.value; } @Override diff --git a/src/main/java/speiger/src/collections/shorts/maps/interfaces/Short2BooleanMap.java b/src/main/java/speiger/src/collections/shorts/maps/interfaces/Short2BooleanMap.java index 2f6c363e..b072a679 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/interfaces/Short2BooleanMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/interfaces/Short2BooleanMap.java @@ -284,41 +284,51 @@ public default boolean remove(Object key, Object value) { */ public boolean computeBoolean(short key, ShortBooleanUnaryOperator mappingFunction); /** - * A Type Specific compute method to reduce boxing/unboxing + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation + * @param mappingFunction the operator that should generate the value if not present + * @return the result of the computed value or present value */ - public boolean computeBooleanNonDefault(short key, ShortBooleanUnaryOperator mappingFunction); + public boolean computeBooleanIfAbsent(short key, ShortPredicate mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present + * @param valueProvider the value if not present * @return the result of the computed value or present value + */ + public boolean supplyBooleanIfAbsent(short key, BooleanSupplier valueProvider); + /** + * A Type Specific compute method to reduce boxing/unboxing + * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". + * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. + * @param key the key that should be computed + * @param mappingFunction the operator that should generate the value if present + * @return the result of the default return value or present value + * @note if not present then compute is not executed */ - public boolean computeBooleanIfAbsent(short key, ShortPredicate mappingFunction); + public boolean computeBooleanIfPresent(short key, ShortBooleanUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value + * @param mappingFunction the operator that should generate the value + * @return the result of the computation */ - public boolean computeBooleanIfAbsentNonDefault(short key, ShortPredicate mappingFunction); + public boolean computeBooleanNonDefault(short key, ShortBooleanUnaryOperator mappingFunction); /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param valueProvider the value if not present + * @param mappingFunction the operator that should generate the value if not present * @return the result of the computed value or present value - */ - public boolean supplyBooleanIfAbsent(short key, BooleanSupplier valueProvider); + */ + public boolean computeBooleanIfAbsentNonDefault(short key, ShortPredicate mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -328,16 +338,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public boolean supplyBooleanIfAbsentNonDefault(short key, BooleanSupplier valueProvider); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public boolean computeBooleanIfPresent(short key, ShortBooleanUnaryOperator mappingFunction); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/shorts/maps/interfaces/Short2ByteMap.java b/src/main/java/speiger/src/collections/shorts/maps/interfaces/Short2ByteMap.java index c4c7e3ba..58820b15 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/interfaces/Short2ByteMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/interfaces/Short2ByteMap.java @@ -309,41 +309,51 @@ public default boolean remove(Object key, Object value) { */ public byte computeByte(short key, ShortByteUnaryOperator mappingFunction); /** - * A Type Specific compute method to reduce boxing/unboxing + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation + * @param mappingFunction the operator that should generate the value if not present + * @return the result of the computed value or present value */ - public byte computeByteNonDefault(short key, ShortByteUnaryOperator mappingFunction); + public byte computeByteIfAbsent(short key, Short2ByteFunction mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present + * @param valueProvider the value if not present * @return the result of the computed value or present value + */ + public byte supplyByteIfAbsent(short key, ByteSupplier valueProvider); + /** + * A Type Specific compute method to reduce boxing/unboxing + * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". + * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. + * @param key the key that should be computed + * @param mappingFunction the operator that should generate the value if present + * @return the result of the default return value or present value + * @note if not present then compute is not executed */ - public byte computeByteIfAbsent(short key, Short2ByteFunction mappingFunction); + public byte computeByteIfPresent(short key, ShortByteUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value + * @param mappingFunction the operator that should generate the value + * @return the result of the computation */ - public byte computeByteIfAbsentNonDefault(short key, Short2ByteFunction mappingFunction); + public byte computeByteNonDefault(short key, ShortByteUnaryOperator mappingFunction); /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param valueProvider the value if not present + * @param mappingFunction the operator that should generate the value if not present * @return the result of the computed value or present value - */ - public byte supplyByteIfAbsent(short key, ByteSupplier valueProvider); + */ + public byte computeByteIfAbsentNonDefault(short key, Short2ByteFunction mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -353,16 +363,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public byte supplyByteIfAbsentNonDefault(short key, ByteSupplier valueProvider); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public byte computeByteIfPresent(short key, ShortByteUnaryOperator mappingFunction); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/shorts/maps/interfaces/Short2CharMap.java b/src/main/java/speiger/src/collections/shorts/maps/interfaces/Short2CharMap.java index ab3e90ff..af57eb20 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/interfaces/Short2CharMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/interfaces/Short2CharMap.java @@ -309,41 +309,51 @@ public default boolean remove(Object key, Object value) { */ public char computeChar(short key, ShortCharUnaryOperator mappingFunction); /** - * A Type Specific compute method to reduce boxing/unboxing + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation + * @param mappingFunction the operator that should generate the value if not present + * @return the result of the computed value or present value */ - public char computeCharNonDefault(short key, ShortCharUnaryOperator mappingFunction); + public char computeCharIfAbsent(short key, Short2CharFunction mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present + * @param valueProvider the value if not present * @return the result of the computed value or present value + */ + public char supplyCharIfAbsent(short key, CharSupplier valueProvider); + /** + * A Type Specific compute method to reduce boxing/unboxing + * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". + * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. + * @param key the key that should be computed + * @param mappingFunction the operator that should generate the value if present + * @return the result of the default return value or present value + * @note if not present then compute is not executed */ - public char computeCharIfAbsent(short key, Short2CharFunction mappingFunction); + public char computeCharIfPresent(short key, ShortCharUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value + * @param mappingFunction the operator that should generate the value + * @return the result of the computation */ - public char computeCharIfAbsentNonDefault(short key, Short2CharFunction mappingFunction); + public char computeCharNonDefault(short key, ShortCharUnaryOperator mappingFunction); /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param valueProvider the value if not present + * @param mappingFunction the operator that should generate the value if not present * @return the result of the computed value or present value - */ - public char supplyCharIfAbsent(short key, CharSupplier valueProvider); + */ + public char computeCharIfAbsentNonDefault(short key, Short2CharFunction mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -353,16 +363,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public char supplyCharIfAbsentNonDefault(short key, CharSupplier valueProvider); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public char computeCharIfPresent(short key, ShortCharUnaryOperator mappingFunction); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/shorts/maps/interfaces/Short2DoubleMap.java b/src/main/java/speiger/src/collections/shorts/maps/interfaces/Short2DoubleMap.java index 04b1629e..ba984125 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/interfaces/Short2DoubleMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/interfaces/Short2DoubleMap.java @@ -309,41 +309,51 @@ public default boolean remove(Object key, Object value) { */ public double computeDouble(short key, ShortDoubleUnaryOperator mappingFunction); /** - * A Type Specific compute method to reduce boxing/unboxing + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation + * @param mappingFunction the operator that should generate the value if not present + * @return the result of the computed value or present value */ - public double computeDoubleNonDefault(short key, ShortDoubleUnaryOperator mappingFunction); + public double computeDoubleIfAbsent(short key, Short2DoubleFunction mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present + * @param valueProvider the value if not present * @return the result of the computed value or present value + */ + public double supplyDoubleIfAbsent(short key, DoubleSupplier valueProvider); + /** + * A Type Specific compute method to reduce boxing/unboxing + * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". + * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. + * @param key the key that should be computed + * @param mappingFunction the operator that should generate the value if present + * @return the result of the default return value or present value + * @note if not present then compute is not executed */ - public double computeDoubleIfAbsent(short key, Short2DoubleFunction mappingFunction); + public double computeDoubleIfPresent(short key, ShortDoubleUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value + * @param mappingFunction the operator that should generate the value + * @return the result of the computation */ - public double computeDoubleIfAbsentNonDefault(short key, Short2DoubleFunction mappingFunction); + public double computeDoubleNonDefault(short key, ShortDoubleUnaryOperator mappingFunction); /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param valueProvider the value if not present + * @param mappingFunction the operator that should generate the value if not present * @return the result of the computed value or present value - */ - public double supplyDoubleIfAbsent(short key, DoubleSupplier valueProvider); + */ + public double computeDoubleIfAbsentNonDefault(short key, Short2DoubleFunction mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -353,16 +363,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public double supplyDoubleIfAbsentNonDefault(short key, DoubleSupplier valueProvider); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public double computeDoubleIfPresent(short key, ShortDoubleUnaryOperator mappingFunction); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/shorts/maps/interfaces/Short2FloatMap.java b/src/main/java/speiger/src/collections/shorts/maps/interfaces/Short2FloatMap.java index 105873f7..41d117a2 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/interfaces/Short2FloatMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/interfaces/Short2FloatMap.java @@ -309,41 +309,51 @@ public default boolean remove(Object key, Object value) { */ public float computeFloat(short key, ShortFloatUnaryOperator mappingFunction); /** - * A Type Specific compute method to reduce boxing/unboxing + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation + * @param mappingFunction the operator that should generate the value if not present + * @return the result of the computed value or present value */ - public float computeFloatNonDefault(short key, ShortFloatUnaryOperator mappingFunction); + public float computeFloatIfAbsent(short key, Short2FloatFunction mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present + * @param valueProvider the value if not present * @return the result of the computed value or present value + */ + public float supplyFloatIfAbsent(short key, FloatSupplier valueProvider); + /** + * A Type Specific compute method to reduce boxing/unboxing + * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". + * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. + * @param key the key that should be computed + * @param mappingFunction the operator that should generate the value if present + * @return the result of the default return value or present value + * @note if not present then compute is not executed */ - public float computeFloatIfAbsent(short key, Short2FloatFunction mappingFunction); + public float computeFloatIfPresent(short key, ShortFloatUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value + * @param mappingFunction the operator that should generate the value + * @return the result of the computation */ - public float computeFloatIfAbsentNonDefault(short key, Short2FloatFunction mappingFunction); + public float computeFloatNonDefault(short key, ShortFloatUnaryOperator mappingFunction); /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param valueProvider the value if not present + * @param mappingFunction the operator that should generate the value if not present * @return the result of the computed value or present value - */ - public float supplyFloatIfAbsent(short key, FloatSupplier valueProvider); + */ + public float computeFloatIfAbsentNonDefault(short key, Short2FloatFunction mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -353,16 +363,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public float supplyFloatIfAbsentNonDefault(short key, FloatSupplier valueProvider); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public float computeFloatIfPresent(short key, ShortFloatUnaryOperator mappingFunction); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/shorts/maps/interfaces/Short2IntMap.java b/src/main/java/speiger/src/collections/shorts/maps/interfaces/Short2IntMap.java index b2b3b506..0dc2b8d1 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/interfaces/Short2IntMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/interfaces/Short2IntMap.java @@ -309,41 +309,51 @@ public default boolean remove(Object key, Object value) { */ public int computeInt(short key, ShortIntUnaryOperator mappingFunction); /** - * A Type Specific compute method to reduce boxing/unboxing + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation + * @param mappingFunction the operator that should generate the value if not present + * @return the result of the computed value or present value */ - public int computeIntNonDefault(short key, ShortIntUnaryOperator mappingFunction); + public int computeIntIfAbsent(short key, Short2IntFunction mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present + * @param valueProvider the value if not present * @return the result of the computed value or present value + */ + public int supplyIntIfAbsent(short key, IntSupplier valueProvider); + /** + * A Type Specific compute method to reduce boxing/unboxing + * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". + * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. + * @param key the key that should be computed + * @param mappingFunction the operator that should generate the value if present + * @return the result of the default return value or present value + * @note if not present then compute is not executed */ - public int computeIntIfAbsent(short key, Short2IntFunction mappingFunction); + public int computeIntIfPresent(short key, ShortIntUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value + * @param mappingFunction the operator that should generate the value + * @return the result of the computation */ - public int computeIntIfAbsentNonDefault(short key, Short2IntFunction mappingFunction); + public int computeIntNonDefault(short key, ShortIntUnaryOperator mappingFunction); /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param valueProvider the value if not present + * @param mappingFunction the operator that should generate the value if not present * @return the result of the computed value or present value - */ - public int supplyIntIfAbsent(short key, IntSupplier valueProvider); + */ + public int computeIntIfAbsentNonDefault(short key, Short2IntFunction mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -353,16 +363,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public int supplyIntIfAbsentNonDefault(short key, IntSupplier valueProvider); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public int computeIntIfPresent(short key, ShortIntUnaryOperator mappingFunction); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/shorts/maps/interfaces/Short2LongMap.java b/src/main/java/speiger/src/collections/shorts/maps/interfaces/Short2LongMap.java index 93073c31..65f039f8 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/interfaces/Short2LongMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/interfaces/Short2LongMap.java @@ -309,41 +309,51 @@ public default boolean remove(Object key, Object value) { */ public long computeLong(short key, ShortLongUnaryOperator mappingFunction); /** - * A Type Specific compute method to reduce boxing/unboxing + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation + * @param mappingFunction the operator that should generate the value if not present + * @return the result of the computed value or present value */ - public long computeLongNonDefault(short key, ShortLongUnaryOperator mappingFunction); + public long computeLongIfAbsent(short key, Short2LongFunction mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present + * @param valueProvider the value if not present * @return the result of the computed value or present value + */ + public long supplyLongIfAbsent(short key, LongSupplier valueProvider); + /** + * A Type Specific compute method to reduce boxing/unboxing + * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". + * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. + * @param key the key that should be computed + * @param mappingFunction the operator that should generate the value if present + * @return the result of the default return value or present value + * @note if not present then compute is not executed */ - public long computeLongIfAbsent(short key, Short2LongFunction mappingFunction); + public long computeLongIfPresent(short key, ShortLongUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value + * @param mappingFunction the operator that should generate the value + * @return the result of the computation */ - public long computeLongIfAbsentNonDefault(short key, Short2LongFunction mappingFunction); + public long computeLongNonDefault(short key, ShortLongUnaryOperator mappingFunction); /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param valueProvider the value if not present + * @param mappingFunction the operator that should generate the value if not present * @return the result of the computed value or present value - */ - public long supplyLongIfAbsent(short key, LongSupplier valueProvider); + */ + public long computeLongIfAbsentNonDefault(short key, Short2LongFunction mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -353,16 +363,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public long supplyLongIfAbsentNonDefault(short key, LongSupplier valueProvider); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public long computeLongIfPresent(short key, ShortLongUnaryOperator mappingFunction); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/shorts/maps/interfaces/Short2ObjectMap.java b/src/main/java/speiger/src/collections/shorts/maps/interfaces/Short2ObjectMap.java index 7e7db371..82878eeb 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/interfaces/Short2ObjectMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/interfaces/Short2ObjectMap.java @@ -266,15 +266,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computation */ public V compute(short key, ShortObjectUnaryOperator mappingFunction); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation - */ - public V computeNonDefault(short key, ShortObjectUnaryOperator mappingFunction); /** * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -284,15 +275,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public V computeIfAbsent(short key, ShortFunction mappingFunction); - /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value - */ - public V computeIfAbsentNonDefault(short key, ShortFunction mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -302,15 +284,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public V supplyIfAbsent(short key, ObjectSupplier valueProvider); - /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param valueProvider the value if not present - * @return the result of the computed value or present value - */ - public V supplyIfAbsentNonDefault(short key, ObjectSupplier valueProvider); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -321,16 +294,6 @@ public default boolean remove(Object key, Object value) { * @note if not present then compute is not executed */ public V computeIfPresent(short key, ShortObjectUnaryOperator mappingFunction); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public V computeIfPresentNonDefault(short key, ShortObjectUnaryOperator mappingFunction); /** * A Type Specific merge method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/shorts/maps/interfaces/Short2ShortMap.java b/src/main/java/speiger/src/collections/shorts/maps/interfaces/Short2ShortMap.java index 98303aad..90751202 100644 --- a/src/main/java/speiger/src/collections/shorts/maps/interfaces/Short2ShortMap.java +++ b/src/main/java/speiger/src/collections/shorts/maps/interfaces/Short2ShortMap.java @@ -308,41 +308,51 @@ public default boolean remove(Object key, Object value) { */ public short computeShort(short key, ShortShortUnaryOperator mappingFunction); /** - * A Type Specific compute method to reduce boxing/unboxing + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value - * @return the result of the computation + * @param mappingFunction the operator that should generate the value if not present + * @return the result of the computed value or present value */ - public short computeShortNonDefault(short key, ShortShortUnaryOperator mappingFunction); + public short computeShortIfAbsent(short key, ShortUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present + * @param valueProvider the value if not present * @return the result of the computed value or present value + */ + public short supplyShortIfAbsent(short key, ShortSupplier valueProvider); + /** + * A Type Specific compute method to reduce boxing/unboxing + * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". + * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. + * @param key the key that should be computed + * @param mappingFunction the operator that should generate the value if present + * @return the result of the default return value or present value + * @note if not present then compute is not executed */ - public short computeShortIfAbsent(short key, ShortUnaryOperator mappingFunction); + public short computeShortIfPresent(short key, ShortShortUnaryOperator mappingFunction); /** - * A Type Specific computeIfAbsent method to reduce boxing/unboxing + * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if not present - * @return the result of the computed value or present value + * @param mappingFunction the operator that should generate the value + * @return the result of the computation */ - public short computeShortIfAbsentNonDefault(short key, ShortUnaryOperator mappingFunction); + public short computeShortNonDefault(short key, ShortShortUnaryOperator mappingFunction); /** - * A Supplier based computeIfAbsent function to fill the most used usecase of this function + * A Type Specific computeIfAbsent method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. * @param key the key that should be computed - * @param valueProvider the value if not present + * @param mappingFunction the operator that should generate the value if not present * @return the result of the computed value or present value - */ - public short supplyShortIfAbsent(short key, ShortSupplier valueProvider); + */ + public short computeShortIfAbsentNonDefault(short key, ShortUnaryOperator mappingFunction); /** * A Supplier based computeIfAbsent function to fill the most used usecase of this function * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". @@ -352,16 +362,6 @@ public default boolean remove(Object key, Object value) { * @return the result of the computed value or present value */ public short supplyShortIfAbsentNonDefault(short key, ShortSupplier valueProvider); - /** - * A Type Specific compute method to reduce boxing/unboxing - * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". - * A "Null Value" will be treated as "Do not insert/remove" based on how the Java has specified it. - * @param key the key that should be computed - * @param mappingFunction the operator that should generate the value if present - * @return the result of the default return value or present value - * @note if not present then compute is not executed - */ - public short computeShortIfPresent(short key, ShortShortUnaryOperator mappingFunction); /** * A Type Specific compute method to reduce boxing/unboxing * If the generated value equals the getDefaultReturnValue it will simply not insert it since that is treated as "null". diff --git a/src/main/java/speiger/src/collections/shorts/queues/ShortArrayFIFOQueue.java b/src/main/java/speiger/src/collections/shorts/queues/ShortArrayFIFOQueue.java index bebc50fc..65b88168 100644 --- a/src/main/java/speiger/src/collections/shorts/queues/ShortArrayFIFOQueue.java +++ b/src/main/java/speiger/src/collections/shorts/queues/ShortArrayFIFOQueue.java @@ -146,6 +146,15 @@ public short peek(int index) { return index >= array.length ? array[index-array.length] : array[index]; } + @Override + public boolean contains(short e) { + if(first == last) return false; + for(int i = 0,m=size();i iterator, int repea return new RepeatingIterator(wrap(iterator), repeats); } + /** + * A Helper function that creates a infinitely looping iterator + * @param iterator that should be looping infinitely + * @return a infinitely looping iterator + */ + public static ShortIterator infinite(ShortIterator iterator) { + return new InfiniteIterator(iterator); + } + + /** + * A Helper function that creates a infinitely looping iterator from a Java Iterator + * @param iterator that should be looping infinitely + * @return a infinitely looping iterator + */ + public static ShortIterator infinite(Iterator iterator) { + return new InfiniteIterator(wrap(iterator)); + } + /** * A Helper function that hard limits the Iterator to a specific size * @param iterator that should be limited @@ -841,6 +862,40 @@ public T next() { } } + private static class InfiniteIterator implements ShortIterator + { + ShortIterator iter; + CollectionWrapper looper = ShortCollections.wrapper(); + int index = 0; + + public InfiniteIterator(ShortIterator iter) { + this.iter = iter; + } + + @Override + public boolean hasNext() { + return true; + } + + @Override + public short nextShort() { + if(iter != null) { + if(iter.hasNext()) { + short value = iter.nextShort(); + looper.add(value); + return value; + } + else iter = null; + } + return looper.getShort((index++) % looper.size()); + } + + @Override + public void forEachRemaining(ShortConsumer action) { throw new UnsupportedOperationException("This is a instant deadlock, so unsupported"); } + public void forEachRemaining(Consumer action) { throw new UnsupportedOperationException("This is a instant deadlock, so unsupported"); } + public void forEachRemaining(E input, ObjectShortConsumer action) { throw new UnsupportedOperationException("This is a instant deadlock, so unsupported"); } + } + private static class RepeatingIterator implements ShortIterator { final int repeats; diff --git a/src/main/java/speiger/src/collections/shorts/utils/ShortLists.java b/src/main/java/speiger/src/collections/shorts/utils/ShortLists.java index 291782cb..ecc4438a 100644 --- a/src/main/java/speiger/src/collections/shorts/utils/ShortLists.java +++ b/src/main/java/speiger/src/collections/shorts/utils/ShortLists.java @@ -12,6 +12,7 @@ import speiger.src.collections.shorts.functions.ShortConsumer; import speiger.src.collections.shorts.lists.AbstractShortList; import speiger.src.collections.shorts.lists.ShortList; +import speiger.src.collections.ints.lists.IntList; import speiger.src.collections.shorts.lists.ShortListIterator; import speiger.src.collections.utils.SanityChecks; @@ -317,6 +318,16 @@ public ShortListIterator listIterator(int index) { return l.listIterator(index); } + @Override + public ShortListIterator indexedIterator(int...indecies) { + return l.indexedIterator(indecies); + } + + @Override + public ShortListIterator indexedIterator(IntList indecies) { + return l.indexedIterator(indecies); + } + @Override public ShortList subList(int from, int to) { return ShortLists.synchronize(l.subList(from, to)); @@ -426,6 +437,16 @@ public ShortListIterator listIterator(int index) { return ShortIterators.unmodifiable(l.listIterator(index)); } + @Override + public ShortListIterator indexedIterator(int...indecies) { + return ShortIterators.unmodifiable(l.indexedIterator(indecies)); + } + + @Override + public ShortListIterator indexedIterator(IntList indecies) { + return ShortIterators.unmodifiable(l.indexedIterator(indecies)); + } + @Override public ShortList subList(int from, int to) { return ShortLists.unmodifiable(l.subList(from, to)); @@ -514,6 +535,16 @@ public ShortListIterator listIterator(int index) { return ShortIterators.empty(); } + @Override + public ShortListIterator indexedIterator(int...indecies) { + return ShortIterators.empty(); + } + + @Override + public ShortListIterator indexedIterator(IntList indecies) { + return ShortIterators.empty(); + } + @Override public int hashCode() { return 1; } diff --git a/src/main/java/speiger/src/collections/shorts/utils/ShortPriorityQueues.java b/src/main/java/speiger/src/collections/shorts/utils/ShortPriorityQueues.java index e948c144..e060c641 100644 --- a/src/main/java/speiger/src/collections/shorts/utils/ShortPriorityQueues.java +++ b/src/main/java/speiger/src/collections/shorts/utils/ShortPriorityQueues.java @@ -89,6 +89,8 @@ protected SynchronizedPriorityQueue(ShortPriorityQueue queue, Object mutex) { @Override public short peek(int index) { synchronized(mutex) { return queue.peek(index); } } @Override + public boolean contains(short e) { synchronized(mutex) { return queue.contains(e); } } + @Override public boolean removeFirst(short e) { synchronized(mutex) { return queue.removeFirst(e); } } @Override public boolean removeLast(short e) { synchronized(mutex) { return queue.removeLast(e); } } diff --git a/src/main/java/speiger/src/collections/shorts/utils/maps/Short2BooleanMaps.java b/src/main/java/speiger/src/collections/shorts/utils/maps/Short2BooleanMaps.java index c88e9a4e..16e46f37 100644 --- a/src/main/java/speiger/src/collections/shorts/utils/maps/Short2BooleanMaps.java +++ b/src/main/java/speiger/src/collections/shorts/utils/maps/Short2BooleanMaps.java @@ -246,18 +246,18 @@ public static class SingletonMap extends AbstractShort2BooleanMap { @Override public boolean computeBoolean(short key, ShortBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanNonDefault(short key, ShortBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean computeBooleanIfAbsent(short key, ShortPredicate mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanIfAbsentNonDefault(short key, ShortPredicate mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean computeBooleanIfPresent(short key, ShortBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanIfPresentNonDefault(short key, ShortBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean supplyBooleanIfAbsent(short key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public boolean computeBooleanNonDefault(short key, ShortBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public boolean computeBooleanIfAbsentNonDefault(short key, ShortPredicate mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public boolean computeBooleanIfPresentNonDefault(short key, ShortBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public boolean supplyBooleanIfAbsentNonDefault(short key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public boolean mergeBoolean(short key, boolean value, BooleanBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -304,18 +304,18 @@ public static class EmptyMap extends AbstractShort2BooleanMap { @Override public boolean computeBoolean(short key, ShortBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanNonDefault(short key, ShortBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean computeBooleanIfAbsent(short key, ShortPredicate mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanIfAbsentNonDefault(short key, ShortPredicate mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean computeBooleanIfPresent(short key, ShortBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanIfPresentNonDefault(short key, ShortBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean supplyBooleanIfAbsent(short key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public boolean computeBooleanNonDefault(short key, ShortBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public boolean computeBooleanIfAbsentNonDefault(short key, ShortPredicate mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public boolean computeBooleanIfPresentNonDefault(short key, ShortBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public boolean supplyBooleanIfAbsentNonDefault(short key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public boolean mergeBoolean(short key, boolean value, BooleanBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -535,18 +535,18 @@ public boolean get(short key) { @Override public boolean computeBoolean(short key, ShortBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanNonDefault(short key, ShortBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean computeBooleanIfAbsent(short key, ShortPredicate mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanIfAbsentNonDefault(short key, ShortPredicate mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean computeBooleanIfPresent(short key, ShortBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public boolean computeBooleanIfPresentNonDefault(short key, ShortBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public boolean supplyBooleanIfAbsent(short key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public boolean computeBooleanNonDefault(short key, ShortBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public boolean computeBooleanIfAbsentNonDefault(short key, ShortPredicate mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public boolean computeBooleanIfPresentNonDefault(short key, ShortBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public boolean supplyBooleanIfAbsentNonDefault(short key, BooleanSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public boolean mergeBoolean(short key, boolean value, BooleanBooleanUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -938,18 +938,18 @@ public AbstractShort2BooleanMap setDefaultReturnValue(boolean v) { @Override public boolean computeBoolean(short key, ShortBooleanUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeBoolean(key, mappingFunction); } } @Override - public boolean computeBooleanNonDefault(short key, ShortBooleanUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeBooleanNonDefault(key, mappingFunction); } } - @Override public boolean computeBooleanIfAbsent(short key, ShortPredicate mappingFunction) { synchronized(mutex) { return map.computeBooleanIfAbsent(key, mappingFunction); } } @Override - public boolean computeBooleanIfAbsentNonDefault(short key, ShortPredicate mappingFunction) { synchronized(mutex) { return map.computeBooleanIfAbsentNonDefault(key, mappingFunction); } } - @Override public boolean computeBooleanIfPresent(short key, ShortBooleanUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeBooleanIfPresent(key, mappingFunction); } } @Override - public boolean computeBooleanIfPresentNonDefault(short key, ShortBooleanUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeBooleanIfPresentNonDefault(key, mappingFunction); } } - @Override public boolean supplyBooleanIfAbsent(short key, BooleanSupplier valueProvider) { synchronized(mutex) { return map.supplyBooleanIfAbsent(key, valueProvider); } } @Override + public boolean computeBooleanNonDefault(short key, ShortBooleanUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeBooleanNonDefault(key, mappingFunction); } } + @Override + public boolean computeBooleanIfAbsentNonDefault(short key, ShortPredicate mappingFunction) { synchronized(mutex) { return map.computeBooleanIfAbsentNonDefault(key, mappingFunction); } } + @Override + public boolean computeBooleanIfPresentNonDefault(short key, ShortBooleanUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeBooleanIfPresentNonDefault(key, mappingFunction); } } + @Override public boolean supplyBooleanIfAbsentNonDefault(short key, BooleanSupplier valueProvider) { synchronized(mutex) { return map.supplyBooleanIfAbsentNonDefault(key, valueProvider); } } @Override public boolean mergeBoolean(short key, boolean value, BooleanBooleanUnaryOperator mappingFunction) { synchronized(mutex) { return map.mergeBoolean(key, value, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/shorts/utils/maps/Short2ByteMaps.java b/src/main/java/speiger/src/collections/shorts/utils/maps/Short2ByteMaps.java index f9ea6d26..62405e45 100644 --- a/src/main/java/speiger/src/collections/shorts/utils/maps/Short2ByteMaps.java +++ b/src/main/java/speiger/src/collections/shorts/utils/maps/Short2ByteMaps.java @@ -250,18 +250,18 @@ public static class SingletonMap extends AbstractShort2ByteMap { @Override public byte computeByte(short key, ShortByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteNonDefault(short key, ShortByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte computeByteIfAbsent(short key, Short2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteIfAbsentNonDefault(short key, Short2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte computeByteIfPresent(short key, ShortByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteIfPresentNonDefault(short key, ShortByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte supplyByteIfAbsent(short key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public byte computeByteNonDefault(short key, ShortByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public byte computeByteIfAbsentNonDefault(short key, Short2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public byte computeByteIfPresentNonDefault(short key, ShortByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public byte supplyByteIfAbsentNonDefault(short key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public byte mergeByte(short key, byte value, ByteByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -312,18 +312,18 @@ public static class EmptyMap extends AbstractShort2ByteMap { @Override public byte computeByte(short key, ShortByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteNonDefault(short key, ShortByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte computeByteIfAbsent(short key, Short2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteIfAbsentNonDefault(short key, Short2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte computeByteIfPresent(short key, ShortByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteIfPresentNonDefault(short key, ShortByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte supplyByteIfAbsent(short key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public byte computeByteNonDefault(short key, ShortByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public byte computeByteIfAbsentNonDefault(short key, Short2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public byte computeByteIfPresentNonDefault(short key, ShortByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public byte supplyByteIfAbsentNonDefault(short key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public byte mergeByte(short key, byte value, ByteByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -547,18 +547,18 @@ public byte get(short key) { @Override public byte computeByte(short key, ShortByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteNonDefault(short key, ShortByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte computeByteIfAbsent(short key, Short2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteIfAbsentNonDefault(short key, Short2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte computeByteIfPresent(short key, ShortByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public byte computeByteIfPresentNonDefault(short key, ShortByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public byte supplyByteIfAbsent(short key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public byte computeByteNonDefault(short key, ShortByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public byte computeByteIfAbsentNonDefault(short key, Short2ByteFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public byte computeByteIfPresentNonDefault(short key, ShortByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public byte supplyByteIfAbsentNonDefault(short key, ByteSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public byte mergeByte(short key, byte value, ByteByteUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -955,18 +955,18 @@ public AbstractShort2ByteMap setDefaultReturnValue(byte v) { @Override public byte computeByte(short key, ShortByteUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeByte(key, mappingFunction); } } @Override - public byte computeByteNonDefault(short key, ShortByteUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeByteNonDefault(key, mappingFunction); } } - @Override public byte computeByteIfAbsent(short key, Short2ByteFunction mappingFunction) { synchronized(mutex) { return map.computeByteIfAbsent(key, mappingFunction); } } @Override - public byte computeByteIfAbsentNonDefault(short key, Short2ByteFunction mappingFunction) { synchronized(mutex) { return map.computeByteIfAbsentNonDefault(key, mappingFunction); } } - @Override public byte computeByteIfPresent(short key, ShortByteUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeByteIfPresent(key, mappingFunction); } } @Override - public byte computeByteIfPresentNonDefault(short key, ShortByteUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeByteIfPresentNonDefault(key, mappingFunction); } } - @Override public byte supplyByteIfAbsent(short key, ByteSupplier valueProvider) { synchronized(mutex) { return map.supplyByteIfAbsent(key, valueProvider); } } @Override + public byte computeByteNonDefault(short key, ShortByteUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeByteNonDefault(key, mappingFunction); } } + @Override + public byte computeByteIfAbsentNonDefault(short key, Short2ByteFunction mappingFunction) { synchronized(mutex) { return map.computeByteIfAbsentNonDefault(key, mappingFunction); } } + @Override + public byte computeByteIfPresentNonDefault(short key, ShortByteUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeByteIfPresentNonDefault(key, mappingFunction); } } + @Override public byte supplyByteIfAbsentNonDefault(short key, ByteSupplier valueProvider) { synchronized(mutex) { return map.supplyByteIfAbsentNonDefault(key, valueProvider); } } @Override public byte mergeByte(short key, byte value, ByteByteUnaryOperator mappingFunction) { synchronized(mutex) { return map.mergeByte(key, value, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/shorts/utils/maps/Short2CharMaps.java b/src/main/java/speiger/src/collections/shorts/utils/maps/Short2CharMaps.java index be0b814f..2437a1f0 100644 --- a/src/main/java/speiger/src/collections/shorts/utils/maps/Short2CharMaps.java +++ b/src/main/java/speiger/src/collections/shorts/utils/maps/Short2CharMaps.java @@ -250,18 +250,18 @@ public static class SingletonMap extends AbstractShort2CharMap { @Override public char computeChar(short key, ShortCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharNonDefault(short key, ShortCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char computeCharIfAbsent(short key, Short2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharIfAbsentNonDefault(short key, Short2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char computeCharIfPresent(short key, ShortCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharIfPresentNonDefault(short key, ShortCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char supplyCharIfAbsent(short key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public char computeCharNonDefault(short key, ShortCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public char computeCharIfAbsentNonDefault(short key, Short2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public char computeCharIfPresentNonDefault(short key, ShortCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public char supplyCharIfAbsentNonDefault(short key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public char mergeChar(short key, char value, CharCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -312,18 +312,18 @@ public static class EmptyMap extends AbstractShort2CharMap { @Override public char computeChar(short key, ShortCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharNonDefault(short key, ShortCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char computeCharIfAbsent(short key, Short2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharIfAbsentNonDefault(short key, Short2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char computeCharIfPresent(short key, ShortCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharIfPresentNonDefault(short key, ShortCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char supplyCharIfAbsent(short key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public char computeCharNonDefault(short key, ShortCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public char computeCharIfAbsentNonDefault(short key, Short2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public char computeCharIfPresentNonDefault(short key, ShortCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public char supplyCharIfAbsentNonDefault(short key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public char mergeChar(short key, char value, CharCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -547,18 +547,18 @@ public char get(short key) { @Override public char computeChar(short key, ShortCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharNonDefault(short key, ShortCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char computeCharIfAbsent(short key, Short2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharIfAbsentNonDefault(short key, Short2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char computeCharIfPresent(short key, ShortCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public char computeCharIfPresentNonDefault(short key, ShortCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public char supplyCharIfAbsent(short key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public char computeCharNonDefault(short key, ShortCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public char computeCharIfAbsentNonDefault(short key, Short2CharFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public char computeCharIfPresentNonDefault(short key, ShortCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public char supplyCharIfAbsentNonDefault(short key, CharSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public char mergeChar(short key, char value, CharCharUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -955,18 +955,18 @@ public AbstractShort2CharMap setDefaultReturnValue(char v) { @Override public char computeChar(short key, ShortCharUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeChar(key, mappingFunction); } } @Override - public char computeCharNonDefault(short key, ShortCharUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeCharNonDefault(key, mappingFunction); } } - @Override public char computeCharIfAbsent(short key, Short2CharFunction mappingFunction) { synchronized(mutex) { return map.computeCharIfAbsent(key, mappingFunction); } } @Override - public char computeCharIfAbsentNonDefault(short key, Short2CharFunction mappingFunction) { synchronized(mutex) { return map.computeCharIfAbsentNonDefault(key, mappingFunction); } } - @Override public char computeCharIfPresent(short key, ShortCharUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeCharIfPresent(key, mappingFunction); } } @Override - public char computeCharIfPresentNonDefault(short key, ShortCharUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeCharIfPresentNonDefault(key, mappingFunction); } } - @Override public char supplyCharIfAbsent(short key, CharSupplier valueProvider) { synchronized(mutex) { return map.supplyCharIfAbsent(key, valueProvider); } } @Override + public char computeCharNonDefault(short key, ShortCharUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeCharNonDefault(key, mappingFunction); } } + @Override + public char computeCharIfAbsentNonDefault(short key, Short2CharFunction mappingFunction) { synchronized(mutex) { return map.computeCharIfAbsentNonDefault(key, mappingFunction); } } + @Override + public char computeCharIfPresentNonDefault(short key, ShortCharUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeCharIfPresentNonDefault(key, mappingFunction); } } + @Override public char supplyCharIfAbsentNonDefault(short key, CharSupplier valueProvider) { synchronized(mutex) { return map.supplyCharIfAbsentNonDefault(key, valueProvider); } } @Override public char mergeChar(short key, char value, CharCharUnaryOperator mappingFunction) { synchronized(mutex) { return map.mergeChar(key, value, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/shorts/utils/maps/Short2DoubleMaps.java b/src/main/java/speiger/src/collections/shorts/utils/maps/Short2DoubleMaps.java index b2796ee8..283580f6 100644 --- a/src/main/java/speiger/src/collections/shorts/utils/maps/Short2DoubleMaps.java +++ b/src/main/java/speiger/src/collections/shorts/utils/maps/Short2DoubleMaps.java @@ -250,18 +250,18 @@ public static class SingletonMap extends AbstractShort2DoubleMap { @Override public double computeDouble(short key, ShortDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleNonDefault(short key, ShortDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double computeDoubleIfAbsent(short key, Short2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleIfAbsentNonDefault(short key, Short2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double computeDoubleIfPresent(short key, ShortDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleIfPresentNonDefault(short key, ShortDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double supplyDoubleIfAbsent(short key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public double computeDoubleNonDefault(short key, ShortDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public double computeDoubleIfAbsentNonDefault(short key, Short2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public double computeDoubleIfPresentNonDefault(short key, ShortDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public double supplyDoubleIfAbsentNonDefault(short key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public double mergeDouble(short key, double value, DoubleDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -312,18 +312,18 @@ public static class EmptyMap extends AbstractShort2DoubleMap { @Override public double computeDouble(short key, ShortDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleNonDefault(short key, ShortDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double computeDoubleIfAbsent(short key, Short2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleIfAbsentNonDefault(short key, Short2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double computeDoubleIfPresent(short key, ShortDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleIfPresentNonDefault(short key, ShortDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double supplyDoubleIfAbsent(short key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public double computeDoubleNonDefault(short key, ShortDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public double computeDoubleIfAbsentNonDefault(short key, Short2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public double computeDoubleIfPresentNonDefault(short key, ShortDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public double supplyDoubleIfAbsentNonDefault(short key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public double mergeDouble(short key, double value, DoubleDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -547,18 +547,18 @@ public double get(short key) { @Override public double computeDouble(short key, ShortDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleNonDefault(short key, ShortDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double computeDoubleIfAbsent(short key, Short2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleIfAbsentNonDefault(short key, Short2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double computeDoubleIfPresent(short key, ShortDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public double computeDoubleIfPresentNonDefault(short key, ShortDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public double supplyDoubleIfAbsent(short key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public double computeDoubleNonDefault(short key, ShortDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public double computeDoubleIfAbsentNonDefault(short key, Short2DoubleFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public double computeDoubleIfPresentNonDefault(short key, ShortDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public double supplyDoubleIfAbsentNonDefault(short key, DoubleSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public double mergeDouble(short key, double value, DoubleDoubleUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -955,18 +955,18 @@ public AbstractShort2DoubleMap setDefaultReturnValue(double v) { @Override public double computeDouble(short key, ShortDoubleUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeDouble(key, mappingFunction); } } @Override - public double computeDoubleNonDefault(short key, ShortDoubleUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeDoubleNonDefault(key, mappingFunction); } } - @Override public double computeDoubleIfAbsent(short key, Short2DoubleFunction mappingFunction) { synchronized(mutex) { return map.computeDoubleIfAbsent(key, mappingFunction); } } @Override - public double computeDoubleIfAbsentNonDefault(short key, Short2DoubleFunction mappingFunction) { synchronized(mutex) { return map.computeDoubleIfAbsentNonDefault(key, mappingFunction); } } - @Override public double computeDoubleIfPresent(short key, ShortDoubleUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeDoubleIfPresent(key, mappingFunction); } } @Override - public double computeDoubleIfPresentNonDefault(short key, ShortDoubleUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeDoubleIfPresentNonDefault(key, mappingFunction); } } - @Override public double supplyDoubleIfAbsent(short key, DoubleSupplier valueProvider) { synchronized(mutex) { return map.supplyDoubleIfAbsent(key, valueProvider); } } @Override + public double computeDoubleNonDefault(short key, ShortDoubleUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeDoubleNonDefault(key, mappingFunction); } } + @Override + public double computeDoubleIfAbsentNonDefault(short key, Short2DoubleFunction mappingFunction) { synchronized(mutex) { return map.computeDoubleIfAbsentNonDefault(key, mappingFunction); } } + @Override + public double computeDoubleIfPresentNonDefault(short key, ShortDoubleUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeDoubleIfPresentNonDefault(key, mappingFunction); } } + @Override public double supplyDoubleIfAbsentNonDefault(short key, DoubleSupplier valueProvider) { synchronized(mutex) { return map.supplyDoubleIfAbsentNonDefault(key, valueProvider); } } @Override public double mergeDouble(short key, double value, DoubleDoubleUnaryOperator mappingFunction) { synchronized(mutex) { return map.mergeDouble(key, value, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/shorts/utils/maps/Short2FloatMaps.java b/src/main/java/speiger/src/collections/shorts/utils/maps/Short2FloatMaps.java index 0428e7de..b2c6a8bb 100644 --- a/src/main/java/speiger/src/collections/shorts/utils/maps/Short2FloatMaps.java +++ b/src/main/java/speiger/src/collections/shorts/utils/maps/Short2FloatMaps.java @@ -250,18 +250,18 @@ public static class SingletonMap extends AbstractShort2FloatMap { @Override public float computeFloat(short key, ShortFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatNonDefault(short key, ShortFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float computeFloatIfAbsent(short key, Short2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatIfAbsentNonDefault(short key, Short2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float computeFloatIfPresent(short key, ShortFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatIfPresentNonDefault(short key, ShortFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float supplyFloatIfAbsent(short key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public float computeFloatNonDefault(short key, ShortFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public float computeFloatIfAbsentNonDefault(short key, Short2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public float computeFloatIfPresentNonDefault(short key, ShortFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public float supplyFloatIfAbsentNonDefault(short key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public float mergeFloat(short key, float value, FloatFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -312,18 +312,18 @@ public static class EmptyMap extends AbstractShort2FloatMap { @Override public float computeFloat(short key, ShortFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatNonDefault(short key, ShortFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float computeFloatIfAbsent(short key, Short2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatIfAbsentNonDefault(short key, Short2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float computeFloatIfPresent(short key, ShortFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatIfPresentNonDefault(short key, ShortFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float supplyFloatIfAbsent(short key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public float computeFloatNonDefault(short key, ShortFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public float computeFloatIfAbsentNonDefault(short key, Short2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public float computeFloatIfPresentNonDefault(short key, ShortFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public float supplyFloatIfAbsentNonDefault(short key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public float mergeFloat(short key, float value, FloatFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -547,18 +547,18 @@ public float get(short key) { @Override public float computeFloat(short key, ShortFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatNonDefault(short key, ShortFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float computeFloatIfAbsent(short key, Short2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatIfAbsentNonDefault(short key, Short2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float computeFloatIfPresent(short key, ShortFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public float computeFloatIfPresentNonDefault(short key, ShortFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public float supplyFloatIfAbsent(short key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public float computeFloatNonDefault(short key, ShortFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public float computeFloatIfAbsentNonDefault(short key, Short2FloatFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public float computeFloatIfPresentNonDefault(short key, ShortFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public float supplyFloatIfAbsentNonDefault(short key, FloatSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public float mergeFloat(short key, float value, FloatFloatUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -955,18 +955,18 @@ public AbstractShort2FloatMap setDefaultReturnValue(float v) { @Override public float computeFloat(short key, ShortFloatUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeFloat(key, mappingFunction); } } @Override - public float computeFloatNonDefault(short key, ShortFloatUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeFloatNonDefault(key, mappingFunction); } } - @Override public float computeFloatIfAbsent(short key, Short2FloatFunction mappingFunction) { synchronized(mutex) { return map.computeFloatIfAbsent(key, mappingFunction); } } @Override - public float computeFloatIfAbsentNonDefault(short key, Short2FloatFunction mappingFunction) { synchronized(mutex) { return map.computeFloatIfAbsentNonDefault(key, mappingFunction); } } - @Override public float computeFloatIfPresent(short key, ShortFloatUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeFloatIfPresent(key, mappingFunction); } } @Override - public float computeFloatIfPresentNonDefault(short key, ShortFloatUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeFloatIfPresentNonDefault(key, mappingFunction); } } - @Override public float supplyFloatIfAbsent(short key, FloatSupplier valueProvider) { synchronized(mutex) { return map.supplyFloatIfAbsent(key, valueProvider); } } @Override + public float computeFloatNonDefault(short key, ShortFloatUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeFloatNonDefault(key, mappingFunction); } } + @Override + public float computeFloatIfAbsentNonDefault(short key, Short2FloatFunction mappingFunction) { synchronized(mutex) { return map.computeFloatIfAbsentNonDefault(key, mappingFunction); } } + @Override + public float computeFloatIfPresentNonDefault(short key, ShortFloatUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeFloatIfPresentNonDefault(key, mappingFunction); } } + @Override public float supplyFloatIfAbsentNonDefault(short key, FloatSupplier valueProvider) { synchronized(mutex) { return map.supplyFloatIfAbsentNonDefault(key, valueProvider); } } @Override public float mergeFloat(short key, float value, FloatFloatUnaryOperator mappingFunction) { synchronized(mutex) { return map.mergeFloat(key, value, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/shorts/utils/maps/Short2IntMaps.java b/src/main/java/speiger/src/collections/shorts/utils/maps/Short2IntMaps.java index efb32102..95c7d24b 100644 --- a/src/main/java/speiger/src/collections/shorts/utils/maps/Short2IntMaps.java +++ b/src/main/java/speiger/src/collections/shorts/utils/maps/Short2IntMaps.java @@ -250,18 +250,18 @@ public static class SingletonMap extends AbstractShort2IntMap { @Override public int computeInt(short key, ShortIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntNonDefault(short key, ShortIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int computeIntIfAbsent(short key, Short2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntIfAbsentNonDefault(short key, Short2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int computeIntIfPresent(short key, ShortIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntIfPresentNonDefault(short key, ShortIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int supplyIntIfAbsent(short key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public int computeIntNonDefault(short key, ShortIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public int computeIntIfAbsentNonDefault(short key, Short2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public int computeIntIfPresentNonDefault(short key, ShortIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public int supplyIntIfAbsentNonDefault(short key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public int mergeInt(short key, int value, IntIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -312,18 +312,18 @@ public static class EmptyMap extends AbstractShort2IntMap { @Override public int computeInt(short key, ShortIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntNonDefault(short key, ShortIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int computeIntIfAbsent(short key, Short2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntIfAbsentNonDefault(short key, Short2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int computeIntIfPresent(short key, ShortIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntIfPresentNonDefault(short key, ShortIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int supplyIntIfAbsent(short key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public int computeIntNonDefault(short key, ShortIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public int computeIntIfAbsentNonDefault(short key, Short2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public int computeIntIfPresentNonDefault(short key, ShortIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public int supplyIntIfAbsentNonDefault(short key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public int mergeInt(short key, int value, IntIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -547,18 +547,18 @@ public int get(short key) { @Override public int computeInt(short key, ShortIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntNonDefault(short key, ShortIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int computeIntIfAbsent(short key, Short2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntIfAbsentNonDefault(short key, Short2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int computeIntIfPresent(short key, ShortIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public int computeIntIfPresentNonDefault(short key, ShortIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public int supplyIntIfAbsent(short key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public int computeIntNonDefault(short key, ShortIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public int computeIntIfAbsentNonDefault(short key, Short2IntFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public int computeIntIfPresentNonDefault(short key, ShortIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public int supplyIntIfAbsentNonDefault(short key, IntSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public int mergeInt(short key, int value, IntIntUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -955,18 +955,18 @@ public AbstractShort2IntMap setDefaultReturnValue(int v) { @Override public int computeInt(short key, ShortIntUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeInt(key, mappingFunction); } } @Override - public int computeIntNonDefault(short key, ShortIntUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeIntNonDefault(key, mappingFunction); } } - @Override public int computeIntIfAbsent(short key, Short2IntFunction mappingFunction) { synchronized(mutex) { return map.computeIntIfAbsent(key, mappingFunction); } } @Override - public int computeIntIfAbsentNonDefault(short key, Short2IntFunction mappingFunction) { synchronized(mutex) { return map.computeIntIfAbsentNonDefault(key, mappingFunction); } } - @Override public int computeIntIfPresent(short key, ShortIntUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeIntIfPresent(key, mappingFunction); } } @Override - public int computeIntIfPresentNonDefault(short key, ShortIntUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeIntIfPresentNonDefault(key, mappingFunction); } } - @Override public int supplyIntIfAbsent(short key, IntSupplier valueProvider) { synchronized(mutex) { return map.supplyIntIfAbsent(key, valueProvider); } } @Override + public int computeIntNonDefault(short key, ShortIntUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeIntNonDefault(key, mappingFunction); } } + @Override + public int computeIntIfAbsentNonDefault(short key, Short2IntFunction mappingFunction) { synchronized(mutex) { return map.computeIntIfAbsentNonDefault(key, mappingFunction); } } + @Override + public int computeIntIfPresentNonDefault(short key, ShortIntUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeIntIfPresentNonDefault(key, mappingFunction); } } + @Override public int supplyIntIfAbsentNonDefault(short key, IntSupplier valueProvider) { synchronized(mutex) { return map.supplyIntIfAbsentNonDefault(key, valueProvider); } } @Override public int mergeInt(short key, int value, IntIntUnaryOperator mappingFunction) { synchronized(mutex) { return map.mergeInt(key, value, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/shorts/utils/maps/Short2LongMaps.java b/src/main/java/speiger/src/collections/shorts/utils/maps/Short2LongMaps.java index 9e56bf12..f0e8323b 100644 --- a/src/main/java/speiger/src/collections/shorts/utils/maps/Short2LongMaps.java +++ b/src/main/java/speiger/src/collections/shorts/utils/maps/Short2LongMaps.java @@ -250,18 +250,18 @@ public static class SingletonMap extends AbstractShort2LongMap { @Override public long computeLong(short key, ShortLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongNonDefault(short key, ShortLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long computeLongIfAbsent(short key, Short2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongIfAbsentNonDefault(short key, Short2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long computeLongIfPresent(short key, ShortLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongIfPresentNonDefault(short key, ShortLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long supplyLongIfAbsent(short key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public long computeLongNonDefault(short key, ShortLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public long computeLongIfAbsentNonDefault(short key, Short2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public long computeLongIfPresentNonDefault(short key, ShortLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public long supplyLongIfAbsentNonDefault(short key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public long mergeLong(short key, long value, LongLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -312,18 +312,18 @@ public static class EmptyMap extends AbstractShort2LongMap { @Override public long computeLong(short key, ShortLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongNonDefault(short key, ShortLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long computeLongIfAbsent(short key, Short2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongIfAbsentNonDefault(short key, Short2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long computeLongIfPresent(short key, ShortLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongIfPresentNonDefault(short key, ShortLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long supplyLongIfAbsent(short key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public long computeLongNonDefault(short key, ShortLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public long computeLongIfAbsentNonDefault(short key, Short2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public long computeLongIfPresentNonDefault(short key, ShortLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public long supplyLongIfAbsentNonDefault(short key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public long mergeLong(short key, long value, LongLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -547,18 +547,18 @@ public long get(short key) { @Override public long computeLong(short key, ShortLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongNonDefault(short key, ShortLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long computeLongIfAbsent(short key, Short2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongIfAbsentNonDefault(short key, Short2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long computeLongIfPresent(short key, ShortLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public long computeLongIfPresentNonDefault(short key, ShortLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public long supplyLongIfAbsent(short key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public long computeLongNonDefault(short key, ShortLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public long computeLongIfAbsentNonDefault(short key, Short2LongFunction mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public long computeLongIfPresentNonDefault(short key, ShortLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public long supplyLongIfAbsentNonDefault(short key, LongSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public long mergeLong(short key, long value, LongLongUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -955,18 +955,18 @@ public AbstractShort2LongMap setDefaultReturnValue(long v) { @Override public long computeLong(short key, ShortLongUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeLong(key, mappingFunction); } } @Override - public long computeLongNonDefault(short key, ShortLongUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeLongNonDefault(key, mappingFunction); } } - @Override public long computeLongIfAbsent(short key, Short2LongFunction mappingFunction) { synchronized(mutex) { return map.computeLongIfAbsent(key, mappingFunction); } } @Override - public long computeLongIfAbsentNonDefault(short key, Short2LongFunction mappingFunction) { synchronized(mutex) { return map.computeLongIfAbsentNonDefault(key, mappingFunction); } } - @Override public long computeLongIfPresent(short key, ShortLongUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeLongIfPresent(key, mappingFunction); } } @Override - public long computeLongIfPresentNonDefault(short key, ShortLongUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeLongIfPresentNonDefault(key, mappingFunction); } } - @Override public long supplyLongIfAbsent(short key, LongSupplier valueProvider) { synchronized(mutex) { return map.supplyLongIfAbsent(key, valueProvider); } } @Override + public long computeLongNonDefault(short key, ShortLongUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeLongNonDefault(key, mappingFunction); } } + @Override + public long computeLongIfAbsentNonDefault(short key, Short2LongFunction mappingFunction) { synchronized(mutex) { return map.computeLongIfAbsentNonDefault(key, mappingFunction); } } + @Override + public long computeLongIfPresentNonDefault(short key, ShortLongUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeLongIfPresentNonDefault(key, mappingFunction); } } + @Override public long supplyLongIfAbsentNonDefault(short key, LongSupplier valueProvider) { synchronized(mutex) { return map.supplyLongIfAbsentNonDefault(key, valueProvider); } } @Override public long mergeLong(short key, long value, LongLongUnaryOperator mappingFunction) { synchronized(mutex) { return map.mergeLong(key, value, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/shorts/utils/maps/Short2ObjectMaps.java b/src/main/java/speiger/src/collections/shorts/utils/maps/Short2ObjectMaps.java index c0e8c4f6..694b1fb3 100644 --- a/src/main/java/speiger/src/collections/shorts/utils/maps/Short2ObjectMaps.java +++ b/src/main/java/speiger/src/collections/shorts/utils/maps/Short2ObjectMaps.java @@ -266,20 +266,12 @@ public static class SingletonMap extends AbstractShort2ObjectMap { @Override public V compute(short key, ShortObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeNonDefault(short key, ShortObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V computeIfAbsent(short key, ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeIfAbsentNonDefault(short key, ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V computeIfPresent(short key, ShortObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeIfPresentNonDefault(short key, ShortObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V supplyIfAbsent(short key, ObjectSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public V supplyIfAbsentNonDefault(short key, ObjectSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public V merge(short key, V value, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override public void mergeAll(Short2ObjectMap m, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -325,20 +317,12 @@ public static class EmptyMap extends AbstractShort2ObjectMap { @Override public V compute(short key, ShortObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeNonDefault(short key, ShortObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V computeIfAbsent(short key, ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeIfAbsentNonDefault(short key, ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V computeIfPresent(short key, ShortObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeIfPresentNonDefault(short key, ShortObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V supplyIfAbsent(short key, ObjectSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public V supplyIfAbsentNonDefault(short key, ObjectSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public V merge(short key, V value, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override public void mergeAll(Short2ObjectMap m, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -561,20 +545,12 @@ public V get(short key) { @Override public V compute(short key, ShortObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeNonDefault(short key, ShortObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V computeIfAbsent(short key, ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeIfAbsentNonDefault(short key, ShortFunction mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V computeIfPresent(short key, ShortObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public V computeIfPresentNonDefault(short key, ShortObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public V supplyIfAbsent(short key, ObjectSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override - public V supplyIfAbsentNonDefault(short key, ObjectSupplier valueProvider) { throw new UnsupportedOperationException(); } - @Override public V merge(short key, V value, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override public void mergeAll(Short2ObjectMap m, ObjectObjectUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -968,20 +944,12 @@ public AbstractShort2ObjectMap setDefaultReturnValue(V v) { @Override public V compute(short key, ShortObjectUnaryOperator mappingFunction) { synchronized(mutex) { return map.compute(key, mappingFunction); } } @Override - public V computeNonDefault(short key, ShortObjectUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeNonDefault(key, mappingFunction); } } - @Override public V computeIfAbsent(short key, ShortFunction mappingFunction) { synchronized(mutex) { return map.computeIfAbsent(key, mappingFunction); } } @Override - public V computeIfAbsentNonDefault(short key, ShortFunction mappingFunction) { synchronized(mutex) { return map.computeIfAbsentNonDefault(key, mappingFunction); } } - @Override public V computeIfPresent(short key, ShortObjectUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeIfPresent(key, mappingFunction); } } @Override - public V computeIfPresentNonDefault(short key, ShortObjectUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeIfPresentNonDefault(key, mappingFunction); } } - @Override public V supplyIfAbsent(short key, ObjectSupplier valueProvider) { synchronized(mutex) { return map.supplyIfAbsent(key, valueProvider); } } @Override - public V supplyIfAbsentNonDefault(short key, ObjectSupplier valueProvider) { synchronized(mutex) { return map.supplyIfAbsentNonDefault(key, valueProvider); } } - @Override public V merge(short key, V value, ObjectObjectUnaryOperator mappingFunction) { synchronized(mutex) { return map.merge(key, value, mappingFunction); } } @Override public void mergeAll(Short2ObjectMap m, ObjectObjectUnaryOperator mappingFunction) { synchronized(mutex) { map.mergeAll(m, mappingFunction); } } diff --git a/src/main/java/speiger/src/collections/shorts/utils/maps/Short2ShortMaps.java b/src/main/java/speiger/src/collections/shorts/utils/maps/Short2ShortMaps.java index 27a0a110..07b09540 100644 --- a/src/main/java/speiger/src/collections/shorts/utils/maps/Short2ShortMaps.java +++ b/src/main/java/speiger/src/collections/shorts/utils/maps/Short2ShortMaps.java @@ -249,18 +249,18 @@ public static class SingletonMap extends AbstractShort2ShortMap { @Override public short computeShort(short key, ShortShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortNonDefault(short key, ShortShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short computeShortIfAbsent(short key, ShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortIfAbsentNonDefault(short key, ShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short computeShortIfPresent(short key, ShortShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortIfPresentNonDefault(short key, ShortShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short supplyShortIfAbsent(short key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public short computeShortNonDefault(short key, ShortShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public short computeShortIfAbsentNonDefault(short key, ShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public short computeShortIfPresentNonDefault(short key, ShortShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public short supplyShortIfAbsentNonDefault(short key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public short mergeShort(short key, short value, ShortShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -311,18 +311,18 @@ public static class EmptyMap extends AbstractShort2ShortMap { @Override public short computeShort(short key, ShortShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortNonDefault(short key, ShortShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short computeShortIfAbsent(short key, ShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortIfAbsentNonDefault(short key, ShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short computeShortIfPresent(short key, ShortShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortIfPresentNonDefault(short key, ShortShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short supplyShortIfAbsent(short key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public short computeShortNonDefault(short key, ShortShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public short computeShortIfAbsentNonDefault(short key, ShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public short computeShortIfPresentNonDefault(short key, ShortShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public short supplyShortIfAbsentNonDefault(short key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public short mergeShort(short key, short value, ShortShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -546,18 +546,18 @@ public short get(short key) { @Override public short computeShort(short key, ShortShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortNonDefault(short key, ShortShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short computeShortIfAbsent(short key, ShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortIfAbsentNonDefault(short key, ShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short computeShortIfPresent(short key, ShortShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @Override - public short computeShortIfPresentNonDefault(short key, ShortShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } - @Override public short supplyShortIfAbsent(short key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override + public short computeShortNonDefault(short key, ShortShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public short computeShortIfAbsentNonDefault(short key, ShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override + public short computeShortIfPresentNonDefault(short key, ShortShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } + @Override public short supplyShortIfAbsentNonDefault(short key, ShortSupplier valueProvider) { throw new UnsupportedOperationException(); } @Override public short mergeShort(short key, short value, ShortShortUnaryOperator mappingFunction) { throw new UnsupportedOperationException(); } @@ -954,18 +954,18 @@ public AbstractShort2ShortMap setDefaultReturnValue(short v) { @Override public short computeShort(short key, ShortShortUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeShort(key, mappingFunction); } } @Override - public short computeShortNonDefault(short key, ShortShortUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeShortNonDefault(key, mappingFunction); } } - @Override public short computeShortIfAbsent(short key, ShortUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeShortIfAbsent(key, mappingFunction); } } @Override - public short computeShortIfAbsentNonDefault(short key, ShortUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeShortIfAbsentNonDefault(key, mappingFunction); } } - @Override public short computeShortIfPresent(short key, ShortShortUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeShortIfPresent(key, mappingFunction); } } @Override - public short computeShortIfPresentNonDefault(short key, ShortShortUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeShortIfPresentNonDefault(key, mappingFunction); } } - @Override public short supplyShortIfAbsent(short key, ShortSupplier valueProvider) { synchronized(mutex) { return map.supplyShortIfAbsent(key, valueProvider); } } @Override + public short computeShortNonDefault(short key, ShortShortUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeShortNonDefault(key, mappingFunction); } } + @Override + public short computeShortIfAbsentNonDefault(short key, ShortUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeShortIfAbsentNonDefault(key, mappingFunction); } } + @Override + public short computeShortIfPresentNonDefault(short key, ShortShortUnaryOperator mappingFunction) { synchronized(mutex) { return map.computeShortIfPresentNonDefault(key, mappingFunction); } } + @Override public short supplyShortIfAbsentNonDefault(short key, ShortSupplier valueProvider) { synchronized(mutex) { return map.supplyShortIfAbsentNonDefault(key, valueProvider); } } @Override public short mergeShort(short key, short value, ShortShortUnaryOperator mappingFunction) { synchronized(mutex) { return map.mergeShort(key, value, mappingFunction); } }