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:org.gradle.model.internal.manage.schema.extract.PropertyAccessorExtractionContext.java

private Map<Class<? extends Annotation>, Annotation> collectAnnotations(Iterable<Method> methods) {
    Map<Class<? extends Annotation>, Annotation> annotations = Maps.newLinkedHashMap();
    for (Method method : methods) {
        for (Annotation annotation : method.getDeclaredAnnotations()) {
            // Make sure more specific annotation doesn't get overwritten with less specific one
            if (!annotations.containsKey(annotation.annotationType())) {
                annotations.put(annotation.annotationType(), annotation);
            }//w  ww . j  a v a2 s .  com
        }
    }
    return Collections.unmodifiableMap(annotations);
}

From source file:org.apache.tez.log.analyzer.StuckTaskAnalyzer.java

@Override
public String getAnalysis() throws IOException {
    Map<String, String> diffMap = Maps.newLinkedHashMap();
    for (Map.Entry<String, String> entry : startedTasks.entrySet()) {
        if (finishedTasks.get(entry.getKey()) == null) {
            diffMap.put(entry.getKey(), entry.getValue());
        }/*from  w w  w .j  a v a2 s. c  o  m*/
    }
    Joiner.MapJoiner joiner = Joiner.on('\n').withKeyValueSeparator("=");
    return joiner.join(diffMap);
}

From source file:org.apache.brooklyn.core.config.external.UrlsExternalConfigSupplier.java

public UrlsExternalConfigSupplier(ManagementContext managementContext, String name, Map<String, String> config)
        throws IOException {
    super(managementContext, name);
    this.config = config;
    resourceUtils = ResourceUtils.create(managementContext.getCatalogClassLoader(), this,
            UrlsExternalConfigSupplier.class.getSimpleName() + "(" + getName() + ")");

    Map<String, String> missing = Maps.newLinkedHashMap();
    for (Map.Entry<String, String> entry : config.entrySet()) {
        String target = entry.getValue();
        if (!resourceUtils.doesUrlExist(target)) {
            missing.put(entry.getKey(), entry.getValue());
        }/*from  w ww .  ja  v  a  2  s  .co  m*/
    }
    if (missing.size() > 0) {
        throw new IllegalStateException("URLs for external config '" + getName() + "' not found: " + missing);
    }
}

From source file:org.gradle.api.tasks.javadoc.AntGroovydoc.java

public void execute(final FileCollection source, File destDir, boolean use, String windowTitle, String docTitle,
        String header, String footer, String overview, boolean includePrivate, final Set<Groovydoc.Link> links,
        final Iterable<File> groovyClasspath, Iterable<File> classpath, Project project) {

    final File tmpDir = new File(project.getBuildDir(), "tmp/groovydoc");
    FileOperations fileOperations = (ProjectInternal) project;
    fileOperations.delete(tmpDir);//w  w  w.ja va 2  s.c  o m
    fileOperations.copy(new Action<CopySpec>() {
        public void execute(CopySpec copySpec) {
            copySpec.from(source).into(tmpDir);
        }
    });

    final Map<String, Object> args = Maps.newLinkedHashMap();
    args.put("sourcepath", tmpDir.toString());
    args.put("destdir", destDir);
    args.put("use", use);
    args.put("private", includePrivate);
    putIfNotNull(args, "windowtitle", windowTitle);
    putIfNotNull(args, "doctitle", docTitle);
    putIfNotNull(args, "header", header);
    putIfNotNull(args, "footer", footer);
    putIfNotNull(args, "overview", overview);

    List<File> combinedClasspath = ImmutableList.<File>builder().addAll(classpath).addAll(groovyClasspath)
            .build();

    ant.withClasspath(combinedClasspath).execute(new Closure<Object>(this, this) {
        @SuppressWarnings("UnusedDeclaration")
        public Object doCall(Object it) {
            final GroovyObjectSupport antBuilder = (GroovyObjectSupport) it;

            antBuilder.invokeMethod("taskdef",
                    ImmutableMap.of("name", "groovydoc", "classname", "org.codehaus.groovy.ant.Groovydoc"));

            antBuilder.invokeMethod("groovydoc", new Object[] { args, new Closure<Object>(this, this) {
                public Object doCall(Object ignore) {
                    for (Groovydoc.Link link : links) {
                        antBuilder.invokeMethod("link", new Object[] { ImmutableMap.of("packages",
                                Joiner.on(",").join(link.getPackages()), "href", link.getUrl()) });
                    }

                    return null;
                }
            } });

            return null;
        }
    });
}

From source file:brooklyn.location.waratek.WaratekMachineLocation.java

public WaratekMachineLocation() {
    this(Maps.newLinkedHashMap());
}

From source file:com.kolich.blog.components.cache.PageCache.java

