Example usage for java.util SortedMap putAll

List of usage examples for java.util SortedMap putAll

Introduction

In this page you can find the example usage for java.util SortedMap putAll.

Prototype

void putAll(Map<? extends K, ? extends V> m);

Source Link

Document

Copies all of the mappings from the specified map to this map (optional operation).

Usage

From source file:com.xpn.xwiki.store.migration.AbstractXWikiMigrationManager.java

/**
 * @return collection of {@link XWikiMigratorInterface} in ascending order, which need be executed.
 * @param context used everywhere/*from  w  w w  .  j ava 2  s . c  o m*/
 * @throws Exception if any error
 */
protected Collection getNeededMigrations(XWikiContext context) throws Exception {
    XWikiDBVersion curversion = getDBVersion(context);
    SortedMap neededMigrations = new TreeMap();

    Map forcedMigrations = getForcedMigrations(context);
    if (!forcedMigrations.isEmpty()) {
        neededMigrations.putAll(forcedMigrations);
    } else {
        Set ignoredMigrations = new HashSet(Arrays
                .asList(context.getWiki().getConfig().getPropertyAsList("xwiki.store.migration.ignored")));
        List allMigrations = getAllMigrations(context);
        for (Iterator it = allMigrations.iterator(); it.hasNext();) {
            XWikiMigratorInterface migrator = (XWikiMigratorInterface) it.next();
            if (ignoredMigrations.contains(migrator.getClass().getName())
                    || ignoredMigrations.contains(migrator.getVersion().toString())) {
                continue;
            }
            if (migrator.getVersion().compareTo(curversion) >= 0) {
                XWikiMigration migration = new XWikiMigration(migrator, false);
                neededMigrations.put(migrator.getVersion(), migration);
            }
        }
    }

    Collection neededMigrationsAsCollection = neededMigrations.values();
    if (LOGGER.isInfoEnabled()) {
        if (!neededMigrations.isEmpty()) {
            LOGGER.info("Current storage version = [" + curversion.toString() + "]");
            LOGGER.info("List of migrations that will be executed:");
            for (Iterator it = neededMigrationsAsCollection.iterator(); it.hasNext();) {
                XWikiMigration migration = (XWikiMigration) it.next();
                if (migration.isForced || migration.migrator.shouldExecute(this.startupVersion)) {
                    LOGGER.info("  " + migration.migrator.getName() + " - "
                            + migration.migrator.getDescription() + (migration.isForced ? " (forced)" : ""));
                }
            }
        } else {
            LOGGER.info(
                    "No storage migration required since current version is [" + curversion.toString() + "]");
        }
    }

    return neededMigrationsAsCollection;
}

From source file:freemarker.ext.dump.DumpAllDirective.java

SortedMap<String, Object> getDataModelDump(Environment env) throws TemplateModelException {
    SortedMap<String, Object> dump = new TreeMap<String, Object>();
    TemplateHashModel dataModel = env.getDataModel();
    // Need to unwrap in order to iterate through the variables
    @SuppressWarnings("unchecked")
    Map<String, Object> unwrappedDataModel = (Map<String, Object>) DeepUnwrap.permissiveUnwrap(dataModel);
    List<String> varNames = new ArrayList<String>(unwrappedDataModel.keySet());

    for (String varName : varNames) {
        dump.putAll(getTemplateVariableDump(varName, dataModel.get(varName)));
    }// w  w  w  .ja  va  2s  .co  m

    return dump;

}

From source file:edu.utah.further.i2b2.hook.further.service.FurtherServicesImpl.java

/**
 * Adapt a query context to an i2b2 TO graph.
 * //from  w  w w. ja va2  s . com
 * @param queryContext
 *            FQC
 * @return i2b2 TO graph ready to be marshaled and inserted into an I2b2
 *         query response message
 */
