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

org.eclipse.collections.impl.map.AbstractMapIterable Maven / Gradle / Ivy

Go to download

Builds the commons-text. Requires eclipse-collections-api be built first and be excluded from any other poms requiring it.

There is a newer version: 11.1.0-r13
Show newest version
/*
 * Copyright (c) 2022 Goldman Sachs.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * and Eclipse Distribution License v. 1.0 which accompany this distribution.
 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
 * and the Eclipse Distribution License is available at
 * http://www.eclipse.org/org/documents/edl-v10.php.
 */

package org.eclipse.collections.impl.map;

import java.util.Map;
import java.util.Optional;

import org.eclipse.collections.api.LazyIterable;
import org.eclipse.collections.api.RichIterable;
import org.eclipse.collections.api.block.function.Function;
import org.eclipse.collections.api.block.function.Function0;
import org.eclipse.collections.api.block.predicate.Predicate;
import org.eclipse.collections.api.block.predicate.Predicate2;
import org.eclipse.collections.api.block.procedure.Procedure;
import org.eclipse.collections.api.block.procedure.Procedure2;
import org.eclipse.collections.api.block.procedure.primitive.ObjectIntProcedure;
import org.eclipse.collections.api.map.MapIterable;
import org.eclipse.collections.impl.AbstractRichIterable;

public abstract class AbstractMapIterable extends AbstractRichIterable 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);
    }

    @Override
    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);
    }

    @Override
    public V getOrDefault(Object key, V defaultValue)
    {
        return this.getIfAbsentValue((K) key, defaultValue);
    }

    @Override
    public V getIfAbsent(K key, Function0 function)
    {
        V result = this.get(key);
        if (!this.isAbsent(result, key))
        {
            return result;
        }
        return function.value();
    }

    @Override
    public V getIfAbsentValue(K key, V value)
    {
        V result = this.get(key);
        if (!this.isAbsent(result, key))
        {
            return result;
        }
        return value;
    }

    @Override
    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; } @Override public boolean anySatisfy(Predicate predicate) { return this.valuesView().anySatisfy(predicate); } @Override public

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

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

boolean noneSatisfyWith(Predicate2 predicate, P parameter) { return this.valuesView().noneSatisfyWith(predicate, parameter); } @Override public LazyIterable asLazy() { return this.valuesView().asLazy(); } @Override public RichIterable> chunk(int size) { return this.valuesView().chunk(size); } @Override public void each(Procedure procedure) { this.forEachValue(procedure); } @Override public

void forEachWith(Procedure2 procedure2, P parameter) { this.valuesView().forEachWith(procedure2, parameter); } @Override public void forEachWithIndex(ObjectIntProcedure objectIntProcedure) { this.valuesView().forEachWithIndex(objectIntProcedure); } @Override public void forEachKey(Procedure procedure) { this.keysView().forEach(procedure); } @Override public void forEachValue(Procedure procedure) { this.valuesView().forEach(procedure); } @Override public boolean contains(Object object) { return this.containsValue(object); } @Override public V detect(Predicate predicate) { return this.valuesView().detect(predicate); } @Override public

V detectWith(Predicate2 predicate, P parameter) { return this.valuesView().detectWith(predicate, parameter); } @Override public Optional detectOptional(Predicate predicate) { return this.valuesView().detectOptional(predicate); } @Override public

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

V detectWithIfNone(Predicate2 predicate, P parameter, Function0 function) { return this.valuesView().detectWithIfNone(predicate, parameter, function); } @Override public V getFirst() { return this.valuesView().getFirst(); } @Override public V getLast() { return this.valuesView().getLast(); } @Override public V getOnly() { return this.valuesView().getOnly(); } @Override public Object[] toArray() { return this.valuesView().toArray(); } @Override public T[] toArray(T[] a) { return this.valuesView().toArray(a); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy