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:co.cask.cdap.data2.transaction.stream.StreamConsumerStateStore.java

@Override
public final void getByGroup(long groupId, Collection<? super StreamConsumerState> result) throws IOException {
    SortedMap<byte[], byte[]> states = Maps.newTreeMap(Bytes.BYTES_COMPARATOR);
    fetchAll(streamId.toBytes(), Bytes.toBytes(groupId), states);

    for (Map.Entry<byte[], byte[]> entry : states.entrySet()) {
        byte[] column = entry.getKey();
        if (getGroupId(column) != groupId) {
            continue;
        }// w w w  .  j  av a  2s  .c om
        byte[] value = entry.getValue();
        if (value != null) {
            result.add(new StreamConsumerState(groupId, getInstanceId(column), decodeOffsets(value)));
        }
    }
}

From source file:org.fenixedu.learning.domain.degree.components.DegreeExecutionCoursesComponent.java

public SortedMap<ExecutionSemester, SortedMap<Integer, SortedSet<ExecutionCourse>>> executionCourses(
        final Degree degree) {
    TreeMap<ExecutionSemester, SortedMap<Integer, SortedSet<ExecutionCourse>>> result = Maps
            .newTreeMap(COMPARATOR_BY_SEMESTER_AND_YEAR);

    final ExecutionSemester current = ExecutionSemester.readActualExecutionSemester();
    final ExecutionSemester previous = current.getPreviousExecutionPeriod();
    final ExecutionSemester next = current.getNextExecutionPeriod();
    final boolean hasNext = next.getExecutionYear().isCurrent() && next != null
            && next.getState().equals(PeriodState.OPEN);
    final ExecutionSemester selected = hasNext ? next : previous;

    result.put(selected, executionCourses(degree, selected));
    result.put(current, executionCourses(degree, current));
    return result;
}

From source file:co.cask.cdap.data2.dataset2.lib.table.inmemory.InMemoryOrderedTableService.java

private static void merge(
        ConcurrentNavigableMap<byte[], NavigableMap<byte[], NavigableMap<Long, Update>>> table, byte[] row,
        Map<byte[], Update> changes, long version) {
    // get the correct row from the table, create it if it doesn't exist
    NavigableMap<byte[], NavigableMap<Long, Update>> rowMap = table.get(row);
    if (rowMap == null) {
        rowMap = Maps.newTreeMap(Bytes.BYTES_COMPARATOR);
        table.put(row, rowMap);// w ww  .  j a va2 s  .  c  o  m
    }
    // now merge the changes into the row, one by one
    for (Map.Entry<byte[], Update> keyVal : changes.entrySet()) {
        // create the column in the row if it does not exist
        NavigableMap<Long, Update> colMap = rowMap.get(keyVal.getKey());
        if (colMap == null) {
            colMap = Maps.newTreeMap();
            rowMap.put(keyVal.getKey(), colMap);
        }
        // put into the column with given version
        Update merged = Updates.mergeUpdates(colMap.get(version), keyVal.getValue());
        colMap.put(version, merged);
    }
}

From source file:org.greatlogic.gxtexamples.client.glgwt.GLValueMap.java

/**
 * Creates a new value map by copying the entries from an existing <code>GLValueMap</code>.
 * @param valueMap The existing value map.
 *///from   w w w  . j ava  2 s  .  co m
public GLValueMap(final GLValueMap valueMap) {
    _skipKeyUnderscores = valueMap._skipKeyUnderscores;
    _valueMap = Maps.newTreeMap(valueMap._valueMap);
}

From source file:eu.interedition.collatex.util.ParallelSegmentationApparatus.java

public static void generate(VariantGraphRanking ranking, GeneratorCallback callback) {

    callback.start();//from w w  w.java  2 s.  co m

    final Set<Witness> allWitnesses = ranking.witnesses();
    for (Iterator<Map.Entry<Integer, Collection<VariantGraph.Vertex>>> rowIt = ranking.getByRank().asMap()
            .entrySet().iterator(); rowIt.hasNext();) {
        final Map.Entry<Integer, Collection<VariantGraph.Vertex>> row = rowIt.next();
        final int rank = row.getKey();
        final Collection<VariantGraph.Vertex> vertices = row.getValue();

        if (vertices.size() == 1 && Iterables.getOnlyElement(vertices).tokens().isEmpty()) {
            // skip start and end vertex
            continue;
        }

        // spreading vertices with same rank according to their registered transpositions
        final Multimap<Integer, VariantGraph.Vertex> verticesByTranspositionRank = HashMultimap.create();
        for (VariantGraph.Vertex v : vertices) {
            int transpositionRank = 0;
            for (VariantGraph.Transposition transposition : v.transpositions()) {
                for (VariantGraph.Vertex tv : transposition) {
                    transpositionRank += (ranking.apply(tv).intValue() - rank);
                }
            }
            verticesByTranspositionRank.put(transpositionRank, v);
        }

        // render segments
        for (Iterator<Integer> transpositionRankIt = Ordering.natural()
                .immutableSortedCopy(verticesByTranspositionRank.keySet()).iterator(); transpositionRankIt
                        .hasNext();) {
            final Multimap<Witness, Token> tokensByWitness = HashMultimap.create();
            for (VariantGraph.Vertex v : verticesByTranspositionRank.get(transpositionRankIt.next())) {
                for (Token token : v.tokens()) {
                    tokensByWitness.put(token.getWitness(), token);
                }
            }

            final SortedMap<Witness, Iterable<Token>> cellContents = Maps.newTreeMap(Witness.SIGIL_COMPARATOR);
            for (Witness witness : allWitnesses) {
                cellContents.put(witness,
                        tokensByWitness.containsKey(witness)
                                ? Iterables.unmodifiableIterable(tokensByWitness.get(witness))
                                : Collections.<Token>emptySet());
            }

            callback.segment(cellContents);
        }
    }

    callback.end();
}

