Example usage for com.google.common.collect Maps unmodifiableNavigableMap

List of usage examples for com.google.common.collect Maps unmodifiableNavigableMap

Introduction

In this page you can find the example usage for com.google.common.collect Maps unmodifiableNavigableMap.

Prototype

@GwtIncompatible("NavigableMap")
public static <K, V> NavigableMap<K, V> unmodifiableNavigableMap(NavigableMap<K, V> map) 

Source Link

Document

Returns an unmodifiable view of the specified navigable map.

Usage

From source file:com.sector91.wit.Scripting.java

public static NavigableMap<String, ScriptEngineFactory> scriptEngines(ClassLoader cl) {
    final NavigableMap<String, ScriptEngineFactory> map = new TreeMap<>();
    final ScriptEngineManager mgr = new ScriptEngineManager(cl);
    for (ScriptEngineFactory factory : mgr.getEngineFactories()) {
        for (String ext : factory.getExtensions()) {
            map.put(ext, factory);/*from w w w .  ja  v a2  s  .c o  m*/
        }
    }
    return Maps.unmodifiableNavigableMap(map);
}

From source file:org.apache.storm.redis.state.RedisKeyValueState.java

private void initPendingCommit() {
    RedisCommands commands = null;//from  ww w.  j  ava  2 s  .  co m
    try {
        commands = container.getInstance();
        if (commands.exists(prepareNamespace)) {
            LOG.debug("Loading previously prepared commit from {}", prepareNamespace);
            NavigableMap<byte[], byte[]> pendingCommitMap = new TreeMap<>(
                    UnsignedBytes.lexicographicalComparator());
            pendingCommitMap.putAll(commands.hgetAll(prepareNamespace));
            pendingCommit = Maps.unmodifiableNavigableMap(pendingCommitMap);
        } else {
            LOG.debug("No previously prepared commits.");
            pendingCommit = EMPTY_PENDING_COMMIT_MAP;
        }
    } finally {
        container.returnInstance(commands);
    }
}

From source file:org.apache.storm.hbase.state.HBaseKeyValueState.java

