Java Code Examples for com.googlecode.cqengine.resultset.ResultSet#isEmpty()

The following examples show how to use com.googlecode.cqengine.resultset.ResultSet#isEmpty() . 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: ResultSets.java    From cqengine with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a Collection-like view of the given ResultSet.
 * <p/>
 * The collection simply delegates to the ResultSet, which in turn will reflect
 * any changes made to the underlying IndexedCollection by other threads.
 * For example consecutive calls to the size() method
 * may return different values if objects are added to or removed from the IndexedCollection.
 *
 * @param resultSet The ResultSet to wrap
 * @return A Collection-like view of the given ResultSet
 */
public static <O> Collection<O> asCollection(final ResultSet<O> resultSet) {
    return new AbstractCollection<O>() {
        @Override
        public Iterator<O> iterator() {
            return resultSet.iterator();
        }
        @Override
        public int size() {
            return resultSet.size();
        }

        @Override
        public boolean contains(Object o) {
            @SuppressWarnings("unchecked")
            O object = (O)o;
            return resultSet.contains(object);
        }

        @Override
        public boolean isEmpty() {
            return resultSet.isEmpty();
        }
    };
}
 
Example 2
Source File: QueryableShipData.java    From Valkyrien-Skies with Apache License 2.0 5 votes vote down vote up
public Optional<ShipData> getShipFromChunk(long chunkLong) {
    Query<ShipData> query = equal(ShipData.CHUNKS, chunkLong);
    ResultSet<ShipData> resultSet = allShips.retrieve(query);

    if (resultSet.size() > 1) {
        throw new IllegalStateException("How the heck did we get 2 or more ships both managing the chunk at " + chunkLong);
    }
    if (resultSet.isEmpty()) {
        return Optional.empty();
    } else {
        return Optional.of(resultSet.uniqueResult());
    }
}
 
Example 3
Source File: QueryableShipData.java    From Valkyrien-Skies with Apache License 2.0 5 votes vote down vote up
public Optional<ShipData> getShip(UUID uuid) {
    Query<ShipData> query = equal(ShipData.UUID, uuid);
    ResultSet<ShipData> resultSet = allShips.retrieve(query);

    if (resultSet.isEmpty()) {
        return Optional.empty();
    } else {
        return Optional.of(resultSet.uniqueResult());
    }
}
 
Example 4
Source File: QueryableShipData.java    From Valkyrien-Skies with Apache License 2.0 5 votes vote down vote up
public Optional<ShipData> getShipFromName(String name) {
    Query<ShipData> query = equal(ShipData.NAME, name);
    ResultSet<ShipData> shipDataResultSet = allShips.retrieve(query);

    if (shipDataResultSet.isEmpty()) {
        return Optional.empty();
    } else {
        return Optional.of(shipDataResultSet.uniqueResult());
    }
}