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:org.apache.shindig.gadgets.parse.GadgetCssRule.java

/**
 * Create a new, blank rule. At least one selector must be added
 * for the rule to be valid (and serializable).
 *///from   w ww . j  a va  2 s. co  m
public GadgetCssRule() {
    selectors = Lists.newLinkedList();
    declarations = Maps.newHashMap();
}

From source file:com.facebook.buck.graph.AbstractAcyclicDepthFirstPostOrderTraversal.java

/**
 * Performs a depth-first, post-order traversal over a DAG.
 * @param initialNodes The nodes from which to perform the traversal. Not allowed to contain
 *     {@code null}.//w  w w.  j  a  va 2  s  .  c o m
 * @throws CycleException if a cycle is found while performing the traversal.
 */
@SuppressWarnings("PMD.PrematureDeclaration")
public void traverse(Iterable<? extends T> initialNodes) throws CycleException, IOException {
    // This corresponds to the current chain of nodes being explored. Enforcing this invariant makes
    // this data structure useful for debugging.
    Deque<Explorable> toExplore = Lists.newLinkedList();
    for (T node : initialNodes) {
        toExplore.add(new Explorable(node));
    }

    Set<T> inProgress = Sets.newHashSet();
    LinkedHashSet<T> explored = Sets.newLinkedHashSet();

    while (!toExplore.isEmpty()) {
        Explorable explorable = toExplore.peek();
        T node = explorable.node;

        // This could happen if one of the initial nodes is a dependency of the other, for example.
        if (explored.contains(node)) {
            toExplore.removeFirst();
            continue;
        }

        inProgress.add(node);

        // Find children that need to be explored to add to the stack.
        int stackSize = toExplore.size();
        for (Iterator<T> iter = explorable.children; iter.hasNext();) {
            T child = iter.next();
            if (inProgress.contains(child)) {
                throw createCycleException(child, toExplore);
            } else if (!explored.contains(child)) {
                toExplore.addFirst(new Explorable(child));

                // Without this break statement:
                // (1) Children will be explored in reverse order instead of the specified order.
                // (2) CycleException may contain extra nodes.
                // Comment out the break statement and run the unit test to verify this for yourself.
                break;
            }
        }

        if (stackSize == toExplore.size()) {
            // Nothing was added to toExplore, so the current node can be popped off the stack and
            // marked as explored.
            toExplore.removeFirst();
            inProgress.remove(node);
            explored.add(node);

            // Now that the internal state of this traversal has been updated, notify the observer.
            onNodeExplored(node);
        }
    }

    Preconditions.checkState(inProgress.isEmpty(), "No more nodes should be in progress.");

    onTraversalComplete(Iterables.unmodifiableIterable(explored));
}

From source file:org.apache.helix.controller.stages.PersistContextStage.java

@Override
public void process(ClusterEvent event) throws Exception {
    HelixManager helixManager = event.getAttribute("helixmanager");
    HelixDataAccessor accessor = helixManager.getHelixDataAccessor();
    PropertyKey.Builder keyBuilder = accessor.keyBuilder();
    ControllerContextProvider contextProvider = event.getAttribute(AttributeName.CONTEXT_PROVIDER.toString());

    // remove marked contexts
    Set<ContextId> removedContexts = contextProvider.getRemovedContexts();
    List<String> removedPaths = Lists.newLinkedList();
    for (ContextId contextId : removedContexts) {
        removedPaths.add(keyBuilder.controllerContext(contextId.stringify()).getPath());
    }//w  w w. ja v  a2  s. co  m
    if (removedPaths.size() > 0) {
        accessor.getBaseDataAccessor().remove(removedPaths, 0);
    }

    // persist pending contexts
    Map<ContextId, ControllerContext> pendingContexts = contextProvider.getPendingContexts();
    List<PropertyKey> keys = Lists.newArrayList();
    List<ControllerContextHolder> properties = Lists.newArrayList();
    for (ContextId contextId : pendingContexts.keySet()) {
        ControllerContextHolder holder = new ControllerContextHolder(pendingContexts.get(contextId));
        if (holder != null) {
            keys.add(keyBuilder.controllerContext(contextId.stringify()));
            properties.add(holder);
        }
    }

    if (keys.size() > 0) {
        accessor.setChildren(keys, properties);
    }
}

From source file:org.summer.ss.core.resource.ImportScope.java

public Iterable<IEObjectDescription> getElements(QualifiedName name) {
    List<IEObjectDescription> result = Lists.newLinkedList();
    Iterable<IEObjectDescription> elements = getAllElements();
    for (IEObjectDescription ed : elements) {
        if (ed.getQualifiedName().equals(name)) {
            result.add(ed);/* w  w w  . j  a v  a  2  s.  c om*/
        }
    }

    if (parent != null) {
        result.addAll(Lists.newLinkedList(parent.getElements(name)));
    }

    return result;
}

From source file:org.apache.kylin.tool.metrics.systemcube.KylinTableCreator.java

