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:au.org.ala.delta.model.DiffUtils.java

private static boolean doCompareMultiStateOrInteger(Set<Integer> attr1Values, Set<Integer> attr2Values,
        boolean attr1Unknown, boolean attr2Unknown, boolean attr1Inapplicable, boolean attr2Inapplicable,
        boolean matchUnknowns, boolean matchInapplicables, MatchType matchType) {

    // If both attributes are unknown or inapplicable this is considered a
    // match. Otherwise, the return value depends on setting for
    // matchInapplicable or matchUnknown.
    if ((attr1Unknown || attr1Inapplicable) && (attr2Unknown || attr2Inapplicable)) {
        return true;
    }//from  w  w  w. ja va 2  s  . co m

    if ((attr1Unknown && attr1Inapplicable) || (attr2Unknown && attr2Inapplicable)) {
        return matchInapplicables;
    }

    if ((attr1Unknown && !attr1Inapplicable) || (attr2Unknown && !attr2Inapplicable)) {
        return matchUnknowns;
    }

    boolean match = false;

    switch (matchType) {
    case EXACT:
        match = attr1Values.equals(attr2Values);
        break;
    case SUBSET:
        // is the first a subset of the second
        match = attr2Values.containsAll(attr1Values);
        break;
    case OVERLAP:
        for (int stateVal : attr1Values) {
            if (attr2Values.contains(stateVal)) {
                match = true;
                break;
            }
        }
        break;
    default:
        throw new RuntimeException(String.format("Unrecognized match type %s", matchType.toString()));
    }

    return match;
}

From source file:org.apache.hyracks.maven.license.LicenseMojo.java

protected MavenProject resolveDependency(Artifact depObj) throws ProjectBuildingException {
    String key = depObj.getGroupId() + ":" + depObj.getArtifactId() + ":" + depObj.getVersion();

    MavenProject depProj = projectCache.get(key);

    if (depProj == null) {
        try {/*from w ww .j a v a2 s.com*/
            depProj = projectBuilder.buildFromRepository(depObj, remoteRepositories, localRepository, false);
        } catch (ProjectBuildingException e) {
            throw new ProjectBuildingException(key, "Error creating dependent artifacts", e);
        }

        Model supplement = supplementModels.get(
                SupplementalModelHelper.generateSupplementMapKey(depObj.getGroupId(), depObj.getArtifactId()));
        if (supplement != null) {
            Model merged = SupplementalModelHelper.mergeModels(assembler, depProj.getModel(), supplement);
            Set<String> origLicenses = depProj.getModel().getLicenses().stream().map(License::getUrl)
                    .collect(Collectors.toSet());
            Set<String> newLicenses = merged.getLicenses().stream().map(License::getUrl)
                    .collect(Collectors.toSet());
            if (!origLicenses.equals(newLicenses)) {
                getLog().warn("license list for " + toGav(depProj) + " changed with supplemental model; was: "
                        + origLicenses + ", now: " + newLicenses);
            }
            depProj = new MavenProject(merged);
            depProj.setArtifact(depObj);
            depProj.setVersion(depObj.getVersion());
        }
        depProj.getArtifact().setScope(depObj.getScope());
        projectCache.put(key, depProj);
    }
    return depProj;
}

From source file:io.cloudslang.lang.compiler.validator.PreCompileValidatorImpl.java

@Override
public void validateResultsWithWhitelist(List<Result> results, List<String> allowedResults, String artifactName,
        List<RuntimeException> errors) {

    final Set<String> artifactResultNames = results.stream().map(Result::getName).collect(toSet());
    if ((artifactResultNames.size() != results.size())
            || !artifactResultNames.equals(new HashSet<>(allowedResults))) {
        errors.add(new RuntimeException("Sequential operation: '" + artifactName + "' syntax is illegal. "
                + FLOW_RESULTS_NOT_ALLOWED_EXPRESSIONS_MESSAGE + allowedResults.toString() + "."));
    }//from   w w  w .  j ava  2 s .  com
}

From source file:edu.uci.ics.jung.algorithms.blockmodel.StructurallyEquivalent.java

/**
 * Checks whether a pair of vertices are structurally equivalent.
 * Specifically, whether v1's predecessors are equal to v2's predecessors,
 * and same for successors.//  ww w.j  av  a2s . c om
 * 
 * @param g the graph in which the structural equivalence comparison is to take place
 * @param v1 the vertex to check for structural equivalence to v2
 * @param v2 the vertex to check for structural equivalence to v1
 */
