Example usage for com.google.common.collect Lists newLinkedList

List of usage examples for com.google.common.collect Lists newLinkedList

Introduction

In this page you can find the example usage for com.google.common.collect Lists newLinkedList.

Prototype

@GwtCompatible(serializable = true)
public static <E> LinkedList<E> newLinkedList() 

Source Link

Document

Creates a mutable, empty LinkedList instance (for Java 6 and earlier).

Usage

From source file:exec.validate_evaluation.microcommits.FinalStateMicroCommitGenerationRunner.java

public void run() {
    Set<String> zips = qhIo.findQueryHistoryZips();
    log.foundZips(zips);/*w ww .j av a2 s. co  m*/
    for (String zip : zips) {
        log.processingZip(zip);
        List<MicroCommit> mcForUser = Lists.newLinkedList();

        Collection<List<Usage>> histories = qhIo.readQueryHistories(zip);
        log.foundHistories(histories.size());

        for (List<Usage> qh : histories) {
            List<MicroCommit> mcs = createCommits(qh);
            log.convertedToCommits(qh.size(), mcs.size());
            mcForUser.addAll(mcs);
        }
        mcIo.store(mcForUser, zip);
    }

    log.done();
}

From source file:com.chiorichan.factory.ShellFactory.java

public List<ScriptTraceElement> examineStackTrace(StackTraceElement[] stackTrace) {
    Validate.notNull(stackTrace);//www . j a  v  a  2  s . c o m

    List<ScriptTraceElement> scriptTrace = Lists.newLinkedList();

    for (StackTraceElement ste : stackTrace) {
        if (ste.getFileName() != null && ste.getFileName().matches("GroovyScript\\d*\\.chi")) {
            scriptTrace.add(new ScriptTraceElement(ste, scriptHistory.get(ste.getFileName())));
        }
    }

    return scriptTrace;
}

From source file:org.geogit.api.hooks.Hookables.java

public static List<CommandHook> findHooksFor(AbstractGeoGitOp<?> operation) {

    final Class<? extends AbstractGeoGitOp> clazz = operation.getClass();

    List<CommandHook> hooks = Lists.newLinkedList();
    /*/*  w  w w.  j ava 2  s  . c  om*/
     * First add any classpath hook, as they can be added to any command, regardless of having
     * the @Hookable annotation or not
     */
    for (CommandHook hook : classPathHooks) {
        if (hook.appliesTo(clazz)) {
            hooks.add(hook);
        }
    }

    /*
     * Now add any script hook that's configured for the operation iif it's @Hookable
     */
    final Optional<String> name = Hookables.getFilename(clazz);
    if (!name.isPresent()) {
        return hooks;
    }

    final File hooksDir = findHooksDirectory(operation);
    if (hooksDir == null) {
        return hooks;
    }

    if (name.isPresent()) {
        String preHookName = "pre_" + name.get().toLowerCase();
        String postHookName = "post_" + name.get().toLowerCase();
        File[] files = hooksDir.listFiles();
        for (File file : files) {
            String filename = file.getName();
            if (isHook(filename, preHookName)) {
                hooks.add(Scripting.createScriptHook(file, true));
            }
            if (isHook(filename, postHookName)) {
                hooks.add(Scripting.createScriptHook(file, false));
            }
        }
    }
    return hooks;

}

From source file:org.axdt.asdoc.scoping.AsdocLibraryScopeProvider.java

protected List<ISelectable> getLibraries(ResourceSet resourceSet) {
    List<ISelectable> result = cache.get(resourceSet);
    if (result == null) {
        result = Lists.newLinkedList();
        result.add(globals);/* w  w w  .  ja  va  2  s. c om*/
        for (AsdocRoot root : docRootProvider.getDocRoots(resourceSet))
            result.add(new AsdocLibrary(root));
        cache.put(resourceSet, result);
    }
    return result;
}

From source file:org.eclipse.epp.internal.logging.aeri.ui.ExpiringReportHistory.java

private void removeOutdated() {
    history.drainTo(Lists.newLinkedList());
}

From source file:org.gradle.model.internal.manage.schema.ModelSchemaExtractor.java

