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:org.syncope.client.util.AttributableOperations.java

/**
 * Calculate modifications needed by first in order to be equal to second.
 * @param updated updated RoleTO//from w ww. j ava  2  s .co  m
 * @param original original RoleTO
 * @return RoleMod containing differences
 */
public static RoleMod diff(final RoleTO updated, final RoleTO original) {
    RoleMod result = new RoleMod();

    diff(updated, original, result);

    // 1. inheritance
    result.setInheritAccountPolicy(updated.isInheritAccountPolicy());
    result.setInheritPasswordPolicy(updated.isInheritPasswordPolicy());
    result.setInheritAttributes(updated.isInheritAttributes());
    result.setInheritDerivedAttributes(updated.isInheritDerivedAttributes());
    result.setInheritVirtualAttributes(updated.isInheritVirtualAttributes());

    // 2. policies
    ReferenceMod refAccountPolicy = new ReferenceMod();
    refAccountPolicy.setId(updated.getAccountPolicy());
    result.setAccountPolicy(refAccountPolicy);

    ReferenceMod refPasswordPolicy = new ReferenceMod();
    refPasswordPolicy.setId(updated.getPasswordPolicy());
    result.setPasswordPolicy(refPasswordPolicy);

    // 3. name
    if (!original.getName().equals(updated.getName())) {
        result.setName(updated.getName());
    }

    // 4. entitlements
    Set<String> updatedEnts = new HashSet<String>(updated.getEntitlements());
    Set<String> originalEnts = new HashSet<String>(original.getEntitlements());
    if (!updatedEnts.equals(originalEnts)) {
        result.setEntitlements(updated.getEntitlements());
    }

    return result;
}

From source file:eionet.cr.util.sesame.ResultCompareUtil.java

/**
 *
 * @param result1/*w w  w  . j  av  a 2 s  . com*/
 * @param result2
 * @return
 * @throws Exception
 */
private static boolean compare(TupleQueryResult result1, TupleQueryResult result2) throws Exception {

    int numOfUnequalRows = 0;
    int i = -1;
    boolean hasNext1 = false;
    boolean hasNext2 = false;
    do {
        i++;

        if (i % 5000 == 0) {
            System.out.println("At row#" + i);
        }

        hasNext1 = result1.hasNext();
        hasNext2 = result2.hasNext();
        if (hasNext1 && hasNext2) {

            BindingSet bindingSet1 = result1.next();
            BindingSet bindingSet2 = result2.next();
            Set<String> names1 = bindingSet1.getBindingNames();
            if (i == 0) {

                Set<String> names2 = bindingSet1.getBindingNames();
                if (!names1.equals(names2)) {
                    throw new Exception("Binding sets not equal:\n" + names1 + "\n" + names2);
                }
            }

            ArrayList<String> values1 = new ArrayList<String>();
            ArrayList<String> values2 = new ArrayList<String>();
            for (String name : names1) {

                Value value1 = bindingSet1.getValue(name);
                Value value2 = bindingSet2.getValue(name);

                String str1 = value1.stringValue();
                String str2 = value2.stringValue();

                values1.add("0.0".equals(str1) ? "0" : str1);
                values2.add("0.0".equals(str2) ? "0" : str2);
            }

            if (!values1.equals(values2)) {
                numOfUnequalRows++;
                System.out.println("Row #" + i + " is different:\n1: " + values1 + "\n2: " + values2);
                return false;
            }
        }
    } while (hasNext1 && hasNext2);

    System.out.println("numOfUnequalRows = " + numOfUnequalRows);

    if (!hasNext1 && hasNext2) {
        throw new CRException("At row#" + i + " result2 has next, but result1 does not!");
    } else if (hasNext1 && !hasNext2) {
        throw new CRException("At row#" + i + " result1 has next, but result2 does not!");
    }

    return numOfUnequalRows == 0;
}

From source file:org.broadinstitute.gatk.tools.walkers.annotator.AnnotationUtils.java

