Example usage for java.util HashSet equals

List of usage examples for java.util HashSet equals

Introduction

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

Prototype

boolean equals(Object o);

Source Link

Document

Compares the specified object with this set for equality.

Usage

From source file:org.apache.accumulo.tserver.DirectoryDecommissioner.java

static boolean same(FileSystem fs1, Path dir, FileSystem fs2, Path newDir)
        throws FileNotFoundException, IOException {
    // its possible that a user changes config in such a way that two uris point to the same thing. Like hdfs://foo/a/b and hdfs://1.2.3.4/a/b both reference
    // the same thing because DNS resolves foo to 1.2.3.4. This method does not analyze uris to determine if equivalent, instead it inspects the contents of
    // what the uris point to.

    //this code is called infrequently and does not need to be optimized.  

    if (fs1.exists(dir) && fs2.exists(newDir)) {

        if (!fs1.isDirectory(dir))
            throw new IllegalArgumentException("expected " + dir + " to be a directory");

        if (!fs2.isDirectory(newDir))
            throw new IllegalArgumentException("expected " + newDir + " to be a directory");

        HashSet<String> names1 = getFileNames(fs1.listStatus(dir));
        HashSet<String> names2 = getFileNames(fs2.listStatus(newDir));

        if (names1.equals(names2)) {
            for (String name : names1)
                if (!hash(fs1, dir, name).equals(hash(fs2, newDir, name)))
                    return false;
            return true;
        }//w ww. ja v  a  2 s  .  c o  m

    }
    return false;
}

From source file:org.apache.hyracks.algebricks.rewriter.rules.PushProjectDownRule.java

private static boolean pushNeededProjections(HashSet<LogicalVariable> toPush, Mutable<ILogicalOperator> opRef,
        IOptimizationContext context, ILogicalOperator initialOp) throws AlgebricksException {
    HashSet<LogicalVariable> allP = new HashSet<LogicalVariable>();
    AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
    VariableUtilities.getSubplanLocalLiveVariables(op, allP);

    HashSet<LogicalVariable> toProject = new HashSet<LogicalVariable>();
    for (LogicalVariable v : toPush) {
        if (allP.contains(v)) {
            toProject.add(v);//  w  w w . j a v  a 2  s .  c om
        }
    }
    if (toProject.equals(allP)) {
        // projection would be redundant, since we would project everything
        // but we can try with the children
        boolean push = false;
        if (pushThroughOp(toProject, opRef, initialOp, context).first) {
            push = true;
        }
        return push;
    } else {
        return pushAllProjectionsOnTopOf(toProject, opRef, context, initialOp);
    }
}

From source file:edu.uci.ics.hyracks.algebricks.rewriter.rules.PushProjectDownRule.java

private static boolean pushNeededProjections(HashSet<LogicalVariable> toPush, Mutable<ILogicalOperator> opRef,
        IOptimizationContext context, ILogicalOperator initialOp) throws AlgebricksException {
    HashSet<LogicalVariable> allP = new HashSet<LogicalVariable>();
    AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
    VariableUtilities.getLiveVariables(op, allP);

    HashSet<LogicalVariable> toProject = new HashSet<LogicalVariable>();
    for (LogicalVariable v : toPush) {
        if (allP.contains(v)) {
            toProject.add(v);/*from www .ja v a 2s  .co m*/
        }
    }
    if (toProject.equals(allP)) {
        // projection would be redundant, since we would project everything
        // but we can try with the children
        boolean push = false;
        if (pushThroughOp(toProject, opRef, initialOp, context).first) {
            push = true;
        }
        return push;
    } else {
        return pushAllProjectionsOnTopOf(toProject, opRef, context, initialOp);
    }
}

From source file:org.apache.accumulo.server.fs.VolumeUtil.java