protected boolean isStructurallyEquivalent(Graph<V, ?> g, V v1, V v2) {

    if (g.degree(v1) != g.degree(v2)) {
        return false;
    }

    Set<V> n1 = new HashSet<V>(g.getPredecessors(v1));
    n1.remove(v2);
    n1.remove(v1);
    Set<V> n2 = new HashSet<V>(g.getPredecessors(v2));
    n2.remove(v1);
    n2.remove(v2);

    Set<V> o1 = new HashSet<V>(g.getSuccessors(v1));
    Set<V> o2 = new HashSet<V>(g.getSuccessors(v2));
    o1.remove(v1);
    o1.remove(v2);
    o2.remove(v1);
    o2.remove(v2);

    // this neglects self-loops and directed edges from 1 to other
    boolean b = (n1.equals(n2) && o1.equals(o2));
    if (!b)
        return b;

    // if there's a directed edge v1->v2 then there's a directed edge v2->v1
    b &= (g.isSuccessor(v1, v2) == g.isSuccessor(v2, v1));

    // self-loop check
    b &= (g.isSuccessor(v1, v1) == g.isSuccessor(v2, v2));

    return b;

}

From source file:org.commonjava.maven.cartographer.preset.ScopeWithEmbeddedProjectsFilter.java

@Override
public ProjectRelationshipFilter getChildFilter(final ProjectRelationship<?> lastRelationship) {
    switch (lastRelationship.getType()) {
    case BOM:/*w w  w.j  a v  a  2 s  .  c o m*/
        return StructuralRelationshipsFilter.INSTANCE;
    case PARENT: {
        return this;
    }
    case EXTENSION:
    case PLUGIN:
    case PLUGIN_DEP: {
        logger.debug("[FILT-OFFx1]: {}", lastRelationship);
        return NoneFilter.INSTANCE;
        //                if ( filter == NoneFilter.INSTANCE )
        //                {
        //                    return this;
        //                }
        //
        //                //                logger.info( "getChildFilter({})", lastRelationship );
        //                return new ScopeWithEmbeddedProjectsFilter( scope, NoneFilter.INSTANCE );
    }
    default: {
        //                logger.info( "getChildFilter({})", lastRelationship );

        final DependencyRelationship dr = (DependencyRelationship) lastRelationship;

        if (DependencyScope.test == dr.getScope() || DependencyScope.provided == dr.getScope()) {
            logger.debug("[FILT-OFFx2]: {}", lastRelationship);
            return StructuralRelationshipsFilter.INSTANCE;
        }

        Set<ProjectRef> exc = null;
        boolean excChanged = false;

        // if there are new excludes, ALWAYS construct a new child filter.
        if (dr.getExcludes() != null && !dr.getExcludes().isEmpty()) {
            if (excludes != null) {
                exc = new HashSet<ProjectRef>(excludes);
                exc.addAll(dr.getExcludes());
                excChanged = !exc.equals(excludes);
            } else {
                exc = new HashSet<ProjectRef>(dr.getExcludes());
                excChanged = true;
            }
        } else if (excludes != null) {
            exc = new HashSet<ProjectRef>(excludes);
        }

        final ProjectRelationshipFilter nextFilter = filter.getChildFilter(lastRelationship);
        if (filter.equals(nextFilter) && !excChanged) {
            return this;
        } else {
            return new ScopeWithEmbeddedProjectsFilter(nextFilter, acceptManaged, exc);
        }
    }
    }
}

From source file:org.commonjava.cartographer.graph.preset.ScopeWithEmbeddedProjectsFilter.java

