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:com.chiorichan.factory.ScriptingBaseJava.java

@SuppressWarnings("unchecked")
String var_export(Object... objs) {
    StringBuilder sb = new StringBuilder();

    for (Object obj : objs) {
        if (obj != null) {
            Map<String, Object> children = Maps.newLinkedHashMap();

            if (obj instanceof Map) {
                for (Entry<Object, Object> e : ((Map<Object, Object>) obj).entrySet()) {
                    String key = ObjectUtil.castToString(e.getKey());
                    if (key == null)
                        key = e.getKey().toString();
                    children.put(key, e.getValue());
                }/*from   w w  w  . ja v a 2s. c om*/
            } else if (obj instanceof List) {
                for (int i = 0; i < ((List<Object>) obj).size(); i++)
                    children.put("" + i, ((List<Object>) obj).get(i));
            } else if (obj instanceof Object[]) {
                for (int i = 0; i < ((Object[]) obj).length; i++)
                    children.put("" + i, ((Object[]) obj)[i]);
            }

            // boolean[], byte[], short[], char[], int[], long[], float[], double[], Object[]

            Object value = ObjectUtil.castToString(obj);
            if (value == null)
                value = obj.toString();

            if (!children.isEmpty())
                value = children.size();

            sb.append("\n" + obj.getClass().getName() + "(" + value + ")");

            if (!children.isEmpty()) {
                sb.append(" {");
                for (Entry<String, Object> c : children.entrySet()) {
                    sb.append("\n\t[" + c.getKey() + "]=>");
                    for (String s : var_export(c.getValue()).split("\n"))
                        sb.append("\n\t" + s);
                }
                sb.append("\n}");
            }
        } else {
            sb.append("\nnull");
        }
    }

    return sb.substring(1).toString();
}

From source file:com.mgmtp.perfload.loadprofiles.ui.util.GraphPointsCalculator.java

/**
 * Calculates graph points for the given list of curve assignments (one graph per curve name).
 * /*from  w  w w  .j a  va  2 s.c  om*/
 * @param stairs
 *            The list of curve assignments
 * @return A map of lists of points. The curve names are the keys.
 */
public Map<String, Set<Point>> calculatePoints(final Collection<Stairs> stairs) {
    List<String> curveNames = computeCurveNames(stairs);

    Map<String, Set<Point>> pointsMap = Maps.newLinkedHashMap();

    for (final String curveName : curveNames) {
        List<CurveItem> curves = Lists.newArrayList();

        for (Stairs item : stairs) {
            if (item.operation.getName().equals(curveName)) {
                CurveItem curve = new CurveItem(calculatePoints(item));
                curves.add(curve);
            }
        }

        pointsMap.put(curveName, sumUpCurves(curves));
    }

    return pointsMap;
}

From source file:org.apache.brooklyn.util.core.task.AbstractExecutionContext.java

/** @see #submit(Map, Runnable) */
@Override
public <T> Task<T> submit(Callable<T> callable) {
    return submitInternal(Maps.newLinkedHashMap(), callable);
}

From source file:com.google.gerrit.server.project.GetConfig.java

@Override
public ConfigInfo apply(ProjectResource resource) {
    ConfigInfo result = new ConfigInfo();
    RefControl refConfig = resource.getControl().controlForRef(GitRepositoryManager.REF_CONFIG);
    ProjectState project = resource.getControl().getProjectState();
    if (refConfig.isVisible()) {
        result.useContributorAgreements = project.isUseContributorAgreements();
        result.useContentMerge = project.isUseContentMerge();
        result.useSignedOffBy = project.isUseSignedOffBy();
        result.requireChangeId = project.isRequireChangeID();
    }//from   w ww  .j  a  va2  s  .  c o  m

    // commentlinks are visible to anyone, as they are used for linkification
    // on the client side.
    result.commentlinks = Maps.newLinkedHashMap();
    for (CommentLinkInfo cl : project.getCommentLinks()) {
        result.commentlinks.put(cl.name, cl);
    }

    // Themes are visible to anyone, as they are rendered client-side.
    result.theme = project.getTheme();
    return result;
}

From source file:com.google.caliper.runner.instrument.JarFinder.java

