List of usage examples for java.util NoSuchElementException NoSuchElementException
public NoSuchElementException()
From source file:BoundedPriorityQueue.java
/** * Returns the highest scoring object in this priority queue, * throwing an exception if the queue is empty. * * @return The highest scoring object in this queue. * @throws NoSuchElementException If the queue is empty. *///from ww w. j av a 2 s .c om public E element() { E result = peek(); if (result == null) throw new NoSuchElementException(); return result; }
From source file:com.opengamma.util.timeseries.fast.longint.object.FastMapLongObjectTimeSeries.java
@Override public T getValueFast(final long time) { T value = _map.get(time);/* w ww. j a va 2 s . c om*/ if (value == _defaultReturnValue) { throw new NoSuchElementException(); } return value; }
From source file:com.telefonica.euro_iaas.paasmanager.dao.impl.ProductInstanceDaoJpaImpl.java
public ProductInstance findUniqueByCriteria(ProductInstanceSearchCriteria criteria) throws NotUniqueResultException { List<ProductInstance> instances = findByCriteria(criteria); if (instances.size() > 1) { throw new NotUniqueResultException(); }//from ww w .jav a 2 s.co m if (instances.size() == 0) throw new NoSuchElementException(); return instances.iterator().next(); }
From source file:WrapperIterator.java
/** * Returns the next element.// w ww . j a v a 2 s . c o m * * @return the next element * @throws NoSuchElementException if there is no next element */ public Object next() { // for chained iterators if (chained) { if (it1 == null) { if (it2 == null) { throw new NoSuchElementException(); } if (it2.hasNext()) { return it2.next(); } it2 = null; next(); } else { if (it1.hasNext()) { return it1.next(); } it1 = null; next(); } } // for other itertors if (hasNext()) { return elements[i++]; } throw new NoSuchElementException(); }
From source file:de.codesourcery.jasm16.ast.ASTUtils.java
public static Iterator<ASTNode> createInOrderIterator(ASTNode node) { if (node == null) { throw new IllegalArgumentException("node must not be NULL"); }/*from ww w. ja v a 2s . c o m*/ final Stack<ASTNode> stack = new Stack<ASTNode>(); stack.push(node); return new Iterator<ASTNode>() { @Override public boolean hasNext() { return !stack.isEmpty(); } /* A (1) * |\ *(5) E B (2) * |\ *(4) D C (3) */ @Override public ASTNode next() { if (stack.isEmpty()) { throw new NoSuchElementException(); } ASTNode result = stack.pop(); final List<ASTNode> children = result.getChildren(); Collections.reverse(children); for (ASTNode child : children) { stack.push(child); } return result; } @Override public void remove() { throw new UnsupportedOperationException(); } }; }
From source file:MicroMap.java
/** * @see java.util.Map#keySet()//from ww w .java2s . c o m */ public Set<K> keySet() { return new AbstractSet<K>() { @Override public Iterator<K> iterator() { return new Iterator<K>() { public boolean hasNext() { return index < MicroMap.this.size(); } public K next() { if (!hasNext()) { throw new NoSuchElementException(); } index++; return key; } public void remove() { MicroMap.this.clear(); } int index; }; } @Override public int size() { return MicroMap.this.size(); } }; }
From source file:UnifyHash.java
public Iterator iterator() { ///#ifdef JDK12 cleanUp();/* w ww .j a v a2 s . c om*/ ///#endif return new Iterator() { private int bucket = 0; private int known = modCount; private Bucket nextBucket; private Object nextVal; { internalNext(); } private void internalNext() { while (true) { while (nextBucket == null) { if (bucket == buckets.length) return; nextBucket = buckets[bucket++]; } nextVal = nextBucket.get(); if (nextVal != null) return; nextBucket = nextBucket.next; } } public boolean hasNext() { return nextBucket != null; } public Object next() { if (known != modCount) throw new ConcurrentModificationException(); if (nextBucket == null) throw new NoSuchElementException(); Object result = nextVal; nextBucket = nextBucket.next; internalNext(); return result; } public void remove() { throw new UnsupportedOperationException(); } }; }
From source file:com.telefonica.euro_iaas.sdc.pupperwrapper.services.tests.ActionsServiceTest.java
@Test public void install() { when(catalogManagerMongo.getNode("1")).thenThrow(new NoSuchElementException()).thenReturn(node1); actionsService.action(Action.INSTALL, "testGroup", "1", "testSoft", "1.0.0", attributeList); Node node = catalogManagerMongo.getNode("1"); Software soft = node.getSoftware("testSoft"); assertTrue(node != null);//from ww w .j a v a2s.c o m assertTrue(soft != null); assertTrue(node.getGroupName().equals("testGroup")); assertTrue(node.getId().equals("1")); assertTrue(soft.getName().equals("testSoft")); assertTrue(soft.getVersion().equals("1.0.0")); assertTrue(soft.getAction().equals(Action.INSTALL)); }
From source file:net.orzo.lib.Files.java
public FileIterator<Object> gzipFileReader(final String path, final String encoding) throws IOException { try {/*w w w.j a va2 s. c o m*/ final GZIPInputStream gis = new GZIPInputStream(new FileInputStream(path)); final Reader reader = new InputStreamReader(gis, encoding); return new FileIterator<Object>() { private final BufferedReader br = new BufferedReader(reader); private String currLine = br.readLine(); @Override public boolean hasNext() { return this.currLine != null; } @Override public Object next() { String ans; if (this.currLine != null) { ans = this.currLine; try { this.currLine = this.br.readLine(); } catch (IOException e) { this.currLine = null; throw new IllegalStateException(e); } return ans; } else { throw new NoSuchElementException(); } } @Override public void close() { try { this.currLine = null; this.br.close(); } catch (IOException e) { throw new IllegalStateException(e); } } @Override public String getPath() { return path; } }; } catch (EOFException ex) { return new EmptyFileIterator(); } }
From source file:gobblin.ingestion.google.webmaster.UrlTriePostOrderIterator.java
@Override public Pair<String, UrlTrieNode> next() { if (hasNext()) { _lastVisited = _toReturn;// w w w. j a va 2s. c om _toReturn = null; return Pair.of(_currentPrefixSb.toString() + _lastVisited.getValue(), _lastVisited); } throw new NoSuchElementException(); }