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:com.rapid7.diskstorage.dynamodb.DynamoDBDelegate.java

public boolean waitForTableCreation(String tableName, boolean verifyIndexesList,
        List<LocalSecondaryIndexDescription> expectedLsiList,
        List<GlobalSecondaryIndexDescription> expectedGsiList) throws BackendException {
    boolean successFlag = false;
    int retryCount = 0;
    while (!successFlag && retryCount < maxRetries) {
        try {//from ww w  .  j  a  va2  s.  c  om
            boolean areAllGSIsActive = true;
            final TableDescription td = describeTable(tableName);
            if (verifyIndexesList) {
                Set<LocalSecondaryIndexDescription> expectedLSIs = new HashSet<LocalSecondaryIndexDescription>();
                if (expectedLsiList != null) {
                    expectedLSIs.addAll(expectedLsiList);
                }
                Set<LocalSecondaryIndexDescription> actualLSIs = new HashSet<LocalSecondaryIndexDescription>();
                if (td.getLocalSecondaryIndexes() != null) {
                    actualLSIs.addAll(td.getLocalSecondaryIndexes());
                }
                // the lsi list should be there even if the table is in creating state
                if (!((expectedLsiList == null && td.getLocalSecondaryIndexes() == null)
                        || expectedLSIs.equals(actualLSIs))) {
                    throw new PermanentBackendException(
                            "LSI list is not as expected during table creation. expectedLsiList="
                                    + expectedLsiList.toString() + "; table description=" + td.toString());
                }

                // ignore the status of all GSIs since they will mess up .equals()
                if (td.getGlobalSecondaryIndexes() != null) {
                    for (GlobalSecondaryIndexDescription gDesc : td.getGlobalSecondaryIndexes()) {
                        if (!TableStatus.ACTIVE.toString().equals(gDesc.getIndexStatus())) {
                            areAllGSIsActive = false;
                            break;
                        }
                    }
                }

                // the gsi list should be there even if the table is in creating state
                if (!areGSIsSameConfiguration(expectedGsiList, td.getGlobalSecondaryIndexes())) {
                    throw new PermanentBackendException(
                            "GSI list is not as expected during table creation. expectedGsiList="
                                    + expectedGsiList.toString() + "; table description=" + td.toString());
                }
            }
            successFlag = td.getTableStatus().equals(TableStatus.ACTIVE.toString()) && areAllGSIsActive;
        } catch (BackendNotFoundException e) {
            successFlag = false;
        }

        if (!successFlag) {
            interruptibleSleep(CONTROL_PLANE_RETRY_DELAY_MS);
        }
        retryCount++;
    }
    if (!successFlag) {
        throw new PermanentBackendException(
                "Table creation not completed for table " + tableName + " after retrying " + this.maxRetries
                        + " times for a duration of " + CONTROL_PLANE_RETRY_DELAY_MS * this.maxRetries + " ms");
    }
    return successFlag;
}

From source file:com.amazon.janusgraph.diskstorage.dynamodb.DynamoDBDelegate.java

