
com.github.dakusui.thincrest.metamor.Dataset Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of thincrest-pcond Show documentation
Show all versions of thincrest-pcond Show documentation
Yet another assertion library powered by "pcond"
The newest version!
package com.github.dakusui.thincrest.metamor;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import static java.util.Collections.unmodifiableList;
import static java.util.Objects.requireNonNull;
public interface Dataset extends Iterable {
String name();
E get(int i);
int size();
default E last() {
return this.get(this.size() - 1);
}
default Stream stream() {
return StreamSupport.stream(this.spliterator(), false);
}
abstract class Base implements Dataset {
private final String name;
Base(String name) {
this.name = requireNonNull(name);
}
public String name() {
return this.name;
}
}
interface OnGoing extends Dataset {
OnGoing add(E value);
Dataset close();
class Impl extends Base implements OnGoing {
final List content;
public Impl(String name) {
super(name);
this.content = new ArrayList<>();
}
public Impl(String name, Dataset content) {
this(name);
for (int i = 0; i < content.size(); i++)
this.add(content.get(i));
}
@Override
public E get(int i) {
return this.content.get(i);
}
@Override
public int size() {
return this.content.size();
}
@Override
public OnGoing add(E value) {
this.content.add(value);
return this;
}
@Override
public Dataset close() {
return new Closed.Impl<>(this.name(), this.content);
}
@Override
public Iterator iterator() {
return this.content.iterator();
}
@Override
public String toString() {
if (this.size() == 0)
return this.name() + ":(empty)";
return this.name() + ":" + last();
}
}
}
interface Closed extends Dataset {
class Impl extends Base implements Closed {
final List content;
public Impl(String name, List content) {
super(name);
this.content = unmodifiableList(content);
}
@Override
public E get(int i) {
return this.content.get(i);
}
@Override
public int size() {
return this.content.size();
}
@Override
public Iterator iterator() {
return this.content.iterator();
}
@Override
public String toString() {
return this.name() + ":" + this.content;
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy