Java Code Examples for java.util.HashSet#equals()

The following examples show how to use java.util.HashSet#equals() . 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 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 2
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 ConcurrentHashMap<String, String> concurrentHashMap =
        new ConcurrentHashMap<>();

    concurrentHashMap.put("One", "Un");
    concurrentHashMap.put("Two", "Deux");
    concurrentHashMap.put("Three", "Trois");

    Set<Map.Entry<String, String>> entrySet = concurrentHashMap.entrySet();
    HashSet<Map.Entry<String, String>> hashSet = new HashSet<>(entrySet);

    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: 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 EnumMap<TestEnum, String> enumMap = new EnumMap<>(TestEnum.class);

    for (TestEnum e : TestEnum.values()) {
        enumMap.put(e, e.name());
    }

    Set<Map.Entry<TestEnum, String>> entrySet = enumMap.entrySet();
    HashSet<Map.Entry<TestEnum, String>> hashSet = new HashSet<>(entrySet);

    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 4
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 EnumMap<TestEnum, String> enumMap = new EnumMap<>(TestEnum.class);

    for (TestEnum e : TestEnum.values()) {
        enumMap.put(e, e.name());
    }

    Set<Map.Entry<TestEnum, String>> entrySet = enumMap.entrySet();
    HashSet<Map.Entry<TestEnum, String>> hashSet = new HashSet<>(entrySet);

    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 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 6
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 EnumMap<TestEnum, String> enumMap = new EnumMap<>(TestEnum.class);

    for (TestEnum e : TestEnum.values()) {
        enumMap.put(e, e.name());
    }

    Set<Map.Entry<TestEnum, String>> entrySet = enumMap.entrySet();
    HashSet<Map.Entry<TestEnum, String>> hashSet = new HashSet<>(entrySet);

    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 7
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 ConcurrentHashMap<String, String> concurrentHashMap =
        new ConcurrentHashMap<>();

    concurrentHashMap.put("One", "Un");
    concurrentHashMap.put("Two", "Deux");
    concurrentHashMap.put("Three", "Trois");

    Set<Map.Entry<String, String>> entrySet = concurrentHashMap.entrySet();
    HashSet<Map.Entry<String, String>> hashSet = new HashSet<>(entrySet);

    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: MapWritable.java    From nutch-htmlunit with Apache License 2.0 6 votes vote down vote up
public boolean equals(Object obj) {
  if (obj instanceof MapWritable) {
    MapWritable map = (MapWritable) obj;
    if (fSize != map.fSize) return false;
    HashSet<KeyValueEntry> set1 = new HashSet<KeyValueEntry>();
    KeyValueEntry e1 = fFirst;
    while (e1 != null) {
      set1.add(e1);
      e1 = e1.fNextEntry;
    }
    HashSet<KeyValueEntry> set2 = new HashSet<KeyValueEntry>();
    KeyValueEntry e2 = map.fFirst;
    while (e2 != null) {
      set2.add(e2);
      e2 = e2.fNextEntry;
    }
    return set1.equals(set2);
  }
  return false;
}
 
Example 9
Source File: DistinctEntrySetElements.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    final EnumMap<TestEnum, String> enumMap = new EnumMap<>(TestEnum.class);

    for (TestEnum e : TestEnum.values()) {
        enumMap.put(e, e.name());
    }

    Set<Map.Entry<TestEnum, String>> entrySet = enumMap.entrySet();
    HashSet<Map.Entry<TestEnum, String>> hashSet = new HashSet<>(entrySet);

    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: MapWritable.java    From anthelion with Apache License 2.0 6 votes vote down vote up
public boolean equals(Object obj) {
  if (obj instanceof MapWritable) {
    MapWritable map = (MapWritable) obj;
    if (fSize != map.fSize) return false;
    HashSet<KeyValueEntry> set1 = new HashSet<KeyValueEntry>();
    KeyValueEntry e1 = fFirst;
    while (e1 != null) {
      set1.add(e1);
      e1 = e1.fNextEntry;
    }
    HashSet<KeyValueEntry> set2 = new HashSet<KeyValueEntry>();
    KeyValueEntry e2 = map.fFirst;
    while (e2 != null) {
      set2.add(e2);
      e2 = e2.fNextEntry;
    }
    return set1.equals(set2);
  }
  return false;
}
 
