Example usage for java.util LinkedList isEmpty

List of usage examples for java.util LinkedList isEmpty

Introduction

In this page you can find the example usage for java.util LinkedList isEmpty.

Prototype

boolean isEmpty();

Source Link

Document

Returns true if this list contains no elements.

Usage

From source file:de.ks.activity.initialization.ActivityInitialization.java

public Node getViewForController(Class<?> targetController) {
    if (!controllers.containsKey(targetController)) {
        throw new IllegalArgumentException("Controller " + targetController.getName()
                + " is not registered. Registered are " + controllers.keySet());
    }//from   w  w  w  .j  a v a2s . com
    LinkedList<Pair<Object, Node>> ctrls = controllers.get(targetController);
    if (ctrls.isEmpty()) {
        return null;
    } else if (ctrls.size() == 1) {
        return ctrls.get(0).getRight();
    } else {
        throw new IllegalArgumentException(
                "There are " + ctrls.size() + " instances registered for the given controller");
    }
}

From source file:com.servioticy.queueclient.SimpleQueueClient.java

@Override
protected Object getImpl() {
    LinkedList<Object> queue;
    Object returnValue;/* www  .ja v a2 s . com*/
    try {
        queue = readQueue();
    } catch (Exception e) {
        return null;
    }
    if (queue.isEmpty()) {
        return null;
    }
    returnValue = queue.getFirst();
    queue.removeFirst();

    try {
        writeQueue(queue);
    } catch (Exception e) {
    }

    return returnValue;
}

From source file:de.ks.activity.initialization.ActivityInitialization.java

@SuppressWarnings("unchecked")
public <T> T getControllerInstance(Class<T> targetController) {
    if (!controllers.containsKey(targetController)) {
        throw new IllegalArgumentException("Controller " + targetController
                + " is not registered. Registered are " + controllers.keySet());
    }/* www. j  ava 2s .c o  m*/
    LinkedList<Pair<Object, Node>> ctrls = controllers.get(targetController);
    if (ctrls.isEmpty()) {
        return null;
    } else if (ctrls.size() == 1) {
        return (T) ctrls.get(0).getLeft();
    } else {
        throw new IllegalArgumentException(
                "There are " + ctrls.size() + " instances registered for the given controller");
    }
}

From source file:org.apache.hadoop.hdfs.server.namenode.FSImageTransactionalStorageInspector.java

/**
 * @return the image files that have the most recent associated 
 * transaction IDs.  If there are multiple storage directories which 
 * contain equal images, we'll return them all.
 * /*from ww  w. j  a va 2s  .  co m*/
 * @throws FileNotFoundException if not images are found.
 */
@Override
List<FSImageFile> getLatestImages() throws IOException {
    LinkedList<FSImageFile> ret = new LinkedList<FSImageFile>();
    for (FSImageFile img : foundImages) {
        if (ret.isEmpty()) {
            ret.add(img);
        } else {
            FSImageFile cur = ret.getFirst();
            if (cur.txId == img.txId) {
                ret.add(img);
            } else if (cur.txId < img.txId) {
                ret.clear();
                ret.add(img);
            }
        }
    }
    if (ret.isEmpty()) {
        throw new FileNotFoundException("No valid image files found");
    }
    return ret;
}

From source file:de.decoit.visa.topology.NetworkCable.java

/**
 * Set the corners of the cable path. The list must have at least 1 element,
 * otherwise an InvalidArgumentException will be caused.
 *
 * @param pCorners A list of the path corners of the cable, cannot be null
 *            or empty//from www.ja va2 s .com
 */
public void setPathCorners(LinkedList<Position2D> pCorners) {
    if (pCorners != null && !pCorners.isEmpty()) {
        pathCorners = pCorners;
    } else {
        throw new IllegalArgumentException("Empty list or null provided");
    }
}

From source file:org.hyperic.hq.measurement.agent.server.TrackerThread.java

private void flushEvents(LinkedList events, String dListName) {
    if (events.isEmpty()) {
        return;/*from  w  ww .  j av  a  2 s  . c o m*/
    }

    for (Iterator i = events.iterator(); i.hasNext();) {
        TrackEvent event = (TrackEvent) i.next();

        try {
            String data = event.encode();
            this.storage.addToList(dListName, data);
            this.log.debug("Stored event (" + data.length() + " bytes) " + event);
        } catch (Exception e) {
            this.log.error("Unable to store data", e);
        }
    }
}

From source file:org.jbpm.db.JbpmSession.java

public void popCurrentSession() {
    LinkedList stack = (LinkedList) currentJbpmSessionStack.get();
    if ((stack == null) || (stack.isEmpty()) || (stack.getFirst() != this)) {
        log.warn("can't pop current session: are you calling JbpmSession.close() multiple times ?");
    } else {//from   w w  w . j  a v a  2 s .com
        stack.removeFirst();
    }
}

From source file:com.ikanow.aleph2.graph.titan.services.SimpleGraphMergeService.java

