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:org.onosproject.store.mastership.impl.RoleValue.java

/**
 * Constructs copy of specified RoleValue.
 *
 * @param original original to create copy from
 */// ww w .j  a  va  2 s .c o m
public RoleValue(final RoleValue original) {
    value.put(MASTER, Lists.newLinkedList(original.value.get(MASTER)));
    value.put(STANDBY, Lists.newLinkedList(original.value.get(STANDBY)));
    value.put(NONE, Lists.newLinkedList(original.value.get(NONE)));
}

From source file:org.opendaylight.protocol.bgp.rib.mock.BGPMock.java

public BGPMock(final EventBus eventBus, final MessageRegistry registry, final List<byte[]> bgpMessages) {
    this.allPreviousByteMessages = Lists.newLinkedList(bgpMessages);
    this.eventBus = eventBus;
    this.allPreviousBGPMessages = this.parsePrevious(registry, this.allPreviousByteMessages);
}

From source file:com.griddynamics.jagger.engine.e1.scenario.DefaultMaxTpsCalculator.java

@Override
public BigDecimal getMaxTps(NodeTpsStatistics stats) {
    Table<Integer, Integer, Pair<Long, BigDecimal>> threadDelayStats = stats.getThreadDelayStats();

    Map<Integer, Pair<Long, BigDecimal>> threadsTps = threadDelayStats.column(0);
    log.debug("Going to calculate max tps for {}", threadsTps);
    List<Integer> threads = Lists.newLinkedList(threadsTps.keySet());

    if (threads.size() < SAMPLE_SIZE) {
        log.debug("Not enough samples to guess a tps max on node");
        return null;
    }//  www .  ja  v  a  2  s .com

    Collections.sort(threads);

    BigDecimal max = null;
    boolean isNonIncreasing = true;

    int start = threads.size() - SAMPLE_SIZE;
    int end = threads.size();

    BigDecimal previous = null;
    for (int i = start; i < end; i++) {
        Integer threadCount = threads.get(i);

        BigDecimal tps = threadsTps.get(threadCount).getSecond();

        if (previous == null) {
            max = tps;
            previous = tps;
        }

        if (tps.compareTo(previous) > 0) {
            isNonIncreasing = false;
            break;
        }

        if (previous.compareTo(max) > 0) {
            max = previous;
        }
    }

    if (!isNonIncreasing) {
        log.debug("Cannot guess max tps. According to stats tps is increasing.");
        return null;
    }

    return max;
}

From source file:ai.grakn.graql.internal.reasoner.query.ReasonerQueryImplCumulativeIterator.java

ReasonerQueryImplCumulativeIterator(Answer sub, LinkedList<ReasonerAtomicQuery> qs,
        Set<ReasonerAtomicQuery> subGoals, QueryCache<ReasonerAtomicQuery> cache) {
    this.subGoals = subGoals;
    this.cache = cache;
    this.partialSub = sub;
    this.nextList = Lists.newLinkedList(qs);

    Iterator<Answer> iterator = nextList.removeFirst().iterator(sub, subGoals, cache);

    this.queryIterator = nextList.isEmpty() ? iterator : Collections.emptyIterator();
    this.atomicQueryIterator = nextList.isEmpty() ? Collections.emptyIterator() : iterator;
}

From source file:org.apache.isis.core.metamodel.facets.CollectionUtils.java

/**
 * Copies the iterable into the specified type.
 *///  ww  w. j ava 2s . c o  m
public static Object copyOf(final Iterable<Object> iterable, final Class<?> requiredType) {

    if (iterable == null) {
        throw new IllegalArgumentException("Iterable must be provided");
    }
    if (requiredType == null) {
        throw new IllegalArgumentException("RequiredType must be provided");
    }

    // specific list implementations
    if (CopyOnWriteArrayList.class == requiredType) {
        return Lists.newCopyOnWriteArrayList(iterable);
    }
    if (LinkedList.class == requiredType) {
        return Lists.newLinkedList(iterable);
    }
    if (ArrayList.class == requiredType) {
        return Lists.newArrayList(iterable);
    }

    if (AbstractList.class == requiredType) {
        return Lists.newArrayList(iterable);
    }

    // specific set implementations
    if (CopyOnWriteArraySet.class == requiredType) {
        return Sets.newCopyOnWriteArraySet(iterable);
    }
    if (LinkedHashSet.class == requiredType) {
        return Sets.newLinkedHashSet(iterable);
    }
    if (HashSet.class == requiredType) {
        return Sets.newHashSet(iterable);
    }
    if (TreeSet.class == requiredType) {
        Iterable rawIterable = iterable;
        return Sets.newTreeSet(rawIterable);
    }

    if (AbstractSet.class == requiredType) {
        return Sets.newLinkedHashSet(iterable);
    }

    // interfaces
    if (List.class == requiredType) {
        return Lists.newArrayList(iterable);
    }
    if (SortedSet.class == requiredType) {
        Iterable rawIterable = iterable;
        return Sets.newTreeSet(rawIterable);
    }
    if (Set.class == requiredType) {
        return Sets.newLinkedHashSet(iterable);
    }
    if (Collection.class == requiredType) {
        return Lists.newArrayList(iterable);
    }

    // array
    if (requiredType.isArray()) {
        Class<?> componentType = requiredType.getComponentType();
        Iterable rawIterable = iterable;
        return Iterables.toArray(rawIterable, componentType);
    }

    // not recognized
    return null;
}

From source file:com.intelligentsia.dowsers.entity.meta.provider.MetaEntityProviderFilterLastVersion.java

@Override
public Collection<MetaEntity> find(final Reference reference) throws NullPointerException {
    // call super
    final LinkedList<MetaEntity> metaEntities = Lists.newLinkedList(super.find(reference));
    // take first
    if (metaEntities.isEmpty()) {
        return ImmutableSet.of();
    } else {//  w ww  .j  av a  2  s  .  c  o  m
        // sort
        Collections.sort(metaEntities);
        // take first
        return ImmutableSet.of(metaEntities.getFirst());
    }
}

From source file:org.grouplens.lenskit.util.parallel.TaskGraphManager.java

TaskGraphManager(String n, DAGNode<T, E> graph) {
    name = n;/*from  w w  w .j a  v a  2  s.c  o  m*/
    tasksToRun = Lists.newLinkedList(graph.getSortedNodes());
    finishedTasks = Sets.newHashSet();
    threads = Lists.newLinkedList();
    errors = Lists.newLinkedList();
    runningTasks = Lists.newLinkedList();
}

From source file:heros.fieldsens.CallEdgeResolver.java

public void applySummaries(WrappedFactAtStatement<Field, Fact, Stmt, Method> factAtStmt) {
    for (CallEdge<Field, Fact, Stmt, Method> incEdge : Lists.newLinkedList(incomingEdges)) {
        analyzer.applySummary(incEdge, factAtStmt);
    }/*www.j av a 2  s  . c o  m*/
}

From source file:com.google.jstestdriver.model.RunDataFactory.java

/**
 * Creates a rRunData from the fileSet and plugin hooks.
 * @return A new RunData for a test pass.
 *///from w  w w  .  j  av a  2s  . c  om
public RunData get() {
    stopWatch.start("Create RunData");
    try {
        List<FileInfo> processedDependencies = Lists.newLinkedList(fileSet);
        List<FileInfo> processedPlugins = Lists.newLinkedList(plugins);
        List<FileInfo> processedTests = Lists.newLinkedList(tests);

        for (ResourcePreProcessor processor : processors) {
            stopWatch.start(processor.toString());
            processedPlugins = processor.processPlugins(processedPlugins);
            processedTests = processor.processTests(processedTests);
            processedDependencies = processor.processDependencies(processedDependencies);
            stopWatch.stop(processor.toString());
        }
        return new RunData(Collections.<ResponseStream>emptyList(),
                testCaseFactory.createCases(processedPlugins, processedDependencies, processedTests),
                testCaseFactory);
    } finally {
        stopWatch.stop("Create RunData");
    }
}

From source file:org.smartdeveloperhub.curator.RandomMessageIdentifierFactory.java

private RandomMessageIdentifierFactory(List<UUID> ids) {
    this.count = 0;
    this.generated = ImmutableList.copyOf(ids);
    this.consumed = Lists.newArrayList();
    this.ids = Lists.newLinkedList(ids);
}