Example usage for java.util Set toArray

List of usage examples for java.util Set toArray

Introduction

In this page you can find the example usage for java.util Set toArray.

Prototype

<T> T[] toArray(T[] a);

Source Link

Document

Returns an array containing all of the elements in this set; the runtime type of the returned array is that of the specified array.

Usage

From source file:edu.wisc.my.stats.dao.support.ConsolidatingQueryInformationDao.java

/**
 * @see edu.wisc.my.stats.dao.QueryInformationDao#getQueryInformationByFactMap()
 */// ww w . ja v  a2 s  .co  m
@SuppressWarnings("unchecked")
public Map<Fact, Set<QueryInformation>> getQueryInformationByFactMap() {
    final Set<Map<Fact, Set<QueryInformation>>> queryInformationByFactMaps = new HashSet<Map<Fact, Set<QueryInformation>>>();

    for (final QueryInformationDao queryInformationDao : this.readableQueryInformationDaos) {
        final Map<Fact, Set<QueryInformation>> queryInformationByFactMap = queryInformationDao
                .getQueryInformationByFactMap();
        queryInformationByFactMaps.add(queryInformationByFactMap);
    }

    final CompositeMap cm = new CompositeMap(
            queryInformationByFactMaps.toArray(new Map[queryInformationByFactMaps.size()]));
    return Collections.unmodifiableMap(cm); //will this work?
}

From source file:com.blogspot.chicchiricco.persistence.AbstractBaseBean.java

/**
 * @return fields to be excluded when computing equals() or hashcode()
 *//* ww  w  .  j a v  a  2  s .co  m*/
private String[] getExcludeFields() {
    Set<String> excludeFields = new HashSet<String>();

    PropertyDescriptor[] propertyDescriptors = BeanUtils.getPropertyDescriptors(getClass());
    for (int i = 0; i < propertyDescriptors.length; i++) {

        if (propertyDescriptors[i].getPropertyType().isInstance(Collections.EMPTY_SET)
                || propertyDescriptors[i].getPropertyType().isInstance(Collections.EMPTY_LIST)) {

            excludeFields.add(propertyDescriptors[i].getName());
        }
    }

    return excludeFields.toArray(new String[] {});
}

From source file:com.opengamma.analytics.financial.interestrate.swaption.method.SwaptionPhysicalFixedIborSABRLMMAtBestMethod.java

