package org.ehcache.xml.model;
import org.ehcache.xml.XmlModel;
import java.time.temporal.TemporalUnit;
public class Expiry {
private final ExpiryType type;
public Expiry(final ExpiryType type) {
this.type = type;
}
public boolean isUserDef() {
return type != null && type.getClazz() != null;
}
public boolean isTTI() {
return type != null && type.getTti() != null;
}
public boolean isTTL() {
return type != null && type.getTtl() != null;
}
public String type() {
return type.getClazz();
}
public long value() {
final TimeType time;
if(isTTI()) {
time = type.getTti();
} else {
time = type.getTtl();
}
return time == null ? 0L : time.getValue().longValue();
}
public TemporalUnit unit() {
final TimeType time;
if(isTTI()) {
time = type.getTti();
} else {
time = type.getTtl();
}
if(time != null) {
return XmlModel.convertToJavaTemporalUnit(time.getUnit());
}
return null;
}
}