You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2019/09/13 17:10:53 UTC
[commons-lang] branch master updated (3ea8244 -> aac260f)
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git.
from 3ea8244 More lambdas, less boilerplate.
new 26ed080 Sort members.
new a1395b6 One empty line between methods.
new aac260f Document interfaces with @FunctionalInterface.
The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../org/apache/commons/lang3/builder/Builder.java | 1 +
.../org/apache/commons/lang3/builder/Diffable.java | 1 +
.../apache/commons/lang3/reflect/TypeLiteral.java | 1 +
.../org/apache/commons/lang3/reflect/Typed.java | 5 +-
.../commons/lang3/builder/DiffBuilderTest.java | 187 ++++++++++-----------
5 files changed, 94 insertions(+), 101 deletions(-)
[commons-lang] 03/03: Document interfaces with @FunctionalInterface.
Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git
commit aac260f84c568e096cb4b24f9b35499cc56a6019
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Sep 13 11:47:47 2019 -0400
Document interfaces with @FunctionalInterface.
Javadoc.
---
src/main/java/org/apache/commons/lang3/builder/Builder.java | 1 +
src/main/java/org/apache/commons/lang3/builder/Diffable.java | 1 +
src/main/java/org/apache/commons/lang3/reflect/TypeLiteral.java | 1 +
src/main/java/org/apache/commons/lang3/reflect/Typed.java | 5 ++++-
4 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/src/main/java/org/apache/commons/lang3/builder/Builder.java b/src/main/java/org/apache/commons/lang3/builder/Builder.java
index 3e69afb..ad4edce 100644
--- a/src/main/java/org/apache/commons/lang3/builder/Builder.java
+++ b/src/main/java/org/apache/commons/lang3/builder/Builder.java
@@ -76,6 +76,7 @@ package org.apache.commons.lang3.builder;
*
* @since 3.0
*/
+@FunctionalInterface
public interface Builder<T> {
/**
diff --git a/src/main/java/org/apache/commons/lang3/builder/Diffable.java b/src/main/java/org/apache/commons/lang3/builder/Diffable.java
index 1cb7982..71ffe31 100644
--- a/src/main/java/org/apache/commons/lang3/builder/Diffable.java
+++ b/src/main/java/org/apache/commons/lang3/builder/Diffable.java
@@ -39,6 +39,7 @@ package org.apache.commons.lang3.builder;
* @param <T> the type of objects that this object may be differentiated against
* @since 3.3
*/
+@FunctionalInterface
public interface Diffable<T> {
/**
diff --git a/src/main/java/org/apache/commons/lang3/reflect/TypeLiteral.java b/src/main/java/org/apache/commons/lang3/reflect/TypeLiteral.java
index cef7ebd..e1e2898 100644
--- a/src/main/java/org/apache/commons/lang3/reflect/TypeLiteral.java
+++ b/src/main/java/org/apache/commons/lang3/reflect/TypeLiteral.java
@@ -69,6 +69,7 @@ import org.apache.commons.lang3.Validate;
* <T> T obtain(Typed<T> typed, ...);
* </pre>
*
+ * @param <T> the type
* @since 3.2
*/
public abstract class TypeLiteral<T> implements Typed<T> {
diff --git a/src/main/java/org/apache/commons/lang3/reflect/Typed.java b/src/main/java/org/apache/commons/lang3/reflect/Typed.java
index b21b51b..f8432d5 100644
--- a/src/main/java/org/apache/commons/lang3/reflect/Typed.java
+++ b/src/main/java/org/apache/commons/lang3/reflect/Typed.java
@@ -20,13 +20,16 @@ import java.lang.reflect.Type;
/**
* Generalization of "has a type."
+ *
+ * @param <T> the type
* @see TypeLiteral
* @since 3.2
*/
+@FunctionalInterface
public interface Typed<T> {
/**
- * Get the {@link Type} represented by this entity.
+ * Gets the {@link Type} represented by this entity.
*
* @return Type
*/
[commons-lang] 01/03: Sort members.
Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git
commit 26ed080b4689a2fd92221416ebeaf6734a962347
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Sep 13 11:39:08 2019 -0400
Sort members.
---
.../commons/lang3/builder/DiffBuilderTest.java | 185 ++++++++++-----------
1 file changed, 92 insertions(+), 93 deletions(-)
diff --git a/src/test/java/org/apache/commons/lang3/builder/DiffBuilderTest.java b/src/test/java/org/apache/commons/lang3/builder/DiffBuilderTest.java
index aebd3ee..a148443 100644
--- a/src/test/java/org/apache/commons/lang3/builder/DiffBuilderTest.java
+++ b/src/test/java/org/apache/commons/lang3/builder/DiffBuilderTest.java
@@ -35,8 +35,6 @@ import org.junit.jupiter.api.Test;
*/
public class DiffBuilderTest {
- private static final ToStringStyle SHORT_STYLE = ToStringStyle.SHORT_PREFIX_STYLE;
-
private static class TypeTestClass implements Diffable<TypeTestClass> {
private ToStringStyle style = SHORT_STYLE;
private boolean booleanField = true;
@@ -83,16 +81,18 @@ public class DiffBuilderTest {
}
@Override
- public int hashCode() {
- return HashCodeBuilder.reflectionHashCode(this, false);
+ public boolean equals(final Object obj) {
+ return EqualsBuilder.reflectionEquals(this, obj, false);
}
@Override
- public boolean equals(final Object obj) {
- return EqualsBuilder.reflectionEquals(this, obj, false);
+ public int hashCode() {
+ return HashCodeBuilder.reflectionHashCode(this, false);
}
}
+ private static final ToStringStyle SHORT_STYLE = ToStringStyle.SHORT_PREFIX_STYLE;
+
@Test
public void testBoolean() {
@@ -149,6 +149,24 @@ public class DiffBuilderTest {
}
@Test
+ public void testByteArrayEqualAsObject() {
+ final DiffResult<String> list = new DiffBuilder<>("String1", "String2", SHORT_STYLE)
+ .append("foo", new boolean[] {false}, new boolean[] {false})
+ .append("foo", new byte[] {0x01}, new byte[] {0x01})
+ .append("foo", new char[] {'a'}, new char[] {'a'})
+ .append("foo", new double[] {1.0}, new double[] {1.0})
+ .append("foo", new float[] {1.0F}, new float[] {1.0F})
+ .append("foo", new int[] {1}, new int[] {1})
+ .append("foo", new long[] {1L}, new long[] {1L})
+ .append("foo", new short[] {1}, new short[] {1})
+ .append("foo", new Object[] {1, "two"}, new Object[] {1, "two"})
+ .build();
+
+ assertEquals(0, list.getNumberOfDiffs());
+ }
+
+
+ @Test
public void testChar() {
final TypeTestClass class1 = new TypeTestClass();
final TypeTestClass class2 = new TypeTestClass();
@@ -177,6 +195,19 @@ public class DiffBuilderTest {
@Test
+ public void testDiffResult() {
+ final TypeTestClass class1 = new TypeTestClass();
+ final TypeTestClass class2 = new TypeTestClass();
+ class2.intField = 2;
+
+ final DiffResult<TypeTestClass> list = new DiffBuilder<>(class1, class2, SHORT_STYLE)
+ .append("prop1", class1.diff(class2))
+ .build();
+ assertEquals(1, list.getNumberOfDiffs());
+ assertEquals("prop1.int", list.getDiffs().get(0).getFieldName());
+ }
+
+ @Test
public void testDouble() {
final TypeTestClass class1 = new TypeTestClass();
final TypeTestClass class2 = new TypeTestClass();
@@ -203,6 +234,7 @@ public class DiffBuilderTest {
(Object[]) diff.getRight());
}
+
@Test
public void testFloat() {
final TypeTestClass class1 = new TypeTestClass();
@@ -230,7 +262,6 @@ public class DiffBuilderTest {
(Object[]) diff.getRight());
}
-
@Test
public void testInt() {
final TypeTestClass class1 = new TypeTestClass();
@@ -286,58 +317,46 @@ public class DiffBuilderTest {
}
@Test
- public void testShort() {
- final TypeTestClass class1 = new TypeTestClass();
- final TypeTestClass class2 = new TypeTestClass();
- class2.shortField = 42;
- final DiffResult<TypeTestClass> list = class1.diff(class2);
- assertEquals(1, list.getNumberOfDiffs());
- final Diff<?> diff = list.getDiffs().get(0);
- assertEquals(Short.valueOf(class1.shortField), diff.getLeft());
- assertEquals(Short.valueOf(class2.shortField), diff.getRight());
+ public void testNullLhs() {
+ assertThrows(IllegalArgumentException.class, () -> new DiffBuilder<>(null, this, ToStringStyle.DEFAULT_STYLE));
}
+ @Test
+ public void testNullRhs() {
+ assertThrows(IllegalArgumentException.class, () -> new DiffBuilder<>(this, null, ToStringStyle.DEFAULT_STYLE));
+ }
@Test
- public void testShortArray() {
+ public void testObject() {
final TypeTestClass class1 = new TypeTestClass();
final TypeTestClass class2 = new TypeTestClass();
- class2.shortArrayField = new short[] {3, 2, 1};
+ class2.objectField = "Some string";
final DiffResult<TypeTestClass> list = class1.diff(class2);
assertEquals(1, list.getNumberOfDiffs());
final Diff<?> diff = list.getDiffs().get(0);
- assertArrayEquals(ArrayUtils.toObject(class1.shortArrayField),
- (Object[]) diff.getLeft());
- assertArrayEquals(ArrayUtils.toObject(class2.shortArrayField),
- (Object[]) diff.getRight());
+ assertEquals(class1.objectField, diff.getLeft());
+ assertEquals(class2.objectField, diff.getRight());
}
@Test
- public void testObject() {
+ public void testObjectArray() {
final TypeTestClass class1 = new TypeTestClass();
final TypeTestClass class2 = new TypeTestClass();
- class2.objectField = "Some string";
+ class2.objectArrayField = new Object[] {"string", 1, 2};
final DiffResult<TypeTestClass> list = class1.diff(class2);
assertEquals(1, list.getNumberOfDiffs());
final Diff<?> diff = list.getDiffs().get(0);
- assertEquals(class1.objectField, diff.getLeft());
- assertEquals(class2.objectField, diff.getRight());
+ assertArrayEquals(class1.objectArrayField, (Object[]) diff.getLeft());
+ assertArrayEquals(class2.objectArrayField, (Object[]) diff.getRight());
}
- /**
- * Test that "left" and "right" are the same instance and are equal.
- */
@Test
- public void testObjectsSameAndEqual() {
- final Integer sameObject = 1;
- final TypeTestClass left = new TypeTestClass();
- left.objectField = sameObject;
- final TypeTestClass right = new TypeTestClass();
- right.objectField = sameObject;
- assertSame(left.objectField, right.objectField);
- assertEquals(left.objectField, right.objectField);
-
- final DiffResult<TypeTestClass> list = left.diff(right);
+ public void testObjectArrayEqual() {
+ final TypeTestClass class1 = new TypeTestClass();
+ final TypeTestClass class2 = new TypeTestClass();
+ class1.objectArrayField = new Object[] {"string", 1, 2};
+ class2.objectArrayField = new Object[] {"string", 1, 2};
+ final DiffResult<TypeTestClass> list = class1.diff(class2);
assertEquals(0, list.getNumberOfDiffs());
}
@@ -373,77 +392,57 @@ public class DiffBuilderTest {
assertEquals(1, list.getNumberOfDiffs());
}
+ /**
+ * Test that "left" and "right" are the same instance and are equal.
+ */
@Test
- public void testObjectArray() {
- final TypeTestClass class1 = new TypeTestClass();
- final TypeTestClass class2 = new TypeTestClass();
- class2.objectArrayField = new Object[] {"string", 1, 2};
- final DiffResult<TypeTestClass> list = class1.diff(class2);
- assertEquals(1, list.getNumberOfDiffs());
- final Diff<?> diff = list.getDiffs().get(0);
- assertArrayEquals(class1.objectArrayField, (Object[]) diff.getLeft());
- assertArrayEquals(class2.objectArrayField, (Object[]) diff.getRight());
- }
+ public void testObjectsSameAndEqual() {
+ final Integer sameObject = 1;
+ final TypeTestClass left = new TypeTestClass();
+ left.objectField = sameObject;
+ final TypeTestClass right = new TypeTestClass();
+ right.objectField = sameObject;
+ assertSame(left.objectField, right.objectField);
+ assertEquals(left.objectField, right.objectField);
- @Test
- public void testObjectArrayEqual() {
- final TypeTestClass class1 = new TypeTestClass();
- final TypeTestClass class2 = new TypeTestClass();
- class1.objectArrayField = new Object[] {"string", 1, 2};
- class2.objectArrayField = new Object[] {"string", 1, 2};
- final DiffResult<TypeTestClass> list = class1.diff(class2);
+ final DiffResult<TypeTestClass> list = left.diff(right);
assertEquals(0, list.getNumberOfDiffs());
}
-
@Test
- public void testByteArrayEqualAsObject() {
- final DiffResult<String> list = new DiffBuilder<>("String1", "String2", SHORT_STYLE)
- .append("foo", new boolean[] {false}, new boolean[] {false})
- .append("foo", new byte[] {0x01}, new byte[] {0x01})
- .append("foo", new char[] {'a'}, new char[] {'a'})
- .append("foo", new double[] {1.0}, new double[] {1.0})
- .append("foo", new float[] {1.0F}, new float[] {1.0F})
- .append("foo", new int[] {1}, new int[] {1})
- .append("foo", new long[] {1L}, new long[] {1L})
- .append("foo", new short[] {1}, new short[] {1})
- .append("foo", new Object[] {1, "two"}, new Object[] {1, "two"})
+ public void testSameObjectIgnoresAppends() {
+ final TypeTestClass testClass = new TypeTestClass();
+ final DiffResult<TypeTestClass> list = new DiffBuilder<>(testClass, testClass, SHORT_STYLE)
+ .append("ignored", false, true)
.build();
-
assertEquals(0, list.getNumberOfDiffs());
}
+
@Test
- public void testDiffResult() {
+ public void testShort() {
final TypeTestClass class1 = new TypeTestClass();
final TypeTestClass class2 = new TypeTestClass();
- class2.intField = 2;
-
- final DiffResult<TypeTestClass> list = new DiffBuilder<>(class1, class2, SHORT_STYLE)
- .append("prop1", class1.diff(class2))
- .build();
+ class2.shortField = 42;
+ final DiffResult<TypeTestClass> list = class1.diff(class2);
assertEquals(1, list.getNumberOfDiffs());
- assertEquals("prop1.int", list.getDiffs().get(0).getFieldName());
- }
-
- @Test
- public void testNullLhs() {
- assertThrows(IllegalArgumentException.class, () -> new DiffBuilder<>(null, this, ToStringStyle.DEFAULT_STYLE));
- }
-
-
- @Test
- public void testNullRhs() {
- assertThrows(IllegalArgumentException.class, () -> new DiffBuilder<>(this, null, ToStringStyle.DEFAULT_STYLE));
+ final Diff<?> diff = list.getDiffs().get(0);
+ assertEquals(Short.valueOf(class1.shortField), diff.getLeft());
+ assertEquals(Short.valueOf(class2.shortField), diff.getRight());
}
@Test
- public void testSameObjectIgnoresAppends() {
- final TypeTestClass testClass = new TypeTestClass();
- final DiffResult<TypeTestClass> list = new DiffBuilder<>(testClass, testClass, SHORT_STYLE)
- .append("ignored", false, true)
- .build();
- assertEquals(0, list.getNumberOfDiffs());
+ public void testShortArray() {
+ final TypeTestClass class1 = new TypeTestClass();
+ final TypeTestClass class2 = new TypeTestClass();
+ class2.shortArrayField = new short[] {3, 2, 1};
+ final DiffResult<TypeTestClass> list = class1.diff(class2);
+ assertEquals(1, list.getNumberOfDiffs());
+ final Diff<?> diff = list.getDiffs().get(0);
+ assertArrayEquals(ArrayUtils.toObject(class1.shortArrayField),
+ (Object[]) diff.getLeft());
+ assertArrayEquals(ArrayUtils.toObject(class2.shortArrayField),
+ (Object[]) diff.getRight());
}
@Test
[commons-lang] 02/03: One empty line between methods.
Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git
commit a1395b6823bde82282e851db1f403a1981a949d3
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Sep 13 11:40:24 2019 -0400
One empty line between methods.
---
.../org/apache/commons/lang3/builder/DiffBuilderTest.java | 12 ------------
1 file changed, 12 deletions(-)
diff --git a/src/test/java/org/apache/commons/lang3/builder/DiffBuilderTest.java b/src/test/java/org/apache/commons/lang3/builder/DiffBuilderTest.java
index a148443..263a50b 100644
--- a/src/test/java/org/apache/commons/lang3/builder/DiffBuilderTest.java
+++ b/src/test/java/org/apache/commons/lang3/builder/DiffBuilderTest.java
@@ -93,7 +93,6 @@ public class DiffBuilderTest {
private static final ToStringStyle SHORT_STYLE = ToStringStyle.SHORT_PREFIX_STYLE;
-
@Test
public void testBoolean() {
final TypeTestClass class1 = new TypeTestClass();
@@ -121,7 +120,6 @@ public class DiffBuilderTest {
(Object[]) diff.getRight());
}
-
@Test
public void testByte() {
final TypeTestClass class1 = new TypeTestClass();
@@ -165,7 +163,6 @@ public class DiffBuilderTest {
assertEquals(0, list.getNumberOfDiffs());
}
-
@Test
public void testChar() {
final TypeTestClass class1 = new TypeTestClass();
@@ -178,7 +175,6 @@ public class DiffBuilderTest {
assertEquals(Character.valueOf(class2.charField), diff.getRight());
}
-
@Test
public void testCharArray() {
final TypeTestClass class1 = new TypeTestClass();
@@ -193,7 +189,6 @@ public class DiffBuilderTest {
(Object[]) diff.getRight());
}
-
@Test
public void testDiffResult() {
final TypeTestClass class1 = new TypeTestClass();
@@ -219,7 +214,6 @@ public class DiffBuilderTest {
assertEquals(Double.valueOf(class2.doubleField), diff.getRight());
}
-
@Test
public void testDoubleArray() {
final TypeTestClass class1 = new TypeTestClass();
@@ -234,7 +228,6 @@ public class DiffBuilderTest {
(Object[]) diff.getRight());
}
-
@Test
public void testFloat() {
final TypeTestClass class1 = new TypeTestClass();
@@ -247,7 +240,6 @@ public class DiffBuilderTest {
assertEquals(Float.valueOf(class2.floatField), diff.getRight());
}
-
@Test
public void testFloatArray() {
final TypeTestClass class1 = new TypeTestClass();
@@ -274,7 +266,6 @@ public class DiffBuilderTest {
assertEquals(Integer.valueOf(class2.intField), diff.getRight());
}
-
@Test
public void testIntArray() {
final TypeTestClass class1 = new TypeTestClass();
@@ -301,7 +292,6 @@ public class DiffBuilderTest {
assertEquals(Long.valueOf(class2.longField), diff.getRight());
}
-
@Test
public void testLongArray() {
final TypeTestClass class1 = new TypeTestClass();
@@ -418,7 +408,6 @@ public class DiffBuilderTest {
assertEquals(0, list.getNumberOfDiffs());
}
-
@Test
public void testShort() {
final TypeTestClass class1 = new TypeTestClass();
@@ -455,7 +444,6 @@ public class DiffBuilderTest {
assertEquals(0, list.getNumberOfDiffs());
}
-
@Test
public void testStylePassedToDiffResult() {
final TypeTestClass class1 = new TypeTestClass();