public void waitForTableCreation(String tableName, boolean verifyIndexesList,
        List<LocalSecondaryIndexDescription> expectedLsiList,
        List<GlobalSecondaryIndexDescription> expectedGsiList) throws BackendException {
    boolean successFlag = false;
    int retryCount = 0;
    while (!successFlag && retryCount < maxRetries) {
        try {// w w w  . j a  v  a 2 s .c  om
            boolean areAllGSIsActive = true;
            final TableDescription td = describeTable(tableName);
            if (verifyIndexesList) {
                Set<LocalSecondaryIndexDescription> expectedLSIs = new HashSet<LocalSecondaryIndexDescription>();
                if (expectedLsiList != null) {
                    expectedLSIs.addAll(expectedLsiList);
                }
                Set<LocalSecondaryIndexDescription> actualLSIs = new HashSet<LocalSecondaryIndexDescription>();
                if (td.getLocalSecondaryIndexes() != null) {
                    actualLSIs.addAll(td.getLocalSecondaryIndexes());
                }
                // the lsi list should be there even if the table is in creating state
                if (!((expectedLsiList == null && td.getLocalSecondaryIndexes() == null)
                        || expectedLSIs.equals(actualLSIs))) {
                    throw new PermanentBackendException(
                            "LSI list is not as expected during table creation. expectedLsiList="
                                    + expectedLsiList.toString() + "; table description=" + td.toString());
                }

                // ignore the status of all GSIs since they will mess up .equals()
                if (td.getGlobalSecondaryIndexes() != null) {
                    for (GlobalSecondaryIndexDescription gDesc : td.getGlobalSecondaryIndexes()) {
                        if (!isTableAcceptingWrites(gDesc.getIndexStatus())) {
                            areAllGSIsActive = false;
                            break;
                        }
                    }
                }

                // the gsi list should be there even if the table is in creating state
                if (!areGSIsSameConfiguration(expectedGsiList, td.getGlobalSecondaryIndexes())) {
                    throw new PermanentBackendException(
                            "GSI list is not as expected during table creation. expectedGsiList="
                                    + expectedGsiList.toString() + "; table description=" + td.toString());
                }
            }
            successFlag = isTableAcceptingWrites(td.getTableStatus()) && areAllGSIsActive;
        } catch (BackendNotFoundException e) {
            successFlag = false;
        }

        if (!successFlag) {
            interruptibleSleep(CONTROL_PLANE_RETRY_DELAY_MS);
        }
        retryCount++;
    }
    if (!successFlag) {
        throw new PermanentBackendException(
                "Table creation not completed for table " + tableName + " after retrying " + this.maxRetries
                        + " times for a duration of " + CONTROL_PLANE_RETRY_DELAY_MS * this.maxRetries + " ms");
    }
}

From source file:au.org.ala.delta.key.Key.java

private boolean checkPresetCharacter(Character presetCharacter, Specimen specimen, List<Item> includedItems) {
    // Preset characters must be multistate
    if (!(presetCharacter instanceof MultiStateCharacter)) {
        return false;
    }/*  w ww . j  a v a2  s.c om*/

    // Used characters or ones that have been made inapplicable cannot be
    // used as
    // presets
    if (specimen.getInapplicableCharacters().contains(presetCharacter)) {
        return false;
    }

    if (specimen.getUsedCharacters().contains(presetCharacter)) {
        return false;
    }

    // A preset character cannot completely eliminate any of the available
    // taxa. Each taxon must be
    // available after at least one of the character states is used in the
    // specimen
    Set<Item> availableTaxa = getSpecimenAvailableTaxa(specimen, includedItems);
    Set<Item> availableTaxaAfterPresetUsed = new HashSet<Item>();

    MultiStateCharacter msPreset = (MultiStateCharacter) presetCharacter;
    for (int i = 0; i < msPreset.getNumberOfStates(); i++) {
        int stateNumber = i + 1;
        MultiStateAttribute attr = createMultiStateAttribute(msPreset, stateNumber);
        specimen.setAttributeForCharacter(msPreset, attr);
        availableTaxaAfterPresetUsed.addAll(getSpecimenAvailableTaxa(specimen, includedItems));
        specimen.removeValueForCharacter(msPreset);
    }

    return availableTaxaAfterPresetUsed.equals(availableTaxa);
}

From source file:com.tesora.dve.tools.aitemplatebuilder.AiTemplateBuilder.java

public static MultiMap<RedistCause, Object> getRedistOperations(final TableStats table,
        final Set<JoinStats> joins, final Set<? extends TemplateRangeItem> availableRanges) {
    final MultiMap<RedistCause, Object> operations = new MultiMap<RedistCause, Object>();
    final TemplateModelItem model = table.getTableDistributionModel();
    if (!model.isBroadcast()) {
        final TemplateRangeItem range = findRangeForTable(availableRanges, table);
        final Set<TableColumn> dv = (range != null) ? range.getRangeColumnsFor(table) : Collections.EMPTY_SET;

        if (table.hasStatements(StatementType.ORDERBY)) {
            operations.put(RedistCause.ORDER_BY, table.getStatementCounts(StatementType.ORDERBY));
        }//www.ja  v  a  2 s . co m

        if (table.hasStatements(StatementType.UPDATE)) {
            final Map<TableColumn, Long> updateColumns = table.getUpdateColumns();
            for (final Entry<TableColumn, Long> entry : updateColumns.entrySet()) {
                final TableColumn column = entry.getKey();
                if (column.isPrimary() || column.isUnique()) {
                    operations.put(RedistCause.UNIQUE_UPDATE, entry);
                } else if (!dv.isEmpty() && dv.contains(column)) {
                    operations.put(RedistCause.DV_UPDATE, entry);
                }
            }
        }

        if (table.hasStatements(StatementType.JOIN)) {
            for (final JoinStats join : CorpusStats.findJoinsForTable(joins, table)) {
                if ((model instanceof Random)
                        || (isRangeToRangeRelationship(join) || isJoinToBroadcastAndRequiresRedist(join))) {
                    if (dv.isEmpty() || (table.equals(join.getLHS()) && !dv.equals(join.getLeftColumns()))
                            || (table.equals(join.getRHS()) && !dv.equals(join.getRightColumns()))) {
                        operations.put(RedistCause.NON_COLLOCATED_JOIN, join);
                    }
                }
            }
        }
    }

    return operations;
}

