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 <K extends Comparable, V> TreeMap<K, V> newTreeMap() 

Source Link

Document

Creates a mutable, empty TreeMap instance using the natural ordering of its elements.

Usage

From source file:com.nesscomputing.migratory.InternalValidator.java

Map<String, ValidationResult> validate(final Collection<String> personalities, final MigratoryOption... options)
        throws MigratoryException {
    final MetadataManager metadataManager = new MetadataManager(migratoryContext);

    metadataManager.ensureMetadata(options);

    final Map<String, List<MetadataInfo>> recordedMigrations = metadataManager.getHistory(personalities,
            options);//from  w w  w .  ja v a2 s .  c  om

    final Map<String, ValidationResult> results = Maps.newTreeMap();

    for (Map.Entry<String, List<MetadataInfo>> personality : recordedMigrations.entrySet()) {
        final DbValidator dbValidator = new DbValidator(
                new MigrationManager(migratoryContext, personality.getKey()));
        final ValidationResult result = dbValidator.validate(personality.getValue());
        results.put(personality.getKey(), result);
    }

    return results;
}

From source file:org.apache.kylin.dimension.DimensionEncodingFactory.java

public static Map<String, Integer> getValidEncodings() {
    if (factoryMap == null)
        initFactoryMap();/*from w  w w  .j  a  v a 2 s .co m*/

    Map<String, Integer> result = Maps.newTreeMap();
    for (Pair<String, Integer> p : factoryMap.keySet()) {
        if (result.containsKey(p.getFirst())) {
            if (result.get(p.getFirst()) > p.getSecond()) {
                continue;//skip small versions
            }
        }

        result.put(p.getFirst(), p.getSecond());
    }
    result.put(DictionaryDimEnc.ENCODING_NAME, 1);
    return result;
}

From source file:org.kiji.rest.representations.KijiRestRow.java

/**
 * Construct a new KijiRestRow object given the entity id.
 *
 * @param entityId is the entity id of the row.
 *//*from w w w  .  j  a  v a 2 s . c o  m*/
public KijiRestRow(KijiRestEntityId entityId) {
    mKijiRestEntityId = entityId;
    mKijiCellMap = Maps.newTreeMap();
}

From source file:com.kodebeagle.javaparser.SingleClassBindingResolver.java

/**
 * Return a naive variableName to variableType map.
 *
 * @return//from  ww w .j a v a2  s  .  c o  m
 */
public Map<String, String> getVariableTypes() {
    final Map<String, String> variableNameTypes = Maps.newTreeMap();
    for (final Entry<Integer, List<ASTNode>> variableBinding : resolver.getVariableBinding().entrySet()) {
        final String varType = checkNotNull(resolver.getVariableTypes().get(variableBinding.getKey()));
        for (final ASTNode node : variableBinding.getValue()) {
            variableNameTypes.put(node.toString(), varType);
        }
    }
    return variableNameTypes;
}

From source file:com.cloudera.oryx.kmeans.common.Weighted.java

/**
 * Sample items from a {@code List<Weighted>} where items with higher weights
 * have a higher probability of being included in the sample.
 * /* w  ww.  j a v  a2 s .  c o  m*/
 * @param things The iterable to sample from
 * @param size The number of items to sample
 * @return A list containing the sampled items
 */
public static <T extends Weighted<?>> List<T> sample(Iterable<T> things, int size, RandomGenerator random) {
    if (random == null) {
        random = RandomManager.getRandom();
    }
    SortedMap<Double, T> sampled = Maps.newTreeMap();
    for (T thing : things) {
        if (thing.weight() > 0) {
            double score = Math.log(random.nextDouble()) / thing.weight();
            if (sampled.size() < size || score > sampled.firstKey()) {
                sampled.put(score, thing);
            }
            if (sampled.size() > size) {
                sampled.remove(sampled.firstKey());
            }
        }
    }
    return Lists.newArrayList(sampled.values());
}

From source file:com.nomsic.sid.FieldRecordProcessor.java

public FieldRecordProcessor() {
    map = Maps.newTreeMap();
}

From source file:com.nesscomputing.migratory.InternalStatus.java

Map<String, StatusResult> status(final Collection<String> personalities, final MigratoryOption... options) {
    LOG.debug("Running status(%s, %s)", personalities, options);

    Map<String, StatusResult> results = Maps.newTreeMap();

    final MetadataManager manager = new MetadataManager(migratoryContext);
    try {/* ww w  .j a  v  a2  s . co m*/
        manager.ensureMetadata(options);

        final Map<String, MetadataInfo> metadataInfos = manager.getStatus(personalities, options);

        // return a superset of the personalities that are requested (and that should be in the
        // reply and the available ones.
        final Set<String> displayPersonalities = Sets.newHashSet();
        if (personalities != null) {
            displayPersonalities.addAll(personalities);
        }
        displayPersonalities.addAll(metadataInfos.keySet());

        for (final String personalityName : displayPersonalities) {
            final MetadataInfo metadataInfo = metadataInfos.get(personalityName);

            final int currentVersion;
            final MigrationState state;

            if (metadataInfo == null) {
                currentVersion = 0;
                state = MigrationState.OK;
            } else {
                currentVersion = metadataInfo.getEndVersion();
                state = metadataInfo.getState();
            }

            final MigrationManager migrationManager = new MigrationManager(migratoryContext, personalityName);
            // Build a migration path from the current version all the way to the end.
            final MigrationPlanner migrationPlanner = new MigrationPlanner(migrationManager, currentVersion,
                    Integer.MAX_VALUE);

            boolean migrationPossible = true;
            try {
                migrationPlanner.plan();
            } catch (MigratoryException me) {
                if (me.getReason() != Reason.VALIDATION_FAILED) {
                    throw me;
                } else {
                    migrationPossible = false;
                }
            }
            final StatusResult result = new StatusResult(personalityName, migrationPossible, state,
                    migrationPlanner.getDirection(), currentVersion, migrationPlanner.getFirstVersion(),
                    migrationPlanner.getLastVersion());

            results.put(personalityName, result);
        }
        return results;
    } catch (Exception e) {
        throw processException(e);
    }
}

