Example usage for java.util TreeMap putAll

List of usage examples for java.util TreeMap putAll

Introduction

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

Prototype

public void putAll(Map<? extends K, ? extends V> map) 

Source Link

Document

Copies all of the mappings from the specified map to this map.

Usage

From source file:com.linkedin.pinot.integration.tests.HybridClusterScanComparisonIntegrationTest.java

protected void runTestLoop(Callable<Object> testMethod, boolean useMultipleThreads) throws Exception {
    // Clean up the Kafka topic
    // TODO jfim: Re-enable this once PINOT-2598 is fixed
    // purgeKafkaTopicAndResetRealtimeTable();

    List<Pair<File, File>> enabledRealtimeSegments = new ArrayList<>();

    // Sort the realtime segments based on their segment name so they get added from earliest to latest
    TreeMap<File, File> sortedRealtimeSegments = new TreeMap<File, File>(new Comparator<File>() {
        @Override/* w w w  . j a  v a2 s  .  co m*/
        public int compare(File o1, File o2) {
            return _realtimeAvroToSegmentMap.get(o1).getName()
                    .compareTo(_realtimeAvroToSegmentMap.get(o2).getName());
        }
    });
    sortedRealtimeSegments.putAll(_realtimeAvroToSegmentMap);

    for (File avroFile : sortedRealtimeSegments.keySet()) {
        enabledRealtimeSegments.add(Pair.of(avroFile, sortedRealtimeSegments.get(avroFile)));

        if (useMultipleThreads) {
            _queryExecutor = new ThreadPoolExecutor(4, 4, 5, TimeUnit.SECONDS,
                    new ArrayBlockingQueue<Runnable>(50), new ThreadPoolExecutor.CallerRunsPolicy());
        }

        // Push avro for the new segment
        LOGGER.info("Pushing Avro file {} into Kafka", avroFile);
        pushAvroIntoKafka(Collections.singletonList(avroFile), KafkaStarterUtils.DEFAULT_KAFKA_BROKER,
                KAFKA_TOPIC);

        // Configure the scan based comparator to use the distinct union of the offline and realtime segments
        configureScanBasedComparator(enabledRealtimeSegments);

        QueryResponse queryResponse = _scanBasedQueryProcessor.processQuery("select count(*) from mytable");

        int expectedRecordCount = queryResponse.getNumDocsScanned();
        waitForRecordCountToStabilizeToExpectedCount(expectedRecordCount,
                System.currentTimeMillis() + getStabilizationTimeMs());

        // Run the actual tests
        LOGGER.info("Running queries");
        testMethod.call();

        if (useMultipleThreads) {
            if (_nQueriesRead == -1) {
                _queryExecutor.shutdown();
                _queryExecutor.awaitTermination(5, TimeUnit.MINUTES);
            } else {
                int totalQueries = _failedQueries.get() + _successfulQueries.get();
                while (totalQueries < _nQueriesRead) {
                    LOGGER.info("Completed " + totalQueries + " out of " + _nQueriesRead + " - waiting");
                    Uninterruptibles.sleepUninterruptibly(20, TimeUnit.SECONDS);
                    totalQueries = _failedQueries.get() + _successfulQueries.get();
                }
                if (totalQueries > _nQueriesRead) {
                    throw new RuntimeException("Executed " + totalQueries + " more than " + _nQueriesRead);
                }
                _queryExecutor.shutdown();
            }
        }
        int totalQueries = _failedQueries.get() + _successfulQueries.get();
        doDisplayStatus(totalQueries);

        // Release resources
        _scanBasedQueryProcessor.close();
        _compareStatusFileWriter.write("Status after push of " + avroFile + ":" + System.currentTimeMillis()
                + ":Executed " + _nQueriesRead + " queries, " + _failedQueries + " failures,"
                + _emptyResults.get() + " empty results\n");
    }
}

From source file:eu.edisonproject.training.wsd.DisambiguatorImpl.java