From source file:org.forgerock.restlet.ext.oauth2.flow.AuthorizeServerResource.java

protected boolean savedConsent(String userid, String clientId, Set<String> scopes) {
    OAuth2ProviderSettings settings = OAuth2Utils.getSettingsProvider(getRequest());
    String attribute = settings.getSharedConsentAttributeName();

    AMIdentity id = OAuth2Utils.getIdentity(userid, OAuth2Utils.getRealm(getRequest()));
    Set<String> attributeSet = null;

    if (id != null) {
        try {/*  w  w  w. j a  v  a  2  s  .  co m*/
            attributeSet = id.getAttribute(attribute);
        } catch (Exception e) {
            OAuth2Utils.DEBUG.error("AuthorizeServerResource.saveConsent(): Unable to get profile attribute",
                    e);
            return false;
        }
    }

    //check the values of the attribute set vs the scope and client requested
    //attribute set is in the form of client_id|scope1 scope2 scope3
    for (String consent : attributeSet) {
        int loc = consent.indexOf(" ");
        String consentClientId = consent.substring(0, loc);
        String[] scopesArray = null;
        if (loc + 1 < consent.length()) {
            scopesArray = consent.substring(loc + 1, consent.length()).split(" ");
        }
        Set<String> consentScopes = null;
        if (scopesArray != null && scopesArray.length > 0) {
            consentScopes = new HashSet<String>(Arrays.asList(scopesArray));
        } else {
            consentScopes = new HashSet<String>();
        }

        //if both the client and the scopes are identical to the saved consent then approve
        if (clientId.equals(consentClientId) && scopes.equals(consentScopes)) {
            return true;
        }
    }

    return false;
}

From source file:com.gzj.tulip.jade.rowmapper.BeanPropertyRowMapper.java

/**
 * Extract the values for all columns in the current row.
 * <p>/*w w w .j a  v a  2s. com*/
 * Utilizes public setters and result set metadata.
 * 
 * @see java.sql.ResultSetMetaData
 */
public Object mapRow(ResultSet rs, int rowNumber) throws SQLException {
    // spring's : Object mappedObject = BeanUtils.instantiateClass(this.mappedClass);
    // jade's : private Object instantiateClass(this.mappedClass);
    // why: ??mappedClass.newInstranceBeanUtils.instantiateClass(mappedClass)1?
    Object mappedObject = instantiateClass(this.mappedClass);
    BeanWrapper bw = new BeanWrapperImpl(mappedObject);

    ResultSetMetaData rsmd = rs.getMetaData();
    int columnCount = rsmd.getColumnCount();

    boolean warnEnabled = logger.isWarnEnabled();
    boolean debugEnabled = logger.isDebugEnabled();
    Set<String> populatedProperties = (checkProperties ? new HashSet<String>() : null);

    for (int index = 1; index <= columnCount; index++) {
        String column = JdbcUtils.lookupColumnName(rsmd, index).toLowerCase();
        PropertyDescriptor pd = this.mappedFields.get(column);
        if (pd != null) {
            try {
                Object value = JdbcUtils.getResultSetValue(rs, index, pd.getPropertyType());
                if (debugEnabled && rowNumber == 0) {
                    logger.debug("Mapping column '" + column + "' to property '" + pd.getName() + "' of type "
                            + pd.getPropertyType());
                }
                bw.setPropertyValue(pd.getName(), value);
                if (populatedProperties != null) {
                    populatedProperties.add(pd.getName());
                }
            } catch (NotWritablePropertyException ex) {
                throw new DataRetrievalFailureException(
                        "Unable to map column " + column + " to property " + pd.getName(), ex);
            }
        } else {
            if (checkColumns) {
                throw new InvalidDataAccessApiUsageException("Unable to map column '" + column
                        + "' to any properties of bean " + this.mappedClass.getName());
            }
            if (warnEnabled && rowNumber == 0) {
                logger.warn("Unable to map column '" + column + "' to any properties of bean "
                        + this.mappedClass.getName());
            }
        }
    }

    if (populatedProperties != null && !populatedProperties.equals(this.mappedProperties)) {
        throw new InvalidDataAccessApiUsageException("Given ResultSet does not contain all fields "
                + "necessary to populate object of class [" + this.mappedClass + "]: " + this.mappedProperties);
    }

    return mappedObject;
}

