diff --git a/weasis-core-img/src/main/java/org/weasis/core/util/Pair.java b/weasis-core-img/src/main/java/org/weasis/core/util/Pair.java new file mode 100644 index 0000000..203ef31 --- /dev/null +++ b/weasis-core-img/src/main/java/org/weasis/core/util/Pair.java @@ -0,0 +1,12 @@ +/* + * Copyright (c) 2024 Weasis Team and other contributors. + * + * This program and the accompanying materials are made available under the terms of the Eclipse + * Public License 2.0 which is available at https://www.eclipse.org/legal/epl-2.0, or the Apache + * License, Version 2.0 which is available at https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 + */ +package org.weasis.core.util; + +public record Pair(K first, V second) {} diff --git a/weasis-core-img/src/main/java/org/weasis/core/util/StringUtil.java b/weasis-core-img/src/main/java/org/weasis/core/util/StringUtil.java index 04b8db3..41d6cfc 100644 --- a/weasis-core-img/src/main/java/org/weasis/core/util/StringUtil.java +++ b/weasis-core-img/src/main/java/org/weasis/core/util/StringUtil.java @@ -157,10 +157,6 @@ public static boolean hasLength(CharSequence str) { return str != null && !str.isEmpty(); } - public static boolean hasLength(String str) { - return hasLength((CharSequence) str); - } - public static boolean hasText(CharSequence str) { if (!hasLength(str)) { return false; @@ -174,10 +170,6 @@ public static boolean hasText(CharSequence str) { return false; } - public static boolean hasText(String str) { - return hasText((CharSequence) str); - } - /** * Removing diacritical marks aka accents * diff --git a/weasis-core-img/src/main/java/org/weasis/core/util/Triple.java b/weasis-core-img/src/main/java/org/weasis/core/util/Triple.java new file mode 100644 index 0000000..e5258f3 --- /dev/null +++ b/weasis-core-img/src/main/java/org/weasis/core/util/Triple.java @@ -0,0 +1,12 @@ +/* + * Copyright (c) 2024 Weasis Team and other contributors. + * + * This program and the accompanying materials are made available under the terms of the Eclipse + * Public License 2.0 which is available at https://www.eclipse.org/legal/epl-2.0, or the Apache + * License, Version 2.0 which is available at https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 + */ +package org.weasis.core.util; + +public record Triple(K first, V second, T third) {} diff --git a/weasis-core-img/src/test/java/org/weasis/core/util/FileUtilTest.java b/weasis-core-img/src/test/java/org/weasis/core/util/FileUtilTest.java index 5126352..02aa45f 100644 --- a/weasis-core-img/src/test/java/org/weasis/core/util/FileUtilTest.java +++ b/weasis-core-img/src/test/java/org/weasis/core/util/FileUtilTest.java @@ -30,7 +30,6 @@ import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; -import java.util.Locale; import java.util.Properties; import javax.imageio.stream.ImageInputStream; import javax.imageio.stream.MemoryCacheImageInputStream; diff --git a/weasis-core-img/src/test/java/org/weasis/core/util/PairTest.java b/weasis-core-img/src/test/java/org/weasis/core/util/PairTest.java new file mode 100644 index 0000000..708ac2f --- /dev/null +++ b/weasis-core-img/src/test/java/org/weasis/core/util/PairTest.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2024 Weasis Team and other contributors. + * + * This program and the accompanying materials are made available under the terms of the Eclipse + * Public License 2.0 which is available at https://www.eclipse.org/legal/epl-2.0, or the Apache + * License, Version 2.0 which is available at https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 + */ +package org.weasis.core.util; + +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + +class PairTest { + @Test + void pairStoresFirstAndSecondValues() { + Pair pair = new Pair<>("first", 1); + assertEquals("first", pair.first()); + assertEquals(1, pair.second()); + } + + @Test + void pairHandlesMixedNullAndNonNullValues() { + Pair pair = new Pair<>("first", null); + assertEquals("first", pair.first()); + assertNull(pair.second()); + + pair = new Pair<>(null, 1); + assertNull(pair.first()); + assertEquals(1, pair.second()); + } + + @Test + void pairWithDifferentTypes() { + Pair pair = new Pair<>(1, "second"); + assertEquals(1, pair.first()); + assertEquals("second", pair.second()); + } + + @Test + void pairEquality() { + Pair pair1 = new Pair<>("first", 1); + Pair pair2 = new Pair<>("first", 1); + assertEquals(pair1, pair2); + } + + @Test + void pairInequality() { + Pair pair1 = new Pair<>("first", 1); + Pair pair2 = new Pair<>("second", 1); + assertNotEquals(pair1, pair2); + + pair2 = new Pair<>("first", 2); + assertNotEquals(pair1, pair2); + } +} diff --git a/weasis-core-img/src/test/java/org/weasis/core/util/TripleTest.java b/weasis-core-img/src/test/java/org/weasis/core/util/TripleTest.java new file mode 100644 index 0000000..6c48791 --- /dev/null +++ b/weasis-core-img/src/test/java/org/weasis/core/util/TripleTest.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2024 Weasis Team and other contributors. + * + * This program and the accompanying materials are made available under the terms of the Eclipse + * Public License 2.0 which is available at https://www.eclipse.org/legal/epl-2.0, or the Apache + * License, Version 2.0 which is available at https://www.apache.org/licenses/LICENSE-2.0. + * + * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 + */ +package org.weasis.core.util; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNull; + +import org.junit.jupiter.api.Test; + +class TripleTest { + + @Test + void tripleStoresFirstSecondAndThirdValues() { + Triple triple = new Triple<>("first", 1, 2.0); + assertEquals("first", triple.first()); + assertEquals(1, triple.second()); + assertEquals(2.0, triple.third()); + } + + @Test + void tripleHandlesMixedNullAndNonNullValues() { + Triple triple = new Triple<>("first", null, 2.0); + assertEquals("first", triple.first()); + assertNull(triple.second()); + assertEquals(2.0, triple.third()); + + triple = new Triple<>(null, 1, null); + assertNull(triple.first()); + assertEquals(1, triple.second()); + assertNull(triple.third()); + } + + @Test + void tripleWithDifferentTypes() { + Triple triple = new Triple<>(1, "second", true); + assertEquals(1, triple.first()); + assertEquals("second", triple.second()); + assertEquals(true, triple.third()); + } + + @Test + void tripleEquality() { + Triple triple1 = new Triple<>("first", 1, 2.0); + Triple triple2 = new Triple<>("first", 1, 2.0); + assertEquals(triple1, triple2); + } + + @Test + void tripleInequality() { + Triple triple1 = new Triple<>("first", 1, 2.0); + Triple triple2 = new Triple<>("second", 1, 2.0); + assertNotEquals(triple1, triple2); + + triple2 = new Triple<>("first", 2, 2.0); + assertNotEquals(triple1, triple2); + + triple2 = new Triple<>("first", 1, 3.0); + assertNotEquals(triple1, triple2); + } +}