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 <C, K extends C, V> TreeMap<K, V> newTreeMap(@Nullable Comparator<C> comparator) 

Source Link

Document

Creates a mutable, empty TreeMap instance using the given comparator.

Usage

From source file:org.eclipse.sirius.business.api.action.PrintInterpreterVariablesAction.java

private SortedMap<String, Object> getSortedVariables(Collection<? extends EObject> selections) {
    EObject context = selections.iterator().next();
    IInterpreter interpreter = InterpreterUtil.getInterpreter(context);
    SortedMap<String, Object> allVariables = Maps.newTreeMap(Ordering.natural());
    allVariables.putAll(interpreter.getVariables());
    allVariables.put("self", context); //$NON-NLS-1$
    return allVariables;
}

From source file:com.mapr.stats.bandit.BayesianBandit.java

/**
 * Samples probability estimates from each bandit and orders the bandits in increasing order.
 * @param sampleSize The number of bandits to sample.
 * @return A list of the indexes of the bandits.
 */// ww  w  .j av a2 s  .  c o m
public List<Integer> rank(int sampleSize) {
    Map<Double, Integer> tmp = Maps.newTreeMap(Ordering.natural().reverse());
    int i = 0;
    for (AbstractBayesianDistribution dist : bd) {
        double p = dist.nextMean();
        tmp.put(p, i);
        i++;
    }

    List<Integer> r = Lists.newArrayList();
    for (Double key : tmp.keySet()) {
        r.add(tmp.get(key));
        if (r.size() >= sampleSize) {
            break;
        }
    }
    return r;
}

From source file:com.facebook.buck.android.StringResources.java

public StringResources getMergedResources(StringResources otherResources) {
    TreeMap<Integer, String> stringsMap = Maps.newTreeMap(otherResources.strings);
    TreeMap<Integer, ImmutableMap<String, String>> pluralsMap = Maps.newTreeMap(otherResources.plurals);
    TreeMultimap<Integer, String> arraysMap = TreeMultimap.create(otherResources.arrays);

    stringsMap.putAll(strings);/*  ww  w .j a  v a 2 s . com*/
    pluralsMap.putAll(plurals);
    arraysMap.putAll(arrays);

    return new StringResources(stringsMap, pluralsMap, arraysMap);
}

From source file:com.netflix.ice.basic.BasicManagers.java

private void doWork() {

    logger.info("trying to find new tag group and data managers...");
    Set<Product> products = Sets.newHashSet(this.products);
    Map<Product, BasicTagGroupManager> tagGroupManagers = Maps.newHashMap(this.tagGroupManagers);
    TreeMap<Key, BasicDataManager> costManagers = Maps.newTreeMap(this.costManagers);
    TreeMap<Key, BasicDataManager> usageManagers = Maps.newTreeMap(this.usageManagers);

    Set<Product> newProducts = Sets.newHashSet();
    AmazonS3Client s3Client = AwsUtils.getAmazonS3Client();
    for (S3ObjectSummary s3ObjectSummary : s3Client
            .listObjects(config.workS3BucketName, config.workS3BucketPrefix + TagGroupWriter.DB_PREFIX)
            .getObjectSummaries()) {/*from w  w w  .  j  av  a 2s .  c  o m*/
        String key = s3ObjectSummary.getKey();
        Product product;
        if (key.endsWith("_all")) {
            product = null;
        } else {
            String name = key.substring((config.workS3BucketPrefix + TagGroupWriter.DB_PREFIX).length());
            product = config.productService.getProductByName(name);
        }
        if (!products.contains(product)) {
            products.add(product);
            newProducts.add(product);
        }
    }

    for (Product product : newProducts) {
        tagGroupManagers.put(product, new BasicTagGroupManager(product));
        for (ConsolidateType consolidateType : ConsolidateType.values()) {
            Key key = new Key(product, consolidateType);
            costManagers.put(key, new BasicDataManager(product, consolidateType, true));
            usageManagers.put(key, new BasicDataManager(product, consolidateType, false));
        }
    }

    if (newProducts.size() > 0) {
        this.costManagers = costManagers;
        this.usageManagers = usageManagers;
        this.tagGroupManagers = tagGroupManagers;
        this.products = products;
    }
}

From source file:com.voxelplugineering.voxelsniper.service.alias.CommonAliasRegistry.java

/**
 * Creates a new {@link AliasRegistry} with the given registry as its parent.
 * //from   w w  w  .  j  ava2  s. c  om
 * @param name The registry name
 * @param parent the parent registry
 * @param caseSensitive If this alias keys should be case sensitive
 */
public CommonAliasRegistry(String name, AliasRegistry parent, boolean caseSensitive) {
    checkNotNull(name);
    this.aliases = Maps.newTreeMap(new Comparator<String>() {

        @Override
        public int compare(String o1, String o2) {
            int l = o1.length() - o2.length();
            if (l == 0) {
                return o1.compareTo(o2);
            }
            return l;
        }
    });
    this.parent = parent;
    this.caseSensitive = caseSensitive;
    this.registryName = name;
}

From source file:com.palantir.atlasdb.keyvalue.partition.util.RowResultUtil.java

