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:io.druid.segment.IndexIO.java

public void validateTwoSegments(final IndexableAdapter adapter1, final IndexableAdapter adapter2) {
    if (adapter1.getNumRows() != adapter2.getNumRows()) {
        throw new SegmentValidationException("Row count mismatch. Expected [%d] found [%d]",
                adapter1.getNumRows(), adapter2.getNumRows());
    }//from w  w w . j  a  va 2s. c om
    {
        final Set<String> dimNames1 = Sets.newHashSet(adapter1.getDimensionNames());
        final Set<String> dimNames2 = Sets.newHashSet(adapter2.getDimensionNames());
        if (!dimNames1.equals(dimNames2)) {
            throw new SegmentValidationException("Dimension names differ. Expected [%s] found [%s]", dimNames1,
                    dimNames2);
        }
        final Set<String> metNames1 = Sets.newHashSet(adapter1.getMetricNames());
        final Set<String> metNames2 = Sets.newHashSet(adapter2.getMetricNames());
        if (!metNames1.equals(metNames2)) {
            throw new SegmentValidationException("Metric names differ. Expected [%s] found [%s]", metNames1,
                    metNames2);
        }
    }
    final Map<String, DimensionHandler> dimHandlers = adapter1.getDimensionHandlers();

    final Iterator<Rowboat> it1 = adapter1.getRows().iterator();
    final Iterator<Rowboat> it2 = adapter2.getRows().iterator();
    long row = 0L;
    while (it1.hasNext()) {
        if (!it2.hasNext()) {
            throw new SegmentValidationException("Unexpected end of second adapter");
        }
        final Rowboat rb1 = it1.next();
        final Rowboat rb2 = it2.next();
        ++row;
        if (rb1.getRowNum() != rb2.getRowNum()) {
            throw new SegmentValidationException("Row number mismatch: [%d] vs [%d]", rb1.getRowNum(),
                    rb2.getRowNum());
        }
        if (rb1.compareTo(rb2) != 0) {
            try {
                validateRowValues(dimHandlers, rb1, adapter1, rb2, adapter2);
            } catch (SegmentValidationException ex) {
                throw new SegmentValidationException(ex, "Validation failure on row %d: [%s] vs [%s]", row, rb1,
                        rb2);
            }
        }
    }
    if (it2.hasNext()) {
        throw new SegmentValidationException("Unexpected end of first adapter");
    }
    if (row != adapter1.getNumRows()) {
        throw new SegmentValidationException("Actual Row count mismatch. Expected [%d] found [%d]", row,
                adapter1.getNumRows());
    }
}

From source file:org.osaf.cosmo.migrate.ZeroPointSixOneToZeroPointSevenMigration.java

/**
 * Fix modification items that are out of sync with the parent item.
 *///from   ww  w  .  j  a  va2 s. c o m
private void migrateModifications(Connection conn) throws Exception {

    PreparedStatement stmt = null;
    PreparedStatement updateItemStmt = null;
    PreparedStatement insertCollectionItemStmt = null;
    PreparedStatement parentsStmt = null;

    ResultSet rs = null;

    long count = 0;

    log.debug("starting migrateModifications()");

    try {
        // get all stamp/item data to migrate
        stmt = conn.prepareStatement("select id, modifiesitemid from item where modifiesitemid is not null");
        // update timestamp
        updateItemStmt = conn.prepareStatement("update item set modifydate=?, version=version+1 where id=?");
        insertCollectionItemStmt = conn
                .prepareStatement("insert into collection_item(collectionid, itemid) values (?,?)");
        parentsStmt = conn.prepareStatement("select collectionid from collection_item where itemid=?");

        rs = stmt.executeQuery();

        HashMap<Long, Set<Long>> parentMap = new HashMap<Long, Set<Long>>();

        // examine each modification and fix if necessary
        while (rs.next()) {
            long itemId = rs.getLong(1);
            long modifiesItemId = rs.getLong(2);

            Set<Long> modParents = getParents(parentsStmt, itemId);
            Set<Long> masterParents = parentMap.get(modifiesItemId);

            // cache the set of parents as it doesn't change
            if (masterParents == null) {
                masterParents = getParents(parentsStmt, modifiesItemId);
                parentMap.put(modifiesItemId, masterParents);
            }

            // If both sets of parents are equal, we are good
            if (modParents.equals(masterParents))
                continue;

            // otherwise add modification to each parent that
            // master is in
            for (Long parent : masterParents) {

                // Only care about collections that item is not in
                if (modParents.contains(parent))
                    continue;

                // insert into parent
                insertCollectionItemStmt.setLong(1, parent);
                insertCollectionItemStmt.setLong(2, itemId);
                if (insertCollectionItemStmt.executeUpdate() != 1)
                    throw new RuntimeException("insert into collection_item failed");

                // update parent and item version/timestamps
                updateItemStmt.setLong(1, System.currentTimeMillis());
                updateItemStmt.setLong(2, itemId);
                if (updateItemStmt.executeUpdate() != 1)
                    throw new RuntimeException("update of item failed");

                updateItemStmt.setLong(1, System.currentTimeMillis());
                updateItemStmt.setLong(2, parent);
                if (updateItemStmt.executeUpdate() != 1)
                    throw new RuntimeException("update of item failed");
            }

            count++;
        }

    } finally {
        close(stmt);
        close(updateItemStmt);
        close(insertCollectionItemStmt);
        close(parentsStmt);
        close(rs);
    }

    log.debug("processed " + count + " out of sync item modifications");
}