@SuppressWarnings("boxing")
public I2b2FurtherQueryResultTo toI2b2FurtherQueryResultTo(final QueryContextTo queryContext) {
    boolean isMasked = false;
    long maskedRecords = 0;
    if (log.isDebugEnabled()) {
        log.debug("Converting query ID " + queryContext.getId() + " to an i2b2 TO");
    }
    final I2b2FurtherQueryResultTo queryResult = new I2b2FurtherQueryResultTo();

    // Copy DQC list to data source result list
    final List<I2b2FurtherDataSourceResult> dataSourceResults = queryResult.getDataSources();
    final int numDataSources = queryContext.getNumChildren();
    if (log.isDebugEnabled()) {
        log.debug("# data sources = " + numDataSources);
    }
    for (final QueryContext childQc : queryContext.getChildren()) {
        if (childQc.getNumRecords() > 0 && childQc.getNumRecords() <= resultMaskBoundary) {
            isMasked = true;
            maskedRecords += childQc.getNumRecords();

        }
        dataSourceResults.add(new I2b2FurtherDataSourceResult(childQc.getDataSourceId(),
                (childQc.getNumRecords() > 0 && childQc.getNumRecords() <= resultMaskBoundary
                        ? I2b2FurtherQueryResultTo.COUNT_SCRUBBED
                        : childQc.getNumRecords())));
        if (log.isDebugEnabled()) {
            log.debug("Added data source result " + childQc);
        }
    }

    // Copy result context list to join result list. Not needed if there's
    // only one
    // data source.
    if (numDataSources > 1) {
        final List<I2b2FurtherJoinResult> joinResults = queryResult.getJoins();
        final SortedMap<ResultType, ResultContext> resultViews = CollectionUtil.newSortedMap();
        resultViews.putAll(queryContext.getResultViews());
        for (final Map.Entry<ResultType, ResultContext> entry : resultViews.entrySet()) {
            final ResultContext resultContext = entry.getValue();
            joinResults.add(new I2b2FurtherJoinResult(WordUtils.capitalize(entry.getKey().name().toLowerCase()),
                    isMasked ? (entry.getKey().equals(ResultType.SUM)
                            ? resultContext.getNumRecords() - maskedRecords
                            : I2b2FurtherQueryResultTo.COUNT_SCRUBBED) : resultContext.getNumRecords()));
            if (log.isDebugEnabled()) {
                log.debug("Added join result " + resultContext);
            }
        }
    }

    if (log.isDebugEnabled()) {
        log.debug("I2b2 TO = " + queryResult);
    }
    return queryResult;
}

From source file:org.apache.cassandra.hadoop.ColumnFamilyRecordReader.java

@Override
public boolean next(ByteBuffer key, SortedMap<ByteBuffer, IColumn> value) throws IOException {
    if (this.nextKeyValue()) {
        key.clear();//  ww  w.ja  v  a 2  s . co m
        key.put(this.getCurrentKey());
        key.rewind();

        value.clear();
        value.putAll(this.getCurrentValue());

        return true;
    }
    return false;
}

From source file:org.apache.cassandra.db.index.sasi.disk.TokenTreeTest.java

@Test
public void buildWithMultipleMapsAndIterate() throws Exception {
    final SortedMap<Long, LongSet> merged = new TreeMap<>();
    final TokenTreeBuilder builder = new TokenTreeBuilder(simpleTokenMap).finish();
    builder.add(collidingTokensMap);/*from w  w  w  .  j a  va 2 s  .  c om*/

    merged.putAll(collidingTokensMap);
    for (Map.Entry<Long, LongSet> entry : simpleTokenMap.entrySet()) {
        if (merged.containsKey(entry.getKey())) {
            LongSet mergingOffsets = entry.getValue();
            LongSet existingOffsets = merged.get(entry.getKey());

            if (mergingOffsets.equals(existingOffsets))
                continue;

            Set<Long> mergeSet = new HashSet<>();
            for (LongCursor merging : mergingOffsets)
                mergeSet.add(merging.value);

            for (LongCursor existing : existingOffsets)
                mergeSet.add(existing.value);

            LongSet mergedResults = new LongOpenHashSet();
            for (Long result : mergeSet)
                mergedResults.add(result);

            merged.put(entry.getKey(), mergedResults);
        } else {
            merged.put(entry.getKey(), entry.getValue());
        }
    }

    final Iterator<Pair<Long, LongSet>> tokenIterator = builder.iterator();
    final Iterator<Map.Entry<Long, LongSet>> listIterator = merged.entrySet().iterator();
    while (tokenIterator.hasNext() && listIterator.hasNext()) {
        Pair<Long, LongSet> tokenNext = tokenIterator.next();
        Map.Entry<Long, LongSet> listNext = listIterator.next();

        Assert.assertEquals(listNext.getKey(), tokenNext.left);
        Assert.assertEquals(listNext.getValue(), tokenNext.right);
    }

    Assert.assertFalse("token iterator not finished", tokenIterator.hasNext());
    Assert.assertFalse("list iterator not finished", listIterator.hasNext());

}

From source file:com.romeikat.datamessie.core.base.util.sparsetable.SparseSingleTable.java

@Override
public synchronized SortedMap<Y, Z> getRowSorted(final X rowHeader,
        final Comparator<? super Y> columnHeaderComparator, final Comparator<? super Z> rowValueComparator) {
    final Map<Y, Z> row = rows.get(rowHeader);
    // Sort column headers by values
    final Comparator<Y> valueComparator = new MapValueKeyComparator<Y, Z>(row, columnHeaderComparator,
            rowValueComparator);//  w ww  . j a va  2 s .  c  o m
    final SortedMap<Y, Z> valuesSorted = new TreeMap<Y, Z>(valueComparator);
    valuesSorted.putAll(row);
    // Done
    return valuesSorted;
}