public PresentValueSABRSensitivityDataBundle presentValueSABRSensitivity(
        final SwaptionPhysicalFixedIbor swaption, final SABRInterestRateDataBundle curves) {
    Validate.notNull(swaption);//from   ww  w  .  j  a v a  2s.  c o m
    Validate.notNull(curves);
    final int nbStrikes = _strikeMoneyness.length;
    final LiborMarketModelDisplacedDiffusionParameters lmmParameters = _parametersInit.copy();
    final SwaptionPhysicalLMMDDSuccessiveLeastSquareCalibrationObjective objective = new SwaptionPhysicalLMMDDSuccessiveLeastSquareCalibrationObjective(
            lmmParameters);
    final SwaptionPhysicalLMMDDSuccessiveLeastSquareCalibrationEngine calibrationEngine = new SwaptionPhysicalLMMDDSuccessiveLeastSquareCalibrationEngine(
            objective, nbStrikes);
    final SwaptionPhysicalFixedIbor[] swaptionCalibration = METHOD_BASKET
            .calibrationBasketFixedLegPeriod(swaption, _strikeMoneyness);
    calibrationEngine.addInstrument(swaptionCalibration, METHOD_SWAPTION_SABR);
    calibrationEngine.calibrate(curves);
    final LiborMarketModelDisplacedDiffusionDataBundle lmmBundle = new LiborMarketModelDisplacedDiffusionDataBundle(
            lmmParameters, curves);

    final int nbCalibrations = swaptionCalibration.length;
    final int nbPeriods = nbCalibrations / nbStrikes;
    final int nbFact = lmmParameters.getNbFactor();
    final List<Integer> instrumentIndex = calibrationEngine.getInstrumentIndex();
    final double[] dPvdPhi = new double[2 * nbPeriods];
    // Implementation note: Derivative of the priced swaptions wrt the calibration parameters (multiplicative factor and additive term)
    // Implementation note: Phi is a vector with the multiplicative factors on the volatility and then the additive terms on the displacements.
    final double[][] dPvdGamma = METHOD_SWAPTION_LMM.presentValueLMMSensitivity(swaption, lmmBundle);
    final double[] dPvdDis = METHOD_SWAPTION_LMM.presentValueDDSensitivity(swaption, lmmBundle);
    for (int loopperiod = 0; loopperiod < nbPeriods; loopperiod++) {
        for (int loopsub = instrumentIndex.get(loopperiod * nbStrikes); loopsub < instrumentIndex
                .get((loopperiod + 1) * nbStrikes); loopsub++) {
            for (int loopfact = 0; loopfact < nbFact; loopfact++) {
                dPvdPhi[loopperiod] += dPvdGamma[loopsub][loopfact]
                        * lmmParameters.getVolatility()[loopsub][loopfact];
                dPvdPhi[nbPeriods + loopperiod] += dPvdDis[loopsub];
            }
        }
    }

    final double[][] dPvCaldPhi = new double[nbCalibrations][2 * nbPeriods];
    // Implementation note: Derivative of the calibration swaptions wrt the calibration parameters (multiplicative factor and additive term)
    final double[][][] dPvCaldGamma = new double[nbCalibrations][][];
    for (int loopcal = 0; loopcal < nbCalibrations; loopcal++) {
        dPvCaldGamma[loopcal] = METHOD_SWAPTION_LMM.presentValueLMMSensitivity(swaptionCalibration[loopcal],
                lmmBundle);
    }
    final double[][] dPvCaldDis = new double[nbCalibrations][];
    for (int loopcal = 0; loopcal < nbCalibrations; loopcal++) {
        dPvCaldDis[loopcal] = METHOD_SWAPTION_LMM.presentValueDDSensitivity(swaptionCalibration[loopcal],
                lmmBundle);
    }
    for (int loopcal = 0; loopcal < nbCalibrations; loopcal++) {
        for (int loopperiod = 0; loopperiod < nbPeriods; loopperiod++) {
            for (int loopsub = instrumentIndex.get(loopperiod * nbStrikes); loopsub < instrumentIndex
                    .get((loopperiod + 1) * nbStrikes); loopsub++) {
                for (int loopfact = 0; loopfact < nbFact; loopfact++) {
                    dPvCaldPhi[loopcal][loopperiod] += dPvCaldGamma[loopcal][loopsub][loopfact]
                            * lmmParameters.getVolatility()[loopsub][loopfact];
                    dPvCaldPhi[loopcal][nbPeriods + loopperiod] += dPvCaldDis[loopcal][loopsub];
                }
            }
        }
    }

    final double[][] dPvCaldTheta = new double[nbCalibrations][3 * nbPeriods];
    // Implementation note: Derivative of the calibration swaptions wrt the SABR parameters as a unique array.
    // Implementation note: Theta is vector with first the Alpha, the the Rho and finally the Nu.
    for (int loopperiod = 0; loopperiod < nbPeriods; loopperiod++) {
        for (int loopstrike = 0; loopstrike < nbStrikes; loopstrike++) {
            final PresentValueSABRSensitivityDataBundle dPvCaldSABR = METHOD_SWAPTION_SABR
                    .presentValueSABRSensitivity(swaptionCalibration[loopperiod * nbStrikes + loopstrike],
                            curves);
            final Set<DoublesPair> keySet = dPvCaldSABR.getAlpha().getMap().keySet();
            final DoublesPair[] keys = keySet.toArray(new DoublesPair[keySet.size()]);
            dPvCaldTheta[loopperiod * nbStrikes + loopstrike][loopperiod] += dPvCaldSABR.getAlpha().getMap()
                    .get(keys[0]);
            dPvCaldTheta[loopperiod * nbStrikes + loopstrike][nbPeriods + loopperiod] = dPvCaldSABR.getRho()
                    .getMap().get(keys[0]);
            dPvCaldTheta[loopperiod * nbStrikes + loopstrike][2 * nbPeriods + loopperiod] = dPvCaldSABR.getNu()
                    .getMap().get(keys[0]);
        }
    }

    final double[][] dfdTheta = new double[2 * nbPeriods][3 * nbPeriods];
    // Implementation note: Derivative of f wrt the SABR parameters.
    for (int loopp = 0; loopp < 2 * nbPeriods; loopp++) {
        for (int loops = 0; loops < 3 * nbPeriods; loops++) {
            for (int loopcal = 0; loopcal < nbCalibrations; loopcal++) {
                dfdTheta[loopp][loops] += -2 * dPvCaldPhi[loopcal][loopp] * dPvCaldTheta[loopcal][loops];
            }
        }
    }
    final double[][] dfdPhi = new double[2 * nbPeriods][2 * nbPeriods];
    // Implementation note: Derivative of f wrt the calibration parameters. This is an approximation: the second order derivative part are ignored.
    for (int loopp1 = 0; loopp1 < 2 * nbPeriods; loopp1++) {
        for (int loopp2 = 0; loopp2 < 2 * nbPeriods; loopp2++) {
            for (int loopcal = 0; loopcal < nbCalibrations; loopcal++) {
                dfdPhi[loopp1][loopp2] += 2 * dPvCaldPhi[loopcal][loopp1] * dPvCaldPhi[loopcal][loopp2];
            }
        }
    }

    final DoubleMatrix2D dfdThetaMat = new DoubleMatrix2D(dfdTheta);
    final DoubleMatrix2D dfdPhiMat = new DoubleMatrix2D(dfdPhi);
    final DoubleMatrix2D dPhidThetaMat = (DoubleMatrix2D) ALGEBRA
            .scale(ALGEBRA.multiply(ALGEBRA.getInverse(dfdPhiMat), dfdThetaMat), -1.0);
    final DoubleMatrix1D dPvdPhiMat = new DoubleMatrix1D(dPvdPhi);
    final DoubleMatrix2D dPvdThetaMat = ALGEBRA
            .getTranspose(ALGEBRA.multiply(ALGEBRA.getTranspose(dPhidThetaMat), dPvdPhiMat));
    final double[] dPvdTheta = dPvdThetaMat.getData()[0];

    // Storage in PresentValueSABRSensitivityDataBundle
    final PresentValueSABRSensitivityDataBundle sensi = new PresentValueSABRSensitivityDataBundle();
    for (int loopp = 0; loopp < nbPeriods; loopp++) {
        final DoublesPair expiryMaturity = new DoublesPair(
                swaptionCalibration[loopp * nbStrikes].getTimeToExpiry(),
                swaptionCalibration[loopp * nbStrikes].getMaturityTime());
        sensi.addAlpha(expiryMaturity, dPvdTheta[loopp]);
        sensi.addRho(expiryMaturity, dPvdTheta[nbPeriods + loopp]);
        sensi.addNu(expiryMaturity, dPvdTheta[2 * nbPeriods + loopp]);
    }
    return sensi;
}

