flink-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From se...@apache.org
Subject [3/4] flink git commit: [FLINK-2457] [core] Slight adjustedments to Tuple0 singleton names to match naming scheme.
Date Fri, 14 Aug 2015 18:38:01 GMT
[FLINK-2457] [core] Slight adjustedments to Tuple0 singleton names to match naming scheme.


Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/c34af206
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/c34af206
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/c34af206

Branch: refs/heads/master
Commit: c34af2068336f28021d27b878523c055ed5afecf
Parents: fab9ce5
Author: Stephan Ewen <sewen@apache.org>
Authored: Fri Aug 14 18:06:29 2015 +0200
Committer: Stephan Ewen <sewen@apache.org>
Committed: Fri Aug 14 18:07:16 2015 +0200

----------------------------------------------------------------------
 .../org/apache/flink/api/java/tuple/Tuple0.java | 21 ++++++------
 .../api/java/tuple/builder/Tuple0Builder.java   |  2 +-
 .../flink/api/java/typeutils/TupleTypeInfo.java |  2 +-
 .../typeutils/runtime/Tuple0Serializer.java     | 34 +++++++++++++++-----
 .../typeutils/runtime/TupleSerializerTest.java  |  6 ++--
 5 files changed, 40 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flink/blob/c34af206/flink-java/src/main/java/org/apache/flink/api/java/tuple/Tuple0.java