From source file:com.textocat.textokit.commons.cas.TreeMapOverlapIndex.java

private TreeMapOverlapIndex(Iterator<A> srcIter) {
    beginIdx = Maps.newTreeMap();
    endIdx = Maps.newTreeMap();/*from ww  w. j  a va 2  s  .c  om*/
    annoIds = Maps.newHashMap();
    while (srcIter.hasNext()) {
        A sa = srcIter.next();
        // empty annotations overlap with nothing
        if (AnnotationUtils.isEmpty(sa)) {
            continue;
        }
        // by begin
        {
            int saBegin = sa.getBegin();
            Set<A> sameBeginSet = beginIdx.get(saBegin);
            if (sameBeginSet == null) {
                // preserve source iterator ordering
                sameBeginSet = Sets.newLinkedHashSet();
                beginIdx.put(saBegin, sameBeginSet);
            }
            sameBeginSet.add(sa);
        }
        // by end
        {
            int saEnd = sa.getEnd();
            Set<A> sameEndSet = endIdx.get(saEnd);
            if (sameEndSet == null) {
                // preserve source iterator ordering
                sameEndSet = Sets.newLinkedHashSet();
                endIdx.put(saEnd, sameEndSet);
            }
            sameEndSet.add(sa);
        }
        // this is required for internal comparator to preserve source iterator ordering
        // if offsets are equal
        if (!annoIds.containsKey(sa)) {
            annoIds.put(sa, ++annoIdCounter);
        }
    }
}

From source file:com.kylinolap.storage.hbase.observer.AggregationCache.java

public AggregationCache(SRowAggregators aggregators, int estSize) {
    this.aggregators = aggregators;
    this.aggBufMap = Maps.newTreeMap();
}

From source file:org.apache.isis.core.metamodel.layout.memberorderfacet.DeweyOrderSet.java

public static DeweyOrderSet createOrderSet(final List<FacetedMethod> facetedMethods) {

    final SortedMap<String, SortedSet<FacetedMethod>> sortedMembersByGroup = Maps.newTreeMap();
    final SortedSet<FacetedMethod> nonAnnotatedGroup = Sets.newTreeSet(new MemberIdentifierComparator());

    // spin over all the members and put them into a Map of SortedSets
    // any non-annotated members go into additional nonAnnotatedGroup set.
    for (final FacetedMethod facetedMethod : facetedMethods) {
        final MemberOrderFacet memberOrder = facetedMethod.getFacet(MemberOrderFacet.class);
        if (memberOrder == null) {
            nonAnnotatedGroup.add(facetedMethod);
            continue;
        }//from   w  ww  . ja  v  a2 s  . co m
        final SortedSet<FacetedMethod> sortedMembersForGroup = getSortedSet(sortedMembersByGroup,
                memberOrder.name());
        sortedMembersForGroup.add(facetedMethod);
    }

    // add the non-annotated group to the first "" group.
    final SortedSet<FacetedMethod> defaultSet = getSortedSet(sortedMembersByGroup, "");
    defaultSet.addAll(nonAnnotatedGroup);

    // create OrderSets, wiring up parents and children.

    // since sortedMembersByGroup is a SortedMap, the
    // iteration will be in alphabetical order (ie parent groups before
    // their children).
    final Set<String> groupNames = sortedMembersByGroup.keySet();
    final SortedMap<String, DeweyOrderSet> orderSetsByGroup = Maps.newTreeMap();

    for (final String string : groupNames) {
        final String groupName = string;
        final DeweyOrderSet deweyOrderSet = new DeweyOrderSet(groupName);
        orderSetsByGroup.put(groupName, deweyOrderSet);
        ensureParentFor(orderSetsByGroup, deweyOrderSet);
    }

    // now populate the OrderSets
    for (final String groupName : groupNames) {
        final DeweyOrderSet deweyOrderSet = orderSetsByGroup.get(groupName);
        // REVIEW: something fishy happens here with casting, hence warnings
        // left in
        final SortedSet sortedMembers = sortedMembersByGroup.get(groupName);
        deweyOrderSet.addAll(sortedMembers);
        deweyOrderSet.copyOverChildren();
    }

    return orderSetsByGroup.get("");
}