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:com.facebook.buck.apple.project_generator.WorkspaceGenerator.java

public WorkspaceGenerator(ProjectFilesystem projectFilesystem, String workspaceName, Path outputDirectory) {
    this.projectFilesystem = projectFilesystem;
    this.workspaceName = workspaceName;
    this.outputDirectory = outputDirectory;
    this.children = Maps.newTreeMap();
}

From source file:org.sonar.core.technicaldebt.TechnicalDebtModelRepository.java

protected void findAvailableXMLFiles() {
    if (contributingPluginKeyToClassLoader == null) {
        contributingPluginKeyToClassLoader = Maps.newTreeMap();
        // Add default model
        contributingPluginKeyToClassLoader.put(DEFAULT_MODEL, getClass().getClassLoader());
        for (PluginMetadata metadata : pluginRepository.getMetadata()) {
            String pluginKey = metadata.getKey();
            ClassLoader classLoader = pluginRepository.getPlugin(pluginKey).getClass().getClassLoader();
            if (classLoader.getResource(getXMLFilePath(pluginKey)) != null) {
                contributingPluginKeyToClassLoader.put(pluginKey, classLoader);
            }/*from  w w w  . j a  va2 s.  c  o m*/
        }
    }
    contributingPluginKeyToClassLoader = Collections.unmodifiableMap(contributingPluginKeyToClassLoader);
}

From source file:io.janusproject.kernel.services.jdk.distributeddata.StandardDistributedDataStructureService.java

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override//from   w  ww .j  ava2 s.c o m
public <K, V> DMultiMap<K, V> getMultiMap(String name, Comparator<? super K> comparator) {
    Map map;
    if (comparator == null) {
        map = Maps.newTreeMap();
    } else {
        map = Maps.newTreeMap(comparator);
    }
    Multimap<K, V> multimap = Multimaps.newListMultimap(map, new ArrayListSupplier<V>());
    return new DMultiMapView<>(name, multimap);
}

From source file:com.github.fge.jsonschema.walk.SchemaWalker.java

private <T> void walkTree(final JsonPointer pwd, final SchemaTree tree, final SchemaListener<T> listener,
        final ProcessingReport report) throws ProcessingException {
    listener.enteringPath(pwd, report);//from  w  ww .  ja  va 2  s .c  o m
    final SchemaTree resolvedTree = resolveTree(tree, report);
    listener.visiting(resolvedTree, report);

    /*
     * Grab pointer collectors
     */
    final Map<String, PointerCollector> map = Maps.newTreeMap();

    map.putAll(collectors);
    map.keySet().retainAll(Sets.newHashSet(resolvedTree.getNode().fieldNames()));

    /*
     * Collect pointers to visit next
     */
    final List<JsonPointer> pointers = Lists.newArrayList();
    for (final PointerCollector collector : map.values())
        collector.collect(pointers, resolvedTree);

    /*
     * Now, visit the collected set of pointers
     */
    for (final JsonPointer ptr : pointers) {
        walkTree(pwd.append(ptr), resolvedTree.append(ptr), listener, report);
    }
    listener.exitingPath(pwd, report);
}

From source file:com.cloudera.science.ml.parallel.summary.InternalStats.java

public void merge(InternalStats other, int maxLevels) {
    if (other.internalNumeric != null) {
        internalNumeric().merge(other.internalNumeric);
    } else {//w  w w .  j  a v a2 s.  c om
        Map<String, Entry> entries = histogram();
        Map<String, Entry> merged = Maps.newTreeMap();
        Set<String> keys = Sets.newTreeSet(Sets.union(entries.keySet(), other.histogram().keySet()));
        for (String key : keys) {
            Entry e = entries.get(key);
            Entry entry = other.histogram().get(key);
            Entry newEntry = new Entry();
            if (e != null) {
                newEntry.inc(e.getCount());
            }
            if (entry != null) {
                newEntry.inc(entry.getCount());
            }
            merged.put(key, newEntry);
            if (merged.size() == maxLevels) {
                this.trimmed = true;
                break;
            }
        }
        entries.clear();
        entries.putAll(merged);
        if (other.trimmed) {
            this.trimmed = true;
        }
    }
}

From source file:org.sonar.server.language.ws.ListAction.java

private Collection<Language> listMatchingLanguages(@Nullable String query, int pageSize) {
    Pattern pattern = Pattern.compile(query == null ? MATCH_ALL : MATCH_ALL + Pattern.quote(query) + MATCH_ALL,
            Pattern.CASE_INSENSITIVE);

    SortedMap<String, Language> languagesByName = Maps.newTreeMap();
    for (Language lang : languages.all()) {
        if (pattern.matcher(lang.getKey()).matches() || pattern.matcher(lang.getName()).matches()) {
            languagesByName.put(lang.getName(), lang);
        }/*from w ww .j  a  va 2  s.c o  m*/
    }
    List<Language> result = Lists.newArrayList(languagesByName.values());
    if (pageSize > 0 && pageSize < result.size()) {
        result = result.subList(0, pageSize);
    }
    return result;
}

