Skip to content

Commit 343a496

Browse files
committed
moved relabeler to internal package
1 parent 203f74e commit 343a496

File tree

6 files changed

+74
-42
lines changed

6 files changed

+74
-42
lines changed

src/main/java/org/cicirello/sequences/distance/KendallTauSequenceDistance.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* JavaPermutationTools: A Java library for computation on permutations and sequences
3-
* Copyright 2005-2023 Vincent A. Cicirello, <https://www.cicirello.org/>.
3+
* Copyright 2005-2025 Vincent A. Cicirello, <https://www.cicirello.org/>.
44
*
55
* This file is part of JavaPermutationTools (https://jpt.cicirello.org/).
66
*
@@ -23,6 +23,9 @@
2323

2424
import java.util.Arrays;
2525
import java.util.List;
26+
import org.cicirello.sequences.distance.internal.KendallTauRelabeler;
27+
import org.cicirello.sequences.distance.internal.RelabelByHashing;
28+
import org.cicirello.sequences.distance.internal.RelabelBySorting;
2629

2730
/**
2831
* Kendall Tau Sequence Distance is the minimum number of adjacent swaps necessary to transform one

src/main/java/org/cicirello/sequences/distance/KendallTauRelabeler.java renamed to src/main/java/org/cicirello/sequences/distance/internal/KendallTauRelabeler.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* JavaPermutationTools: A Java library for computation on permutations and sequences
3-
* Copyright 2005-2022 Vincent A. Cicirello, <https://www.cicirello.org/>.
3+
* Copyright 2005-2025 Vincent A. Cicirello, <https://www.cicirello.org/>.
44
*
55
* This file is part of JavaPermutationTools (https://jpt.cicirello.org/).
66
*
@@ -19,7 +19,7 @@
1919
* You should have received a copy of the GNU General Public License
2020
* along with JavaPermutationTools. If not, see <http://www.gnu.org/licenses/>.
2121
*/
22-
package org.cicirello.sequences.distance;
22+
package org.cicirello.sequences.distance.internal;
2323

2424
import java.util.List;
2525

@@ -30,7 +30,7 @@
3030
* @author <a href=https://www.cicirello.org/ target=_top>Vincent A. Cicirello</a>, <a
3131
* href=https://www.cicirello.org/ target=_top>https://www.cicirello.org/</a>
3232
*/
33-
interface KendallTauRelabeler {
33+
public interface KendallTauRelabeler {
3434

3535
/**
3636
* Relabels the elements of the sequence to integers from 0 to k where there are k+1 distinct

src/main/java/org/cicirello/sequences/distance/RelabelByHashing.java renamed to src/main/java/org/cicirello/sequences/distance/internal/RelabelByHashing.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* JavaPermutationTools: A Java library for computation on permutations and sequences
3-
* Copyright 2005-2022 Vincent A. Cicirello, <https://www.cicirello.org/>.
3+
* Copyright 2005-2025 Vincent A. Cicirello, <https://www.cicirello.org/>.
44
*
55
* This file is part of JavaPermutationTools (https://jpt.cicirello.org/).
66
*
@@ -19,7 +19,7 @@
1919
* You should have received a copy of the GNU General Public License
2020
* along with JavaPermutationTools. If not, see <http://www.gnu.org/licenses/>.
2121
*/
22-
package org.cicirello.sequences.distance;
22+
package org.cicirello.sequences.distance.internal;
2323

2424
import java.util.HashMap;
2525
import java.util.Iterator;
@@ -31,7 +31,7 @@
3131
* @author <a href=https://www.cicirello.org/ target=_top>Vincent A. Cicirello</a>, <a
3232
* href=https://www.cicirello.org/ target=_top>https://www.cicirello.org/</a>
3333
*/
34-
final class RelabelByHashing implements KendallTauRelabeler {
34+
public final class RelabelByHashing implements KendallTauRelabeler {
3535

3636
@Override
3737
public int relabel(Object[] s1, Object[] s2, int[][] relabeling) {

src/main/java/org/cicirello/sequences/distance/RelabelBySorting.java renamed to src/main/java/org/cicirello/sequences/distance/internal/RelabelBySorting.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* JavaPermutationTools: A Java library for computation on permutations and sequences
3-
* Copyright 2005-2023 Vincent A. Cicirello, <https://www.cicirello.org/>.
3+
* Copyright 2005-2025 Vincent A. Cicirello, <https://www.cicirello.org/>.
44
*
55
* This file is part of JavaPermutationTools (https://jpt.cicirello.org/).
66
*
@@ -19,7 +19,7 @@
1919
* You should have received a copy of the GNU General Public License
2020
* along with JavaPermutationTools. If not, see <http://www.gnu.org/licenses/>.
2121
*/
22-
package org.cicirello.sequences.distance;
22+
package org.cicirello.sequences.distance.internal;
2323

2424
import java.util.Arrays;
2525
import java.util.Iterator;
@@ -31,7 +31,7 @@
3131
* @author <a href=https://www.cicirello.org/ target=_top>Vincent A. Cicirello</a>, <a
3232
* href=https://www.cicirello.org/ target=_top>https://www.cicirello.org/</a>
3333
*/
34-
final class RelabelBySorting implements KendallTauRelabeler {
34+
public final class RelabelBySorting implements KendallTauRelabeler {
3535

3636
@Override
3737
public int relabel(int[] s1, int[] s2, int[][] relabeling) {

src/test/java/org/cicirello/sequences/distance/KendallTauSequenceDistanceTests.java

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018-2022 Vincent A. Cicirello, <https://www.cicirello.org/>.
2+
* Copyright 2018-2025 Vincent A. Cicirello, <https://www.cicirello.org/>.
33
*
44
* This file is part of JavaPermutationTools (https://jpt.cicirello.org/).
55
*
@@ -154,37 +154,6 @@ public void testKendallTauDistanceExceptions() {
154154
thrown = assertThrows(IllegalArgumentException.class, () -> d.distance(s1, s2));
155155
}
156156

157-
@Test
158-
public void testKendallTauSequenceDistance_HashTableBaseClass() {
159-
class TestHT extends RelabelByHashing.BaseHT {
160-
TestHT(int min) {
161-
super(32, min);
162-
}
163-
}
164-
for (int n = 1; n <= 32; n *= 2) {
165-
TestHT ht = new TestHT(n);
166-
assertEquals(n, ht.minSize);
167-
assertEquals(n - 1, ht.mask);
168-
}
169-
TestHT ht = new TestHT(3);
170-
assertEquals(4, ht.minSize);
171-
for (int n = 5; n < 8; n++) {
172-
ht = new TestHT(n);
173-
assertEquals(8, ht.minSize);
174-
assertEquals(7, ht.mask);
175-
}
176-
for (int n = 9; n < 16; n++) {
177-
ht = new TestHT(n);
178-
assertEquals(16, ht.minSize);
179-
assertEquals(15, ht.mask);
180-
}
181-
for (int n = 17; n <= 64; n++) {
182-
ht = new TestHT(n);
183-
assertEquals(32, ht.minSize);
184-
assertEquals(31, ht.mask);
185-
}
186-
}
187-
188157
@Test
189158
public void testKendallTauDistanceExceptionsDiffElements() {
190159
final KendallTauSequenceDistance d = new KendallTauSequenceDistance();
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright 2018-2025 Vincent A. Cicirello, <https://www.cicirello.org/>.
3+
*
4+
* This file is part of JavaPermutationTools (https://jpt.cicirello.org/).
5+
*
6+
* JavaPermutationTools is free software: you can
7+
* redistribute it and/or modify it under the terms of the GNU
8+
* General Public License as published by the Free Software
9+
* Foundation, either version 3 of the License, or (at your
10+
* option) any later version.
11+
*
12+
* JavaPermutationTools is distributed in the hope
13+
* that it will be useful, but WITHOUT ANY WARRANTY; without even
14+
* the implied warranty of MERCHANTABILITY or FITNESS FOR A
15+
* PARTICULAR PURPOSE. See the GNU General Public License for more
16+
* details.
17+
*
18+
* You should have received a copy of the GNU General Public License
19+
* along with JavaPermutationTools. If not, see <http://www.gnu.org/licenses/>.
20+
*/
21+
package org.cicirello.sequences.distance.internal;
22+
23+
import static org.junit.jupiter.api.Assertions.*;
24+
25+
import org.junit.jupiter.api.*;
26+
27+
/** JUnit tests for KendallTauSequenceDistance. */
28+
public class KendallTauSequenceDistanceInternalTests {
29+
30+
@Test
31+
public void testKendallTauSequenceDistance_HashTableBaseClass() {
32+
class TestHT extends RelabelByHashing.BaseHT {
33+
TestHT(int min) {
34+
super(32, min);
35+
}
36+
}
37+
for (int n = 1; n <= 32; n *= 2) {
38+
TestHT ht = new TestHT(n);
39+
assertEquals(n, ht.minSize);
40+
assertEquals(n - 1, ht.mask);
41+
}
42+
TestHT ht = new TestHT(3);
43+
assertEquals(4, ht.minSize);
44+
for (int n = 5; n < 8; n++) {
45+
ht = new TestHT(n);
46+
assertEquals(8, ht.minSize);
47+
assertEquals(7, ht.mask);
48+
}
49+
for (int n = 9; n < 16; n++) {
50+
ht = new TestHT(n);
51+
assertEquals(16, ht.minSize);
52+
assertEquals(15, ht.mask);
53+
}
54+
for (int n = 17; n <= 64; n++) {
55+
ht = new TestHT(n);
56+
assertEquals(32, ht.minSize);
57+
assertEquals(31, ht.mask);
58+
}
59+
}
60+
}

0 commit comments

Comments
 (0)