List of usage examples for java.util Set equals
boolean equals(Object o);
From source file:com.googlecode.fightinglayoutbugs.helpers.TestHelper.java
/** * Handles {@code null}, numbers, collections, and arrays. *//*from w w w . j av a 2 s . c om*/ public static Matcher<Object> is(final Object expected, final Object... moreExpectedValues) { return new BaseMatcher<Object>() { @Override public boolean matches(Object o) { boolean matches; if (o == null) { matches = (moreExpectedValues.length == 0 && expected == null); } else if (o instanceof Number) { if (moreExpectedValues.length > 0) { matches = false; } else { if (expected instanceof Number) { if (expected instanceof Long && o instanceof Integer) { matches = (((Long) expected) == ((Integer) o).longValue()); } else if (expected instanceof Integer && o instanceof Long) { matches = (((Integer) expected).longValue() == ((Long) o)); } else { matches = o.equals(expected); } } else { matches = false; } } } else if (o instanceof Collection) { if (moreExpectedValues.length > 0) { if (o instanceof Set) { Set<?> expectedSet = Sets.union(TestHelper.asSet(expected), TestHelper.asSet(moreExpectedValues)); matches = expectedSet.equals(o); } else if (o instanceof List) { List<?> expectedList = Lists.asList(expected, moreExpectedValues); matches = expectedList.equals(o); } else { throw new RuntimeException( "Don't know how to match a " + o.getClass().getName() + " instance."); } } else if (expected == null) { throw new RuntimeException( "Ambigious matcher: Use either isNull() or isEqualTo(Collections.singleton(null))"); } else if (expected instanceof Collection) { matches = expected.equals(o); } else { matches = (((Collection) o).size() == 1 && expected.equals(((Collection) o).iterator().next())); } } else if (o.getClass().isArray()) { final Object expectedArray; if (moreExpectedValues.length > 0) { final Object[] a = new Object[moreExpectedValues.length + 1]; a[0] = expected; System.arraycopy(moreExpectedValues, 0, a, 1, moreExpectedValues.length); expectedArray = a; } else if (expected != null && !expected.getClass().isArray()) { expectedArray = new Object[] { expected }; } else { expectedArray = expected; } matches = new IsEqual<Object>(expectedArray).matches(o); } else { matches = (moreExpectedValues.length == 0 && o.equals(expected)); } return matches; } @Override public void describeTo(Description description) { if (moreExpectedValues.length == 0) { if (expected instanceof SelfDescribing) { ((SelfDescribing) expected).describeTo(description); } else { description.appendText(StringHelper.asString(expected)); } } else { final List<Object> temp = new ArrayList<Object>(moreExpectedValues.length + 1); temp.add(expected); temp.addAll(Arrays.asList(moreExpectedValues)); description.appendText(Joiner.on(", ").join(temp)); } } }; }
From source file:org.jahia.test.TestHelper.java
public static JahiaSite createSite(String name, Set<String> languages, Set<String> mandatoryLanguages, boolean mixLanguagesActive) throws Exception { createSite(name, "localhost" + System.currentTimeMillis(), WEB_TEMPLATES, null, null, null); final JCRSessionWrapper session = JCRSessionFactory.getInstance().getCurrentUserSession(); JCRSiteNode site = (JCRSiteNode) session.getNode("/sites/" + name); if (!CollectionUtils.isEmpty(languages) && !languages.equals(site.getLanguages())) { site.setLanguages(languages);/*from ww w. j a v a 2 s .c o m*/ } if (!CollectionUtils.isEmpty(mandatoryLanguages) && !mandatoryLanguages.equals(site.getMandatoryLanguages())) { site.setMandatoryLanguages(mandatoryLanguages); } if (mixLanguagesActive != site.isMixLanguagesActive()) { site.setMixLanguagesActive(mixLanguagesActive); } session.save(); return site; }
From source file:voldemort.utils.RebalanceUtils.java
/** * Confirms that both clusters have the same set of zones defined. * //from w ww.j a v a 2s. c o m * @param lhs * @param rhs */ public static void validateClusterZonesSame(final Cluster lhs, final Cluster rhs) { Set<Zone> lhsSet = new HashSet<Zone>(lhs.getZones()); Set<Zone> rhsSet = new HashSet<Zone>(rhs.getZones()); if (!lhsSet.equals(rhsSet)) throw new VoldemortException("Zones are not the same [ lhs cluster zones (" + lhs.getZones() + ") not equal to rhs cluster zones (" + rhs.getZones() + ") ]"); }
From source file:org.jahia.test.utils.TestHelper.java
public static JahiaSite createSite(String name, Set<String> languages, Set<String> mandatoryLanguages, boolean mixLanguagesActive) throws Exception { createSite(name, "localhost" + System.currentTimeMillis(), getDefaultTemplateSet(), null, null, null); final JCRSessionWrapper session = JCRSessionFactory.getInstance().getCurrentUserSession(); JCRSiteNode site = (JCRSiteNode) session.getNode("/sites/" + name); if (!CollectionUtils.isEmpty(languages) && !languages.equals(site.getLanguages())) { site.setLanguages(languages);/*from w ww .j a v a2 s. com*/ } if (!CollectionUtils.isEmpty(mandatoryLanguages) && !mandatoryLanguages.equals(site.getMandatoryLanguages())) { site.setMandatoryLanguages(mandatoryLanguages); } if (mixLanguagesActive != site.isMixLanguagesActive()) { site.setMixLanguagesActive(mixLanguagesActive); } session.save(); return site; }
From source file:org.beangle.commons.lang.StrUtils.java
/** * ","?????./*w w w . j av a 2 s . c o m*/ * * @param first * @param second * @return */ public static boolean isEqualSeq(final String first, final String second, final String delimiter) { if (StringUtils.isNotEmpty(first) && StringUtils.isNotEmpty(second)) { String[] firstWords = StringUtils.split(first, delimiter); Set<String> firstSet = CollectUtils.newHashSet(); for (int i = 0; i < firstWords.length; i++) { firstSet.add(firstWords[i]); } String[] secondWords = StringUtils.split(second, delimiter); Set<String> secondSet = CollectUtils.newHashSet(); for (int i = 0; i < secondWords.length; i++) { secondSet.add(secondWords[i]); } return firstSet.equals(secondSet); } else { return StringUtils.isEmpty(first) & StringUtils.isEmpty(second); } }
From source file:com.cloudera.whirr.cm.CmServerClusterInstance.java
public static synchronized Set<Integer> portsPush(ClusterActionEvent event, Set<String> ports) { Set<Integer> portsNew = new HashSet<Integer>(); if (CmServerClusterInstance.ports.get(event) == null) { CmServerClusterInstance.ports.put(event, new HashSet<Integer>()); }/*from w w w.j a v a 2 s . co m*/ for (String port : ports) { if (ports != null && !ports.equals("")) { try { Integer portInteger = Integer.parseInt(port); if (!CmServerClusterInstance.ports.get(event).contains(portInteger)) { portsNew.add(portInteger); CmServerClusterInstance.ports.get(event).add(portInteger); } } catch (NumberFormatException e) { // ignore } } } return portsNew; }
From source file:org.deri.iris.queryrewriting.RewritingUtils.java
private static Set<Set<Set<ILiteral>>> mergeDecompositions( final Set<Set<Set<ILiteral>>> currentLevelDecompositions) { final Set<Set<Set<ILiteral>>> next = new LinkedHashSet<Set<Set<ILiteral>>>(); for (final Set<Set<ILiteral>> decomposition : currentLevelDecompositions) { // merge the components of the decomposition to create one set of literal less than the current // decomposition for (final Set<ILiteral> comp1 : decomposition) { for (final Set<ILiteral> comp2 : decomposition) { if (!comp1.equals(comp2)) { final Set<Set<ILiteral>> mergedDecomposition = new LinkedHashSet<Set<ILiteral>>(); mergedDecomposition.addAll(decomposition); final Set<ILiteral> mergedComponent = Sets.newLinkedHashSet(comp1); mergedComponent.addAll(comp2); mergedDecomposition.add(mergedComponent); mergedDecomposition.remove(comp1); mergedDecomposition.remove(comp2); next.add(mergedDecomposition); }/*from www. ja v a 2 s . c o m*/ } } } return next; }
From source file:org.onehippo.repository.documentworkflow.DocumentWorkflowTest.java
protected static void assertMatchingSCXMLStates(SCXMLWorkflowExecutor executor, TreeSet<String> states) { Set<String> stateIds = getSCXMLStatusStateIds(executor); if (!stateIds.equals(states)) { Assert.fail("Current SCXML states not matching expected states.\n" + "States : " + stateIds + "\n" + "expected: " + states); }//ww w .j ava2 s. c o m }
From source file:org.deri.iris.queryrewriting.RewritingUtils.java
private static boolean validDecomposition(final Set<IRule> components, final Set<PositionJoin> exJoins, final List<IRule> tgds, final Map<IPosition, Set<IRule>> exPos) { final Set<PositionJoin> compExJoins = new LinkedHashSet<PositionJoin>(); for (final IRule c : components) { compExJoins.addAll(DepGraphUtils.computeExistentialJoins(c, tgds, exPos)); }/*from w w w . ja va 2 s. c om*/ return compExJoins.equals(exJoins); }
From source file:edu.uci.ics.asterix.test.aql.TestsUtils.java
private static boolean equalStrings(String s1, String s2) { String[] rowsOne = s1.split("\n"); String[] rowsTwo = s2.split("\n"); for (int i = 0; i < rowsOne.length; i++) { String row1 = rowsOne[i]; String row2 = rowsTwo[i]; if (row1.equals(row2)) continue; String[] fields1 = row1.split(" "); String[] fields2 = row2.split(" "); boolean bagEncountered = false; Set<String> bagElements1 = new HashSet<String>(); Set<String> bagElements2 = new HashSet<String>(); for (int j = 0; j < fields1.length; j++) { if (j >= fields2.length) { return false; } else if (fields1[j].equals(fields2[j])) { if (fields1[j].equals("{{")) bagEncountered = true; if (fields1[j].startsWith("}}")) { if (!bagElements1.equals(bagElements2)) return false; bagEncountered = false; bagElements1.clear(); bagElements2.clear(); }// w w w . jav a 2 s. c o m continue; } else if (fields1[j].indexOf('.') < 0) { if (bagEncountered) { bagElements1.add(fields1[j].replaceAll(",$", "")); bagElements2.add(fields2[j].replaceAll(",$", "")); continue; } return false; } else { // If the fields are floating-point numbers, test them // for equality safely fields1[j] = fields1[j].split(",")[0]; fields2[j] = fields2[j].split(",")[0]; try { Double double1 = Double.parseDouble(fields1[j]); Double double2 = Double.parseDouble(fields2[j]); float float1 = (float) double1.doubleValue(); float float2 = (float) double2.doubleValue(); if (Math.abs(float1 - float2) == 0) continue; else { return false; } } catch (NumberFormatException ignored) { // Guess they weren't numbers - must simply not be equal return false; } } } } return true; }