Skip to content

Commit fee358b

Browse files
authored
Merge pull request #217 from cicirello/remove-deprecated
Removed Permutation.Mechanic nested class
2 parents 46e6a81 + d97ed60 commit fee358b

File tree

3 files changed

+1
-214
lines changed

3 files changed

+1
-214
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ details below.
1717
### Deprecated
1818

1919
### Removed
20+
* Permutation.Mechanic nested class previously deprecated in v3.2.0 (breaking change).
2021

2122
### Fixed
2223

src/main/java/org/cicirello/permutations/Permutation.java

Lines changed: 0 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -930,118 +930,4 @@ public boolean equals(Object other) {
930930
public int hashCode() {
931931
return Arrays.hashCode(permutation);
932932
}
933-
934-
/**
935-
* <p>The Permutation.Mechanic class provides a means of adding application-specific
936-
* operations on Permutations without the need to directly alter the Permutation
937-
* class. It is similar to a Visitor from the Visitor pattern.</p>
938-
*
939-
* <p>The methods of the Permutation.Mechanic class are unsafe, and if used incorrectly
940-
* can result in invalid Permutation state, and/or runtime exceptions. The methods of
941-
* this nested class do not perform any bounds checks. Additionally, they do not check
942-
* whether the usage produces a valid permutation.</p>
943-
*
944-
* <p>The Permutation.Mechanic class cannot be instantiated directly. To use, you must
945-
* define a subtype by extending the Permutation.Mechanic class. It is the responsibility
946-
* of the subclass to ensure that all of the methods of the subclass are safe. For example,
947-
* one of the set methods of the Permutation.Mechanic class enables setting a specific
948-
* index of a Permutation to any integer value. Individual calls to that method will
949-
* produce an invalid Permutation. It is the responsibility of any public method of the subclass to ensure
950-
* that a combination of calls to the set method is performed that results in a valid Permutation by the
951-
* time that subclass method returns.</p>
952-
*
953-
* <p>Here's the Mechanic analogy: Imagine that you take your car in for service. The mechanic
954-
* opens the hood, and starts disconnecting and removing stuff. During much of that time,
955-
* your car is inoperable. However, by the time you pick up your car, it has been put back
956-
* together properly, and is in functioning order. Perhaps it has new tires, or a new timing belt, etc,
957-
* so its state has changed.</p>
958-
*
959-
* <p>Consider a subclass, Subclass, of the Permutation.Mechanic. An object of Subclass is like a mechanic,
960-
* and the Permutation passed to its methods is the car. Each call to a public method of Subclass is like
961-
* a visit to the service station. Just like a mechanic can take your car apart during that service visit,
962-
* a public method of Subclass can similarly, temporarily, create a non-functioning Permutation. However,
963-
* that public method is expected to ensure that the Permutation is fully valid before returning.</p>
964-
*
965-
* @deprecated This class will be removed in the next major release, 4.0.0, and you should instead
966-
* use the functionality provided by the {@link Permutation#apply(PermutationUnaryOperator)} and
967-
* {@link Permutation#apply(PermutationBinaryOperator,Permutation)} methods, and the related
968-
* {@link PermutationUnaryOperator} and {@link PermutationBinaryOperator} interfaces.
969-
*
970-
* @author <a href=https://www.cicirello.org/ target=_top>Vincent A. Cicirello</a>,
971-
* <a href=https://www.cicirello.org/ target=_top>https://www.cicirello.org/</a>
972-
*/
973-
@Deprecated public static class Mechanic {
974-
975-
/**
976-
* The default constructor can only be called by subclasses.
977-
*/
978-
protected Mechanic() {}
979-
980-
/**
981-
* Changes the state of the Permutation according to the contents
982-
* of an array of int values. The caller of this method is responsible
983-
* to ensure that the array is the same length as the Permutation,
984-
* and that the elements are a valid permutation of the integers from the
985-
* set { 0, 1, ..., n-1 } where n is the length of the permutation.
986-
* The behavior of the Permutation object may become unstable otherwise.
987-
*
988-
* @param p Permutation object to change.
989-
* @param permutation An array of int values, assumed the be a valid permutation
990-
* of the integers from 0 to n-1.
991-
*/
992-
protected final void set(Permutation p, int[] permutation) {
993-
System.arraycopy(permutation, 0, p.permutation, 0, permutation.length);
994-
}
995-
996-
/**
997-
* Changes the integer in one specific location of a Permutation. Individual calls
998-
* to this method will, in most cases, produce an invalid Permutation. The caller
999-
* is responsible for making a combination of calls to this method that together produce
1000-
* a valid Permutation. The behavior of the Permutation object may become unstable otherwise.
1001-
* The caller should not return until the state of the Permutation object is again valid.
1002-
*
1003-
* @param p Permutation object to change.
1004-
* @param index The index of the position to change.
1005-
* @param value The value to change that position to.
1006-
*/
1007-
protected final void set(Permutation p, int index, int value) {
1008-
p.permutation[index] = value;
1009-
}
1010-
1011-
/**
1012-
* Changes a range of permutation elements. This method does not verify that the
1013-
* change produces a valid permutation. The caller is responsible for making a combination
1014-
* of calls to this method and/or the other methods of the Permutation.Mechanic class that
1015-
* together produce a valid Permutation.
1016-
* The behavior of the Permutation object may become unstable otherwise.
1017-
* The caller should not return until the state of the Permutation object is again valid.
1018-
*
1019-
* @param p Permutation object to change.
1020-
* @param index The index for the start of the new elements.
1021-
* @param subpermutation The new elements, which are copied into the permutation beginning
1022-
* at position index of the permutation.
1023-
*/
1024-
protected final void set(Permutation p, int index, int[] subpermutation) {
1025-
System.arraycopy(subpermutation, 0, p.permutation, index, subpermutation.length);
1026-
}
1027-
1028-
/**
1029-
* Changes a range of permutation elements. This method does not verify that the
1030-
* change produces a valid permutation. The caller is responsible for making a combination
1031-
* of calls to this method and/or the other methods of the Permutation.Mechanic class that
1032-
* together produce a valid Permutation.
1033-
* The behavior of the Permutation object may become unstable otherwise.
1034-
* The caller should not return until the state of the Permutation object is again valid.
1035-
*
1036-
* @param p Permutation object to change.
1037-
* @param source An array to copy elements from.
1038-
* @param fromIndex An index into source where copying begins, e.g., the first element
1039-
* copied is source[fromIndex].
1040-
* @param toIndex An index into the Permutation p, where the elements will be copied to.
1041-
* @param numElementsToSet The number of elements to copy from source to p.
1042-
*/
1043-
protected final void set(Permutation p, int[] source, int fromIndex, int toIndex, int numElementsToSet) {
1044-
System.arraycopy(source, fromIndex, p.permutation, toIndex, numElementsToSet);
1045-
}
1046-
}
1047933
}

