no.ssb.jsonstat.v1.Category 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 java.util.*;
public final class Category implements Iterable {
private final Map labels = new LinkedHashMap<>();
private final Map indices = new LinkedHashMap<>();
private final Map> children = new LinkedHashMap<>();
public Category(Map indices, Map labels, Map> children) {
this.indices.putAll(indices);
this.labels.putAll(labels);
this.children.putAll(children);
}
public int getIndex(String id) {
Integer integer = indices.get(id);
if (integer == null) {
return 0;
}
return integer;
}
public Optional getLabel(String id) {
return Optional.ofNullable(labels.get(id));
}
public List getChild(String id) {
return children.containsKey(id) ? children.get(id) : Collections.emptyList();
}
@Override
public Iterator iterator() {
if (!indices.isEmpty()) {
return indices.keySet().iterator();
}
else {
return labels.keySet().iterator();
}
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Category category = (Category) o;
if (!children.equals(category.children)) return false;
if (!indices.equals(category.indices)) return false;
if (!labels.equals(category.labels)) return false;
return true;
}
@Override
public int hashCode() {
int result = labels.hashCode();
result = 31 * result + indices.hashCode();
result = 31 * result + children.hashCode();
return result;
}
}