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

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

Introduction

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

Prototype

public static <K, V> LinkedHashMap<K, V> newLinkedHashMap() 

Source Link

Document

Creates a mutable, empty, insertion-ordered LinkedHashMap instance.

Usage

From source file:brooklyn.event.basic.AbstractStructuredConfigKey.java

protected RawT extractValue(Map<?, ?> vals, ExecutionContext exec, boolean coerce, boolean unmodifiable) {
    RawT base = null;//from  w  w  w.  ja  va2  s .c o m
    Map<String, Object> subkeys = Maps.newLinkedHashMap();
    for (Map.Entry<?, ?> entry : vals.entrySet()) {
        Object k = entry.getKey();

        if (acceptsKeyMatch(k)) {
            base = extractValueMatchingThisKey(entry.getValue(), exec, coerce);
        }

        if (acceptsSubkey(k)) {
            String subKeyName = extractSubKeyName(k);
            Object value;
            if (coerce) {
                @SuppressWarnings("unchecked")
                SubElementConfigKey<V> kk = k instanceof SubElementConfigKey<?> ? (SubElementConfigKey<V>) k
                        : (SubElementConfigKey<V>) subKey(subKeyName);
                value = kk.extractValue(vals, exec);
            } else {
                value = vals.get(k);
            }
            subkeys.put(subKeyName, value);
        }
    }
    return merge(base, subkeys, unmodifiable);
}

From source file:org.cinchapi.concourse.server.storage.db.PrimaryRecord.java

/**
 * Return a log of revisions to the field mapped from {@code key}.
 * //  ww  w. ja v  a  2 s . co m
 * @param key
 * @return the revision log
 */
public Map<Long, String> audit(Text key) {
    read.lock();
    try {
        Map<Long, String> audit = Maps.newLinkedHashMap();
        List<Revision<PrimaryKey, Text, Value>> revisions = history.get(key); /* Authorized */
        if (revisions != null) {
            Iterator<Revision<PrimaryKey, Text, Value>> it = revisions.iterator();
            while (it.hasNext()) {
                Revision<PrimaryKey, Text, Value> revision = it.next();
                audit.put(revision.getVersion(), revision.toString());
            }
        }
        return audit;
    } finally {
        read.unlock();
    }
}

From source file:org.apache.parquet.cli.commands.ShowPagesCommand.java

@Override
@SuppressWarnings("unchecked")
public int run() throws IOException {
    Preconditions.checkArgument(targets != null && targets.size() >= 1, "A Parquet file is required.");
    Preconditions.checkArgument(targets.size() == 1, "Cannot process multiple Parquet files.");

    String source = targets.get(0);
    ParquetFileReader reader = ParquetFileReader.open(getConf(), qualifiedPath(source));

    MessageType schema = reader.getFileMetaData().getSchema();
    Map<ColumnDescriptor, PrimitiveType> columns = Maps.newLinkedHashMap();
    if (this.columns == null || this.columns.isEmpty()) {
        for (ColumnDescriptor descriptor : schema.getColumns()) {
            columns.put(descriptor, primitive(schema, descriptor.getPath()));
        }/*  www . j a  v a 2  s  .  com*/
    } else {
        for (String column : this.columns) {
            columns.put(descriptor(column, schema), primitive(column, schema));
        }
    }

    CompressionCodecName codec = reader.getRowGroups().get(0).getColumns().get(0).getCodec();
    // accumulate formatted lines to print by column
    Map<String, List<String>> formatted = Maps.newLinkedHashMap();
    PageFormatter formatter = new PageFormatter();
    PageReadStore pageStore;
    int rowGroupNum = 0;
    while ((pageStore = reader.readNextRowGroup()) != null) {
        for (ColumnDescriptor descriptor : columns.keySet()) {
            List<String> lines = formatted.get(columnName(descriptor));
            if (lines == null) {
                lines = Lists.newArrayList();
                formatted.put(columnName(descriptor), lines);
            }

            formatter.setContext(rowGroupNum, columns.get(descriptor), codec);
            PageReader pages = pageStore.getPageReader(descriptor);

            DictionaryPage dict = pages.readDictionaryPage();
            if (dict != null) {
                lines.add(formatter.format(dict));
            }
            DataPage page;
            while ((page = pages.readPage()) != null) {
                lines.add(formatter.format(page));
            }
        }
        rowGroupNum += 1;
    }

    // TODO: Show total column size and overall size per value in the column summary line
    for (String columnName : formatted.keySet()) {
        console.info(String.format("\nColumn: %s\n%s", columnName, StringUtils.leftPad("", 80, '-')));
        console.info(formatter.getHeader());
        for (String line : formatted.get(columnName)) {
            console.info(line);
        }
        console.info("");
    }

    return 0;
}

