本文整理汇总了Java中java.util.IdentityHashMap类的典型用法代码示例。如果您正苦于以下问题:Java IdentityHashMap类的具体用法?Java IdentityHashMap怎么用?Java IdentityHashMap使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IdentityHashMap类属于java.util包,在下文中一共展示了IdentityHashMap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: groupByVersion
import java.util.IdentityHashMap; //导入依赖的package包/类
protected Map<MicroserviceVersionMeta, Map<String, MicroserviceInstance>> groupByVersion(Invocation invocation,
Map<String, MicroserviceInstance> instances) {
OperationMeta latestOperationMeta = invocation.getOperationMeta();
MicroserviceMeta latestMicroserviceMeta = latestOperationMeta.getSchemaMeta().getMicroserviceMeta();
AppManager appManager = RegistryUtils.getServiceRegistry().getAppManager();
MicroserviceVersions MicroserviceVersions =
appManager.getOrCreateMicroserviceVersions(latestMicroserviceMeta.getAppId(), latestMicroserviceMeta.getName());
Map<MicroserviceVersionMeta, Map<String, MicroserviceInstance>> versionMap = new IdentityHashMap<>();
for (MicroserviceInstance instance : instances.values()) {
MicroserviceVersionMeta versionMeta = MicroserviceVersions.getVersion(instance.getServiceId());
Map<String, MicroserviceInstance> versionInstances = versionMap.computeIfAbsent(versionMeta, vm -> {
return new HashMap<>();
});
versionInstances.put(instance.getInstanceId(), instance);
}
return versionMap;
}
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:19,代码来源:OperationInstancesDiscoveryFilter.java
示例2: register
import java.util.IdentityHashMap; //导入依赖的package包/类
@Override
public synchronized String register(String subject, Schema schema)
throws IOException, RestClientException {
Map<Schema, String> schemaIdMap;
if (schemaCache.containsKey(subject)) {
schemaIdMap = schemaCache.get(subject);
} else {
schemaIdMap = new IdentityHashMap<Schema, String>();
schemaCache.put(subject, schemaIdMap);
}
if (schemaIdMap.containsKey(schema)) {
return schemaIdMap.get(schema);
} else {
String id = getIdFromRegistry(subject, schema);
schemaIdMap.put(schema, id);
idCache.get(null).put(id, schema);
return id;
}
}
示例3: register
import java.util.IdentityHashMap; //导入依赖的package包/类
@Override
public synchronized String register(String subject, Schema schema)
throws IOException, RestClientException {
Map<Schema, String> schemaIdMap;
if (schemaCache.containsKey(subject)) {
schemaIdMap = schemaCache.get(subject);
} else {
schemaIdMap = new IdentityHashMap<Schema, String>();
schemaCache.put(subject, schemaIdMap);
}
if (schemaIdMap.containsKey(schema)) {
return schemaIdMap.get(schema);
} else {
if (schemaIdMap.size() >= identityMapCapacity) {
throw new IllegalStateException("Too many schema objects created for " + subject + "!");
}
String id = registerAndGetId(subject, schema);
schemaIdMap.put(schema, id);
idCache.get(null).put(id, schema);
return id;
}
}
示例4: getVersion
import java.util.IdentityHashMap; //导入依赖的package包/类
@Override
public synchronized int getVersion(String subject, Schema schema)
throws IOException, RestClientException{
Map<Schema, Integer> schemaVersionMap;
if (versionCache.containsKey(subject)) {
schemaVersionMap = versionCache.get(subject);
} else {
schemaVersionMap = new IdentityHashMap<Schema, Integer>();
versionCache.put(subject, schemaVersionMap);
}
if (schemaVersionMap.containsKey(schema)) {
return schemaVersionMap.get(schema);
} else {
if (schemaVersionMap.size() >= identityMapCapacity) {
throw new IllegalStateException("Too many schema objects created for " + subject + "!");
}
int version = getVersionFromRegistry(subject, schema);
schemaVersionMap.put(schema, version);
return version;
}
}
示例5: findRedirect
import java.util.IdentityHashMap; //导入依赖的package包/类
static CloneableEditorSupport findRedirect(CloneableEditorSupport one, boolean check) {
Map<Lookup,CloneableEditorSupport> all = CHECKED.get();
if (all == null) {
all = new IdentityHashMap<Lookup, CloneableEditorSupport>();
CHECKED.set(all);
}
final Lookup lkp = one.getLookup();
try {
if (check && all.containsKey(lkp)) {
return null;
}
all.put(lkp, one);
for (CloneableEditorSupportRedirector r : Lookup.getDefault().lookupAll(CloneableEditorSupportRedirector.class)) {
CloneableEditorSupport ces = r.redirect(lkp);
if (ces != null && ces != one) {
return ces;
}
}
return null;
} finally {
all.remove(lkp);
}
}
示例6: sortFiles
import java.util.IdentityHashMap; //导入依赖的package包/类
public static Map<ClasspathInfo, Collection<FileObject>> sortFiles(Collection<? extends FileObject> from) {
Map<CPCategorizer, Collection<FileObject>> m = new HashMap<CPCategorizer, Collection<FileObject>>();
for (FileObject f : from) {
CPCategorizer cpCategorizer = new CPCategorizer(f);
Collection<FileObject> files = m.get(cpCategorizer);
if (files == null) {
m.put(cpCategorizer, files = new LinkedList<FileObject>());
}
files.add(f);
}
Map<ClasspathInfo, Collection<FileObject>> result = new IdentityHashMap<ClasspathInfo, Collection<FileObject>>();
for (Entry<CPCategorizer, Collection<FileObject>> e : m.entrySet()) {
result.put(ClasspathInfo.create(e.getKey().boot, e.getKey().compile, e.getKey().source), e.getValue());
}
return result;
}
示例7: vulOnderzoeken
import java.util.IdentityHashMap; //导入依赖的package包/类
private static Map<Onderzoek, Lo3Onderzoek> vulOnderzoeken(final Collection<Onderzoek> onderzoeken) {
final Map<Onderzoek, Lo3Onderzoek> resultaat = new IdentityHashMap<>();
for (final Onderzoek onderzoek : onderzoeken) {
final OnderzoekStandaardRecord onderzoekActueel = bepaalLaatsteRecord(onderzoek.getStandaard());
Assert.notNull(onderzoekActueel, "Geen actueel record voor onderzoek gevonden.");
if (onderzoekActueel != null) {
final String lo3GegevensInOnderzoek = bepaalGegevensInOnderzoek(onderzoekActueel);
final Lo3Datum datumIngangOnderzoek = new BrpDatum(onderzoekActueel.getDatumAanvang(), null).converteerNaarLo3Datum();
final boolean isOnderzoekBeindigd = StatusOnderzoek.AFGESLOTEN.getNaam().equals(onderzoekActueel.getStatus());
final Lo3Datum datumEindeOnderzoek = isOnderzoekBeindigd ? new BrpDatum(onderzoekActueel.getDatumEinde(), null).converteerNaarLo3Datum() : null;
final Lo3Onderzoek lo3Onderzoek = new Lo3Onderzoek(new Lo3Integer(lo3GegevensInOnderzoek, null), datumIngangOnderzoek, datumEindeOnderzoek);
resultaat.put(onderzoek, lo3Onderzoek);
}
}
return resultaat;
}
示例8: computeDataFlow
import java.util.IdentityHashMap; //导入依赖的package包/类
private void computeDataFlow() {
Map<Tree, Collection<Tree>> res = new IdentityHashMap<Tree, Collection<Tree>>(7);
for (Map.Entry<Tree, Iterable<? extends TreePath>> e : assignmentsForUse.entrySet()) {
Tree k = e.getKey();
for (TreePath p : e.getValue()) {
if (p == null) {
continue;
}
Tree l = p.getLeaf();
Collection<Tree> users = res.get(l);
if (users == null) {
users = new ArrayList<Tree>(2);
res.put(l, users);
}
users.add(k);
}
}
dataFlow = res;
}
示例9: testIdentityHashMap
import java.util.IdentityHashMap; //导入依赖的package包/类
@Test
public void testIdentityHashMap() {
for (int i = 0; i < 100000; i++) {
Map<Integer,String> test = new IdentityHashMap<>();
for (int k = 0; k < 7; k++) {
test.put(new Integer(k), "");
}
Iterator<Integer> testIter = test.keySet().iterator();
while (testIter.hasNext()) {
Integer elem = testIter.next();
if (elem.intValue() != 6) {
testIter.remove();
}
}
assertEquals(1, test.keySet().size());
assertEquals(Collections.singleton(new Integer(6)), test.keySet());
}
}
示例10: main
import java.util.IdentityHashMap; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
final IdentityHashMap<String, String> identityHashMap =
new IdentityHashMap<>();
identityHashMap.put("One", "Un");
identityHashMap.put("Two", "Deux");
identityHashMap.put("Three", "Trois");
Set<Map.Entry<String, String>> entrySet = identityHashMap.entrySet();
HashSet<Map.Entry<String, String>> hashSet = new HashSet<>(entrySet);
// NB: These comparisons are valid in this case because none of the
// keys put into 'identityHashMap' above are equal to any other.
if (false == hashSet.equals(entrySet)) {
throw new RuntimeException("Test FAILED: Sets are not equal.");
}
if (hashSet.hashCode() != entrySet.hashCode()) {
throw new RuntimeException("Test FAILED: Set's hashcodes are not equal.");
}
}
示例11: main
import java.util.IdentityHashMap; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
final IdentityHashMap<String, String> identityHashMap =
new IdentityHashMap<>();
identityHashMap.put("One", "Un");
identityHashMap.put("Two", "Deux");
identityHashMap.put("Three", "Trois");
Iterator<Map.Entry<String, String>> entrySetIterator =
identityHashMap.entrySet().iterator();
Map.Entry<String, String> entry = entrySetIterator.next();
entrySetIterator.remove();
try {
entry.getKey();
throw new RuntimeException("Test FAILED: Entry not invalidated by removal.");
} catch (Exception e) { }
}
示例12: invoke
import java.util.IdentityHashMap; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
if (method.getDeclaringClass() == Object.class) {
return method.invoke(map, args);
}
String methodName = method.getName();
Object value = null;
if (methodName.length() > 3 && methodName.startsWith("get")) {
value = map.get(methodName.substring(3, 4).toLowerCase() + methodName.substring(4));
} else if (methodName.length() > 2 && methodName.startsWith("is")) {
value = map.get(methodName.substring(2, 3).toLowerCase() + methodName.substring(3));
} else {
value = map.get(methodName.substring(0, 1).toLowerCase() + methodName.substring(1));
}
if (value instanceof Map<?,?> && ! Map.class.isAssignableFrom(method.getReturnType())) {
value = realize0((Map<String, Object>) value, method.getReturnType(), null, new IdentityHashMap<Object, Object>());
}
return value;
}
示例13: testReconcile
import java.util.IdentityHashMap; //导入依赖的package包/类
@Test
public void testReconcile() throws Exception {
Map<Instruction, String> values = new IdentityHashMap<>();
values.put(CreateInstruction.builder().build(), "i1");
values.put(CancelInstruction.builder().build(), "i2");
values.put(null, "i3");
values.put(CancelInstruction.builder().build(), null);
Request request = Request.builder().build();
doReturn(TRUE).when(target).checkCreated(same(context), any(), eq("i1"), any(), any());
doReturn(TRUE).when(target).checkCancelled(same(context), any(), eq("i2"), any(), any());
Map<Instruction, Boolean> results = target.reconcile(context, request, values);
assertEquals(results.size(), 2);
results.values().forEach(Assert::assertTrue);
verify(target).checkCreated(same(context), any(), eq("i1"), any(), any());
verify(target).checkCancelled(same(context), any(), eq("i2"), any(), any());
// No input
assertEquals(target.reconcile(context, request, null).size(), 0);
}
示例14: makeMapsMoreTypes
import java.util.IdentityHashMap; //导入依赖的package包/类
private static <T> Collection<Object[]> makeMapsMoreTypes(String desc,
T[] keys,
T val) {
Collection<Object[]> cases = new ArrayList<>();
cases.add(createCase("Hashtable with " + desc,
new Hashtable<>(), keys, val));
cases.add(createCase("IdentityHashMap with " + desc,
new IdentityHashMap<>(), keys, val));
cases.add(createCase("TreeMap with " + desc,
new TreeMap<>(), keys, val));
cases.add(createCase("WeakHashMap with " + desc,
new WeakHashMap<>(), keys, val));
cases.add(createCase("ConcurrentHashMap with " + desc,
new ConcurrentHashMap<>(), keys, val));
cases.add(createCase("ConcurrentSkipListMap with " + desc,
new ConcurrentSkipListMap<>(), keys, val));
return cases;
}
示例15: getRedisService
import java.util.IdentityHashMap; //导入依赖的package包/类
/**
* 获取单例
*
* @param redisPropertiesFilename
* @param tClass
* @param <T>
* @return
*/
public static <T extends AbstractRedisService> T getRedisService(String redisPropertiesFilename, Class<T> tClass) {
IdentityHashMap<Class, ? extends AbstractRedisService> redisServices = INSTANCES.get(redisPropertiesFilename);
if (redisServices != null) {
return (T) redisServices.get(tClass);
}
IdentityHashMap<Class, AbstractRedisService> newRedisServices = new IdentityHashMap<>();
RedisConfig redisConfig = getRedisConfig(redisPropertiesFilename);
newRedisServices.put(AppInfoCacheServiceAbstract.class, new AppInfoCacheServiceAbstract(redisConfig));
newRedisServices.put(InterfaceInfoCacheServiceAbstract.class, new InterfaceInfoCacheServiceAbstract(redisConfig));
newRedisServices.put(TokenInfoCacheServiceAbstract.class, new TokenInfoCacheServiceAbstract(redisConfig));
newRedisServices.put(FrequencyCacheServiceAbstract.class, new FrequencyCacheServiceAbstract(redisConfig));
newRedisServices.put(StatisticsCacheServiceAbstract.class, new StatisticsCacheServiceAbstract(redisConfig));
newRedisServices.put(VerificationCodeServiceAbstract.class, new VerificationCodeServiceAbstract(redisConfig));
newRedisServices.put(AuthCodeCacheServiceAbstract.class, new AuthCodeCacheServiceAbstract(redisConfig));
redisServices = INSTANCES.putIfAbsent(redisPropertiesFilename, newRedisServices);
if (redisServices == null) {
redisServices = newRedisServices;
}
return (T) redisServices.get(tClass);
}