From source file:com.google.gerrit.server.plugins.ListPlugins.java

public JsonElement display(OutputStream displayOutputStream) throws UnsupportedEncodingException {
    PrintWriter stdout = null;//w ww  .  java2 s  .  c  om
    if (displayOutputStream != null) {
        try {
            stdout = new PrintWriter(new BufferedWriter(new OutputStreamWriter(displayOutputStream, "UTF-8")));
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException("JVM lacks UTF-8 encoding", e);
        }
    }

    Map<String, PluginInfo> output = Maps.newTreeMap();
    List<Plugin> plugins = Lists.newArrayList(pluginLoader.getPlugins(all));
    Collections.sort(plugins, new Comparator<Plugin>() {
        @Override
        public int compare(Plugin a, Plugin b) {
            return a.getName().compareTo(b.getName());
        }
    });

    if (!format.isJson()) {
        stdout.format("%-30s %-10s %-8s\n", "Name", "Version", "Status");
        stdout.print("-------------------------------------------------------------------------------\n");
    }

    for (Plugin p : plugins) {
        PluginInfo info = new PluginInfo(p);
        if (format.isJson()) {
            output.put(p.getName(), info);
        } else {
            stdout.format("%-30s %-10s %-8s\n", p.getName(), Strings.nullToEmpty(info.version),
                    p.isDisabled() ? "DISABLED" : "ENABLED");
        }
    }

    if (stdout == null) {
        return OutputFormat.JSON.newGson().toJsonTree(output, new TypeToken<Map<String, Object>>() {
        }.getType());
    } else if (format.isJson()) {
        format.newGson().toJson(output, new TypeToken<Map<String, PluginInfo>>() {
        }.getType(), stdout);
        stdout.print('\n');
    }
    stdout.flush();
    return null;
}

From source file:indigo.runtime.AnalysisContext.java

private AnalysisContext(Collection<Operation> newOperations, ConflictResolutionPolicy policy,
        AnalysisContext parentContext, boolean propagateTransformations, GenericPredicateFactory factory,
        Map<String, ConditionPredicateAssignment> predicateSizeConstraints) {

    this.resolutionPolicy = policy;
    this.parentContext = parentContext;
    this.transformedOps = Maps.newTreeMap();
    this.transformedOpsPre = Maps.newTreeMap();
    this.factory = factory;
    this.predicateSizeConstraints = predicateSizeConstraints;

    this.operations = parentContext.operations.entrySet().stream()
            .collect(Collectors.toMap(Entry::getKey, Entry::getValue));

    this.opEffects = parentContext.opEffects.entrySet().stream()
            .collect(Collectors.toMap(Entry::getKey, Entry::getValue));

    if (propagateTransformations) {
        for (Entry<String, Collection<PredicateAssignment>> parentTransforms : parentContext.transformedOps
                .entrySet()) {/*from w  w  w .java 2s  .com*/
            opEffects.put(parentTransforms.getKey(), parentTransforms.getValue());
        }
    }

    for (Operation op : newOperations) {
        opEffects.put(op.opName(), op.getEffects());
        operations.put(op.opName(), op);
    }

    this.predicateToOpsIncludingPre = computePredicateToOpsIndex();
}

From source file:com.palantir.typescript.text.reconciler.PresentationReconciler.java

public PresentationReconciler() {
    this.classifier = TypeScriptPlugin.getDefault().getClassifier();
    this.listener = new MyTextListener();
    this.finalLexStates = Maps.newTreeMap();
}

From source file:org.sonar.server.debt.DebtModelPluginRepository.java

private void findAvailableXMLFiles() {
    if (contributingPluginKeyToClassLoader == null) {
        contributingPluginKeyToClassLoader = Maps.newTreeMap();
        // Add default model
        contributingPluginKeyToClassLoader.put(DEFAULT_MODEL, getClass().getClassLoader());
        for (PluginInfo pluginInfo : pluginRepository.getPluginInfos()) {
            String pluginKey = pluginInfo.getKey();
            Plugin plugin = pluginRepository.getPluginInstance(pluginKey);
            ClassLoader classLoader = plugin.getClass().getClassLoader();
            if (classLoader.getResource(getXMLFilePath(pluginKey)) != null) {
                contributingPluginKeyToClassLoader.put(pluginKey, classLoader);
            }/*from w  w w .  j a  v a  2 s  . c o  m*/
        }
    }
    contributingPluginKeyToClassLoader = Collections.unmodifiableMap(contributingPluginKeyToClassLoader);
}