List of usage examples for java.util NoSuchElementException NoSuchElementException
public NoSuchElementException()
From source file:OneItemSet.java
public Iterator<E> iterator() { return new Iterator() { public boolean hasNext() { return hasNxt; }/*from w w w. j a v a2 s. c om*/ public E next() { if (hasNxt) { hasNxt = false; return item; } throw new NoSuchElementException(); } public void remove() { item = null; } boolean hasNxt = true; }; }
From source file:com.yahoo.bard.webservice.util.IntervalPeriodIterator.java
@Override public Interval next() { if (!hasNext()) { throw new NoSuchElementException(); }// w ww. j a v a2 s . c o m position += 1; DateTime nextPosition = ObjectUtils.min(intervalEnd, boundaryAt(position)); Interval result = new Interval(currentPosition, nextPosition); currentPosition = nextPosition; return result; }
From source file:nl.xillio.gitbreakers.procrastimaster.server.services.AbstractService.java
public T get(Integer id) { T result = repository.findOne(id);/* w w w .j a va2s .c o m*/ if (result == null) { throw new NoSuchElementException(); } return result; }
From source file:cn.cdwx.jpa.utils.PropertiesLoader.java
/** * ?StringProperty,Null./* w w w.j a va 2 s . co m*/ */ public String getProperty(String key) { String value = getValue(key); if (value == null) { throw new NoSuchElementException(); } return value; }
From source file:com.basho.riak.pbc.MapReduceResponseSource.java
@Override public MapReduceResponse next() throws IOException { if (!hasNext()) throw new NoSuchElementException(); is_given = true;// ww w . j av a 2s . c o m return new MapReduceResponse(r, contentType); }
From source file:jetbrains.exodus.query.InMemoryHeapSortIterable.java
@Override public Iterator<Entity> iterator() { return new Iterator<Entity>() { private int i; private int size; private List<Entity> heap; @Override/* w ww. j a v a 2s . c o m*/ public boolean hasNext() { if (heap == null) { init(); } return i < size; } @Override public Entity next() { if (heap == null) { init(); } if (i >= size) { throw new NoSuchElementException(); } ++i; siftDown(0); final Entity current = heap.get(0); heap.set(0, heap.remove(size - 1)); return current; } @Override public void remove() { throw new UnsupportedOperationException(); } private void init() { heap = new ArrayList<>(); for (final Entity entity : source) { heap.add(entity); } size = heap.size(); if (size > 16) { if (log.isTraceEnabled()) { log.trace("HeapSort called, size = " + size, new Exception()); } } for (int i = (size - 2) / 2; i > 0; i -= 1) { siftDown(i); } } private void siftDown(int i) { final int count = heap.size(); while (true) { int j = (i * 2) + 1; if (j >= count) { break; } Entity child = heap.get(j); if (j < count - 1) { final Entity rightChild = heap.get(j + 1); if (comparator.compare(child, rightChild) >= 0) { child = rightChild; j += 1; } } final Entity parent = heap.get(i); if (comparator.compare(child, parent) >= 0) { break; } heap.set(i, child); heap.set(j, parent); i = j; } } }; }
From source file:$.PropertiesLoader.java
/** * ?StringProperty,Null./*from www .j a v a 2 s . c o m*/ */ public String getProperty(String key) { String value = getValue(key); if (value == null) { throw new NoSuchElementException(); } return value; }
From source file:Main.java
/** * Create new {@link Iterable} object which combine the first and the second * parameters.// w ww . jav a2s. co m * * @param <T> * Type of the items in the array of the first specified * parameter, this type also specify the type of the arrays of * the which will be returned by the returned {@link Iterable} * @param <E> * Type of the second {@link Iterable} arrays. It may be the same * type as the first {@link Iterable}, or array of any other * subclass * @param firstIterable * {@link Iterable}, the first {@link Iterable} which contains * items * @param secondIterable * {@link Iterable}, the second {@link Iterable} which contains * items * @return {@link Iterable}, object which will return {@link Iterator}s * which will iterate over the second {@link Iterable} parameter as * many times as there are items in the first {@link Iterable} * parameter. The returned arrays will contains every possible * combination between items in the first {@link Iterable}, and the * second {@link Iterable}. For example: if the first * {@link Iterable} contains <code>{1, 2}</code> and the second * {@link Iterable} contains <code>{'a', 'b', 'c'}</code> the * returned {@link Iterable} object will dynamically combine the * {@link Iterable}s and provide following combination in specified * order: * <code>{1, 'a'}, {1, 'b'}, {1, 'c'}, {2, 'a'}, {2, 'b'}, {2, 'c'}</code> */ public static <T, E extends T> Iterable<T[]> combineIterables(final Iterable<T[]> firstIterable, final Iterable<E[]> secondIterable) { return new Iterable<T[]>() { /** * {@inheritDoc} */ public Iterator<T[]> iterator() { return new Iterator<T[]>() { private Iterator<T[]> firstArrayIterator = firstIterable.iterator(); private final Iterator<E[]> secondArrayIterator = secondIterable.iterator(); private T[] appendArray = secondArrayIterator.next(); /** * {@inheritDoc} */ public boolean hasNext() { return firstArrayIterator.hasNext() || secondArrayIterator.hasNext(); } /** * {@inheritDoc} */ public T[] next() { if (!hasNext()) { throw new NoSuchElementException(); } if (!firstArrayIterator.hasNext()) { firstArrayIterator = firstIterable.iterator(); appendArray = secondArrayIterator.next(); } T[] streamsItem = firstArrayIterator.next(); @SuppressWarnings("unchecked") T[] result = (T[]) Array.newInstance(streamsItem.getClass().getComponentType(), streamsItem.length + appendArray.length); System.arraycopy(streamsItem, 0, result, 0, streamsItem.length); System.arraycopy(appendArray, 0, result, streamsItem.length, appendArray.length); return result; } /** * {@inheritDoc} */ public void remove() { throw new UnsupportedOperationException(); } }; } }; }
From source file:marmot.tokenize.preprocess.WikiReader.java
protected String readNonEmptyLine(InternalReader reader) { String line = fixLine(reader.readLine()); if (line == null) { throw new NoSuchElementException(); }/*from w ww. ja va 2 s.c o m*/ line = line.trim(); while (line.isEmpty()) { line = fixLine(reader.readLine()); if (line == null) { throw new NoSuchElementException(); } line = line.trim(); } return line; }
From source file:SerializableEnumeration.java
public Object nextElement() throws NoSuchElementException { try {// w w w. ja va2 s .c o m Object nextObj = get(index); index++; return nextObj; } catch (IndexOutOfBoundsException e) { throw new NoSuchElementException(); } }