com.scalar.db.sql.common.RecordsResultSet Maven / Gradle / Ivy
package com.scalar.db.sql.common;
import com.scalar.db.sql.ColumnDefinitions;
import com.scalar.db.sql.Record;
import com.scalar.db.sql.ResultSet;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.Iterator;
import java.util.Objects;
import java.util.Optional;
import javax.annotation.concurrent.NotThreadSafe;
@NotThreadSafe
public class RecordsResultSet implements ResultSet {
private final Iterator recordIterator;
private final ColumnDefinitions columnDefinitions;
@SuppressFBWarnings("EI_EXPOSE_REP2")
public RecordsResultSet(Iterator recordIterator, ColumnDefinitions columnDefinitions) {
this.recordIterator = Objects.requireNonNull(recordIterator);
this.columnDefinitions = Objects.requireNonNull(columnDefinitions);
}
public RecordsResultSet(Iterable recordIterable, ColumnDefinitions columnDefinitions) {
this(recordIterable.iterator(), columnDefinitions);
}
@Override
public Optional one() {
if (!recordIterator.hasNext()) {
return Optional.empty();
}
return Optional.of(recordIterator.next());
}
@SuppressFBWarnings("EI_EXPOSE_REP")
@Override
public Iterator iterator() {
return recordIterator;
}
@Override
public ColumnDefinitions getColumnDefinitions() {
return columnDefinitions;
}
}