@Override
public ProjectRelationshipFilter getChildFilter(final ProjectRelationship<?, ?> lastRelationship) {
    switch (lastRelationship.getType()) {
    case BOM://from www .  j a  va2 s  .  c  o m
        return StructuralRelationshipsFilter.INSTANCE;
    case PARENT: {
        return this;
    }
    case EXTENSION:
    case PLUGIN:
    case PLUGIN_DEP: {
        logger.debug("[FILT-OFFx1]: {}", lastRelationship);
        return NoneFilter.INSTANCE;
        //                if ( filter == NoneFilter.INSTANCE )
        //                {
        //                    return this;
        //                }
        //
        //                //                logger.info( "getChildFilter({})", lastRelationship );
        //                return new ScopeWithEmbeddedProjectsFilter( scope, NoneFilter.INSTANCE );
    }
    default: {
        //                logger.info( "getChildFilter({})", lastRelationship );

        final DependencyRelationship dr = (DependencyRelationship) lastRelationship;

        if (DependencyScope.test == dr.getScope() || DependencyScope.provided == dr.getScope()) {
            logger.debug("[FILT-OFFx2]: {}", lastRelationship);
            return StructuralRelationshipsFilter.INSTANCE;
        }

        Set<ProjectRef> exc = null;
        boolean excChanged = false;

        // if there are new excludes, ALWAYS construct a new child filter.
        if (dr.getExcludes() != null && !dr.getExcludes().isEmpty()) {
            if (excludes != null) {
                exc = new HashSet<ProjectRef>(excludes);
                exc.addAll(dr.getExcludes());
                excChanged = !exc.equals(excludes);
            } else {
                exc = new HashSet<ProjectRef>(dr.getExcludes());
                excChanged = true;
            }
        } else if (excludes != null) {
            exc = new HashSet<ProjectRef>(excludes);
        }

        final ProjectRelationshipFilter nextFilter = filter.getChildFilter(lastRelationship);
        if (filter.equals(nextFilter) && !excChanged) {
            return this;
        } else {
            return new ScopeWithEmbeddedProjectsFilter(nextFilter, acceptManaged, exc);
        }
    }
    }
}

From source file:org.openvpms.archetype.rules.product.io.ProductDataComparator.java

/**
 * Determines if the price, cost and maximum discount of two prices are the same.
 *
 * @param data  the price data// www  .j a v  a2  s .co m
 * @param price the price to compare with
 * @return {@code true} if the price and cost are the same in both
 */
private boolean priceEquals(PriceData data, ProductPrice price) {
    IMObjectBean bean = new IMObjectBean(price, service);
    BigDecimal cost = bean.getBigDecimal("cost", BigDecimal.ZERO);
    BigDecimal maxDiscount = bean.getBigDecimal("maxDiscount", BigDecimal.ZERO);
    if (price.getPrice().compareTo(data.getPrice()) == 0 && cost.compareTo(data.getCost()) == 0
            && maxDiscount.compareTo(data.getMaxDiscount()) == 0 && (!FIXED_PRICE.equals(data.getShortName())
                    || data.isDefault() == ProductIOHelper.isDefault(bean))) {
        Set<Lookup> pricingGroups = ProductIOHelper.getPricingGroups(price, service);
        return pricingGroups.equals(data.getPricingGroups());
    }
    return false;
}

From source file:org.bonitasoft.console.common.server.page.CustomPageServiceTest.java

@Test
public void should_get_Custom_Page_permissions_to_CompoundPermissions_with_empty_list() throws Exception {
    // Given/*from   ww  w .  jav  a  2s  .  c  o m*/
    final String fileContent = "name=customPage1\n" + "resources=[]";

    final File pagePropertiesFile = File.createTempFile(PAGE_PROPERTIES, ".tmp");
    IOUtils.write(fileContent.getBytes(), new FileOutputStream(pagePropertiesFile));
    doReturn(Collections.emptySet()).when(resourcesPermissionsMapping).getPropertyAsSet("GET|unkown/resource");

    // When
    final Set<String> customPagePermissions = customPageService.getCustomPagePermissions(pagePropertiesFile,
            resourcesPermissionsMapping, false);

    // Then
    assertTrue(customPagePermissions.equals(new HashSet<String>()));
}

From source file:fr.mby.portal.coreimpl.acl.BasicRoleFactoryTest.java