protected static Set<String> validateFounderIDs(final Set<String> founderIds, final VariantContext vc) {
    Set<String> vcSamples = new HashSet<>();
    Set<String> returnIDs = founderIds;
    vcSamples.addAll(vc.getSampleNames());
    if (!vcSamples.isEmpty()) {
        if (founderIds != null) {
            vcSamples.removeAll(founderIds);
            if (vcSamples.equals(vc.getSampleNames()))
                returnIDs = vc.getSampleNames();
        }//from  w  ww  .  j a  v a 2  s.c o  m
    }
    return returnIDs;
}

From source file:edu.stanford.muse.util.JSONUtils.java

private static JSONObject jsonForAddressBook(AddressBook ab) throws JSONException {
    JSONObject result = new JSONObject();
    JSONArray entries = new JSONArray();
    List<Contact> allContacts = ab.allContacts();

    // ankita wants the first contact to always be me

    // ** CHANGED CODE BY ANKITA **

    int i = 1;/*w  w w . j  ava 2 s.c  o m*/

    //      Set<String> myAddresses = ab.getOwnAddrsSet();
    Contact me = ab.getContactForSelf();
    Set<String> myAddresses = me.emails;

    for (Contact c : allContacts) {
        if (myAddresses.equals(c.getEmails()))
            entries.put(0, c.toJson());
        else
            entries.put(i++, c.toJson());
    }
    //      entries.put(0, myAddresses);

    /*
     * OLD CODE:
    int i = 0;
    Contact me = ab.getOwnContact();
    if (me != null)
    {
       entries.put (0, me.toJson());  // ORIGINAL:   entries.put(0, me);
       i++;
    }
            
    for (Contact c: allContacts)
    {
       if (me == c)
    continue;
       entries.put(i++, c.toJson());
    }
    */

    result.put("entries", entries);
    return result;
}

From source file:org.apache.syncope.core.propagation.impl.AbstractPropagationTaskExecutor.java

public static void createOrUpdate(final ObjectClass oclass, final String accountId, final Set<Attribute> attrs,
        final String resource, final PropagationMode propagationMode, final ConnectorObject beforeObj,
        final Connector connector, final Set<String> propagationAttempted,
        final ConnObjectUtil connObjectUtil) {

    // set of attributes to be propagated
    final Set<Attribute> attributes = new HashSet<Attribute>(attrs);

    // check if there is any missing or null / empty mandatory attribute
    List<Object> mandatoryAttrNames = new ArrayList<Object>();
    Attribute mandatoryMissing = AttributeUtil.find(MANDATORY_MISSING_ATTR_NAME, attrs);
    if (mandatoryMissing != null) {
        attributes.remove(mandatoryMissing);

        if (beforeObj == null) {
            mandatoryAttrNames.addAll(mandatoryMissing.getValue());
        }//w w  w  .  j  av a 2 s. c o  m
    }
    Attribute mandatoryNullOrEmpty = AttributeUtil.find(MANDATORY_NULL_OR_EMPTY_ATTR_NAME, attrs);
    if (mandatoryNullOrEmpty != null) {
        attributes.remove(mandatoryNullOrEmpty);

        mandatoryAttrNames.addAll(mandatoryNullOrEmpty.getValue());
    }
    if (!mandatoryAttrNames.isEmpty()) {
        throw new IllegalArgumentException(
                "Not attempted because there are mandatory attributes without value(s): " + mandatoryAttrNames);
    }

    if (beforeObj == null) {
        // 1. get name
        final Name name = (Name) AttributeUtil.find(Name.NAME, attributes);

        // 2. check if:
        //      * accountId is not blank;
        //      * accountId is not equal to Name.
        if (StringUtils.isNotBlank(accountId) && (name == null || !accountId.equals(name.getNameValue()))) {
            // 2.a retrieve uid
            final Uid uid = (Uid) AttributeUtil.find(Uid.NAME, attributes);

            // 2.b add Uid if not provided
            if (uid == null) {
                attributes.add(AttributeBuilder.build(Uid.NAME, Collections.singleton(accountId)));
            }
        }

        // 3. provision entry
        LOG.debug("Create {} on {}", attributes, resource);

        connector.create(propagationMode, oclass, attributes, null, propagationAttempted);
    } else {
        // 1. check if rename is really required
        final Name newName = (Name) AttributeUtil.find(Name.NAME, attributes);

        LOG.debug("Rename required with value {}", newName);

        if (newName != null && newName.equals(beforeObj.getName())
                && !newName.getNameValue().equals(beforeObj.getUid().getUidValue())) {

            LOG.debug("Remote object name unchanged");
            attributes.remove(newName);
        }

        // 2. check wether anything is actually needing to be propagated, i.e. if there is attribute
        // difference between beforeObj - just read above from the connector - and the values to be propagated
        Map<String, Attribute> originalAttrMap = connObjectUtil.toMap(beforeObj.getAttributes());
        Map<String, Attribute> updateAttrMap = connObjectUtil.toMap(attributes);

        // Only compare attribute from beforeObj that are also being updated
        Set<String> skipAttrNames = originalAttrMap.keySet();
        skipAttrNames.removeAll(updateAttrMap.keySet());
        for (String attrName : new HashSet<String>(skipAttrNames)) {
            originalAttrMap.remove(attrName);
        }

        Set<Attribute> originalAttrs = new HashSet<Attribute>(originalAttrMap.values());

        if (originalAttrs.equals(attributes)) {
            LOG.debug("Don't need to propagate anything: {} is equal to {}", originalAttrs, attributes);
        } else {
            LOG.debug("Attributes that would be updated {}", attributes);

            Set<Attribute> strictlyModified = new HashSet<Attribute>();
            for (Attribute attr : attributes) {
                if (!originalAttrs.contains(attr)) {
                    strictlyModified.add(attr);
                }
            }

            // 3. provision entry
            LOG.debug("Update {} on {}", strictlyModified, resource);

            connector.update(propagationMode, beforeObj.getObjectClass(), beforeObj.getUid(), strictlyModified,
                    null, propagationAttempted);
        }
    }
}

