Example usage for java.util NoSuchElementException NoSuchElementException

List of usage examples for java.util NoSuchElementException NoSuchElementException

Introduction

In this page you can find the example usage for java.util NoSuchElementException NoSuchElementException.

Prototype

public NoSuchElementException(String s) 

Source Link

Document

Constructs a NoSuchElementException , saving a reference to the error message string s for later retrieval by the getMessage method.

Usage

From source file:com.theminequest.MineQuest.SQLExecutor.java

/**
 * Query an SQL and return a {@link java.sql.ResultSet} of the result.
 * If the SQL file contains {@code %s} in the query, the parameters
 * specified will replace {@code %s} in the query. Remember that if the query
 * is not a {@code SELECT, EXPLAIN, CALL, SCRIPT, SHOW, HELP} query, this will ALWAYS return null.<br>
 * In the event that the queries are different per database, prefix
 * <code>S:</code> at the beginning of the query followed by the database type and another
 * colon./*from w w w.ja v a  2s.  co  m*/
 * @param queryfilename sql filename to use
 * @param params parameters for sql file
 * @return ResultSet of SQL query (or null... if there really is nothing good.)
 */
public ResultSet querySQL(String queryfilename, String... params) {
    InputStream i = MineQuest.activePlugin.getResource("sql/" + queryfilename + ".sql");
    if (i == null)
        throw new NoSuchElementException("No such resource: " + queryfilename + ".sql");
    String[] filecontents = convertStreamToString(i).split(IOUtils.LINE_SEPARATOR);
    for (String line : filecontents) {
        // ignore comments
        if (!line.startsWith("#") && !line.equals("")) {
            if (line.startsWith("S:")) {
                String[] split = line.split(":");
                if (split[1].equalsIgnoreCase(databasetype.name()))
                    line = split[2];
                else
                    continue;
            }
            if (params != null && params.length != 0) {
                int paramsposition = 0;
                while (paramsposition < params.length && line.contains("%s")) {
                    line = line.replaceFirst("%s", params[paramsposition]);
                    paramsposition++;
                }
            }
            ResultSet result = db.query(line);
            if (result != null)
                return result;
        }
    }
    return null;
}

From source file:com.opengamma.util.timeseries.fast.integer.FastArrayIntDoubleTimeSeries.java

@Override
public int getLatestTimeFast() {
    if (_times.length > 0) {
        final int index = _times.length - 1;
        return _times[index];
    } else {//from   www .  ja va 2 s.co  m
        throw new NoSuchElementException("Series is empty");
    }
}

From source file:karma.oss.zookeeper.queue.ZkMessageQueue.java

/**
 * Get first available (that is un-claimed) element from the ordered child list. Then get the child's data from
 * zookeeper/*from  w  w w.j  a v  a 2s  . c o m*/
 * @param orderedChildren
 *         List of ordered children from zookeeper
 * @param markClaimed
 *         Whether to claim this child. If true, the child will not be available in the next read until
*         put back by calling putbackElement()
 * @return
 *         Bytes of available element, Optional.absent() otherwise
 * @throws KeeperException
 * @throws InterruptedException
 */
private Optional<Element<byte[]>> getFirstAvailableElement(NavigableMap<Long, String> orderedChildren,
        boolean markClaimed) throws KeeperException, InterruptedException {

    boolean hasUnClaimedElements = false;
    TreeMap<Long, String> claimedChildren = orderedClaimedChildren(null);

    for (Entry<Long, String> entry : orderedChildren.entrySet()) {
        // skip children already claimed
        if (claimedChildren.containsKey(entry.getKey())) {
            LOG.debug("Element already claimed: " + entry.getValue(), "; skipping");
            continue;
        }

        hasUnClaimedElements = true;
        final String elementId = entry.getValue();
        try {
            final String claimPath = claimDir + "/" + elementId;
            while (markClaimed) {
                try {
                    final byte[] hostNameBytes = StringUtils.getBytesUtf8(getLocalHostName());
                    zookeeperRef.get().create(claimPath, hostNameBytes, acl, CreateMode.EPHEMERAL);
                    LOG.info("Element claimed: " + entry.getValue());
                    break;
                } catch (KeeperException.NodeExistsException e) {
                    LOG.info("Node at path: " + claimPath + " already exists. Trying different node.");
                    throw e; // will be caught by the outer loop.
                } catch (KeeperException.NoNodeException e) {
                    createDir();
                }
            }

            final String path = dir + "/" + elementId;
            byte[] data = zookeeperRef.get().getData(path, false, null);
            return Optional.of(Element.create(elementId, data));
        } catch (KeeperException.NodeExistsException e) {
            // Another client claimed the node first.
            // Refresh claimed children
            claimedChildren = orderedClaimedChildren(null);
        }
    }

    if (!hasUnClaimedElements) {
        throw new NoSuchElementException("No unclaimed element found");
    }

    return Optional.absent();
}

From source file:com.opengamma.util.timeseries.fast.integer.FastArrayIntDoubleTimeSeries.java

@Override
public double getLatestValueFast() {
    if (_values.length > 0) {
        return _values[_values.length - 1];
    } else {//from w  ww.  j av a 2  s .  c  o  m
        throw new NoSuchElementException("Series is empty");
    }
}

From source file:com.opengamma.util.timeseries.fast.longint.FastArrayLongDoubleTimeSeries.java

@Override
public long getLatestTimeFast() {
    if (_times.length > 0) {
        final int index = _times.length - 1;
        return _times[index];
    } else {//from w  w w.  j  av a  2s .c o m
        throw new NoSuchElementException("Series is empty");
    }
}

From source file:com.opengamma.util.timeseries.fast.integer.object.FastArrayIntObjectTimeSeries.java

@Override
public T getLatestValueFast() {
    if (_values.length > 0) {
        return _values[_values.length - 1];
    } else {//from  w  w  w . j  av a2 s  .  c  om
        throw new NoSuchElementException("Series is empty");
    }
}

From source file:com.eucalyptus.entities.EntityWrapper.java

public <T> T lookupAndClose(final T example) throws NoSuchElementException {
    T ret = null;//from   ww w  .j  a  v a 2s .  c o m
    try {
        ret = this.getUnique(example);
        this.commit();
    } catch (final EucalyptusCloudException ex) {
        this.rollback();
        throw new NoSuchElementException(ex.getMessage());
    }
    return ret;
}

From source file:com.devicehive.service.DeviceCommandService.java

public CompletableFuture<Void> update(DeviceCommand cmd, DeviceCommandWrapper commandWrapper) {
    if (cmd == null) {
        throw new NoSuchElementException("Command not found");
    }/*from   www .j av  a  2s .  c  om*/
    cmd.setIsUpdated(true);

    if (commandWrapper.getCommand() != null) {
        cmd.setCommand(commandWrapper.getCommand().orElse(null));
    }
    if (commandWrapper.getTimestamp() != null && commandWrapper.getTimestamp().isPresent()) {
        cmd.setTimestamp(commandWrapper.getTimestamp().get());
    }
    if (commandWrapper.getParameters() != null) {
        cmd.setParameters(commandWrapper.getParameters().orElse(null));
    }
    if (commandWrapper.getLifetime() != null) {
        cmd.setLifetime(commandWrapper.getLifetime().orElse(null));
    }
    if (commandWrapper.getStatus() != null) {
        cmd.setStatus(commandWrapper.getStatus().orElse(null));
    }
    if (commandWrapper.getResult() != null) {
        cmd.setResult(commandWrapper.getResult().orElse(null));
    }

    hiveValidator.validate(cmd);

    CompletableFuture<Response> future = new CompletableFuture<>();
    rpcClient.call(Request.newBuilder().withBody(new CommandUpdateRequest(cmd)).build(),
            new ResponseConsumer(future));
    return future.thenApply(response -> null);
}

From source file:jenkins.plugins.openstack.compute.internal.Openstack.java

public @Nonnull Server getServerById(@Nonnull String id) throws NoSuchElementException {
    Server server = client.compute().servers().get(id);
    if (server == null)
        throw new NoSuchElementException("No such server running: " + id);
    return server;
}