static boolean same(FileSystem fs1, Path dir, FileSystem fs2, Path newDir)
        throws FileNotFoundException, IOException {
    // its possible that a user changes config in such a way that two uris point to the same thing. Like hdfs://foo/a/b and hdfs://1.2.3.4/a/b both reference
    // the same thing because DNS resolves foo to 1.2.3.4. This method does not analyze uris to determine if equivalent, instead it inspects the contents of
    // what the uris point to.

    // this code is called infrequently and does not need to be optimized.

    if (fs1.exists(dir) && fs2.exists(newDir)) {

        if (!fs1.isDirectory(dir))
            throw new IllegalArgumentException("expected " + dir + " to be a directory");

        if (!fs2.isDirectory(newDir))
            throw new IllegalArgumentException("expected " + newDir + " to be a directory");

        HashSet<String> names1 = getFileNames(fs1.listStatus(dir));
        HashSet<String> names2 = getFileNames(fs2.listStatus(newDir));

        if (names1.equals(names2)) {
            for (String name : names1)
                if (!hash(fs1, dir, name).equals(hash(fs2, newDir, name)))
                    return false;
            return true;
        }/*www.j a  v a 2 s.co m*/

    }
    return false;
}

From source file:jef.tools.ArrayUtils.java

/**
 * ??//from   ww  w . j  av a2 s  .co  m
 * 
 * @param array1
 * @param array2
 * @return
 * 
 */
public static boolean equalsIgnoreOrder(Object array1, Object array2) {
    Object[] obj1 = toObject(array1);
    Object[] obj2 = toObject(array2);
    HashSet<Object> set1 = new HashSet<Object>(Arrays.asList(obj1));
    HashSet<Object> set2 = new HashSet<Object>(Arrays.asList(obj2));
    return set1.equals(set2);
}

From source file:edu.umn.msi.tropix.proteomics.conversion.impl.MzXMLToDTAConverterStreamingImplTest.java

private void testStructure(final MzXMLToDTAOptions options) throws Exception {
    final MzXMLToDTAConverterStreamingImpl converter = new MzXMLToDTAConverterStreamingImpl();
    DTAList dtaList;/*www .  jav  a2s.  c  o m*/
    InputStream mzxmlStream;
    mzxmlStream = ProteomicsTests.getResourceAsStream("validMzXML.mzxml");
    try {
        dtaList = converter.mzxmlToDTA(mzxmlStream, options);
        VerifyUtils.verifyDTAList(dtaList);
    } finally {
        IO_UTILS.closeQuietly(mzxmlStream);
    }

    mzxmlStream = ProteomicsTests.getResourceAsStream("validMzXML.mzxml");
    try {
        dtaList = converter.mzxmlToDTA(mzxmlStream, options);
        final HashSet<String> originalNames = new HashSet<String>();
        originalNames.addAll(Arrays.asList(new String[] { "mrr.103.106.1.dta", "mrr.1105.1106.2.dta",
                "mrr.1105.1106.3.dta", "mrr.2025.2026.2.dta", "mrr.2025.2026.3.dta", "mrr.3009.3011.1.dta" }));

        final HashSet<String> mzxmlNames = new HashSet<String>();
        for (final DTAList.Entry entry : dtaList) {
            mzxmlNames.add(entry.getName());
        }
        assert mzxmlNames.equals(originalNames);
    } finally {
        IO_UTILS.closeQuietly(mzxmlStream);
    }

}

From source file:hr.fer.spocc.automaton.fsm.AbstractFiniteStateMachine.java

@SuppressWarnings("unchecked")
@Override/*from  ww w . j a  v  a  2  s .  c o m*/
public boolean equals(Object obj) {
    if (obj == this)
        return true;
    if (obj == null)
        return false;
    if (!(obj instanceof NondeterministicFiniteAutomaton))
        return false;

    NondeterministicFiniteAutomaton<T> other = (NondeterministicFiniteAutomaton<T>) obj;

    HashSet<Transition<T>> t1 = new HashSet<Transition<T>>(getTransitions());

    HashSet<Transition<T>> t2 = new HashSet<Transition<T>>(other.getTransitions());

    return t1.equals(t2) && getStartState().equals(other.getStartState());
}

From source file:org.dspace.authority.orcid.OrcidAuthorityValue.java

