This is an automated email from the ASF dual-hosted git repository.
jamesbognar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/juneau.git
The following commit(s) were added to refs/heads/master by this push:
new f77c8c512c Marshall module improvements
f77c8c512c is described below
commit f77c8c512c309f11bb9dd53fa82f088f22a97726
Author: James Bognar <[email protected]>
AuthorDate: Sat Dec 13 10:05:21 2025 -0500
Marshall module improvements
---
.../apache/juneau/commons/collections/Flag.java | 47 +++++++++++++++
.../juneau/commons/collections/Flag_Test.java | 68 ++++++++++++++++++++++
2 files changed, 115 insertions(+)
diff --git
a/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/collections/Flag.java
b/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/collections/Flag.java
index d4ffa00c24..52decbedc1 100644
---
a/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/collections/Flag.java
+++
b/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/collections/Flag.java
@@ -267,4 +267,51 @@ public class Flag {
value = false;
return this;
}
+
+ /**
+ * Returns a string representation of this flag.
+ *
+ * <p>
+ * The format is simply the string representation of the boolean value.
+ *
+ * @return A string representation of this flag.
+ */
+ @Override
+ public String toString() {
+ return String.valueOf(value);
+ }
+
+ /**
+ * Compares the specified object with this flag for equality.
+ *
+ * <p>
+ * Returns <jk>true</jk> if and only if the specified object is also a
<c>Flag</c> and both flags
+ * have the same boolean value.
+ *
+ * @param o The object to be compared for equality with this flag.
+ * @return <jk>true</jk> if the specified object is equal to this flag.
+ */
+ @Override
+ public boolean equals(Object o) {
+ return (o instanceof Flag o2) && eq(this, o2, (x, y) -> x.value
== y.value);
+ }
+
+ /**
+ * Returns the hash code value for this flag.
+ *
+ * <p>
+ * The hash code is computed from the boolean value using the standard
<c>Boolean.hashCode(boolean)</c>
+ * method, which returns <c>1231</c> for <c>true</c> and <c>1237</c>
for <c>false</c>.
+ *
+ * <p>
+ * This ensures that <c>flag1.equals(flag2)</c> implies that
<c>flag1.hashCode()==flag2.hashCode()</c>
+ * for any two flags <c>flag1</c> and <c>flag2</c>, as required by the
general contract of
+ * {@link Object#hashCode()}.
+ *
+ * @return The hash code value for this flag.
+ */
+ @Override
+ public int hashCode() {
+ return Boolean.hashCode(value);
+ }
}
\ No newline at end of file
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/commons/collections/Flag_Test.java
b/juneau-utest/src/test/java/org/apache/juneau/commons/collections/Flag_Test.java
index c02387c84a..82a6fdf144 100644
---
a/juneau-utest/src/test/java/org/apache/juneau/commons/collections/Flag_Test.java
+++
b/juneau-utest/src/test/java/org/apache/juneau/commons/collections/Flag_Test.java
@@ -239,4 +239,72 @@ class Flag_Test extends TestBase {
assertEquals(2, d);
}
+
+
//-----------------------------------------------------------------------------------------------------------------
+ // toString(), equals(), hashCode()
+
//-----------------------------------------------------------------------------------------------------------------
+
+ @Test
+ void d01_toString_true() {
+ var flag = Flag.of(true);
+ assertEquals("true", flag.toString());
+ }
+
+ @Test
+ void d02_toString_false() {
+ var flag = Flag.of(false);
+ assertEquals("false", flag.toString());
+ }
+
+ @Test
+ void d03_equals_sameValue() {
+ var flag1 = Flag.of(true);
+ var flag2 = Flag.of(true);
+ assertTrue(flag1.equals(flag2));
+ assertTrue(flag2.equals(flag1));
+ }
+
+ @Test
+ void d04_equals_differentValue() {
+ var flag1 = Flag.of(true);
+ var flag2 = Flag.of(false);
+ assertFalse(flag1.equals(flag2));
+ assertFalse(flag2.equals(flag1));
+ }
+
+ @Test
+ void d05_equals_sameInstance() {
+ var flag = Flag.of(true);
+ assertTrue(flag.equals(flag));
+ }
+
+ @Test
+ void d06_equals_notAFlag() {
+ var flag = Flag.of(true);
+ assertFalse(flag.equals("not a flag"));
+ assertFalse(flag.equals(null));
+ }
+
+ @Test
+ void d07_hashCode_sameValue() {
+ var flag1 = Flag.of(true);
+ var flag2 = Flag.of(true);
+ assertEquals(flag1.hashCode(), flag2.hashCode());
+ }
+
+ @Test
+ void d08_hashCode_differentValue() {
+ var flag1 = Flag.of(true);
+ var flag2 = Flag.of(false);
+ // Different values should have different hash codes (though
not guaranteed)
+ assertNotEquals(flag1.hashCode(), flag2.hashCode());
+ }
+
+ @Test
+ void d09_hashCode_booleanHashCode() {
+ var flagTrue = Flag.of(true);
+ var flagFalse = Flag.of(false);
+ assertEquals(Boolean.hashCode(true), flagTrue.hashCode());
+ assertEquals(Boolean.hashCode(false), flagFalse.hashCode());
+ }
}
\ No newline at end of file