List of usage examples for java.util.concurrent ConcurrentSkipListMap putIfAbsent
public V putIfAbsent(K key, V value)
From source file:com.doctor.other.concurrent_hash_map_based_table.ConcurrentHashMapBasedTable.java
/** * /*from w ww . j a v 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); }