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

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

Introduction

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

Prototype

public static <C, K extends C, V> TreeMap<K, V> newTreeMap(@Nullable Comparator<C> comparator) 

Source Link

Document

Creates a mutable, empty TreeMap instance using the given comparator.

Usage

From source file:com.palantir.atlasdb.keyvalue.partition.util.RowResultUtil.java

public static RowResult<Value> mergeResults(PeekingIterator<RowResult<Value>> it,
        QuorumParameters.QuorumRequestParameters quorumRequestParameters) {
    Preconditions.checkArgument(it.hasNext());

    byte[] row = it.peek().getRowName();
    final SortedMap<byte[], Value> result = Maps.newTreeMap(UnsignedBytes.lexicographicalComparator());
    int failCount = 0;
    int succCount = 0;
    RuntimeException lastSuppressedException = null;

    while (it.hasNext() && Arrays.equals(it.peek().getRowName(), row)) {
        try {/* ww  w  .j  a  v  a2s. c om*/
            for (Map.Entry<Cell, Value> e : it.next().getCells()) {
                final byte[] col = e.getKey().getColumnName();

                // Assert that there is not contradictory data
                if (result.containsKey(col) && e.getValue().getTimestamp() == result.get(col).getTimestamp()) {
                    assert Arrays.equals(result.get(col).getContents(), e.getValue().getContents());
                }

                if (!result.containsKey(col) || result.get(col).getTimestamp() < e.getValue().getTimestamp()) {
                    result.put(col, e.getValue());
                }
            }
            succCount++;
        } catch (RuntimeException e) {
            System.err.println("Could not read for rangeRequest.");
            failCount++;
            if (failCount >= quorumRequestParameters.getFailureFactor()) {
                throw Throwables.rewrapAndThrowUncheckedException("Could not get enough reads.", e);
            }
            lastSuppressedException = e;
        }
    }

    if (succCount < quorumRequestParameters.getSuccessFactor()) {
        if (lastSuppressedException != null) {
            throw lastSuppressedException;
        } else {
            throw new RuntimeException("Not enough reads for row " + Arrays.toString(row));
        }
    }

    return RowResult.create(row, result);
}

From source file:org.apache.apex.malhar.lib.state.managed.ManagedStateTestUtils.java

/**
 * Validates the bucket data on the File System.
 * @param fileAccess        file access//  w  w w . j  a v a 2s .  com
 * @param bucketId          bucket id
 * @param unsavedBucket     bucket data to compare with.
 * @param keysPerTimeBucket num keys per time bucket
 * @throws IOException
 */
public static void validateBucketOnFileSystem(FileAccess fileAccess, long bucketId,
        Map<Slice, Bucket.BucketedValue> unsavedBucket, int keysPerTimeBucket) throws IOException {
    RemoteIterator<LocatedFileStatus> iterator = fileAccess.listFiles(bucketId);
    TreeMap<Slice, Slice> fromDisk = Maps.newTreeMap(new SliceComparator());
    int size = 0;
    while (iterator.hasNext()) {
        LocatedFileStatus fileStatus = iterator.next();

        String timeBucketStr = fileStatus.getPath().getName();
        if (timeBucketStr.equals(BucketsFileSystem.META_FILE_NAME) || timeBucketStr.endsWith(".tmp")) {
            //ignoring meta file
            continue;
        }

        LOG.debug("bucket {} time-bucket {}", bucketId, timeBucketStr);

        FileAccess.FileReader reader = fileAccess.getReader(bucketId, timeBucketStr);

        reader.readFully(fromDisk);
        size += keysPerTimeBucket;
        Assert.assertEquals("size of bucket " + bucketId, size, fromDisk.size());
    }

    Assert.assertEquals("size of bucket " + bucketId, unsavedBucket.size(), fromDisk.size());

    Map<Slice, Slice> testBucket = Maps.transformValues(unsavedBucket,
            new Function<Bucket.BucketedValue, Slice>() {
                @Override
                public Slice apply(@Nullable Bucket.BucketedValue input) {
                    assert input != null;
                    return input.getValue();
                }
            });
    Assert.assertEquals("data of bucket" + bucketId, testBucket, fromDisk);
}

