IdentityTemplateLibrary { static Point2d[] decodeCoordinates(String str) { if (str.startsWith("|(")) { int end = str.indexOf(')', 2); if (end < 0) return new Point2d[0]; String[] strs = str.substring(2, end).split(";"); Point2d[] points = new Point2d[strs.length]; for (int i = 0; i < strs.length; i++) { String coord = strs[i]; int first = coord.indexOf(','); int second = coord.indexOf(',', first+1); points[i] = new Point2d(Double.parseDouble(coord.substring(0, first)), Double.parseDouble(coord.substring(first + 1, second))); } return points; } else { String[] strs = str.split(", "); Point2d[] points = new Point2d[strs.length / 2]; for (int i = 0; i < strs.length; i += 2) { points[i / 2] = new Point2d(Double.parseDouble(strs[i]), Double.parseDouble(strs[i + 1])); } return points; } } private  IdentityTemplateLibrary(); IdentityTemplateLibrary add(IdentityTemplateLibrary library);  }
@Test public void decodeCoordinates() throws Exception { Point2d[] points = IdentityTemplateLibrary.decodeCoordinates("12.5, 5.5, 4, 2"); assertThat(points.length, is(2)); assertThat(points[0].x, closeTo(12.5, 0.01)); assertThat(points[0].y, closeTo(5.5, 0.01)); assertThat(points[1].x, closeTo(4, 0.01)); assertThat(points[1].y, closeTo(2, 0.01)); }