private Term mapreduceDisambiguate(String term, Set<Term> possibleTerms, Set<String> ngarms,
        double minimumSimilarity) throws IOException {
    String filePath = ".." + File.separator + "etc" + File.separator + "Avro Document" + File.separator + term
            + File.separator + term + ".avro";
    TermAvroSerializer ts = new TermAvroSerializer(filePath, Term.getClassSchema());
    List<CharSequence> empty = new ArrayList<>();
    empty.add("");
    for (Term t : possibleTerms) {
        List<CharSequence> nuid = t.getNuids();
        if (nuid == null || nuid.isEmpty() || nuid.contains(null)) {
            t.setNuids(empty);//from   w w w.  j a  v a 2  s.c o  m
        }

        List<CharSequence> buids = t.getBuids();
        if (buids == null || buids.isEmpty() || buids.contains(null)) {
            t.setBuids(empty);
        }
        List<CharSequence> alt = t.getAltLables();
        if (alt == null || alt.isEmpty() || alt.contains(null)) {
            t.setAltLables(empty);
        }
        List<CharSequence> gl = t.getGlosses();
        if (gl == null || gl.isEmpty() || gl.contains(null)) {
            t.setGlosses(empty);
        } else {
            StringBuilder glosses = new StringBuilder();
            for (CharSequence n : gl) {
                glosses.append(n).append(" ");
            }
            gl = new ArrayList<>();
            stemer.setDescription(glosses.toString());
            gl.add(stemer.execute());
            t.setGlosses(gl);

        }
        List<CharSequence> cat = t.getCategories();
        if (cat == null || cat.contains(null)) {
            t.setCategories(empty);
        }
        ts.serialize(t);
    }
    Term context = new Term();
    context.setUid("context");
    StringBuilder glosses = new StringBuilder();
    context.setLemma(term);
    context.setOriginalTerm(term);
    context.setUrl("empty");
    for (String n : ngarms) {
        glosses.append(n).append(" ");
    }
    List<CharSequence> contextGlosses = new ArrayList<>();
    stemer.setDescription(glosses.toString());

    contextGlosses.add(stemer.execute());
    context.setGlosses(contextGlosses);
    List<CharSequence> nuid = context.getNuids();
    if (nuid == null || nuid.isEmpty() || nuid.contains(null)) {
        context.setNuids(empty);
    }

    List<CharSequence> buids = context.getBuids();
    if (buids == null || buids.isEmpty() || buids.contains(null)) {
        context.setBuids(empty);
    }
    List<CharSequence> alt = context.getAltLables();
    if (alt == null || alt.isEmpty() || alt.contains(null)) {
        context.setAltLables(empty);
    }
    List<CharSequence> gl = context.getGlosses();
    if (gl == null || gl.isEmpty() || gl.contains(null)) {
        context.setGlosses(empty);
    }
    List<CharSequence> cat = context.getCategories();
    if (cat == null || cat.contains(null)) {
        context.setCategories(empty);
    }
    ts.serialize(context);
    ts.close();

    ITFIDFDriver tfidfDriver = new TFIDFDriverImpl(term);
    tfidfDriver.executeTFIDF(new File(filePath).getParent());

    Map<CharSequence, Map<String, Double>> featureVectors = CSVFileReader
            .tfidfResult2Map(TFIDFDriverImpl.OUTPUT_PATH4 + File.separator + "part-r-00000");
    Map<String, Double> contextVector = featureVectors.remove("context");

    Map<CharSequence, Double> scoreMap = new HashMap<>();
    for (CharSequence key : featureVectors.keySet()) {
        Double similarity = cosineSimilarity(contextVector, featureVectors.get(key));
        scoreMap.put(key, similarity);
    }
    if (scoreMap.isEmpty()) {
        return null;
    }

    ValueComparator bvc = new ValueComparator(scoreMap);
    TreeMap<CharSequence, Double> sorted_map = new TreeMap(bvc);
    sorted_map.putAll(scoreMap);

    Iterator<CharSequence> it = sorted_map.keySet().iterator();
    CharSequence winner = it.next();

    Double s1 = scoreMap.get(winner);
    if (s1 < getMinimumSimilarity()) {
        return null;
    }

    return getTermFromDB(winner);

}