From source file:com.sinosoft.one.data.jade.rowmapper.BeanPropertyRowMapper.java

/**
 * Extract the values for all columns in the current row.
 * <p>/*from   w  ww.  java 2  s . com*/
 * Utilizes public setters and result set metadata.
 * 
 * @see java.sql.ResultSetMetaData
 */
public Object mapRow(ResultSet rs, int rowNumber) throws SQLException {
    // spring's : Object mappedObject = BeanUtils.instantiateClass(this.mappedClass);
    // jade's : private Object instantiateClass(this.mappedClass);
    // why: ??mappedClass.newInstranceBeanUtils.instantiateClass(mappedClass)1?
    Object mappedObject = instantiateClass(this.mappedClass);
    BeanWrapper bw = new BeanWrapperImpl(mappedObject);
    bw.setConversionService(this.conversionService);
    ResultSetMetaData rsmd = rs.getMetaData();
    int columnCount = rsmd.getColumnCount();

    boolean warnEnabled = logger.isWarnEnabled();
    boolean debugEnabled = logger.isDebugEnabled();
    Set<String> populatedProperties = (checkProperties ? new HashSet<String>() : null);

    for (int index = 1; index <= columnCount; index++) {
        String column = JdbcUtils.lookupColumnName(rsmd, index).toLowerCase();
        PropertyDescriptor pd = this.mappedFields.get(column);
        if (pd != null) {
            try {
                Object value = JdbcUtils.getResultSetValue(rs, index, pd.getPropertyType());
                if (debugEnabled && rowNumber == 0) {
                    logger.debug("Mapping column '" + column + "' to property '" + pd.getName() + "' of type "
                            + pd.getPropertyType());
                }
                bw.setPropertyValue(pd.getName(), value);
                if (populatedProperties != null) {
                    populatedProperties.add(pd.getName());
                }
            } catch (NotWritablePropertyException ex) {
                throw new DataRetrievalFailureException(
                        "Unable to map column " + column + " to property " + pd.getName(), ex);
            }
        } else {
            if (checkColumns) {
                throw new InvalidDataAccessApiUsageException("Unable to map column '" + column
                        + "' to any properties of bean " + this.mappedClass.getName());
            }
            if (warnEnabled && rowNumber == 0) {
                logger.warn("Unable to map column '" + column + "' to any properties of bean "
                        + this.mappedClass.getName());
            }
        }
    }

    if (populatedProperties != null && !populatedProperties.equals(this.mappedProperties)) {
        throw new InvalidDataAccessApiUsageException("Given ResultSet does not contain all fields "
                + "necessary to populate object of class [" + this.mappedClass + "]: " + this.mappedProperties);
    }

    return mappedObject;
}

From source file:org.voltdb.planner.ParsedSelectStmt.java