public <T> ModelSchema<T> extract(Class<T> type) throws InvalidManagedModelElementTypeException {
    validateType(type);/*w w  w.  j av  a 2s.co m*/

    List<Method> methodList = Arrays.asList(type.getDeclaredMethods());
    if (methodList.isEmpty()) {
        return new ModelSchema<T>(type, Collections.<ModelProperty<?>>emptyList());
    }

    List<ModelProperty<?>> properties = Lists.newLinkedList();

    Map<String, Method> methods = Maps.newHashMap();
    for (Method method : methodList) {
        String name = method.getName();
        if (methods.containsKey(name)) {
            throw invalidMethod(type, name, "overloaded methods are not supported");
        }
        methods.put(name, method);
    }

    List<String> methodNames = Lists.newLinkedList(methods.keySet());
    List<String> handled = Lists.newArrayList();

    for (ListIterator<String> iterator = methodNames.listIterator(); iterator.hasNext();) {
        String methodName = iterator.next();

        Method method = methods.get(methodName);
        if (methodName.startsWith("get") && !methodName.equals("get")) {
            if (method.getParameterTypes().length != 0) {
                throw invalidMethod(type, methodName, "getter methods cannot take parameters");
            }

            Class<?> returnType = method.getReturnType();
            if (!returnType.equals(String.class)) {
                throw invalidMethod(type, methodName, "only String properties are supported");
            }

            // hardcoded for now
            ModelType<String> propertyType = ModelType.of(String.class);

            Character getterPropertyNameFirstChar = methodName.charAt(3);
            if (!Character.isUpperCase(getterPropertyNameFirstChar)) {
                throw invalidMethod(type, methodName,
                        "the 4th character of the getter method name must be an uppercase character");
            }

            String propertyNameCapitalized = methodName.substring(3);
            String propertyName = StringUtils.uncapitalize(propertyNameCapitalized);
            String setterName = "set" + propertyNameCapitalized;

            if (!methods.containsKey(setterName)) {
                throw invalidMethod(type, methodName, "no corresponding setter for getter");
            }

            Method setter = methods.get(setterName);
            handled.add(setterName);

            if (!setter.getReturnType().equals(void.class)) {
                throw invalidMethod(type, setterName, "setter method must have void return type");
            }

            Type[] setterParameterTypes = setter.getGenericParameterTypes();
            if (setterParameterTypes.length != 1) {
                throw invalidMethod(type, setterName, "setter method must have exactly one parameter");
            }

            ModelType<?> setterType = ModelType.of(setterParameterTypes[0]);
            if (!setterType.equals(propertyType)) {
                throw invalidMethod(type, setterName,
                        "setter method param must be of exactly the same type as the getter returns (expected: "
                                + propertyType + ", found: " + setterType + ")");
            }

            properties.add(new ModelProperty<String>(propertyName, propertyType));
            iterator.remove();
        }
    }

    methodNames.removeAll(handled);

    // TODO - should call out valid getters without setters
    if (!methodNames.isEmpty()) {
        throw invalid(type, "only paired getter/setter methods are supported (invalid methods: ["
                + Joiner.on(", ").join(methodNames) + "])");
    }

    return new ModelSchema<T>(type, properties);
}

From source file:org.apache.aurora.common.net.http.handlers.ContentionPrinter.java

@GET
@Produces(MediaType.TEXT_PLAIN)/*w w  w.  j  a  va2  s  . co m*/
public String getContention() {
    List<String> lines = Lists.newLinkedList();
    ThreadMXBean bean = ManagementFactory.getThreadMXBean();

    Map<Long, StackTraceElement[]> threadStacks = Maps.newHashMap();
    for (Map.Entry<Thread, StackTraceElement[]> entry : Thread.getAllStackTraces().entrySet()) {
        threadStacks.put(entry.getKey().getId(), entry.getValue());
    }

    Set<Long> lockOwners = Sets.newHashSet();

    lines.add("Locked threads:");
    for (ThreadInfo t : bean.getThreadInfo(bean.getAllThreadIds())) {
        switch (t.getThreadState()) {
        case BLOCKED:
        case WAITING:
        case TIMED_WAITING:
            lines.addAll(getThreadInfo(t, threadStacks.get(t.getThreadId())));
            if (t.getLockOwnerId() != -1)
                lockOwners.add(t.getLockOwnerId());
            break;
        }
    }

    if (lockOwners.size() > 0) {
        lines.add("\nLock Owners");
        for (ThreadInfo t : bean.getThreadInfo(Longs.toArray(lockOwners))) {
            lines.addAll(getThreadInfo(t, threadStacks.get(t.getThreadId())));
        }
    }

    return String.join("\n", lines);
}

From source file:org.sonar.plugins.switchoffviolations.pattern.PatternDecoder.java

public List<Pattern> decode(String patternsList) {
    List<Pattern> patterns = Lists.newLinkedList();
    String[] patternsLines = StringUtils.split(patternsList, "\n");
    for (String patternLine : patternsLines) {
        Pattern pattern = decodeLine(patternLine.trim());
        if (pattern != null) {
            patterns.add(pattern);/*from  w w  w.  j a  v a 2 s.c  o m*/
        }
    }
    return patterns;
}

From source file:com.ansorgit.plugins.bash.util.CompletionUtil.java

/**
 * Provide a list of absolute paths on the current system which match the given prefix.
 * Prefix is path whose last entry may be a partial match. A match with "/etc/def" matches
 * all files and directories in /etc which start with "def".
 *
 * @param prefix A path which is used to collect matching files.
 * @param accept//from  w  ww  .  j a va2 s  . com
 * @return A list of full paths which match the prefix.
 */
@NotNull
public static List<String> completeAbsolutePath(@NotNull String prefix, Predicate<File> accept) {
    File base = new File(prefix);

    //a dot tricks Java into thinking dir/. is equal to dir and thus exists
    boolean dotSuffix = prefix.endsWith(".") && !prefix.startsWith(".");
    if (!base.exists() || dotSuffix) {
        base = base.getParentFile();
        if (base == null || !base.exists()) {
            return Collections.emptyList();
        }
    }

    File basePath;
    String matchPrefix;
    if (base.isDirectory()) {
        basePath = base;
        matchPrefix = "";
    } else {
        basePath = base.getParentFile();
        matchPrefix = base.getName();
    }

    List<String> result = Lists.newLinkedList();

    for (File fileCandidate : collectFiles(basePath, matchPrefix)) {
        if (!accept.apply(fileCandidate)) {
            continue;
        }

        if (fileCandidate.isDirectory()) {
            result.add(fileCandidate.getAbsolutePath() + "/");
        } else {
            result.add(fileCandidate.getAbsolutePath());
        }
    }

    return result;
}

From source file:org.gradoop.io.impl.tlf.functions.EdgeLabelList.java

@Override
public void flatMap(GraphTransaction<G, V, E> graphTransaction, Collector<List<String>> collector)
        throws Exception {
    List<String> list = Lists.newLinkedList();
    for (E edge : graphTransaction.getEdges()) {
        list.add(edge.getLabel());//  w w w  .  j  a va2  s . c  om
    }
    collector.collect(list);
}