Example usage for com.google.common.collect Maps newTreeMap

List of usage examples for com.google.common.collect Maps newTreeMap

Introduction

In this page you can find the example usage for com.google.common.collect Maps newTreeMap.

Prototype

public static <K extends Comparable, V> TreeMap<K, V> newTreeMap() 

Source Link

Document

Creates a mutable, empty TreeMap instance using the natural ordering of its elements.

Usage

From source file:org.auraframework.docs.ApiContentsModel.java

@SuppressWarnings("unchecked")
public static synchronized void refreshSymbols() {
    Reader reader = null;/* www.j a v  a 2 s . c om*/
    try {
        try {
            final ResourceLoader resourceLoader = Aura.getConfigAdapter().getResourceLoader();
            reader = new InputStreamReader(resourceLoader.getResourceAsStream("jsdoc/symbolSet.json"));
            JsonStreamReader jsonReader = new JsonStreamReader(reader);
            jsonReader.disableLengthLimitsBecauseIAmStreamingAndMyMemoryUseIsNotProportionalToTheStreamLength();
            jsonReader.next();
            List<Object> readSymbols = jsonReader.getList();
            symbols = Maps.newTreeMap();
            List<Map<String, Object>> classes = new ArrayList<Map<String, Object>>();
            for (Object symbol : readSymbols) {
                Map<String, Object> map = (Map<String, Object>) symbol;
                if (!map.containsKey("access")) {
                    map.put("access", "public");
                }
                if ("class".equalsIgnoreCase((String) map.get("kind"))) {
                    classes.add(map);
                    map.put("methods", new ArrayList<Map<String, Object>>());
                    if (!map.containsKey("properties")) {
                        map.put("properties", new ArrayList<Map<String, Object>>());
                    }
                } else if ("function".equalsIgnoreCase((String) map.get("kind"))) {
                    for (Map<String, Object> aClass : classes) {
                        if (map.get("memberof") != null && map.get("memberof").equals(aClass.get("longname"))) {
                            ((List<Map<String, Object>>) aClass.get("methods")).add(map);
                        }
                    }
                } else if ("member".equalsIgnoreCase((String) map.get("kind"))
                        && !map.containsKey("undocumented") && map.get("access").equals("public")) {
                    for (Map<String, Object> aClass : classes) {
                        if (map.get("memberof") != null && map.get("memberof").equals(aClass.get("longname"))) {
                            ((List<Map<String, Object>>) aClass.get("properties")).add(map);
                        }
                    }
                }
            }
            for (Object symbol : readSymbols) {
                Map<String, Object> map = (Map<String, Object>) symbol;
                List<Map<String, Object>> l = (List<Map<String, Object>>) map.get("methods");
                if (l != null) {
                    Collections.sort(l, SYMBOL_COMPARATOR);
                }
                l = (List<Map<String, Object>>) map.get("properties");
                if (l != null) {
                    Collections.sort(l, SYMBOL_COMPARATOR);
                }
                String name = (String) map.get("name");
                if (name != null) {
                    symbols.put(name, map);
                }
            }
        } finally {
            if (reader != null) {
                reader.close();
            }
        }
    } catch (IOException e) {
        throw new AuraRuntimeException(e);
    }
}

From source file:cuchaz.enigma.mapping.type.MethodMapping.java

public MethodMapping(String obfName, Signature obfSignature, String deobfName) {
    if (obfName == null) {
        throw new IllegalArgumentException("obf name cannot be null!");
    }//from   w w w  .  ja  va  2  s.c  o  m
    if (obfSignature == null) {
        throw new IllegalArgumentException("obf signature cannot be null!");
    }
    m_obfName = obfName;
    m_deobfName = NameValidator.validateMethodName(deobfName);
    m_obfSignature = obfSignature;
    m_arguments = Maps.newTreeMap();
}

From source file:co.cask.tephra.snapshot.SnapshotCodecV2.java

@Override
protected NavigableMap<Long, TransactionManager.InProgressTx> decodeInProgress(BinaryDecoder decoder)
        throws IOException {

    int size = decoder.readInt();
    NavigableMap<Long, TransactionManager.InProgressTx> inProgress = Maps.newTreeMap();
    while (size != 0) { // zero denotes end of list as per AVRO spec
        for (int remaining = size; remaining > 0; --remaining) {
            long txId = decoder.readLong();
            long expiration = decoder.readLong();
            long visibilityUpperBound = decoder.readLong();
            int txTypeIdx = decoder.readInt();
            TransactionType txType;//w  w w. j  a v  a 2 s .  co  m
            try {
                txType = TransactionType.values()[txTypeIdx];
            } catch (ArrayIndexOutOfBoundsException e) {
                throw new IOException("Type enum ordinal value is out of range: " + txTypeIdx);
            }
            inProgress.put(txId, new TransactionManager.InProgressTx(visibilityUpperBound, expiration, txType,
                    new LongArrayList()));
        }
        size = decoder.readInt();
    }
    return inProgress;
}

From source file:co.cask.tigon.data.transaction.snapshot.SnapshotCodecV2.java