@Test
public void testInitializeAndBuildRole() throws Exception {
    IPermission perm1 = basicPermissionFactory.build(TEST_PERM_NAME_1);
    Assert.assertNotNull("Permission 1 should not be null !", perm1);

    IPermission perm2 = basicPermissionFactory.build(TEST_PERM_NAME_2);
    Assert.assertNotNull("Permission 2 should not be null !", perm2);

    IPermission perm3 = basicPermissionFactory.build(TEST_PERM_NAME_3);
    Assert.assertNotNull("Permission 3 should not be null !", perm3);

    IPermission perm4 = basicPermissionFactory.build(TEST_PERM_NAME_4);
    Assert.assertNotNull("Permission 4 should not be null !", perm4);

    // Create Role 1 whith Perms 2 & 3
    Set<IPermission> permissionsRole1 = new HashSet<IPermission>();
    permissionsRole1.add(perm2);//ww  w  .ja v a2s .  com
    permissionsRole1.add(perm3);
    IRole initializedRole1 = this.basicRoleFactory.initializeRole(TEST_ROLE_NAME_1, permissionsRole1, null);

    // Check Role 1 name
    Assert.assertNotNull("Initialized role 1 should not be null !", initializedRole1);
    Assert.assertEquals("Bad role 1 name !", initializedRole1.getName(), TEST_ROLE_NAME_1);

    // Check Role 1 empty sub-roles
    Set<IRole> role1SubRoles = initializedRole1.getSubRoles();
    Assert.assertNotNull("Initialized role 1 sub-roles should not be null !", role1SubRoles);
    Assert.assertTrue("Bad role 1 sub-roles size !", role1SubRoles.isEmpty());

    // Check Role 1 perms
    Set<IPermission> role1Perms = initializedRole1.getPermissions();
    Assert.assertNotNull("Initialized role 1 permissions should not be null !", role1Perms);
    Assert.assertEquals("Bad role 1 permissions size !", role1Perms.size(), 2);
    Assert.assertFalse("Role permissions Set should be different than the one passed on initialization !",
            role1Perms == permissionsRole1);
    Assert.assertTrue("Role permissions Set should be equals to the one passed on initialization !",
            role1Perms.equals(permissionsRole1));

    // Check Role 1 building
    IRole builtRole1 = this.basicRoleFactory.build(TEST_ROLE_NAME_1);
    Assert.assertTrue("Role built should be the same the one return after initialization !",
            builtRole1 == initializedRole1);

    // Create Role 2 with Perms 4 and sub-role 1
    Set<IPermission> permissionsRole2 = new HashSet<IPermission>();
    permissionsRole2.add(perm4);
    Set<IRole> subRolesRole2 = new HashSet<IRole>();
    subRolesRole2.add(builtRole1);
    IRole initializedRole2 = this.basicRoleFactory.initializeRole(TEST_ROLE_NAME_2, permissionsRole2,
            subRolesRole2);

    // Check Role 2 name
    Assert.assertNotNull("Initialized role 2 should not be null !", initializedRole2);
    Assert.assertEquals("Bad role 2 name !", initializedRole2.getName(), TEST_ROLE_NAME_2);

    // Check Role 2 sub-roles
    Set<IRole> role2SubRoles = initializedRole2.getSubRoles();
    Assert.assertNotNull("Initialized role 2 sub-roles should not be null !", role2SubRoles);
    Assert.assertTrue("Bad role 2 sub-roles size !", role2SubRoles.size() == 1);
    Assert.assertTrue("Bad role 2 sub-roles size !", role2SubRoles.iterator().next() == builtRole1);

    // Check Role 2 perms
    Set<IPermission> role2Perms = initializedRole2.getPermissions();
    Assert.assertNotNull("Initialized role 2 permissions should not be null !", role2Perms);
    Assert.assertEquals("Bad role 2 permissions size !", role2Perms.size(), 1);
    Assert.assertTrue("Role 2 permissions Set should contains perm 4 !", role2Perms.contains(perm4));

    // Check Role 1 building
    IRole builtRole2 = this.basicRoleFactory.build(TEST_ROLE_NAME_2);
    Assert.assertTrue("Role built should be the same the one return after initialization !",
            builtRole2 == initializedRole2);

}

From source file:com.grendelscan.commons.http.apache_overrides.serializable.SerializableBasicCookie.java

@Override
public boolean equals(final Object obj) {
    if (obj == null || !(obj instanceof Cookie)) {
        return false;
    }//from   w  w w .  j  av  a 2 s . c  o  m
    Cookie c = (Cookie) obj;
    boolean goodPorts = false;
    if (ports == null) {
        goodPorts = c.getPorts() == null;
    } else if (ports.length == c.getPorts().length) {
        Set<Integer> p1 = new HashSet<Integer>(ports.length);
        Set<Integer> p2 = new HashSet<Integer>(ports.length);
        for (int i = 0; i < ports.length; i++) {
            p1.add(ports[i]);
            p2.add(c.getPorts()[i]);
        }
        goodPorts = p1.equals(p2);
    }
    return goodPorts & cookieDomain.equalsIgnoreCase(c.getDomain()) && cookiePath.equalsIgnoreCase(c.getPath())
            && value.equals(c.getValue()) && name.equalsIgnoreCase(c.getName());

}