Java Code Examples for java.util.IdentityHashMap#entrySet()

The following examples show how to use java.util.IdentityHashMap#entrySet() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DistinctEntrySetElements.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
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.");
    }
}
 
Example 2
Source File: DistinctEntrySetElements.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
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.");
    }
}
 
Example 3
Source File: DataSerializer.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
    }
  }
}
 
Example 4
Source File: DistinctEntrySetElements.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
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.");
    }
}
 
Example 5
Source File: DistinctEntrySetElements.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
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.");
    }
}
 
Example 6
Source File: DataSerializer.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
    }
  }
}
 
Example 7
Source File: DistinctEntrySetElements.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
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.");
    }
}
 
Example 8
Source File: DistinctEntrySetElements.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
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.");
    }
}
 
Example 9
Source File: DistinctEntrySetElements.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
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.");
    }
}
 
Example 10
Source File: DistinctEntrySetElements.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
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.");
    }
}
 
Example 11
Source File: MaterialCache.java    From litematica with GNU Lesser General Public License v3.0 6 votes vote down vote up
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;
}
 
Example 12
Source File: DistinctEntrySetElements.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
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.");
    }
}
 
Example 13
Source File: DistinctEntrySetElements.java    From native-obfuscator with GNU General Public License v3.0 6 votes vote down vote up
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.");
    }
}
 
Example 14
Source File: DistinctEntrySetElements.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
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.");
    }
}
 
Example 15
Source File: RegexDfaByte.java    From arcusplatform with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example 16
Source File: IdentityHashMapTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * 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());
}
 
Example 17
Source File: IdentityHashMapTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * 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()));
    }
}
 
Example 18
Source File: IdentityHashMapTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
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));
}
 
Example 19
Source File: CityGMLImportManager.java    From importer-exporter with Apache License 2.0 5 votes vote down vote up
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);
		}
	}
}
 
Example 20
Source File: IdentityHashMapTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
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);
}