diff options
author | Sean Owen <sowen@cloudera.com> | 2016-01-08 13:02:30 -0800 |
---|---|---|
committer | Reynold Xin <rxin@databricks.com> | 2016-01-08 13:02:30 -0800 |
commit | 659fd9d04b988d48960eac4f352ca37066f43f5c (patch) | |
tree | 1893735497a7cfae284d7a9eb4dd07bed62b4ac4 /examples/src | |
parent | 553fd7b912a32476b481fd3f80c1d0664b6c6484 (diff) | |
download | spark-659fd9d04b988d48960eac4f352ca37066f43f5c.tar.gz spark-659fd9d04b988d48960eac4f352ca37066f43f5c.tar.bz2 spark-659fd9d04b988d48960eac4f352ca37066f43f5c.zip |
[SPARK-4819] Remove Guava's "Optional" from public API
Replace Guava `Optional` with (an API clone of) Java 8 `java.util.Optional` (edit: and a clone of Guava `Optional`)
See also https://github.com/apache/spark/pull/10512
Author: Sean Owen <sowen@cloudera.com>
Closes #10513 from srowen/SPARK-4819.
Diffstat (limited to 'examples/src')
-rw-r--r-- | examples/src/main/java/org/apache/spark/examples/streaming/JavaStatefulNetworkWordCount.java | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/examples/src/main/java/org/apache/spark/examples/streaming/JavaStatefulNetworkWordCount.java b/examples/src/main/java/org/apache/spark/examples/streaming/JavaStatefulNetworkWordCount.java index 14997c64d5..f52cc7c205 100644 --- a/examples/src/main/java/org/apache/spark/examples/streaming/JavaStatefulNetworkWordCount.java +++ b/examples/src/main/java/org/apache/spark/examples/streaming/JavaStatefulNetworkWordCount.java @@ -23,17 +23,14 @@ import java.util.regex.Pattern; import scala.Tuple2; -import com.google.common.base.Optional; -import com.google.common.collect.Lists; - import org.apache.spark.SparkConf; import org.apache.spark.api.java.function.*; import org.apache.spark.api.java.JavaPairRDD; +import org.apache.spark.api.java.Optional; import org.apache.spark.api.java.StorageLevels; import org.apache.spark.streaming.Durations; import org.apache.spark.streaming.State; import org.apache.spark.streaming.StateSpec; -import org.apache.spark.streaming.Time; import org.apache.spark.streaming.api.java.*; /** @@ -67,8 +64,8 @@ public class JavaStatefulNetworkWordCount { // Initial state RDD input to mapWithState @SuppressWarnings("unchecked") - List<Tuple2<String, Integer>> tuples = Arrays.asList(new Tuple2<String, Integer>("hello", 1), - new Tuple2<String, Integer>("world", 1)); + List<Tuple2<String, Integer>> tuples = + Arrays.asList(new Tuple2<>("hello", 1), new Tuple2<>("world", 1)); JavaPairRDD<String, Integer> initialRDD = ssc.sparkContext().parallelizePairs(tuples); JavaReceiverInputDStream<String> lines = ssc.socketTextStream( @@ -77,7 +74,7 @@ public class JavaStatefulNetworkWordCount { JavaDStream<String> words = lines.flatMap(new FlatMapFunction<String, String>() { @Override public Iterable<String> call(String x) { - return Lists.newArrayList(SPACE.split(x)); + return Arrays.asList(SPACE.split(x)); } }); @@ -85,18 +82,17 @@ public class JavaStatefulNetworkWordCount { new PairFunction<String, String, Integer>() { @Override public Tuple2<String, Integer> call(String s) { - return new Tuple2<String, Integer>(s, 1); + return new Tuple2<>(s, 1); } }); // Update the cumulative count function - final Function3<String, Optional<Integer>, State<Integer>, Tuple2<String, Integer>> mappingFunc = + Function3<String, Optional<Integer>, State<Integer>, Tuple2<String, Integer>> mappingFunc = new Function3<String, Optional<Integer>, State<Integer>, Tuple2<String, Integer>>() { - @Override public Tuple2<String, Integer> call(String word, Optional<Integer> one, State<Integer> state) { - int sum = one.or(0) + (state.exists() ? state.get() : 0); - Tuple2<String, Integer> output = new Tuple2<String, Integer>(word, sum); + int sum = one.orElse(0) + (state.exists() ? state.get() : 0); + Tuple2<String, Integer> output = new Tuple2<>(word, sum); state.update(sum); return output; } |