java.util.IdentityHashMap#entrySet ( )源码实例Demo

下面列出了java.util.IdentityHashMap#entrySet ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

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.");
    }
}
 
源代码2 项目: arcusplatform   文件: RegexDfaByte.java
public <T> RegexDfaByte<T> transform(Function<V,T> transformer) {
   IdentityHashMap<State<V>,State<T>> stateMap = new IdentityHashMap<>();

   State<T> newInitialState = null;
   for (State<V> state : states) {
      State<T> transformed = state.transform(transformer);
      if (transformed.isInitialState()) {
         newInitialState = transformed;
      }

      stateMap.put(state, transformed);
   }

   for (Map.Entry<State<V>,State<T>> entry : stateMap.entrySet()) {
      State<V> oldState = entry.getKey();
      State<T> newState = entry.getValue();
      newState.setTransitions(oldState.getTransitions().transform(stateMap,transformer));
   }

   if (newInitialState == null) {
      throw new IllegalStateException("no initial state");
   }

   Set<State<T>> newStates = ImmutableSet.copyOf(stateMap.values());
   return new RegexDfaByte<T>(newInitialState, newStates);
}
 
源代码3 项目: TencentKona-8   文件: DistinctEntrySetElements.java
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.");
    }
}
 
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.");
    }
}
 
源代码5 项目: jdk8u60   文件: DistinctEntrySetElements.java
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.");
    }
}
 
源代码6 项目: litematica   文件: MaterialCache.java
protected NBTTagList writeMapToNBT(IdentityHashMap<IBlockState, ItemStack> map)
{
    NBTTagList list = new NBTTagList();

    for (Map.Entry<IBlockState, ItemStack> entry : map.entrySet())
    {
        NBTTagCompound tag = new NBTTagCompound();
        NBTTagCompound stateTag = new NBTTagCompound();
        NBTUtil.writeBlockState(stateTag, entry.getKey());

        tag.setTag("Block", stateTag);
        tag.setTag("Item", entry.getValue().writeToNBT(new NBTTagCompound()));

        list.appendTag(tag);
    }

    return list;
}
 
源代码7 项目: openjdk-jdk8u   文件: DistinctEntrySetElements.java
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.");
    }
}
 
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.");
    }
}
 
源代码9 项目: openjdk-jdk9   文件: DistinctEntrySetElements.java
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.");
    }
}
 
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 项目: gemfirexd-oss   文件: DataSerializer.java
/**
 * Writes a <code>IdentityHashMap</code> to a <code>DataOutput</code>.  Note
 * that even though <code>map</code> may be an instance of a
 * subclass of <code>IdentityHashMap</code>, <code>readIdentityHashMap</code> will
 * always return an instance of <code>IdentityHashMap</code>, <B>not</B> an
 * instance of the subclass.  To preserve the class type of
 * <code>map</code>, {@link #writeObject(Object, DataOutput)} should be used for data
 * serialization.
 *
 * @throws IOException
 *         A problem occurs while writing to <code>out</code>
 *
 * @see #readIdentityHashMap
 */
public static void writeIdentityHashMap(IdentityHashMap<?,?> map, DataOutput out)
  throws IOException {

  InternalDataSerializer.checkOut(out);

  int size;
  if (map == null) {
    size = -1;
  } else {
    size = map.size();
  }
  InternalDataSerializer.writeArrayLength(size, out);
  if (DEBUG) {
    InternalDataSerializer.logger.info( LocalizedStrings.DEBUG, "Writing IdentityHashMap with " + size + " elements: " + map);
  }
  if (size > 0) {
    for (Map.Entry<?,?> entry: map.entrySet()){
      writeObject(entry.getKey(), out);
      writeObject(entry.getValue(), out);
    }
  }
}
 
源代码12 项目: openjdk-8   文件: DistinctEntrySetElements.java
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.");
    }
}
 
源代码13 项目: gemfirexd-oss   文件: DataSerializer.java
/**
 * Writes a <code>IdentityHashMap</code> to a <code>DataOutput</code>.  Note
 * that even though <code>map</code> may be an instance of a
 * subclass of <code>IdentityHashMap</code>, <code>readIdentityHashMap</code> will
 * always return an instance of <code>IdentityHashMap</code>, <B>not</B> an
 * instance of the subclass.  To preserve the class type of
 * <code>map</code>, {@link #writeObject(Object, DataOutput)} should be used for data
 * serialization.
 *
 * @throws IOException
 *         A problem occurs while writing to <code>out</code>
 *
 * @see #readIdentityHashMap
 */
public static void writeIdentityHashMap(IdentityHashMap<?,?> map, DataOutput out)
  throws IOException {

  InternalDataSerializer.checkOut(out);

  int size;
  if (map == null) {
    size = -1;
  } else {
    size = map.size();
  }
  InternalDataSerializer.writeArrayLength(size, out);
  if (DEBUG) {
    InternalDataSerializer.logger.info( LocalizedStrings.DEBUG, "Writing IdentityHashMap with " + size + " elements: " + map);
  }
  if (size > 0) {
    for (Map.Entry<?,?> entry: map.entrySet()){
      writeObject(entry.getKey(), out);
      writeObject(entry.getValue(), out);
    }
  }
}
 
源代码14 项目: jdk8u-jdk   文件: DistinctEntrySetElements.java
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.");
    }
}
 
源代码15 项目: jdk8u-dev-jdk   文件: DistinctEntrySetElements.java
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.");
    }
}
 
