java.util.NoSuchElementException Java Examples

The following examples show how to use java.util.NoSuchElementException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JBBPTokenizerTest.java    From java-binary-block-parser with Apache License 2.0 6 votes vote down vote up
@Test
public void testStructure_NonamedArray_Spaces() {
  final JBBPTokenizer parser = new JBBPTokenizer("    [ 333 ]  { ");

  final Iterator<JBBPToken> iterator = parser.iterator();

  final JBBPToken item = iterator.next();

  assertEquals(JBBPTokenType.STRUCT_START, item.getType());
  assertNull(item.getFieldName());
  assertNull(item.getFieldTypeParameters());
  assertTrue(item.isArray());
  assertEquals(333, item.getArraySizeAsInt().intValue());
  assertEquals(4, item.getPosition());

  try {
    iterator.next();
    fail("Must throw NSEE");
  } catch (NoSuchElementException ex) {

  }
}
 
Example #2
Source File: GreedyFixingSetFinder.java    From SJS with Apache License 2.0 6 votes vote down vote up
@Override
public FixingSetListener.Action currentFixingSet(Collection<T> out, FixingSetListener<T, ?> listener) {

    Collection<Collection<T>> cores = new LinkedList<>(this.cores);
    while (!cores.isEmpty()) {
        // At each iteration, pick the constraint that appears in the
        // greatest number of uncovered cores.

        Map<T, Integer> counts = cores.stream()
            .flatMap(Collection::stream)
            .collect(Collectors.toMap(
                c -> c,
                c -> 1,
                (v1, v2) -> v1 + v2));

        T constraint = allConstraints.stream()
            .filter(counts::containsKey)
            .max((c1, c2) -> counts.get(c1) - counts.get(c2))
            .orElseThrow(NoSuchElementException::new);
        out.add(constraint);
        cores.removeIf(core -> core.contains(constraint));
    }

    return FixingSetListener.Action.CONTINUE;
}
 
Example #3
Source File: LocalAccount.java    From nextcloud-notes with GNU General Public License v3.0 6 votes vote down vote up
/**
 * @param availableApiVersions <code>["0.2", "1.0", ...]</code>
 */
public void setPreferredApiVersion(@Nullable String availableApiVersions) {
    // TODO move this logic to NotesClient?
    try {
        if (availableApiVersions == null) {
            this.preferredApiVersion = null;
            return;
        }
        JSONArray versionsArray = new JSONArray(availableApiVersions);
        Collection<ApiVersion> supportedApiVersions = new HashSet<>(versionsArray.length());
        for (int i = 0; i < versionsArray.length(); i++) {
            ApiVersion parsedApiVersion = ApiVersion.of(versionsArray.getString(i));
            for (ApiVersion temp : NotesClient.SUPPORTED_API_VERSIONS) {
                if (temp.compareTo(parsedApiVersion) == 0) {
                    supportedApiVersions.add(parsedApiVersion);
                    break;
                }
            }
        }
        this.preferredApiVersion = Collections.max(supportedApiVersions);
    } catch (JSONException | NoSuchElementException e) {
        e.printStackTrace();
        this.preferredApiVersion = null;
    }
}
 
Example #4
Source File: EtdContractSpec.java    From Strata with Apache License 2.0 6 votes vote down vote up
@Override
public Object get(String propertyName) {
  switch (propertyName.hashCode()) {
    case 3355:  // id
      return id;
    case 3575610:  // type
      return type;
    case 913218206:  // exchangeId
      return exchangeId;
    case -1402840545:  // contractCode
      return contractCode;
    case -1724546052:  // description
      return description;
    case -2126070377:  // priceInfo
      return priceInfo;
    case 405645655:  // attributes
      return attributes;
    default:
      throw new NoSuchElementException("Unknown property: " + propertyName);
  }
}
 
