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.apache.pulsar.client.impl.MessageImpl.java

MessageImpl(BatchMessageIdImpl batchMessageIdImpl, MessageMetadata msgMetadata,
        PulsarApi.SingleMessageMetadata singleMessageMetadata, ByteBuf payload, ClientCnx cnx) {
    this.msgMetadataBuilder = MessageMetadata.newBuilder(msgMetadata);
    this.messageId = batchMessageIdImpl;
    this.cnx = cnx;

    this.payload = Unpooled.copiedBuffer(payload);

    if (singleMessageMetadata.getPropertiesCount() > 0) {
        Map<String, String> properties = Maps.newTreeMap();
        for (KeyValue entry : singleMessageMetadata.getPropertiesList()) {
            properties.put(entry.getKey(), entry.getValue());
        }/*from  w ww  . ja v  a  2 s .  co m*/
        this.properties = Collections.unmodifiableMap(properties);
    } else {
        properties = Collections.emptyMap();
    }
}

From source file:com.android.tools.idea.sdk.SdkPackages.java

private void computeUpdates() {
    Map<String, UpdatablePkgInfo> newConsolidatedPkgs = Maps.newTreeMap();
    UpdatablePkgInfo[] updatablePkgInfos = new UpdatablePkgInfo[myLocalPkgInfos.length];
    for (int i = 0; i < myLocalPkgInfos.length; i++) {
        updatablePkgInfos[i] = new UpdatablePkgInfo(myLocalPkgInfos[i]);
    }//from  w  ww  .ja  v  a2s .  c  o  m
    Set<RemotePkgInfo> updates = Sets.newTreeSet();

    // Find updates to locally installed packages
    for (UpdatablePkgInfo info : updatablePkgInfos) {
        IPkgDesc localDesc = info.getLocalInfo().getDesc();
        for (RemotePkgInfo remote : myRemotePkgInfos.get(localDesc.getType())) {
            if (remote.getPkgDesc().isUpdateFor(localDesc, FullRevision.PreviewComparison.IGNORE)) {
                info.addRemote(remote);
                myUpdatedPkgs.add(info);
                updates.add(remote);
            }
        }
        // the consolidated packages map is always keyed by the non-preview installid, whether or not the UpdatablePackage happens to
        // contain a preview package.
        newConsolidatedPkgs.put(info.getPkgDesc(true).getBaseInstallId(), info);
    }

    // Find new packages not yet installed
    nextRemote: for (RemotePkgInfo remote : myRemotePkgInfos.values()) {
        if (updates.contains(remote)) {
            // if package is already a known update, it's not new.
            continue nextRemote;
        }
        IPkgDesc remoteDesc = remote.getPkgDesc();
        for (UpdatablePkgInfo info : updatablePkgInfos) {
            IPkgDesc localDesc = info.getLocalInfo().getDesc();
            if (remoteDesc.compareTo(localDesc) == 0
                    || remoteDesc.isUpdateFor(localDesc, FullRevision.PreviewComparison.IGNORE)
                    || localDesc.isUpdateFor(remoteDesc,
                            FullRevision.PreviewComparison.IGNORE) /* shouldn't happen in the normal case */) {
                // if package is same as an installed or is an update for an installed
                // one, then it's not new.
                continue nextRemote;
            }
        }

        myNewPkgs.add(remote);
        String key = remoteDesc.getBaseInstallId();
        UpdatablePkgInfo existing = newConsolidatedPkgs.get(key);
        if (existing != null) {
            existing.addRemote(remote);
        } else {
            newConsolidatedPkgs.put(key, new UpdatablePkgInfo(remote));
        }
    }
    myConsolidatedPkgs = newConsolidatedPkgs;
}

From source file:de.blizzy.documentr.page.CherryPicker.java

@Override
public SortedMap<String, List<CommitCherryPickResult>> cherryPick(String projectName, String branchName,
        String path, List<String> commits, Set<String> targetBranches,
        Set<CommitCherryPickConflictResolve> conflictResolves, boolean dryRun, User user, Locale locale)
        throws IOException {

    Assert.hasLength(projectName);/*  w  w w .jav  a2 s  .  co m*/
    Assert.hasLength(path);
    Assert.notEmpty(commits);
    Assert.notEmpty(targetBranches);
    Assert.notNull(conflictResolves);
    Assert.notNull(user);

    // always do a dry run first and return early if it fails
    if (!dryRun) {
        SortedMap<String, List<CommitCherryPickResult>> results = cherryPick(projectName, branchName, path,
                commits, targetBranches, conflictResolves, true, user, locale);
        for (List<CommitCherryPickResult> branchResults : results.values()) {
            for (CommitCherryPickResult result : branchResults) {
                if (result.getStatus() != CommitCherryPickResult.Status.OK) {
                    return results;
                }
            }
        }
    }

    try {
        SortedMap<String, List<CommitCherryPickResult>> results = Maps.newTreeMap();
        for (String targetBranch : targetBranches) {
            List<CommitCherryPickResult> branchResults = cherryPick(projectName, branchName, path, commits,
                    targetBranch, conflictResolves, dryRun, user, locale);
            results.put(targetBranch, branchResults);
        }
        return results;
    } catch (GitAPIException e) {
        throw new IOException(e);
    }
}

