Example usage for java.util.concurrent ConcurrentSkipListMap get

List of usage examples for java.util.concurrent ConcurrentSkipListMap get

Introduction

In this page you can find the example usage for java.util.concurrent ConcurrentSkipListMap get.

Prototype

public V get(Object key) 

Source Link

Document

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

Usage

From source file:com.doctor.other.concurrent_hash_map_based_table.ConcurrentHashMapBasedTable.java

public List<T> get(final String rowKey, final String columnKey, final String timesplice) {
    Preconditions.checkState(StringUtils.isNotBlank(rowKey), "rowKey is blank");
    Preconditions.checkState(StringUtils.isNotBlank(columnKey), "columnKey is blank");
    Preconditions.checkState(StringUtils.isNotBlank(timesplice), "timesplice is blank");

    ConcurrentHashMap<String, ConcurrentSkipListMap<String, ConcurrentSet<T>>> row = table.get(rowKey);
    if (row == null) {
        return Arrays.asList();
    }/*from  ww  w. ja v a2s.  co  m*/

    ConcurrentSkipListMap<String, ConcurrentSet<T>> column = row.get(columnKey);
    if (column == null) {
        return Arrays.asList();
    }

    ConcurrentSet<T> values = column.get(timesplice);

    if (values == null) {
        return Arrays.asList();
    }

    return values.stream().collect(Collectors.toList());
}

From source file:com.doctor.other.concurrent_hash_map_based_table.ConcurrentHashMapBasedTable.java

/**
 * ?//  w  w w . j ava2 s  . c  o m
 */
public void clear() {
    for (String rowKey : table.keySet()) {
        ConcurrentHashMap<String, ConcurrentSkipListMap<String, ConcurrentSet<T>>> rowMap = table.get(rowKey);
        for (String columnKey : rowMap.keySet()) {
            ConcurrentSkipListMap<String, ConcurrentSet<T>> columnMap = rowMap.get(columnKey);

            Iterator<String> iterator = columnMap.keySet().iterator();
            while (iterator.hasNext()) {
                String timesplices = iterator.next();
                columnMap.get(timesplices).clear();
                iterator.remove();
            }

        }
        rowMap.clear();
    }

    table.clear();
}

From source file:com.doctor.other.concurrent_hash_map_based_table.ConcurrentHashMapBasedTable.java

/**
 * /* w w  w.  j av a2s . c  o m*/
 * @param rowKey
 * @param columnKey
 * @param timesplice
 *            ?:201572701
 * @param value
 * @return
 */
public boolean put(final String rowKey, final String columnKey, final String timesplice, final T value) {
    Preconditions.checkState(StringUtils.isNotBlank(rowKey), "rowKey is blank");
    Preconditions.checkState(StringUtils.isNotBlank(columnKey), "columnKey is blank");
    Preconditions.checkState(StringUtils.isNotBlank(timesplice), "timesplice is blank");
    Preconditions.checkNotNull(value, "value is null");

    ConcurrentHashMap<String, ConcurrentSkipListMap<String, ConcurrentSet<T>>> row = table.get(rowKey);
    if (row == null) {
        table.putIfAbsent(rowKey,
                new ConcurrentHashMap<String, ConcurrentSkipListMap<String, ConcurrentSet<T>>>());
    }

    row = table.get(rowKey);

    ConcurrentSkipListMap<String, ConcurrentSet<T>> column = row.get(columnKey);
    if (column == null) {
        row.putIfAbsent(columnKey, new ConcurrentSkipListMap<String, ConcurrentSet<T>>());
    }

    column = row.get(columnKey);

    ConcurrentSet<T> values = column.get(timesplice);
    if (values == null) {
        column.putIfAbsent(timesplice, new ConcurrentSet<>());
    }

    values = column.get(timesplice);
    return values.add(value);
}

From source file:com.doctor.other.concurrent_hash_map_based_table.ConcurrentHashMapBasedTable.java

private void pruneCache() {
    String expireTime = LocalDateTime.now().minusHours(ttl).format(Util.timeFormatter);
    log.info("{expireTime:{}}", expireTime);

    for (String rowKey : table.keySet()) {
        ConcurrentHashMap<String, ConcurrentSkipListMap<String, ConcurrentSet<T>>> rowMap = table.get(rowKey);
        for (String columnKey : rowMap.keySet()) {
            ConcurrentSkipListMap<String, ConcurrentSet<T>> columnMap = rowMap.get(columnKey);

            Iterator<String> iterator = columnMap.keySet().iterator();
            while (iterator.hasNext()) {
                String timesplices = iterator.next();
                if (timesplices.compareTo(expireTime) < 0) {
                    columnMap.get(timesplices).clear();
                    iterator.remove();/*from w  w w  . j  av  a 2  s .  co  m*/
                } else {
                    break;
                }
            }
        }
    }

}