List of usage examples for java.util NoSuchElementException NoSuchElementException
public NoSuchElementException(String s)
From source file:com.opengamma.util.timeseries.fast.integer.FastArrayIntDoubleTimeSeries.java
@Override public FastIntDoubleTimeSeries headFast(final int numItems) { if (numItems <= _times.length) { final int[] times = new int[numItems]; final double[] values = new double[numItems]; System.arraycopy(_times, 0, times, 0, numItems); System.arraycopy(_values, 0, values, 0, numItems); return new FastArrayIntDoubleTimeSeries(getEncoding(), times, values); } else {/*from ww w. j a v a2s . c om*/ throw new NoSuchElementException("Not enough elements"); } }
From source file:com.opengamma.util.timeseries.fast.integer.object.FastArrayIntObjectTimeSeries.java
@SuppressWarnings("unchecked") public FastIntObjectTimeSeries<T> headFast(final int numItems) { if (numItems <= _times.length) { final int[] times = new int[numItems]; final T[] values = (T[]) new Object[numItems]; System.arraycopy(_times, 0, times, 0, numItems); System.arraycopy(_values, 0, values, 0, numItems); return new FastArrayIntObjectTimeSeries<T>(getEncoding(), times, values); } else {/* w w w . java 2 s .c o m*/ throw new NoSuchElementException("Not enough elements"); } }
From source file:com.opengamma.util.timeseries.fast.longint.object.FastArrayLongObjectTimeSeries.java
@SuppressWarnings("unchecked") public FastLongObjectTimeSeries<T> head(final int numItems) { if (numItems <= _times.length) { final long[] times = new long[numItems]; final T[] values = (T[]) new Object[numItems]; System.arraycopy(_times, 0, times, 0, numItems); System.arraycopy(_values, 0, values, 0, numItems); return new FastArrayLongObjectTimeSeries<T>(getEncoding(), times, values); } else {/*from ww w . j a va 2 s . c o m*/ throw new NoSuchElementException("Not enough elements"); } }
From source file:com.opengamma.util.timeseries.fast.longint.FastArrayLongDoubleTimeSeries.java
@Override public FastLongDoubleTimeSeries head(final int numItems) { if (numItems <= _times.length) { final long[] times = new long[numItems]; final double[] values = new double[numItems]; System.arraycopy(_times, 0, times, 0, numItems); System.arraycopy(_values, 0, values, 0, numItems); return new FastArrayLongDoubleTimeSeries(getEncoding(), times, values); } else {//from w w w.j a v a2 s.c om throw new NoSuchElementException("Not enough elements"); } }
From source file:de.codesourcery.jasm16.emulator.EmulationOptions.java
public DefaultScreen getScreen(IEmulator emulator) { List<IDevice> result = emulator.getDevicesByDescriptor(DefaultScreen.DESC); if (result.isEmpty()) { throw new NoSuchElementException("Internal error, found no default screen?"); }//from ww w.j a v a 2 s . c o m if (result.size() > 1) { throw new RuntimeException("Internal error, found more than one default screen?"); } return (DefaultScreen) result.get(0); }
From source file:karma.oss.zookeeper.queue.ZkMessageQueue.java
public Element<byte[]> inspect(String elementId) throws KeeperException, InterruptedException { try {//from ww w .ja v a2 s .c o m final String path = dir + "/" + elementId; final byte[] data = zookeeperRef.get().getData(path, false, null); return Element.create(elementId, data); } catch (KeeperException.NoNodeException e) { throw new NoSuchElementException("Not found: " + elementId + " at " + dir); } }
From source file:it.unimi.di.big.mg4j.document.PropertyBasedDocumentFactory.java
/** Resolves the given key against the given metadata, falling back to the default metadata * and guaranteeing a non-<code>null</code> result. * /*from w w w . jav a 2 s. c o m*/ * @param key a key. * @param metadata a metadata map. * @return the value returned by <code>metadata</code> for <code>key</code>, or the value * returned by {@link #defaultMetadata} for <code>key</code> if the former is <code>null</code>; if the * latter is <code>null</code>, too, a {@link NoSuchElementException} will be thrown. */ protected Object resolveNotNull(final Enum<?> key, final Reference2ObjectMap<Enum<?>, Object> metadata) { final Object value = resolve(key, metadata); if (value == null) throw new NoSuchElementException("The key " + key + " cannot be resolved"); return value; }
From source file:com.github.pascalgn.jiracli.web.HttpClient.java
private <T> T doExecute(HttpUriRequest request, boolean retry, Function<HttpEntity, T> function) { LOGGER.debug("Calling URL: {} [{}]", request.getURI(), request.getMethod()); // disable XSRF check: if (!request.containsHeader("X-Atlassian-Token")) { request.addHeader("X-Atlassian-Token", "nocheck"); }/*www. jav a 2 s. c o m*/ HttpResponse response; try { response = httpClient.execute(request, httpClientContext); } catch (IOException e) { if (Thread.interrupted()) { LOGGER.trace("Could not call URL: {}", request.getURI(), e); throw new InterruptedError(); } else { throw new IllegalStateException("Could not call URL: " + request.getURI(), e); } } LOGGER.debug("Response received ({})", response.getStatusLine().toString().trim()); HttpEntity entity = response.getEntity(); try { if (Thread.interrupted()) { throw new InterruptedError(); } int statusCode = response.getStatusLine().getStatusCode(); if (isSuccess(statusCode)) { T result; try { result = function.apply(entity, Hint.none()); } catch (NotAuthenticatedException e) { if (retry) { resetAuthentication(); setCredentials(); return doExecute(request, false, function); } else { throw e.getCause(); } } catch (RuntimeException e) { if (Thread.interrupted()) { LOGGER.trace("Could not call URL: {}", request.getURI(), e); throw new InterruptedError(); } else { throw e; } } if (Thread.interrupted()) { throw new InterruptedError(); } return result; } else { if (statusCode == HttpURLConnection.HTTP_UNAUTHORIZED) { resetAuthentication(); if (retry) { setCredentials(); return doExecute(request, false, function); } else { String error = readErrorResponse(request.getURI(), entity); LOGGER.debug("Unauthorized [401]: {}", error); throw new AccessControlException("Unauthorized [401]: " + request.getURI()); } } else if (statusCode == HttpURLConnection.HTTP_FORBIDDEN) { resetAuthentication(); checkAccountLocked(response); if (retry) { setCredentials(); return doExecute(request, false, function); } else { throw new AccessControlException("Forbidden [403]: " + request.getURI()); } } else { String status = response.getStatusLine().toString().trim(); String message; if (entity == null) { message = status; } else { String error = readErrorResponse(request.getURI(), entity); message = status + (error.isEmpty() ? "" : ": " + error); } if (Thread.interrupted()) { throw new InterruptedError(); } if (statusCode == HttpURLConnection.HTTP_NOT_FOUND) { throw new NoSuchElementException(message); } else { throw new IllegalStateException(message); } } } } finally { EntityUtils.consumeQuietly(entity); } }
From source file:de.codesourcery.jasm16.emulator.EmulationOptions.java
public DefaultVectorDisplay getVectorDisplay(IEmulator emulator) { List<IDevice> result = emulator.getDevicesByDescriptor(DefaultVectorDisplay.DEVICE_DESCRIPTOR); if (result.isEmpty()) { throw new NoSuchElementException("Internal error, found no default vector display ?"); }/*from ww w . j a v a 2 s . co m*/ if (result.size() > 1) { throw new RuntimeException("Internal error, found more than one vector display ?"); } return (DefaultVectorDisplay) result.get(0); }
From source file:com.eucalyptus.entities.EntityWrapper.java
/** * Returns the unique result from the database that exactly matches <code>example</code>. The differences between this method and {@link #getUnique(Object)} are: * <ol><li>{@link #getUnique(Object)} uses <i><code>enableLike</code></i> match and this method does not. <i><code>enableLike</code></i> criteria trips hibernate when * special characters are involved. So it has been replaced by exact "=" (equals to)</li> * <li>Unique result logic is correctly implemented in this method. If the query returns more than one result, this method correctly throws an exception * wrapping <code>NonUniqueResultException</code>. {@link #getUnique(Object)} does not throw an exception in this case and returns a result as long as it finds * one or more matching results (because of the following properties set on the query: <code>setMaxResults(1)</code>, <code>setFetchSize(1)</code> and * <code>setFirstResult(0)</code>)</li></ol> * /*from w w w .j a v a 2s . c o m*/ * @param example * @return * @throws EucalyptusCloudException */ @SuppressWarnings("unchecked") public <T> T getUniqueEscape(final T example) throws EucalyptusCloudException { try { Object id = null; try { id = this.getEntityManager().getEntityManagerFactory().getPersistenceUnitUtil() .getIdentifier(example); } catch (final Exception ex) { } if (id != null) { final T res = (T) this.getEntityManager().find(example.getClass(), id); if (res == null) { throw new NoSuchElementException("@Id: " + id); } else { return res; } } else if ((example instanceof HasNaturalId) && (((HasNaturalId) example).getNaturalId() != null)) { final String natId = ((HasNaturalId) example).getNaturalId(); final T ret = (T) this.createCriteria(example.getClass()).setLockMode(LockMode.NONE) .setCacheable(true).add(Restrictions.naturalId().set("naturalId", natId)).uniqueResult(); if (ret == null) { throw new NoSuchElementException("@NaturalId: " + natId); } return ret; } else { final T ret = (T) this.createCriteria(example.getClass()).setLockMode(LockMode.NONE) .setCacheable(true).add(Example.create(example)).uniqueResult(); if (ret == null) { throw new NoSuchElementException("example: " + LogUtil.dumpObject(example)); } return ret; } } catch (final NonUniqueResultException ex) { throw new EucalyptusCloudException( "Get unique failed for " + example.getClass().getSimpleName() + " because " + ex.getMessage(), ex); } catch (final NoSuchElementException ex) { throw new EucalyptusCloudException( "Get unique failed for " + example.getClass().getSimpleName() + " using " + ex.getMessage(), ex); } catch (final Exception ex) { final Exception newEx = PersistenceExceptions.throwFiltered(ex); throw new EucalyptusCloudException("Get unique failed for " + example.getClass().getSimpleName() + " because " + newEx.getMessage(), newEx); } }