From source file:edu.uci.ics.asterix.tools.external.data.GenericSocketFeedAdapterFactory.java

private void configureSockets(Map<String, String> configuration) throws Exception {
    sockets = new ArrayList<Pair<String, Integer>>();
    String modeValue = configuration.get(KEY_MODE);
    if (modeValue != null) {
        mode = Mode.valueOf(modeValue.trim().toUpperCase());
    }//from   ww w .  j  a  v  a  2  s.c  o m
    String socketsValue = configuration.get(KEY_SOCKETS);
    if (socketsValue == null) {
        throw new IllegalArgumentException(
                "\'sockets\' parameter not specified as part of adapter configuration");
    }
    Map<InetAddress, Set<String>> ncMap = AsterixRuntimeUtil.getNodeControllerMap();
    List<String> ncs = AsterixRuntimeUtil.getAllNodeControllers();
    String[] socketsArray = socketsValue.split(",");
    Random random = new Random();
    for (String socket : socketsArray) {
        String[] socketTokens = socket.split(":");
        String host = socketTokens[0].trim();
        int port = Integer.parseInt(socketTokens[1].trim());
        Pair<String, Integer> p = null;
        switch (mode) {
        case IP:
            Set<String> ncsOnIp = ncMap.get(InetAddress.getByName(host));
            if (ncsOnIp == null || ncsOnIp.isEmpty()) {
                throw new IllegalArgumentException("Invalid host " + host
                        + " as it is not part of the AsterixDB cluster. Valid choices are "
                        + StringUtils.join(ncMap.keySet(), ", "));
            }
            String[] ncArray = ncsOnIp.toArray(new String[] {});
            String nc = ncArray[random.nextInt(ncArray.length)];
            p = new Pair<String, Integer>(nc, port);
            break;

        case NC:
            p = new Pair<String, Integer>(host, port);
            if (!ncs.contains(host)) {
                throw new IllegalArgumentException(
                        "Invalid NC " + host + " as it is not part of the AsterixDB cluster. Valid choices are "
                                + StringUtils.join(ncs, ", "));

            }
            break;
        }
        sockets.add(p);
    }
}