boolean groupByIsAnOrderByPermutation() {
    if (m_groupAndOrderByPermutationWasTested) {
        return m_groupAndOrderByPermutationResult;
    }//from   w w w  .ja  va2 s .c om
    m_groupAndOrderByPermutationWasTested = true;

    int size = m_groupByColumns.size();
    if (size != m_orderColumns.size()) {
        return false;
    }
    Set<AbstractExpression> orderPrefixExprs = new HashSet<>(size);
    Set<AbstractExpression> groupExprs = new HashSet<>(size);
    int ii = 0;
    for (ParsedColInfo gb : m_groupByColumns) {
        AbstractExpression gexpr = gb.expression;
        if (gb.expression == null) {
            return false;
        }
        AbstractExpression oexpr = m_orderColumns.get(ii).expression;
        ++ii;
        // Save some cycles in the common case of matching by position.
        if (gb.expression.equals(oexpr)) {
            continue;
        }
        groupExprs.add(gexpr);
        orderPrefixExprs.add(oexpr);
    }
    m_groupAndOrderByPermutationResult = groupExprs.equals(orderPrefixExprs);
    return m_groupAndOrderByPermutationResult;
}

From source file:com.gs.collections.impl.test.Verify.java

public static void assertSetsEqual(String setName, Set<?> expectedSet, Set<?> actualSet) {
    try {/*from w  w w  .ja va2s .c  o  m*/
        if (expectedSet == null) {
            Assert.assertNull(setName + " should be null", actualSet);
            return;
        }

        Verify.assertObjectNotNull(setName, actualSet);
        Verify.assertSize(setName, expectedSet.size(), actualSet);

        if (!actualSet.equals(expectedSet)) {
            MutableSet<?> inExpectedOnlySet = UnifiedSet.newSet(expectedSet);
            inExpectedOnlySet.removeAll(actualSet);

            int numberDifferences = inExpectedOnlySet.size();
            String message = setName + ": " + numberDifferences + " elements different.";

            if (numberDifferences > MAX_DIFFERENCES) {
                Assert.fail(message);
            }

            MutableSet<?> inActualOnlySet = UnifiedSet.newSet(actualSet);
            inActualOnlySet.removeAll(expectedSet);

            //noinspection UseOfObsoleteAssert
            junit.framework.Assert.failNotEquals(message, inExpectedOnlySet, inActualOnlySet);
        }
    } catch (AssertionError e) {
        Verify.throwMangledException(e);
    }
}

From source file:com.mx.core.dao.BeanPropRowMap.java

/**
 * Extract the values for all columns in the current row.
 * <p>Utilizes public setters and result set metadata.
 * @see java.sql.ResultSetMetaData/*from   ww  w  .j av  a  2  s .com*/
 */
public T mapRow(ResultSet rs, int rowNumber) throws SQLException {
    Assert.state(this.mappedClass != null, "Mapped class was not specified");
    T mappedObject = BeanUtils.instantiate(this.mappedClass);
    BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(mappedObject);
    initBeanWrapper(bw);

    ResultSetMetaData rsmd = rs.getMetaData();
    int columnCount = rsmd.getColumnCount();
    Set<String> populatedProperties = (isCheckFullyPopulated() ? new HashSet<String>() : null);

    for (int index = 1; index <= columnCount; index++) {
        String column = JdbcUtils.lookupColumnName(rsmd, index);
        PropertyDescriptor pd = this.mappedFields.get(column.replaceAll(" ", "").toLowerCase());
        if (pd != null) {
            try {
                Object value = getColumnValue(rs, index, pd);
                if (logger.isDebugEnabled() && rowNumber == 0) {
                    //logger.debug("Mapping column '" + column + "' to property '" +
                    //      pd.getName() + "' of type " + pd.getPropertyType());
                }
                try {
                    bw.setPropertyValue(pd.getName(), value);
                } catch (TypeMismatchException e) {
                    if (value == null && primitivesDefaultedForNullValue) {
                        logger.debug("Intercepted TypeMismatchException for row " + rowNumber + " and column '"
                                + column + "' with value " + value + " when setting property '" + pd.getName()
                                + "' of type " + pd.getPropertyType() + " on object: " + mappedObject);
                    } else {
                        throw e;
                    }
                }
                if (populatedProperties != null) {
                    populatedProperties.add(pd.getName());
                }
            } catch (NotWritablePropertyException ex) {
                throw new DataRetrievalFailureException(
                        "Unable to map column " + column + " to property " + pd.getName(), ex);
            }
        }
    }

    if (populatedProperties != null && !populatedProperties.equals(this.mappedProperties)) {
        throw new InvalidDataAccessApiUsageException("Given ResultSet does not contain all fields "
                + "necessary to populate object of class [" + this.mappedClass + "]: " + this.mappedProperties);
    }

    return mappedObject;
}