Example usage for org.joda.time DurationField getDifference

List of usage examples for org.joda.time DurationField getDifference

Introduction

In this page you can find the example usage for org.joda.time DurationField getDifference.

Prototype

public abstract int getDifference(long minuendInstant, long subtrahendInstant);

Source Link

Document

Computes the difference between two instants, as measured in the units of this field.

Usage

From source file:de.openali.odysseus.chart.ext.base.axisrenderer.DateTimeTickCalculator.java

License:Open Source License

/**
 * Calculates the ticks shown for the given Axis
 *///from w w  w .  j a  v a 2  s.  co  m
@SuppressWarnings("rawtypes")
@Override
public Double[] calcTicks(final GC gc, final IAxis axis, final Number minDisplayInterval,
        final Point ticklabelSize) {
    final IDataRange<Number> numRange = axis.getNumericRange();
    if (numRange == null || numRange.getMin() == null || numRange.getMax() == null)
        return new Double[] {};

    final long start = numRange.getMin().longValue();
    final long end = numRange.getMax().longValue();

    final IDateTimeAxisField axisField = m_fieldTypeProvider.getDateTimeAxisField(numRange);

    final DateTimeZone jodaTZ = DateTimeZone.forTimeZone(KalypsoCorePlugin.getDefault().getTimeZone());
    final DurationField field = axisField.getFieldType().getDurationType()
            .getField(GregorianChronology.getInstance(jodaTZ));

    final int tickCount = Math.max(1, field.getDifference(end, start));
    final int maximumTickCount = axis.getScreenHeight() / (ticklabelSize.x + 2/* Pixel */);
    final int[] rollOvers = axisField.getRollovers();

    final int rollOver = calculateRollover(tickCount, maximumTickCount, rollOvers);

    final List<Double> ticks = new ArrayList<>();
    Long tick = getFirstRollValue(axisField, start, end);
    ticks.add(tick.doubleValue());
    while (tick < end) {
        tick = field.add(tick, rollOver);
        ticks.add(tick.doubleValue());
    }

    return ticks.toArray(new Double[ticks.size()]);
}