Example #5
Source File: KnownAmountBondPaymentPeriod.java    From Strata with Apache License 2.0 6 votes vote down vote up
@Override
public Object get(String propertyName) {
  switch (propertyName.hashCode()) {
    case -786681338:  // payment
      return payment;
    case -2129778896:  // startDate
      return startDate;
    case -1607727319:  // endDate
      return endDate;
    case 1457691881:  // unadjustedStartDate
      return unadjustedStartDate;
    case 31758114:  // unadjustedEndDate
      return unadjustedEndDate;
    default:
      throw new NoSuchElementException("Unknown property: " + propertyName);
  }
}
 
Example #6
Source File: TelephonyRegistry.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private void remove(IBinder binder) {
    synchronized (mRecords) {
        final int recordCount = mRecords.size();
        for (int i = 0; i < recordCount; i++) {
            Record r = mRecords.get(i);
            if (r.binder == binder) {
                if (DBG) {
                    log("remove: binder=" + binder + " r.callingPackage " + r.callingPackage
                            + " r.callback " + r.callback);
                }

                if (r.deathRecipient != null) {
                    try {
                        binder.unlinkToDeath(r.deathRecipient, 0);
                    } catch (NoSuchElementException e) {
                        if (VDBG) log("UnlinkToDeath NoSuchElementException sending to r="
                                + r + " e=" + e);
                    }
                }

                mRecords.remove(i);
                return;
            }
        }
    }
}
 
Example #7
Source File: CrossGammaParameterSensitivity.java    From Strata with Apache License 2.0 6 votes vote down vote up
@Override
public Object get(String propertyName) {
  switch (propertyName.hashCode()) {
    case 842855857:  // marketDataName
      return marketDataName;
    case -1169106440:  // parameterMetadata
      return parameterMetadata;
    case 106006350:  // order
      return order;
    case 575402001:  // currency
      return currency;
    case 564403871:  // sensitivity
      return sensitivity;
    default:
      throw new NoSuchElementException("Unknown property: " + propertyName);
  }
}
 
Example #8
Source File: HttpClientContextCaptorTest.java    From armeria with Apache License 2.0 5 votes vote down vote up
@Test
void badPath() {
    try (ClientRequestContextCaptor ctxCaptor = Clients.newContextCaptor()) {
        // Send a request with a bad path.
        // Note: A colon cannot come in the first path component.
        final HttpResponse res = WebClient.of().get("http://127.0.0.1:1/:");
        assertThatThrownBy(ctxCaptor::get).isInstanceOf(NoSuchElementException.class)
                                          .hasMessageContaining("no request was made");
        res.aggregate();
    }
}
 
Example #9
Source File: InsnList.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public Object next() {
    if (next == null) {
        throw new NoSuchElementException();
    }
    AbstractInsnNode result = next;
    prev = result;
    next = result.next;
    remove = result;
    return result;
}
 
Example #10
Source File: JGrafana.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
/**
 * Gets a panel by title.
 *
 * @param title: The panel title to be retrieved.
 * @return: The panel.
 */
public GrafanaPanel getPanelByTitle(String title) {
    Optional<GrafanaPanel> panel = this.dashboard.panels.stream().filter(x -> x.title.equals(title)).findFirst();
    if (!panel.isPresent()) {
        throw new NoSuchElementException(String.format("There is no panel with title \"%s\"", title));
    }
    return panel.get();
}
 
Example #11
Source File: DefaultTapiResolver.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public TapiNepRef getNepRef(String sipId) throws NoSuchElementException {
    updateCache();
    TapiNepRef ret = null;
    try {
        ret = tapiNepRefList.stream()
                .filter(nep -> nep.getSipId() != null && nep.getSipId().equals(sipId))
                .findFirst().get();
    } catch (NoSuchElementException e) {
        log.error("Nep not found associated with {}", sipId);
        throw e;
    }
    return ret;
}
 
