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(Iterable<? extends E> elements) 

Source Link

Document

Creates a mutable LinkedList instance containing the given elements; a very thin shortcut for creating an empty list then calling Iterables#addAll .

Usage

From source file:com.facebook.buck.distributed.BuildTargetsQueue.java

public static BuildTargetsQueue newQueue(BuildRuleResolver resolver, Iterable<BuildTarget> targetsToBuild) {
    // Build the reverse dependency graph by traversing the action graph Top-Down.
    Map<String, Set<String>> allReverseDeps = new HashMap<>();
    Map<String, Integer> numberOfDependencies = new HashMap<>();
    Set<String> visitedTargets = Sets.newHashSet();
    Queue<BuildRule> buildRulesToProcess = Lists
            .newLinkedList(FluentIterable.from(targetsToBuild).transform(x -> {
                BuildRule rule = resolver.getRule(x);
                visitedTargets.add(ruleToTarget(rule));
                return rule;
            }));/* w  w  w  .j ava  2s.  co m*/
    while (!buildRulesToProcess.isEmpty()) {
        BuildRule rule = buildRulesToProcess.remove();
        String target = ruleToTarget(rule);
        numberOfDependencies.put(target, rule.getBuildDeps().size());
        for (BuildRule dependencyRule : rule.getBuildDeps()) {
            String dependencyTarget = ruleToTarget(dependencyRule);
            if (!allReverseDeps.containsKey(dependencyTarget)) {
                allReverseDeps.put(dependencyTarget, Sets.newHashSet());
            }
            allReverseDeps.get(dependencyTarget).add(target);

            if (!visitedTargets.contains(dependencyTarget)) {
                visitedTargets.add(dependencyTarget);
                buildRulesToProcess.add(dependencyRule);
            }
        }
    }

    // Do the reference counting and create the EnqueuedTargets.
    List<EnqueuedTarget> zeroDependencyTargets = new ArrayList<>();
    Map<String, EnqueuedTarget> allEnqueuedTargets = new HashMap<>();
    for (String target : visitedTargets) {
        Iterable<String> currentRevDeps = null;
        if (allReverseDeps.containsKey(target)) {
            currentRevDeps = allReverseDeps.get(target);
        } else {
            currentRevDeps = new ArrayList<>();
        }

        EnqueuedTarget enqueuedTarget = new EnqueuedTarget(target, ImmutableList.copyOf(currentRevDeps),
                Preconditions.checkNotNull(numberOfDependencies.get(target)));
        allEnqueuedTargets.put(target, enqueuedTarget);

        if (enqueuedTarget.areAllDependenciesResolved()) {
            zeroDependencyTargets.add(enqueuedTarget);
        }
    }

    return new BuildTargetsQueue(zeroDependencyTargets, allEnqueuedTargets);
}

From source file:org.splevo.jamopp.refactoring.java.caslicensehandler.cheatsheet.actions.JaMoPPRoutines.java

/**
 * Returns the concrete classifier (JaMoPP) for the given type (JavaCore).
 * /* ww w.  j  ava2s.  c o m*/
 * @param type
 *            represents the type.
 * @return the matched classifier.
 */
public static Optional<ConcreteClassifier> getConcreteClassifierOf(IType type) {
    ResourceSet resourceSet = ((JaMoPPJavaSoftwareElement) CASLicenseHandlerConfiguration.getInstance()
            .getVariationPoint().getLocation()).getJamoppElement().eResource().getResourceSet();

    final String typeName = type.getElementName();
    URI resourceURI = URI.createPlatformResourceURI(type.getResource().getFullPath().toString(), true);
    Resource r = resourceSet.getResource(resourceURI, true);
    for (CompilationUnit cu : Iterables.filter(r.getContents(), CompilationUnit.class)) {
        LinkedList<ConcreteClassifier> queue = Lists.newLinkedList(cu.getClassifiers());
        while (!queue.isEmpty()) {
            ConcreteClassifier classifier = queue.pop();
            if (typeName.equals(classifier.getName())) {
                return Optional.of(classifier);
            }
        }
    }

    return Optional.absent();
}

From source file:org.auraframework.test.mock.Stub.java

public Stub(Invocation invocation, List<Answer<T>> answers) {
    if (answers.isEmpty()) {
        throw new IllegalArgumentException("Must provide at least one answer for a stub");
    }/*w  w w . j  ava  2s .  co m*/
    reset();
    this.invocation = invocation;
    this.answers = Lists.newLinkedList(answers);
}

From source file:cc.recommenders.io.Logger.java

public static List<String> getCapturedLog() {
    return Lists.newLinkedList(log);
}

From source file:com.ykun.commons.utils.collection.ListUtils.java

/**
 * @see com.google.common.collect.Lists#newArrayList
 *//* w ww  .j a  va  2 s.  c o m*/
public static <T> LinkedList<T> newLinkedList(Iterable<? extends T> elements) {
    return Lists.newLinkedList(elements);
}

From source file:de.minestar.director.threading.BatchRunnable.java

public void copyList(List<QueuedBlock> list) {
    queue = Lists.newLinkedList(list);
}

From source file:com.insightml.data.utils.InstancesFilter.java

static <I extends Sample> ISamples<I, ?> filterBySmallestLabelSize(final Iterable<I> instances) {
    final List<I> filtered = new LinkedList<>();
    final List<I> instancesCopy = Lists.newLinkedList(instances);
    final int oldSize = instancesCopy.size();
    final int max = getMaxInstances(instances);

    final Map<String, Integer> labels = new HashMap<>();
    for (int i = 0; i < oldSize; ++i) {
        final int index = (int) (Math.random() * instancesCopy.size());
        final I instance = instancesCopy.remove(index);
        final String label = (String) instance.getExpected(0);
        final Integer count = labels.get(label);
        if (count == null || count.doubleValue() < max) {
            filtered.add(instance);//from w w  w.  ja va 2s .c  om
            labels.put(label, count == null ? 1 : count + 1);
        }
    }
    return new Samples<>(filtered);
}

From source file:com.google.jstestdriver.debugger.DebuggerFileListProcessor.java

public List<FileInfo> processTests(List<FileInfo> files) {
    LinkedList<FileInfo> processed = Lists.newLinkedList(files);
    processed.add(new FileInfo("debugger.js", time.now().getMillis(), -1, false, false, DEBUGGER_SOURCE,
            "debugger.js"));
    return processed;
}

From source file:org.apache.crunch.impl.mr.plan.NodePath.java

public NodePath(NodePath other) {
    this.path = Lists.newLinkedList(other.path);
}

From source file:ru.frostman.web.classloading.enhance.Enhancer.java

public static void prepareClasses(Map<String, AppClass> classes) {
    for (AppClass appClass : Lists.newLinkedList(classes.values())) {
        appClass.setEnhancedBytecode(null);

        if (appClass.isGenerated()) {
            classes.remove(appClass.getName());
            continue;
        }//w w w .  j  a  va 2  s  .  co m

        CtClass ctClass;
        try {
            ctClass = classPool.makeClass(new ByteArrayInputStream(appClass.getBytecode()));
        } catch (Exception e) {
            throw new EnhancerException(e);
        }

        appClass.setCtClass(ctClass);
    }

}