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.enonic.cms.core.content.ContentEntity.java

/**
 * Constructor that creates a new instance as a copy of the given content.
 *///from  w  w  w .  j  av a2 s. c  o  m
public ContentEntity(ContentEntity source) {
    this();

    this.key = source.getKey();
    this.createdAt = source.getCreatedAt();
    this.timestamp = source.getTimestamp();
    this.deleted = source.getDeleted();
    this.name = source.getName();
    this.priority = source.getPriority();
    this.availableFrom = source.getAvailableFrom();
    this.availableTo = source.getAvailableTo();
    this.owner = source.getOwner();
    this.assignee = source.getAssignee();
    this.assigner = source.getAssigner();
    this.assignmentDueDate = source.getAssignmentDueDate();
    this.assignmentDescription = source.getAssignmentDescription();
    this.category = source.getCategory();
    this.language = source.getLanguage();
    this.source = source.getSource();
    this.mainVersion = source.getMainVersion();
    this.draftVersion = source.getDraftVersion();
    this.contentHomes = source.getContentHomesAsMap() != null ? Maps.newTreeMap(source.getContentHomesAsMap())
            : null;
    this.versions = source.getVersions() != null ? Lists.newArrayList(source.getVersions()) : null;
    this.relatedParents = source.getRelatedParentContentVersions() != null
            ? Sets.newHashSet(source.getRelatedParentContentVersions())
            : null;
    this.sectionContents = source.getSectionContents() != null ? Sets.newHashSet(source.getSectionContents())
            : null;
    this.directMenuItemPlacements = source.getDirectMenuItemPlacements() != null
            ? new TreeSet<MenuItemEntity>(source.getDirectMenuItemPlacements())
            : null;
    if (source.getContentAccessRights() != null) {
        TreeMap<GroupKey, ContentAccessEntity> contentAccessRightsCopy = Maps
                .newTreeMap(new GroupKeyComparator());
        contentAccessRightsCopy.putAll(source.contentAccessRights);
        this.contentAccessRights = contentAccessRightsCopy;
    }
}

From source file:co.cask.cdap.data2.dataset2.lib.table.inmemory.InMemoryOrderedTable.java

protected static NavigableMap<byte[], byte[]> getLatestNotExcluded(
        NavigableMap<byte[], NavigableMap<Long, byte[]>> rowMap, Transaction tx) {

    // todo: for some subclasses it is ok to do changes in place...
    NavigableMap<byte[], byte[]> result = Maps.newTreeMap(Bytes.BYTES_COMPARATOR);
    for (Map.Entry<byte[], NavigableMap<Long, byte[]>> column : rowMap.entrySet()) {
        // NOTE: versions map already sorted, first comes latest version
        // todo: not cool to rely on external implementation specifics
        for (Map.Entry<Long, byte[]> versionAndValue : column.getValue().entrySet()) {
            // NOTE: we know that excluded versions are ordered
            if (tx == null || tx.isVisible(versionAndValue.getKey())) {
                result.put(column.getKey(), versionAndValue.getValue());
                break;
            }//  w  ww .  j  a v a2 s  . c o  m
        }
    }

    return result;
}

From source file:co.cask.cdap.data2.dataset2.lib.timeseries.FactTable.java

public void add(List<Fact> facts) {
    // Simply collecting all rows/cols/values that need to be put to the underlying table.
    NavigableMap<byte[], NavigableMap<byte[], byte[]>> gaugesTable = Maps.newTreeMap(Bytes.BYTES_COMPARATOR);
    NavigableMap<byte[], NavigableMap<byte[], byte[]>> incrementsTable = Maps
            .newTreeMap(Bytes.BYTES_COMPARATOR);
    for (Fact fact : facts) {
        for (Measurement measurement : fact.getMeasurements()) {
            byte[] rowKey = codec.createRowKey(fact.getDimensionValues(), measurement.getName(),
                    fact.getTimestamp());
            byte[] column = codec.createColumn(fact.getTimestamp());

            if (MeasureType.COUNTER == measurement.getType()) {
                inc(incrementsTable, rowKey, column, measurement.getValue());
            } else {
                set(gaugesTable, rowKey, column, Bytes.toBytes(measurement.getValue()));
            }/*w w  w  . j  av a2s.c o m*/
        }
    }

    NavigableMap<byte[], NavigableMap<byte[], Long>> convertedIncrementsTable = Maps
            .transformValues(incrementsTable, TRANSFORM_MAP_BYTE_ARRAY_TO_LONG);

    NavigableMap<byte[], NavigableMap<byte[], Long>> convertedGaugesTable = Maps.transformValues(gaugesTable,
            TRANSFORM_MAP_BYTE_ARRAY_TO_LONG);

    // todo: replace with single call, to be able to optimize rpcs in underlying table
    timeSeriesTable.put(convertedGaugesTable);
    timeSeriesTable.increment(convertedIncrementsTable);
    if (metrics != null) {
        metrics.increment(putCountMetric, convertedGaugesTable.size());
        metrics.increment(incrementCountMetric, convertedIncrementsTable.size());
    }
}

From source file:com.google.idea.blaze.android.rendering.BlazeRenderErrorContributor.java

/**
 * We can't find generated resources. If a layout uses them, the layout won't render correctly.
 *//*from w  w w .  j av a  2  s  . c  o m*/