From source file:hoot.services.controllers.osm.OSMTestUtils.java

private static void verifyTestRelationsUnmodified(Set<Long> relationIds, Set<Long> wayIds, Set<Long> nodeIds,
        long changesetId, boolean verifyTags) {
    Long[] relationIdsArr = relationIds.toArray(new Long[relationIds.size()]);
    Long[] nodeIdsArr = nodeIds.toArray(new Long[nodeIds.size()]);
    Long[] wayIdsArr = wayIds.toArray(new Long[wayIds.size()]);
    Map<Long, CurrentRelations> relations = createQuery(getMapId()).from(currentRelations)
            .where((currentRelations.changesetId.eq(changesetId)))
            .transform(groupBy(currentRelations.id).as(currentRelations));

    assertEquals(4, relations.size());//from  w  w  w .  ja va2s . c om

    CurrentRelations relationRecord = relations.get(relationIdsArr[0]);
    assertEquals(new Long(changesetId), relationRecord.getChangesetId());
    assertEquals(relationIdsArr[0], relationRecord.getId());
    assertEquals(new Long(1), relationRecord.getVersion());

    List<CurrentRelationMembers> relationMembers = createQuery(getMapId()).select(currentRelationMembers)
            .from(currentRelationMembers).where(currentRelationMembers.relationId.eq(relationIdsArr[0]))
            .orderBy(currentRelationMembers.sequenceId.asc()).fetch();

    assertEquals(4, relationMembers.size());
    CurrentRelationMembers member = relationMembers.get(0);
    assertEquals(relationRecord.getId(), member.getRelationId());
    assertEquals(DbUtils.nwr_enum.node, member.getMemberType());
    assertEquals("role1", member.getMemberRole());
    assertEquals(new Integer(1), member.getSequenceId());

    assertEquals(nodeIdsArr[0], member.getMemberId());
    member = relationMembers.get(1);
    assertEquals(relationRecord.getId(), member.getRelationId());
    assertEquals(DbUtils.nwr_enum.way, member.getMemberType());
    assertEquals("role3", member.getMemberRole());
    assertEquals(new Integer(2), member.getSequenceId());

    assertEquals(wayIdsArr[1], member.getMemberId());
    member = relationMembers.get(2);
    assertEquals(relationRecord.getId(), member.getRelationId());
    assertEquals(DbUtils.nwr_enum.way, member.getMemberType());
    assertEquals("role2", member.getMemberRole());
    assertEquals(new Integer(3), member.getSequenceId());

    assertEquals(wayIdsArr[0], member.getMemberId());
    member = relationMembers.get(3);
    assertEquals(relationRecord.getId(), member.getRelationId());
    assertEquals(DbUtils.nwr_enum.node, member.getMemberType());
    assertEquals("", member.getMemberRole());
    assertEquals(new Integer(4), member.getSequenceId());

    assertEquals(nodeIdsArr[2], member.getMemberId());
    if (verifyTags) {
        Map<String, String> tags = PostgresUtils.postgresObjToHStore(relationRecord.getTags());
        assertEquals(1, tags.size());
        assertEquals("val 1", tags.get("key 1"));
    }

    relationRecord = relations.get(relationIdsArr[1]);
    assertEquals(new Long(changesetId), relationRecord.getChangesetId());
    assertEquals(relationIdsArr[1], relationRecord.getId());
    assertEquals(new Long(1), relationRecord.getVersion());

    relationMembers = createQuery(getMapId()).select(currentRelationMembers).from(currentRelationMembers)
            .where(currentRelationMembers.relationId.eq(relationIdsArr[1]))
            .orderBy(currentRelationMembers.sequenceId.asc()).fetch();

    assertEquals(2, relationMembers.size());
    member = relationMembers.get(0);
    assertEquals(relationRecord.getId(), member.getRelationId());
    assertEquals(DbUtils.nwr_enum.node, member.getMemberType());
    assertEquals("role1", member.getMemberRole());
    assertEquals(new Integer(1), member.getSequenceId());

    assertEquals(nodeIdsArr[4], member.getMemberId());
    member = relationMembers.get(1);
    assertEquals(relationRecord.getId(), member.getRelationId());
    assertEquals(DbUtils.nwr_enum.relation, member.getMemberType());
    assertEquals("role1", member.getMemberRole());
    assertEquals(new Integer(2), member.getSequenceId());

    assertEquals(relationIdsArr[0], member.getMemberId());
    if (verifyTags) {
        Map<String, String> tags = PostgresUtils.postgresObjToHStore(relationRecord.getTags());
        assertEquals(2, tags.size());
        assertEquals("val 2", tags.get("key 2"));
        assertEquals("val 3", tags.get("key 3"));
    }

    relationRecord = relations.get(relationIdsArr[2]);
    assertEquals(new Long(changesetId), relationRecord.getChangesetId());
    assertEquals(relationIdsArr[2], relationRecord.getId());
    assertEquals(new Long(1), relationRecord.getVersion());

    relationMembers = createQuery(getMapId()).select(currentRelationMembers).from(currentRelationMembers)
            .where(currentRelationMembers.relationId.eq(relationIdsArr[2]))
            .orderBy(currentRelationMembers.sequenceId.asc()).fetch();

    assertEquals(1, relationMembers.size());
    member = relationMembers.get(0);
    assertEquals(relationRecord.getId(), member.getRelationId());
    assertEquals(DbUtils.nwr_enum.way, member.getMemberType());
    assertEquals("", member.getMemberRole());
    assertEquals(new Integer(1), member.getSequenceId());

    assertEquals(wayIdsArr[1], member.getMemberId());
    if (verifyTags) {
        Map<String, String> tags = PostgresUtils.postgresObjToHStore(relationRecord.getTags());
        assertEquals(1, tags.size());
        assertEquals("val 4", tags.get("key 4"));
    }

    relationRecord = relations.get(relationIdsArr[3]);
    assertEquals(new Long(changesetId), relationRecord.getChangesetId());
    assertEquals(relationIdsArr[3], relationRecord.getId());
    assertEquals(new Long(1), relationRecord.getVersion());

    relationMembers = createQuery(getMapId()).select(currentRelationMembers).from(currentRelationMembers)
            .where(currentRelationMembers.relationId.eq(relationIdsArr[3]))
            .orderBy(currentRelationMembers.sequenceId.asc()).fetch();

    assertEquals(1, relationMembers.size());
    member = relationMembers.get(0);
    assertEquals(relationRecord.getId(), member.getRelationId());
    assertEquals(DbUtils.nwr_enum.node, member.getMemberType());
    assertEquals("role1", member.getMemberRole());
    assertEquals(new Integer(1), member.getSequenceId());

    assertEquals(nodeIdsArr[2], member.getMemberId());
    if (verifyTags) {
        assertTrue((relationRecord.getTags() == null)
                || PostgresUtils.postgresObjToHStore(relationRecord.getTags()).isEmpty());
    }
}