From source file:org.mifosplatform.portfolio.loanproduct.domain.LoanProduct.java

public boolean update(final List<Charge> newProductCharges) {
    if (newProductCharges == null) {
        return false;
    }/*from w ww .j ava  2s  . c o  m*/

    boolean updated = false;
    if (this.charges != null) {
        final Set<Charge> currentSetOfCharges = new HashSet<Charge>(this.charges);
        final Set<Charge> newSetOfCharges = new HashSet<Charge>(newProductCharges);

        if (!currentSetOfCharges.equals(newSetOfCharges)) {
            updated = true;
            this.charges = newProductCharges;
        }
    } else {
        updated = true;
        this.charges = newProductCharges;
    }
    return updated;
}

From source file:de.upb.wdqa.wdvd.ItemDiff.java

public boolean hasPropertyChanged(String property) {
    Set<String> old_statement_ids = new HashSet<String>();
    Set<String> new_statement_ids = new HashSet<String>();

    Iterator<Statement> oldStatements = oldItem.getAllStatements();
    while (oldStatements.hasNext()) {
        Statement statement = oldStatements.next();
        if (property.equals(statement.getClaim().getMainSnak().getPropertyId().getId())) {
            old_statement_ids.add(statement.getStatementId());
        }//from  w  w w .j a v  a2  s .  c  om
    }

    Iterator<Statement> newStatements = newItem.getAllStatements();
    while (newStatements.hasNext()) {
        Statement statement = newStatements.next();
        if (property.equals(statement.getClaim().getMainSnak().getPropertyId().getId())) {
            new_statement_ids.add(statement.getStatementId());
        }
    }

    boolean result = !old_statement_ids.equals(new_statement_ids);

    return result;
}

From source file:ddf.catalog.impl.operations.UpdateOperations.java

private boolean foundAllUpdateRequestMetacards(UpdateRequest updateRequest, QueryResponse response) {
    Set<String> originalKeys = updateRequest.getUpdates().stream().map(Map.Entry::getKey).map(Object::toString)
            .collect(Collectors.toSet());
    Set<String> responseKeys = response.getResults().stream().map(Result::getMetacard)
            .map(m -> m.getAttribute(updateRequest.getAttributeName())).filter(Objects::nonNull)
            .map(Attribute::getValue).filter(Objects::nonNull).map(Object::toString)
            .collect(Collectors.toSet());
    return originalKeys.equals(responseKeys);
}

From source file:edu.uci.ics.pregelix.example.util.TestExecutor.java

private 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 ww.jav a2  s  .co 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;
}

From source file:org.mifosplatform.portfolio.loanproduct.domain.LoanProduct.java

public boolean updateFeeMasterData(final Collection<FeeMaster> newProductFeeMasterData) {
    if (newProductFeeMasterData == null) {
        return false;
    }/*from ww w .ja  va 2 s  .co  m*/

    boolean updated = false;
    if (this.feeMasterData != null) {
        final Set<FeeMaster> currentSetOfFeeMasterData = new HashSet<FeeMaster>(this.feeMasterData);
        final Set<FeeMaster> newSetOfFeeMasterData = new HashSet<FeeMaster>(newProductFeeMasterData);

        if (!currentSetOfFeeMasterData.equals(newSetOfFeeMasterData)) {
            updated = true;
            this.feeMasterData = newProductFeeMasterData;
        }
    } else {
        updated = true;
        this.feeMasterData = newProductFeeMasterData;
    }
    return updated;
}

From source file:org.jahia.utils.maven.plugin.osgi.BuildFrameworkPackageListMojo.java