From source file:net.pms.dlna.protocolinfo.ProtocolInfo.java

/**
 * Creates a new instance using the provided information.
 *
 * @param protocol the {@link Protocol} for the new instance. Use
 *            {@code null} for "any".//from w  w w .j  a v  a2s. co  m
 * @param network the network for the new instance. Use {@code null} or
 *            blank for "any".
 * @param contentFormat the content format for the new instance. Use
 *            {@code null} or blank for "any".
 * @param attributes a {@link Map} of {@link ProtocolInfoAttributeName} and
 *            {@link ProtocolInfoAttribute} pairs for the new instance.
 */
public ProtocolInfo(Protocol protocol, String network, String contentFormat,
        Map<ProtocolInfoAttributeName, ProtocolInfoAttribute> attributes) {
    this.protocol = protocol == null ? Protocol.ALL : protocol;
    this.network = isBlank(network) ? WILDCARD : network;
    this.mimeType = createMimeType(contentFormat);
    TreeMap<ProtocolInfoAttributeName, ProtocolInfoAttribute> tmpAttributes = createEmptyAttributesMap();
    tmpAttributes.putAll(attributes);
    this.attributes = Collections.unmodifiableSortedMap(tmpAttributes);
    this.attributesString = generateAttributesString();
    this.additionalInfo = this.attributesString;
    this.stringValue = generateStringValue();
}

From source file:net.pms.dlna.protocolinfo.ProtocolInfo.java

