Java Code Examples for java.util.Map.getClass()

The following are Jave code examples for showing how to use getClass() of the java.util.Map class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: jsf-sdk   File: MapTemplate.java   View Source Code Vote up 6 votes
public void write(Packer pk, Map<K, V> target, boolean required)
        throws IOException {
    if (!(target instanceof Map)) {
        if (target == null) {
            if (required) {
                throw new MessageTypeException("Attempted to write null");
            }
            pk.writeNil();
            return;
        }
        throw new MessageTypeException("Target is not a Map but " + target.getClass());
    }
    Map<K, V> map = (Map<K, V>) target;
    pk.writeMapBegin(map.size());
    for (Map.Entry<K, V> pair : map.entrySet()) {
        keyTemplate.write(pk, pair.getKey());
        valueTemplate.write(pk, pair.getValue());
    }
    pk.writeMapEnd();
}
 
Example 2
Project: Reer   File: ReflectiveEnvironment.java   View Source Code Vote up 5 votes
private Map<String, String> getEnv() {
    try {
        Map<String, String> theUnmodifiableEnvironment = System.getenv();
        Class<?> cu = theUnmodifiableEnvironment.getClass();
        Field m = cu.getDeclaredField("m");
        m.setAccessible(true);
        @SuppressWarnings("unchecked")
        Map<String, String> result = (Map<String, String>)m.get(theUnmodifiableEnvironment);
        return result;
    } catch (Exception e) {
        throw new NativeIntegrationException("Unable to get mutable environment map", e);
    }
}
 
Example 3
Project: incubator-netbeans   File: ProxyLookup.java   View Source Code Vote up 5 votes
private static <K,V> Map<K,V> unmodifiableMap(Map<K,V> map) {
    Map<K,V> res = Collections.unmodifiableMap(map);
    if (unmodifiableClass == null) {
        unmodifiableClass = res.getClass();
    }
    return res;
}
 
Example 4
Project: aceql-http   File: MapCopier.java   View Source Code Vote up 5 votes
/**
    * Copy a Map<K, V> to another Map
    * 
    * @param map
    *            the map to copy
    * @return the copied map
    */
   public Map<K, V> copy(Map<K, V> map) {
Map<K, V> mapCopy = null;

if (map instanceof HashMap) {
    mapCopy = new HashMap<K, V>(map);
} else if (map instanceof Hashtable) {
    mapCopy = new Hashtable<K, V>(map);
} else if (map instanceof LinkedHashMap) {
    mapCopy = new LinkedHashMap<K, V>(map);
} else if (map instanceof TreeMap) {
    mapCopy = new TreeMap<K, V>(map);
} else {
    throw new IllegalArgumentException(
	    "copy implementation not supported for Map class: "
		    + map.getClass());
}

/*
 * Set<K> keys = map.keySet();
 * 
 * for (Iterator<K> iterator = keys.iterator(); iterator.hasNext();) { K
 * key = (K) iterator.next(); V value = map.get(key);
 * 
 * mapCopy.put(key, value); }
 */

return mapCopy;
   }
 
Example 5
Project: verify-service-provider   File: EnvironmentHelper.java   View Source Code Vote up 5 votes
private static Map<String, String> getWritableEnvironmentMap() throws NoSuchFieldException, IllegalAccessException {
    Map<String, String> env = System.getenv();
    Class<?> cl = env.getClass();
    Field field = cl.getDeclaredField("m");
    field.setAccessible(true);

    @SuppressWarnings("unchecked")
    Map<String, String> result = (Map<String, String>) field.get(env);
    return result;
}
 
Example 6
Project: incubator-netbeans   File: ProxyLookup.java   View Source Code Vote up 4 votes
private static boolean isUnmodifiable(Map<?,?> map) {
    return map.getClass() == unmodifiableClass;
}
 
Example 7
Project: pcloud-networking-java   File: MapTypeAdapter.java   View Source Code Vote up 4 votes
@Override
public void serialize(ProtocolWriter writer, Map<K, V> value) throws IOException {
    throw new UnserializableTypeException(value.getClass());
}