Skip to content

Commit 2e4ceab

Browse files
committed
Implement custom toArray function, some of our code reuses the underlying array and so the out-of-the box solution doesn't work as expected.
1 parent a339734 commit 2e4ceab

File tree

1 file changed

+9
-1
lines changed
  • base/isomorphism/src/main/java/org/openscience/cdk/isomorphism

1 file changed

+9
-1
lines changed

base/isomorphism/src/main/java/org/openscience/cdk/isomorphism/Mappings.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.openscience.cdk.interfaces.IChemObject;
3838
import org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer;
3939

40+
import java.util.Arrays;
4041
import java.util.Iterator;
4142
import java.util.Map;
4243

@@ -352,7 +353,14 @@ public Iterator<int[]> iterator() {
352353
* @return array of mappings
353354
*/
354355
public int[][] toArray() {
355-
return Iterables.toArray(iterable, int[].class);
356+
int[][] res = new int[14][];
357+
int size = 0;
358+
for (int[] map : this) {
359+
if (size == res.length)
360+
res = Arrays.copyOf(res, size + (size >> 1));
361+
res[size++] = map.clone();
362+
}
363+
return Arrays.copyOf(res, size);
356364
}
357365

358366
/**

0 commit comments

Comments
 (0)