summaryrefslogtreecommitdiff
path: root/test/files/jvm/duration-java
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2012-09-04 14:51:05 -0700
committerPaul Phillips <paulp@improving.org>2012-09-04 20:11:06 -0700
commit5b9b394d99bd7e4446e0f15475b34ec287d91685 (patch)
tree3f4d0f74f0ebd341fb453fd6a07d31e17423b4d2 /test/files/jvm/duration-java
parent9556dfbf9dbb1b129b5eaab577d90cf09206ed4d (diff)
downloadscala-5b9b394d99bd7e4446e0f15475b34ec287d91685.tar.gz
scala-5b9b394d99bd7e4446e0f15475b34ec287d91685.tar.bz2
scala-5b9b394d99bd7e4446e0f15475b34ec287d91685.zip
Removing duplication from Duration.
I don't know what good it is to have code review if we are checking in code like this. We must raise the bar, people. When the justification for code being in the standard library is borderline at best - as it is here - then the code must be of exceptional quality. This code is not of exceptional quality. Mostly these are not behavioral changes, but: - I removed finite_? as it is a gratuitous deviation from every isXXX method in the world. This isn't ruby. - I removed all the regexps, which only made things complicated - I removed all the unnecessary casts, which is to say, all of them - I made more things final, sealed, and private - The unapply structure was all wrong; returning Option[Duration] on the string unapply meant you'd have to say case Duration(Duration(x, y)) => ... So I fixed apply and unapply to be symmetric. - And I removed the "parse" method, since it was doing what apply is supposed to do. There's a test case to exercise accessing it from java, which also reveals what I hope are bugs. Thanks to viktor klang for DurationConversions.
Diffstat (limited to 'test/files/jvm/duration-java')
-rw-r--r--test/files/jvm/duration-java/Test.java38
1 files changed, 38 insertions, 0 deletions
diff --git a/test/files/jvm/duration-java/Test.java b/test/files/jvm/duration-java/Test.java
new file mode 100644
index 0000000000..02feb522b8
--- /dev/null
+++ b/test/files/jvm/duration-java/Test.java
@@ -0,0 +1,38 @@
+import scala.concurrent.util.Duration;
+import java.util.*;
+import java.util.concurrent.TimeUnit;
+import static java.util.concurrent.TimeUnit.*;
+
+public class Test {
+ public static List<Double> inputs = Arrays.asList(0d, 1d, 7d, 10d, 12d, 24d, 30d, 60d, 100d, 1000d, 1e6);
+ public static List<Double> makeNumbers() {
+ ArrayList<Double> xs = new ArrayList<Double>();
+ for (Double n1: inputs) {
+ for (Double n2: inputs) {
+ Double n = n1 * n2;
+ if (!xs.contains(n))
+ xs.add(n);
+ }
+ }
+ Double[] arr = xs.toArray(new Double[0]);
+ Arrays.sort(arr);
+ return Arrays.asList(arr);
+ }
+
+ public static void p(Object x) {
+ System.out.println(x);
+ }
+ public static void main(String[] args) {
+ for (TimeUnit t : TimeUnit.values()) {
+ for (Double n: makeNumbers()) {
+ String s = "" + n + " " + t.toString().toLowerCase();
+ Duration d = Duration.create(n, t);
+ p(String.format("%25s => %s", s, d));
+ }
+ }
+ for (String s: Arrays.asList("Inf", "-Inf", "+Inf", "PlusInf", "MinusInf")) {
+ Duration d = Duration.create(s);
+ p(String.format("%25s => %s", s, d));
+ }
+ }
+}