This commit is contained in:
RedKale
2016-06-23 11:29:13 +08:00
parent 828da4b196
commit cfd65492d2
2 changed files with 11 additions and 2 deletions

View File

@@ -18,7 +18,9 @@ import java.util.function.Consumer;
* @param <T> 集合元素的数据类型
*/
@SuppressWarnings("unchecked")
public class Sheet<T> implements java.io.Serializable {
public class Sheet<T> implements java.io.Serializable, Iterable<T> {
private static final List EMPTYLIST = new ArrayList();
private long total = -1;
@@ -91,9 +93,16 @@ public class Sheet<T> implements java.io.Serializable {
this.rows = (Collection<T>) data;
}
public void forEach(final Consumer<T> consumer) {
@Override
public Iterator<T> iterator() {
return (this.rows == null) ? EMPTYLIST.iterator() : this.rows.iterator();
}
@Override
public void forEach(final Consumer<? super T> consumer) {
if (consumer != null && this.rows != null && !this.rows.isEmpty()) {
this.rows.forEach(consumer);
}
}
}