Skip to content

Commit 7c84581

Browse files
committed
More nullity annotations and other fixes for Tuples.
1 parent 3978b34 commit 7c84581

File tree

11 files changed

+184
-144
lines changed

11 files changed

+184
-144
lines changed

src/main/java/org/organicdesign/fp/tuple/Tuple10.java

+16-13
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
package org.organicdesign.fp.tuple;
1616

17+
import org.jetbrains.annotations.NotNull;
18+
1719
import java.io.Serializable;
1820
import java.util.Objects;
1921

@@ -24,18 +26,19 @@
2426
// ======================================================================================
2527

2628
/**
27-
Holds 10 items of potentially different types. Designed to let you easily create immutable
28-
subclasses (to give your data structures meaningful names) with correct equals(), hashCode(), and
29-
toString() methods.
29+
* Holds 10 items of potentially different types. Designed to let you easily create immutable
30+
* subclasses (to give your data structures meaningful names) with correct equals(), hashCode(), and
31+
* toString() methods.
3032
*/
3133
public class Tuple10<A,B,C,D,E,F,G,H,I,J> implements Serializable {
3234

3335
// For serializable. Make sure to change whenever internal data format changes.
34-
// Implemented because implementing serializable only on a sub-class of an
36+
// Implemented because implementing serializable only on a subclass of an
3537
// immutable class requires a serialization proxy. That's probably worse than
36-
// the conceptual burdeon of all tuples being Serializable. private static final long serialVersionUID = 20160906065500L;
38+
// the conceptual burden of all tuples being Serializable.
39+
private static final long serialVersionUID = 20211228180200L;
3740

38-
// Fields are protected so that sub-classes can make accessor methods with meaningful names.
41+
// Fields are protected so that subclasses can make accessor methods with meaningful names.
3942
protected final A _1;
4043
protected final B _2;
4144
protected final C _3;
@@ -48,19 +51,19 @@ public class Tuple10<A,B,C,D,E,F,G,H,I,J> implements Serializable {
4851
protected final J _10;
4952

5053
/**
51-
Constructor is protected (not public) for easy inheritance. Josh Bloch's "Item 1" says public
52-
static factory methods are better than constructors because they have names, they can return
53-
an existing object instead of a new one, and they can return a sub-type. Therefore, you
54-
have more flexibility with a static factory as part of your public API then with a public
55-
constructor.
54+
* Constructor is protected (not public) for easy inheritance. Josh Bloch's "Item 1" says public
55+
* static factory methods are better than constructors because they have names, they can return
56+
* an existing object instead of a new one, and they can return a subtype. Therefore, you
57+
* have more flexibility with a static factory as part of your public API then with a public
58+
* constructor.
5659
*/
5760
protected Tuple10(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j) {
5861
_1 = a; _2 = b; _3 = c; _4 = d; _5 = e; _6 = f; _7 = g; _8 = h; _9 = i;
5962
_10 = j;
6063
}
6164

6265
/** Public static factory method */
63-
public static <A,B,C,D,E,F,G,H,I,J> Tuple10<A,B,C,D,E,F,G,H,I,J>
66+
public static <A,B,C,D,E,F,G,H,I,J> @NotNull Tuple10<A,B,C,D,E,F,G,H,I,J>
6467
of(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j) {
6568
return new Tuple10<>(a, b, c, d, e, f, g, h, i, j);
6669
}
@@ -87,7 +90,7 @@ protected Tuple10(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j) {
8790
public J _10() { return _10; }
8891

8992
@Override
90-
public String toString() {
93+
public @NotNull String toString() {
9194
return getClass().getSimpleName() + "(" +
9295
stringify(_1) + "," + stringify(_2) + "," +
9396
stringify(_3) + "," + stringify(_4) + "," + stringify(_5) + "," +

src/main/java/org/organicdesign/fp/tuple/Tuple11.java

+16-13
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
package org.organicdesign.fp.tuple;
1616

17+
import org.jetbrains.annotations.NotNull;
18+
1719
import java.io.Serializable;
1820
import java.util.Objects;
1921

@@ -24,18 +26,19 @@
2426
// ======================================================================================
2527

2628
/**
27-
Holds 11 items of potentially different types. Designed to let you easily create immutable
28-
subclasses (to give your data structures meaningful names) with correct equals(), hashCode(), and
29-
toString() methods.
29+
* Holds 11 items of potentially different types. Designed to let you easily create immutable
30+
* subclasses (to give your data structures meaningful names) with correct equals(), hashCode(), and
31+
* toString() methods.
3032
*/
3133
public class Tuple11<A,B,C,D,E,F,G,H,I,J,K> implements Serializable {
3234

3335
// For serializable. Make sure to change whenever internal data format changes.
34-
// Implemented because implementing serializable only on a sub-class of an
36+
// Implemented because implementing serializable only on a subclass of an
3537
// immutable class requires a serialization proxy. That's probably worse than
36-
// the conceptual burdeon of all tuples being Serializable. private static final long serialVersionUID = 20160906065500L;
38+
// the conceptual burden of all tuples being Serializable.
39+
private static final long serialVersionUID = 20211228180200L;
3740

38-
// Fields are protected so that sub-classes can make accessor methods with meaningful names.
41+
// Fields are protected so that subclasses can make accessor methods with meaningful names.
3942
protected final A _1;
4043
protected final B _2;
4144
protected final C _3;
@@ -49,19 +52,19 @@ public class Tuple11<A,B,C,D,E,F,G,H,I,J,K> implements Serializable {
4952
protected final K _11;
5053

5154
/**
52-
Constructor is protected (not public) for easy inheritance. Josh Bloch's "Item 1" says public
53-
static factory methods are better than constructors because they have names, they can return
54-
an existing object instead of a new one, and they can return a sub-type. Therefore, you
55-
have more flexibility with a static factory as part of your public API then with a public
56-
constructor.
55+
* Constructor is protected (not public) for easy inheritance. Josh Bloch's "Item 1" says public
56+
* static factory methods are better than constructors because they have names, they can return
57+
* an existing object instead of a new one, and they can return a subtype. Therefore, you
58+
* have more flexibility with a static factory as part of your public API then with a public
59+
* constructor.
5760
*/
5861
protected Tuple11(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k) {
5962
_1 = a; _2 = b; _3 = c; _4 = d; _5 = e; _6 = f; _7 = g; _8 = h; _9 = i;
6063
_10 = j; _11 = k;
6164
}
6265

6366
/** Public static factory method */
64-
public static <A,B,C,D,E,F,G,H,I,J,K> Tuple11<A,B,C,D,E,F,G,H,I,J,K>
67+
public static <A,B,C,D,E,F,G,H,I,J,K> @NotNull Tuple11<A,B,C,D,E,F,G,H,I,J,K>
6568
of(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k) {
6669
return new Tuple11<>(a, b, c, d, e, f, g, h, i, j, k);
6770
}
@@ -90,7 +93,7 @@ protected Tuple11(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k) {
9093
public K _11() { return _11; }
9194

9295
@Override
93-
public String toString() {
96+
public @NotNull String toString() {
9497
return getClass().getSimpleName() + "(" +
9598
stringify(_1) + "," + stringify(_2) + "," +
9699
stringify(_3) + "," + stringify(_4) + "," + stringify(_5) + "," +

src/main/java/org/organicdesign/fp/tuple/Tuple12.java

+16-13
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
package org.organicdesign.fp.tuple;
1616

17+
import org.jetbrains.annotations.NotNull;
18+
1719
import java.io.Serializable;
1820
import java.util.Objects;
1921

@@ -24,18 +26,19 @@
2426
// ======================================================================================
2527

2628
/**
27-
Holds 12 items of potentially different types. Designed to let you easily create immutable
28-
subclasses (to give your data structures meaningful names) with correct equals(), hashCode(), and
29-
toString() methods.
29+
* Holds 12 items of potentially different types. Designed to let you easily create immutable
30+
* subclasses (to give your data structures meaningful names) with correct equals(), hashCode(), and
31+
* toString() methods.
3032
*/
3133
public class Tuple12<A,B,C,D,E,F,G,H,I,J,K,L> implements Serializable {
3234

3335
// For serializable. Make sure to change whenever internal data format changes.
34-
// Implemented because implementing serializable only on a sub-class of an
36+
// Implemented because implementing serializable only on a subclass of an
3537
// immutable class requires a serialization proxy. That's probably worse than
36-
// the conceptual burdeon of all tuples being Serializable. private static final long serialVersionUID = 20160906065500L;
38+
// the conceptual burden of all tuples being Serializable.
39+
private static final long serialVersionUID = 20211228180200L;
3740

38-
// Fields are protected so that sub-classes can make accessor methods with meaningful names.
41+
// Fields are protected so that subclasses can make accessor methods with meaningful names.
3942
protected final A _1;
4043
protected final B _2;
4144
protected final C _3;
@@ -50,19 +53,19 @@ public class Tuple12<A,B,C,D,E,F,G,H,I,J,K,L> implements Serializable {
5053
protected final L _12;
5154

5255
/**
53-
Constructor is protected (not public) for easy inheritance. Josh Bloch's "Item 1" says public
54-
static factory methods are better than constructors because they have names, they can return
55-
an existing object instead of a new one, and they can return a sub-type. Therefore, you
56-
have more flexibility with a static factory as part of your public API then with a public
57-
constructor.
56+
* Constructor is protected (not public) for easy inheritance. Josh Bloch's "Item 1" says public
57+
* static factory methods are better than constructors because they have names, they can return
58+
* an existing object instead of a new one, and they can return a subtype. Therefore, you
59+
* have more flexibility with a static factory as part of your public API then with a public
60+
* constructor.
5861
*/
5962
protected Tuple12(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l) {
6063
_1 = a; _2 = b; _3 = c; _4 = d; _5 = e; _6 = f; _7 = g; _8 = h; _9 = i;
6164
_10 = j; _11 = k; _12 = l;
6265
}
6366

6467
/** Public static factory method */
65-
public static <A,B,C,D,E,F,G,H,I,J,K,L> Tuple12<A,B,C,D,E,F,G,H,I,J,K,L>
68+
public static <A,B,C,D,E,F,G,H,I,J,K,L> @NotNull Tuple12<A,B,C,D,E,F,G,H,I,J,K,L>
6669
of(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l) {
6770
return new Tuple12<>(a, b, c, d, e, f, g, h, i, j, k, l);
6871
}
@@ -93,7 +96,7 @@ protected Tuple12(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l) {
9396
public L _12() { return _12; }
9497

9598
@Override
96-
public String toString() {
99+
public @NotNull String toString() {
97100
return getClass().getSimpleName() + "(" +
98101
stringify(_1) + "," + stringify(_2) + "," +
99102
stringify(_3) + "," + stringify(_4) + "," + stringify(_5) + "," +

src/main/java/org/organicdesign/fp/tuple/Tuple3.java

+16-13
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
package org.organicdesign.fp.tuple;
1616

17+
import org.jetbrains.annotations.NotNull;
18+
1719
import java.io.Serializable;
1820
import java.util.Objects;
1921

@@ -24,35 +26,36 @@
2426
// ======================================================================================
2527

2628
/**
27-
Holds 3 items of potentially different types. Designed to let you easily create immutable
28-
subclasses (to give your data structures meaningful names) with correct equals(), hashCode(), and
29-
toString() methods.
29+
* Holds 3 items of potentially different types. Designed to let you easily create immutable
30+
* subclasses (to give your data structures meaningful names) with correct equals(), hashCode(), and
31+
* toString() methods.
3032
*/
3133
public class Tuple3<A,B,C> implements Serializable {
3234

3335
// For serializable. Make sure to change whenever internal data format changes.
34-
// Implemented because implementing serializable only on a sub-class of an
36+
// Implemented because implementing serializable only on a subclass of an
3537
// immutable class requires a serialization proxy. That's probably worse than
36-
// the conceptual burdeon of all tuples being Serializable. private static final long serialVersionUID = 20160906065500L;
38+
// the conceptual burden of all tuples being Serializable.
39+
private static final long serialVersionUID = 20211228180200L;
3740

38-
// Fields are protected so that sub-classes can make accessor methods with meaningful names.
41+
// Fields are protected so that subclasses can make accessor methods with meaningful names.
3942
protected final A _1;
4043
protected final B _2;
4144
protected final C _3;
4245

4346
/**
44-
Constructor is protected (not public) for easy inheritance. Josh Bloch's "Item 1" says public
45-
static factory methods are better than constructors because they have names, they can return
46-
an existing object instead of a new one, and they can return a sub-type. Therefore, you
47-
have more flexibility with a static factory as part of your public API then with a public
48-
constructor.
47+
* Constructor is protected (not public) for easy inheritance. Josh Bloch's "Item 1" says public
48+
* static factory methods are better than constructors because they have names, they can return
49+
* an existing object instead of a new one, and they can return a subtype. Therefore, you
50+
* have more flexibility with a static factory as part of your public API then with a public
51+
* constructor.
4952
*/
5053
protected Tuple3(A a, B b, C c) {
5154
_1 = a; _2 = b; _3 = c;
5255
}
5356

5457
/** Public static factory method */
55-
public static <A,B,C> Tuple3<A,B,C> of(A a, B b, C c) {
58+
public static <A,B,C> @NotNull Tuple3<A,B,C> of(A a, B b, C c) {
5659
return new Tuple3<>(a, b, c);
5760
}
5861

@@ -64,7 +67,7 @@ public static <A,B,C> Tuple3<A,B,C> of(A a, B b, C c) {
6467
public C _3() { return _3; }
6568

6669
@Override
67-
public String toString() {
70+
public @NotNull String toString() {
6871
return getClass().getSimpleName() + "(" +
6972
stringify(_1) + "," + stringify(_2) + "," +
7073
stringify(_3) + ")";

src/main/java/org/organicdesign/fp/tuple/Tuple4.java

+16-13
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
package org.organicdesign.fp.tuple;
1616

17+
import org.jetbrains.annotations.NotNull;
18+
1719
import java.io.Serializable;
1820
import java.util.Objects;
1921

@@ -24,36 +26,37 @@
2426
// ======================================================================================
2527

2628
/**
27-
Holds 4 items of potentially different types. Designed to let you easily create immutable
28-
subclasses (to give your data structures meaningful names) with correct equals(), hashCode(), and
29-
toString() methods.
29+
* Holds 4 items of potentially different types. Designed to let you easily create immutable
30+
* subclasses (to give your data structures meaningful names) with correct equals(), hashCode(), and
31+
* toString() methods.
3032
*/
3133
public class Tuple4<A,B,C,D> implements Serializable {
3234

3335
// For serializable. Make sure to change whenever internal data format changes.
34-
// Implemented because implementing serializable only on a sub-class of an
36+
// Implemented because implementing serializable only on a subclass of an
3537
// immutable class requires a serialization proxy. That's probably worse than
36-
// the conceptual burdeon of all tuples being Serializable. private static final long serialVersionUID = 20160906065500L;
38+
// the conceptual burden of all tuples being Serializable.
39+
private static final long serialVersionUID = 20211228180200L;
3740

38-
// Fields are protected so that sub-classes can make accessor methods with meaningful names.
41+
// Fields are protected so that subclasses can make accessor methods with meaningful names.
3942
protected final A _1;
4043
protected final B _2;
4144
protected final C _3;
4245
protected final D _4;
4346

4447
/**
45-
Constructor is protected (not public) for easy inheritance. Josh Bloch's "Item 1" says public
46-
static factory methods are better than constructors because they have names, they can return
47-
an existing object instead of a new one, and they can return a sub-type. Therefore, you
48-
have more flexibility with a static factory as part of your public API then with a public
49-
constructor.
48+
* Constructor is protected (not public) for easy inheritance. Josh Bloch's "Item 1" says public
49+
* static factory methods are better than constructors because they have names, they can return
50+
* an existing object instead of a new one, and they can return a subtype. Therefore, you
51+
* have more flexibility with a static factory as part of your public API then with a public
52+
* constructor.
5053
*/
5154
protected Tuple4(A a, B b, C c, D d) {
5255
_1 = a; _2 = b; _3 = c; _4 = d;
5356
}
5457

5558
/** Public static factory method */
56-
public static <A,B,C,D> Tuple4<A,B,C,D> of(A a, B b, C c, D d) {
59+
public static <A,B,C,D> @NotNull Tuple4<A,B,C,D> of(A a, B b, C c, D d) {
5760
return new Tuple4<>(a, b, c, d);
5861
}
5962

@@ -67,7 +70,7 @@ public static <A,B,C,D> Tuple4<A,B,C,D> of(A a, B b, C c, D d) {
6770
public D _4() { return _4; }
6871

6972
@Override
70-
public String toString() {
73+
public @NotNull String toString() {
7174
return getClass().getSimpleName() + "(" +
7275
stringify(_1) + "," + stringify(_2) + "," +
7376
stringify(_3) + "," + stringify(_4) + ")";

0 commit comments

Comments
 (0)