@Override
public boolean hasTheSameInformationAs(Object o) {
    if (this == o) {
        return true;
    }/*from   w  ww.j  a v a 2s .c  o m*/
    if (o == null || getClass() != o.getClass()) {
        return false;
    }
    if (!super.hasTheSameInformationAs(o)) {
        return false;
    }

    OrcidAuthorityValue that = (OrcidAuthorityValue) o;

    if (orcid_id != null ? !orcid_id.equals(that.orcid_id) : that.orcid_id != null) {
        return false;
    }

    for (String key : otherMetadata.keySet()) {
        if (otherMetadata.get(key) != null) {
            List<String> metadata = otherMetadata.get(key);
            List<String> otherMetadata = that.otherMetadata.get(key);
            if (otherMetadata == null) {
                return false;
            } else {
                HashSet<String> metadataSet = new HashSet<String>(metadata);
                HashSet<String> otherMetadataSet = new HashSet<String>(otherMetadata);
                if (!metadataSet.equals(otherMetadataSet)) {
                    return false;
                }
            }
        } else {
            if (that.otherMetadata.get(key) != null) {
                return false;
            }
        }
    }

    return true;
}

From source file:org.dspace.authority.orcid.Orcidv2AuthorityValue.java

/**
 * The regular equals() only checks if both AuthorityValues describe the same authority.
 * This method checks if the AuthorityValues have different information
 * E.g. it is used to decide when lastModified should be updated.
 * @param o object// w ww . j  a  v a2  s.  c o  m
 * @return true or false
 */
@Override
public boolean hasTheSameInformationAs(Object o) {
    if (this == o) {
        return true;
    }
    if (o == null || getClass() != o.getClass()) {
        return false;
    }
    if (!super.hasTheSameInformationAs(o)) {
        return false;
    }

    Orcidv2AuthorityValue that = (Orcidv2AuthorityValue) o;

    if (orcid_id != null ? !orcid_id.equals(that.orcid_id) : that.orcid_id != null) {
        return false;
    }

    for (String key : otherMetadata.keySet()) {
        if (otherMetadata.get(key) != null) {
            List<String> metadata = otherMetadata.get(key);
            List<String> otherMetadata = that.otherMetadata.get(key);
            if (otherMetadata == null) {
                return false;
            } else {
                HashSet<String> metadataSet = new HashSet<String>(metadata);
                HashSet<String> otherMetadataSet = new HashSet<String>(otherMetadata);
                if (!metadataSet.equals(otherMetadataSet)) {
                    return false;
                }
            }
        } else {
            if (that.otherMetadata.get(key) != null) {
                return false;
            }
        }
    }

    return true;
}

From source file:alma.acs.tmcdb.compare.TestHighLevelNodes.java

public void testMACI_Components() throws Exception {
    String[] xmlAllNodes = retrieveComponentsList(xmlAccess);
    String[] rdbAllNodes = retrieveComponentsList(rdbAccess);
    assertEquals(xmlAllNodes.length, rdbAllNodes.length);
    HashSet<String> xmlNodes = new HashSet<String>(Arrays.asList(xmlAllNodes));
    HashSet<String> rdbNodes = new HashSet<String>(Arrays.asList(rdbAllNodes));
    logger.info("XML: " + xmlNodes.toString() + ";\n TMCDB: " + rdbNodes.toString());

    assertTrue(xmlNodes.equals(rdbNodes));
    assertTrue(CollectionUtils.isEqualCollection(xmlNodes, rdbNodes));

    for (Iterator<String> iterator = xmlNodes.iterator(); iterator.hasNext();) {
        String xmlstring = "MACI/Components/" + (String) iterator.next();
        DAO xmlDao = xmlDAL.get_DAO_Servant(xmlstring);
        DAO rdbDao = rdbDAL.get_DAO_Servant(xmlstring);
        assertEquals(xmlDao.get_string("Code"), rdbDao.get_string("Code"));
        assertEquals(xmlDao.get_string("Type"), rdbDao.get_string("Type"));
        assertEquals(xmlDao.get_string("Container"), rdbDao.get_string("Container"));
        assertEquals(xmlDao.get_string("Default"), rdbDao.get_string("Default"));
        assertEquals(xmlDao.get_string("ImplLang"), rdbDao.get_string("ImplLang"));
    }//from   w w w. ja  v  a 2s.  co m

}