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:io.janusproject.kernel.services.jdk.distributeddata.StandardDistributedDataStructureService.java

@SuppressWarnings("unchecked")
@Override/*  www .jav a  2  s . com*/
public <K, V> DMap<K, V> getMap(String name, Comparator<? super K> comparator) {
    Map<K, V> map;
    if (comparator == null) {
        map = (Map<K, V>) Maps.newTreeMap();
    } else {
        map = Maps.newTreeMap(comparator);
    }
    return new DMapView<>(name, map);
}

From source file:io.mapzone.arena.analytics.graph.ui.FeaturePropertySelectorUI.java

private void fill() {
    if (combo != null && !combo.isDisposed() && featureSource != null) {

        final Collection<PropertyDescriptor> schemaDescriptors = featureSource.getSchema().getDescriptors();
        final GeometryDescriptor geometryDescriptor = featureSource.getSchema().getGeometryDescriptor();
        final TreeMap<String, PropertyDescriptor> properties = Maps.newTreeMap();
        for (PropertyDescriptor descriptor : schemaDescriptors) {
            if (geometryDescriptor == null || !geometryDescriptor.equals(descriptor)) {
                properties.put(descriptor.getName().getLocalPart(), descriptor);
            }//  www.j av a2s  . c o m
        }
        final List<String> columns = Lists.newArrayList();
        columns.addAll(properties.keySet());
        combo.setItems(columns.toArray(new String[properties.size()]));

        combo.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                onSelect.accept(properties.get(columns.get(combo.getSelectionIndex())));
            }
        });
        combo.getParent().layout();
    }
}

From source file:elaborate.editor.config.Configuration.java

public XMLConfiguration load(Reader reader) {
    try {//from  w  ww  .j av  a  2s .  c o m
        messages = Maps.newTreeMap();
        AbstractConfiguration.setDefaultListDelimiter(',');
        XMLConfiguration config = new XMLConfiguration();
        config.clear();
        config.load(reader);
        processConfiguration(config);
        xmlConfig = config;
        return config;
    } catch (ConfigurationException e) {
        throw new RuntimeException("Failed to load configuration", e);
    }
}

From source file:com.google.caliper.model.InstrumentSpec.java

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

From source file:com.google.gdt.eclipse.designer.model.LayoutDataNameSupport.java

@Override
protected Map<String, String> getValueMap() {
    // prepare variables
    Map<String, String> valueMap = Maps.newTreeMap();
    {/*www  .j  a v a2 s.co  m*/
        valueMap.put("dataAcronym", getAcronym());
        valueMap.put("dataClassName", getClassName());
        valueMap.put("widgetName", getParentName());
        valueMap.put("widgetName-cap", getParentNameCap());
    }
    return valueMap;
}

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

Map<String, List<MetadataInfo>> migrate(final MigrationPlan migrationPlan, final MigratoryOption[] options)
        throws MigratoryException {
    if (migratoryConfig.isReadOnly()) {
        throw new MigratoryException(Reason.IS_READONLY);
    }//ww w .j a va 2 s  .c o m

    final MetadataManager metadataManager = new MetadataManager(migratoryContext);

    try {
        metadataManager.ensureMetadata(options);

        final Map<String, List<MetadataInfo>> migrationResults = Maps.newTreeMap();
        final Collection<String> existingPersonalities = metadataManager.retrieveExistingPersonalities();

        MigrationPlan planToExecute = migrationPlan;

        // If no personalities were give, migrate all existing personalities to the latest and greatest version.
        if (planToExecute == null || planToExecute.isEmpty()) {
            planToExecute = new MigrationPlan();
            for (String existingPersonality : existingPersonalities) {
                migrationPlan.addMigration(existingPersonality);
            }
        }

        // Make sure that all requested personalities either already exist in the
        // database or that they can be created.
        for (final MigrationPlanEntry migrationPlanEntry : planToExecute.getEntries()) {
            final String personalityName = migrationPlanEntry.getPersonalityName();

            try {
                metadataManager.lock(personalityName);
                final List<MigrationResult> results = migratePersonality(metadataManager, personalityName,
                        migrationPlanEntry.getTargetVersion(), options);

                final List<MetadataInfo> personalityMigrationResult = metadataManager.commit(results);
                if (!personalityMigrationResult.isEmpty()) {
                    migrationResults.put(personalityName, personalityMigrationResult);
                }

                final MigrationState state = MigrationResult.determineMigrationState(results);
                if (state != MigrationState.OK) {
                    break;
                }
            } catch (MigratoryException me) {
                metadataManager.rollback();
                throw me;
            } catch (RuntimeException re) {
                metadataManager.rollback();
                throw re;
            }
        }
        return migrationResults;
    } catch (Exception e) {
        throw processException(e);
    }
}

From source file:de.cosmocode.json.JSON.java

/**
 * Creates a {@link JSONObject} backed by a {@link SortedMap}
 * containing all pairs of the provided map.
 * /*from ww  w. j av  a2  s .  co m*/
 * @param <K> the generic key type
 * @param <V> the generic value type
 * @param map the source map all pairs will be copied from
 * @return a new {@link JSONObject} containing all pairs from map, backed by a sorted map
 */
public static <K extends Comparable<K>, V> JSONObject createSortedJSONObject(Map<K, V> map) {
    final SortedMap<K, V> sorted = Maps.newTreeMap();
    sorted.putAll(map);
    return new JSONObject(sorted);
}

From source file:com.github.fge.jsonschema.core.keyword.syntax.checkers.helpers.DependenciesSyntaxChecker.java

@Override
protected final void checkValue(final Collection<JsonPointer> pointers, final MessageBundle bundle,
        final ProcessingReport report, final SchemaTree tree) throws ProcessingException {
    final JsonNode node = getNode(tree);
    final Map<String, JsonNode> map = Maps.newTreeMap();
    map.putAll(JacksonUtils.asMap(node));

    String key;/* w  w w. j  a v a  2 s  .c  o  m*/
    JsonNode value;

    for (final Map.Entry<String, JsonNode> entry : map.entrySet()) {
        key = entry.getKey();
        value = entry.getValue();
        if (value.isObject())
            pointers.add(JsonPointer.of(keyword, key));
        else
            checkDependency(report, bundle, entry.getKey(), tree);
    }

}

From source file:eu.interedition.text.event.AnnotationEventSource.java

public void listen(final AnnotationEventListener listener, final int pageSize, final Text text,
        final Criterion criterion, final Set<Name> dataSet) throws IOException {
    textRepository.read(text, new TextConsumer() {

        public void read(Reader content, long contentLength) throws IOException {
            final SortedMap<Long, Set<Annotation>> starts = Maps.newTreeMap();
            final SortedMap<Long, Set<Annotation>> ends = Maps.newTreeMap();

            long offset = 0;
            long next = 0;
            long pageEnd = 0;

            listener.start();/*from   w w  w.j a  v a  2s  . c o  m*/

            final Set<Annotation> annotationData = Sets.newHashSet();
            while (true) {
                if ((offset % pageSize) == 0) {
                    pageEnd = Math.min(offset + pageSize, contentLength);
                    final Range pageRange = new Range(offset, pageEnd);
                    final Iterable<Annotation> pageAnnotations = annotationRepository
                            .find(and(criterion, text(text), rangeOverlap(pageRange)), dataSet);
                    for (Annotation a : pageAnnotations) {
                        final long start = a.getRange().getStart();
                        final long end = a.getRange().getEnd();
                        if (start >= offset) {
                            Set<Annotation> starting = starts.get(start);
                            if (starting == null) {
                                starts.put(start, starting = Sets.newHashSet());
                            }
                            starting.add(a);
                            annotationData.add(a);
                        }
                        if (end <= pageEnd) {
                            Set<Annotation> ending = ends.get(end);
                            if (ending == null) {
                                ends.put(end, ending = Sets.newHashSet());
                            }
                            ending.add(a);
                            annotationData.add(a);
                        }
                    }

                    next = Math.min(starts.isEmpty() ? contentLength : starts.firstKey(),
                            ends.isEmpty() ? contentLength : ends.firstKey());
                }

                if (offset == next) {
                    final Set<Annotation> startEvents = (!starts.isEmpty() && offset == starts.firstKey()
                            ? starts.remove(starts.firstKey())
                            : Sets.<Annotation>newHashSet());
                    final Set<Annotation> endEvents = (!ends.isEmpty() && offset == ends.firstKey()
                            ? ends.remove(ends.firstKey())
                            : Sets.<Annotation>newHashSet());

                    final Set<Annotation> terminating = Sets.filter(endEvents, Predicates.not(EMPTY));
                    if (!terminating.isEmpty())
                        listener.end(offset, filter(annotationData, terminating, true));

                    final Set<Annotation> empty = Sets.filter(startEvents, EMPTY);
                    if (!empty.isEmpty())
                        listener.empty(offset, filter(annotationData, empty, true));

                    final Set<Annotation> starting = Sets.filter(startEvents, Predicates.not(EMPTY));
                    if (!starting.isEmpty())
                        listener.start(offset, filter(annotationData, starting, false));

                    next = Math.min(starts.isEmpty() ? contentLength : starts.firstKey(),
                            ends.isEmpty() ? contentLength : ends.firstKey());
                }

                if (offset == contentLength) {
                    break;
                }

                final long readTo = Math.min(pageEnd, next);
                if (offset < readTo) {
                    final char[] currentText = new char[(int) (readTo - offset)];
                    int read = content.read(currentText);
                    if (read > 0) {
                        listener.text(new Range(offset, offset + read), new String(currentText, 0, read));
                        offset += read;
                    }
                }
            }

            listener.end();
        }
    });
}

From source file:org.ambraproject.service.migration.Migrations.java

/**
 * Sort migrations by version, checking that each version is unique and conforms to convention.
 *
 * @param migrations distinct migration objects
 * @return the migrations, sorted by version
 * @throws RuntimeException if a migration violates the numbering convention
 *///from www. j a  va2s .c om
private static ImmutableList<Migration> sort(Iterable<? extends Migration> migrations) {
    SortedMap<Integer, Migration> map = Maps.newTreeMap();
    for (Migration migration : migrations) {
        int version = migration.getVersion();

        // Validate that version number matches convention
        if (version <= SchemaMigration.THRESHOLD && !(migration instanceof LegacyMigration)) {
            String message = String.format(
                    "Illegal migration version: %d; non-legacy migrations must have version > %d", version,
                    SchemaMigration.THRESHOLD);
            throw new RuntimeException(message);
        }

        if (map.put(version, migration) != null) {
            throw new RuntimeException("Collision on migration version: " + version);
        }
    }
    return ImmutableList.copyOf(map.values());
}