List of usage examples for java.util NoSuchElementException NoSuchElementException
public NoSuchElementException()
From source file:com.telefonica.euro_iaas.sdc.pupperwrapper.services.tests.ActionsServiceTest.java
@Test public void deleteNodeNotFoundTest() throws IOException { Process shell = mock(Process.class); Process shell2 = mock(Process.class); Process shellNodeName = mock(Process.class); String[] cmd = { anyString() }; // call to puppet cert list --all when(processBuilderFactory.createProcessBuilder(cmd)).thenReturn(shellNodeName).thenReturn(shell) .thenReturn(shell2);//w ww. j av a 2 s .co m String strNodeName = "\"1.novalocal\""; when(shellNodeName.getInputStream()).thenReturn(new ByteArrayInputStream(strNodeName.getBytes("UTF-8"))); when(shellNodeName.getErrorStream()).thenReturn(new ByteArrayInputStream(" ".getBytes("UTF-8"))); String str = "Node 1.novalocal is registered"; String strdelete = "Node 1 unregistered"; when(shell.getInputStream()).thenReturn(new ByteArrayInputStream(str.getBytes("UTF-8"))) .thenReturn(new ByteArrayInputStream(strdelete.getBytes("UTF-8"))); String strEr = " "; when(shell.getErrorStream()).thenReturn(new ByteArrayInputStream(strEr.getBytes("UTF-8"))); String str2 = "1.novalocal"; when(shell2.getInputStream()).thenReturn(new ByteArrayInputStream(str2.getBytes("UTF-8"))); String strEr2 = " "; when(shell2.getErrorStream()).thenReturn(new ByteArrayInputStream(strEr2.getBytes("UTF-8"))); when(catalogManagerMongo.getNode("1")).thenThrow(new NoSuchElementException()).thenReturn(node1); when(statusLine.getStatusCode()).thenReturn(200); actionsService.deleteNode("1"); verify(shell, times(1)).getInputStream(); verify(shell2, times(1)).getInputStream(); verify(shellNodeName, times(1)).getInputStream(); verify(processBuilderFactory, times(3)).createProcessBuilder((String[]) anyObject()); }
From source file:Base64InputStream.java
/** * Returns an iterator over this buffer's elements. * * @return an iterator over this buffer's elements *//* w w w.j av a 2 s . c om*/ public Iterator<Byte> iterator() { return new Iterator<Byte>() { private int index = head; private int lastReturnedIndex = -1; public boolean hasNext() { return index != tail; } public Byte next() { if (!hasNext()) { throw new NoSuchElementException(); } lastReturnedIndex = index; index = increment(index); return new Byte(buffer[lastReturnedIndex]); } public void remove() { if (lastReturnedIndex == -1) { throw new IllegalStateException(); } // First element can be removed quickly if (lastReturnedIndex == head) { UnboundedFifoByteBuffer.this.remove(); lastReturnedIndex = -1; return; } // Other elements require us to shift the subsequent elements int i = lastReturnedIndex + 1; while (i != tail) { if (i >= buffer.length) { buffer[i - 1] = buffer[0]; i = 0; } else { buffer[i - 1] = buffer[i]; i++; } } lastReturnedIndex = -1; tail = decrement(tail); buffer[tail] = 0; index = decrement(index); } }; }
From source file:com.siemens.sw360.datahandler.common.CommonUtils.java
public static <T> T getFirst(Iterable<T> iterable) { final Iterator<T> iterator = iterable.iterator(); if (iterator.hasNext()) { return iterator.next(); } else {//from w w w .j a v a 2 s. c om throw new NoSuchElementException(); } }
From source file:com.meidusa.amoeba.net.poolable.copy.CursorableLinkedList.java
/** * Returns the element at the beginning of this list. *//*from w w w . j a v a2 s .c om*/ public Object getFirst() { try { return _head.next().value(); } catch (NullPointerException e) { throw new NoSuchElementException(); } }
From source file:CalendarUtils.java
/** * This constructs an Iterator that will start and stop over a date * range based on the focused date and the range style. For instance, * passing Thursday, July 4, 2002 and a RANGE_MONTH_SUNDAY will return * an Iterator that starts with Sunday, June 30, 2002 and ends with * Saturday, August 3, 2002./*w w w . j av a2 s. c o m*/ */ public static Iterator getCalendarIterator(Calendar focus, int rangeStyle) { Calendar start = null; Calendar end = null; int startCutoff = Calendar.SUNDAY; int endCutoff = Calendar.SATURDAY; switch (rangeStyle) { case RANGE_MONTH_SUNDAY: case RANGE_MONTH_MONDAY: //Set start to the first of the month start = trunc(focus, Calendar.MONTH); //Set end to the last of the month end = (Calendar) start.clone(); end.add(Calendar.MONTH, 1); end.add(Calendar.DATE, -1); //Loop start back to the previous sunday or monday if (rangeStyle == RANGE_MONTH_MONDAY) { startCutoff = Calendar.MONDAY; endCutoff = Calendar.SUNDAY; } break; case RANGE_WEEK_SUNDAY: case RANGE_WEEK_MONDAY: case RANGE_WEEK_RELATIVE: case RANGE_WEEK_CENTER: //Set start and end to the current date start = trunc(focus, Calendar.DATE); end = trunc(focus, Calendar.DATE); switch (rangeStyle) { case RANGE_WEEK_SUNDAY: //already set by default break; case RANGE_WEEK_MONDAY: startCutoff = Calendar.MONDAY; endCutoff = Calendar.SUNDAY; break; case RANGE_WEEK_RELATIVE: startCutoff = focus.get(Calendar.DAY_OF_WEEK); endCutoff = startCutoff - 1; break; case RANGE_WEEK_CENTER: startCutoff = focus.get(Calendar.DAY_OF_WEEK) - 3; endCutoff = focus.get(Calendar.DAY_OF_WEEK) + 3; break; } break; default: throw new RuntimeException("The range style " + rangeStyle + " is not valid."); } if (startCutoff < Calendar.SUNDAY) { startCutoff += 7; } if (endCutoff > Calendar.SATURDAY) { endCutoff -= 7; } while (start.get(Calendar.DAY_OF_WEEK) != startCutoff) { start.add(Calendar.DATE, -1); } while (end.get(Calendar.DAY_OF_WEEK) != endCutoff) { end.add(Calendar.DATE, 1); } final Calendar startFinal = start; final Calendar endFinal = end; Iterator it = new Iterator() { Calendar spot = null; { spot = startFinal; spot.add(Calendar.DATE, -1); } public boolean hasNext() { return spot.before(endFinal); } public Object next() { if (spot.equals(endFinal)) { throw new NoSuchElementException(); } spot.add(Calendar.DATE, 1); return spot.clone(); } public void remove() { throw new UnsupportedOperationException(); } }; return it; }
From source file:com.meidusa.amoeba.net.poolable.copy.CursorableLinkedList.java
/** * Returns the element at the end of this list. *///from w w w. java2 s . co m public Object getLast() { try { return _head.prev().value(); } catch (NullPointerException e) { throw new NoSuchElementException(); } }
From source file:edu.cornell.med.icb.goby.alignments.ConcatAlignmentReader.java
/** * Returns the next alignment entry from the input stream. * * @return the alignment read entry from the input stream. *///from w ww . j a v a 2 s . c o m public Alignments.AlignmentEntry next() { if (!hasNext()) { throw new NoSuchElementException(); } else { final Alignments.AlignmentEntry alignmentEntry = readers[activeIndex].next(); final int queryIndex = alignmentEntry.getQueryIndex(); final int newQueryIndex = mergedQueryIndex(activeIndex, queryIndex); Alignments.AlignmentEntry.Builder builder = alignmentEntry.newBuilderForType() .mergeFrom(alignmentEntry); if (adjustQueryIndices && newQueryIndex != queryIndex) { builder = builder.setQueryIndex(newQueryIndex); } if (adjustSampleIndices) { builder = builder.setSampleIndex(activeIndex); } if (alignmentEntry.hasReadOriginIndex() && hasReadOrigin[activeIndex]) { // remove conflicts by permuting read origin index to the concatenated read origin indices: builder = builder.setReadOriginIndex( readOriginPermutations[activeIndex][alignmentEntry.getReadOriginIndex()]); } return builder.build(); } }
From source file:com.google.android.apps.common.testing.accessibility.framework.uielement.ViewHierarchyElement.java
/** * @param atIndex The index of the child {@link ViewHierarchyElement} to obtain. Must be &ge 0 and * < {@link #getChildViewCount()}. * @return The requested child, or {@code null} if no such child exists at the given * {@code atIndex}// ww w. j a va 2 s . c o m * @throws NoSuchElementException if {@code atIndex} is less than 0 or greater than * {@code getChildViewCount() - 1} */ public ViewHierarchyElement getChildView(int atIndex) { if ((atIndex < 0) || (childIds == null) || (atIndex >= childIds.size())) { throw new NoSuchElementException(); } return getWindow().getViewById(childIds.get(atIndex)); }
From source file:de.csw.expertfinder.mediawiki.api.MediaWikiAPI.java
private Iterator<Element> getInfoForAllRevisions(final int articleId, final int startRevId, boolean fetchContent) { return new Iterator<Element>() { private int current = 0; private int rvstartid = startRevId; private NodeList revisions; private boolean queryContinue = true; public void remove() { throw new UnsupportedOperationException(); }// w w w. ja va 2 s .co m public Element next() { if (hasNext()) return (Element) revisions.item(current++); throw new NoSuchElementException(); } public boolean hasNext() { if (revisions == null || // first call queryContinue && current == revisions.getLength()) { // current // list // exhausted, // but // there's // more // to // fetch fetchNext(); } if (!queryContinue && current == revisions.getLength()) // current // list // exhausted // and // nothing // more // to // fetch: // finished! return false; return true; } private void fetchNext() { BasicNameValuePair[] params = new BasicNameValuePair[] { new BasicNameValuePair("prop", "revisions"), new BasicNameValuePair("pageids", "" + articleId), new BasicNameValuePair("rvstartid", "" + rvstartid), new BasicNameValuePair("rvdir", "newer"), new BasicNameValuePair("rvlimit", "500"), new BasicNameValuePair("rvprop", "ids|user"), new BasicNameValuePair("redirects", "") }; try { Document document = queryMediaWiki("query", params); revisions = document.getElementsByTagName("rev"); current = 0; NodeList queryContinues = document.getElementsByTagName("query-continue"); if (queryContinues.getLength() == 0) { queryContinue = false; } else { Element queryContinueElement = (Element) queryContinues.item(0); NodeList nextRevisionsElements = queryContinueElement.getElementsByTagName("revisions"); Element nextRevisions = (Element) nextRevisionsElements.item(0); String rvstartidStr = nextRevisions.getAttribute("rvstartid"); if (rvstartidStr == null || rvstartidStr.isEmpty()) { rvstartidStr = nextRevisions.getAttribute("rvcontinue"); } rvstartid = Integer.parseInt(rvstartidStr); } } catch (MediaWikiAPIException e) { log.error("Request to MediaWiki API failed", e); } } }; }
From source file:com.opengamma.util.timeseries.fast.integer.FastArrayIntDoubleTimeSeries.java
@Override public double getValueFast(final int time) { final int binarySearch = Arrays.binarySearch(_times, time); if (binarySearch >= 0 && _times[binarySearch] == time) { return _values[binarySearch]; } else {/*from ww w. jav a 2 s.com*/ throw new NoSuchElementException(); } }