From source file:org.gradle.execution.TaskNameResolver.java

/**
 * Finds the names of all tasks, without necessarily creating or configuring the tasks. Returns an empty map when none are found.
 *//*  ww  w  .  j a v a  2s  .c o m*/
public Map<String, TaskSelectionResult> selectAll(ProjectInternal project, boolean includeSubProjects) {
    Map<String, TaskSelectionResult> selected = Maps.newLinkedHashMap();

    if (includeSubProjects) {
        Set<String> taskNames = Sets.newLinkedHashSet();
        collectTaskNames(project, taskNames);
        for (String taskName : taskNames) {
            selected.put(taskName, new MultiProjectTaskSelectionResult(taskName, project));
        }
    } else {
        for (String taskName : getTaskNames(project)) {
            selected.put(taskName, new SingleProjectTaskSelectionResult(taskName, project.getTasks()));
        }
    }

    return selected;
}

From source file:com.exoplatform.iversion.VersionNode.java

/**
 * Gets the properties of its parents and itself.
 * Builds the map key, and Version Property, 
 * and the map is also immutable object.
 * /*from  w w  w .j a v  a2 s .  c o  m*/
 * @return
 */
public Map<K, VersionProperty<V>> mergeProperties() {
    Map<K, VersionProperty<V>> properties = Maps.newLinkedHashMap();

    for (VersionNode<K, V, M, T> parent : parents) {
        for (Map.Entry<K, VersionProperty<V>> entry : parent.getProperties().entrySet()) {
            K key = entry.getKey();
            //TODO: this code processes only get latest property value
            VersionProperty<V> nextValue = entry.getValue();
            VersionProperty<V> prevValue = properties.get(key);

            if (prevValue == null) {
                properties.put(key, nextValue);
            } else if (prevValue.revision < nextValue.revision) {
                properties.put(key, nextValue);
            }
        }
    }

    properties.putAll(version.getVersionProperties());

    return Collections.unmodifiableMap(properties);
}

From source file:org.onosproject.store.primitives.impl.PartitionedAsyncDocumentTree.java

@Override
public CompletableFuture<Map<String, Versioned<V>>> getChildren(DocumentPath path) {
    return Tools/*from  ww w .ja va 2  s .  c  o  m*/
            .allOf(partitions().stream().map(partition -> partition.getChildren(path).exceptionally(r -> null))
                    .collect(Collectors.toList()))
            .thenApply(allChildren -> {
                Map<String, Versioned<V>> children = Maps.newLinkedHashMap();
                allChildren.stream().filter(Objects::nonNull).forEach(children::putAll);
                return children;
            });
}

From source file:org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.java