From source file:com.google.caliper.runner.ResultDataWriter.java

/**
 * Writes a copy of the given {@code env} to the {@code CaliperData}. This method uses the given
 * environment's localName if it's set; otherwise, it assigns a meaningless localName to the copy.
 *///ww w .  j a  va2s .co m
public String writeEnvironment(Environment env) {
    Preconditions.checkState(run.environments.isEmpty());
    Environment copy = new Environment();
    copy.properties = Maps.newTreeMap(env.properties);
    copy.localName = Objects.firstNonNull(env.localName, "A");
    run.environments.add(copy);
    return copy.localName;
}

From source file:co.cask.cdap.data2.transaction.stream.leveldb.LevelDBStreamFileConsumer.java

/**
 * @param streamConfig   Stream configuration.
 * @param consumerConfig Consumer configuration.
 * @param reader         For reading stream events. This class is responsible for closing the reader.
 *///  w w  w .ja  va  2s. co  m
public LevelDBStreamFileConsumer(CConfiguration cConf, StreamConfig streamConfig, ConsumerConfig consumerConfig,
        FileReader<StreamEventOffset, Iterable<StreamFileOffset>> reader, StreamConsumerStateStore stateStore,
        StreamConsumerState beginConsumerState, @Nullable ReadFilter extraFilter, LevelDBTableCore tableCore,
        Object dbLock) {
    super(cConf, streamConfig, consumerConfig, reader, stateStore, beginConsumerState, extraFilter);
    this.tableCore = tableCore;
    this.dbLock = dbLock;
    this.rowMapForClaim = Maps.newTreeMap(Bytes.BYTES_COMPARATOR);
    this.colMapForClaim = Maps.newTreeMap(Bytes.BYTES_COMPARATOR);
}

From source file:org.apache.isis.core.runtime.services.ServicesInstallerFromConfigurationAndAnnotation.java

@Override
public List<Object> getServices() {
    LOG.info("installing " + this.getClass().getName());

    if (serviceList == null) {

        final SortedMap<String, SortedSet<String>> positionedServices = Maps
                .newTreeMap(new DeweyOrderComparator());
        servicesInstallerFromConfiguration.appendServices(positionedServices);
        servicesInstallerFromAnnotation.appendServices(positionedServices);

        serviceList = ServicesInstallerUtils.instantiateServicesFrom(positionedServices, serviceInstantiator);
    }//from  ww w .ja v  a2 s  . c  o  m

    return serviceList;
}

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

/**
 * Creates a new {@link AliasRegistry} with the given registry as its
 * parent./*w w  w  .j ava2 s  .  c om*/
 * 
 * @param name The registry name
 * @param parent the parent registry
 */
public CommonAliasRegistry(String name, AliasRegistry parent) {
    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 = Gunsmith.getConfiguration().get("caseSensitiveAliases", Boolean.class).or(true); // default
                                                                                                          // to
                                                                                                          // non-action
    this.registryName = name;
}

From source file:com.palantir.atlasdb.keyvalue.remoting.serialization.RowResultDeserializer.java

private SortedMap<byte[], Set<Long>> deserializeWithTimestamps(JsonNode node, DeserializationContext ctxt)
        throws IOException {
    SortedMap<byte[], Set<Long>> result = Maps.newTreeMap(UnsignedBytes.lexicographicalComparator());
    Iterator<JsonNode> it = node.get("columns").elements();
    while (it.hasNext()) {
        JsonNode col = it.next();/*from  w  w w.  jav a 2  s . c  o m*/
        byte[] colName = col.get("column").binaryValue();
        Set<Long> timestamps = Sets.newHashSet();
        Iterator<JsonNode> colIt = col.get("timestamps").elements();
        while (colIt.hasNext()) {
            JsonNode colVal = colIt.next();
            long timestamp = colVal.asLong();
            timestamps.add(timestamp);
        }
        result.put(colName, timestamps);
    }
    return result;
}