private void reportGeneratedResources(AndroidResourceModule resourceModule, TargetMap targetMap,
        ArtifactLocationDecoder decoder) {
    Map<String, Throwable> brokenClasses = logger.getBrokenClasses();
    if (brokenClasses == null || brokenClasses.isEmpty()) {
        return;
    }

    // Sorted entries for deterministic error message.
    SortedMap<ArtifactLocation, TargetIdeInfo> generatedResources = Maps
            .newTreeMap(getGeneratedResources(targetMap.get(resourceModule.targetKey)));

    for (TargetKey dependency : resourceModule.transitiveResourceDependencies) {
        generatedResources.putAll(getGeneratedResources(targetMap.get(dependency)));
    }

    if (generatedResources.isEmpty()) {
        return;
    }

    HtmlBuilder builder = new HtmlBuilder();
    builder.add("Generated resources will not be discovered by the IDE:");
    builder.beginList();
    for (Map.Entry<ArtifactLocation, TargetIdeInfo> entry : generatedResources.entrySet()) {
        ArtifactLocation resource = entry.getKey();
        TargetIdeInfo target = entry.getValue();
        builder.listItem().add(resource.getRelativePath()).add(" from ");
        addTargetLink(builder, target, decoder);
    }
    builder.endList().add("Please avoid using generated resources, ")
            .addLink("then ", "sync the project", " ", getLinkManager().createSyncProjectUrl())
            .addLink("and ", "refresh the layout", ".", getLinkManager().createRefreshRenderUrl());
    addIssue().setSeverity(HighlightSeverity.ERROR, HIGH_PRIORITY + 1) // Reported above broken classes
            .setSummary("Generated resources").setHtmlContent(builder).build();
}

From source file:com.edmunds.etm.runtime.api.ApplicationSeries.java

/**
 * Adds or replaces the specified application version in this series.
 *
 * @param application the application to add or replace
 * @return the previous application of the same version, or null if there was no entry for the version
 *///  www. ja  v  a2  s  .c o  m
public ApplicationSeries addOrReplace(Application application) {
    Validate.notNull(application);
    if (!application.getName().equals(name)) {
        String message = String.format("Application name '%s' does not match series name '%s'",
                application.getName(), name);
        throw new IllegalArgumentException(message);
    }

    final Application previous = applicationsByVersion.get(application.getVersion());

    // If the previous version of this app was active so should this version be.
    if (previous != null && previous.isActive()) {
        application = new Application(application, true);
    }

    // Create a mutable copy of the active versions map.
    final TreeMap<ApplicationVersion, Application> temp = Maps.newTreeMap(applicationsByVersion);

    // Add the new version.
    temp.put(application.getVersion(), application);

    // Activate if necessary
    updateActiveVersion(temp);

    // Wrap the mapping in a new application series.
    return new ApplicationSeries(name, temp);
}

From source file:co.cask.cdap.data2.dataset2.lib.table.leveldb.LevelDBTableCore.java

public synchronized void increment(NavigableMap<byte[], NavigableMap<byte[], Long>> updates)
        throws IOException {
    Map<byte[], Map<byte[], byte[]>> resultMap = Maps.newHashMap();
    for (NavigableMap.Entry<byte[], NavigableMap<byte[], Long>> row : updates.entrySet()) {
        NavigableMap<byte[], Long> increments = row.getValue();
        Map<byte[], byte[]> replacing = Maps.newTreeMap(Bytes.BYTES_COMPARATOR);
        Map<byte[], Long> result = getResultMap(row.getKey(), increments);
        for (Map.Entry<byte[], Long> entry : result.entrySet()) {
            replacing.put(entry.getKey(), Bytes.toBytes(entry.getValue()));
        }/*from w w  w. j av a2s .co  m*/
        resultMap.put(row.getKey(), replacing);
    }
    persist(resultMap, System.currentTimeMillis());
}

From source file:co.cask.cdap.data2.dataset2.lib.table.inmemory.InMemoryOrderedTable.java

private NavigableMap<byte[], byte[]> getLatest(NavigableMap<byte[], NavigableMap<Long, byte[]>> rowMap) {
    if (rowMap == null) {
        return EMPTY_ROW_MAP;
    }/*from   w w w.  j av a 2s  .c om*/

    NavigableMap<byte[], byte[]> result = Maps.newTreeMap(Bytes.BYTES_COMPARATOR);
    for (Map.Entry<byte[], NavigableMap<Long, byte[]>> column : rowMap.entrySet()) {
        // latest go first
        result.put(column.getKey(), column.getValue().firstEntry().getValue());
    }
    return result;
}

From source file:co.cask.cdap.data2.transaction.queue.leveldb.LevelDBQueueConsumer.java

@Override
protected void undoState(Set<byte[]> rowKeys, byte[] stateColumnName) throws IOException, InterruptedException {
    if (rowKeys.isEmpty()) {
        return;// ww  w.j  av  a 2s.com
    }
    NavigableMap<byte[], NavigableMap<byte[], byte[]>> changes = Maps.newTreeMap(Bytes.BYTES_COMPARATOR);
    for (byte[] rowKey : rowKeys) {
        NavigableMap<byte[], byte[]> row = Maps.newTreeMap(Bytes.BYTES_COMPARATOR);
        row.put(stateColumnName, DUMMY_STATE_CONTENT);
        changes.put(rowKey, row);
    }
    core.undo(changes, KeyValue.LATEST_TIMESTAMP);
}