Search in sources :

Example 1 with NoOrder

use of com.cinchapi.concourse.lang.sort.NoOrder in project concourse by cinchapi.

the class Operations method getKeyRecordsOptionalAtomic.

/**
 * From {@code store}, get the most recently stored value at
 * {@code timestamp} for {@code key} in each of the {@code records}.
 *
 * <p>
 * If possible, apply the {@code order} and {@code page} parameters to the
 * result set.
 * </p>
 *
 * @param store
 * @param key
 * @param records
 * @param timestamp
 * @param order
 * @param page
 * @param supplier a {@link Supplier} of a {@link Sortable} in which the
 *            results can be gathered
 * @return the result set - a {@link Map} from each of the relevant
 *         {@code records} to the most recently stored value for {@code key}
 */
public static <M extends Map<Long, TObject> & Sortable<TObject>> Map<Long, TObject> getKeyRecordsOptionalAtomic(Store store, String key, Iterable<Long> records, long timestamp, Order order, Page page, Supplier<M> supplier) {
    M data = supplier.get();
    if (order instanceof NoOrder) {
        // If page == NoPage, this is a no-op; otherwise, apply the
        // pagination directly to the input records so that we don't fetch
        // more data than required.
        records = Paging.page(records, page);
        page = NoPage.INSTANCE;
    }
    for (long record : records) {
        try {
            Set<TObject> values = timestamp == Time.NONE ? Stores.select(store, key, record) : Stores.select(store, key, record, timestamp);
            TObject value = Iterables.getLast(values);
            data.put(record, value);
        } catch (NoSuchElementException e) {
            continue;
        }
    }
    if (timestamp == Time.NONE) {
        data.sort(Sorting.byValue(order, store));
    } else {
        data.sort(Sorting.byValue(order, store), timestamp);
    }
    // a no-op
    return Paging.page(data, page);
}
Also used : TObject(com.cinchapi.concourse.thrift.TObject) NoOrder(com.cinchapi.concourse.lang.sort.NoOrder) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

NoOrder (com.cinchapi.concourse.lang.sort.NoOrder)1 TObject (com.cinchapi.concourse.thrift.TObject)1 NoSuchElementException (java.util.NoSuchElementException)1