From source file:org.esa.beam.timeseries.ui.graph.TimeSeriesGraphModel.java

private String[] getAliasNames() {
    final Set<String> aliasNamesSet = displayAxisMapping.getAliasNames();
    return aliasNamesSet.toArray(new String[aliasNamesSet.size()]);
}

From source file:grails.plugin.cache.redis.GrailsRedisCache.java

@SuppressWarnings("unchecked")
@Override/* w ww.  j  av a 2 s.c o  m*/
public void clear() {
    // need to del each key individually
    template.execute(new RedisCallback<Object>() {
        public Object doInRedis(RedisConnection connection) throws DataAccessException {
            // another clear is on-going
            if (connection.exists(cacheLockName)) {
                return null;
            }

            try {
                connection.set(cacheLockName, cacheLockName);

                int offset = 0;
                boolean finished = false;

                do {
                    // need to paginate the keys
                    Set<byte[]> keys = connection.zRange(setName, (offset) * PAGE_SIZE,
                            (offset + 1) * PAGE_SIZE - 1);
                    finished = keys.size() < PAGE_SIZE;
                    offset++;
                    if (!keys.isEmpty()) {
                        connection.del(keys.toArray(new byte[keys.size()][]));
                    }
                } while (!finished);

                connection.del(setName);
                return null;

            } finally {
                connection.del(cacheLockName);
            }
        }
    }, true);
}

