custom charts: Add formatter for the charts
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.chart.ui / src / org / eclipse / tracecompass / internal / tmf / chart / ui / data / ChartRange.java
1 /*******************************************************************************
2 * Copyright (c) 2016 EfficiOS Inc., Jonathan Rajotte-Julien
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *******************************************************************************/
9
10 package org.eclipse.tracecompass.internal.tmf.chart.ui.data;
11
12 import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
13
14 import java.math.BigDecimal;
15
16 /**
17 * BigDecimal based range representation
18 *
19 * @author Jonathan Rajotte-Julien
20 */
21 public class ChartRange {
22
23 // ------------------------------------------------------------------------
24 // Members
25 // ------------------------------------------------------------------------
26
27 private BigDecimal fMinimum;
28 private BigDecimal fMaximum;
29 private BigDecimal fRange;
30
31 // ------------------------------------------------------------------------
32 // Constructors
33 // ------------------------------------------------------------------------
34
35 /**
36 * Constructor.
37 */
38 public ChartRange() {
39 fMinimum = checkNotNull(BigDecimal.ZERO);
40 fMaximum = checkNotNull(BigDecimal.ONE);
41 fRange = checkNotNull(getMaximum().subtract(getMinimum()));
42 }
43
44 /**
45 * Constructor with minimum and maximum values supplied.
46 *
47 * @param minimum
48 * The minimum value of the range
49 * @param maximum
50 * The maximum value of the range
51 */
52 public ChartRange(BigDecimal minimum, BigDecimal maximum) {
53 fMinimum = minimum;
54 fMaximum = maximum;
55 fRange = checkNotNull(maximum.subtract(minimum));
56 }
57
58 // ------------------------------------------------------------------------
59 // Accessors
60 // ------------------------------------------------------------------------
61
62 /**
63 * Accessor that returns the lower bound of the range.
64 *
65 * @return The minimum value of the range
66 */
67 public BigDecimal getMinimum() {
68 return fMinimum;
69 }
70
71 /**
72 * Accessor that returns the upper bound of the range.
73 *
74 * @return The maximum value of the range
75 */
76 public BigDecimal getMaximum() {
77 return fMaximum;
78 }
79
80 /**
81 * Accessor that returns the difference between the lower and the upper
82 * bounds of the range.
83 *
84 * @return The range delta
85 */
86 public BigDecimal getDelta() {
87 return fRange;
88 }
89
90 /**
91 * Method that checks if the delta is equal to zero.
92 *
93 * @return {@code true} if the delta is null, else {@code false}
94 */
95 public boolean isDeltaNull() {
96 return getDelta().compareTo(BigDecimal.ZERO) == 0;
97 }
98
99 // ------------------------------------------------------------------------
100 // Mutators
101 // ------------------------------------------------------------------------
102
103 /**
104 * Mutator that sets the minimum value of the range.
105 *
106 * @param minimum
107 * The new minimum value
108 */
109 public void setMinimum(BigDecimal minimum) {
110 fMinimum = minimum;
111 fRange = checkNotNull(getMaximum().subtract(getMinimum()));
112 }
113
114 /**
115 * Mutator that sets the maximum value of the range.
116 *
117 * @param maximum
118 * The new maximum value
119 */
120 public void setMaximum(BigDecimal maximum) {
121 fMaximum = maximum;
122 fRange = checkNotNull(getMaximum().subtract(getMinimum()));
123 }
124
125 // ------------------------------------------------------------------------
126 // Operations
127 // ------------------------------------------------------------------------
128
129 /**
130 * This method clamps the positive minimum value of this range down to zero.
131 * It returns the current object back with the minimum value modified.
132 *
133 * @return The current range map
134 */
135 public ChartRange clamp() {
136 fMinimum = fMinimum.min(BigDecimal.ZERO);
137
138 return this;
139 }
140
141 }
This page took 0.034516 seconds and 5 git commands to generate.