All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.gs.collections.impl.map.AbstractMapIterable Maven / Gradle / Ivy

Go to download

GS Collections is a collections framework for Java. It has JDK-compatible List, Set and Map implementations with a rich API and set of utility classes that work with any JDK compatible Collections, Arrays, Maps or Strings. The iteration protocol was inspired by the Smalltalk collection framework.

There is a newer version: 7.0.3
Show newest version
/*
 * 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 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 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 function, P parameter) { V result = this.get(key); if (this.isAbsent(result, key)) { result = function.valueOf(parameter); } return result; } public boolean anySatisfy(Predicate predicate) { return this.valuesView().anySatisfy(predicate); } public

boolean anySatisfyWith(Predicate2 predicate, P parameter) { return this.valuesView().anySatisfyWith(predicate, parameter); } public boolean allSatisfy(Predicate predicate) { return this.valuesView().allSatisfy(predicate); } public

boolean allSatisfyWith(Predicate2 predicate, P parameter) { return this.valuesView().allSatisfyWith(predicate, parameter); } public boolean noneSatisfy(Predicate predicate) { return this.valuesView().noneSatisfy(predicate); } public

boolean noneSatisfyWith(Predicate2 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 keyFunction, Function valueFunction) { return this.valuesView().toMap(keyFunction, valueFunction); } public MutableSortedMap toSortedMap( Function keyFunction, Function valueFunction) { return this.valuesView().toSortedMap(keyFunction, valueFunction); } public MutableSortedMap toSortedMap( Comparator comparator, Function keyFunction, Function 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 comparator) { return this.valuesView().toSortedList(comparator); } public > MutableList toSortedListBy(Function function) { return this.valuesView().toSortedListBy(function); } public MutableSortedSet toSortedSet() { return this.valuesView().toSortedSet(); } public MutableSortedSet toSortedSet(Comparator comparator) { return this.valuesView().toSortedSet(comparator); } public > MutableSortedSet toSortedSetBy(Function function) { return this.valuesView().toSortedSetBy(function); } public RichIterable> chunk(int size) { return this.valuesView().chunk(size); } public void forEach(Procedure procedure) { this.forEachValue(procedure); } public

void forEachWith(Procedure2 procedure2, P parameter) { this.valuesView().forEachWith(procedure2, parameter); } public void forEachWithIndex(ObjectIntProcedure objectIntProcedure) { this.valuesView().forEachWithIndex(objectIntProcedure); } public void forEachKey(Procedure procedure) { this.keysView().forEach(procedure); } public void forEachValue(Procedure procedure) { this.valuesView().forEach(procedure); } public RichIterable collect(Function function) { return this.valuesView().collect(function); } public BooleanIterable collectBoolean(BooleanFunction booleanFunction) { return this.valuesView().collectBoolean(booleanFunction); } public R collectBoolean(BooleanFunction booleanFunction, R target) { return this.valuesView().collectBoolean(booleanFunction, target); } public R collectByte(ByteFunction byteFunction, R target) { return this.valuesView().collectByte(byteFunction, target); } public R collectChar(CharFunction charFunction, R target) { return this.valuesView().collectChar(charFunction, target); } public R collectDouble(DoubleFunction doubleFunction, R target) { return this.valuesView().collectDouble(doubleFunction, target); } public R collectFloat(FloatFunction floatFunction, R target) { return this.valuesView().collectFloat(floatFunction, target); } public R collectInt(IntFunction intFunction, R target) { return this.valuesView().collectInt(intFunction, target); } public R collectLong(LongFunction longFunction, R target) { return this.valuesView().collectLong(longFunction, target); } public R collectShort(ShortFunction shortFunction, R target) { return this.valuesView().collectShort(shortFunction, target); } public > C collect(Function function, C target) { return this.valuesView().collect(function, target); } public > C collectIf(Predicate predicate, Function function, C target) { return this.valuesView().collectIf(predicate, function, target); } public RichIterable collectWith(Function2 function, P parameter) { return this.valuesView().collectWith(function, parameter); } public > C collectWith(Function2 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 predicate) { return this.valuesView().count(predicate); } public

int countWith(Predicate2 predicate, P parameter) { return this.valuesView().countWith(predicate, parameter); } public V detect(Predicate predicate) { return this.valuesView().detect(predicate); } public

V detectWith(Predicate2 predicate, P parameter) { return this.valuesView().detectWith(predicate, parameter); } public V detectIfNone(Predicate predicate, Function0 function) { return this.valuesView().detectIfNone(predicate, function); } public

V detectWithIfNone(Predicate2 predicate, P parameter, Function0 function) { return this.valuesView().detectWithIfNone(predicate, parameter, function); } public > C flatCollect(Function> 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 function, C target) { return this.valuesView().groupBy(function, target); } public > C groupByEach(Function> function, C target) { return this.valuesView().groupByEach(function, target); } public IV injectInto(IV injectedValue, Function2 function) { return this.valuesView().injectInto(injectedValue, function); } public int injectInto(int injectedValue, IntObjectToIntFunction function) { return this.valuesView().injectInto(injectedValue, function); } public long injectInto(long injectedValue, LongObjectToLongFunction function) { return this.valuesView().injectInto(injectedValue, function); } public double injectInto(double injectedValue, DoubleObjectToDoubleFunction function) { return this.valuesView().injectInto(injectedValue, function); } public float injectInto(float injectedValue, FloatObjectToFloatFunction function) { return this.valuesView().injectInto(injectedValue, function); } public long sumOfInt(IntFunction function) { return this.valuesView().sumOfInt(function); } public double sumOfFloat(FloatFunction function) { return this.valuesView().sumOfFloat(function); } public long sumOfLong(LongFunction function) { return this.valuesView().sumOfLong(function); } public double sumOfDouble(DoubleFunction 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 comparator) { return this.valuesView().max(comparator); } public > V maxBy(Function function) { return this.valuesView().maxBy(function); } public V min() { return this.valuesView().min(); } public V min(Comparator comparator) { return this.valuesView().min(comparator); } public > V minBy(Function function) { return this.valuesView().minBy(function); } public

RichIterable rejectWith(Predicate2 predicate, P parameter) { return this.valuesView().rejectWith(predicate, parameter); } public > R reject(Predicate predicate, R target) { return this.valuesView().reject(predicate, target); } public > R rejectWith(Predicate2 predicate, P parameter, R targetCollection) { return this.valuesView().rejectWith(predicate, parameter, targetCollection); } public

RichIterable selectWith(Predicate2 predicate, P parameter) { return this.valuesView().selectWith(predicate, parameter); } public > R select(Predicate predicate, R target) { return this.valuesView().select(predicate, target); } public > R selectWith(Predicate2 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); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy