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.largecode.interview.rustem.service.UsersServiceImpl.java

@Override
public void updateUser(Long id, UserDto userDto, Role roleOfCreator) {
    LOGGER.debug("Update user id = {} with data {}", id, userDto);
    Optional<User> userInDb = Optional.ofNullable(userRepository.findOne(id));
    userInDb.ifPresent((user) -> {//www .  j av  a 2s.  com
        roleOfCreator.modifyUserProperties(userDto, user);
        userRepository.saveAndFlush(user);
    });
    userInDb.orElseThrow(
            () -> new NoSuchElementException(String.format("User=%s not found for updating.", id)));

}

From source file:com.hierynomus.smbj.server.StubSmbServer.java

private void runServer() {
    try (Socket accept = socket.accept()) {
        InputStream inputStream = accept.getInputStream();
        OutputStream outputStream = accept.getOutputStream();
        while (!stop.get()) {
            int packetLength = readTcpHeader(inputStream);
            // Read the SMB packet
            IOUtils.read(inputStream, new byte[packetLength]);
            if (stubbedResponses.size() > 0) {
                Response response = stubbedResponses.remove(0);
                byte[] b = IOUtils.toByteArray(response.getBytes());
                outputStream/*from ww  w.  j av a 2 s.  co m*/
                        .write(new Buffer.PlainBuffer(Endian.BE).putByte((byte) 0).putUInt24(b.length).array());
                outputStream.write(b);
                outputStream.flush();
            } else {
                throw new NoSuchElementException("The response list is empty!");
            }
        }

    } catch (IOException | Buffer.BufferException e) {
        serverException.set(new RuntimeException(e));
        throw serverException.get();
    }
}

From source file:narvis.modules.weather.OwPortal.java

@Override
public double getPercentageOfCloud() throws NoSuchElementException {
    if (this._currentWeather.getCloudsInstance().hasPercentageOfClouds())
        return this._currentWeather.getCloudsInstance().getPercentageOfClouds();

    throw new NoSuchElementException("No cloud percentage found");
}

From source file:com.eviware.soapui.utils.ContainerWalker.java

public AbstractButton findCheckBoxWithLabel(String labelText) {
    for (Component component : containedComponents) {
        if (component instanceof JCheckBox) {
            JCheckBox checkBox = (JCheckBox) component;
            if (String.valueOf(checkBox.getText()).equals(labelText)) {
                return checkBox;
            }/*from w  ww . j a  v  a2  s.c om*/
        }
    }
    throw new NoSuchElementException("No checkbox found with label " + labelText);
}

From source file:de.unioninvestment.eai.portal.portlet.crud.domain.portal.Portal.java

/**
 * Ermittelt die CompanyId.//w w w . j a v a2s  .c o  m
 * 
 * @return CompanyId
 */
public Long getCompanyId() {
    if (companyId == null) {
        try {
            Company company = CompanyLocalServiceUtil.getCompanyByWebId(portalInstanceId);
            if (company == null) {
                throw new NoSuchElementException("No Liferay companyId for webId 'liferay.com' found!");
            } else {
                companyId = company.getCompanyId();
            }
        } catch (SystemException e) {
            throw new TechnicalCrudPortletException("Error getting companyId by webId 'liferay.com'", e);
        } catch (PortalException e) {
            throw new TechnicalCrudPortletException("Error getting companyId by webId 'liferay.com'", e);
        }
    }
    return companyId;
}

From source file:com.graphhopper.apache.commons.collections.IntDoubleBinaryHeap.java

public int peek_element() {
    if (isEmpty()) {
        throw new NoSuchElementException("Heap is empty. Cannot peek element.");
    } else {/* ww  w.j  a va  2  s .  c o  m*/
        return elements[1];
    }
}

From source file:org.datagator.api.client.SpooledRowBuffer.java

@Override
public Iterator<Object[]> iterator() {
    if (rowsCount <= cacheLimit) {
        return this.cache.iterator();
    } else {//from w  w w.  j  a v  a  2  s  .  c o  m
        try {
            flush();
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
        return new Iterator<Object[]>() {

            private final JsonParser jp;
            private int rowIndex = 0;
            private final TypeReference<ArrayList<Object>> tr = new TypeReference<ArrayList<Object>>() {
            };

            {
                try {
                    // TODO lock cache file
                    cacheFile.seek(0);
                    FileReader reader = new FileReader(cacheFile.getFD());
                    jp = Entity.json.createParser(reader);
                    JsonToken token = jp.nextToken(); // START_ARRAY
                    if (!token.equals(JsonToken.START_ARRAY)) {
                        throw new RuntimeException("Corrupted cache file");
                    }
                } catch (IOException ex) {
                    throw new RuntimeException(ex);
                }
            }

            @Override
            public boolean hasNext() {
                return rowIndex < rowsCount;
            }

            @Override
            public Object[] next() {
                if (!hasNext()) {
                    throw new NoSuchElementException("No such elememnt.");
                }
                try {
                    rowIndex += 1;
                    ArrayList<Object> buffer = jp.readValueAs(tr);
                    return buffer.toArray();
                } catch (IOException ex) {
                    throw new RuntimeException(ex);
                }
            }

            @Override
            public void remove() {
                throw new UnsupportedOperationException("Not supported yet.");
            }

        };
    }
}

From source file:com.zjy.mongo.util.BSONLoader.java

public BSONObject next() {
    try {/*from  w ww.j a  v  a 2s.c  o  m*/
        byte[] data = new byte[nextLen + 4];
        System.arraycopy(nextHdr, 0, data, 0, 4);
        input.readFully(data, 4, nextLen - 4);
        decoder.decode(data, callback);
        return (BSONObject) callback.get();
    } catch (IOException e) {
        /* If we can't read another length it's not an error, just return quietly. */
        LOG.info("No Length Header available." + e);
        hasMore.set(false);
        try {
            input.close();
        } catch (IOException e1) {
            LOG.warn(e1.getMessage(), e1);
        }
        throw new NoSuchElementException("Iteration completed.");
    }
}

From source file:com.amalto.core.storage.hibernate.ScrollableIterator.java

public DataRecord next() {
    if (firstNextCall) {
        for (ResultsCallback callback : callbacks) {
            callback.onBeginOfResults();
        }//from  w  ww. ja v  a  2  s  . c om
        firstNextCall = false;
    }
    Object next;
    try {
        if (allowNextCall) {
            boolean hasNext = results.next();
            if (!hasNext) {
                throw new NoSuchElementException("No more results for iterator."); // Required by next() API
            }
        } else {
            isFirstHasNextCall = false;
            allowNextCall = true;
        }
        next = results.get()[0];
    } catch (Exception e) {
        notifyCallbacks(); // In case of exception, notify the callbacks so statelessSession can be closed.
        throw new RuntimeException(e);
    }

    ComplexTypeMetadata type = storageClassLoader.getTypeFromClass(next.getClass());
    ObjectDataRecordReader reader = getReader(type);
    if (!(next instanceof Wrapper)) {
        throw new IllegalArgumentException("Result object is not an instance of " + Wrapper.class.getName());
    }
    // TODO A bind should *not* be needed (but storage class loader isn't correctly set in case of distinct block strategy for m&m).
    storageClassLoader.bind(Thread.currentThread());
    try {
        return reader.read(storageRepository.getMappingFromDatabase(type), (Wrapper) next);
    } finally {
        storageClassLoader.unbind(Thread.currentThread());
    }
}

From source file:io.knotx.knot.action.domain.FormEntity.java

private static String getFormIdentifier(Fragment fragment) {
    return fragment.knots().stream().filter(knot -> knot.startsWith(FRAGMENT_KNOT_PREFIX))
            .map(knot -> StringUtils.removePattern(knot, FRAGMENT_KNOT_PATTERN))
            .map(id -> StringUtils.isBlank(id) ? FORM_DEFAULT_IDENTIFIER : id).findFirst().orElseThrow(() -> {
                LOGGER.error("Could not find action adapter name in fragment [{}].", fragment);
                return new NoSuchElementException("Could not find action adapter name");
            });/*from   w  w  w.  ja  v  a  2 s .  c  o  m*/
}