private void resolveSplitPackages(Map<String, Map<String, Map<String, VersionLocation>>> packageVersionCounts,
        Map<String, Set<String>> packageVersions) {
    for (Map.Entry<String, Map<String, Map<String, VersionLocation>>> resolvedPackageVersion : packageVersionCounts
            .entrySet()) {/* w w w  . ja  va2 s. c om*/
        boolean allVersionsEqual = true;
        Set<String> previousVersions = null;
        for (Map.Entry<String, Map<String, VersionLocation>> versionLocationEntry : resolvedPackageVersion
                .getValue().entrySet()) {
            if (previousVersions != null
                    && !previousVersions.equals(versionLocationEntry.getValue().keySet())) {
                allVersionsEqual = false;
                break;
            }
            previousVersions = versionLocationEntry.getValue().keySet();
        }
        if (resolvedPackageVersion.getValue().size() > 1 && !allVersionsEqual) {
            getLog().warn("Split-package with different versions detected for package "
                    + resolvedPackageVersion.getKey() + ":");
        }
        Set<String> versions = new HashSet<String>();
        for (Map.Entry<String, Map<String, VersionLocation>> versionLocationEntry : resolvedPackageVersion
                .getValue().entrySet()) {
            if (resolvedPackageVersion.getValue().size() > 1 && !allVersionsEqual) {
                for (Map.Entry<String, VersionLocation> versionLocationsEntry : versionLocationEntry.getValue()
                        .entrySet()) {
                    getLog().warn("  - " + versionLocationEntry.getKey() + " v"
                            + versionLocationsEntry.getValue().getVersion() + " count="
                            + versionLocationsEntry.getValue().getCounter() + " Specification-Version="
                            + versionLocationsEntry.getValue().getSpecificationVersion());
                }
            }
            if (versionLocationEntry.getValue() == null) {
                continue;
            }
            for (String version : versionLocationEntry.getValue().keySet()) {
                if (!versions.contains(version)) {
                    versions.add(version);
                }
            }
        }
        packageVersions.put(resolvedPackageVersion.getKey(), versions);
    }
}

From source file:org.apache.storm.daemon.nimbus.NimbusUtils.java

private static List<String> mkMissingAssignmentTopologies(Topologies topologies,
        Map<String, Set<ExecutorInfo>> topologyToExecutors,
        Map<String, Set<ExecutorInfo>> topologyToAliveExecutors,
        Map<String, SchedulerAssignmentImpl> topologyToSchedulerAssignment) {

    Collection<TopologyDetails> topologyDetails = topologies.getTopologies();

    List<String> missingAssignmentTopologies = new ArrayList<String>();
    for (TopologyDetails topologyDetailsItem : topologyDetails) {
        String tid = topologyDetailsItem.getId();
        Set<ExecutorInfo> alle = topologyToExecutors.get(tid);
        Set<ExecutorInfo> alivee = topologyToAliveExecutors.get(tid);
        SchedulerAssignment assignment = topologyToSchedulerAssignment.get(tid);
        int numUsedWorkers = numUsedWorkers(assignment);
        int numWorkers = topologies.getById(tid).getNumWorkers();

        if (alle == null || alle.isEmpty() || !alle.equals(alivee) || numUsedWorkers < numWorkers) {
            missingAssignmentTopologies.add(tid);
        }/*  ww w .  j a v  a2s .  co m*/
    }
    return missingAssignmentTopologies;
}

From source file:com.doculibre.constellio.services.SkosServicesImpl.java

/**
 * Copies content modifications from modified thesaurus into initial thesaurus.
 * /*from ww w. j  ava  2s  . c  om*/
 * @see com.doculibre.constellio.services.SkosServices#merge(com.doculibre.constellio.entities.skos.Thesaurus,
 *      com.doculibre.constellio.entities.skos.Thesaurus)
 */