From source file:org.syncope.client.util.AttributableOperations.java

private static void populate(final Map<String, AttributeTO> updatedAttrs,
        final Map<String, AttributeTO> originalAttrs, final AbstractAttributableMod result,
        final boolean virtuals) {

    for (Map.Entry<String, AttributeTO> entry : updatedAttrs.entrySet()) {
        AttributeMod mod = new AttributeMod();
        mod.setSchema(entry.getKey());/*from  w ww. j av  a  2s  .co  m*/

        Set<String> updatedValues = new HashSet<String>(entry.getValue().getValues());

        Set<String> originalValues = originalAttrs.containsKey(entry.getKey())
                ? new HashSet<String>(originalAttrs.get(entry.getKey()).getValues())
                : Collections.EMPTY_SET;

        if (!updatedValues.equals(originalValues)) {
            // avoid unwanted inputs
            updatedValues.remove("");
            if (!entry.getValue().isReadonly()) {
                mod.setValuesToBeAdded(new ArrayList<String>(updatedValues));

                if (!mod.isEmpty()) {
                    if (virtuals) {
                        result.addVirtualAttributeToBeRemoved(mod.getSchema());
                    } else {
                        result.addAttributeToBeRemoved(mod.getSchema());
                    }
                }
            }

            mod.setValuesToBeRemoved(new ArrayList<String>(originalValues));

            if (!mod.isEmpty()) {
                if (virtuals) {
                    result.addVirtualAttributeToBeUpdated(mod);
                } else {
                    result.addAttributeToBeUpdated(mod);
                }
            }
        }
    }
}

From source file:com.act.lcms.db.analysis.IonDetectionAnalysis.java

