Example usage for com.google.common.collect Iterators getNext

List of usage examples for com.google.common.collect Iterators getNext

Introduction

In this page you can find the example usage for com.google.common.collect Iterators getNext.

Prototype

@Nullable
public static <T> T getNext(Iterator<? extends T> iterator, @Nullable T defaultValue) 

Source Link

Document

Returns the next element in iterator or defaultValue if the iterator is empty.

Usage

From source file:com.google.gcloud.datastore.DatastoreHelper.java

static Entity get(DatastoreReader reader, Key key) {
    return Iterators.getNext(reader.get(new Key[] { key }), null);
}

From source file:com.google.cloud.datastore.DatastoreHelper.java

static Entity get(Transaction reader, Key key) {
    return Iterators.getNext(reader.get(new Key[] { key }), null);
}

From source file:com.google.cloud.datastore.DatastoreHelper.java

static Entity get(Datastore reader, Key key, ReadOption... options) {
    return Iterators.getNext(reader.get(Collections.singletonList(key), options), null);
}

From source file:org.apache.nifi.processors.kite.FailureTracker.java

public void add(String reason) {
    count += 1;/*from   w w  w. java  2s  . c om*/
    String problem = Iterators.getNext(REASON_SEPARATOR.split(reason).iterator(), "Unknown");
    if (examples.containsKey(problem)) {
        occurrences.put(problem, occurrences.get(problem) + 1);
    } else {
        examples.put(problem, reason);
        occurrences.put(problem, 1);
    }
}

From source file:org.lenskit.util.io.SequencedObjectStream.java

public SequencedObjectStream(Iterable<? extends ObjectStream<? extends T>> streams) {
    streamIter = streams.iterator();//from   ww w  .ja  va2  s  .  c o  m
    current = Iterators.getNext(streamIter, null);
}

From source file:org.lenskit.util.io.SequencedObjectStream.java

@Override
public T readObject() {
    T obj = null;//w  w w . j  a  v  a2s. c  o  m
    while (current != null) {
        obj = current.readObject();
        if (obj == null) {
            current = Iterators.getNext(streamIter, null);
        } else {
            break;
        }
    }

    return obj;
}

From source file:com.continuuity.weave.internal.appmaster.RunnableContainerRequest.java

/**
 * Remove a resource request and return it.
 * @return The {@link Resource} and {@link Collection} of {@link RuntimeSpecification} or
 *         {@code null} if there is no more request.
 *///  ww  w.j a v  a2s  . co  m
Map.Entry<Resource, ? extends Collection<RuntimeSpecification>> takeRequest() {
    Map.Entry<Resource, Collection<RuntimeSpecification>> next = Iterators.getNext(requests, null);
    return next == null ? null : Maps.immutableEntry(next.getKey(), ImmutableList.copyOf(next.getValue()));
}

From source file:kn.uni.gis.dataimport.util.GeoUtil.java

public CPolygon receivePolygon(String dataTable, String whereClause) {
    return Iterators.getNext(receivePolygons(dataTable, whereClause).iterator(), null);
}

From source file:org.kitesdk.cli.commands.UpdateDatasetCommand.java

@Override
public int run() throws IOException {
    if (datasets == null || datasets.size() != 1) {
        throw new IllegalArgumentException("Exactly one dataset name must be specified.");
    }//from  w  w  w.  j a v  a  2  s . co m

    String dataset = datasets.remove(0);
    Dataset<GenericData.Record> currentDataset = load(dataset, GenericData.Record.class).getDataset();

    DatasetDescriptor.Builder descriptorBuilder = new DatasetDescriptor.Builder(currentDataset.getDescriptor());

    if (avroSchemaFile != null) {
        descriptorBuilder.schemaUri(qualifiedURI(avroSchemaFile));
    }

    if (properties != null) {
        for (String propValue : properties) {
            Iterator<String> parts = PROP_VALUE_SEP.split(propValue).iterator();
            descriptorBuilder.property(Iterators.getNext(parts, null), Iterators.getNext(parts, null));
        }
    }

    DatasetDescriptor descriptor = descriptorBuilder.build();

    if (isDataUri(dataset)) {
        Datasets.<GenericData.Record, Dataset<GenericData.Record>>update(dataset, descriptor,
                GenericData.Record.class);
    } else {
        getDatasetRepository().update(dataset, descriptor);
    }

    console.debug("Updated {}", dataset);

    return 0;
}

From source file:kn.uni.gis.dataimport.util.GeoUtil.java

public Location coordIn(CPoint point, CPolygon poly, final double e) {
    return Iterators.getNext(receiveGeos(
            select(within(gFromT(point), gFromT(poly)), distance(gFromT(point), boundary(gFromT(poly)))),
            new GeoFactory<Location>() {
                @Override//from  w ww  .j  av  a  2  s . c  om
                public Location createGeo(ResultSet object) throws SQLException {
                    System.out.println(object.getMetaData().getColumnCount());
                    return Location.forPosition(object.getBoolean(1), (object.getDouble(2) < e));
                }
            }).iterator(), null);
}