public static TableDesc generateKylinTableForMetricsQueryRPC(KylinConfig kylinConfig, SinkTool sinkTool) {
    List<Pair<String, String>> columns = Lists.newLinkedList();
    columns.addAll(HiveTableCreator.getHiveColumnsForMetricsQueryRPC());
    columns.addAll(HiveTableCreator.getPartitionKVsForHiveTable());
    return generateKylinTable(sinkTool, kylinConfig.getKylinMetricsSubjectQueryRpcCall(), columns);
}

From source file:org.killbill.billing.invoice.tree.ItemsInterval.java

public ItemsInterval(final ItemsNodeInterval interval, final Item initialItem) {
    this.interval = interval;
    this.items = Lists.newLinkedList();
    if (initialItem != null) {
        items.add(initialItem);/*www .j  a  v  a2  s. com*/
    }
}

From source file:cc.recommenders.evaluation.io.ProjectFoldedUsageStore.java

public TypeStore createTypeStore(ICoReTypeName type, int numFolds) throws IOException {
    Asserts.assertGreaterThan(numFolds, 0);
    Asserts.assertTrue(isAvailable(type, numFolds));

    List<ProjectFoldedUsage> usages = Lists.newLinkedList();

    String fileName = type.toString().replace('/', '_') + ".zip";
    IReadingArchive ra = in.getReadingArchive(fileName);
    while (ra.hasNext()) {
        ProjectFoldedUsage pfu = ra.getNext(ProjectFoldedUsage.class);
        usages.add(pfu);//from   w ww  .java2  s . c o  m
    }
    ra.close();
    Map<String, Integer> counts = index.getCounts(type);
    Map<String, Integer> mapping = foldingStrategy.createMapping(counts, numFolds);
    return new TypeStore(usages, mapping);
}

From source file:com.programmablefun.runtime.RangeValue.java

public List<Value> asList() {
    List<Value> res = Lists.newLinkedList();
    RangeIterator iter = new RangeIterator();
    while (iter.hasNext()) {
        res.add(iter.next());/* w  w  w.  j  av a2 s.  c o  m*/
    }
    return res;
}

From source file:org.gradle.launcher.continuous.TaskInputsWatcher.java

public TaskInputsWatcher(TriggerListener listener, FileWatcherFactory fileWatcherFactory) {
    this.listener = listener;
    this.fileWatcherFactory = fileWatcherFactory;
    this.tasks = Lists.newLinkedList();
}

From source file:org.onosproject.drivers.lumentum.PortDiscoveryLumentumRoadm.java

@Override
public List<PortDescription> getPorts() {
    try {/* ww  w.  ja  v a2 s  .  c o  m*/
        snmp = new LumentumSnmpDevice(handler().data().deviceId());
    } catch (IOException e) {
        log.error("Failed to connect to device: ", e);

        return Collections.emptyList();
    }

    List<PortDescription> ports = Lists.newLinkedList();

    OID[] oids = { new OID(CTRL_PORT_STATE + "1"), new OID(CTRL_PORT_STATE + "2") };

    for (OID oid : oids) {

        for (TreeEvent event : snmp.get(oid)) {
            if (event != null) {
                VariableBinding[] varBindings = event.getVariableBindings();
                for (VariableBinding varBinding : varBindings) {
                    if (varBinding.getVariable().toInt() == 1) {
                        int portNumber = varBinding.getOid().removeLast();
                        int portDirection = varBinding.getOid().removeLast();
                        SparseAnnotations ann = DefaultAnnotations.builder()
                                .set(AnnotationKeys.PORT_NAME, portDirection + "-" + portNumber).build();
                        PortDescription p = new OmsPortDescription(PortNumber.portNumber(ports.size() + 1),
                                true, LumentumSnmpDevice.START_CENTER_FREQ, LumentumSnmpDevice.END_CENTER_FREQ,
                                LumentumSnmpDevice.CHANNEL_SPACING.frequency(), ann);
                        ports.add(p);
                    }
                }
            }
        }
    }

    // Create LINE IN and LINE OUT ports as these are not reported through SNMP
    SparseAnnotations annLineIn = DefaultAnnotations.builder().set(AnnotationKeys.PORT_NAME, "LINE IN").build();
    ports.add(new OmsPortDescription(PortNumber.portNumber(ports.size() + 1), true,
            LumentumSnmpDevice.START_CENTER_FREQ, LumentumSnmpDevice.END_CENTER_FREQ,
            LumentumSnmpDevice.CHANNEL_SPACING.frequency(), annLineIn));

    SparseAnnotations annLineOut = DefaultAnnotations.builder().set(AnnotationKeys.PORT_NAME, "LINE OUT")
            .build();
    ports.add(new OmsPortDescription(PortNumber.portNumber(ports.size() + 1), true,
            LumentumSnmpDevice.START_CENTER_FREQ, LumentumSnmpDevice.END_CENTER_FREQ,
            LumentumSnmpDevice.CHANNEL_SPACING.frequency(), annLineOut));

    return ports;
}