@Override
public void onObjectBatch(Stream<Tuple2<Long, IBatchRecord>> batch, Optional<Integer> batch_size,
        Optional<JsonNode> grouping_key) {

    // (some horrible mutable state to keep this simple)
    final LinkedList<Tuple2<Long, IBatchRecord>> mutable_user_elements = new LinkedList<>();

    final Optional<Validation<BasicMessageBean, JsonNode>> output = batch.filter(t2 -> {
        if (!t2._2().injected() && mutable_user_elements.isEmpty()) { // (save one element per label in case there are no injected elements)
            mutable_user_elements.add(t2);
        }//  w ww.j  a va  2  s  . c  om
        return t2._2().injected();
    }).filter(t2 -> {
        final ObjectNode o = (ObjectNode) t2._2().getJson();
        return Optional.ofNullable(o.get(GraphAnnotationBean.type)).filter(j -> (null != j) && j.isTextual())
                .map(j -> j.asText()).map(type -> {
                    if (GraphAnnotationBean.ElementType.edge.toString().equals(type)) {
                        // Return the first matching edge:
                        return true;
                    } else if (GraphAnnotationBean.ElementType.vertex.toString().equals(type)) {
                        // Return the first matching vertex:
                        return true;
                    } else
                        return false;
                }).orElse(false);
    }).findFirst().<Validation<BasicMessageBean, JsonNode>>map(
            element -> _context.get().emitImmutableObject(_context.get().getNextUnusedId(),
                    element._2().getJson(), Optional.empty(), Optional.empty(), Optional.empty()));

    if (!output.isPresent()) { // If didn't find any matching elements, then stick the first one we did find in there
        mutable_user_elements.forEach(t2 -> _context.get().emitImmutableObject(t2._1(), t2._2().getJson(),
                Optional.empty(), Optional.empty(), Optional.empty()));
    }
}

From source file:io.druid.segment.realtime.firehose.LocalFirehoseFactory.java

@Override
public Firehose connect(StringInputRowParser firehoseParser) throws IOException {
    log.info("Searching for all [%s] in and beneath [%s]", filter, baseDir.getAbsoluteFile());

    Collection<File> foundFiles = FileUtils.listFiles(baseDir.getAbsoluteFile(), new WildcardFileFilter(filter),
            TrueFileFilter.INSTANCE);//from www  .  java2s .co  m

    if (foundFiles == null || foundFiles.isEmpty()) {
        throw new ISE("Found no files to ingest! Check your schema.");
    }
    log.info("Found files: " + foundFiles);

    final LinkedList<File> files = Lists.newLinkedList(foundFiles);

    return new FileIteratingFirehose(new Iterator<LineIterator>() {
        @Override
        public boolean hasNext() {
            return !files.isEmpty();
        }

        @Override
        public LineIterator next() {
            try {
                return FileUtils.lineIterator(files.poll());
            } catch (Exception e) {
                throw Throwables.propagate(e);
            }
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }
    }, firehoseParser);
}

From source file:org.trnltk.experiment.bruteforce.BruteForceExperiments.java

@Test
public void shouldParseTbmmJournal_b0241h_andCreateRootHistogram() throws IOException {
    final File tokenizedFile = new File("core/src/test/resources/tokenizer/tbmm_b0241h_tokenized.txt");
    final List<String> lines = Files.readLines(tokenizedFile, Charsets.UTF_8);
    final LinkedList<String> words = new LinkedList<String>();
    for (String line : lines) {
        words.addAll(Lists.newArrayList(Splitter.on(" ").trimResults().omitEmptyStrings().split(line)));
    }//from w w  w.ja  va  2s  .  co  m

    final HashMultiset<Root> roots = HashMultiset.create(words.size() * 4);
    final HashMultiset<String> lemmas = HashMultiset.create(words.size() * 4);

    for (String word : words) {
        final LinkedList<MorphemeContainer> morphemeContainers = parser.parse(new TurkishSequence(word));
        if (morphemeContainers.isEmpty())
            System.out.println("Word is not parsable " + word);

        final List<Root> rootsForWord = Lists.transform(morphemeContainers,
                new Function<MorphemeContainer, Root>() {
                    @Override
                    public Root apply(MorphemeContainer input) {
                        return input.getRoot();
                    }
                });

        final List<String> lemmasForWord = Lists.transform(morphemeContainers,
                new Function<MorphemeContainer, String>() {
                    @Override
                    public String apply(MorphemeContainer input) {
                        return input.getRoot().getLexeme().getLemma();
                    }
                });

        roots.addAll(rootsForWord);
        lemmas.addAll(lemmasForWord);

        if (roots.size() > 50000)
            break;
    }

    System.out.println("Found lemma count " + lemmas.size());
    final ImmutableMultiset<String> lemmasSortedByCount = Multisets.copyHighestCountFirst(lemmas);
    for (Multiset.Entry<String> stringEntry : lemmasSortedByCount.entrySet()) {
        final String lemma = stringEntry.getElement();
        final int count = stringEntry.getCount();
        System.out.println(String.format("%5d ", count) + lemma);
    }

    System.out.println("Found root count " + roots.size());
    //        final ImmutableMultiset<Root> rootsSortedByCount = Multisets.copyHighestCountFirst(roots);
    //        for (Multiset.Entry<Root> rootEntry : rootsSortedByCount.entrySet()) {
    //            final Root root = rootEntry.getElement();
    //            final int count = rootEntry.getCount();
    //            System.out.println(String.format("%5d ", count) + root.toString());
    //        }
}