com.gs.collections.impl.map.AbstractMapIterable Maven / Gradle / Ivy
Show all versions of gs-collections Show documentation
/*
* Copyright 2011 Goldman Sachs.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.gs.collections.impl.map;
import java.util.Collection;
import java.util.Comparator;
import java.util.Map;
import com.gs.collections.api.BooleanIterable;
import com.gs.collections.api.LazyIterable;
import com.gs.collections.api.RichIterable;
import com.gs.collections.api.bag.MutableBag;
import com.gs.collections.api.block.function.Function;
import com.gs.collections.api.block.function.Function0;
import com.gs.collections.api.block.function.Function2;
import com.gs.collections.api.block.function.primitive.BooleanFunction;
import com.gs.collections.api.block.function.primitive.ByteFunction;
import com.gs.collections.api.block.function.primitive.CharFunction;
import com.gs.collections.api.block.function.primitive.DoubleFunction;
import com.gs.collections.api.block.function.primitive.DoubleObjectToDoubleFunction;
import com.gs.collections.api.block.function.primitive.FloatFunction;
import com.gs.collections.api.block.function.primitive.FloatObjectToFloatFunction;
import com.gs.collections.api.block.function.primitive.IntFunction;
import com.gs.collections.api.block.function.primitive.IntObjectToIntFunction;
import com.gs.collections.api.block.function.primitive.LongFunction;
import com.gs.collections.api.block.function.primitive.LongObjectToLongFunction;
import com.gs.collections.api.block.function.primitive.ShortFunction;
import com.gs.collections.api.block.predicate.Predicate;
import com.gs.collections.api.block.predicate.Predicate2;
import com.gs.collections.api.block.procedure.Procedure;
import com.gs.collections.api.block.procedure.Procedure2;
import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure;
import com.gs.collections.api.collection.primitive.MutableBooleanCollection;
import com.gs.collections.api.collection.primitive.MutableByteCollection;
import com.gs.collections.api.collection.primitive.MutableCharCollection;
import com.gs.collections.api.collection.primitive.MutableDoubleCollection;
import com.gs.collections.api.collection.primitive.MutableFloatCollection;
import com.gs.collections.api.collection.primitive.MutableIntCollection;
import com.gs.collections.api.collection.primitive.MutableLongCollection;
import com.gs.collections.api.collection.primitive.MutableShortCollection;
import com.gs.collections.api.list.MutableList;
import com.gs.collections.api.map.MapIterable;
import com.gs.collections.api.map.MutableMap;
import com.gs.collections.api.map.sorted.MutableSortedMap;
import com.gs.collections.api.multimap.MutableMultimap;
import com.gs.collections.api.set.MutableSet;
import com.gs.collections.api.set.sorted.MutableSortedSet;
import com.gs.collections.api.tuple.Pair;
public abstract class AbstractMapIterable implements MapIterable
{
protected int keyAndValueHashCode(K key, V value)
{
return (key == null ? 0 : key.hashCode()) ^ (value == null ? 0 : value.hashCode());
}
protected boolean keyAndValueEquals(K key, V value, Map map)
{
if (value == null && !map.containsKey(key))
{
return false;
}
V oValue = map.get(key);
return oValue == value || oValue != null && oValue.equals(value);
}
public boolean isEmpty()
{
return this.size() == 0;
}
public boolean notEmpty()
{
return !this.isEmpty();
}
public A ifPresentApply(K key, Function super V, ? extends A> function)
{
V result = this.get(key);
return this.isAbsent(result, key) ? null : function.valueOf(result);
}
protected boolean isAbsent(V result, K key)
{
return result == null && !this.containsKey(key);
}
public V getIfAbsent(K key, Function0 extends V> function)
{
V result = this.get(key);
if (!this.isAbsent(result, key))
{
return result;
}
return function.value();
}
public V getIfAbsentValue(K key, V value)
{
V result = this.get(key);
if (!this.isAbsent(result, key))
{
return result;
}
return value;
}
public V getIfAbsentWith(
K key,
Function super P, ? extends V> function,
P parameter)
{
V result = this.get(key);
if (this.isAbsent(result, key))
{
result = function.valueOf(parameter);
}
return result;
}
public boolean anySatisfy(Predicate super V> predicate)
{
return this.valuesView().anySatisfy(predicate);
}
public
boolean anySatisfyWith(Predicate2 super V, ? super P> predicate, P parameter)
{
return this.valuesView().anySatisfyWith(predicate, parameter);
}
public boolean allSatisfy(Predicate super V> predicate)
{
return this.valuesView().allSatisfy(predicate);
}
public
boolean allSatisfyWith(Predicate2 super V, ? super P> predicate, P parameter)
{
return this.valuesView().allSatisfyWith(predicate, parameter);
}
public boolean noneSatisfy(Predicate super V> predicate)
{
return this.valuesView().noneSatisfy(predicate);
}
public
boolean noneSatisfyWith(Predicate2 super V, ? super P> predicate, P parameter)
{
return this.valuesView().noneSatisfyWith(predicate, parameter);
}
public void appendString(Appendable appendable)
{
this.valuesView().appendString(appendable);
}
public void appendString(Appendable appendable, String separator)
{
this.valuesView().appendString(appendable, separator);
}
public void appendString(Appendable appendable, String start, String separator, String end)
{
this.valuesView().appendString(appendable, start, separator, end);
}
public MutableBag toBag()
{
return this.valuesView().toBag();
}
public LazyIterable asLazy()
{
return this.valuesView().asLazy();
}
public MutableList toList()
{
return this.valuesView().toList();
}
public MutableMap toMap(
Function super V, ? extends NK> keyFunction,
Function super V, ? extends NV> valueFunction)
{
return this.valuesView().toMap(keyFunction, valueFunction);
}
public MutableSortedMap toSortedMap(
Function super V, ? extends NK> keyFunction,
Function super V, ? extends NV> valueFunction)
{
return this.valuesView().toSortedMap(keyFunction, valueFunction);
}
public MutableSortedMap toSortedMap(
Comparator super NK> comparator,
Function super V, ? extends NK> keyFunction,
Function super V, ? extends NV> valueFunction)
{
return this.valuesView().toSortedMap(comparator, keyFunction, valueFunction);
}
public MutableSet toSet()
{
return this.valuesView().toSet();
}
public MutableList toSortedList()
{
return this.valuesView().toSortedList();
}
public MutableList toSortedList(Comparator super V> comparator)
{
return this.valuesView().toSortedList(comparator);
}
public > MutableList toSortedListBy(Function super V, ? extends R> function)
{
return this.valuesView().toSortedListBy(function);
}
public MutableSortedSet toSortedSet()
{
return this.valuesView().toSortedSet();
}
public MutableSortedSet toSortedSet(Comparator super V> comparator)
{
return this.valuesView().toSortedSet(comparator);
}
public > MutableSortedSet toSortedSetBy(Function super V, ? extends R> function)
{
return this.valuesView().toSortedSetBy(function);
}
public RichIterable> chunk(int size)
{
return this.valuesView().chunk(size);
}
public void forEach(Procedure super V> procedure)
{
this.forEachValue(procedure);
}
public void forEachWith(Procedure2 super V, ? super P> procedure2, P parameter)
{
this.valuesView().forEachWith(procedure2, parameter);
}
public void forEachWithIndex(ObjectIntProcedure super V> objectIntProcedure)
{
this.valuesView().forEachWithIndex(objectIntProcedure);
}
public void forEachKey(Procedure super K> procedure)
{
this.keysView().forEach(procedure);
}
public void forEachValue(Procedure super V> procedure)
{
this.valuesView().forEach(procedure);
}
public RichIterable collect(Function super V, ? extends R> function)
{
return this.valuesView().collect(function);
}
public BooleanIterable collectBoolean(BooleanFunction super V> booleanFunction)
{
return this.valuesView().collectBoolean(booleanFunction);
}
public R collectBoolean(BooleanFunction super V> booleanFunction, R target)
{
return this.valuesView().collectBoolean(booleanFunction, target);
}
public R collectByte(ByteFunction super V> byteFunction, R target)
{
return this.valuesView().collectByte(byteFunction, target);
}
public R collectChar(CharFunction super V> charFunction, R target)
{
return this.valuesView().collectChar(charFunction, target);
}
public R collectDouble(DoubleFunction super V> doubleFunction, R target)
{
return this.valuesView().collectDouble(doubleFunction, target);
}
public R collectFloat(FloatFunction super V> floatFunction, R target)
{
return this.valuesView().collectFloat(floatFunction, target);
}
public R collectInt(IntFunction super V> intFunction, R target)
{
return this.valuesView().collectInt(intFunction, target);
}
public R collectLong(LongFunction super V> longFunction, R target)
{
return this.valuesView().collectLong(longFunction, target);
}
public R collectShort(ShortFunction super V> shortFunction, R target)
{
return this.valuesView().collectShort(shortFunction, target);
}
public > C collect(Function super V, ? extends R> function, C target)
{
return this.valuesView().collect(function, target);
}
public > C collectIf(Predicate super V> predicate, Function super V, ? extends R> function, C target)
{
return this.valuesView().collectIf(predicate, function, target);
}
public RichIterable collectWith(Function2 super V, ? super P, ? extends VV> function, P parameter)
{
return this.valuesView().collectWith(function, parameter);
}
public > C collectWith(Function2 super V, ? super P, ? extends R> function, P parameter, C targetCollection)
{
return this.valuesView().collectWith(function, parameter, targetCollection);
}
public boolean contains(Object object)
{
return this.containsValue(object);
}
public boolean containsAllArguments(Object... elements)
{
return this.valuesView().containsAllArguments(elements);
}
public boolean containsAllIterable(Iterable> source)
{
return this.valuesView().containsAllIterable(source);
}
public boolean containsAll(Collection> source)
{
return this.containsAllIterable(source);
}
public int count(Predicate super V> predicate)
{
return this.valuesView().count(predicate);
}
public
int countWith(Predicate2 super V, ? super P> predicate, P parameter)
{
return this.valuesView().countWith(predicate, parameter);
}
public V detect(Predicate super V> predicate)
{
return this.valuesView().detect(predicate);
}
public
V detectWith(Predicate2 super V, ? super P> predicate, P parameter)
{
return this.valuesView().detectWith(predicate, parameter);
}
public V detectIfNone(Predicate super V> predicate, Function0 extends V> function)
{
return this.valuesView().detectIfNone(predicate, function);
}
public
V detectWithIfNone(Predicate2 super V, ? super P> predicate, P parameter, Function0 extends V> function)
{
return this.valuesView().detectWithIfNone(predicate, parameter, function);
}
public > C flatCollect(Function super V, ? extends Iterable> function, C target)
{
return this.valuesView().flatCollect(function, target);
}
public V getFirst()
{
return this.valuesView().getFirst();
}
public V getLast()
{
return this.valuesView().getLast();
}
public > C groupBy(Function super V, ? extends R> function, C target)
{
return this.valuesView().groupBy(function, target);
}
public > C groupByEach(Function super V, ? extends Iterable> function, C target)
{
return this.valuesView().groupByEach(function, target);
}
public IV injectInto(IV injectedValue, Function2 super IV, ? super V, ? extends IV> function)
{
return this.valuesView().injectInto(injectedValue, function);
}
public int injectInto(int injectedValue, IntObjectToIntFunction super V> function)
{
return this.valuesView().injectInto(injectedValue, function);
}
public long injectInto(long injectedValue, LongObjectToLongFunction super V> function)
{
return this.valuesView().injectInto(injectedValue, function);
}
public double injectInto(double injectedValue, DoubleObjectToDoubleFunction super V> function)
{
return this.valuesView().injectInto(injectedValue, function);
}
public float injectInto(float injectedValue, FloatObjectToFloatFunction super V> function)
{
return this.valuesView().injectInto(injectedValue, function);
}
public long sumOfInt(IntFunction super V> function)
{
return this.valuesView().sumOfInt(function);
}
public double sumOfFloat(FloatFunction super V> function)
{
return this.valuesView().sumOfFloat(function);
}
public long sumOfLong(LongFunction super V> function)
{
return this.valuesView().sumOfLong(function);
}
public double sumOfDouble(DoubleFunction super V> function)
{
return this.valuesView().sumOfDouble(function);
}
public String makeString()
{
return this.valuesView().makeString();
}
public String makeString(String separator)
{
return this.valuesView().makeString(separator);
}
public String makeString(String start, String separator, String end)
{
return this.valuesView().makeString(start, separator, end);
}
public V max()
{
return this.valuesView().max();
}
public V max(Comparator super V> comparator)
{
return this.valuesView().max(comparator);
}
public > V maxBy(Function super V, ? extends R> function)
{
return this.valuesView().maxBy(function);
}
public V min()
{
return this.valuesView().min();
}
public V min(Comparator super V> comparator)
{
return this.valuesView().min(comparator);
}
public > V minBy(Function super V, ? extends R> function)
{
return this.valuesView().minBy(function);
}
public RichIterable rejectWith(Predicate2 super V, ? super P> predicate, P parameter)
{
return this.valuesView().rejectWith(predicate, parameter);
}
public > R reject(Predicate super V> predicate, R target)
{
return this.valuesView().reject(predicate, target);
}
public > R rejectWith(Predicate2 super V, ? super P> predicate, P parameter, R targetCollection)
{
return this.valuesView().rejectWith(predicate, parameter, targetCollection);
}
public
RichIterable selectWith(Predicate2 super V, ? super P> predicate, P parameter)
{
return this.valuesView().selectWith(predicate, parameter);
}
public > R select(Predicate super V> predicate, R target)
{
return this.valuesView().select(predicate, target);
}
public > R selectWith(Predicate2 super V, ? super P> predicate, P parameter, R targetCollection)
{
return this.valuesView().selectWith(predicate, parameter, targetCollection);
}
public Object[] toArray()
{
return this.valuesView().toArray();
}
public T[] toArray(T[] a)
{
return this.valuesView().toArray(a);
}
public >> R zip(Iterable that, R target)
{
return this.valuesView().zip(that, target);
}
public >> R zipWithIndex(R target)
{
return this.valuesView().zipWithIndex(target);
}
}