import java.math.BigDecimal;
/**
- * BigDecimal based range representation
+ * BigDecimal based range representation. The chart range cannot be 0.
*
* @author Jonathan Rajotte-Julien
*/
* The maximum value of the range
*/
public ChartRange(BigDecimal minimum, BigDecimal maximum) {
- fMinimum = minimum;
- fMaximum = maximum;
- fRange = checkNotNull(maximum.subtract(minimum));
+ BigDecimal subtract = maximum.subtract(minimum);
+ if (minimum.compareTo(maximum) > 0) {
+ throw new IllegalArgumentException("ChartRange: minimum should be lower than or equal to the maximum (min: " + minimum + ", max: " + maximum + ')'); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ if (BigDecimal.ZERO.equals(subtract)) {
+ // Minimum and maximum values are all the same, so add 1 to the minimum
+ fMinimum = minimum;
+ fMaximum = minimum.add(BigDecimal.ONE);
+ fRange = checkNotNull(BigDecimal.ONE);
+ } else {
+ fMinimum = minimum;
+ fMaximum = maximum;
+ fRange = checkNotNull(subtract);
+ }
}
// ------------------------------------------------------------------------
return fRange;
}
- /**
- * Method that checks if the delta is equal to zero.
- *
- * @return {@code true} if the delta is null, else {@code false}
- */
- public boolean isDeltaNull() {
- return getDelta().compareTo(BigDecimal.ZERO) == 0;
- }
-
- // ------------------------------------------------------------------------
- // Mutators
- // ------------------------------------------------------------------------
-
- /**
- * Mutator that sets the minimum value of the range.
- *
- * @param minimum
- * The new minimum value
- */
- public void setMinimum(BigDecimal minimum) {
- fMinimum = minimum;
- fRange = checkNotNull(getMaximum().subtract(getMinimum()));
- }
-
- /**
- * Mutator that sets the maximum value of the range.
- *
- * @param maximum
- * The new maximum value
- */
- public void setMaximum(BigDecimal maximum) {
- fMaximum = maximum;
- fRange = checkNotNull(getMaximum().subtract(getMinimum()));
- }
-
// ------------------------------------------------------------------------
// Operations
// ------------------------------------------------------------------------
* @return The current range map
*/
public ChartRange clamp() {
- fMinimum = fMinimum.min(BigDecimal.ZERO);
+ if (fMinimum.compareTo(BigDecimal.ZERO) > 0) {
+ fMinimum = checkNotNull(BigDecimal.ZERO);
+ fRange = fMaximum;
+ }
return this;
}
+ @Override
+ public String toString() {
+ return "ChartRange: [" + fMinimum + ", " + fMaximum + "]"; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
+ }
+
}
\ No newline at end of file
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.tracecompass.common.core.format.DecimalUnitFormat;
-import org.eclipse.tracecompass.internal.tmf.chart.ui.data.ChartRange;
import org.eclipse.tracecompass.internal.tmf.chart.ui.data.ChartRangeMap;
/**
return (buffer == null ? new StringBuffer() : buffer);
}
- ChartRange internalRange = rangeMap.getPlottedRange();
- ChartRange externalRange = rangeMap.getInputDataRange();
-
- /* If any range's delta is null, format with the external bounds */
- if (internalRange.isDeltaNull() || externalRange.isDeltaNull()) {
- StringBuffer buffer = super.format(externalRange.getMinimum().doubleValue(), toAppendTo, pos);
- return (buffer == null ? new StringBuffer() : buffer);
- }
-
/* Find external value before formatting */
Double externalValue = checkNotNull(fRangeMap).getExternalValue(number).doubleValue();
StringBuffer buffer = super.format(externalValue, toAppendTo, pos);
import java.text.ParsePosition;
import org.eclipse.jdt.annotation.Nullable;
-import org.eclipse.tracecompass.internal.tmf.chart.ui.data.ChartRange;
+import org.eclipse.tracecompass.common.core.NonNullUtils;
import org.eclipse.tracecompass.internal.tmf.chart.ui.data.ChartRangeMap;
import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestampFormat;
fRangeMap = map;
}
+ /**
+ * Get the pattern string of the format.
+ *
+ * @return the pattern string.
+ */
+ public String getPattern() {
+ return NonNullUtils.checkNotNull(fFormat.toPattern());
+ }
+
// ------------------------------------------------------------------------
// Operations
// ------------------------------------------------------------------------
return checkNotNull(toAppendTo.append(fFormat.format(time)));
}
- ChartRange internalRange = rangeMap.getPlottedRange();
- ChartRange externalRange = rangeMap.getInputDataRange();
-
- /* If any range's delta is null, format with the external bounds */
- if (internalRange.isDeltaNull() || externalRange.isDeltaNull()) {
- return checkNotNull(toAppendTo.append(fFormat.format(externalRange.getMinimum().doubleValue())));
- }
-
/* Find external value before formatting */
BigDecimal externalValue = checkNotNull(fRangeMap).getExternalValue(number);
return checkNotNull(toAppendTo.append(fFormat.format(externalValue.longValue())));