/**
 * Returns a list of jar files reachable from the given class loaders.
 *
 * <p><b>Warning:</b> Current limitations:
 *
 * <ul>/*from   w  w  w .  j a  v a  2 s  . c o  m*/
 *   <li>Looks only for files and JARs in URLs available from {@link URLClassLoader} instances or
 *       the {@linkplain ClassLoader#getSystemClassLoader() system class loader}.
 *   <li>Only understands {@code file:} URLs.
 * </ul>
 *
 * @throws IOException if the attempt to read class path resources (jar files or directories)
 *     failed.
 */
public static ImmutableSet<File> findJarFiles(ClassLoader first, ClassLoader... rest) throws IOException {
    Scanner scanner = new Scanner();
    Map<File, ClassLoader> map = Maps.newLinkedHashMap();
    for (ClassLoader classLoader : Lists.asList(first, rest)) {
        map.putAll(getClassPathEntries(classLoader));
    }
    for (Map.Entry<File, ClassLoader> entry : map.entrySet()) {
        scanner.scan(entry.getKey(), entry.getValue());
    }
    return scanner.jarFiles();
}

From source file:com.bj58.oceanus.core.context.TransactionContext.java

public TransactionContext() {
    connsInTransaction = Maps.newLinkedHashMap();
    stmtsInTransaction = Maps.newLinkedHashMap();
    sqlsInTransaction = Lists.newLinkedList();
}

From source file:org.gradle.api.internal.tasks.compile.incremental.classpath.SplitClasspathEntrySnapshotCache.java

@Override
public Map<File, ClasspathEntrySnapshot> getClasspathEntrySnapshots(Map<File, HashCode> fileHashes) {
    Map<File, HashCode> globalEntries = Maps.newLinkedHashMap();
    Map<File, HashCode> localEntries = Maps.newLinkedHashMap();
    for (Map.Entry<File, HashCode> entry : fileHashes.entrySet()) {
        if (fileLocations.isImmutable(entry.getKey().getPath())) {
            globalEntries.put(entry.getKey(), entry.getValue());
        } else {/*from   w  ww  . j  a v  a 2 s .  c  o m*/
            localEntries.put(entry.getKey(), entry.getValue());
        }
    }
    Map<File, ClasspathEntrySnapshot> globalSnapshots = globalCache.getClasspathEntrySnapshots(globalEntries);
    Map<File, ClasspathEntrySnapshot> localSnapshots = localCache.getClasspathEntrySnapshots(localEntries);

    Map<File, ClasspathEntrySnapshot> snapshots = Maps.newLinkedHashMap();
    for (File entry : fileHashes.keySet()) {
        ClasspathEntrySnapshot snapshot = globalSnapshots.get(entry);
        if (snapshot == null) {
            snapshot = localSnapshots.get(entry);
        }
        snapshots.put(entry, snapshot);
    }
    return snapshots;
}

From source file:org.graylog2.plugin.configuration.ConfigurationRequest.java

@JsonValue
public Map<String, Map<String, Object>> asList() {
    final Map<String, Map<String, Object>> configs = Maps.newLinkedHashMap();

    for (ConfigurationField f : fields.values()) {
        final Map<String, Object> config = Maps.newHashMap();
        config.put("type", f.getFieldType());
        config.put("human_name", f.getHumanName());
        config.put("description", f.getDescription());
        config.put("default_value", f.getDefaultValue());
        config.put("is_optional", f.isOptional().equals(ConfigurationField.Optional.OPTIONAL));
        config.put("attributes", f.getAttributes());
        config.put("additional_info", f.getAdditionalInformation());

        configs.put(f.getName(), config);
    }/*from   ww w .j a v  a 2s  .  c  o  m*/

    return configs;
}

From source file:org.valens.TemplateConfigurator.java

@Override
public void populateContextForEdit(@NotNull Map<String, Object> context, @NotNull BuildConfiguration bc,
        @Nullable Plan plan) {// w w w . j  av a 2  s .  co m

    Map<String, String> result = Maps.newLinkedHashMap();
    super.populateContextForEdit(context, bc, plan);

    if (planManager != null) {
        for (TopLevelPlan p : planManager.getAllPlansUnrestricted()) {
            boolean state = true;
            if (p.getBuildDefinition().getCustomConfiguration().get(SELECTED_TEMPLATE_ENABLED) == null
                    || p.getBuildDefinition().getCustomConfiguration().get(SELECTED_TEMPLATE_ENABLED).toString()
                            .equalsIgnoreCase("false")) {
                state = false;
            }
            if (state) {
                for (Job j : p.getAllJobs()) {
                    log.debug("populateContextForEdit  " + p.getProject() + " - " + p.getName());
                    result.put(j.getName(), j.getKey());
                }
            }
        }
    }

    context.put("templates", result);
}

From source file:blockplus.model.OptionsSupplier.java

private Map<IPosition, Set<IPosition>> getPotentialPositionsByLight(final Board board, final Colors color,
        final Iterable<IPosition> lights, final int radius) {
    final Map<IPosition, Set<IPosition>> map = Maps.newLinkedHashMap();
    for (final IPosition light : lights) {
        final Set<IPosition> potentialReferentialPositions = Sets.newTreeSet();
        for (int k = 0; k <= radius; ++k)
            for (final IPosition neighbour : board.neighbours(light, k))
                if (board.isMutable(color, neighbour))
                    potentialReferentialPositions.add(neighbour);
        map.put(light, potentialReferentialPositions);
    }/*  w w w.j a  va  2 s .  co  m*/
    return map;
}