From source file:org.locationtech.geogig.cli.porcelain.Init.java

public static Map<String, String> splitConfig(final String configArg) {
    Map<String, String> configProps = Maps.newTreeMap();
    if (configArg != null) {
        String[] options = configArg.split(",");
        for (String option : options) {
            String[] kv = option.split("=", 2);
            if (kv.length < 2)
                continue;
            configProps.put(kv[0], kv[1]);
        }//ww w . j  ava  2 s .  com
    }
    return configProps;
}

From source file:com.romeikat.datamessie.core.base.dao.impl.AbstractEntityWithIdAndVersionDao.java

private TreeMap<Long, Long> transformIntoMap(final List<IdAndVersion> idsAndVersions) {
    final TreeMap<Long, Long> result = Maps.newTreeMap();
    for (final IdAndVersion idAndVersion : idsAndVersions) {
        result.put(idAndVersion.getId(), idAndVersion.getVersion());
    }/*from   ww  w.  j a v a 2s  .co m*/
    return result;
}

From source file:com.huawei.streaming.cql.semanticanalyzer.CreateDatasourceAnalyzer.java

private void parseStreamProperties() {
    TreeMap<String, String> properties = Maps.newTreeMap();

    StreamPropertiesContext propertiesContext = context.getDataSourceProperties();
    if (propertiesContext == null) {
        analyzeContext.setDatasourceConfigs(properties);
        return;//from   w w  w.j a v  a2s  .  c o  m
    }

    List<KeyValuePropertyContext> propertyList = propertiesContext.getProperties();

    for (KeyValuePropertyContext ctx : propertyList) {
        String key = ctx.getKey();
        String value = ctx.getValue();
        properties.put(key, value);
    }

    analyzeContext.setDatasourceConfigs(properties);
}

From source file:ru.runa.wfe.ss.cache.AltSubstitutionCacheImpl.java

private void loadCacheFor(Long actorId) {
    TreeMap<Substitution, HashSet<Long>> result = Maps.newTreeMap();
    for (Substitution substitution : substitutionDao.getByActorId(actorId, true)) {
        HashSet<Long> substitutors = loadCacheFor(actorId, substitution);
        result.put(substitution, substitutors);
    }//  www .j a  va 2s  .  c  om
    actorToSubstitutorsCache.put(actorId, result);
}

From source file:com.eucalyptus.stats.SystemMetric.java

public void setValues(Map<String, Object> sensorValues) {
    //Use sorted structure
    this.values = Maps.newTreeMap();
    if (sensorValues != null) {
        this.values.putAll(sensorValues);
    }//w w  w.  j a va2s.  c o m
}

From source file:com.ibm.vicos.kvs.KVSOperationProcessor.java

public AuthExecResult authexec(List<Operation> operations, Authenticator authenticator, Result result,
        AuxiliaryData auxiliaryData) {//from   w w w.  j a  va 2s. com
    LOG.trace("Authexec {}, {}, {}", operations, authenticator, result);
    TreeMap<String, String> data = Maps.newTreeMap();
    data.putAll(auxiliaryData.getData());
    KVSState state = new KVSState(data);

    // verify current state
    String a = cryptoUtils.hash(state.items());
    if (!authenticator.getValue().equals(a)) {
        throw new IntegrityException(
                "Integrity violation! Expected: " + authenticator.getValue() + " but found: " + a);
    }

    Result ourResult = execute(state, operations);
    boolean isValid = result.equals(ourResult);
    if (!isValid) {
        LOG.debug("Result expected: {}", result);
        LOG.debug("Result actual: {}", ourResult);
    }

    long sequenceNumber = operations.stream().reduce((prev, next) -> next).get().getSequenceNumber();

    Authenticator newAuthenticator = Authenticator.newBuilder().setValue(cryptoUtils.hash(state.items()))
            .setSequenceNumber(sequenceNumber).build();

    return AuthExecResult.builder().setAuthenticator(newAuthenticator).setAuxiliaryData(state.toAuxiliaryData())
            .setValid(isValid).build();
}

From source file:org.eclipse.wb.core.gef.policy.validator.CompatibleLayoutRequestValidator.java

private static boolean executeScriptBoolean(String script, Object parent, Object child) throws Exception {
    Map<String, Object> variables = Maps.newTreeMap();
    variables.put("parent", parent);
    variables.put("child", child);
    return (Boolean) ScriptUtils.evaluate(DEF_functions + script, variables);
}