diff options
author | slewis | 2013-08-27 06:31:15 +0000 |
---|---|---|
committer | slewis | 2013-08-27 06:31:15 +0000 |
commit | 194e758969dce220fa81ea79f62b00bb9ca5fdbc (patch) | |
tree | f889c562e3a1c5a059d09a99b552ffb9c8264c89 /framework | |
parent | 2f17f934963178b016e9c27263f903e6db6872ac (diff) | |
download | org.eclipse.ecf-194e758969dce220fa81ea79f62b00bb9ca5fdbc.tar.gz org.eclipse.ecf-194e758969dce220fa81ea79f62b00bb9ca5fdbc.tar.xz org.eclipse.ecf-194e758969dce220fa81ea79f62b00bb9ca5fdbc.zip |
Additions to support generics bug
https://bugs.eclipse.org/bugs/show_bug.cgi?id=415919
Diffstat (limited to 'framework')
-rw-r--r-- | framework/bundles/org.eclipse.ecf.sharedobject/src/org/eclipse/ecf/core/sharedobject/util/PropertiesUtil.java | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/framework/bundles/org.eclipse.ecf.sharedobject/src/org/eclipse/ecf/core/sharedobject/util/PropertiesUtil.java b/framework/bundles/org.eclipse.ecf.sharedobject/src/org/eclipse/ecf/core/sharedobject/util/PropertiesUtil.java new file mode 100644 index 000000000..5a9bef2c6 --- /dev/null +++ b/framework/bundles/org.eclipse.ecf.sharedobject/src/org/eclipse/ecf/core/sharedobject/util/PropertiesUtil.java @@ -0,0 +1,87 @@ +package org.eclipse.ecf.core.sharedobject.util; + +import java.util.Map; + +/** + * @since 2.4 + */ +public class PropertiesUtil { + + @SuppressWarnings("unchecked") + public static final <T> T getProperty(Class<T> type, Map<String, ?> properties, String name, T def) { + if (properties == null) + return def; + if (name == null) + return def; + Object o = properties.get(name); + if (o == null) + return def; + if (type.isInstance(o)) + return (T) o; + return def; + } + + public static final String getPropertyString(Map<String, ?> properties, String name, String def) { + return getProperty(String.class, properties, name, def); + } + + public static final String getPropertyString(Map<String, ?> properties, String name) { + return getPropertyString(properties, name, null); + } + + public static final float getPropertyFloat(Map<String, ?> properties, String name, float def) { + return getProperty(Float.class, properties, name, def); + } + + public static final float getPropertyFloat(Map<String, ?> properties, String name) { + return getPropertyFloat(properties, name, 0.0f); + } + + public static final double getPropertyDouble(Map<String, ?> properties, String name, double def) { + return getProperty(Double.class, properties, name, def); + } + + public static final double getPropertyDouble(Map<String, ?> properties, String name) { + return getPropertyDouble(properties, name, 0.0d); + } + + public static final int getPropertyInteger(Map<String, ?> properties, String name, int def) { + return getProperty(Integer.class, properties, name, def); + } + + public static final int getPropertyInteger(Map<String, ?> properties, String name) { + return getPropertyInteger(properties, name, 0); + } + + public static final long getPropertyLong(Map<String, ?> properties, String name, long def) { + return getProperty(Long.class, properties, name, def); + } + + public static final long getPropertyLong(Map<String, ?> properties, String name) { + return getPropertyLong(properties, name, 0l); + } + + public static final boolean getPropertyBoolean(Map<String, ?> properties, String name, boolean def) { + return getProperty(Boolean.class, properties, name, def); + } + + public static final boolean getPropertyBoolean(Map<String, ?> properties, String name) { + return getPropertyBoolean(properties, name, false); + } + + public static final byte[] getPropertyBytes(Map<String, ?> properties, String name, byte[] def) { + if (properties == null) + return def; + if (name == null) + return def; + Object o = properties.get(name); + if (o instanceof byte[]) + return (byte[]) o; + return def; + } + + public static final byte[] getPropertyBytes(Map<String, ?> properties, String name) { + return getPropertyBytes(properties, name, null); + } + +} |