
com.belladati.sdk.impl.AttributeImpl Maven / Gradle / Ivy
package com.belladati.sdk.impl;
import com.belladati.sdk.report.Attribute;
import com.belladati.sdk.report.AttributeValue;
import com.belladati.sdk.util.CachedList;
import com.fasterxml.jackson.databind.JsonNode;
class AttributeImpl implements Attribute {
private final BellaDatiServiceImpl service;
private final String reportId;
private final String name;
private final String code;
AttributeImpl(BellaDatiServiceImpl service, String reportId, JsonNode node) throws InvalidAttributeException {
this.service = service;
this.reportId = reportId;
if (node.hasNonNull("name") && node.hasNonNull("code")) {
this.name = node.get("name").asText();
this.code = node.get("code").asText();
} else {
throw new InvalidAttributeException(node);
}
}
@Override
public String getName() {
return name;
}
@Override
public String getCode() {
return code;
}
@Override
public CachedList getValues() {
return service.getAttributeValues(reportId, code);
}
@Override
public String toString() {
return name;
}
@Override
public boolean equals(Object obj) {
if (obj instanceof AttributeImpl) {
return code.equals(((AttributeImpl) obj).code) && reportId.equals(((AttributeImpl) obj).reportId);
}
return false;
}
@Override
public int hashCode() {
return code.hashCode() ^ reportId.hashCode();
}
class InvalidAttributeException extends Exception {
/** The serialVersionUID */
private static final long serialVersionUID = -4920843734203654180L;
public InvalidAttributeException(JsonNode node) {
super("Invalid attribute JSON: " + node.toString());
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy