Example usage for com.google.common.collect ClassToInstanceMap merge

List of usage examples for com.google.common.collect ClassToInstanceMap merge

Introduction

In this page you can find the example usage for com.google.common.collect ClassToInstanceMap merge.

Prototype

default V merge(K key, V value, BiFunction<? super V, ? super V, ? extends V> remappingFunction) 

Source Link

Document

If the specified key is not already associated with a value or is associated with null, associates it with the given non-null value.

Usage

From source file:com.opengamma.strata.basics.market.ImmutableTypedReferenceData.java

@Override
public TypedReferenceData combinedWith(TypedReferenceData other) {
    ClassToInstanceMap<Object> combined = MutableClassToInstanceMap.create();
    combined.putAll(values);/*from www . ja v a 2 s.  c  o m*/
    for (Class<?> type : other.types()) {
        combined.merge(type, other.getValue(type), (v1, v2) -> {
            if (v1.equals(v2)) {
                return v1;
            }
            throw new IllegalArgumentException(Messages.format(
                    "Unable to combine reference data, values differ for type '{}'", type.getSimpleName()));
        });
    }
    return ImmutableTypedReferenceData.of(combined);
}