@Override
protected NavigableMap<Long, TransactionManager.InProgressTx> decodeInProgress(BinaryDecoder decoder)
        throws IOException {

    int size = decoder.readInt();
    NavigableMap<Long, TransactionManager.InProgressTx> inProgress = Maps.newTreeMap();
    while (size != 0) { // zero denotes end of list as per AVRO spec
        for (int remaining = size; remaining > 0; --remaining) {
            long txId = decoder.readLong();
            long expiration = decoder.readLong();
            long visibilityUpperBound = decoder.readLong();
            inProgress.put(txId, new TransactionManager.InProgressTx(visibilityUpperBound, expiration));
        }//from  www .j a va  2  s  .  c  om
        size = decoder.readInt();
    }
    return inProgress;
}

From source file:com.greensopinion.swagger.jaxrsgen.model.Service.java

public Service(String apiVersion, String basePath, String path, String description,
        List<ServiceApi> serviceApis, List<ApiModel> models) {
    this.apiVersion = checkNotNull(apiVersion, "Must provide apiVersion");
    this.basePath = checkNotNull(basePath, "Must provide a basePath");
    this.path = checkNotNull(path, "Must provide a path");
    this.description = description;
    this.serviceApis = copyOf(checkNotNull(serviceApis, "Must provide serviceApis"));
    Map<String, ApiModel> modelByName = Maps.newTreeMap();
    checkNotNull(models, "Must provide models");
    for (ApiModel model : models) {
        modelByName.put(model.getName(), model);
    }/*www .  j  a  va 2 s .co  m*/
    this.models = ImmutableMap.copyOf(modelByName);

}

From source file:com.google.gerrit.server.change.FileInfoJson.java

Map<String, FileInfo> toFileInfoMap(Change change, PatchSet patchSet, @Nullable PatchSet base)
        throws PatchListNotAvailableException {
    ObjectId a = (base == null) ? null : ObjectId.fromString(base.getRevision().get());
    ObjectId b = ObjectId.fromString(patchSet.getRevision().get());
    PatchList list = patchListCache.get(new PatchListKey(change.getProject(), a, b, Whitespace.IGNORE_NONE));

    Map<String, FileInfo> files = Maps.newTreeMap();
    for (PatchListEntry e : list.getPatches()) {
        FileInfoJson.FileInfo d = new FileInfoJson.FileInfo();
        d.status = e.getChangeType() != Patch.ChangeType.MODIFIED ? e.getChangeType().getCode() : null;
        d.oldPath = e.getOldName();//  w  w w  .  j  av a2s . co  m
        if (e.getPatchType() == Patch.PatchType.BINARY) {
            d.binary = true;
        } else {
            d.linesInserted = e.getInsertions() > 0 ? e.getInsertions() : null;
            d.linesDeleted = e.getDeletions() > 0 ? e.getDeletions() : null;
        }

        FileInfoJson.FileInfo o = files.put(e.getNewName(), d);
        if (o != null) {
            // This should only happen on a delete-add break created by JGit
            // when the file was rewritten and too little content survived. Write
            // a single record with data from both sides.
            d.status = Patch.ChangeType.REWRITE.getCode();
            if (o.binary != null && o.binary) {
                d.binary = true;
            }
            if (o.linesInserted != null) {
                d.linesInserted = o.linesInserted;
            }
            if (o.linesDeleted != null) {
                d.linesDeleted = o.linesDeleted;
            }
        }
    }
    return files;
}

From source file:ezbakehelpers.ezconfigurationhelpers.elasticsearch.ElasticsearchConfigurationHelper.java

/**
 * This helper will return a comma separated string of elasticsearch hosts names with port
 *    host1:port,host2:port..../* w w w .ja  v  a  2  s  . c o  m*/
 * @return a comma separated list or elasticsearch hosts, or null if no host present
 */
public String getElasticsearchHostWithPort() {
    String hostsWithPort = null;
    int port = getElasticsearchPort();
    String hostString = getElasticsearchHost();

    Map<String, Integer> hostPortMap = Maps.newTreeMap();
    if (hostString != null) {
        for (String hostName : Splitter.on(",").omitEmptyStrings().trimResults().split(hostString)) {
            hostPortMap.put(hostName, port);
        }
        hostsWithPort = Joiner.on(",").withKeyValueSeparator(":").join(hostPortMap);
    }
    return hostsWithPort;
}

From source file:de.tu_berlin.dima.oligos.profiler.PseudoColumnProfiler.java

