java.util.HashSet#equals ( )源码实例Demo

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

源代码1 项目: nutch-htmlunit   文件: MapWritable.java
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;
}
 
源代码2 项目: gemfirexd-oss   文件: ProjectRestrictNode.java
/**
 * 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);
}
 
源代码3 项目: jdk8u-jdk   文件: DistinctEntrySetElements.java
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.");
    }
}
 
源代码4 项目: 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.");
    }
}
 
源代码5 项目: TencentKona-8   文件: DistinctEntrySetElements.java
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.");
    }
}
 
源代码6 项目: anthelion   文件: MapWritable.java
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;
}
 
源代码7 项目: hottub   文件: DistinctEntrySetElements.java
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.");
    }
}
 
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 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.");
    }
}
 
源代码10 项目: jdk8u-jdk   文件: DistinctEntrySetElements.java
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.");
    }
}
 
源代码11 项目: 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.");
    }
}
 
源代码12 项目: jdk8u-jdk   文件: DistinctEntrySetElements.java
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.");
    }
}
 
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.");
    }
}
 
源代码14 项目: openjdk-jdk9   文件: DistinctEntrySetElements.java
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.");
    }
}
 
源代码15 项目: astor   文件: RandomDataTest.java
@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;
}
 
源代码16 项目: astor   文件: RandomDataTest.java
@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;
}
 
源代码17 项目: TencentKona-8   文件: Serialization.java
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!");
    }
}
 
源代码18 项目: astor   文件: RandomDataTest.java
@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;
}
 
源代码19 项目: astor   文件: RandomDataTest.java
@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;
}
 
源代码20 项目: spotbugs   文件: Ideas_2011_07_03.java
@NoWarning("EC_UNRELATED_TYPES")
public boolean test(HashSet<Integer> s1, TreeSet<Integer> s2) {
    return s1.equals(s2);
}