Permutation { public String toCycleString() { int n = this.values.length; boolean[] p = new boolean[n]; Arrays.fill(p, true); StringBuilder sb = new StringBuilder(); int j = 0; for (int i = 0; i < n; i++) { if (p[i]) { sb.append('('); sb.append(i); p[i] = false; j = i; while (p[values[j]]) { sb.append(", "); j = values[j]; sb.append(j); p[j] = false; } sb.append(')'); } } return sb.toString(); } Permutation(int size);  Permutation(int... values);  Permutation(Permutation other); @Override boolean equals(Object other); @Override int hashCode(); boolean isIdentity(); int size(); int get(int index); int[] getValues(); int firstIndexOfDifference(Permutation other); List<Integer> getOrbit(int element); void set(int index, int value); void setTo(Permutation other); Permutation multiply(Permutation other); Permutation invert(); String toCycleString(); @Override String toString();  }
@Test public void toCycleStringTest() { int[] values = new int[]{0, 2, 1, 4, 5, 3, 7, 8, 9, 6}; String expected = "(0)(1, 2)(3, 4, 5)(6, 7, 8, 9)"; Permutation p = new Permutation(values); Assert.assertEquals(expected, p.toCycleString()); }