From source file:de.cosmocode.rendering.SortedMapping.java

public SortedMapping() {
    this.renderers = Maps.newTreeMap(Reflection.orderByHierarchy());
}

From source file:co.cask.cdap.metrics.process.KafkaConsumerMetaTable.java

public synchronized void save(Map<TopicPartition, Long> offsets) throws Exception {

    NavigableMap<byte[], NavigableMap<byte[], Long>> updates = Maps.newTreeMap(Bytes.BYTES_COMPARATOR);
    for (Map.Entry<TopicPartition, Long> entry : offsets.entrySet()) {
        updates.put(getKey(entry.getKey()), Bytes.immutableSortedMapOf(OFFSET_COLUMN, entry.getValue()));
    }/*from   www .j  av a  2 s .c om*/
    metaTable.put(updates);
}

From source file:org.apache.crunch.io.hbase.RegionLocationTable.java

public static RegionLocationTable create(String tableName, List<HRegionLocation> regionLocationList) {
    NavigableMap<byte[], String> regionStartToServerHostName = Maps.newTreeMap(Bytes.BYTES_COMPARATOR);
    for (HRegionLocation regionLocation : regionLocationList) {
        byte[] startKey = regionLocation.getRegionInfo().getStartKey();
        if (startKey == null) {
            startKey = HConstants.EMPTY_START_ROW;
        }/*w ww.ja v  a 2s.  co m*/
        regionStartToServerHostName.put(startKey, regionLocation.getServerName().getHostname());
    }
    return new RegionLocationTable(tableName, regionStartToServerHostName);
}

From source file:org.fenixedu.learning.domain.DissertationsUtils.java

public static SortedMap<ExecutionYear, List<Thesis>> allThesesByYear(Collection<Degree> degrees) {
    TreeMap<ExecutionYear, List<Thesis>> thesesByYear = Maps.newTreeMap(REVERSE_COMPARATOR_BY_YEAR);
    Stream<Thesis> allTheses = degrees.stream()
            .flatMap(degree -> degree.getThesisSet().stream().filter(thesis -> thesis.getEnrolment() != null));
    thesesByYear.putAll(allTheses.collect(groupingBy(Thesis::getExecutionYear)));
    return thesesByYear;
}

From source file:org.gradle.cache.internal.CacheVersionMapping.java

private CacheVersionMapping(NavigableMap<GradleVersion, CacheVersion> versions) {
    Preconditions.checkArgument(!versions.isEmpty(), "versions must not be empty");
    this.versions = Maps.newTreeMap(versions);
}

From source file:org.apache.kylin.gridtable.GTInvertedIndexOfColumn.java

public GTInvertedIndexOfColumn(IGTComparator comparator) {
    this.comparator = comparator;
    this.rwLock = new ReentrantReadWriteLock();
    this.rangeIndex = Maps.newTreeMap(comparator);
    this.nullIndex = new ConciseSet();
}

From source file:dk.ilios.spanner.model.InstrumentSpec.java

private InstrumentSpec(Builder builder) {
    this.className = builder.className;
    this.options = Maps.newTreeMap(builder.options);
}

From source file:com.kegare.caveworld.util.CaveConfiguration.java

private void setNewCategoriesMap() {
    try {/*from  w w w.ja  v a  2s. com*/
        Field field = Configuration.class.getDeclaredField("categories");
        field.setAccessible(true);

        TreeMap<String, ConfigCategory> treeMap = (TreeMap) field.get(this);
        TreeMap<String, ConfigCategory> newMap = Maps.newTreeMap(this);
        newMap.putAll(treeMap);

        field.set(this, newMap);
    } catch (Throwable e) {
    }
}