@Injectable
public PageCache(@Required final GitRepository repo, @Required final BlogEventBus eventBus) {
    cache_ = Maps.newLinkedHashMap();
    canonicalPagesDir_ = repo.getFileRelativeToContentRoot(pagesDir__).getAbsolutePath();
    eventBus.register(this);
}

From source file:org.apache.drill.exec.compile.DrillJavaFileObject.java

public DrillJavaFileObject addOutputJavaFile(String className) {
    if (outputFiles == null) {
        outputFiles = Maps.newLinkedHashMap();
    }/*from  www  . j a  v  a 2 s  .  c  o m*/
    DrillJavaFileObject outputFile = new DrillJavaFileObject(className, Kind.CLASS);
    outputFiles.put(className, outputFile);
    return outputFile;
}

From source file:com.cinchapi.common.collect.AnyMaps.java

/**
 * Explode a "flat" map that contains navigable keys to a nested structure
 * that can be traversed using the {@link #navigate(String, Map)} method.
 * <p>//from w  ww. j  av a 2s . c o m
 * For example, if the provided {@code map} has a key {@code foo.bar.0} that
 * maps to the value "baz", this method will return a map that contains a
 * mapping from {@code foo} to a mapping from {@code bar} to a list that
 * contains the value "baz" at position 0.
 * <p>
 * <p>
 * The map returned from this method is navigable such that a query for any
 * of the keys in the original {@code map} will return the same associated
 * value from the {@link #navigate(String, Map)} method. The advantage of
 * exploding a map is that it makes it possible to fetch nested inner
 * structures from a navigable query on one of the parent keys (e.g. the
 * example above would return a map if one were to navigate for "foo")
 * </p>
 * 
 * @param map
 * @return a nested map
 * @deprecated in favor of the {@link Association} framework. Create an
 *             {@link Association} using {@link Association#of(Map)} with a
 *             "flat" map. The map will be exploded, implicitly and
 *             traversable using the {@link Association#fetch(String)}
 *             method in a manner that is similar to the way the
 *             {@link #navigate(String, Map)} method worked.
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
@Deprecated
public static Map<String, Object> explode(Map<String, Object> map) {
    Map<String, Object> exploded = Maps.newLinkedHashMap();
    map.forEach((key, value) -> {
        String[] components = key.split("\\.");
        String[] reversed = Array.reverse(components);
        Verify.thatArgument(Ints.tryParse(components[0]) == null,
                "The map cannot contain keys that start with a numeric component. " + "'{}' is an invalid key.",
                key);
        String originalKey = key;
        try {
            for (String component : reversed) {
                key = component;
                components = Arrays.copyOf(components, components.length - 1);
                String path = String.join(".", components);
                Object container;
                Integer index;
                container = navigate(path, exploded);
                if ((index = Ints.tryParse(component)) != null) {
                    if (container == null) {
                        container = Lists.newArrayList();
                    }
                    List list = (List) container;
                    for (int i = list.size(); i < index; ++i) { // Pad the
                                                                // list, if
                                                                // necessary
                        list.add(null);
                    }
                    if (index < list.size()) {
                        // This means we are modifying an existing item in
                        // the list, so we must be sure to upsert instead of
                        // adding and shifting elements around.
                        list.set(index, value);
                    } else {
                        list.add(index, value);
                    }
                } else {
                    if (container == null) {
                        container = Maps.newLinkedHashMap();
                    }
                    ((Map) container).put(component, value);
                }
                value = container;
            }
            exploded.putAll((Map) value);
        } catch (ClassCastException e) {
            throw new IllegalArgumentException(
                    AnyStrings.format("Cannot explode '{}' because the path leads to a different "
                            + "type tree than a previously exploded key.", originalKey));
        }
    });
    return exploded;
}

From source file:org.sonar.api.resources.ResourceTypes.java

public ResourceTypes(ResourceTypeTree[] trees) {
    Preconditions.checkNotNull(trees);//from  w  w w  .ja va  2s  .  c  o  m

    Map<String, ResourceTypeTree> treeMap = Maps.newHashMap();
    Map<String, ResourceType> typeMap = Maps.newLinkedHashMap();
    Collection<ResourceType> rootsSet = Sets.newHashSet();

    for (ResourceTypeTree tree : trees) {
        rootsSet.add(tree.getRootType());
        for (ResourceType type : tree.getTypes()) {
            if (treeMap.containsKey(type.getQualifier())) {
                throw new IllegalStateException(
                        "Qualifier " + type.getQualifier() + " is defined in several trees");
            }
            treeMap.put(type.getQualifier(), tree);
            typeMap.put(type.getQualifier(), type);
        }
    }
    treeByQualifier = ImmutableMap.copyOf(treeMap);
    typeByQualifier = ImmutableMap.copyOf(typeMap);
    rootTypes = ImmutableList.copyOf(rootsSet);
}

From source file:brooklyn.basic.AbstractBrooklynObject.java

public AbstractBrooklynObject() {
    this(Maps.newLinkedHashMap());
}