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.codehaus.httpcache4j.cache.Vary.java

/**
 * Constructor//from w w  w. ja va2s.c o m
 *
 * @param headers the vary headers as keys from the response, with request headers as values.
 */
public Vary(final Map<String, String> headers) {
    Validate.notNull(headers, "Headers may not be null");
    Map<String, String> h = Maps.newTreeMap(new VaryComparator());
    h.putAll(headers);
    varyHeaders = Collections.unmodifiableMap(h);
}

From source file:org.apache.kylin.storage.hbase.lookup.HBaseLookupRowEncoder.java

@Override
public HBaseRow encode(String[] row) {
    String[] keys = getKeyData(row);
    String[] values = getValueData(row);
    byte[] rowKey = encodeRowKey(keys);
    NavigableMap<byte[], byte[]> qualifierValMap = Maps
            .newTreeMap(org.apache.hadoop.hbase.util.Bytes.BYTES_COMPARATOR);
    for (int i = 0; i < values.length; i++) {
        byte[] qualifier = Bytes.toBytes(String.valueOf(valueIndexes[i]));
        byte[] byteValue = toBytes(values[i]);
        qualifierValMap.put(qualifier, byteValue);
    }/*from   ww w.j ava2 s .com*/
    return new HBaseRow(rowKey, qualifierValMap);
}

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

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

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

From source file:de.cosmocode.palava.ipc.session.Entries.java

@Override
public void execute(IpcCall call, Map<String, Object> result) throws IpcCommandExecutionException {
    final IpcArguments arguments = call.getArguments();
    final boolean sort = arguments.getBoolean(Naming.SORT, false);
    final String namespace = arguments.getString(Naming.NAMESPACE, null);
    final IpcSession session = call.getConnection().getSession();

    final Map<Object, Object> entries = sort ? Maps.newTreeMap(ordering) : Maps.newHashMap();

    if (namespace == null) {
        entries.putAll(session);//from  w  w w.  j av  a  2s  . c om
    } else if (session.containsKey(namespace)) {
        @SuppressWarnings("unchecked")
        final Map<Object, Object> namespaced = (Map<Object, Object>) session.get(namespace);
        entries.putAll(namespaced);
    }

    result.put(Naming.ENTRIES, entries);
}

From source file:org.codehaus.httpcache4j.cache.Vary.java

public Vary(Headers headers) {
    Map<String, String> h = Maps.newTreeMap(new VaryComparator());
    for (Header header : headers) {
        h.put(header.getName(), header.getValue());
    }//ww  w. j a  v a2s . c o  m
    varyHeaders = Collections.unmodifiableMap(h);
}

From source file:be.nbb.xdb.DbRawDataUtil.java

@Nonnull
@SuppressWarnings("null")
public static <C, T extends Throwable> CheckedIterator<Object[], T> distinct(
        @Nonnull CheckedIterator<Object[], T> rows, @Nonnull List<C> selectColumns,
        @Nonnull ToIntFunction<C> toIndex, @Nonnull Function<C, SuperDataType> toDataType,
        @Nonnull BiConsumer<Object[], Object[]> aggregator) throws T {

    TreeMap<Object[], Object[]> result = Maps.newTreeMap(newRowOrdering(selectColumns, toIndex, toDataType));
    Equivalence<Object[]> equivalence = newRowEquivalence(selectColumns, toIndex);
    Object[] first = null;/*from w w w .j a  v a  2 s .  com*/
    while (rows.hasNext()) {
        Object[] current = rows.next();
        // pre-check to avoid using TreeMap#get(Object)
        if (!equivalence.equivalent(first, current)) {
            first = result.get(current);
            if (first == null) {
                result.put(current, current);
                first = current;
            } else {
                aggregator.accept(first, current);
            }
        } else {
            aggregator.accept(first, current);
        }
    }
    return new SizedCheckedIterator(result.keySet());
}

From source file:com.google.caliper.json.NaturallySortedMapTypeAdapterFactory.java

@SuppressWarnings("unchecked")
@Override//from  www  . jav a  2  s .c  om
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> typeToken) {
    Type type = typeToken.getType();
    if (!CLASSES.contains(typeToken.getRawType()) || !(type instanceof ParameterizedType)) {
        return null;
    }

    com.google.common.reflect.TypeToken<SortedMap<?, ?>> betterToken = (com.google.common.reflect.TypeToken<SortedMap<?, ?>>) com.google.common.reflect.TypeToken
            .of(typeToken.getType());
    final TypeAdapter<Map<?, ?>> mapAdapter = (TypeAdapter<Map<?, ?>>) gson
            .getAdapter(TypeToken.get(betterToken.getSupertype(Map.class).getType()));
    return new TypeAdapter<T>() {
        @Override
        public void write(JsonWriter out, T value) throws IOException {
            TreeMap<?, ?> treeMap = Maps.newTreeMap((SortedMap<?, ?>) value);
            mapAdapter.write(out, treeMap);
        }

        @SuppressWarnings("rawtypes")
        @Override
        public T read(JsonReader in) throws IOException {
            TreeMap treeMap = Maps.newTreeMap();
            treeMap.putAll(mapAdapter.read(in));
            return (T) treeMap;
        }
    };
}

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

private SortedMap<byte[], Value> deserializeWithValue(JsonNode node, DeserializationContext ctxt)
        throws IOException {
    SortedMap<byte[], Value> result = Maps.newTreeMap(UnsignedBytes.lexicographicalComparator());
    Iterator<JsonNode> it = node.get("columns").elements();
    while (it.hasNext()) {
        JsonNode col = it.next();//w ww .  j av a2 s . c o  m
        byte[] colName = col.get("column").binaryValue();
        byte[] contents = col.get("contents").binaryValue();
        long timestamp = col.get("timestamp").asLong();
        result.put(colName, Value.create(contents, timestamp));
    }
    return result;
}

From source file:co.cask.cdap.data2.transaction.queue.leveldb.LevelDBQueueProducer.java

@Override
protected int persist(Iterable<QueueEntry> entries, Transaction transaction) throws Exception {
    long writePointer = transaction.getWritePointer();
    byte[] rowKeyPrefix = Bytes.add(queueRowPrefix, Bytes.toBytes(writePointer));
    int count = 0;
    int bytes = 0;

    for (QueueEntry entry : entries) {
        // Row key = queue_name + writePointer + counter
        byte[] rowKey = Bytes.add(rowKeyPrefix, Bytes.toBytes(count++));
        NavigableMap<byte[], byte[]> row = Maps.newTreeMap(Bytes.BYTES_COMPARATOR);
        row.put(QueueEntryRow.DATA_COLUMN, entry.getData());
        row.put(QueueEntryRow.META_COLUMN, QueueEntry.serializeHashKeys(entry.getHashKeys()));
        changes.put(rowKey, row);//from  w  ww.j a  va  2  s  .com
        bytes += entry.getData().length;
    }
    // TODO introduce a constant in the OcTableCore for the latest timestamp
    core.persist(changes, KeyValue.LATEST_TIMESTAMP);

    return bytes;
}

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

/**
 * Creates a new value map for storing values by key. The keys can be <code>String</code> values or
 * <code>IGLXMLAttribute</code> values.
 * @param skipKeyUnderscores If the key values contain underscores then the key will be stripped up
 * to and including the last underscore.
 *//*from w  w w . j a  va  2  s .c  o  m*/
public GLValueMap(final boolean skipKeyUnderscores) {
    _skipKeyUnderscores = skipKeyUnderscores;
    _valueMap = Maps.newTreeMap(String.CASE_INSENSITIVE_ORDER);
}