/**
 * Creates a new instance using the provided information.
 *
 * @param protocol the {@link Protocol} for the new instance. Use
 *            {@code null} for "any"./*  w w  w. ja  v a2s . c  o  m*/
 * @param network the network for the new instance. Use {@code null} or
 *            blank for "any".
 * @param mimeType the mime-type for the new instance. Use {@code null} or
 *            {@link MimeType#ANYANY} for "any".
 * @param attributes a {@link Map} of {@link ProtocolInfoAttributeName} and
 *            {@link ProtocolInfoAttribute} pairs for the new instance.
 */
public ProtocolInfo(Protocol protocol, String network, MimeType mimeType,
        Map<ProtocolInfoAttributeName, ProtocolInfoAttribute> attributes) {
    this.protocol = protocol == null ? Protocol.ALL : protocol;
    this.network = isBlank(network) ? WILDCARD : network;
    this.mimeType = mimeType == null ? MimeType.ANYANY : mimeType;
    TreeMap<ProtocolInfoAttributeName, ProtocolInfoAttribute> tmpAttributes = createEmptyAttributesMap();
    tmpAttributes.putAll(attributes);
    this.attributes = Collections.unmodifiableSortedMap(tmpAttributes);
    this.attributesString = generateAttributesString();
    this.additionalInfo = this.attributesString;
    this.stringValue = generateStringValue();
}

From source file:eu.edisonproject.training.wsd.DisambiguatorImpl.java

private Set<Term> tf_idf_Disambiguation(Set<Term> possibleTerms, Set<String> nGrams, String lemma,
        double confidence, boolean matchTitle) throws IOException, ParseException {
    LOGGER.log(Level.FINE, "Loaded {0} for {1}", new Object[] { nGrams.size(), lemma });
    if (nGrams.size() < 7) {
        LOGGER.log(Level.WARNING, "Found only {0} n-grams for {1}. Not enough for disambiguation.",
                new Object[] { nGrams.size(), lemma });
        return null;
    }/*from   w w  w .  ja v  a  2s  .  co  m*/

    List<List<String>> allDocs = new ArrayList<>();
    Map<CharSequence, List<String>> docs = new HashMap<>();

    for (Term tv : possibleTerms) {
        Set<String> doc = getDocument(tv);
        allDocs.add(new ArrayList<>(doc));
        docs.put(tv.getUid(), new ArrayList<>(doc));
    }

    Set<String> contextDoc = new HashSet<>();
    StringBuilder ngString = new StringBuilder();
    for (String s : nGrams) {
        if (s.contains("_")) {
            String[] parts = s.split("_");
            for (String token : parts) {
                if (token.length() >= 1 && !token.contains(lemma)) {
                    //                        contextDoc.add(token);
                    ngString.append(token).append(" ");
                }
            }
        } else if (s.length() >= 1 && !s.contains(lemma)) {
            ngString.append(s).append(" ");
            //                contextDoc.add(s);
        }
    }
    tokenizer.setDescription(ngString.toString());
    String cleanText = tokenizer.execute();
    lematizer.setDescription(cleanText);
    String lematizedText = lematizer.execute();
    List<String> ngList = Arrays.asList(lematizedText.split(" "));
    contextDoc.addAll(ngList);

    docs.put("context", new ArrayList<>(contextDoc));

    Map<CharSequence, Map<String, Double>> featureVectors = new HashMap<>();
    for (CharSequence k : docs.keySet()) {
        List<String> doc = docs.get(k);
        Map<String, Double> featureVector = new TreeMap<>();
        for (String term : doc) {
            if (!featureVector.containsKey(term)) {
                double tfidf = tfIdf(doc, allDocs, term);
                featureVector.put(term, tfidf);
            }
        }
        featureVectors.put(k, featureVector);
    }

    Map<String, Double> contextVector = featureVectors.remove("context");
    Map<CharSequence, Double> scoreMap = new HashMap<>();
    for (CharSequence key : featureVectors.keySet()) {
        Double similarity = cosineSimilarity(contextVector, featureVectors.get(key));

        for (Term t : possibleTerms) {
            if (t.getUid().equals(key) && matchTitle) {
                stemer.setDescription(t.getLemma().toString());
                String stemTitle = stemer.execute();
                stemer.setDescription(lemma);
                String stemLema = stemer.execute();
                //                    List<String> subTokens = new ArrayList<>();
                //                    if (!t.getLemma().toString().toLowerCase().startsWith("(") && t.getLemma().toString().toLowerCase().contains("(") && t.getLemma().toLowerCase().contains(")")) {
                //                        int index1 = t.getLemma().toString().toLowerCase().indexOf("(") + 1;
                //                        int index2 = t.getLemma().toString().toLowerCase().indexOf(")");
                //                        String sub = t.getLemma().toString().toLowerCase().substring(index1, index2);
                //                        subTokens.addAll(tokenize(sub, true));
                //                    }
                double factor = 0.15;
                if (stemTitle.length() > stemLema.length()) {
                    if (stemTitle.contains(stemLema)) {
                        factor = 0.075;
                    }
                } else if (stemLema.length() > stemTitle.length()) {
                    if (stemLema.contains(stemTitle)) {
                        factor = 0.075;
                    }
                }
                int dist = edu.stanford.nlp.util.StringUtils.editDistance(stemTitle, stemLema);
                similarity = similarity - (dist * factor);
                t.setConfidence(similarity);
            }
        }
        scoreMap.put(key, similarity);
    }

    if (scoreMap.isEmpty()) {
        return null;
    }

    ValueComparator bvc = new ValueComparator(scoreMap);
    TreeMap<CharSequence, Double> sorted_map = new TreeMap(bvc);
    sorted_map.putAll(scoreMap);
    //        System.err.println(sorted_map);

    Iterator<CharSequence> it = sorted_map.keySet().iterator();
    CharSequence winner = it.next();

    Double s1 = scoreMap.get(winner);
    if (s1 < confidence) {
        return null;
    }

    Set<Term> terms = new HashSet<>();
    for (Term t : possibleTerms) {
        if (t.getUid().equals(winner)) {
            terms.add(t);
        }
    }
    if (!terms.isEmpty()) {
        return terms;
    } else {
        LOGGER.log(Level.INFO, "No winner");
        return null;
    }
}

From source file:net.spfbl.core.Analise.java

protected static synchronized TreeMap<String, Short[]> getClusterMap() {
    TreeMap<String, Short[]> cloneMap = new TreeMap<String, Short[]>();
    cloneMap.putAll(clusterMap);
    return cloneMap;
}

From source file:org.sonatype.nexus.rest.AbstractResourceStoreContentPlexusResource.java

protected ContentListDescribeResponseResource describeResponse(Context context, Request req, Response res,
        Variant variant, ResourceStoreRequest request, StorageItem item, Throwable e) {
    ContentListDescribeResponseResource result = new ContentListDescribeResponseResource();

    result.getProcessedRepositoriesList().addAll(request.getProcessedRepositories());

    // applied mappings
    for (Map.Entry<String, List<String>> mappingEntry : request.getAppliedMappings().entrySet()) {
        result.addAppliedMapping(mappingEntry.getKey() + " repository applied " + mappingEntry.getValue());
    }//www. ja va2  s .com

    if (item == null) {
        result.setResponseType("NOT_FOUND");

        if (e != null) {
            result.addNotFoundReasoning(buildNotFoundReasoning(null, e));
        }

        return result;
    }

    if (item instanceof StorageFileItem) {
        result.setResponseType("FILE");

    } else if (item instanceof StorageCollectionItem) {
        result.setResponseType("COLL");

    } else if (item instanceof StorageLinkItem) {
        result.setResponseType("LINK");
    } else {
        result.setResponseType(item.getClass().getName());
    }

    result.setResponseActualClass(item.getClass().getName());

    result.setResponsePath(item.getPath());

    if (!item.isVirtual()) {
        result.setResponseUid(item.getRepositoryItemUid().toString());

        result.setOriginatingRepositoryId(item.getRepositoryItemUid().getRepository().getId());

        result.setOriginatingRepositoryName(item.getRepositoryItemUid().getRepository().getName());

        result.setOriginatingRepositoryMainFacet(
                item.getRepositoryItemUid().getRepository().getRepositoryKind().getMainFacet().getName());
    } else {
        result.setResponseUid("virtual");
    }

    // properties
    result.addProperty("created=" + item.getCreated());
    result.addProperty("modified=" + item.getModified());
    result.addProperty("lastRequested=" + item.getLastRequested());
    result.addProperty("remoteChecked=" + item.getRemoteChecked());
    result.addProperty("remoteUrl=" + item.getRemoteUrl());
    result.addProperty("storedLocally=" + item.getStoredLocally());
    result.addProperty("isExpired=" + item.isExpired());
    result.addProperty("readable=" + item.isReadable());
    result.addProperty("writable=" + item.isWritable());
    result.addProperty("virtual=" + item.isVirtual());

    // attributes
    final TreeMap<String, String> sortedAttributes = Maps.newTreeMap();
    sortedAttributes.putAll(item.getRepositoryItemAttributes().asMap());
    for (Map.Entry<String, String> entry : sortedAttributes.entrySet()) {
        result.addAttribute(entry.toString());
    }

    // sources
    if (item instanceof StorageCompositeItem) {
        StorageCompositeItem composite = (StorageCompositeItem) item;
        for (StorageItem source : composite.getSources()) {
            if (!source.isVirtual()) {
                result.addSource(source.getRepositoryItemUid().toString());
            } else {
                result.addSource(source.getPath());
            }
        }
    }

    return result;
}

From source file:edu.ksu.cis.santos.mdcf.dml.symbol.SymbolTable.java

/**
 * Retrieves an immutable {@link Map} of {@link Member#name} to {@link Member}
 * with its declaring {@link Feature} that contains all declared and closest
 * (least) inherited members of the provided features.
 * /*from  www. ja  va  2 s  .  co  m*/
 * @param featureNames
 *          The fully-qualified name ({@link Feature#name}) of the
 *          {@link Feature}s whose members to be retrieved.
 * @return an immutable {@link Map}.
 */
public Map<String, Pair<Feature, Member>> allMemberMap(final Iterable<String> featureNames) {
    final TreeMap<String, Pair<Feature, Member>> b = new TreeMap<>();

    for (final String featureName : featureNames) {
        b.putAll(allMemberMap(featureName));
    }

    return Collections.unmodifiableMap(b);
}

From source file:org.openecomp.sdc.validation.impl.validators.EcompGuideLineValidator.java

@SuppressWarnings("unchecked")
private void validateNovaServerResourceMetaData(String fileName, String resourceId, Resource resource,
        GlobalValidationContext globalValidationContext) {
    Map<String, Object> novaServerProp = resource.getProperties();
    Object novaServerPropMetadata;
    if (MapUtils.isNotEmpty(novaServerProp)) {
        novaServerPropMetadata = novaServerProp.get("metadata");
        if (novaServerPropMetadata == null) {
            globalValidationContext.addMessage(fileName, ErrorLevel.WARNING,
                    ErrorMessagesFormatBuilder.getErrorWithParameters(
                            Messages.MISSING_NOVA_SERVER_METADATA.getErrorMessage(), resourceId));
        } else if (novaServerPropMetadata instanceof Map) {
            TreeMap<String, Object> propertyMap = new TreeMap(new Comparator<String>() {

                @Override/*from w w w.j  a  v a2s . c  o m*/
                public int compare(String o1, String o2) {
                    return o1.compareToIgnoreCase(o2);
                }

                @Override
                public boolean equals(Object obj) {
                    return false;
                }
            });
            propertyMap.putAll((Map) novaServerPropMetadata);
            if (!propertyMap.containsKey("vf_module_id")) {
                globalValidationContext.addMessage(fileName, ErrorLevel.WARNING,
                        ErrorMessagesFormatBuilder.getErrorWithParameters(
                                Messages.MISSING_NOVA_SERVER_VF_MODULE_ID.getErrorMessage(), resourceId));
            }
            if (!propertyMap.containsKey("vnf_id")) {
                globalValidationContext.addMessage(fileName, ErrorLevel.WARNING,
                        ErrorMessagesFormatBuilder.getErrorWithParameters(
                                Messages.MISSING_NOVA_SERVER_VNF_ID.getErrorMessage(), resourceId));
            }
        }
    }
}

From source file:edu.ksu.cis.santos.mdcf.dml.symbol.SymbolTable.java

/**
 * Retrieves an immutable {@link Map} of {@link Member#name} to
 * {@link Invariant} with its declaring {@link Feature} that contains all
 * declared and closest (least) inherited members of the provided feature.
 * /*from   w  ww .  j a  v  a 2s .co  m*/
 * @param featureName
 *          The fully-qualified name ({@link Feature#name}) of the
 *          {@link Feature} whose members to be retrieved.
 * @return an immutable {@link Map}.
 */
public Map<String, Pair<Feature, Member>> allMemberMap(final String featureName) {
    final Map<String, Map<String, Pair<Feature, Member>>> map = featureMemberMap();

    Map<String, Pair<Feature, Member>> result = map.get(featureName);

    if (result == null) {
        final TreeMap<String, Pair<Feature, Member>> b = new TreeMap<>();

        final Feature feature = feature(featureName);

        for (final NamedType nt : feature.supers) {
            b.putAll(allMemberMap(nt.name));
        }

        for (final Member m : feature.members) {
            b.put(m.name, ImmutablePair.of(feature, m));
        }

        result = Collections.unmodifiableMap(b);

        map.put(featureName, result);
    }

    return result;
}