/** * Get and return the value in the Map at the specified key, or if there is no value at the key, return the result * of evaluating the specified {@link Function0}, and put that value in the map at the specified key. * <p> * This method handles the {@code null}-value-at-key case correctly. */ public static <K, V> V getIfAbsentPut(Map<K, V> map, K key, Function0<? extends V> instanceBlock) { if (map instanceof MutableMap) { return ((MutableMap<K, V>) map).getIfAbsentPut(key, instanceBlock); } V result = map.get(key); if (MapIterate.isAbsent(result, map, key)) { result = instanceBlock.value(); map.put(key, result); } return result; }
/** * Get and return the value in the Map at the specified key, or if there is no value at the key, return the result * of evaluating the specified {@link Function0}, and put that value in the map at the specified key. * <p> * This method handles the {@code null}-value-at-key case correctly. */ public static <K, V> V getIfAbsentPut(Map<K, V> map, K key, Function0<? extends V> instanceBlock) { if (map instanceof MutableMap) { return ((MutableMap<K, V>) map).getIfAbsentPut(key, instanceBlock); } V result = map.get(key); if (MapIterate.isAbsent(result, map, key)) { result = instanceBlock.value(); map.put(key, result); } return result; }
@Override public <K, V> MutableMap<K, V> aggregateInPlaceBy( Function<? super T, ? extends K> groupBy, Function0<? extends V> zeroValueFactory, Procedure2<? super V, ? super T> mutatingAggregator) { MutableMap<K, V> map = UnifiedMap.newMap(); this.each(each -> { K key = groupBy.valueOf(each); V value = map.getIfAbsentPut(key, zeroValueFactory); mutatingAggregator.value(value, each); }); return map; }
@Override public <K, V> MutableMap<K, V> aggregateInPlaceBy( Function<? super T, ? extends K> groupBy, Function0<? extends V> zeroValueFactory, Procedure2<? super V, ? super T> mutatingAggregator) { MutableMap<K, V> map = UnifiedMap.newMap(); this.each(each -> { K key = groupBy.valueOf(each); V value = map.getIfAbsentPut(key, zeroValueFactory); mutatingAggregator.value(value, each); }); return map; }
@Override public <K, V> MutableMap<K, V> aggregateBy( Function<? super T, ? extends K> groupBy, Function0<? extends V> zeroValueFactory, Function2<? super V, ? super T, ? extends V> nonMutatingAggregator) { MutableMap<K, V> map = UnifiedMap.newMap(); this.each(each -> { K key = groupBy.valueOf(each); V value = map.getIfAbsentPut(key, zeroValueFactory); map.put(key, nonMutatingAggregator.value(value, each)); }); return map; } }
@Override public <K, V> MutableMap<K, V> aggregateBy( Function<? super T, ? extends K> groupBy, Function0<? extends V> zeroValueFactory, Function2<? super V, ? super T, ? extends V> nonMutatingAggregator) { MutableMap<K, V> map = UnifiedMap.newMap(); this.each(each -> { K key = groupBy.valueOf(each); V value = map.getIfAbsentPut(key, zeroValueFactory); map.put(key, nonMutatingAggregator.value(value, each)); }); return map; } }
private static void verifyConstraintOn( LongArrayList nodeIds, NodePropertyAccessor nodePropertyAccessor, StoreIndexDescriptor descriptor ) throws IndexEntryConflictException { MutableMap<Value,Long> points = Maps.mutable.empty(); MutableLongIterator iter = nodeIds.longIterator(); try { while ( iter.hasNext() ) { long id = iter.next(); Value value = nodePropertyAccessor.getNodePropertyValue( id, descriptor.schema().getPropertyId() ); Long other = points.getIfAbsentPut( value, id ); if ( other != id ) { throw new IndexEntryConflictException( other, id, value ); } } } catch ( EntityNotFoundException e ) { throw new RuntimeException( "Failed to validate uniqueness constraint", e ); } }
@Override public void value(T each) { V groupKey = this.groupBy.valueOf(each); DoubleDoublePair sumCompensation = this.map.getIfAbsentPut(groupKey, () -> PrimitiveTuples.pair(0.0d, 0.0d)); double sum = sumCompensation.getOne(); double compensation = sumCompensation.getTwo(); double adjustedValue = this.function.doubleValueOf(each) - compensation; double nextSum = sum + adjustedValue; compensation = nextSum - sum - adjustedValue; sum = nextSum; this.map.put(groupKey, PrimitiveTuples.pair(sum, compensation)); }
@Override public void value(T each) { V groupKey = this.groupBy.valueOf(each); DoubleDoublePair sumCompensation = this.map.getIfAbsentPut(groupKey, () -> PrimitiveTuples.pair(0.0d, 0.0d)); double sum = sumCompensation.getOne(); double compensation = sumCompensation.getTwo(); double adjustedValue = this.function.floatValueOf(each) - compensation; double nextSum = sum + adjustedValue; compensation = nextSum - sum - adjustedValue; sum = nextSum; this.map.put(groupKey, PrimitiveTuples.pair(sum, compensation)); }
@Override public void value(T each) { V groupKey = this.groupBy.valueOf(each); DoubleDoublePair sumCompensation = this.map.getIfAbsentPut(groupKey, () -> PrimitiveTuples.pair(0.0d, 0.0d)); double sum = sumCompensation.getOne(); double compensation = sumCompensation.getTwo(); double adjustedValue = this.function.floatValueOf(each) - compensation; double nextSum = sum + adjustedValue; compensation = nextSum - sum - adjustedValue; sum = nextSum; this.map.put(groupKey, PrimitiveTuples.pair(sum, compensation)); }
@Override public void value(T each) { V groupKey = this.groupBy.valueOf(each); DoubleDoublePair sumCompensation = this.map.getIfAbsentPut(groupKey, () -> PrimitiveTuples.pair(0.0d, 0.0d)); double sum = sumCompensation.getOne(); double compensation = sumCompensation.getTwo(); double adjustedValue = this.function.doubleValueOf(each) - compensation; double nextSum = sum + adjustedValue; compensation = nextSum - sum - adjustedValue; sum = nextSum; this.map.put(groupKey, PrimitiveTuples.pair(sum, compensation)); }
@Override public void value(T each) { K key = this.groupBy.valueOf(each); V value = this.map.getIfAbsentPut(key, this.zeroValueFactory); this.mutatingAggregator.value(value, each); } }
/** * Get and return the value in the Map at the specified key, or if there is no value at the key, return the result * of evaluating the specified {@link Function0}, and put that value in the map at the specified key. * <p> * This method handles the {@code null}-value-at-key case correctly. */ public static <K, V> V getIfAbsentPut(Map<K, V> map, K key, Function0<? extends V> instanceBlock) { if (map instanceof MutableMap) { return ((MutableMap<K, V>) map).getIfAbsentPut(key, instanceBlock); } V result = map.get(key); if (MapIterate.isAbsent(result, map, key)) { result = instanceBlock.value(); map.put(key, result); } return result; }
@Override public <K, V> MutableMap<K, V> aggregateInPlaceBy( Function<? super T, ? extends K> groupBy, Function0<? extends V> zeroValueFactory, Procedure2<? super V, ? super T> mutatingAggregator) { MutableMap<K, V> map = UnifiedMap.newMap(); this.each(each -> { K key = groupBy.valueOf(each); V value = map.getIfAbsentPut(key, zeroValueFactory); mutatingAggregator.value(value, each); }); return map; }
@Override public <K, V> MutableMap<K, V> aggregateBy( Function<? super T, ? extends K> groupBy, Function0<? extends V> zeroValueFactory, Function2<? super V, ? super T, ? extends V> nonMutatingAggregator) { MutableMap<K, V> map = UnifiedMap.newMap(); this.each(each -> { K key = groupBy.valueOf(each); V value = map.getIfAbsentPut(key, zeroValueFactory); map.put(key, nonMutatingAggregator.value(value, each)); }); return map; } }
@Override public void value(T each) { V groupKey = this.groupBy.valueOf(each); DoubleDoublePair sumCompensation = this.map.getIfAbsentPut(groupKey, () -> PrimitiveTuples.pair(0.0d, 0.0d)); double sum = sumCompensation.getOne(); double compensation = sumCompensation.getTwo(); double adjustedValue = this.function.doubleValueOf(each) - compensation; double nextSum = sum + adjustedValue; compensation = nextSum - sum - adjustedValue; sum = nextSum; this.map.put(groupKey, PrimitiveTuples.pair(sum, compensation)); }
@Override public void value(T each) { V groupKey = this.groupBy.valueOf(each); DoubleDoublePair sumCompensation = this.map.getIfAbsentPut(groupKey, () -> PrimitiveTuples.pair(0.0d, 0.0d)); double sum = sumCompensation.getOne(); double compensation = sumCompensation.getTwo(); double adjustedValue = this.function.floatValueOf(each) - compensation; double nextSum = sum + adjustedValue; compensation = nextSum - sum - adjustedValue; sum = nextSum; this.map.put(groupKey, PrimitiveTuples.pair(sum, compensation)); }
private static void verifyConstraintOn( LongArrayList nodeIds, NodePropertyAccessor nodePropertyAccessor, StoreIndexDescriptor descriptor ) throws IndexEntryConflictException { MutableMap<Value,Long> points = Maps.mutable.empty(); MutableLongIterator iter = nodeIds.longIterator(); try { while ( iter.hasNext() ) { long id = iter.next(); Value value = nodePropertyAccessor.getNodePropertyValue( id, descriptor.schema().getPropertyId() ); Long other = points.getIfAbsentPut( value, id ); if ( other != id ) { throw new IndexEntryConflictException( other, id, value ); } } } catch ( EntityNotFoundException e ) { throw new RuntimeException( "Failed to validate uniqueness constraint", e ); } }
missingByKey.getIfAbsentPut(expectedRowView, NEW_LIST).add(expected); surplusByKey.getIfAbsentPut(actualRowView, NEW_LIST).add(actual);
AtomicInteger objectOrder2 = countByObject.getIfAbsentPut(candidateObject, new Function0<AtomicInteger>() { @Override public AtomicInteger value() {