源代码16 项目: j2objc   文件: IdentityHashMapTest.java
public void test_spliterator_entrySet() {
    IdentityHashMap<String, String> hashMap = new IdentityHashMap<>();
    hashMap.put("a", "1");
    hashMap.put("b", "2");
    hashMap.put("c", "3");
    hashMap.put("d", "4");
    hashMap.put("e", "5");
    hashMap.put("f", "6");
    hashMap.put("g", "7");
    hashMap.put("h", "8");
    hashMap.put("i", "9");
    hashMap.put("j", "10");
    hashMap.put("k", "11");
    hashMap.put("l", "12");
    hashMap.put("m", "13");
    hashMap.put("n", "14");
    hashMap.put("o", "15");
    hashMap.put("p", "16");

    Set<Map.Entry<String, String>> values = hashMap.entrySet();
    ArrayList<Map.Entry<String, String>> expectedValues = new ArrayList<>(values);

    Comparator<Map.Entry<String, String>> comparator =
            (a, b) -> (a.getKey().compareTo(b.getKey()));

    SpliteratorTester.runBasicIterationTests(values.spliterator(), expectedValues);
    SpliteratorTester.runBasicSplitTests(values, expectedValues, comparator);
    SpliteratorTester.testSpliteratorNPE(values.spliterator());
    SpliteratorTester.assertSupportsTrySplit(values);
}
 
源代码17 项目: importer-exporter   文件: CityGMLImportManager.java
protected void delegateToADEImporter(AbstractGML object, long objectId, AbstractObjectType<?> objectType) throws CityGMLImportException, SQLException {
	// delegate import of ADE object to an ADE importer
	if (object instanceof ADEModelObject) {
		ADEModelObject adeObject = (ADEModelObject)object;

		ForeignKeys foreignKeys = (ForeignKeys)object.getLocalProperty(CoreConstants.FOREIGN_KEYS_SET);
		if (foreignKeys == null)
			foreignKeys = ForeignKeys.EMPTY_SET;

		getADEImportManager(adeObject).importObject(adeObject, objectId, objectType, foreignKeys);
	}

	// if the object is a CityGML feature or an ADE feature derived from a CityGML feature
	// then check for generic ADE properties and delegate their import to an ADE importer
	if (object instanceof AbstractFeature && object instanceof CityGMLModuleComponent) {
		AbstractFeature feature = (AbstractFeature)object;

		List<ADEModelObject> properties = propertyCollector.getADEProperties(feature);
		if (properties != null && !properties.isEmpty()) {
			IdentityHashMap<ADEImportManager, ADEPropertyCollection> groupedBy = new IdentityHashMap<>();
			for (ADEModelObject property : properties) {
				ADEImportManager adeImporter = getADEImportManager(property);
				ADEPropertyCollection collection = groupedBy.get(adeImporter);
				if (collection == null) {
					collection = new ADEPropertyCollection();
					groupedBy.put(adeImporter, collection);
				}

				collection.register(property);
			}

			for (Entry<ADEImportManager, ADEPropertyCollection> entry : groupedBy.entrySet())
				entry.getKey().importGenericApplicationProperties(entry.getValue(), feature, objectId, (FeatureType)objectType);
		}
	}
}
 
源代码18 项目: j2objc   文件: IdentityHashMapTest.java
public void test_underlyingMap() {
    IdentityHashMap<String, String> ihm = new IdentityHashMap<String, String>();
    String key = "key";
    String value = "value";
    ihm.put(key, value);

    Set<Map.Entry<String, String>> set = ihm.entrySet();
    assertEquals(1, set.size());

    Map.Entry<String, String> entry = set.iterator().next();

    String newValue = "newvalue";
    entry.setValue(newValue);
    assertSame(newValue, ihm.get(key));
}
 
源代码19 项目: j2objc   文件: IdentityHashMapTest.java
/**
 * java.util.IdentityHashMap#entrySet()
 * java.util.IdentityHashMap#keySet()
 * java.util.IdentityHashMap#values()
 */
public void test_sets() {
    // tests with null keys and values
    IdentityHashMap map = new IdentityHashMap();

    // null key and null value
    map.put("key", "value");
    map.put(null, null);
    map.put("a key", null);
    map.put("another key", null);

    Set keyset = map.keySet();
    Collection valueset = map.values();
    Set entries = map.entrySet();
    Iterator it = entries.iterator();
    while (it.hasNext()) {
        Map.Entry entry = (Map.Entry) it.next();
        assertTrue("EntrySetIterator can not find entry ", entries
                .contains(entry));

        assertTrue("entry key not found in map", map.containsKey(entry
                .getKey()));
        assertTrue("entry value not found in map", map.containsValue(entry
                .getValue()));

        assertTrue("entry key not found in the keyset", keyset
                .contains(entry.getKey()));
        assertTrue("entry value not found in the valueset", valueset
                .contains(entry.getValue()));
    }
}
 
源代码20 项目: j2objc   文件: IdentityHashMapTest.java
/**
 * java.util.IdentityHashMap#entrySet()
 * java.util.IdentityHashMap#remove(java.lang.Object)
 */
public void test_entrySet_removeAll() {
    IdentityHashMap map = new IdentityHashMap();
    for (int i = 0; i < 1000; i++) {
        map.put(new Integer(i), new Integer(i));
    }
    Set set = map.entrySet();

    set.removeAll(set);
    assertEquals("did not remove all elements in the map", 0, map.size());
    assertTrue("did not remove all elements in the entryset", set.isEmpty());

    Iterator it = set.iterator();
    assertTrue("entrySet iterator still has elements", !it.hasNext());
}