public void applyPlugins(PluginRequests requests, final ScriptHandlerInternal scriptHandler,
        @Nullable final PluginManagerInternal target, ClassLoaderScope classLoaderScope) {
    if (requests.isEmpty()) {
        defineScriptHandlerClassScope(scriptHandler, classLoaderScope,
                Collections.<PluginImplementation<?>>emptyList());
        return;/*from  w  ww .jav  a  2s .  com*/
    }

    if (target == null) {
        throw new IllegalStateException("Plugin target is 'null' and there are plugin requests");
    }

    final PluginResolver effectivePluginResolver = wrapInNotInClasspathCheck(classLoaderScope);

    List<Result> results = collect(requests, new Transformer<Result, PluginRequest>() {
        public Result transform(PluginRequest request) {
            return resolveToFoundResult(effectivePluginResolver, request);
        }
    });

    // Could be different to ids in the requests as they may be unqualified
    final Map<Result, PluginId> legacyActualPluginIds = Maps.newLinkedHashMap();
    final Map<Result, PluginImplementation<?>> pluginImpls = Maps.newLinkedHashMap();
    final Map<Result, PluginImplementation<?>> pluginImplsFromOtherLoaders = Maps.newLinkedHashMap();

    if (!results.isEmpty()) {
        final RepositoryHandler repositories = scriptHandler.getRepositories();
        final List<MavenArtifactRepository> mavenRepos = repositories.withType(MavenArtifactRepository.class);
        final Set<String> repoUrls = Sets.newLinkedHashSet();

        for (final Result result : results) {
            applyPlugin(result.request, result.found.getPluginId(), new Runnable() {
                @Override
                public void run() {
                    result.found.execute(new PluginResolveContext() {
                        public void addLegacy(PluginId pluginId, final String m2RepoUrl,
                                Object dependencyNotation) {
                            legacyActualPluginIds.put(result, pluginId);
                            repoUrls.add(m2RepoUrl);
                            scriptHandler.addScriptClassPathDependency(dependencyNotation);
                        }

                        @Override
                        public void add(PluginImplementation<?> plugin) {
                            pluginImpls.put(result, plugin);
                        }

                        @Override
                        public void addFromDifferentLoader(PluginImplementation<?> plugin) {
                            pluginImplsFromOtherLoaders.put(result, plugin);
                        }
                    });
                }
            });
        }

        for (final String m2RepoUrl : repoUrls) {
            boolean repoExists = any(mavenRepos, new Spec<MavenArtifactRepository>() {
                public boolean isSatisfiedBy(MavenArtifactRepository element) {
                    return element.getUrl().toString().equals(m2RepoUrl);
                }
            });
            if (!repoExists) {
                repositories.maven(new Action<MavenArtifactRepository>() {
                    public void execute(MavenArtifactRepository mavenArtifactRepository) {
                        mavenArtifactRepository.setUrl(m2RepoUrl);
                    }
                });
            }
        }
    }

    defineScriptHandlerClassScope(scriptHandler, classLoaderScope, pluginImplsFromOtherLoaders.values());

    // We're making an assumption here that the target's plugin registry is backed classLoaderScope.
    // Because we are only build.gradle files right now, this holds.
    // It won't for arbitrary scripts though.
    for (final Map.Entry<Result, PluginId> entry : legacyActualPluginIds.entrySet()) {
        final PluginRequest request = entry.getKey().request;
        final PluginId id = entry.getValue();
        applyPlugin(request, id, new Runnable() {
            public void run() {
                target.apply(id.toString());
            }
        });
    }

    for (final Map.Entry<Result, PluginImplementation<?>> entry : Iterables.concat(pluginImpls.entrySet(),
            pluginImplsFromOtherLoaders.entrySet())) {
        final Result result = entry.getKey();
        applyPlugin(result.request, result.found.getPluginId(), new Runnable() {
            public void run() {
                target.apply(entry.getValue());
            }
        });
    }
}

From source file:org.jclouds.ibm.smartcloud.xml.LocationHandler.java

@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
    if (qName.equalsIgnoreCase("ID")) {
        id = currentText.toString().trim();
    } else if (qName.equalsIgnoreCase("Name")) {
        name = currentText.toString().trim();
    } else if (qName.equalsIgnoreCase("Description")) {
        description = currentText.toString().trim();
        if (description.equals(""))
            description = null;//from   www  .  j av a2s  .c om
    } else if (qName.equalsIgnoreCase("State")) {
        state = State.fromValue(Integer.parseInt(currentText.toString().trim()));
    } else if (qName.equalsIgnoreCase("Value")) {
        capabilities.get(capabilityName).put(capabilityKey, currentText.toString().trim());
    } else if (qName.equalsIgnoreCase("Location")) {
        if (currentText.toString().trim().equals("")) {
            this.loc = new Location(id, name, description, location, state, capabilities);
            id = null;
            name = null;
            description = null;
            location = null;
            state = null;
            capabilities = Maps.newLinkedHashMap();
            capabilityKey = null;
            capabilityName = null;
        } else {
            location = currentText.toString().trim();
        }
    }
    currentText = new StringBuilder();
}

From source file:org.smartdeveloperhub.curator.connector.io.ConstraintParser.java

private ConstraintParser(Model model, Resource resource, List<Variable> variables) {
    this.model = model;
    this.resource = resource;
    this.pendingResources = Lists.newLinkedList();
    this.parsedResources = Lists.newArrayList();
    this.resourceTarget = Maps.newLinkedHashMap();
    this.resourceBindings = Maps.newLinkedHashMap();
    boostrap(variables);/*ww  w . j  a  v a 2s.  co m*/
}

From source file:org.cloudsmith.geppetto.ruby.jrubyparser.RubyRakefileTaskFinder.java

public Map<String, String> findTasks(Node root) {
    // use a linked map to get entries in the order they are added
    Map<String, String> resultMap = Maps.newLinkedHashMap();

    this.stack = Lists.newLinkedList();
    this.nameStack = Lists.newLinkedList();

    // this.qualifiedName = Lists.reverse(Lists.newArrayList(qualifiedName));
    if (root != null)
        findTasksInternal(root, resultMap);
    return resultMap;
}