Example #12
Source File: BunchedMapScanTest.java    From fdb-record-layer with Apache License 2.0 5 votes vote down vote up
private void testScan(int limit, boolean reverse, @Nonnull BiFunction<Transaction,byte[],BunchedMapIterator<Tuple,Tuple>> iteratorFunction) {
    try (Transaction tr = db.createTransaction()) {
        byte[] continuation = null;
        List<Tuple> readKeys = new ArrayList<>();
        Tuple lastKey = null;
        do {
            int returned = 0;
            BunchedMapIterator<Tuple,Tuple> bunchedMapIterator = iteratorFunction.apply(tr, continuation);
            while (bunchedMapIterator.hasNext()) {
                Tuple toAdd = bunchedMapIterator.peek().getKey();
                readKeys.add(toAdd);
                assertEquals(toAdd, bunchedMapIterator.next().getKey());
                if (lastKey != null) {
                    assertEquals(reverse ? 1 : -1, lastKey.compareTo(toAdd));
                }
                lastKey = toAdd;
                returned += 1;
            }
            assertFalse(bunchedMapIterator.hasNext());
            assertThrows(NoSuchElementException.class, bunchedMapIterator::peek);
            assertThrows(NoSuchElementException.class, bunchedMapIterator::next);
            continuation = bunchedMapIterator.getContinuation();
            if (limit == ReadTransaction.ROW_LIMIT_UNLIMITED || returned < limit) {
                assertNull(continuation);
            } else {
                assertNotNull(continuation);
            }
        } while (continuation != null);
        if (reverse) {
            readKeys = Lists.reverse(readKeys);
        }
        assertEquals(keys, readKeys);
        tr.cancel();
    }
}
 
Example #13
Source File: ListBasedXMLEventReader.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public XMLEvent nextEvent() {
	if (hasNext()) {
		this.currentEvent = this.events.get(this.cursor);
		this.cursor++;
		return this.currentEvent;
	}
	else {
		throw new NoSuchElementException();
	}
}
 
Example #14
Source File: LinkedHashMultimap.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
Iterator<Map.Entry<K, V>> entryIterator() {
  return new Iterator<Map.Entry<K, V>>() {
    ValueEntry<K, V> nextEntry = multimapHeaderEntry.successorInMultimap;
    ValueEntry<K, V> toRemove;

    @Override
    public boolean hasNext() {
      return nextEntry != multimapHeaderEntry;
    }

    @Override
    public Map.Entry<K, V> next() {
      if (!hasNext()) {
        throw new NoSuchElementException();
      }
      ValueEntry<K, V> result = nextEntry;
      toRemove = result;
      nextEntry = nextEntry.successorInMultimap;
      return result;
    }

    @Override
    public void remove() {
      checkRemove(toRemove != null);
      LinkedHashMultimap.this.remove(toRemove.getKey(), toRemove.getValue());
      toRemove = null;
    }
  };
}
 
Example #15
Source File: PoolUtils.java    From commons-pool with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public T borrowObject() throws Exception, NoSuchElementException,
        IllegalStateException {
    final WriteLock writeLock = readWriteLock.writeLock();
    writeLock.lock();
    try {
        return pool.borrowObject();
    } finally {
        writeLock.unlock();
    }
}
 
Example #16
Source File: FilterTest.java    From Lightweight-Stream-API with Apache License 2.0 5 votes vote down vote up
@Test(expected = NoSuchElementException.class)
public void testFilterIteratorNextOnEmpty() {
    DoubleStream.empty()
            .filter(Functions.greaterThan(Math.PI))
            .iterator()
            .next();
}
 
Example #17
Source File: GetLeadActivities.java    From REST-Sample-Code with MIT License 5 votes vote down vote up
private String convertStreamToString(InputStream inputStream) {

		try {
			return new Scanner(inputStream).useDelimiter("\\A").next();
		} catch (NoSuchElementException e) {
			return "";
		}
	}
 
Example #18
Source File: DefaultFileResourceService.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
@Transactional( readOnly = true )
public void copyFileResourceContent( FileResource fileResource, OutputStream outputStream )
    throws IOException, NoSuchElementException
{
    fileResourceContentStore.copyContent( fileResource.getStorageKey(), outputStream );
}
 
