Skip to main content
summaryrefslogtreecommitdiffstats
path: root/debug
diff options
context:
space:
mode:
authorMarc Khouzam2011-02-02 16:39:37 -0500
committerMarc Khouzam2011-02-02 16:39:37 -0500
commit4881bba10c7d5f78d704cd8615527b7356a4a664 (patch)
treea27215dbcdcdf1c4d34e88a39727948f9faf73e8 /debug
parent6a815d839a22dddeb6ce30f8009f0e28547ebb15 (diff)
downloadorg.eclipse.cdt-4881bba10c7d5f78d704cd8615527b7356a4a664.tar.gz
org.eclipse.cdt-4881bba10c7d5f78d704cd8615527b7356a4a664.tar.xz
org.eclipse.cdt-4881bba10c7d5f78d704cd8615527b7356a4a664.zip
Bug 335528: [multi-process] Move startOrRestart to the Processes service
Diffstat (limited to 'debug')
-rw-r--r--debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDebugUtils.java23
1 files changed, 23 insertions, 0 deletions
diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDebugUtils.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDebugUtils.java
index f9cdb805d6..ec7de3bb4e 100644
--- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDebugUtils.java
+++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDebugUtils.java
@@ -19,6 +19,7 @@ import java.nio.charset.CharsetDecoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import java.util.Map;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
@@ -673,4 +674,26 @@ public class CDebugUtils {
private static void throwCoreException(String msg, Exception innerException, int code) throws CoreException {
throw new CoreException(new Status(IStatus.ERROR, CDebugCorePlugin.getUniqueIdentifier(), code, msg, innerException));
}
+
+ /**
+ * Generic method to fetch an attribute from a Map that has keys of type String. The defaultValue
+ * parameter will be returned if the map does not contain the key, or if the matching value is not
+ * of the correct type.
+ *
+ * @param <V> The type of the value we are looking for. Specified by the type of defaultValue.
+ * @param attributes The map with keys of type String, and values of any type. Cannot be null.
+ * @param key They key for which we want the value.
+ * @param defaultValue The default value to return if the key is not found in the map, or if the value found
+ * is not of the same type as defaultValue. Cannot be null.
+ * @return The value, if found and of the same type as defaultValue. Else, returns defaultValue.
+ * @since 7.1
+ */
+ @SuppressWarnings("unchecked")
+ public static <V> V getAttribute(Map<String, ?> attributes, String key, V defaultValue) {
+ Object value = attributes.get(key);
+ if (defaultValue.getClass().isInstance(value)) {
+ return (V)value;
+ }
+ return defaultValue;
+ }
}

Back to the top