-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
150 additions
and
9 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
weasis-core-img/src/main/java/org/weasis/core/util/Pair.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, V>(K first, V second) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
weasis-core-img/src/main/java/org/weasis/core/util/Triple.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, V, T>(K first, V second, T third) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
weasis-core-img/src/test/java/org/weasis/core/util/PairTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String, Integer> pair = new Pair<>("first", 1); | ||
assertEquals("first", pair.first()); | ||
assertEquals(1, pair.second()); | ||
} | ||
|
||
@Test | ||
void pairHandlesMixedNullAndNonNullValues() { | ||
Pair<String, Integer> 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<Integer, String> pair = new Pair<>(1, "second"); | ||
assertEquals(1, pair.first()); | ||
assertEquals("second", pair.second()); | ||
} | ||
|
||
@Test | ||
void pairEquality() { | ||
Pair<String, Integer> pair1 = new Pair<>("first", 1); | ||
Pair<String, Integer> pair2 = new Pair<>("first", 1); | ||
assertEquals(pair1, pair2); | ||
} | ||
|
||
@Test | ||
void pairInequality() { | ||
Pair<String, Integer> pair1 = new Pair<>("first", 1); | ||
Pair<String, Integer> pair2 = new Pair<>("second", 1); | ||
assertNotEquals(pair1, pair2); | ||
|
||
pair2 = new Pair<>("first", 2); | ||
assertNotEquals(pair1, pair2); | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
weasis-core-img/src/test/java/org/weasis/core/util/TripleTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String, Integer, Double> triple = new Triple<>("first", 1, 2.0); | ||
assertEquals("first", triple.first()); | ||
assertEquals(1, triple.second()); | ||
assertEquals(2.0, triple.third()); | ||
} | ||
|
||
@Test | ||
void tripleHandlesMixedNullAndNonNullValues() { | ||
Triple<String, Integer, Double> 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<Integer, String, Boolean> triple = new Triple<>(1, "second", true); | ||
assertEquals(1, triple.first()); | ||
assertEquals("second", triple.second()); | ||
assertEquals(true, triple.third()); | ||
} | ||
|
||
@Test | ||
void tripleEquality() { | ||
Triple<String, Integer, Double> triple1 = new Triple<>("first", 1, 2.0); | ||
Triple<String, Integer, Double> triple2 = new Triple<>("first", 1, 2.0); | ||
assertEquals(triple1, triple2); | ||
} | ||
|
||
@Test | ||
void tripleInequality() { | ||
Triple<String, Integer, Double> triple1 = new Triple<>("first", 1, 2.0); | ||
Triple<String, Integer, Double> 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); | ||
} | ||
} |