changeset 7551:4bf1ce19c7cd

Automated merge with http://hg.openjdk.java.net/lambda/lambda//jdk
author psandoz
date Fri, 01 Mar 2013 11:33:02 +0100
parents 3f73ae4dc13f (current diff) e4c9aab508b1 (diff)
children 996188a59559
files
diffstat 2 files changed, 36 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/util/OptionalDouble.java	Thu Feb 28 13:45:03 2013 -0800
+++ b/src/share/classes/java/util/OptionalDouble.java	Fri Mar 01 11:33:02 2013 +0100
@@ -216,7 +216,9 @@
         }
 
         OptionalDouble other = (OptionalDouble) o;
-        return (isPresent && other.isPresent) ? value == other.value : isPresent == other.isPresent;
+        return (isPresent && other.isPresent)
+               ? Double.compare(value, other.value) == 0
+               : isPresent == other.isPresent;
     }
 
     @Override
--- a/src/share/classes/java/util/stream/Collectors.java	Thu Feb 28 13:45:03 2013 -0800
+++ b/src/share/classes/java/util/stream/Collectors.java	Fri Mar 01 11:33:02 2013 +0100
@@ -36,6 +36,7 @@
 import java.util.NoSuchElementException;
 import java.util.Objects;
 import java.util.OptionalDouble;
+import java.util.OptionalLong;
 import java.util.Set;
 import java.util.StringJoiner;
 import java.util.function.BiConsumer;
@@ -458,8 +459,8 @@
     public static final class LongStatistics implements LongConsumer, IntConsumer {
         private long count;
         private long sum;
-        private long min;
-        private long max;
+        private long min = Long.MAX_VALUE;
+        private long max = Long.MIN_VALUE;
 
         @Override
         public void accept(int value) {
@@ -489,24 +490,34 @@
             return sum;
         }
 
-        public long getMin() {
-            return min;
+        public OptionalLong getMin() {
+            return count > 0 ? OptionalLong.of(min) : OptionalLong.empty();
         }
 
-        public long getMax() {
-            return max;
+        public OptionalLong getMax() {
+            return count > 0 ? OptionalLong.of(max) : OptionalLong.empty();
         }
 
         public OptionalDouble getMean() {
             return count > 0 ? OptionalDouble.of((double) sum / count) : OptionalDouble.empty();
         }
+
+        @Override
+        public String toString() {
+            return new StringJoiner(", ", this.getClass().getSimpleName() + "{", "}").
+                    add("count=" + getCount()).
+                    add("sum=" + getSum()).
+                    add("min=" + getMin()).
+                    add("max=" + getMax()).
+                    toString();
+        }
     }
 
     public static final class DoubleStatistics implements DoubleConsumer {
         private long count;
         private double sum;
-        private double min;
-        private double max;
+        private double min = Double.POSITIVE_INFINITY;
+        private double max = Double.NEGATIVE_INFINITY;
 
         @Override
         public void accept(double value) {
@@ -531,17 +542,27 @@
             return sum;
         }
 
-        public double getMin() {
-            return min;
+        public OptionalDouble getMin() {
+            return count > 0 ? OptionalDouble.of(min) : OptionalDouble.empty();
         }
 
-        public double getMax() {
-            return max;
+        public OptionalDouble getMax() {
+            return count > 0 ? OptionalDouble.of(max) : OptionalDouble.empty();
         }
 
         public OptionalDouble getMean() {
             return count > 0 ? OptionalDouble.of(sum / count) : OptionalDouble.empty();
         }
+
+        @Override
+        public String toString() {
+            return new StringJoiner(", ", this.getClass().getSimpleName() + "{", "}").
+                    add("count=" + getCount()).
+                    add("sum=" + getSum()).
+                    add("min=" + getMin()).
+                    add("max=" + getMax()).
+                    toString();
+        }
     }
 
     public static Collector.OfLong<LongStatistics> toLongStatistics() {