com.ringcentral.platform.metrics.samples.DefaultSampleSpec Maven / Gradle / Ivy
package com.ringcentral.platform.metrics.samples;
import com.ringcentral.platform.metrics.labels.Label;
import com.ringcentral.platform.metrics.labels.LabelUtils;
import com.ringcentral.platform.metrics.labels.LabelValue;
import com.ringcentral.platform.metrics.names.MetricName;
import java.util.List;
import java.util.Map;
import static java.lang.Boolean.*;
import static java.util.Collections.*;
import static org.apache.commons.lang3.StringUtils.*;
public class DefaultSampleSpec implements SampleSpec {
private Boolean enabled;
private MetricName name;
private String measurableName;
private List labelValues;
private Object value;
private String type;
public static DefaultSampleSpec sampleSpec() {
return new DefaultSampleSpec();
}
public DefaultSampleSpec() {}
public DefaultSampleSpec(
Boolean enabled,
MetricName name,
String measurableName,
List labelValues,
Object value,
String type) {
this.enabled = enabled;
this.name = name;
this.measurableName = measurableName;
this.labelValues = labelValues;
this.value = value;
this.type = type;
}
public boolean hasEnabled() {
return enabled != null;
}
public DefaultSampleSpec enable() {
return enabled(TRUE);
}
public DefaultSampleSpec disable() {
return enabled(FALSE);
}
public DefaultSampleSpec enabled(Boolean enabled) {
this.enabled = enabled;
return this;
}
public Boolean getEnabled() {
return enabled;
}
public boolean isEnabled() {
return !hasEnabled() || getEnabled();
}
public boolean hasName() {
return name != null;
}
public DefaultSampleSpec name(MetricName name) {
this.name = name;
return this;
}
public MetricName name() {
return name;
}
public boolean hasMeasurableName() {
return isNotBlank(measurableName);
}
public DefaultSampleSpec noMeasurableName() {
return measurableName(EMPTY);
}
public DefaultSampleSpec measurableName(String measurableName) {
this.measurableName = measurableName;
return this;
}
public String measurableName() {
return measurableName;
}
public boolean hasLabelValues() {
return labelValues != null && !labelValues.isEmpty();
}
public DefaultSampleSpec noLabelValues() {
return labelValues(emptyList());
}
public DefaultSampleSpec labelValues(List labelValues) {
this.labelValues = labelValues;
return this;
}
public List labelValues() {
return labelValues;
}
public boolean hasLabel(Label label) {
return LabelUtils.hasLabel(labelValues, label);
}
public String valueOf(Label label) {
return LabelUtils.valueOf(labelValues, label);
}
public LabelValue labelValueOf(Label label) {
return LabelUtils.labelValueOf(labelValues, label);
}
public Map