
org.javafunk.funk.Maps Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of funk-core Show documentation
Show all versions of funk-core Show documentation
Functional utilities for Java: core APIs
The newest version!
/*
* Copyright (C) 2011-Present Funk committers.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
* style license a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.javafunk.funk;
import org.javafunk.funk.functors.Mapper;
import org.javafunk.funk.functors.functions.NullaryFunction;
import org.javafunk.funk.functors.functions.UnaryFunction;
import java.util.Map;
import java.util.Set;
public class Maps {
private Maps() {}
public static V getOrAdd(Map map, U key, UnaryFunction super U, ? extends V> mapper) {
if (map.containsKey(key)) {
return map.get(key);
} else {
V newValue = mapper.call(key);
map.put(key, newValue);
return newValue;
}
}
public static V getOrAdd(Map map, U key, final NullaryFunction extends V> factory) {
return getOrAdd(map, key, new Mapper() {
@Override public V map(U input) {
return factory.call();
}
});
}
public static Mapper super Map, Set>> toEntrySet() {
return new Mapper
© 2015 - 2025 Weber Informatics LLC | Privacy Policy