private Long getVisitId(String visitToken) throws Exception { Long visitId = null; if (!CommonUtil.isEmptyString(visitToken)) { if (!visitIdMap.containsKey(visitToken)) { try { visitId = visitDao.findByTrialTitleToken(context.getEntityId(), null, visitToken).iterator().next().getId(); } catch (NoSuchElementException e) { VisitOutVO visitVO = createVisit(visitToken); visitId = visitVO.getId(); jobOutput.println("visit '" + visitVO.getUniqueName() + "' created"); } visitIdMap.put(visitToken, visitId); } else { visitId = visitIdMap.get(visitToken); } } return visitId; }
public Object next() { if (hasNext()) { removed = false; if (counter != 0) { last = current; current = current.next; } counter++; return current.data; } throw new NoSuchElementException(); }
private static void getLoadAvg(double[] doubles) { InputStreamReader isr = null; BufferedReader br = null; try { isr = new InputStreamReader(new FileInputStream("/proc/loadavg")); br = new BufferedReader(isr, 512); String line = br.readLine(); if (line == null) { return; } st.setString(line); doubles[LinuxSystemStats.loadAverage1DOUBLE] = st.nextTokenAsDouble(); doubles[LinuxSystemStats.loadAverage5DOUBLE] = st.nextTokenAsDouble(); doubles[LinuxSystemStats.loadAverage15DOUBLE] = st.nextTokenAsDouble(); } catch (NoSuchElementException nsee) { } catch (IOException ioe) { } finally { st.releaseResources(); if (br != null) try { br.close(); } catch (IOException ignore) { } } }
public E next() { final Node<E> pred = nextNode; if (pred == null) throw new NoSuchElementException(); // assert nextItem != null; lastRet = pred; E item = null; for (Node<E> p = succ(pred), q;; p = q) { if (p == null || (item = p.item) != null) { nextNode = p; E x = nextItem; nextItem = item; return x; } // unlink deleted nodes if ((q = succ(p)) != null) NEXT.compareAndSet(pred, p, q); } }
public boolean addAll(Enumeration<String> comps) throws InvalidNameException { boolean added = false; while (comps.hasMoreElements()) { try { String comp = comps.nextElement(); if (size() > 0 && syntaxDirection == FLAT) { throw new InvalidNameException( "A flat name can only have a single component"); } components.addElement(comp); added = true; } catch (NoSuchElementException e) { break; // "comps" has shrunk. } } return added; }
public static CoprocessIterator<Long> getHandleIterator(TiDAGRequest req, List<RegionTask> regionTasks, TiSession session) { return new DAGIterator<Long>( req.buildScan(true), regionTasks, session, SchemaInfer.create(req), req.getPushDownType() ) { @Override public Long next() { if (hasNext()) { return rowReader.readRow(handleTypes).getLong(0); } else { throw new NoSuchElementException(); } } }; }
@Override public IPosition next() { if (!hasNext()) { throw new NoSuchElementException(); } if (model.getSleep()>0) { try { Thread.sleep(model.getSleep()); if (countSleeps) sleepCount++; } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new RuntimeException(e); } } Scalar<Double> point = new Scalar<>(model.getName(), count, model.getValue()); count++; return point; }
/** * Returns an enumeration of the components of this vector. The * returned <tt>Enumeration</tt> object will generate all items in * this vector. The first item generated is the item at index <tt>0</tt>, * then the item at index <tt>1</tt>, and so on. * * @return an enumeration of the components of this vector. * @see Enumeration * @see java.util.Iterator */ public Enumeration<SimEvent> elements() { return new Enumeration<SimEvent>() { int count = start; public boolean hasMoreElements() { return count < size; } public SimEvent nextElement() { synchronized (CircularEventQueue.this) { if (count < size) { return data[count++]; } } throw new NoSuchElementException("Vector Enumeration"); } }; }
/** * Parses the metadata of a link (edge) to an {@link EdgeMetadata} object. * * @param gfa string containing the contents of the GFA file * @param byteOffset the byte offset where the edge should be located * @return an {@link EdgeMetadata} object containing a link's metadata * @throws MetadataParseException if the GFA file or given line is invalid */ public EdgeMetadata parseEdgeMetadata(final GfaFile gfa, final long byteOffset) throws MetadataParseException { final String line = getLine(gfa.getRandomAccessFile(), byteOffset); validateLine(line, "L", byteOffset); final StringTokenizer st = initializeStringTokenizer(line, byteOffset); try { st.nextToken(); st.nextToken(); final String fromOrient = st.nextToken(); st.nextToken(); final String toOrient = st.nextToken(); final String overlap = st.nextToken(); return new EdgeMetadata(fromOrient, toOrient, overlap); } catch (final NoSuchElementException e) { throw new MetadataParseException("Not enough parameters for link at position " + byteOffset, e); } }
private Object invokeMethod(Object moduleInstance, Map<String, Map<String, Object>> argsDescription) throws NoSuchMethodException, SecurityException, ClassNotFoundException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, APICallException { if (moduleInstance == null) { throw new NoSuchElementException(); } Method m = fetchMethod(moduleInstance.getClass()); if (m == null) { throw new NoSuchMethodException(); } Object[] args = fetchArgsValues(argsDescription); return (args == null) ? m.invoke(moduleInstance) : m.invoke(moduleInstance, args); }
/** * This method returns the value of the named double data read from the Telemetry class. If the named data does * not exist, it is created and assigned the given default value. Then it is sent to the Driver Station. * * @param key specifies the name associated with the double data. * @param defaultValue specifies the default value if it does not exist. * @return double data value. */ public double getNumber(String key, double defaultValue) { final String funcName = "getNumber"; double value; if (debugEnabled) { dbgTrace.traceEnter(funcName, TrcDbgTrace.TraceLevel.API, "key=%s,defValue=%f", key, defaultValue); } try { value = getNumber(key); } catch (NoSuchElementException e) { putNumber(key, defaultValue); value = defaultValue; } if (debugEnabled) { dbgTrace.traceExit(funcName, TrcDbgTrace.TraceLevel.API, "=%f", value); } return value; }
@Override public T next() { if (hasNext()) { T ret = (T)view.get(position); lastPosition = position; position++; return ret; } throw new NoSuchElementException(); }
@Override public E next() { if (!hasNext()) { throw new NoSuchElementException(); } element = elements[index++]; return element; }
public void testSpanTwoRanges() { for (Range<Integer> range1 : RANGES) { for (Range<Integer> range2 : RANGES) { RangeMap<Integer, Integer> rangeMap = TreeRangeMap.create(); rangeMap.put(range1, 1); rangeMap.put(range2, 2); Range<Integer> expected; if (range1.isEmpty()) { if (range2.isEmpty()) { expected = null; } else { expected = range2; } } else { if (range2.isEmpty()) { expected = range1; } else { expected = range1.span(range2); } } try { assertEquals(expected, rangeMap.span()); assertNotNull(expected); } catch (NoSuchElementException e) { assertNull(expected); } } } }
@Test public void testOptionalMapOnEmpty() { Optional<String> emptyName = Optional.empty(); // or Optional.ofNullable(null); Optional<String> emptyUpperName = emptyName.map(String::toUpperCase); assertThat(emptyUpperName.isPresent()).isFalse(); try { assertThat(emptyUpperName.get()).isEqualTo("FRED"); fail("found a value on an empty Optional"); } catch (NoSuchElementException e) { // ignore } }
public BasicBlock block(Label label) { Objects.requireNonNull(label); BasicBlock result = index.get(label); if (result != null) { return result; } else { throw new NoSuchElementException("Label not found: " + label); } }
/** * Gets an item which was previously interned. * * @param item {@code non-null;} the item to look for * @return {@code non-null;} the equivalent already-interned instance */ public <T extends OffsettedItem> T get(T item) { throwIfNotPrepared(); OffsettedItem result = interns.get(item); if (result != null) { return (T) result; } throw new NoSuchElementException(item.toString()); }
/** * Called when the client side {@link IBinder} for this {@link CustomTabsSessionToken} is dead. * Can also be used to clean up {@link DeathRecipient} instances allocated for the given token. * @param sessionToken The session token for which the {@link DeathRecipient} call has been * received. * @return Whether the clean up was successful. Multiple calls with two tokens holdings the * same binder will return false. */ protected boolean cleanUpSession(CustomTabsSessionToken sessionToken) { try { synchronized (mDeathRecipientMap) { IBinder binder = sessionToken.getCallbackBinder(); DeathRecipient deathRecipient = mDeathRecipientMap.get(binder); binder.unlinkToDeath(deathRecipient, 0); mDeathRecipientMap.remove(binder); } } catch (NoSuchElementException e) { return false; } return true; }
@Test public void firstOrErrorNoElement() { Flowable.empty() .firstOrError() .test() .assertNoValues() .assertError(NoSuchElementException.class); }
public T getResource() { try { return internalPool.borrowObject(); } catch (NoSuchElementException nse) { if (null == nse.getCause()) { // The exception was caused by an exhausted pool throw new JedisExhaustedPoolException("Could not get a resource since the pool is exhausted", nse); } // Otherwise, the exception was caused by the implemented activateObject() or // ValidateObject() throw new JedisException("Could not get a resource from the pool", nse); } catch (Exception e) { throw new JedisConnectionException("Could not get a resource from the pool", e); } }
public void testFind_notPresent() { Iterable<String> list = Lists.newArrayList("cool", "pants"); Iterator<String> iterator = list.iterator(); try { Iterators.find(iterator, Predicates.alwaysFalse()); fail(); } catch (NoSuchElementException e) { } assertFalse(iterator.hasNext()); }
@Override public TimeValue next() { if (!hasNext()) { throw new NoSuchElementException(); } curr++; return delay; }
public boolean isReified(Var v) { Objects.requireNonNull(v); Boolean r = vars.get(v); if (r != null) { return r.booleanValue(); } else { throw new NoSuchElementException("Variable not found: " + v); } }
@Override public E next() { if (taken) throw new NoSuchElementException(); taken = true; return data; }
public final E next() { Node p = nextNode; if (p == null) throw new NoSuchElementException(); E e = nextItem; advance(p); return e; }
public @Override int getStartOffset() { synchronized (ProxyHighlightsContainer.this.LOCK) { if (index1 == -2 && index2 == -2) { throw new IllegalStateException("Uninitialized sequence, call moveNext() first."); //NOI18N } else if (index1 == -1 || index2 == -1) { throw new NoSuchElementException(); } return marks[index1].getPreviousMarkOffset(); } }
/** TODO: Documentation */ public double getDouble(String columnName) throws NoSuchColumnException, NoSuchElementException { DBUtil.notNullNotEmpty(columnName, "The columnName must neither be null nor empty: " + columnName); Object object = this.pull(columnName); if (object == null) { throw new NoSuchElementException("Column has null value: " + columnName); } return Double.parseDouble(object.toString()); }
/** */ @Override public FileObject next() { if (!hasNext()) { throw new NoSuchElementException(); } upToDate = false; return nextObject; }
@Override public void nextPanel() { if (!hasNext()) { throw new NoSuchElementException(); } index++; }
/** * @throws NoSuchElementException {@inheritDoc} */ public E getLast() { @SuppressWarnings("unchecked") E result = (E) elements[(tail - 1) & (elements.length - 1)]; if (result == null) throw new NoSuchElementException(); return result; }
@CollectionFeature.Require(SUPPORTS_REMOVE) @CollectionSize.Require(ZERO) public void testRemove_empty() { try { getQueue().remove(); fail("emptyQueue.remove() should throw"); } catch (NoSuchElementException expected) { } expectUnchanged(); }
/************************* * Message Processing * *************************/ protected void processStatus(org.ethereum.net.eth.message.StatusMessage msg, ChannelHandlerContext ctx) throws InterruptedException { try { Genesis genesis = GenesisLoader.loadGenesis(config, config.genesisInfo(), config.getBlockchainConfig().getCommonConstants().getInitialNonce(), true); if (!Arrays.equals(msg.getGenesisHash(), genesis.getHash()) || msg.getProtocolVersion() != version.getCode()) { loggerNet.info("Removing EthHandler for {} due to protocol incompatibility", ctx.channel().remoteAddress()); ethState = EthState.STATUS_FAILED; recordEvent(EventType.INCOMPATIBLE_PROTOCOL); disconnect(ReasonCode.INCOMPATIBLE_PROTOCOL); ctx.pipeline().remove(this); // Peer is not compatible for the 'eth' sub-protocol return; } if (msg.getNetworkId() != config.networkId()) { ethState = EthState.STATUS_FAILED; recordEvent(EventType.INVALID_NETWORK); disconnect(ReasonCode.NULL_IDENTITY); return; } // basic checks passed, update statistics channel.getNodeStatistics().ethHandshake(msg); ethereumListener.onEthStatusUpdated(channel, msg); if (peerDiscoveryMode) { loggerNet.debug("Peer discovery mode: STATUS received, disconnecting..."); disconnect(ReasonCode.REQUESTED); ctx.close().sync(); ctx.disconnect().sync(); return; } } catch (NoSuchElementException e) { loggerNet.debug("EthHandler already removed"); } }
/** * 返回List前端的元素, 并把该元素从List中删除.(模拟LIFO) * @throws NoSuchElementException * if the client attempts to remove an item from an empty list * @return List前端第一个元素 */ public Item popFirst() { if (getSize() == 0) throw new NoSuchElementException("This DoubleLinkedList is empty!"); return pop(0); }
/** * Removes and returns the greatest element of this queue. * * @throws NoSuchElementException if the queue is empty */ @CanIgnoreReturnValue public E removeLast() { if (isEmpty()) { throw new NoSuchElementException(); } return removeAndGet(getMaxElementIndex()); }
@CollectionSize.Require(ZERO) public void testEmptySetLast() { try { sortedSet.last(); fail(); } catch (NoSuchElementException e) { } }
protected Element ExportCustom(Document root) { Element eMove ; if (m_bMoveCorresponding) { eMove = root.createElement("MoveCorresponding") ; } else { eMove = root.createElement("Move") ; } Element eFrom = root.createElement("From") ; m_valueFrom.ExportTo(eFrom, root) ; eMove.appendChild(eFrom) ; ListIterator i = m_arrToIdentifiers.listIterator() ; try { CIdentifier idDest = (CIdentifier)i.next() ; while (idDest != null) { Element dest ; if (m_bFillAll) { dest = root.createElement("Fill") ; } else { dest = root.createElement("To") ; } idDest.ExportTo(dest, root) ; eMove.appendChild(dest) ; idDest = (CIdentifier)i.next() ; } } catch (NoSuchElementException e) { // nothing } return eMove; }
@Override public K lastKey() { Entry<K, V> entry = lastEntry(); if (entry == null) { throw new NoSuchElementException(); } else { return entry.getKey(); } }
public E next() { if (cursor == fence) throw new NoSuchElementException(); @SuppressWarnings("unchecked") E result = (E) elements[cursor]; // This check doesn't catch all possible comodifications, // but does catch the ones that corrupt traversal if (tail != fence || result == null) throw new ConcurrentModificationException(); lastRet = cursor; cursor = (cursor + 1) & (elements.length - 1); return result; }
public Cell next() { if (cache != null) { Cell kv = cache; cache = null; return kv; } if (valuesI == null) { return null; } try { return valuesI.next(); } catch (NoSuchElementException e) { return null; } }
public static String getFileProperty(Path path, String property) throws IOException { Properties properties = new Properties(); try (InputStream inputStream = new FileInputStream(path.toString())) { properties.load(inputStream); } if (!properties.containsKey(property)) { throw new NoSuchElementException("Property does not exist"); } return properties.getProperty(property); }