Skip to content

Commit

Permalink
Change "Duration" to "Durations" to avoid changing Duration case clas…
Browse files Browse the repository at this point in the history
…s API
  • Loading branch information
srowen committed Sep 22, 2014
1 parent bda301c commit 5a9e706
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
14 changes: 12 additions & 2 deletions streaming/src/main/scala/org/apache/spark/streaming/Duration.scala
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,23 @@ object Minutes {
}

// Java-friendlier versions of the objects above.
// Named "Durations" instead of "Duration" to avoid changing the case class's implied API.

object Duration {
object Durations {

// No 'milliseconds' since it would conflict with methods above. Use the constructor directly.
/**
* @return [[org.apache.spark.streaming.Duration]] representing given number of milliseconds.
*/
def milliseconds(milliseconds: Long) = Milliseconds(milliseconds)

/**
* @return [[org.apache.spark.streaming.Duration]] representing given number of seconds.
*/
def seconds(seconds: Long) = Seconds(seconds)

/**
* @return [[org.apache.spark.streaming.Duration]] representing given number of minutes.
*/
def minutes(minutes: Long) = Minutes(minutes)

}
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,19 @@ public void testDiv() {
Assert.assertEquals(200.0, new Duration(1000).div(new Duration(5)), 1.0e-12);
}

@Test
public void testMilliseconds() {
Assert.assertEquals(new Duration(100), Durations.milliseconds(100));
}

@Test
public void testSeconds() {
Assert.assertEquals(new Duration(30 * 1000), Duration.seconds(30));
Assert.assertEquals(new Duration(30 * 1000), Durations.seconds(30));
}

@Test
public void testMinutes() {
Assert.assertEquals(new Duration(2 * 60 * 1000), Duration.minutes(2));
Assert.assertEquals(new Duration(2 * 60 * 1000), Durations.minutes(2));
}

}

0 comments on commit 5a9e706

Please sign in to comment.