You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
95 lines
2.3 KiB
95 lines
2.3 KiB
2 years ago
|
package com.fr.plugin.heatpointmapbox.ui;
|
||
|
|
||
|
import java.awt.*;
|
||
|
import java.util.Map;
|
||
|
|
||
|
/**
|
||
|
* @author xx
|
||
|
*/
|
||
|
public class MapUtil {
|
||
|
public static String getString(Map map, String key) {
|
||
|
return getString(map, key, null);
|
||
|
}
|
||
|
|
||
|
public static String getString(Map map, String key, String def) {
|
||
|
if (null == map) {
|
||
|
return def;
|
||
|
}
|
||
|
if (null != map.get(key)) {
|
||
|
return map.get(key).toString();
|
||
|
} else {
|
||
|
return def;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static Integer getInteger(Map map, String key) {
|
||
|
return getInteger(map, key, null);
|
||
|
}
|
||
|
|
||
|
public static Integer getInteger(Map map, String key, Integer def) {
|
||
|
if (null == map) {
|
||
|
return def;
|
||
|
}
|
||
|
if (null != map.get(key)) {
|
||
|
return Integer.parseInt(map.get(key).toString());
|
||
|
} else {
|
||
|
return def;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static Double getDouble(Map map, String key) {
|
||
|
return getDouble(map, key, null);
|
||
|
}
|
||
|
|
||
|
public static Double getDouble(Map map, String key, Double def) {
|
||
|
if (null == map) {
|
||
|
return def;
|
||
|
}
|
||
|
if (null != map.get(key)) {
|
||
|
return Double.parseDouble(map.get(key).toString());
|
||
|
} else {
|
||
|
return def;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static Boolean getBoolean(Map map, String key) {
|
||
|
return getBoolean(map, key, null);
|
||
|
}
|
||
|
|
||
|
public static Boolean getBoolean(Map map, String key, Boolean def) {
|
||
|
if (null == map) {
|
||
|
return def;
|
||
|
}
|
||
|
String s = getString(map, key);
|
||
|
if (null != s) {
|
||
|
if ("true".equals(s)) {
|
||
|
return true;
|
||
|
} else if ("false".equals(s)){
|
||
|
return false;
|
||
|
} else {
|
||
|
return def;
|
||
|
}
|
||
|
} else {
|
||
|
return def;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static String toHex(Color c) {
|
||
|
if (null == c) {
|
||
|
return "transparent";
|
||
|
}
|
||
|
String hex = Integer.toHexString(c.getRGB());
|
||
|
if (hex.length() == 8) {
|
||
|
hex = "#" + hex.substring(2);
|
||
|
}
|
||
|
return hex;
|
||
|
}
|
||
|
public static Color toColor(String c) {
|
||
|
if (null != c && c.startsWith("#")) {
|
||
|
c = c.substring(1);
|
||
|
return new Color(Integer.parseInt(c, 16));
|
||
|
}
|
||
|
return null;
|
||
|
}
|
||
|
}
|