io.yields.math.framework.kpi.StatDefinition.java Source code

Java tutorial

Introduction

Here is the source code for io.yields.math.framework.kpi.StatDefinition.java

Source

/*
 * Copyright 2014 by Yields.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.yields.math.framework.kpi;

import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;

import org.apache.commons.lang.Validate;

import java.io.Serializable;
import java.util.DoubleSummaryStatistics;

/**
 * @author Tim Rombauts
 */
@JsonIdentityInfo(generator = ObjectIdGenerators.IntSequenceGenerator.class, property = "@id")
public class StatDefinition extends Definition implements Serializable {

    private Double minValue;

    private Double maxValue;

    private Double referenceLevel;

    public StatDefinition(String name) {
        this(null, name, null, null, null, null);
    }

    public StatDefinition(StatDefinition parent, String name, String description, DoubleSummaryStatistics stats,
            double referenceLevel) {
        this(parent, name, description, stats.getMin(), stats.getMax(), referenceLevel);
    }

    public StatDefinition(StatDefinition parent, String name, Double minValue, Double maxValue,
            Double referenceLevel) {
        this(parent, name, null, minValue, maxValue, referenceLevel);
    }

    public StatDefinition(StatDefinition parent, String name, String description, Double minValue, Double maxValue,
            Double referenceLevel) {
        super(parent, name, description);
        if (minValue != null && maxValue != null && referenceLevel != null) {
            Validate.isTrue(minValue <= referenceLevel && referenceLevel <= maxValue);
        }
        this.minValue = minValue;
        this.maxValue = maxValue;
        this.referenceLevel = referenceLevel;
    }

    /**
     * for JSON
     */
    public StatDefinition() {
    }

    public Double getMinValue() {
        return minValue;
    }

    public Double getMaxValue() {
        return maxValue;
    }

    public Double getReferenceLevel() {
        return referenceLevel;
    }

}