本文整理匯總了Java中java.util.Map.getClass方法的典型用法代碼示例。如果您正苦於以下問題:Java Map.getClass方法的具體用法?Java Map.getClass怎麽用?Java Map.getClass使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.Map
的用法示例。
在下文中一共展示了Map.getClass方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: write
import java.util.Map; //導入方法依賴的package包/類
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();
}
示例2: getEnv
import java.util.Map; //導入方法依賴的package包/類
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);
}
}
示例3: unmodifiableMap
import java.util.Map; //導入方法依賴的package包/類
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;
}
示例4: copy
import java.util.Map; //導入方法依賴的package包/類
/**
* 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;
}
示例5: getWritableEnvironmentMap
import java.util.Map; //導入方法依賴的package包/類
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;
}
示例6: isUnmodifiable
import java.util.Map; //導入方法依賴的package包/類
private static boolean isUnmodifiable(Map<?,?> map) {
return map.getClass() == unmodifiableClass;
}
示例7: serialize
import java.util.Map; //導入方法依賴的package包/類
@Override
public void serialize(ProtocolWriter writer, Map<K, V> value) throws IOException {
throw new UnserializableTypeException(value.getClass());
}