Example usage for org.joda.time Interval toDurationMillis

List of usage examples for org.joda.time Interval toDurationMillis

Introduction

In this page you can find the example usage for org.joda.time Interval toDurationMillis.

Prototype

public long toDurationMillis() 

Source Link

Document

Gets the duration of this time interval in milliseconds.

Usage

From source file:udpserver.Task.java

public String getDurationString() {
    Interval interval;
    if (endTime == null) {
        interval = new Interval(startTime, DateTime.now());
    } else {//from  ww  w . j a va2 s  .com
        interval = new Interval(startTime, endTime);
    }
    return Long.toString(interval.toDurationMillis());
}

From source file:uk.ac.susx.tag.method51.twitter.pipeline.TweetGenerator.java

License:Apache License

@Override
protected void doWork() throws Exception {

    Interval interval = getService().getNextInterval();
    Interval lifetime = getService().getLifetime();

    final long taskTime = interval.getEndMillis();
    final long taskStartTime = lifetime.getStartMillis();
    final long taskEndTime = lifetime.getEndMillis();
    final long taskDuration = lifetime.toDurationMillis();

    if (taskTime >= taskEndTime) {
        stopAsync();/*from w w  w  .j a  v  a2s .  co m*/
        return;
    }

    List<Tweet> tweets = new LinkedList<>();
    int intervalTotal;
    switch (shape) {
    case FLAT:
        intervalTotal = rate;
        break;
    case SINE_WAVE:
        double progress = (taskTime - taskStartTime) / (double) taskDuration;
        intervalTotal = (int) Math.floor(rate * Math.sin(progress * Math.PI));
        break;
    default:
        intervalTotal = rate;
        break;
    }

    for (int i = 0; i < intervalTotal; ++i) {
        tweets.add(generateTweet(i, intervalTotal));
    }

    produce(tweets);

}