Graph { public Graph permute(int[] p) { if (p.length != order) throw new IllegalArgumentException("permuation size should equal |V| (order)"); Graph cpy = new Graph(order); cpy.flags = flags; cpy.order = order; cpy.size = size; for (int u = 0; u < order; u++) { int d = degrees[u]; final int v = p[u]; if (d > 4) cpy.edges[v] = new Edge[d]; cpy.atoms[v] = atoms[u]; cpy.valences[v] = valences[u]; cpy.addTopology(topologyOf(u).transform(p)); while (--d >= 0) { final Edge e = edgeAt(u, d); if (u > e.other(u)) { final int w = p[e.other(u)]; final Edge f = new Edge(v, w, e.bond(u)); cpy.edges[v][cpy.degrees[v]++] = f; cpy.edges[w][cpy.degrees[w]++] = f; cpy.size++; } } } return cpy.sort(new CanOrderFirst()); } Graph(int expSize);   Graph(Graph org); Atom atom(int i); int degree(int u); List<Edge> edges(int u); int[] neighbors(int u); boolean adjacent(int u, int v); int implHCount(int u); Edge edge(int u, int v); Edge edgeAt(int u, int j); Topology topologyOf(int u); Configuration configurationOf(int u); int order(); int size(); static Graph fromSmiles(String smi); static Graph parse(String smi, boolean strict, Set<String> warnings); String toSmiles(); String toSmiles(int[] visitedAt); Graph aromatic(); Graph resonate(); Graph kekule(); boolean assignable(); Graph permute(int[] p); Iterable<Atom> atoms(); Iterable<Edge> edges(); int getFlags(final int mask); int getFlags(); void setTitle(String title); String getTitle(); Graph sort(EdgeComparator comparator); static final int HAS_AROM; static final int HAS_ATM_STRO; static final int HAS_EXT_STRO; static final int HAS_BND_STRO; static final int HAS_STRO; }
@Test public void permute() { Graph g = new Graph(2); g.addAtom(mock(Atom.class)); g.addAtom(mock(Atom.class)); g.addAtom(mock(Atom.class)); g.addAtom(mock(Atom.class)); g.addEdge(new Edge(0, 1, Bond.IMPLICIT)); g.addEdge(new Edge(1, 2, Bond.IMPLICIT)); g.addEdge(new Edge(2, 3, Bond.IMPLICIT)); assertThat(g.degree(0), is(1)); assertThat(g.degree(1), is(2)); assertThat(g.degree(2), is(2)); assertThat(g.degree(3), is(1)); Graph h = g.permute(new int[]{1, 0, 3, 2}); assertThat(h.degree(0), is(2)); assertThat(h.degree(1), is(1)); assertThat(h.degree(2), is(1)); assertThat(h.degree(3), is(2)); assertThat(g.atom(0), is(h.atom(1))); assertThat(g.atom(1), is(h.atom(0))); assertThat(g.atom(2), is(h.atom(3))); assertThat(g.atom(3), is(h.atom(2))); }