private void initPendingCommit() {
    HBaseProjectionCriteria criteria = new HBaseProjectionCriteria();
    criteria.addColumnFamily(columnFamily);
    Get get = hbaseClient.constructGetRequests(prepareNamespace, criteria);
    try {/*from  ww w .  j av a2 s .co m*/
        Result[] results = hbaseClient.batchGet(Collections.singletonList(get));
        Result result = results[0];
        if (!result.isEmpty()) {
            LOG.debug("Loading previously prepared commit from {}", prepareNamespace);
            NavigableMap<byte[], byte[]> familyMap = result.getFamilyMap(columnFamily);
            pendingCommit = Maps.unmodifiableNavigableMap(familyMap);
        } else {
            LOG.debug("No previously prepared commits.");
            pendingCommit = EMPTY_PENDING_COMMIT_MAP;
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:org.apache.jackrabbit.oak.plugins.document.Document.java

/**
 * Transform and seal the data of this document. That is, the data becomes
 * immutable and transformation may be performed on the data.
 *
 * @param map the map to transform.//w  w  w  .j a  v a  2 s .  com
 * @param key the key for the given map or <code>null</code> if the map
 *            is the top level data map.
 * @param level the level. Zero for the top level map, one for an entry in
 *              the top level map, etc.
 * @return the transformed and sealed map.
 */
@Nonnull
protected Map<?, ?> transformAndSeal(@Nonnull Map<Object, Object> map, @Nullable String key, int level) {
    for (Map.Entry<Object, Object> entry : map.entrySet()) {
        Object value = entry.getValue();
        if (value instanceof Map) {
            @SuppressWarnings("unchecked")
            Map<Object, Object> childMap = (Map<Object, Object>) value;
            entry.setValue(transformAndSeal(childMap, entry.getKey().toString(), level + 1));
        }
    }
    if (map instanceof NavigableMap) {
        return Maps.unmodifiableNavigableMap((NavigableMap<Object, Object>) map);
    } else {
        return Collections.unmodifiableMap(map);
    }
}

From source file:org.apache.storm.redis.state.RedisKeyValueState.java

@Override
public void prepareCommit(long txid) {
    LOG.debug("prepareCommit txid {}", txid);
    validatePrepareTxid(txid);//from  w  ww . j a  v  a2 s  .  c o m
    RedisCommands commands = null;
    try {
        ConcurrentNavigableMap<byte[], byte[]> currentPending = pendingPrepare;
        pendingPrepare = createPendingPrepareMap();
        commands = container.getInstance();
        if (commands.exists(prepareNamespace)) {
            LOG.debug("Prepared txn already exists, will merge", txid);
            for (Map.Entry<byte[], byte[]> e : pendingCommit.entrySet()) {
                if (!currentPending.containsKey(e.getKey())) {
                    currentPending.put(e.getKey(), e.getValue());
                }
            }
        }
        if (!currentPending.isEmpty()) {
            commands.hmset(prepareNamespace, currentPending);
        } else {
            LOG.debug("Nothing to save for prepareCommit, txid {}.", txid);
        }
        txIds.put(PREPARE_TXID_KEY, String.valueOf(txid));

        commands.hmset(txidNamespace, txIds);
        pendingCommit = Maps.unmodifiableNavigableMap(currentPending);
    } finally {
        container.returnInstance(commands);
    }
}

From source file:org.apache.storm.hbase.state.HBaseKeyValueState.java

@Override
public void prepareCommit(long txid) {
    LOG.debug("prepareCommit txid {}", txid);
    validatePrepareTxid(txid);/*from ww w  . j a v a2s  .  c o  m*/

    try {
        ConcurrentNavigableMap<byte[], byte[]> currentPending = pendingPrepare;
        pendingPrepare = createPendingPrepareMap();

        Result result = getColumnFamily(prepareNamespace, columnFamily);
        if (!result.isEmpty()) {
            LOG.debug("Prepared txn already exists, will merge", txid);
            for (Map.Entry<byte[], byte[]> e : pendingCommit.entrySet()) {
                if (!currentPending.containsKey(e.getKey())) {
                    currentPending.put(e.getKey(), e.getValue());
                }
            }
        } else {
            LOG.debug("Nothing to save for prepareCommit, txid {}.", txid);
        }

        if (!currentPending.isEmpty()) {
            mutateRow(prepareNamespace, columnFamily, currentPending);
        } else {
            LOG.debug("Nothing to save for prepareCommit, txid {}.", txid);
        }

        txIds.put(PREPARE_TXID_KEY, String.valueOf(txid).getBytes());
        mutateRow(txidNamespace, columnFamily, txIds);
        pendingCommit = Maps.unmodifiableNavigableMap(currentPending);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:org.apache.jackrabbit.oak.plugins.document.NodeDocument.java

/**
 * Creates a map with previous revision ranges for this document. The
 * revision keys are sorted descending, newest first!
 *
 * @param includeStale whether stale revision ranges are included or not.
 * @return the previous ranges for this document.
 *///from ww  w.  ja  v a 2 s.c o  m
@Nonnull
private NavigableMap<Revision, Range> createPreviousRanges(boolean includeStale) {
    NavigableMap<Revision, Range> ranges;
    Map<Revision, String> map = getLocalMap(PREVIOUS);
    if (map.isEmpty()) {
        ranges = EMPTY_RANGE_MAP;
    } else {
        Map<Revision, String> stale = Collections.emptyMap();
        if (!includeStale) {
            stale = getLocalMap(STALE_PREV);
        }
        NavigableMap<Revision, Range> transformed = new TreeMap<Revision, Range>(REVERSE);
        for (Map.Entry<Revision, String> entry : map.entrySet()) {
            Range r = Range.fromEntry(entry.getKey(), entry.getValue());
            if (String.valueOf(r.height).equals(stale.get(r.high))) {
                continue;
            }
            transformed.put(r.high, r);
        }
        ranges = Maps.unmodifiableNavigableMap(transformed);
    }
    return ranges;
}