本文整理汇总了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());
}