Example usage for java.util Set equals

List of usage examples for java.util Set equals

Introduction

In this page you can find the example usage for java.util Set equals.

Prototype

boolean equals(Object o);

Source Link

Document

Compares the specified object with this set for equality.

Usage

From source file:ch.systemsx.cisd.openbis.generic.server.business.importer.DatabaseInstanceImporter.java

private void checkMetaData(final SimpleDatabaseMetaData currentMetaData,
        final SimpleDatabaseMetaData metaData) {
    final String currentVersion = currentMetaData.getDatabaseVersion();
    final String importedVersion = metaData.getDatabaseVersion();
    if (currentVersion.equals(importedVersion) == false) {
        throw new UserFailureException("Version of current database is " + currentVersion
                + " which does not match the version of the database to be imported: " + importedVersion);
    }//from w ww .j  a v a 2 s .c o  m
    final Set<String> currentTables = getTableNames(currentMetaData);
    final Set<String> importedTables = getTableNames(metaData);
    if (currentTables.equals(importedTables) == false) {
        Set<String> missingTables = new HashSet<String>(currentTables);
        missingTables.removeAll(importedTables);
        if (missingTables.size() > 0) {
            throw new UserFailureException("Current database has tables " + missingTables
                    + "\n which do not exist in the database to be imported.");
        }
        Set<String> unknownTables = new HashSet<String>(importedTables);
        unknownTables.removeAll(currentTables);
        if (unknownTables.size() > 0) {
            throw new UserFailureException("Current database does not have tables " + unknownTables
                    + "\n which exist in the database to be imported.");
        }
    }
}

From source file:org.reficio.ws.server.matcher.SoapOperationMatcher.java

/**
 * Last matching mechanism ->// w  w  w. j  a va  2s. com
 * When a non ws-compliant document-literal service specifies wsdl:part using the type instead of the element tag
 * Resources:
 * http://stackoverflow.com/questions/1172118/what-is-the-difference-between-type-and-element-in-wsdl
 * http://www.xfront.com/ElementVersusType.html
 * http://www.xfront.com/GlobalVersusLocal.html !!!
 *
 * @param rootNodes root nodes of the request
 * @return operation matched
 */
@SuppressWarnings("unchecked")
private BindingOperation getOperationByInputTypes(final Set<Node> rootNodes) {
    AggregatingVisitor<BindingOperation> visitor = new AggregatingVisitor<BindingOperation>() {
        @Override
        public void visit(BindingOperation operation) {
            Collection<Part> expectedParts = operation.getOperation().getInput().getMessage().getParts()
                    .values();
            Set<QName> expectedTypes = new HashSet<QName>();
            for (Part part : expectedParts) {
                expectedTypes.add(part.getElementName());
            }
            Set<QName> receivedTypes = XmlUtils.getNodeTypes(rootNodes);
            if (expectedTypes.equals(receivedTypes)) {
                addResult(operation);
            } else if (expectedParts.isEmpty() && receivedTypes.size() == 1) {
                // check the case when pseudo input name was sent when no input was expected and got one element
                QName receivedType = receivedTypes.toArray(new QName[receivedTypes.size()])[0];
                String namespaceUri = operation.getOperation().getInput().getMessage().getQName()
                        .getNamespaceURI();
                String name = operation.getOperation().getName();
                QName pseudoInputName = new QName(namespaceUri, name);
                if (pseudoInputName.equals(receivedType)) {
                    addResult(operation);
                }
            }
        }
    };
    visitOperation(visitor);
    return visitor.getUniqueResult();
}

From source file:delfos.dataset.basic.rating.RatingsDatasetAdapter.java

