本文整理了Java中java.util.IdentityHashMap.put()
方法的一些代码示例,展示了IdentityHashMap.put()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IdentityHashMap.put()
方法的具体详情如下:
包路径:java.util.IdentityHashMap
类名称:IdentityHashMap
方法名:put
[英]Associates the specified value with the specified key in this identity hash map. If the map previously contained a mapping for the key, the old value is replaced.
[中]将指定值与此标识哈希映射中的指定键相关联。如果映射以前包含键的映射,则替换旧值。
代码示例来源:origin: SonarSource/sonarqube
void match(RAW raw, BASE base) {
if (!rawToBase.containsKey(raw)) {
rawToBase.put(raw, base);
baseToRaw.put(base, raw);
}
}
代码示例来源:origin: apache/incubator-dubbo
private static JavaBeanDescriptor createDescriptorIfAbsent(Object obj, JavaBeanAccessor accessor, IdentityHashMap<Object, JavaBeanDescriptor> cache) {
if (cache.containsKey(obj)) {
return cache.get(obj);
} else if (obj instanceof JavaBeanDescriptor) {
return (JavaBeanDescriptor) obj;
} else {
JavaBeanDescriptor result = createDescriptorForSerialize(obj.getClass());
cache.put(obj, result);
serializeInternal(result, obj, accessor, cache);
return result;
}
}
代码示例来源:origin: apache/incubator-druid
private WritableMemory getMemory(ByteBuffer buffer)
{
WritableMemory mem = memCache.get(buffer);
if (mem == null) {
mem = WritableMemory.wrap(buffer, ByteOrder.LITTLE_ENDIAN);
memCache.put(buffer, mem);
}
return mem;
}
代码示例来源:origin: Graylog2/graylog2-server
final CodeBlock leftBlock = codeSnippet.get(expr.left());
final CodeBlock rightBlock = codeSnippet.get(expr.right());
codeSnippet.put(expr, CodeBlock.of("$L", intermediateName));
代码示例来源:origin: spotbugs/spotbugs
private void addHandler(InstructionHandle handle, CodeExceptionGen exceptionHandler) {
List<CodeExceptionGen> handlerList = codeToHandlerMap.get(handle);
if (handlerList == null) {
handlerList = new LinkedList<>();
codeToHandlerMap.put(handle, handlerList);
}
handlerList.add(exceptionHandler);
}
}
代码示例来源:origin: apache/incubator-dubbo
private static JavaBeanDescriptor createDescriptorIfAbsent(Object obj, JavaBeanAccessor accessor, IdentityHashMap<Object, JavaBeanDescriptor> cache) {
if (cache.containsKey(obj)) {
return cache.get(obj);
} else if (obj instanceof JavaBeanDescriptor) {
return (JavaBeanDescriptor) obj;
} else {
JavaBeanDescriptor result = createDescriptorForSerialize(obj.getClass());
cache.put(obj, result);
serializeInternal(result, obj, accessor, cache);
return result;
}
}
代码示例来源:origin: org.apache.lucene/lucene-core
/**
* Prunes the blockedQueue by removing all DWPT that are associated with the given flush queue.
*/
private void pruneBlockedQueue(final DocumentsWriterDeleteQueue flushingQueue) {
Iterator<BlockedFlush> iterator = blockedFlushes.iterator();
while (iterator.hasNext()) {
BlockedFlush blockedFlush = iterator.next();
if (blockedFlush.dwpt.deleteQueue == flushingQueue) {
iterator.remove();
assert !flushingWriters.containsKey(blockedFlush.dwpt) : "DWPT is already flushing";
// Record the flushing DWPT to reduce flushBytes in doAfterFlush
flushingWriters.put(blockedFlush.dwpt, Long.valueOf(blockedFlush.bytes));
// don't decr pending here - it's already done when DWPT is blocked
flushQueue.add(blockedFlush.dwpt);
}
}
}
代码示例来源:origin: opentripplanner/OpenTripPlanner
public void addIncoming(Vertex tov, Edge e) {
List<Edge> toIncoming = incoming.get(tov);
if (toIncoming == null) {
toIncoming = new ArrayList<Edge>(INITIAL_EDGELIST_CAPACITY);
incoming.put(tov, toIncoming);
}
if (!toIncoming.contains(e))
toIncoming.add(e);
}
代码示例来源:origin: protostuff/protostuff
/**
* If you are sure that you are only using a single implementation of your interface/abstract class, then it
* makes sense to map it directly to its impl class to avoid writing the type.
* <p>
* Note that the type is always written when your field is {@link java.lang.Object}.
* <p>
* Pojo ids start at 1.
*/
@Override
public <T> Registry mapPojo(Class<? super T> baseClass, Class<T> implClass)
{
if (strategy.pojoMapping.containsKey(baseClass))
throw new IllegalArgumentException("Duplicate registration for: " + baseClass);
BaseHS<?> wrapper = strategy.pojoMapping.get(implClass);
if (wrapper == null)
throw new IllegalArgumentException("Must register the impl class first. " + implClass);
strategy.pojoMapping.put(baseClass, wrapper);
return this;
}
代码示例来源:origin: apache/hive
private static void throwRangesError(DiskRangeList ranges, long offset, long end) {
seen.put(ranges, true);
StringBuilder errors = new StringBuilder();
while (ranges.prev != null) {
if (seen.containsKey(ranges.prev)) {
errors.append("loop: [").append(ranges).append(
"].prev = [").append(ranges.prev).append("]; ");
seen.put(ranges, true);
seen.put(ranges, true);
StringBuilder sb = new StringBuilder("Incorrect ranges detected while looking for ");
if (offset == end) {
"].next.prev = [").append(ranges.next.prev).append("]; ");
if (seen.containsKey(ranges.next)) {
errors.append("loop: [").append(ranges).append(
"].next = [").append(ranges.next).append("]; ");
seen.put(ranges, true);
代码示例来源:origin: opentripplanner/OpenTripPlanner
public void addOutgoing(Vertex fromv, Edge e) {
List<Edge> fromOutgoing = outgoing.get(fromv);
if (fromOutgoing == null) {
fromOutgoing = new ArrayList<Edge>(INITIAL_EDGELIST_CAPACITY);
outgoing.put(fromv, fromOutgoing);
}
if (!fromOutgoing.contains(e))
fromOutgoing.add(e);
}
代码示例来源:origin: apache/incubator-dubbo
private static Object instantiateForDeserialize(JavaBeanDescriptor beanDescriptor, ClassLoader loader, IdentityHashMap<JavaBeanDescriptor, Object> cache) {
if (cache.containsKey(beanDescriptor)) {
return cache.get(beanDescriptor);
cache.put(beanDescriptor, result);
} else {
try {
Class<?> cl = name2Class(loader, beanDescriptor.getClassName());
result = instantiate(cl);
cache.put(beanDescriptor, result);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e.getMessage(), e);
代码示例来源:origin: protostuff/protostuff
/**
* Pojo ids start at 1.
*/
@Override
public <T> Registry registerPojo(Class<T> clazz, int id)
{
if (clazz.isInterface() || Modifier.isAbstract(clazz.getModifiers()))
throw new IllegalArgumentException("Not a concrete class: " + clazz);
if (id < 1)
throw new IllegalArgumentException("pojo ids start at 1.");
if (id >= strategy.pojos.size())
grow(strategy.pojos, id + 1);
else if (strategy.pojos.get(id) != null)
{
throw new IllegalArgumentException("Duplicate id registration: " + id +
" (" + clazz.getName() + ")");
}
if (strategy.pojoMapping.containsKey(clazz))
throw new IllegalArgumentException("Duplicate registration for: " + clazz);
BaseHS<T> wrapper = new Lazy<T>(id, clazz, strategy);
strategy.pojos.set(id, wrapper);
strategy.pojoMapping.put(clazz, wrapper);
return this;
}
代码示例来源:origin: apache/incubator-dubbo
/**
* If the object has already been written, just write its ref.
*
* @return true if we're writing a ref.
*/
@Override
public boolean addRef(Object object)
throws IOException {
if (_refs == null)
_refs = new IdentityHashMap();
Integer ref = (Integer) _refs.get(object);
if (ref != null) {
int value = ref.intValue();
writeRef(value);
return true;
} else {
_refs.put(object, new Integer(_refs.size()));
return false;
}
}
代码示例来源:origin: apache/incubator-dubbo
private static Object instantiateForDeserialize(JavaBeanDescriptor beanDescriptor, ClassLoader loader, IdentityHashMap<JavaBeanDescriptor, Object> cache) {
if (cache.containsKey(beanDescriptor)) {
return cache.get(beanDescriptor);
cache.put(beanDescriptor, result);
} else {
try {
Class<?> cl = name2Class(loader, beanDescriptor.getClassName());
result = instantiate(cl);
cache.put(beanDescriptor, result);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e.getMessage(), e);
代码示例来源:origin: apache/hive
@Override
public TezSessionState reopen(TezSessionState session) throws Exception {
WmTezSession wmTezSession = ensureOwnedSession(session);
HiveConf sessionConf = wmTezSession.getConf();
if (sessionConf == null) {
// TODO: can this ever happen?
LOG.warn("Session configuration is null for " + wmTezSession);
sessionConf = new HiveConf(conf, WorkloadManager.class);
}
SettableFuture<WmTezSession> future = SettableFuture.create();
currentLock.lock();
try {
if (current.toReopen.containsKey(wmTezSession)) {
throw new AssertionError("The session is being reopened more than once " + session);
}
current.toReopen.put(wmTezSession, future);
notifyWmThreadUnderLock();
} finally {
currentLock.unlock();
}
return future.get();
}
代码示例来源:origin: wildfly/wildfly
private static Throwable injectDestination(Throwable t, URI destination) {
StackTraceElement[] stackTrace = new StackTraceElement[5];
System.arraycopy(t.getStackTrace(), 0, stackTrace, 1, 4);
stackTrace[0] = new StackTraceElement("", "..use of destination...", destination.toString(), -1);
t.setStackTrace(stackTrace);
IdentityHashMap<Throwable, Throwable> encountered = new IdentityHashMap<>(3);
encountered.put(t, t);
Throwable cause = t.getCause();
while (cause != null && encountered.get(cause) == null) {
encountered.put(cause, cause);
cause.setStackTrace(Arrays.copyOfRange(cause.getStackTrace(), 0, 5));
cause = cause.getCause();
}
return t;
}
代码示例来源:origin: com.google.inject/guice
if (initializablesCache.containsKey(instance)) {
@SuppressWarnings("unchecked") // Map from T to InjectableReference<T>
Initializable<T> cached = (Initializable<T>) initializablesCache.get(instance);
return cached;
source,
cycleDetectingLockFactory.create(instance.getClass()));
initializablesCache.put(instance, injectableReference);
pendingInjections.add(injectableReference);
return injectableReference;
代码示例来源:origin: protostuff/protostuff
/**
* Pojo ids start at 1.
*/
@Override
public <T> Registry registerPojo(Schema<T> schema, Pipe.Schema<T> pipeSchema,
int id)
{
if (id >= strategy.pojos.size())
grow(strategy.pojos, id + 1);
else if (strategy.pojos.get(id) != null)
{
throw new IllegalArgumentException("Duplicate id registration: " + id +
" (" + schema.typeClass().getName() + ")");
}
if (strategy.pojoMapping.containsKey(schema.typeClass()))
throw new IllegalArgumentException("Duplicate registration for: " + schema.typeClass());
Registered<T> wrapper = new Registered<T>(id, schema, pipeSchema, strategy);
strategy.pojos.set(id, wrapper);
strategy.pojoMapping.put(schema.typeClass(), wrapper);
return this;
}
代码示例来源:origin: apache/hive
void addUpdateError(WmTezSession wmTezSession, int endpointVersion) {
currentLock.lock();
try {
Integer existing = current.updateErrors.get(wmTezSession);
// Only store the latest error, if there are multiple.
if (existing != null && existing >= endpointVersion) return;
current.updateErrors.put(wmTezSession, endpointVersion);
notifyWmThreadUnderLock();
} finally {
currentLock.unlock();
}
}
内容来源于网络,如有侵权,请联系作者删除!