Example usage for org.joda.time DurationField add

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

Introduction

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

Prototype

public abstract long add(long instant, long value);

Source Link

Document

Adds a duration value (which may be negative) to the instant.

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.jav 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()]);
}