@Override
public boolean equals(Object obj) {
    if (obj instanceof RatingsDataset) {
        RatingsDataset<? extends Rating> otherRatingsDataset = (RatingsDataset) obj;

        Set<Integer> thisAllUsers = new TreeSet<>(this.allUsers());
        Set<Integer> otherAllUsers = new TreeSet<>(otherRatingsDataset.allUsers());

        if (!thisAllUsers.equals(otherAllUsers)) {
            return false;
        }//w ww .  j av a 2  s . c o m

        for (int idUser : thisAllUsers) {
            try {
                Map<Integer, ? extends Rating> thisUserRatingsRated = this.getUserRatingsRated(idUser);
                Map<Integer, ? extends Rating> otherUserRatingsRated = otherRatingsDataset
                        .getUserRatingsRated(idUser);

                Set<Integer> thisDatasetItemsRated = new TreeSet<>(thisUserRatingsRated.keySet());
                Set<Integer> otherDatasetItemsRated = new TreeSet<>(otherUserRatingsRated.keySet());

                if (!thisDatasetItemsRated.equals(otherDatasetItemsRated)) {
                    return false;
                }

                for (int item : thisDatasetItemsRated) {
                    Rating thisRating = thisUserRatingsRated.get(item);
                    Rating otherRating = otherUserRatingsRated.get(item);

                    if (!thisRating.equals(otherRating)) {
                        return false;
                    }
                }

            } catch (UserNotFound ex) {
                ERROR_CODES.USER_NOT_FOUND.exit(ex);
            }
        }
        return true;
    }
    return super.equals(obj); //To change body of generated methods, choose Tools | Templates.
}

From source file:org.gradle.caching.internal.tasks.ChmodBenchmark.java

@Benchmark
public void createFileJava7SetPermissionsWhenNeeded(Blackhole blackhole) throws IOException {
    int incrementAndGet = counter.incrementAndGet();
    Path file = Files.createFile(tempDirPath.resolve("file-" + incrementAndGet));
    Set<PosixFilePermission> originalPermissions = Files.getPosixFilePermissions(file);
    Set<PosixFilePermission> permissionsToSet;
    if (incrementAndGet % 2 == 0) {
        permissionsToSet = DEFAULT_JAVA7_FILE_PERMISSIONS;
    } else {/*www . j a va 2  s.  co m*/
        permissionsToSet = WEIRD_JAVA7_FILE_PERMISSIONS;
    }
    // This should pass 50% of the time
    if (!originalPermissions.equals(permissionsToSet)) {
        Files.setPosixFilePermissions(file, permissionsToSet);
    }
    blackhole.consume(file);
}

From source file:com.mindquarry.desktop.client.widget.workspace.WorkspaceBrowserWidget.java

public boolean changesEqual(Map<File, Change> first, Map<File, Change> second, boolean remote) {
    if (first == null && second == null) {
        return true;
    }// w  w  w. j a  va  2s .c o m
    if (first == null || second == null) {
        return false;
    }
    if (first.size() != second.size()) {
        return false;
    }
    Set<File> firstKeys = first.keySet();
    Set<File> secondKeys = second.keySet();
    if (!firstKeys.equals(secondKeys)) {
        return false;
    }
    for (File file : firstKeys) {
        Status firstStatus = first.get(file).getStatus();
        Status secondStatus = second.get(file).getStatus();
        if (remote) {
            if (firstStatus.getRepositoryTextStatus() != secondStatus.getRepositoryTextStatus()) {
                return false;
            }
        } else {
            if (firstStatus.getTextStatus() != secondStatus.getTextStatus()) {
                return false;
            }
        }
    }

    return true;
}

From source file:org.openvpms.archetype.rules.product.ProductPriceUpdater.java

/**
 * Determines if the prices associated with a product should be updated.
 *
 * @param product the product/* w w w  . ja v a 2 s .c  o m*/
 * @return {@code true} if prices should be updated
 */
private boolean needsUpdate(Product product) {
    boolean update = true;
    if (!product.isNew()) {
        Product prior = (Product) service.get(product.getObjectReference());
        if (prior != null) {
            Set<EntityRelationship> oldSuppliers = getProductSuppliers(prior);
            Set<EntityRelationship> newSuppliers = getProductSuppliers(product);
            if (oldSuppliers.equals(newSuppliers)) {
                update = !checkEquals(oldSuppliers, newSuppliers);
            }
        }
    }
    return update;
}

From source file:com.todoroo.astrid.tags.TagsControlSet.java