public static Map<ScanData.KIND, List<LCMSWell>> readInputExperimentalSetup(DB db, File inputFile)
        throws IOException, SQLException, ClassNotFoundException {

    TSVParser parser = new TSVParser();
    parser.parse(inputFile);//www .j a v a  2  s. c o m
    Set<String> headerSet = new HashSet<>(parser.getHeader());

    if (!headerSet.equals(ALL_HEADERS)) {
        throw new RuntimeException(String.format("Invalid header types! The allowed header types are: %s",
                StringUtils.join(ALL_HEADERS, ",")));
    }

    Map<ScanData.KIND, List<LCMSWell>> result = new HashMap<>();

    HashMap<String, Plate> plateCache = new HashMap<>();

    for (Map<String, String> row : parser.getResults()) {
        String wellType = row.get(HEADER_WELL_TYPE);
        String barcode = row.get(HEADER_PLATE_BARCODE);
        Integer rowCoordinate = Integer.parseInt(row.get(HEADER_WELL_ROW));
        Integer columnCoordinate = Integer.parseInt(row.get(HEADER_WELL_COLUMN));

        Plate plate = plateCache.get(barcode);
        if (plate == null) {
            plate = Plate.getPlateByBarcode(db, barcode);
            plateCache.put(barcode, plate);
        }

        LCMSWell well = LCMSWell.getInstance().getByPlateIdAndCoordinates(db, plate.getId(), rowCoordinate,
                columnCoordinate);

        if (well == null) {
            throw new RuntimeException(String.format("Well plate id %d, row %d and col %d does not exist",
                    plate.getId(), rowCoordinate, columnCoordinate));
        }

        if (wellType.equals("POS")) {
            List<LCMSWell> values = result.get(ScanData.KIND.POS_SAMPLE);
            if (values == null) {
                values = new ArrayList<>();
                result.put(ScanData.KIND.POS_SAMPLE, values);
            }
            values.add(well);
        } else {
            List<LCMSWell> values = result.get(ScanData.KIND.NEG_CONTROL);
            if (values == null) {
                values = new ArrayList<>();
                result.put(ScanData.KIND.NEG_CONTROL, values);
            }

            values.add(well);
        }
    }

    return result;
}

From source file:org.apache.syncope.common.util.AttributableOperations.java

/**
 * Calculate modifications needed by first in order to be equal to second.
 *
 * @param updated updated RoleTO/*ww w . ja  v  a2s.c om*/
 * @param original original RoleTO
 * @param incremental perform incremental diff (without removing existing info)
 * @return RoleMod containing differences
 */
