
org.bongiorno.collections.ImprovedMap Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of collections Show documentation
Show all versions of collections Show documentation
Improve the java 8 collections and add some other collection related stuff
package org.bongiorno.collections;
import java.util.HashMap;
import java.util.function.BinaryOperator;
import java.util.function.Function;
/**
* @author chribong
*/
public class ImprovedMap extends QuickMap {
public ImprovedMap() {
super(new HashMap<>());
}
public ImprovedMap transform(Function super K, ? extends A> fOfK, Function super V, ? extends B> fOfV) {
ImprovedMap retVal = new ImprovedMap<>();
this.entrySet().stream().forEach(e -> retVal.put(fOfK.apply(e.getKey()), fOfV.apply(e.getValue())));
return retVal;
}
public static BinaryOperator noDupKeys() {
return (u, v) -> {
throw new IllegalStateException(String.format("Duplicate key %s", u));
};
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy