当前位置: 首页>>代码示例>>Java>>正文


Java IdentityHashMap.put方法代码示例

本文整理汇总了Java中java.util.IdentityHashMap.put方法的典型用法代码示例。如果您正苦于以下问题:Java IdentityHashMap.put方法的具体用法?Java IdentityHashMap.put怎么用?Java IdentityHashMap.put使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.IdentityHashMap的用法示例。


在下文中一共展示了IdentityHashMap.put方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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);
}
 
开发者ID:wxz1211,项目名称:dooo,代码行数:29,代码来源:AbstractRedisService.java

示例2: getConstantExpressionSet

import java.util.IdentityHashMap; //导入方法依赖的package包/类
/**
 * Get a list of expressions that mark boundaries into a constant space.
 * @param e
 * @return
 */
public static Set<LogicalExpression> getConstantExpressionSet(LogicalExpression e){
  IdentityHashMap<LogicalExpression, Object> map = new IdentityHashMap<>();
  ConstantExpressionIdentifier visitor = new ConstantExpressionIdentifier();


  if(e.accept(visitor, map) && map.isEmpty()){
    // if we receive a constant value here but the map is empty, this means the entire tree is a constant.
    // note, we can't use a singleton collection here because we need an identity set.
    map.put(e, true);
    return map.keySet();
  }else if(map.isEmpty()){
    // so we don't continue to carry around a map, we let it go here and simply return an empty set.
    return Collections.emptySet();
  }else{
    return map.keySet();
  }
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:23,代码来源:ConstantExpressionIdentifier.java

示例3: processCollection

import java.util.IdentityHashMap; //导入方法依赖的package包/类
private Object processCollection(Object parent, Property property, Collection<?> col,
	IdentityHashMap<Object, Object> map, Map<Object, Object> evictees, InitialiserCallback callback,
	List<PropertySet> propsToSet)
{
	Collection<Object> newList = getSupportedCollection(col);

	for( Object colObj : col )
	{
		if( colObj != null )
		{
			Object newObj = processObject(parent, property, colObj, null, map, evictees, callback, propsToSet);
			newList.add(newObj);
		}
	}

	map.put(col, newList);
	return newList;
}
 
开发者ID:equella,项目名称:Equella,代码行数:19,代码来源:InitialiserServiceImpl.java

示例4: 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) { }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:EntrySetIteratorRemoveInvalidatesEntry.java

示例5: checkChildren

import java.util.IdentityHashMap; //导入方法依赖的package包/类
private boolean checkChildren(LogicalExpression e, IdentityHashMap<LogicalExpression, Object> value, boolean transmitsConstant){
  List<LogicalExpression> constants = Lists.newLinkedList();
  boolean constant = true;

  for(LogicalExpression child : e){
    if(child.accept(this, value)){
      constants.add(child);
    }else{
      constant = false;
    }
  }

  // if one or more clauses isn't constant, this isn't constant.  this also isn't a constant if it operates on a set.
  if(!constant || !transmitsConstant){
    for(LogicalExpression c: constants){
      value.put(c, true);
    }
  }
  return constant && transmitsConstant;
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:21,代码来源:ConstantExpressionIdentifier.java

示例6: readIdentityHashMap

import java.util.IdentityHashMap; //导入方法依赖的package包/类
/**
 * Reads a <code>IdentityHashMap</code> from a <code>DataInput</code>. Note that key identity is
 * not preserved unless the keys belong to a class whose serialization preserves identity.
 *
 * @throws IOException A problem occurs while reading from <code>in</code>
 * @throws ClassNotFoundException The class of one of the <Code>IdentityHashMap</code>'s elements
 *         cannot be found.
 *
 * @see #writeIdentityHashMap
 */
public static <K, V> IdentityHashMap<K, V> readIdentityHashMap(DataInput in)
    throws IOException, ClassNotFoundException {

  InternalDataSerializer.checkIn(in);

  int size = InternalDataSerializer.readArrayLength(in);
  if (size == -1) {
    return null;
  } else {
    IdentityHashMap<K, V> map = new IdentityHashMap<K, V>(size);
    for (int i = 0; i < size; i++) {
      K key = DataSerializer.<K>readObject(in);
      V value = DataSerializer.<V>readObject(in);
      map.put(key, value);
    }

    if (logger.isTraceEnabled(LogMarker.SERIALIZER)) {
      logger.trace(LogMarker.SERIALIZER, "Read IdentityHashMap with {} elements: {}", size, map);
    }

    return map;
  }
}
 
开发者ID:ampool,项目名称:monarch,代码行数:34,代码来源:DataSerializer.java

示例7: testIdentityHashMapObject

import java.util.IdentityHashMap; //导入方法依赖的package包/类
/**
 * Tests data serializing an {@link IdentityHashMap} using {@link DataSerializer#writeObject}.
 */
@Test
public void testIdentityHashMapObject() throws Exception {
  Random random = getRandom();
  IdentityHashMap map = new IdentityHashMap();
  int size = random.nextInt(50);
  for (int i = 0; i < size; i++) {
    Object key = new Long(random.nextLong());
    Object value = String.valueOf(random.nextLong());
    map.put(key, value);
  }

  DataOutputStream out = getDataOutput();
  DataSerializer.writeObject(map, out);
  out.flush();

  DataInput in = getDataInput();
  IdentityHashMap map2 = (IdentityHashMap) DataSerializer.readObject(in);
  assertEquals(new HashMap(map), new HashMap(map2));
}
 
开发者ID:ampool,项目名称:monarch,代码行数:23,代码来源:DataSerializableJUnitTest.java

示例8: 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.");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:DistinctEntrySetElements.java

示例9: actionPerformed

import java.util.IdentityHashMap; //导入方法依赖的package包/类
@Override
public void actionPerformed (ActionEvent e) {
    //System.err.println("Models.ActionSupport.actionPerformed("+e+")");
    Node[] ns = getActiveNodes(e);
    int i, k = ns.length;
    IdentityHashMap<Action, ArrayList<Object>> h = new IdentityHashMap<Action, ArrayList<Object>>();
    for (i = 0; i < k; i++) {
        Object node = ns[i].getLookup().lookup(Object.class);
        Action[] as = ns [i].getActions (false);
        int j, jj = as.length;
        for (j = 0; j < jj; j++) {
            if (equals (as [j])) {
                ArrayList<Object> l = h.get (as [j]);
                if (l == null) {
                    l = new ArrayList<Object>();
                    h.put (as [j], l);
                }
                l.add (node);
            }
        }
    }
    //System.err.println("  k = "+k);
    if (k == 0) {
        if (multiselectionType != MULTISELECTION_TYPE_EXACTLY_ONE) {
            performer.perform(new Object[]{});
        }
    } else {
        //System.err.println("  h = "+h);
        Iterator<Action> it = h.keySet ().iterator ();
        while (it.hasNext ()) {
            ActionSupport a = (ActionSupport) it.next ();
            //System.err.println("  "+a.performer+".perform("+((ArrayList) h.get (a)));
            a.performer.perform (
                ((ArrayList) h.get (a)).toArray ()
            );
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:39,代码来源:Models.java

示例10: commit

import java.util.IdentityHashMap; //导入方法依赖的package包/类
private void commit () {
    final List<Work> first = new LinkedList<Work>();
    final List<Work> rest = new LinkedList<Work>();
    final IdentityHashMap<Work,Work> seenDelete = new IdentityHashMap<Work, Work>();
    final Map<URL,Map<String,Pair<FileEventLog.FileOp,Work>>> myChanges = getChanges(false);
    if (myChanges != null) {
        for (Map<String,Pair<FileOp,Work>> changesInRoot : myChanges.values()) {
            for (Pair<FileOp,Work> desc : changesInRoot.values()) {
                if (desc.first() == FileOp.DELETE) {
                    if (!seenDelete.containsKey(desc.second())) {
                        first.add(desc.second());
                        seenDelete.put(desc.second(), desc.second());
                    }
                }
                else {
                    rest.add(desc.second());
                }
            }
        }
    }
    final RepositoryUpdater ru = RepositoryUpdater.getDefault();
    if (LOG.isLoggable(Level.FINER)) {
        LOG.finer("SCHEDULING: " + first); //NOI18N
    }
    ru.scheduleWork(first);
    
    if (LOG.isLoggable(Level.FINER)) {
        LOG.finer("SCHEDULING: " + rest); //NOI18N
    }
    ru.scheduleWork(rest);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:32,代码来源:FileEventLog.java

示例11: createDescriptorIfAbsent

import java.util.IdentityHashMap; //导入方法依赖的package包/类
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;
    }
}
 
开发者ID:zhuxiaolei,项目名称:dubbo2,代码行数:13,代码来源:JavaBeanSerializeUtil.java

示例12: getAllAtoms

import java.util.IdentityHashMap; //导入方法依赖的package包/类
/**
 * Returns a modifiable copy of the list of all i-th atom from all tuples in
 * some arbitrary order (0 is first atom, 1 is second atom...)
 * 
 * @throws - ErrorAPI if this tupleset contains at least one tuple whose
 *             length is less than or equal to i
 */
public List<SimAtom> getAllAtoms(int column) throws ErrorAPI {
	if (empty())
		return new ArrayList<SimAtom>(0);
	if (column < 0 || column >= arity())
		throw new ErrorAPI("This tupleset does not have an \"" + column + "th\" column.");
	IdentityHashMap<SimAtom,Boolean> ans = new IdentityHashMap<SimAtom,Boolean>();
	for (SimTuple x : this)
		ans.put(x.get(column), Boolean.TRUE);
	return new ArrayList<SimAtom>(ans.keySet());
}
 
开发者ID:AlloyTools,项目名称:org.alloytools.alloy,代码行数:18,代码来源:SimTupleset.java

示例13: ofIdentityHashMap

import java.util.IdentityHashMap; //导入方法依赖的package包/类
/**
 * Checks adequacy of the expected maximum size of a static field
 * of type {@code IdentityHashMap}.
 *
 * Having
 * <pre>
 * class XClass {
 *     static IdentityHashMap theMap = new IdentityHashMap(M);
 * }
 * </pre>
 *
 * you should call from the test
 *
 * <pre>
 * OptimalCapacity.ofIdentityHashMap(XClass.class, "theMap", M);
 * </pre>
 */
public static void ofIdentityHashMap(Class<?> clazz, String fieldName,
        int expectedMaxSize)
{
    try {
        Field field = clazz.getDeclaredField(fieldName);
        field.setAccessible(true);
        Object obj = field.get(null);
        if (!IdentityHashMap.class.equals(obj.getClass())) {
            throw new RuntimeException("'" + field +
                "' expected to be of type IdentityHashMap");
        }
        IdentityHashMap<?,?> map = (IdentityHashMap<?,?>)obj;

        // Check that size of map is what was expected
        if (map.size() != expectedMaxSize) {
            throw new RuntimeException("Size of '" + field +
                "' is " + map.size() +
                ", which differs from expected " + expectedMaxSize);
        }

        // Check that the map allocated only necessary amount of memory
        IdentityHashMap<Object, Object> tmp = new IdentityHashMap<>(map);
        if (internalArraySize(map) != internalArraySize(tmp)) {
            throw new RuntimeException("Final capacity of '" + field +
                "' is " + internalArraySize(map) +
                ", which exceeds necessary minimum " + internalArraySize(tmp));
        }

        // Check that map was initially properly sized
        tmp = new IdentityHashMap<>(expectedMaxSize);
        tmp.put(new Object(), new Object()); // trigger storage init
        if (internalArraySize(map) != internalArraySize(tmp)) {
            throw new RuntimeException("Requested number of elements in '" + field +
                "' was " + expectedMaxSize +
                ", which resulted in final capacity " + internalArraySize(tmp) +
                ", which differs from necessary minimum " + internalArraySize(map));
        }
    } catch (ReflectiveOperationException roe) {
        throw new RuntimeException(roe);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:59,代码来源:OptimalCapacity.java

示例14: initialiseClones

import java.util.IdentityHashMap; //导入方法依赖的package包/类
private void initialiseClones(Object object, IdentityHashMap<Object, Object> previous, Map<Object, Object> evictees,
	Object parent, Property property)
{
	if( object == null || previous.containsKey(object) )
	{
		return;
	}

	Class<? extends Object> clazz = object.getClass();
	if( clazz.isArray() || clazz.isPrimitive() || clazz.getPackage().getName().equals("java.lang") ) //$NON-NLS-1$
	{
		return;
	}
	if( property != null
		&& (property.isDoNotClone() || (getCacheObject(clazz).isEntity() && !(object instanceof IdCloneable))) )
	{
		return;
	}

	previous.put(object, object);

	if( object instanceof Collection )
	{
		Collection<?> col = (Collection<?>) object;
		for( Object colObj : col )
		{
			initialiseClones(unwrapHibernate(colObj), previous, evictees, parent, property);
		}
	}
	else if( object instanceof Map )
	{
		initialiseClones(((Map<?, ?>) object).keySet(), previous, evictees, parent, property);
		initialiseClones(((Map<?, ?>) object).values(), previous, evictees, parent, property);
	}
	else
	{
		List<Property> properties = getCacheObject(clazz).getProperties();
		for( Property childProp : properties )
		{
			initialiseClones(unwrapHibernate(childProp.get(object)), previous, evictees, object, childProp);
		}
	}

	evictees.put(object, object);
	if( object instanceof IdCloneable )
	{
		((IdCloneable) object).setId(0);
	}
}
 
开发者ID:equella,项目名称:Equella,代码行数:50,代码来源:InitialiserServiceImpl.java

示例15: acquireBuffer

import java.util.IdentityHashMap; //导入方法依赖的package包/类
static ByteBuffer acquireBuffer(int size, DMStats stats, boolean send) {
  ByteBuffer result;
  if (TCPConduit.useDirectBuffers) {
    IdentityHashMap<BBSoftReference, BBSoftReference> alreadySeen = null; // keys are used like a
                                                                          // set
    BBSoftReference ref = (BBSoftReference) bufferQueue.poll();
    while (ref != null) {
      ByteBuffer bb = ref.getBB();
      if (bb == null) {
        // it was garbage collected
        int refSize = ref.consumeSize();
        if (refSize > 0) {
          if (ref.getSend()) { // fix bug 46773
            stats.incSenderBufferSize(-refSize, true);
          } else {
            stats.incReceiverBufferSize(-refSize, true);
          }
        }
      } else if (bb.capacity() >= size) {
        bb.rewind();
        bb.limit(size);
        return bb;
      } else {
        // wasn't big enough so put it back in the queue
        Assert.assertTrue(bufferQueue.offer(ref));
        if (alreadySeen == null) {
          alreadySeen = new IdentityHashMap<BBSoftReference, BBSoftReference>();
        }
        if (alreadySeen.put(ref, ref) != null) {
          // if it returns non-null then we have already seen this item
          // so we have worked all the way through the queue once.
          // So it is time to give up and allocate a new buffer.
          break;
        }
      }
      ref = (BBSoftReference) bufferQueue.poll();
    }
    result = ByteBuffer.allocateDirect(size);
  } else {
    // if we are using heap buffers then don't bother with keeping them around
    result = ByteBuffer.allocate(size);
  }
  if (send) {
    stats.incSenderBufferSize(size, TCPConduit.useDirectBuffers);
  } else {
    stats.incReceiverBufferSize(size, TCPConduit.useDirectBuffers);
  }
  return result;
}
 
开发者ID:ampool,项目名称:monarch,代码行数:50,代码来源:Buffers.java


注:本文中的java.util.IdentityHashMap.put方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。