Example usage for java.util NoSuchElementException NoSuchElementException

List of usage examples for java.util NoSuchElementException NoSuchElementException

Introduction

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

Prototype

public NoSuchElementException() 

Source Link

Document

Constructs a NoSuchElementException with null as its error message string.

Usage

From source file:com.thoughtworks.studios.journey.utils.IterableUtils.java

public static <T> Iterable<T> uniqueBy(final Function<T, Object> function, final Iterable<T> iterable) {
    return new Iterable<T>() {
        @Override/*from w ww.j av a2s.co m*/
        public Iterator<T> iterator() {
            final Iterator<T> iterator = iterable.iterator();

            return new Iterator<T>() {
                Set<Object> keys = new HashSet<>();
                T nextItem;

                @Override
                public boolean hasNext() {
                    while (iterator.hasNext()) {
                        nextItem = iterator.next();
                        if (keys.add(function.apply(nextItem))) {
                            return true;
                        }
                    }

                    return false;
                }

                @Override
                public T next() {
                    if (nextItem == null && !hasNext()) {
                        throw new NoSuchElementException();
                    }

                    return nextItem;
                }

                @Override
                public void remove() {
                }
            };
        }
    };
}

From source file:eu.popgen.canephora.parsers.plink.FAMReader.java

/**
 *
 * @return/* ww  w  .java 2 s.c o  m*/
 */
@Override
public FAMRecord next() {
    FAMRecord n;
    if (this.next == null) {
        try {
            n = readRecord();
            if (n == null) {
                throw new NoSuchElementException();
            }
        } catch (IOException ex) {
            throw new RuntimeException("Could not parse FAM line");
        }
        return n;
    } else {
        n = this.next;
        this.next = null;
        return n;
    }
}

From source file:BreadthFirstPathTreeIterator.java

/** Returns the next element in the iteration.
        /* www.j ava 2 s  . c  o m*/
@return The next element in the iteration
*/

public Object next() {
    if (endOfTree)
        throw new NoSuchElementException();

    String file = getNextFile();
    if (file == null) {
        throw new NoSuchElementException();
    }
    this.nextFile = null;
    return file;
}

From source file:cn.cdwx.jpa.utils.PropertiesLoader.java

/**
 * ?IntegerProperty.Null./*from  w  w  w  .j  a v a 2s  .co m*/
 */
public Integer getInteger(String key) {
    String value = getValue(key);
    if (value == null) {
        throw new NoSuchElementException();
    }
    return Integer.valueOf(value);
}

From source file:CollectionUtilities.java

public static Iterator singletonIterator(final Object item) {
    return new Iterator() {
        private boolean gotItem = false;

        public boolean hasNext() {
            return !this.gotItem;
        }/*from   w  w w . j av  a2s  .  c o  m*/

        public Object next() {
            if (this.gotItem) {
                throw new NoSuchElementException();
            }
            this.gotItem = true;
            return item;
        }

        public void remove() {
            if (!this.gotItem) {
                this.gotItem = true;
            } else {
                throw new NoSuchElementException();
            }
        }
    };
}

From source file:gobblin.ingestion.google.webmaster.UrlTriePrefixGrouper.java

@Override
public Triple<String, GoogleWebmasterFilter.FilterOperator, UrlTrieNode> next() {
    if (hasNext()) {
        Triple<String, GoogleWebmasterFilter.FilterOperator, UrlTrieNode> retVal = _retVal;
        _retVal = null;//from  www. jav  a  2s  . c om
        return retVal;
    }
    throw new NoSuchElementException();
}

From source file:ArrayEnumeration.java

/**
 * Returns the next element in the Array.
 *
 * @return the next element in the array.
 * @throws  NoSuchElementException  if no more elements exist.
 *///from   w w  w.  j  a va 2  s .c  o  m
public Object nextElement() {
    if (counter >= objectarray.length) {
        throw new NoSuchElementException();
    }

    final Object retval = objectarray[counter];
    counter += 1;
    return retval;
}

From source file:com.celements.iterator.DocumentIterator.java

/**
 * Returns the next element in the iteration.
 *
 * @return the next element in the iteration.
 * @exception NoSuchElementException iteration has no more elements.
 *//*from   w w w  .ja  v a  2 s. c  o  m*/
public XWikiDocument next() {
    if (hasNext()) {
        XWikiDocument theCurrentDoc = _currentDoc;
        _currentDoc = null;
        return theCurrentDoc;
    }
    throw new NoSuchElementException();
}

From source file:eu.popgen.canephora.parsers.plink.BIMReader.java

/**
 *
 * @return// w ww.  j  a  va 2s.  c om
 */
@Override
public BIMRecord next() {
    BIMRecord n;
    if (this.next == null) {
        try {
            n = readRecord();
            if (n == null) {
                throw new NoSuchElementException();
            }
        } catch (IOException ex) {
            throw new RuntimeException("Could not parse FAM line");
        }
        return n;
    } else {
        n = this.next;
        this.next = null;
        return n;
    }
}

From source file:$.PropertiesLoader.java

/**
     * ?IntegerProperty.Null./*from   w ww  .  j  a v  a 2s.  co  m*/
     */
    public Integer getInteger(String key) {
        String value = getValue(key);
        if (value == null) {
            throw new NoSuchElementException();
        }
        return Integer.valueOf(value);
    }