com.softicar.platform.common.container.map.Maps Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of platform-common Show documentation
Show all versions of platform-common Show documentation
The SoftiCAR Platform is a lightweight, Java-based library to create interactive business web applications.
package com.softicar.platform.common.container.map;
import java.util.Map;
/**
* Utility methods for {@link Map}.
*
* @author Oliver Richers
*/
public class Maps {
// -------------------- double -------------------- //
public static double getDoubleOrZero(Map map, K key) {
return Maps.getDoubleOrDefault(map, key, 0.0);
}
public static double getDoubleOrDefault(Map map, K key, double defaultValue) {
Double value = map.get(key);
return value != null? value : defaultValue;
}
public static double addDouble(Map map, K key, double value) {
Double oldValue = map.put(key, value);
if (oldValue != null) {
value += oldValue;
map.put(key, value);
}
return value;
}
}