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

The following examples show how to use java.util.TreeSet#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: TestMorfologikAnalyzer.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private void assertPOSToken(TokenStream ts, String term, String... tags) throws IOException {
  ts.incrementToken();
  assertEquals(term, ts.getAttribute(CharTermAttribute.class).toString());
  
  TreeSet<String> actual = new TreeSet<>();
  TreeSet<String> expected = new TreeSet<>();
  for (StringBuilder b : ts.getAttribute(MorphosyntacticTagsAttribute.class).getTags()) {
    actual.add(b.toString());
  }
  for (String s : tags) {
    expected.add(s);
  }
  
  if (!expected.equals(actual)) {
    System.out.println("Expected:\n" + expected);
    System.out.println("Actual:\n" + actual);
    assertEquals(expected, actual);
  }
}
 
Example 2
Source File: IncompatibleEqualsNegativeCases.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
@NoWarning("EC")
public boolean testCollection(Collection<String> c, HashSet<String> s, TreeSet<String> s2, Set<String> s3,  Object o) {
    if (c.equals(s))
        return true;
    if (s.equals(c))
        return true;
    if (o.equals(c))
        return true;
    if (s.equals(s2))
        return true;
    if (s2.equals(s3))
        return true;

    return false;
}
 
Example 3
Source File: CuboidCLI.java    From Kylin with Apache License 2.0 5 votes vote down vote up
public static int simulateCuboidGeneration(CubeDesc cube) {
    CuboidScheduler scheduler = new CuboidScheduler(cube);

    long baseCuboid = Cuboid.getBaseCuboidId(cube);
    Collection<Long> cuboidSet = new TreeSet<Long>();
    cuboidSet.add(baseCuboid);
    LinkedList<Long> cuboidQueue = new LinkedList<Long>();
    cuboidQueue.push(baseCuboid);
    while (!cuboidQueue.isEmpty()) {
        long cuboid = cuboidQueue.pop();
        Collection<Long> spnanningCuboids = scheduler.getSpanningCuboid(cuboid);
        for (Long sc : spnanningCuboids) {
            boolean notfound = cuboidSet.add(sc);
            if (!notfound) {
                throw new IllegalStateException("Find duplicate spanning cuboid " + sc + " from cuboid " + cuboid);
            }
            cuboidQueue.push(sc);
        }
    }

    TreeSet<Long> enumCuboids = enumCalcCuboidCount(cube);
    if (enumCuboids.equals(cuboidSet) == false) {
        throw new IllegalStateException("Expected cuboid set " + enumCuboids + "; but actual cuboid set " + cuboidSet);
    }

    int mathCount = mathCalcCuboidCount(cube);
    if (mathCount != enumCuboids.size()) {
        throw new IllegalStateException("Math cuboid count " + mathCount + ", but actual cuboid count " + enumCuboids.size());
    }

    return mathCount;

}
 
Example 4
Source File: Sample.java    From pattern-matching with Apache License 2.0 5 votes vote down vote up
@Override
public boolean equals(Object obj) {
	if (this == obj)
		return true;
	if (obj == null)
		return false;
	if (getClass() != obj.getClass())
		return false;
	Sample otherSample = (Sample) obj;
	if (modelNodeToDataNode == null && otherSample.modelNodeToDataNode == null)
		return true;

	TreeSet<String> dn1 = this.getIDs();
	double mismatch1 = this.getMismatch();
	TreeSet<String> rel1 = this.getRelationships();

	TreeSet<String> dn2 = otherSample.getIDs();
	double mismatch2 = otherSample.getMismatch();
	TreeSet<String> rel2 = otherSample.getRelationships();

	// System.out.println(mismatch1);
	// System.out.println(mismatch1);
	// printSet(dn1);
	// printSet(dn2);
	// printSet(rel1);
	// printSet(rel2);

	if (mismatch1 == mismatch2 && dn1.equals(dn2) && rel1.equals(rel2)) {
		// System.out.println("equal");
		return true;
	}
	// System.out.println("not equal");
	return false;
}
 