From source file:com.romeikat.datamessie.core.base.util.sparsetable.SparseSingleTable.java

@Override
public synchronized SortedMap<X, Z> getColumnSorted(final Y columnHeader,
        final Comparator<? super X> rowHeaderComparator, final Comparator<? super Z> columnValueComparator) {
    final Map<X, Z> column = columns.get(columnHeader);
    // Sort row headers by values
    final Comparator<X> valueComparator = new MapValueKeyComparator<X, Z>(column, rowHeaderComparator,
            columnValueComparator);//from w w  w  . j a  v  a2 s. c  om
    final SortedMap<X, Z> valuesSorted = new TreeMap<X, Z>(valueComparator);
    valuesSorted.putAll(column);
    // Done
    return valuesSorted;
}

From source file:org.jenkinsci.plugins.jenkinsreviewbot.ReviewboardOps.java

private SortedMap<String, Integer> getRepositories(String url)
        throws IOException, JAXBException, ParseException {
    ReviewboardConnection con = ReviewboardConnection.fromConfiguration();
    ensureAuthentication(con, http);/*from  w w  w. j  a  va  2s . co  m*/
    Response response = getResponse(http, url, Response.class);
    SortedMap<String, Integer> map = new TreeMap<String, Integer>(String.CASE_INSENSITIVE_ORDER);
    if (response.count > 0) {
        for (Item i : response.repositories.array) {
            map.put(i.name, i.id);
        }
        if (response.links.next != null) {
            map.putAll(getRepositories(response.links.next.href));
        }
    }
    return map;
}

From source file:org.gvnix.web.screen.roo.addon.AbstractPatternMetadataProvider.java

/**
 * Read the values of GvNIXRelationsPattern and for each field defined as
 * relation retrieve its java type details.
 * <p>/*from  ww w .  ja va  2s  .c  o m*/
 * It parses the value of the GvNIXRelationsPattern annotation.
 * GvNIXRelationsPattern example:
 * </p>
 * <code>{ "PatternName1: field1=tabular, field2=register", "PatternName2: field3=tabular_edit_register" }</code>
 * 
 * @param mid Metadata identification string
 * @param controller Controller physical type metadata
 * @param entity Entity java type
 * @param webMetadataService Web metadata service
 * @return Map with java types and java type details
 */
protected SortedMap<JavaType, JavaTypeMetadataDetails> getRelationFieldsDetails(String mid,
        PhysicalTypeMetadata controller, JavaType entity, WebMetadataService webMetadataService) {

    SortedMap<JavaType, JavaTypeMetadataDetails> relatedApplicationTypeMetadata = new TreeMap<JavaType, JavaTypeMetadataDetails>();

    // For each eligible field: put all java types details in the same map
    List<JavaType> relations = getRelationFields(mid, controller, entity, webMetadataService);
    for (JavaType relation : relations) {

        SortedMap<JavaType, JavaTypeMetadataDetails> tmp = getFieldJavaTypesDetails(relation, mid,
                webMetadataService);
        if (tmp != null) {

            relatedApplicationTypeMetadata.putAll(tmp);
        }
    }

    return relatedApplicationTypeMetadata;
}

From source file:org.squale.squalecommon.enterpriselayer.facade.quality.MeasureFacade.java

/**
 * Affichage des facteurs du Kiviat : tous les facteurs ou seulement ceux ayant une note
 * //from   w w  w .  java2  s  .c o m
 * @param pValues les donnes  afficher : facteur + note
 * @param pNullValuesList la liste des facteurs dont la note est nulle
 * @param pAllFactors tous les facteurs (="true") ou seulement les facteurs ayant une note
 * @param pFactorsMin nombre de facteurs minimal que l'on doit afficher sur le Kiviat
 * @return values les donnes rellement  afficher : facteur + note
 */
private static SortedMap deleteFactors(SortedMap pValues, ArrayList pNullValuesList, String pAllFactors,
        int pFactorsMin) {
    SortedMap values = new TreeMap();
    // Seulement les facteurs ayant une note ? ==> suppression des facteurs ayant une note nulle.
    // Mais trois facteurs doivent au moins s'afficher (nuls ou pas !)
    if (pValues.size() > pFactorsMin && !pAllFactors.equals("true")) {
        // Nombre de suppressions possible
        int nbTotalDeletions = pValues.size() - pFactorsMin;
        // Nombre de suppressions effectu
        int nbCurrentDeletions = 0;
        // Parcours de la liste des facteurs avec une note nulle, pour les supprimer de l'affichage
        Iterator itList = pNullValuesList.iterator();
        while (itList.hasNext() && nbCurrentDeletions < nbTotalDeletions) {
            String keyListe = (String) itList.next();
            pValues.remove(keyListe);
            nbCurrentDeletions += 1;
        }
    }
    values.putAll(pValues);
    return values;
}