no.ssb.jsonstat.v1.Stat Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of json-stat-java Show documentation
Show all versions of json-stat-java Show documentation
Json stat implementation in Java
The newest version!
package no.ssb.jsonstat.v1;
import no.ssb.jsonstat.v1.parser.JacksonStatParser;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
public final class Stat {
private final List datasets = new ArrayList<>();
public Stat(List datasets) {
this.datasets.addAll(datasets);
}
public List getDatasets() {
return Collections.unmodifiableList(datasets);
}
public Optional getDataset(final String id) {
return datasets.stream().filter(dataset -> dataset.getId().equals(id)).findFirst();
}
public Optional getDataset(final int index) {
return index < datasets.size() ? Optional.of(getDatasets().get(index)) : Optional.empty();
}
public static Stat parse(InputStream stream) throws IOException {
return new JacksonStatParser().parse(stream);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Stat stat = (Stat) o;
if (!datasets.equals(stat.datasets)) return false;
return true;
}
@Override
public int hashCode() {
return datasets.hashCode();
}
}