summaryrefslogtreecommitdiffstats
path: root/statistics/src/main/java/com/yahoo/statistics/Limits.java
blob: c7c958a06ff9ddc19c8b43fff0cfff9bd67852ce (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.statistics;


import java.util.List;
import java.util.ArrayList;


/**
 * Limits for a histogram, this is only a wrapper for initializing
 * a histogram.
 *
 * @author  <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a>
 */
public class Limits {
    private final List<Axis> axes = new ArrayList<>(1);
    private boolean frozen = false;

    /**
     * Create an empty Limits instance.
     */
    public Limits() {
    }

    /**
     * Create a Limits instance suitable for use in a Value.Parameters instance.
     * The instance will be frozen.
     */
    public Limits(double[] limits) {
        addAxis(null, limits);
        freeze();
    }

    /**
     * @param name the name of the variable for this axis
     * @param limits the bucket limits for this axis
     */
    public void addAxis(String name, double[] limits) {
        if (frozen) {
            throw new IllegalStateException("Can not add more axes to a frozen Limits instance.");
        }
        axes.add(new Axis(name, limits));
    }

    int getDimensions() {
        return axes.size();
    }

    Axis getAxis(int i) {
        return axes.get(i);
    }

    /**
     * Prevent adding any mores axes.
     */
    public void freeze() {
        this.frozen = true;
    }

    /**
     * True if further change is not permitted.
     *
     * @return whether this object now should be considered immutable
     */
    public boolean isFrozen() {
        return frozen;
    }

}