public static RoleMod diff(final RoleTO updated, final RoleTO original, final boolean incremental) {
    RoleMod result = new RoleMod();

    diff(updated, original, result, incremental);

    // 1. inheritance
    result.setInheritOwner(updated.isInheritOwner());
    result.setInheritTemplates(updated.isInheritTemplates());
    result.setInheritAccountPolicy(updated.isInheritAccountPolicy());
    result.setInheritPasswordPolicy(updated.isInheritPasswordPolicy());
    result.setInheritAttributes(updated.isInheritAttrs());
    result.setInheritDerAttrs(updated.isInheritDerAttrs());
    result.setInheritVirAttrs(updated.isInheritVirAttrs());

    // 2. policies
    result.setAccountPolicy(new ReferenceMod(updated.getAccountPolicy()));
    result.setPasswordPolicy(new ReferenceMod(updated.getPasswordPolicy()));

    // 3. name
    if (!original.getName().equals(updated.getName())) {
        result.setName(updated.getName());
    }

    // 4. entitlements
    Set<String> updatedEnts = new HashSet<String>(updated.getEntitlements());
    Set<String> originalEnts = new HashSet<String>(original.getEntitlements());
    if (updatedEnts.equals(originalEnts)) {
        result.setModEntitlements(false);
        result.getEntitlements().clear();
    } else {
        result.setModEntitlements(true);
        result.getEntitlements().addAll(updated.getEntitlements());
    }

    // 5. templates
    Set<String> updatedTemplates = new HashSet<String>(updated.getRAttrTemplates());
    Set<String> originalTemplates = new HashSet<String>(original.getRAttrTemplates());
    if (updatedTemplates.equals(originalTemplates)) {
        result.setModRAttrTemplates(false);
        result.getRAttrTemplates().clear();
    } else {
        result.setModRAttrTemplates(true);
        result.getRAttrTemplates().addAll(updated.getRAttrTemplates());
    }
    updatedTemplates = new HashSet<String>(updated.getRDerAttrTemplates());
    originalTemplates = new HashSet<String>(original.getRDerAttrTemplates());
    if (updatedTemplates.equals(originalTemplates)) {
        result.setModRDerAttrTemplates(false);
        result.getRDerAttrTemplates().clear();
    } else {
        result.setModRDerAttrTemplates(true);
        result.getRDerAttrTemplates().addAll(updated.getRDerAttrTemplates());
    }
    updatedTemplates = new HashSet<String>(updated.getRVirAttrTemplates());
    originalTemplates = new HashSet<String>(original.getRVirAttrTemplates());
    if (updatedTemplates.equals(originalTemplates)) {
        result.setModRVirAttrTemplates(false);
        result.getRVirAttrTemplates().clear();
    } else {
        result.setModRVirAttrTemplates(true);
        result.getRVirAttrTemplates().addAll(updated.getRVirAttrTemplates());
    }
    updatedTemplates = new HashSet<String>(updated.getMAttrTemplates());
    originalTemplates = new HashSet<String>(original.getMAttrTemplates());
    if (updatedTemplates.equals(originalTemplates)) {
        result.setModMAttrTemplates(false);
        result.getMAttrTemplates().clear();
    } else {
        result.setModMAttrTemplates(true);
        result.getMAttrTemplates().addAll(updated.getMAttrTemplates());
    }
    updatedTemplates = new HashSet<String>(updated.getMDerAttrTemplates());
    originalTemplates = new HashSet<String>(original.getMDerAttrTemplates());
    if (updatedTemplates.equals(originalTemplates)) {
        result.setModMDerAttrTemplates(false);
        result.getMDerAttrTemplates().clear();
    } else {
        result.setModMDerAttrTemplates(true);
        result.getMDerAttrTemplates().addAll(updated.getMDerAttrTemplates());
    }
    updatedTemplates = new HashSet<String>(updated.getMVirAttrTemplates());
    originalTemplates = new HashSet<String>(original.getMVirAttrTemplates());
    if (updatedTemplates.equals(originalTemplates)) {
        result.setModMVirAttrTemplates(false);
        result.getMVirAttrTemplates().clear();
    } else {
        result.setModMVirAttrTemplates(true);
        result.getMVirAttrTemplates().addAll(updated.getMVirAttrTemplates());
    }

    // 6. owner
    result.setUserOwner(new ReferenceMod(updated.getUserOwner()));
    result.setRoleOwner(new ReferenceMod(updated.getRoleOwner()));

    return result;
}

From source file:org.apache.syncope.common.lib.AttributableOperations.java

/**
 * Calculate modifications needed by first in order to be equal to second.
 *
 * @param updated updated RoleTO// w w w  . ja va2 s .co m
 * @param original original RoleTO
 * @param incremental perform incremental diff (without removing existing info)
 * @return RoleMod containing differences
 */
public static RoleMod diff(final RoleTO updated, final RoleTO original, final boolean incremental) {
    RoleMod result = new RoleMod();

    diff(updated, original, result, incremental);

    // 1. inheritance
    result.setInheritOwner(updated.isInheritOwner());
    result.setInheritTemplates(updated.isInheritTemplates());
    result.setInheritAccountPolicy(updated.isInheritAccountPolicy());
    result.setInheritPasswordPolicy(updated.isInheritPasswordPolicy());
    result.setInheritPlainAttrs(updated.isInheritPlainAttrs());
    result.setInheritDerAttrs(updated.isInheritDerAttrs());
    result.setInheritVirAttrs(updated.isInheritVirAttrs());

    // 2. policies
    result.setAccountPolicy(new ReferenceMod(updated.getAccountPolicy()));
    result.setPasswordPolicy(new ReferenceMod(updated.getPasswordPolicy()));

    // 3. name
    if (!original.getName().equals(updated.getName())) {
        result.setName(updated.getName());
    }

    // 4. entitlements
    Set<String> updatedEnts = new HashSet<>(updated.getEntitlements());
    Set<String> originalEnts = new HashSet<>(original.getEntitlements());
    if (updatedEnts.equals(originalEnts)) {
        result.setModEntitlements(false);
        result.getEntitlements().clear();
    } else {
        result.setModEntitlements(true);
        result.getEntitlements().addAll(updated.getEntitlements());
    }

    // 5. templates
    Set<String> updatedTemplates = new HashSet<>(updated.getRPlainAttrTemplates());
    Set<String> originalTemplates = new HashSet<>(original.getRPlainAttrTemplates());
    if (updatedTemplates.equals(originalTemplates)) {
        result.setModRAttrTemplates(false);
        result.getRPlainAttrTemplates().clear();
    } else {
        result.setModRAttrTemplates(true);
        result.getRPlainAttrTemplates().addAll(updated.getRPlainAttrTemplates());
    }
    updatedTemplates = new HashSet<>(updated.getRDerAttrTemplates());
    originalTemplates = new HashSet<>(original.getRDerAttrTemplates());
    if (updatedTemplates.equals(originalTemplates)) {
        result.setModRDerAttrTemplates(false);
        result.getRDerAttrTemplates().clear();
    } else {
        result.setModRDerAttrTemplates(true);
        result.getRDerAttrTemplates().addAll(updated.getRDerAttrTemplates());
    }
    updatedTemplates = new HashSet<>(updated.getRVirAttrTemplates());
    originalTemplates = new HashSet<>(original.getRVirAttrTemplates());
    if (updatedTemplates.equals(originalTemplates)) {
        result.setModRVirAttrTemplates(false);
        result.getRVirAttrTemplates().clear();
    } else {
        result.setModRVirAttrTemplates(true);
        result.getRVirAttrTemplates().addAll(updated.getRVirAttrTemplates());
    }
    updatedTemplates = new HashSet<>(updated.getMPlainAttrTemplates());
    originalTemplates = new HashSet<>(original.getMPlainAttrTemplates());
    if (updatedTemplates.equals(originalTemplates)) {
        result.setModMAttrTemplates(false);
        result.getMPlainAttrTemplates().clear();
    } else {
        result.setModMAttrTemplates(true);
        result.getMPlainAttrTemplates().addAll(updated.getMPlainAttrTemplates());
    }
    updatedTemplates = new HashSet<>(updated.getMDerAttrTemplates());
    originalTemplates = new HashSet<>(original.getMDerAttrTemplates());
    if (updatedTemplates.equals(originalTemplates)) {
        result.setModMDerAttrTemplates(false);
        result.getMDerAttrTemplates().clear();
    } else {
        result.setModMDerAttrTemplates(true);
        result.getMDerAttrTemplates().addAll(updated.getMDerAttrTemplates());
    }
    updatedTemplates = new HashSet<>(updated.getMVirAttrTemplates());
    originalTemplates = new HashSet<>(original.getMVirAttrTemplates());
    if (updatedTemplates.equals(originalTemplates)) {
        result.setModMVirAttrTemplates(false);
        result.getMVirAttrTemplates().clear();
    } else {
        result.setModMVirAttrTemplates(true);
        result.getMVirAttrTemplates().addAll(updated.getMVirAttrTemplates());
    }

    // 6. owner
    result.setUserOwner(new ReferenceMod(updated.getUserOwner()));
    result.setRoleOwner(new ReferenceMod(updated.getRoleOwner()));

    return result;
}

From source file:org.beanfuse.lang.SeqStringUtil.java

/**
 * ","?????./*from   w  w w .  j a  va  2s. 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 firstSet = new HashSet();
        for (int i = 0; i < firstWords.length; i++) {
            firstSet.add(firstWords[i]);
        }
        String[] secondWords = StringUtils.split(second, delimiter);
        Set secondSet = new HashSet();
        for (int i = 0; i < secondWords.length; i++) {
            secondSet.add(secondWords[i]);
        }
        return firstSet.equals(secondSet);
    } else {
        return StringUtils.isEmpty(first) & StringUtils.isEmpty(second);
    }
}