ProductTransformation { static Rectangle parseSubset(String input, Rectangle productRectangle) { Pattern p = Pattern.compile("subset\\s+([\\d\\.]+)\\s*,\\s*([\\d\\.]+)\\s*,\\s*([\\d\\.]+)\\s*,\\s*([\\d\\.]+).*"); Matcher m = p.matcher(input); if (m.matches()) { String xString = m.group(1); String yString = m.group(2); String wString = m.group(3); String hString = m.group(4); int x = Double.valueOf(xString).intValue(); int y = Double.valueOf(yString).intValue(); int w = Double.valueOf(wString).intValue(); int h = Double.valueOf(hString).intValue(); return new Rectangle(x, y, w, h); } return productRectangle; } ProductTransformation(Rectangle subsetRectangle, boolean flipX, boolean flipY); static ProductTransformation parse(String productTransformationString, Rectangle productRectangle); AffineTransform getTransform();  }
@Test public void testParseSubset() throws Exception { Rectangle productRectangle = new Rectangle(30, 40); Rectangle subsetRect = ProductTransformation.parseSubset("subset 2.0,3,4.0,5 flipX flipY", productRectangle); assertEquals(new Rectangle(2, 3, 4, 5), subsetRect); subsetRect = ProductTransformation.parseSubset("subset 21, 32 , 46 , 567", productRectangle); assertEquals(new Rectangle(21, 32, 46, 567), subsetRect); subsetRect = ProductTransformation.parseSubset("subset 21, 32 ", productRectangle); assertEquals(productRectangle, subsetRect); }