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

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

Introduction

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

Prototype

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

Source Link

Document

Returns the single element contained in iterator , or defaultValue if the iterator is empty.

Usage

From source file:com.clarkparsia.sbol.SBOLUtils.java

public static DnaComponent getRootComponent(SBOLDocument doc) {
    return Iterators.getOnlyElement(Iterators.filter(doc.getContents().iterator(), DnaComponent.class), null);
}

From source file:hudson.plugins.timestamper.io.TimestampsReader.java

/**
 * Read the next time-stamp.//  w  w w  . ja va2s .  co  m
 * 
 * @return the next time-stamp, or {@link Optional#absent()} if there are no
 *         more to read
 * @throws IOException
 */
public Optional<Timestamp> read() throws IOException {
    List<Timestamp> timestamps = new ArrayList<Timestamp>();
    read(1, Optional.of(timestamps));
    return Optional.fromNullable(Iterators.getOnlyElement(timestamps.iterator(), null));
}