Example 5
Source File: CuboidCLI.java    From kylin-on-parquet-v2 with Apache License 2.0 4 votes vote down vote up
public static int simulateCuboidGeneration(CubeDesc cubeDesc, boolean validate) {
    CuboidScheduler scheduler = cubeDesc.getInitialCuboidScheduler();
    long baseCuboid = Cuboid.getBaseCuboidId(cubeDesc);
    Collection<Long> cuboidSet = new TreeSet<Long>();
    cuboidSet.add(baseCuboid);
    LinkedList<Long> cuboidQueue = new LinkedList<Long>();
    cuboidQueue.push(baseCuboid);
    while (!cuboidQueue.isEmpty()) {
        long cuboid = cuboidQueue.pop();
        Collection<Long> spnanningCuboids = scheduler.getSpanningCuboid(cuboid);
        for (Long sc : spnanningCuboids) {
            boolean notfound = cuboidSet.add(sc);
            if (!notfound) {
                throw new IllegalStateException("Find duplicate spanning cuboid " + sc + " from cuboid " + cuboid);
            }

            cuboidQueue.push(sc);

        }
    }

    boolean enableDimCap = false;
    for (AggregationGroup agg : cubeDesc.getAggregationGroups()) {
        if (agg.getDimCap() > 0) {
            enableDimCap = true;
            break;
        }
    }

    if (validate) {
        if (enableDimCap) {
            if (cubeDesc.getAllCuboids().size() != cuboidSet.size()) {
                throw new IllegalStateException("Expected cuboid set " + cubeDesc.getAllCuboids() + "; but actual cuboid set " + cuboidSet);
            }
        } else {
            //only run this for test purpose, performance is bad when # of dims is large
            TreeSet<Long> enumCuboids = enumCalcCuboidCount(cubeDesc);
            System.out.println(Arrays.toString(enumCuboids.toArray(new Long[enumCuboids.size()])));
            if (enumCuboids.equals(cuboidSet) == false) {
                throw new IllegalStateException("Expected cuboid set " + enumCuboids + "; but actual cuboid set " + cuboidSet);
            }

            //check all valid and invalid
            for (long i = 0; i < baseCuboid; ++i) {
                if (cuboidSet.contains(i)) {
                    if (!scheduler.isValid(i)) {
                        throw new RuntimeException();
                    }

                    if (scheduler.findBestMatchCuboid(i) != i) {
                        throw new RuntimeException();
                    }
                } else {
                    if (scheduler.isValid(i)) {
                        throw new RuntimeException();
                    }

                    long corrected = scheduler.findBestMatchCuboid(i);
                    if (corrected == i) {
                        throw new RuntimeException();
                    }

                    if (!scheduler.isValid(corrected)) {
                        throw new RuntimeException();
                    }

                    if (scheduler.findBestMatchCuboid(corrected) != corrected) {
                        throw new RuntimeException();
                    }
                }
            }
        }
    }

    return cuboidSet.size();

}
 
Example 6
Source File: CuboidCLI.java    From kylin with Apache License 2.0 4 votes vote down vote up
public static int simulateCuboidGeneration(CubeDesc cubeDesc, boolean validate) {
    CuboidScheduler scheduler = cubeDesc.getInitialCuboidScheduler();
    long baseCuboid = Cuboid.getBaseCuboidId(cubeDesc);
    Collection<Long> cuboidSet = new TreeSet<Long>();
    cuboidSet.add(baseCuboid);
    LinkedList<Long> cuboidQueue = new LinkedList<Long>();
    cuboidQueue.push(baseCuboid);
    while (!cuboidQueue.isEmpty()) {
        long cuboid = cuboidQueue.pop();
        Collection<Long> spnanningCuboids = scheduler.getSpanningCuboid(cuboid);
        for (Long sc : spnanningCuboids) {
            boolean notfound = cuboidSet.add(sc);
            if (!notfound) {
                throw new IllegalStateException("Find duplicate spanning cuboid " + sc + " from cuboid " + cuboid);
            }

            cuboidQueue.push(sc);

        }
    }

    boolean enableDimCap = false;
    for (AggregationGroup agg : cubeDesc.getAggregationGroups()) {
        if (agg.getDimCap() > 0) {
            enableDimCap = true;
            break;
        }
    }

    if (validate) {
        if (enableDimCap) {
            if (cubeDesc.getAllCuboids().size() != cuboidSet.size()) {
                throw new IllegalStateException("Expected cuboid set " + cubeDesc.getAllCuboids() + "; but actual cuboid set " + cuboidSet);
            }
        } else {
            //only run this for test purpose, performance is bad when # of dims is large
            TreeSet<Long> enumCuboids = enumCalcCuboidCount(cubeDesc);
            System.out.println(Arrays.toString(enumCuboids.toArray(new Long[enumCuboids.size()])));
            if (enumCuboids.equals(cuboidSet) == false) {
                throw new IllegalStateException("Expected cuboid set " + enumCuboids + "; but actual cuboid set " + cuboidSet);
            }

            //check all valid and invalid
            for (long i = 0; i < baseCuboid; ++i) {
                if (cuboidSet.contains(i)) {
                    if (!scheduler.isValid(i)) {
                        throw new RuntimeException();
                    }

                    if (scheduler.findBestMatchCuboid(i) != i) {
                        throw new RuntimeException();
                    }
                } else {
                    if (scheduler.isValid(i)) {
                        throw new RuntimeException();
                    }

                    long corrected = scheduler.findBestMatchCuboid(i);
                    if (corrected == i) {
                        throw new RuntimeException();
                    }

                    if (!scheduler.isValid(corrected)) {
                        throw new RuntimeException();
                    }

                    if (scheduler.findBestMatchCuboid(corrected) != corrected) {
                        throw new RuntimeException();
                    }
                }
            }
        }
    }

    return cuboidSet.size();

}