public static RowResult<Set<Value>> allResults(PeekingIterator<RowResult<Set<Value>>> it) {
    Preconditions.checkArgument(it.hasNext());

    final byte[] row = it.peek().getRowName();
    SortedMap<byte[], Set<Value>> result = Maps.newTreeMap(UnsignedBytes.lexicographicalComparator());
    while (it.hasNext() && Arrays.equals(row, it.peek().getRowName())) {
        RowResult<Set<Value>> kvsResult = it.next();
        for (Map.Entry<Cell, Set<Value>> e : kvsResult.getCells()) {
            final byte[] col = e.getKey().getColumnName();
            if (!result.containsKey(col)) {
                result.put(col, Sets.<Value>newHashSet());
            }/*  w  ww. j ava2s .  c o  m*/
            result.get(col).addAll(e.getValue());
        }
    }

    // Assert that there is no multiple values for same key
    for (Set<Value> cell : result.values()) {
        for (Value val : cell) {
            for (Value otherVal : cell) {
                if (val != otherVal) {
                    assert val.getTimestamp() != otherVal.getTimestamp();
                }
            }
        }
    }

    return RowResult.create(row, result);
}

From source file:io.sarl.eclipse.wizards.elements.newagent.NewSarlAgentWizardPage.java

@Override
protected void getTypeContent(Resource ecoreResource, String typeComment) throws CoreException {
    GeneratedCode code = this.sarlGenerator.createScript(ecoreResource, getPackageFragment().getElementName());
    io.sarl.lang.sarl.Agent agent = this.sarlGenerator.createAgent(code, getTypeName(), getSuperClass());
    this.sarlGenerator.attachComment(code, agent, typeComment);

    Map<ActionKey, IMethod> operationsToImplement;

    if (isCreateInherited()) {
        operationsToImplement = Maps.newTreeMap((Comparator<ActionKey>) null);
    } else {/*from  w  w  w. j  av  a2 s.c o  m*/
        operationsToImplement = null;
    }

    populateInheritanceContext(Jdt2Ecore.toTypeFinder(getJavaProject()),
            // Discarding final operation.
            null,
            // Discarding overridable operation.
            null,
            // Discarding inherited fields,
            null, operationsToImplement,
            // Discarding super constructors,
            null, code.getCodeGenerator().getActionSignatureProvider(), getSuperClass(),
            Collections.<String>emptyList());

    if (operationsToImplement != null) {
        Jdt2Ecore.createActions(code, operationsToImplement.values(), agent);
    }

    code.finalizeScript();
}

From source file:io.sarl.eclipse.wizards.elements.aop.newagent.NewSarlAgentWizardPage.java

@Override
protected void getTypeContent(Resource ecoreResource, String typeComment) throws CoreException {
    IScriptBuilder scriptBuilder = this.codeBuilderFactory.createScript(getPackageFragment().getElementName(),
            ecoreResource);//from   w  ww  .  j  ava  2  s.c o m
    IAgentBuilder agent = scriptBuilder.addAgent(getTypeName());
    agent.setExtends(getSuperClass());
    agent.setDocumentation(typeComment.trim());

    Map<ActionPrototype, IMethod> operationsToImplement;

    if (isCreateInherited()) {
        operationsToImplement = Maps.newTreeMap((Comparator<ActionPrototype>) null);
    } else {
        operationsToImplement = null;
    }

    this.jdt2sarl.populateInheritanceContext(this.jdt2sarl.toTypeFinder(getJavaProject()),
            // Discarding final operation.
            null,
            // Discarding overridable operation.
            null,
            // Discarding inherited fields,
            null, operationsToImplement,
            // Discarding super constructors,
            null, getSuperClass(), Collections.<String>emptyList());

    if (operationsToImplement != null) {
        this.jdt2sarl.createActions(agent, operationsToImplement.values());
    }

    scriptBuilder.finalizeScript();
}

From source file:org.apache.pulsar.client.impl.conf.ProducerConfigurationData.java

public ProducerConfigurationData clone() {
    try {//  w ww . jav  a2 s  .c  om
        ProducerConfigurationData c = (ProducerConfigurationData) super.clone();
        c.encryptionKeys = Sets.newTreeSet(this.encryptionKeys);
        c.properties = Maps.newTreeMap(this.properties);
        return c;
    } catch (CloneNotSupportedException e) {
        throw new RuntimeException("Failed to clone ProducerConfigurationData", e);
    }
}

From source file:co.cask.cdap.data2.transaction.stream.inmemory.InMemoryStreamConsumerStateStore.java

@Override
protected void delete(byte[] row, Set<byte[]> columns) throws IOException {
    if (columns.isEmpty()) {
        return;/*from  www.j  ava2  s.  co  m*/
    }
    Map<byte[], byte[]> deleteColumns = Maps.newTreeMap(Bytes.BYTES_COMPARATOR);
    for (byte[] column : columns) {
        deleteColumns.put(column, Bytes.EMPTY_BYTE_ARRAY); // Value doesn't matter
    }
    byte[][] columnsArr = new byte[columns.size()][];
    int i = 0;
    for (byte[] column : columns) {
        columnsArr[i] = column;
        i++;
    }

    try {
        table.delete(row, columnsArr);
    } catch (Exception e) {
        throw new IOException(e);
    }
}