src/test/java/org/cicirello/permutations/PermutationTestCases.java

Lines changed: 0 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -257,106 +257,6 @@ public void testPermutationSetFromArray() {
257257
);
258258
}
259259

260-
@Test @SuppressWarnings("deprecation") public void testPermutationMechanicSet() {
261-
262-
class MyMech extends Permutation.Mechanic {
263-
public void testSet(Permutation p, int[] a) {
264-
set(p, a);
265-
}
266-
public void testSet(Permutation p, int i, int v) {
267-
set(p, i, v);
268-
}
269-
public void testSet(Permutation p, int i, int[] a) {
270-
set(p, i, a);
271-
}
272-
public void testSet(Permutation p, int[] s, int from, int to, int numElements) {
273-
set(p, s, from, to, numElements);
274-
}
275-
}
276-
MyMech test = new MyMech();
277-
278-
int[][] arrays = { { 0 }, { 1, 0 }, { 1, 0, 2 }, { 3, 1, 2, 0 } };
279-
for (int[] a : arrays) {
280-
Permutation p = new Permutation(a.length, 0);
281-
test.testSet(p, a.clone());
282-
validatePermutation(p, a.length);
283-
for (int i = 0; i < a.length; i++) {
284-
assertEquals(a[i], p.get(i));
285-
}
286-
}
287-
for (int[] a : arrays) {
288-
Permutation p = new Permutation(a.length, 0);
289-
for (int i = 0; i < a.length; i++) {
290-
test.testSet(p, i, a[i]);
291-
}
292-
validatePermutation(p, a.length);
293-
for (int i = 0; i < a.length; i++) {
294-
assertEquals(a[i], p.get(i));
295-
}
296-
}
297-
for (int[] a : arrays) {
298-
Permutation p = new Permutation(a.length, 0);
299-
test.testSet(p, 0, a.clone());
300-
validatePermutation(p, a.length);
301-
for (int i = 0; i < a.length; i++) {
302-
assertEquals(a[i], p.get(i));
303-
}
304-
}
305-
for (int[] a : arrays) {
306-
Permutation p = new Permutation(a);
307-
int[] change = a.length > 2 ? new int[] {7, 5} : new int[] {7};
308-
int start = a.length > 1 ? 1 : 0;
309-
test.testSet(p, start, change);
310-
for (int i = 0; i < start; i++) {
311-
assertEquals(a[i], p.get(i));
312-
}
313-
for (int i = 0; i < change.length; i++) {
314-
assertEquals(change[i], p.get(start+i), "checking changed elements");
315-
}
316-
for (int i = start + change.length; i < a.length; i++) {
317-
assertEquals(a[i], p.get(i));
318-
}
319-
}
320-
for (int[] a : arrays) {
321-
Permutation p = new Permutation(a.length, 0);
322-
test.testSet(p, a.clone(), 0, 0, a.length);
323-
validatePermutation(p, a.length);
324-
for (int i = 0; i < a.length; i++) {
325-
assertEquals(a[i], p.get(i));
326-
}
327-
}
328-
for (int[] a : arrays) {
329-
Permutation p = new Permutation(a);
330-
int[] change = a.length > 2 ? new int[] {7, 5} : new int[] {7};
331-
int start = a.length > 1 ? 1 : 0;
332-
test.testSet(p, change, 0, start, change.length);
333-
for (int i = 0; i < start; i++) {
334-
assertEquals(a[i], p.get(i));
335-
}
336-
for (int i = 0; i < change.length; i++) {
337-
assertEquals(change[i], p.get(start+i), "checking changed elements");
338-
}
339-
for (int i = start + change.length; i < a.length; i++) {
340-
assertEquals(a[i], p.get(i));
341-
}
342-
}
343-
for (int[] a : arrays) {
344-
Permutation p = new Permutation(a);
345-
int[] change = a.length > 2 ? new int[] {9, 9, 7, 5, 9, 9} : new int[] {9, 9, 7, 9, 9};
346-
int start = a.length > 1 ? 1 : 0;
347-
test.testSet(p, change, 2, start, change.length - 4);
348-
for (int i = 0; i < start; i++) {
349-
assertEquals(a[i], p.get(i));
350-
}
351-
for (int i = 2; i < change.length-2; i++) {
352-
assertEquals(change[i], p.get(start+i-2), "checking changed elements");
353-
}
354-
for (int i = start + change.length - 4; i < a.length; i++) {
355-
assertEquals(a[i], p.get(i));
356-
}
357-
}
358-
}
359-
360260
@Test
361261
public void testPermutationCopyConstructor() {
362262
for (int n = 1; n <= 10; n++) {

0 commit comments

Comments
 (0)