@Override
public Column<String> profile() {
    try {//from www  .jav a  2 s. c  o m
        Map<String, Long> quantileHistogram = connector.getHistogram();
        Map<String, Long> mostFrequentValues = connector.getMostFrequentValues();
        Map<String, Long> exactValues = Maps.newTreeMap();
        for (Entry<String, Long> e : mostFrequentValues.entrySet()) {
            exactValues.put(e.getKey(), e.getValue());
        }

        if (!isEnum) {
            for (Entry<String, Long> e : quantileHistogram.entrySet()) {
                String key = e.getKey();
                long value = e.getValue();
                if (!exactValues.containsKey(key)) {
                    exactValues.put(key, value);
                }
            }
        }
        Set<Constraint> constraints = connector.getConstraints();
        String min = connector.getMin();
        String max = connector.getMax();
        long cardinality = exactValues.size();
        long numNulls = connector.getNumNulls();
        Histogram<String> distribution = new StringHistogram(exactValues);
        return new Column<String>(schema, table, column, type, constraints, min, max, cardinality, numNulls,
                distribution, parser);
    } catch (SQLException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.google.template.soy.msgs.restricted.SoyMsgBundleImpl.java

/**
 * Note: If there exist duplicate message ids in the {@code msgs} list, the first one wins.
 * However, the source paths from subsequent duplicates will be added to the source paths for the
 * message./*from   w  w w . ja va  2 s.  c o  m*/
 *
 * @param localeString The language/locale string of this bundle of messages, or null if unknown.
 *     Should only be null for bundles newly extracted from source files. Should always be set
 *     for bundles parsed from message files/resources.
 * @param msgs The list of messages. List order will become the iteration order.
 */
public SoyMsgBundleImpl(@Nullable String localeString, List<SoyMsg> msgs) {

    this.localeString = localeString;

    SortedMap<Long, SoyMsg> tempMsgMap = Maps.newTreeMap();
    for (SoyMsg msg : msgs) {
        checkArgument(Objects.equals(msg.getLocaleString(), localeString));
        long msgId = msg.getId();

        if (!tempMsgMap.containsKey(msgId)) { // new message id
            tempMsgMap.put(msgId, msg);

        } else { // duplicate message id
            SoyMsg existingMsg = tempMsgMap.get(msgId);
            for (String source : msg.getSourcePaths()) {
                existingMsg.addSourcePath(source);
            }
        }
    }

    msgMap = ImmutableMap.copyOf(tempMsgMap);
}

From source file:com.lastcalc.servlets.WorksheetServlet.java

protected static WorksheetResponse getWorksheetResponse(Worksheet worksheet, WorksheetRequest request,
        String requestURI) throws IOException {
    final ArrayList<Line> qaPairs = worksheet.qaPairs;

    if (request.questions != null) {
        //int earliestModified = Integer.MAX_VALUE;
        final TreeMap<Integer, String> orderedQuestions = Maps.newTreeMap();
        orderedQuestions.putAll(request.questions);
        for (final Entry<Integer, String> question : orderedQuestions.entrySet()) {
            final int pos = question.getKey() - 1;
            if (pos < qaPairs.size()) {
                final Line qaPair = qaPairs.get(pos);
                qaPair.lineNum = question.getKey();
                qaPair.question = question.getValue();
                //earliestModified = Math.min(earliestModified, pos);
            } else {
                qaPairs.add(new Line(question.getKey(), question.getValue(), null));
            }/*from   w  ww.j a  v  a  2  s. c om*/
        }
        for (int x = 0; x < qaPairs.size(); x++) {
            final Line qaPair = qaPairs.get(x);
            qaPair.answer = null;
        }
        // Remove any qaPairs that have been removed from the browser DOM
        if (!orderedQuestions.isEmpty()) {
            while (qaPairs.size() > orderedQuestions.lastKey()) {
                qaPairs.remove(qaPairs.size() - 1);
            }
        }
    }

    // Recompute worksheet
    final SequentialParser seqParser = SequentialParser.create();

    for (final Line qap : qaPairs) {
        if (qap.question.trim().length() == 0) {
            qap.answer = TokenList.createD();
        } else {
            if (qap.answer == null) {
                qap.answer = seqParser.parseNext(Tokenizer.tokenize(qap.question));//original ian's code
            } else {
                seqParser.processNextAnswer(qap.answer);
            }
        }
    }

    worksheet.definedParsers = seqParser.getUserDefinedParsers().getParsers();

    final WorksheetResponse response = new WorksheetResponse();
    if (request.getRecognizedWords) {
        response.recognizedWords = SequentialParser.recognizedWords;
    }

    response.answers = Maps.newHashMap();
    response.answerTypes = Maps.newHashMap();
    response.variables = seqParser.getUserDefinedKeywordMap();

    for (int x = 0; x < qaPairs.size(); x++) {
        final TokenList answer = qaPairs.get(x).answer;
        final TokenList strippedAnswer = seqParser.stripUDF(answer);

        if (qaPairs.get(x).lineNum == x + 1) {

            System.out.println("lineNum properly matches qaPairs index");

            response.answers.put(x + 1, Renderers.toHtml(requestURI, strippedAnswer).toString());
            response.answerTypes.put(x + 1, getAnswerType(strippedAnswer));
        } else {

            System.out.println("lineNum DOES NOT MATCH qaPairs index, lineNum: " + qaPairs.get(x).lineNum
                    + " , qaPairs index: " + (x + 1) + " ...............................\n\n");

            response.answers.put(qaPairs.get(x).lineNum,
                    Renderers.toHtml(requestURI, strippedAnswer).toString());
            response.answerTypes.put(qaPairs.get(x).lineNum, getAnswerType(strippedAnswer));
        }

    }
    return response;
}