@Override
public Set<SkosConcept> merge(Thesaurus initialThesaurus, Thesaurus modifiedThesaurus) {
    Set<SkosConcept> deletedConcepts = new HashSet<SkosConcept>();
    Map<String, SkosConcept> initialConcepts = initialThesaurus.getFlattenedConcepts();
    Map<String, SkosConcept> modifiedConcepts = modifiedThesaurus.getFlattenedConcepts();

    initialThesaurus.setDcTitle(modifiedThesaurus.getDcTitle());
    initialThesaurus.setDcDescription(modifiedThesaurus.getDcDescription());
    initialThesaurus.setDcDate(modifiedThesaurus.getDcDate());
    initialThesaurus.setDcCreator(modifiedThesaurus.getDcCreator());

    // Manage deleted and modified concepts
    for (SkosConcept initialConcept : initialConcepts.values()) {
        String rdfAbout = initialConcept.getRdfAbout();
        if (!modifiedConcepts.containsKey(rdfAbout)) {
            deletedConcepts.add(initialConcept);
        } else {
            SkosConcept modifiedConcept = modifiedConcepts.get(rdfAbout);
            initialConcept.setSkosNotes(modifiedConcept.getSkosNotes());

            // Broader before modifications
            Set<SkosConcept> previousBroader = initialConcept.getBroader();
            // Broader as found in the modified file
            Set<SkosConcept> modifiedBroader = modifiedConcept.getBroader();

            // Undo previous relationship
            if (!previousBroader.isEmpty() && !previousBroader.equals(modifiedBroader)) {
                initialConcept.getBroader().clear();
                for (SkosConcept previousBroaderConcept : previousBroader) {
                    previousBroaderConcept.getNarrower().remove(initialConcept);
                }
            }

            // This concept still has a broader concept
            if (!modifiedBroader.isEmpty()) {
                for (SkosConcept modifiedBroaderConcept : modifiedBroader) {
                    // Did the modified broader exist initially?
                    SkosConcept existingBroader = initialConcepts.get(modifiedBroaderConcept.getRdfAbout());
                    if (existingBroader != null) {
                        // Create the relationship if it didn't exist before
                        if (!existingBroader.getNarrower().contains(initialConcept)) {
                            existingBroader.addNarrower(initialConcept);
                        }
                    } else {
                        // Create the broader relationship with the new SkosConcept
                        modifiedBroaderConcept.setThesaurus(initialThesaurus);
                        modifiedBroaderConcept.addNarrower(initialConcept);
                    }
                }
            } else if (!initialThesaurus.getTopConcepts().contains(initialConcept)) {
                // It is now a top concept
                initialThesaurus.addTopConcept(initialConcept);
            }

            // Rebuild related from scratch
            initialConcept.getRelated().clear();
            for (SkosConcept related : modifiedConcept.getRelated()) {
                SkosConcept existingRelated = initialConcepts.get(related.getRdfAbout());
                if (existingRelated != null) {
                    // Add related existing skos concept
                    initialConcept.addRelated(existingRelated);
                } else {
                    // Add related new skos concept
                    related.setThesaurus(initialThesaurus);
                    initialConcept.addRelated(related);
                }
            }

            // Rebuild pref labels from scratch
            initialConcept.getPrefLabels().clear();
            initialConcept.getPrefLabels().addAll(modifiedConcept.getPrefLabels());

            // Rebuild alt labels from scratch
            initialConcept.getAltLabels().clear();
            for (SkosConceptAltLabel altLabel : modifiedConcept.getAltLabels()) {
                altLabel.setSkosConcept(initialConcept);
                initialConcept.getAltLabels().add(altLabel);
            }
        }
    }

    // Will include newly discovered concepts after processing modified and deleted concepts
    initialConcepts = initialThesaurus.getFlattenedConcepts();
    // Manage new concepts
    // First pass : Attach new concepts to the thesaurus
    for (SkosConcept modifiedConcept : modifiedConcepts.values()) {
        String rdfAbout = modifiedConcept.getRdfAbout();
        if (!initialConcepts.containsKey(rdfAbout)) {
            modifiedConcept.setThesaurus(initialThesaurus);
        }
    }

    // Will include newly discovered concepts after first pass
    initialConcepts = initialThesaurus.getFlattenedConcepts();
    // Second pass : Attach new concepts to their broader/narrower/related
    for (SkosConcept modifiedConcept : modifiedConcepts.values()) {
        // Newly added
        if (modifiedConcept.getThesaurus().equals(initialThesaurus)) {
            // Broader / narrower
            Set<SkosConcept> broader = modifiedConcept.getBroader();
            if (!broader.isEmpty()) {
                for (SkosConcept broaderConcept : broader) {
                    SkosConcept existingBroader = initialConcepts.get(broaderConcept.getRdfAbout());
                    if (!existingBroader.getNarrower().contains(modifiedConcept)) {
                        existingBroader.addNarrower(modifiedConcept);
                    }
                }
            } else if (!initialThesaurus.getTopConcepts().contains(modifiedConcept)) {
                initialThesaurus.addTopConcept(modifiedConcept);
            }

            // Related
            Set<SkosConcept> relatedModifiedThesaurus = new HashSet<SkosConcept>();
            relatedModifiedThesaurus.addAll(modifiedConcept.getRelated());
            // Rebuild from scratch
            modifiedConcept.getRelated().clear();
            for (SkosConcept related : relatedModifiedThesaurus) {
                SkosConcept existingRelated = initialConcepts.get(related.getRdfAbout());
                // Add related existing skos concept
                modifiedConcept.addRelated(existingRelated);
            }
        }
    }
    return deletedConcepts;
}