Example usage for java.util.concurrent ConcurrentNavigableMap tailMap

List of usage examples for java.util.concurrent ConcurrentNavigableMap tailMap

Introduction

In this page you can find the example usage for java.util.concurrent ConcurrentNavigableMap tailMap.

Prototype

ConcurrentNavigableMap<K, V> tailMap(K fromKey, boolean inclusive);

Source Link

Usage

From source file:com.sm.store.server.QueryIterator.java

private Iterator<Key> buildRest(Predicate predicate) {
    if (!sorted) {
        tableScan = true;//w w w  .  j  a  va  2 s .c o m
        return remoteStore.getStore().getMap().keySet().iterator();
    } else {
        boolean inclusive = (predicate.getOperator() == GreaterEQ
                || predicate.getOperator() == Predicate.Operator.LessEQ) ? true : false;
        ConcurrentNavigableMap sortedStore = (ConcurrentNavigableMap) ((RemoteScanStore) remoteStore)
                .getSortedStore().getMap();
        if (predicate.getOperator() == Predicate.Operator.GreaterEQ
                || predicate.getOperator() == Predicate.Operator.Greater) {
            Key from = createKey(predicate.right().getValue(), keyType);
            return sortedStore.tailMap(from, inclusive).keySet().iterator();
        } else {
            Key from = createKey(predicate.right().getValue(), keyType);
            return sortedStore.headMap(from, inclusive).keySet().iterator();
        }
    }
}

From source file:com.palantir.atlasdb.transaction.impl.SerializableTransaction.java

private void verifyRows(Transaction ro) {
    for (String table : rowsRead.keySet()) {
        final ConcurrentNavigableMap<Cell, byte[]> readsForTable = getReadsForTable(table);
        Multimap<ColumnSelection, byte[]> map = Multimaps.newSortedSetMultimap(
                Maps.<ColumnSelection, Collection<byte[]>>newHashMap(), new Supplier<SortedSet<byte[]>>() {
                    @Override/*  www  . j  ava  2 s .  c om*/
                    public TreeSet<byte[]> get() {
                        return Sets.newTreeSet(UnsignedBytes.lexicographicalComparator());
                    }
                });
        for (RowRead r : rowsRead.get(table)) {
            map.putAll(r.cols, r.rows);
        }
        for (final ColumnSelection cols : map.keySet()) {
            for (List<byte[]> batch : Iterables.partition(map.get(cols), 1000)) {
                SortedMap<byte[], RowResult<byte[]>> currentRows = ro.getRows(table, batch, cols);
                for (byte[] row : batch) {
                    RowResult<byte[]> currentRow = currentRows.get(row);
                    Map<Cell, byte[]> orignalReads = readsForTable
                            .tailMap(Cells.createSmallestCellForRow(row), true)
                            .headMap(Cells.createLargestCellForRow(row), true);

                    // We want to filter out all our reads to just the set that matches our column selection.
                    orignalReads = Maps.filterKeys(orignalReads, new Predicate<Cell>() {
                        @Override
                        public boolean apply(Cell input) {
                            return cols.contains(input.getColumnName());
                        }
                    });

                    if (writesByTable.get(table) != null) {
                        // We don't want to verify any reads that we wrote to cause we will just read our own values.
                        // NB: We filter our write set out here because our normal SI checking handles this case to ensure the value hasn't changed.
                        orignalReads = Maps.filterKeys(orignalReads,
                                Predicates.not(Predicates.in(writesByTable.get(table).keySet())));
                    }

                    if (currentRow == null && orignalReads.isEmpty()) {
                        continue;
                    }

                    if (currentRow == null) {
                        throw TransactionSerializableConflictException.create(table, getTimestamp(),
                                System.currentTimeMillis() - timeCreated);
                    }

                    Map<Cell, byte[]> currentCells = Maps2.fromEntries(currentRow.getCells());
                    if (writesByTable.get(table) != null) {
                        // We don't want to verify any reads that we wrote to cause we will just read our own values.
                        // NB: We filter our write set out here because our normal SI checking handles this case to ensure the value hasn't changed.
                        currentCells = Maps.filterKeys(currentCells,
                                Predicates.not(Predicates.in(writesByTable.get(table).keySet())));
                    }
                    if (!areMapsEqual(orignalReads, currentCells)) {
                        throw TransactionSerializableConflictException.create(table, getTimestamp(),
                                System.currentTimeMillis() - timeCreated);
                    }
                }
            }
        }

    }
}