----------------------------------------------------------------------
diff --git a/flink-java/src/main/java/org/apache/flink/api/java/tuple/Tuple0.java b/flink-java/src/main/java/org/apache/flink/api/java/tuple/Tuple0.java
index c2db0bc..1caee2a 100644
--- a/flink-java/src/main/java/org/apache/flink/api/java/tuple/Tuple0.java
+++ b/flink-java/src/main/java/org/apache/flink/api/java/tuple/Tuple0.java
@@ -21,16 +21,20 @@ import java.io.ObjectStreamException;
 
 /**
  * A tuple with 0 fields.
- * <p>
- * {@code Tuple0} is a singleton.
+ * 
+ * <p>The Tuple0 is a soft singleton, i.e., there is a "singleton" instance, but it
does
+ * not prevent creation of additional instances.</p>
  * 
  * @see Tuple
  */
 public class Tuple0 extends Tuple {
 	private static final long serialVersionUID = 1L;
 
-	public static final Tuple0 instance = new Tuple0();
+	/** An immutable reusable Tuple0 instance */
+	public static final Tuple0 INSTANCE = new Tuple0();
 
+	// ------------------------------------------------------------------------
+	
 	@Override
 	public int getArity() {
 		return 0;
@@ -69,13 +73,7 @@ public class Tuple0 extends Tuple {
 	 */
 	@Override
 	public boolean equals(Object o) {
-		if (this == o) {
-			return true;
-		}
-		if (!(o instanceof Tuple0)) {
-			return false;
-		}
-		return true;
+		return this == o || o instanceof Tuple0;
 	}
 
 	@Override
@@ -85,7 +83,6 @@ public class Tuple0 extends Tuple {
 
 	// singleton deserialization
 	private Object readResolve() throws ObjectStreamException {
-		return instance;
+		return INSTANCE;
 	}
-
 }

http://git-wip-us.apache.org/repos/asf/flink/blob/c34af206/flink-java/src/main/java/org/apache/flink/api/java/tuple/builder/Tuple0Builder.java
----------------------------------------------------------------------
diff --git a/flink-java/src/main/java/org/apache/flink/api/java/tuple/builder/Tuple0Builder.java
b/flink-java/src/main/java/org/apache/flink/api/java/tuple/builder/Tuple0Builder.java
index 2a1546e..5facb7e 100644
--- a/flink-java/src/main/java/org/apache/flink/api/java/tuple/builder/Tuple0Builder.java
+++ b/flink-java/src/main/java/org/apache/flink/api/java/tuple/builder/Tuple0Builder.java
@@ -35,7 +35,7 @@ public class Tuple0Builder {
 	private List<Tuple0> tuples = new ArrayList<Tuple0>();
 
 	public Tuple0Builder add() {
-		tuples.add(Tuple0.instance);
+		tuples.add(Tuple0.INSTANCE);
 		return this;
 	}
 

http://git-wip-us.apache.org/repos/asf/flink/blob/c34af206/flink-java/src/main/java/org/apache/flink/api/java/typeutils/TupleTypeInfo.java
----------------------------------------------------------------------
diff --git a/flink-java/src/main/java/org/apache/flink/api/java/typeutils/TupleTypeInfo.java
b/flink-java/src/main/java/org/apache/flink/api/java/typeutils/TupleTypeInfo.java
index 0e59b8e..a671bd4 100644
--- a/flink-java/src/main/java/org/apache/flink/api/java/typeutils/TupleTypeInfo.java
+++ b/flink-java/src/main/java/org/apache/flink/api/java/typeutils/TupleTypeInfo.java
@@ -77,7 +77,7 @@ public final class TupleTypeInfo<T extends Tuple> extends TupleTypeInfoBase<T>
{
 	@Override
 	public TupleSerializer<T> createSerializer(ExecutionConfig executionConfig) {
 		if (this.tupleType == Tuple0.class) {
-			return (TupleSerializer<T>) Tuple0Serializer.getInstance();
+			return (TupleSerializer<T>) Tuple0Serializer.INSTANCE;
 		}
 
 		TypeSerializer<?>[] fieldSerializers = new TypeSerializer<?>[getArity()];

http://git-wip-us.apache.org/repos/asf/flink/blob/c34af206/flink-java/src/main/java/org/apache/flink/api/java/typeutils/runtime/Tuple0Serializer.java
----------------------------------------------------------------------
diff --git a/flink-java/src/main/java/org/apache/flink/api/java/typeutils/runtime/Tuple0Serializer.java
b/flink-java/src/main/java/org/apache/flink/api/java/typeutils/runtime/Tuple0Serializer.java
index e2d43e1..246cecf 100644
--- a/flink-java/src/main/java/org/apache/flink/api/java/typeutils/runtime/Tuple0Serializer.java
+++ b/flink-java/src/main/java/org/apache/flink/api/java/typeutils/runtime/Tuple0Serializer.java
@@ -19,17 +19,18 @@ import org.apache.flink.core.memory.DataInputView;
 import org.apache.flink.core.memory.DataOutputView;
 
 public class Tuple0Serializer extends TupleSerializer<Tuple0> {
+	
 	private static final long serialVersionUID = 1278813169022975971L;
 
-	private static final Tuple0Serializer singleton = new Tuple0Serializer();
+	public static final Tuple0Serializer INSTANCE = new Tuple0Serializer();
 
+	// ------------------------------------------------------------------------
+	
 	private Tuple0Serializer() {
 		super(Tuple0.class, new TypeSerializer<?>[0]);
 	}
 
-	public static Tuple0Serializer getInstance() {
-		return singleton;
-	}
+	// ------------------------------------------------------------------------
 
 	@Override
 	public Tuple0Serializer duplicate() {
@@ -38,13 +39,13 @@ public class Tuple0Serializer extends TupleSerializer<Tuple0> {
 
 	@Override
 	public Tuple0 createInstance() {
-		return Tuple0.instance;
+		return Tuple0.INSTANCE;
 	}
 
 	@Override
 	public Tuple0 createInstance(Object[] fields) {
 		if (fields == null || fields.length == 0) {
-			return Tuple0.instance;
+			return Tuple0.INSTANCE;
 		}
 
 		throw new UnsupportedOperationException(
@@ -53,7 +54,7 @@ public class Tuple0Serializer extends TupleSerializer<Tuple0> {
 
 	@Override
 	public Tuple0 copy(Tuple0 from) {
-		return Tuple0.instance;
+		return from;
 	}
 
 	@Override
@@ -74,7 +75,7 @@ public class Tuple0Serializer extends TupleSerializer<Tuple0> {
 	@Override
 	public Tuple0 deserialize(DataInputView source) throws IOException {
 		source.readByte();
-		return Tuple0.instance;
+		return Tuple0.INSTANCE;
 	}
 
 	@Override
@@ -88,4 +89,21 @@ public class Tuple0Serializer extends TupleSerializer<Tuple0> {
 		target.writeByte(source.readByte());
 	}
 
+	// ------------------------------------------------------------------------
+
+
+	@Override
+	public int hashCode() {
+		return 1837461876;
+	}
+
+	@Override
+	public boolean equals(Object obj) {
+		return obj == this || obj instanceof Tuple0Serializer;
+	}
+
+	@Override
+	public String toString() {
+		return "Tuple0Serializer";
+	}
 }

http://git-wip-us.apache.org/repos/asf/flink/blob/c34af206/flink-java/src/test/java/org/apache/flink/api/java/typeutils/runtime/TupleSerializerTest.java
----------------------------------------------------------------------
diff --git a/flink-java/src/test/java/org/apache/flink/api/java/typeutils/runtime/TupleSerializerTest.java
b/flink-java/src/test/java/org/apache/flink/api/java/typeutils/runtime/TupleSerializerTest.java
index beda8e9..017eb44 100644
--- a/flink-java/src/test/java/org/apache/flink/api/java/typeutils/runtime/TupleSerializerTest.java
+++ b/flink-java/src/test/java/org/apache/flink/api/java/typeutils/runtime/TupleSerializerTest.java
@@ -44,14 +44,14 @@ public class TupleSerializerTest {
 
 	@Test
 	public void testTuple0() {
-		Tuple0[] testTuples = new Tuple0[] { Tuple0.instance, Tuple0.instance, Tuple0.instance
};
+		Tuple0[] testTuples = new Tuple0[] { Tuple0.INSTANCE, Tuple0.INSTANCE, Tuple0.INSTANCE
};
 
 		runTests(testTuples);
 	}
 
 	@Test
 	public void testTuple1Int() {
-		@SuppressWarnings("unchecked")
+		@SuppressWarnings({"unchecked", "rawtypes"})
 		Tuple1<Integer>[] testTuples = new Tuple1[] {
 			new Tuple1<Integer>(42), new Tuple1<Integer>(1), new Tuple1<Integer>(0),
new Tuple1<Integer>(-1),
 			new Tuple1<Integer>(Integer.MAX_VALUE), new Tuple1<Integer>(Integer.MIN_VALUE)
@@ -64,7 +64,7 @@ public class TupleSerializerTest {
 	public void testTuple1String() {
 		Random rnd = new Random(68761564135413L);
 		
-		@SuppressWarnings("unchecked")
+		@SuppressWarnings({"unchecked", "rawtypes"})
 		Tuple1<String>[] testTuples = new Tuple1[] {
 			new Tuple1<String>(StringUtils.getRandomString(rnd, 10, 100)),
 			new Tuple1<String>("abc"),


Mime
View raw message