Example #19
Source File: LinkedBlockingDeque.java    From commons-pool with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public E removeLast() {
    final E x = pollLast();
    if (x == null) {
        throw new NoSuchElementException();
    }
    return x;
}
 
Example #20
Source File: InsnList.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public Object next() {
    if (next == null) {
        throw new NoSuchElementException();
    }
    AbstractInsnNode result = next;
    prev = result;
    next = result.next;
    remove = result;
    return result;
}
 
Example #21
Source File: OpenIntToDoubleHashMap.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Simple constructor.
 */
private Iterator() {

    // preserve the modification count of the map to detect concurrent modifications later
    referenceCount = count;

    // initialize current index
    next = -1;
    try {
        advance();
    } catch (NoSuchElementException nsee) { // NOPMD
        // ignored
    }

}
 
Example #22
Source File: SelectItemsIterator.java    From ctsms with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public SelectItem next() {
	if (nextCalled) {
		throw new NoSuchElementException();
	}
	nextCalled = true;
	return item;
}
 
Example #23
Source File: ReplicationLogBuffer.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * @return The number of bytes returned by getData
 * @throws NoSuchElementException if there was no log in the
 * buffer the last time next() was called.
 */
public int getSize() throws NoSuchElementException{
    synchronized (outputLatch) {
        if (validOutBuffer) {
            return outBufferStored;
        } else {
            throw new NoSuchElementException();
        }
    }
}
 
Example #24
Source File: IdentityLinkedList.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public E next() {
    checkForComodification();
    if (nextIndex == size)
        throw new NoSuchElementException();

    lastReturned = next;
    next = next.next;
    nextIndex++;
    return lastReturned.element;
}
 
Example #25
Source File: LinkedListTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * java.util.LinkedList#removeFirst()
 */
public void test_removeFirst() {
    // Test for method java.lang.Object java.util.LinkedList.removeFirst()
    ll.removeFirst();
    assertTrue("Failed to remove first element",
            ll.getFirst() != objArray[0]);

    LinkedList list = new LinkedList();
    try {
        list.removeFirst();
        fail("Should throw NoSuchElementException");
    } catch (NoSuchElementException e) {
        // Excepted
    }
}
 
Example #26
Source File: OptionalIntTest.java    From Lightweight-Stream-API with Apache License 2.0 5 votes vote down vote up
@Test(expected = NoSuchElementException.class)
public void testOrElseThrow2() {
    assertEquals(25, OptionalInt.empty().orElseThrow(new Supplier<NoSuchElementException>() {
        @Override
        public NoSuchElementException get() {
            return new NoSuchElementException();
        }
    }));
}
 
Example #27
Source File: StreamedPortDataBase.java    From CloverETL-Engine with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public DataRecord peek() {
	if (current != null) {
		return current;
	}
	throw new NoSuchElementException();
}
 
Example #28
Source File: CompositeEnumeration.java    From knox with Apache License 2.0 5 votes vote down vote up
@Override
public T nextElement() {
  if( hasMoreElements() ) {
    return array[index].nextElement();
  } else {
    throw new NoSuchElementException();
  }
}
 
Example #29
Source File: ForwardIterator.java    From monsoon with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Advance along the chain.
 * @return The next chain element, or null if no more elements are available.
 */
public synchronized Chain<T> advance() {
    if (next_ == null) {
        if (!forward_.hasNext()) throw new NoSuchElementException();
        next_ = new Chain<>(forward_.next(), forward_);
        forward_ = null;
    }
    return next_;
}
 
Example #30
Source File: StrTokenizer.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Gets the token previous to the last returned token.
 *
 * @return the previous token
 */
@Override
public String previous() {
    if (hasPrevious()) {
        return tokens[--tokenPos];
    }
    throw new NoSuchElementException();
}