@Override
public boolean hasChanges(Task original) {
    Set<TagData> existingSet = newHashSet(tagService.getTagDataForTask(original.getUUID()));
    Set<TagData> selectedSet = newHashSet(selectedTags);
    return !existingSet.equals(selectedSet);
}

From source file:org.dataconservancy.ui.model.builder.xstream.BopConverterTest.java

@Test
public void testUnmarshalPersonsBop() throws IOException, SAXException {
    assertEquals(2, personBop.getPersons().size());
    assertEquals(2, ((Bop) x.fromXML(x.toXML(personBop))).getPersons().size());
    Bop actual = (Bop) x.fromXML(PERSONS_XML);
    assertEquals(personBop.getPersons().size(), actual.getPersons().size());
    final Set<Person> actualPersons = actual.getPersons();
    final Set<Person> expectedPersons = personBop.getPersons();
    assertTrue(expectedPersons.equals(actualPersons));
    assertEquals(personBop, actual);//from   w  ww . ja  va2  s  .  c  o m
    Assert.assertEquals(personBop.getPersons(), ((Bop) x.fromXML(x.toXML(personBop))).getPersons());
}

From source file:org.dataconservancy.ui.model.builder.xstream.BopConverterTest.java

@Test
public void testUnmarshalDataItemsBop() throws IOException, SAXException {
    assertEquals(2, dataItemBop.getDataItems().size());
    assertEquals(2, ((Bop) x.fromXML(x.toXML(dataItemBop))).getDataItems().size());
    Bop actual = (Bop) x.fromXML(DI_BOP_XML);
    assertEquals(dataItemBop.getDataItems(), actual.getDataItems());
    final Set<DataItem> actualDIs = actual.getDataItems();
    final Set<DataItem> expectedDIs = dataItemBop.getDataItems();
    assertTrue(expectedDIs.equals(actualDIs));
    assertEquals(dataItemBop, actual);/*from w  w w.j a v a  2 s  .co m*/
    Assert.assertEquals(dataItemBop.getDataItems(), ((Bop) x.fromXML(x.toXML(dataItemBop))).getDataItems());
}

From source file:br.usp.poli.lta.cereda.nfa2dfa.utils.Conversion.java

public Triple<Integer, Set<Integer>, List<SimpleTransition>> minimize() {

    Set<Integer> Q = new HashSet<>();
    Set<Integer> A = new HashSet<>(accepting);
    Set<Integer> R = new HashSet<>();
    for (SimpleTransition transition : transitions) {
        Q.add(transition.getSource());//from ww  w  . j a  v a  2 s  .  c  om
        Q.add(transition.getTarget());
    }

    for (int q : Q) {
        if (!A.contains(q)) {
            R.add(q);
        }
    }

    Set<Set<Integer>> T = new HashSet<>();
    T.add(A);
    T.add(R);

    Set<Set<Integer>> P = new HashSet<>();

    while (!T.equals(P)) {
        P = new HashSet<>(T);
        T = new HashSet<>();
        for (Set<Integer> p : P) {
            for (Set<Integer> i : split(p, P)) {
                if (!i.isEmpty()) {
                    T.add(i);
                }
            }
        }
    }

    Map<Integer, Integer> names = new HashMap<>();
    int counter = 0;
    for (Set<Integer> t : T) {
        if (t.contains(initial)) {
            for (int i : t) {
                names.put(i, counter);
            }
        }
    }

    for (Set<Integer> t : T) {
        if (!t.contains(initial)) {
            counter++;
            for (int i : t) {
                names.put(i, counter);
            }
        }
    }

    List<SimpleTransition> converted = new ArrayList<>();

    for (SimpleTransition transition : transitions) {
        SimpleTransition t = new SimpleTransition(names.get(transition.getSource()), transition.getSymbol(),
                names.get(transition.getTarget()));
        if (!hasTransition(converted, t)) {
            converted.add(t);
        }
    }

    Triple<Integer, Set<Integer>, List<SimpleTransition>> result = new Triple<>();

    result.setFirst(names.get(initial));
    result.setThird(converted);

    HashSet<Integer> FF = new HashSet<>();
    for (int i : accepting) {
        FF.add(names.get(i));
    }

    result.setSecond(FF);

    return result;

}