From source file:org.obiba.onyx.spring.context.OnyxMessageSourceFactoryBean.java

public Object getObject() throws Exception {
    ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
    messageSource.setResourceLoader(resourceLoader);

    Set<String> basenames = new TreeSet<String>();
    if (this.resourceLoader instanceof ResourcePatternResolver) {
        findBasenames(basenames, onyxConfigPath, MESSAGES_PROPERTIES_SUFFIX);
        findBasenames(basenames, onyxConfigPath, MESSAGES_XML_SUFFIX);
    }/*from w w w .  jav  a 2s. c  o  m*/
    if (extraBasenames != null) {
        basenames.addAll(extraBasenames);
    }
    String[] basenamesArray = basenames.toArray(new String[] {});
    log.debug("MessageSource contains the following basenames: {}", Arrays.toString(basenamesArray));
    messageSource.setBasenames(basenamesArray);

    MessageSource moduleMessageSource = loadJarBundles();
    messageSource.setParentMessageSource(moduleMessageSource);

    return new StringReferenceFormatingMessageSource(messageSource);
}

From source file:org.apache.syncope.core.persistence.beans.AbstractBaseBean.java

/**
 * @return fields to be excluded when computing equals() or hashcode()
 *///from   ww w  . ja  va  2s .co m
private String[] getExcludeFields() {
    Set<String> excludeFields = new HashSet<String>();

    PropertyDescriptor[] propertyDescriptors = BeanUtils.getPropertyDescriptors(getClass());
    for (int i = 0; i < propertyDescriptors.length; i++) {

        if (propertyDescriptors[i].getPropertyType().isInstance(Collections.emptySet())
                || propertyDescriptors[i].getPropertyType().isInstance(Collections.emptyList())) {

            excludeFields.add(propertyDescriptors[i].getName());
        }
    }

    return excludeFields.toArray(new String[] {});
}

From source file:springfox.documentation.spring.data.rest.EntitySearchRequestHandler.java

@Override
public PatternsRequestCondition getPatternsCondition() {
    Set<String> patterns = newHashSet();
    for (String each : requestMapping.getPatternsCondition().getPatterns()) {
        String replaced = each.replace("/{repository}", resource.getPath().toString()).replace("/{search}",
                searchResource.getPath().toString());
        patterns.add(replaced);/*from ww  w  .ja v a 2  s.  co m*/
    }
    return new PatternsRequestCondition(patterns.toArray(new String[patterns.size()]));
}