public override long UpdateValue(long key, long initialValueIfAbsent, LongToLongFunction function) { ++_modCount; if (IsSentinelKey(key)) { return(UpdateValueForSentinelKey(key, initialValueIfAbsent, function)); } //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int idx = indexOf(key); int idx = IndexOf(key); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final long keyAtIdx = getKeyAt(idx); long keyAtIdx = GetKeyAt(idx); if (keyAtIdx == key) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final long newValue = function.applyAsLong(getValueAt(idx)); long newValue = function.applyAsLong(GetValueAt(idx)); SetValueAt(idx, newValue); return(newValue); } if (keyAtIdx == REMOVED_KEY) { --_removals; } //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final long value = function.applyAsLong(initialValueIfAbsent); long value = function.applyAsLong(initialValueIfAbsent); SetKeyAt(idx, key); SetValueAt(idx, value); ++_entriesInMemory; if (_entriesInMemory >= _resizeOccupancyThreshold) { GrowAndRehash(); } return(value); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void getIfAbsentPutWithKey() internal virtual void getIfAbsentPutWithKey() { //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @SuppressWarnings("Convert2Lambda") final org.eclipse.collections.api.block.function.primitive.LongToLongFunction function = spy(new org.eclipse.collections.api.block.function.primitive.LongToLongFunction() //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': LongToLongFunction function = spy(new LongToLongFunctionAnonymousInnerClass(this)); assertEquals(10, _map.getIfAbsentPutWithKey(0, function)); assertEquals(10, _map.getIfAbsentPutWithKey(0, function)); assertEquals(11, _map.getIfAbsentPutWithKey(1, function)); assertEquals(11, _map.getIfAbsentPutWithKey(1, function)); assertEquals(12, _map.getIfAbsentPutWithKey(2, function)); assertEquals(12, _map.getIfAbsentPutWithKey(2, function)); verify(function).valueOf(eq(0L)); verify(function).valueOf(eq(1L)); verify(function).valueOf(eq(2L)); verifyNoMoreInteractions(function); }
private long UpdateValueForSentinelKey(long key, long initialValueIfAbsent, LongToLongFunction function) { if (key == EMPTY_KEY) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final long newValue = function.applyAsLong(hasZeroKey ? zeroValue : initialValueIfAbsent); long newValue = function.applyAsLong(_hasZeroKey ? _zeroValue : initialValueIfAbsent); _hasZeroKey = true; _zeroValue = newValue; return(newValue); } if (key == REMOVED_KEY) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final long newValue = function.applyAsLong(hasOneKey ? oneValue : initialValueIfAbsent); long newValue = function.applyAsLong(_hasOneKey ? _oneValue : initialValueIfAbsent); _hasOneKey = true; _oneValue = newValue; return(newValue); } throw new AssertionError("Invalid sentinel key: " + key); }
public override long GetIfAbsentPutWithKey(long key, LongToLongFunction function) { return(getIfAbsentPut(key, () => function.valueOf(key))); }