Example 11
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 EnumMap<TestEnum, String> enumMap = new EnumMap<>(TestEnum.class);

    for (TestEnum e : TestEnum.values()) {
        enumMap.put(e, e.name());
    }

    Set<Map.Entry<TestEnum, String>> entrySet = enumMap.entrySet();
    HashSet<Map.Entry<TestEnum, String>> hashSet = new HashSet<>(entrySet);

    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 12
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 13
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 ConcurrentHashMap<String, String> concurrentHashMap =
        new ConcurrentHashMap<>();

    concurrentHashMap.put("One", "Un");
    concurrentHashMap.put("Two", "Deux");
    concurrentHashMap.put("Three", "Trois");

    Set<Map.Entry<String, String>> entrySet = concurrentHashMap.entrySet();
    HashSet<Map.Entry<String, String>> hashSet = new HashSet<>(entrySet);

    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: ProjectRestrictNode.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Is it possible to do a distinct scan on this ResultSet tree.
 * (See SelectNode for the criteria.)
 *
 * @param distinctColumns the set of distinct columns
 * @return Whether or not it is possible to do a distinct scan on this ResultSet tree.
 */
@Override
 boolean isPossibleDistinctScan(Set distinctColumns)
{
	if (restriction != null || 
		(restrictionList != null && restrictionList.size() != 0))
	{
		return false;
	}

	HashSet columns = new HashSet();
	for (int i = 0; i < resultColumns.size(); i++) {
		ResultColumn rc = (ResultColumn) resultColumns.elementAt(i);
		BaseColumnNode bc = rc.getBaseColumnNode();
		if (bc == null) return false;
		columns.add(bc);
	}

	return columns.equals(distinctColumns) && childResult.isPossibleDistinctScan(distinctColumns);
}
 
Example 15
Source File: RandomDataTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private int findSample(Object[] u, Object[] samp) {
    for (int i = 0; i < u.length; i++) {
        HashSet<Object> set = (HashSet<Object>) u[i];
        HashSet<Object> sampSet = new HashSet<Object>();
        for (int j = 0; j < samp.length; j++) {
            sampSet.add(samp[j]);
        }
        if (set.equals(sampSet)) {
            return i;
        }
    }
    fail("sample not found:{" + samp[0] + "," + samp[1] + "}");
    return -1;
}
 
Example 16
Source File: Serialization.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    int failures = 0;

    for (int i = 0; i < NUM_SETS; i++) {
        HashSet<Integer> hashSet = createHashSet();

        HashSet<Integer> result = null;
        try {
            result = serDeser(hashSet);
        } catch (IOException ioe) {
            System.err.println(ioe);
            failures++;
        } catch (ClassNotFoundException cnfe) {
            System.err.println(cnfe);
            failures++;
        }

        if (!hashSet.equals(result)) {
            System.err.println("Unequal HashSets!");
            printHashSet(hashSet);
            System.err.println();
            failures++;
        }
    }

    if (failures != 0) {
        throw new RuntimeException("HashSet/Serialzation failed with "+
                failures+" failures!");
    }
}
 
Example 17
Source File: RandomDataTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private int findSample(Object[] u, Object[] samp) {
	for (int i = 0; i < u.length; i++) {
		HashSet<Object> set = (HashSet<Object>) u[i];
		HashSet<Object> sampSet = new HashSet<Object>();
		for (int j = 0; j < samp.length; j++) {
			sampSet.add(samp[j]);
		}
		if (set.equals(sampSet)) {
			return i;
		}
	}
	fail("sample not found:{" + samp[0] + "," + samp[1] + "}");
	return -1;
}
 
Example 18
Source File: RandomDataTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private int findSample(Object[] u, Object[] samp) {
    for (int i = 0; i < u.length; i++) {
        HashSet<Object> set = (HashSet<Object>) u[i];
        HashSet<Object> sampSet = new HashSet<Object>();
        for (int j = 0; j < samp.length; j++) {
            sampSet.add(samp[j]);
        }
        if (set.equals(sampSet)) {
            return i;
        }
    }
    fail("sample not found:{" + samp[0] + "," + samp[1] + "}");
    return -1;
}
 
Example 19
Source File: RandomDataTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private int findSample(Object[] u, Object[] samp) {
    for (int i = 0; i < u.length; i++) {
        HashSet<Object> set = (HashSet<Object>) u[i];
        HashSet<Object> sampSet = new HashSet<Object>();
        for (int j = 0; j < samp.length; j++) {
            sampSet.add(samp[j]);
        }
        if (set.equals(sampSet)) {
            return i;
        }
    }
    fail("sample not found:{" + samp[0] + "," + samp[1] + "}");
    return -1;
}
 
Example 20
Source File: Ideas_2011_07_03.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
@NoWarning("EC_UNRELATED_TYPES")
public boolean test(HashSet<Integer> s1, TreeSet<Integer> s2) {
    return s1.equals(s2);
}