ImageSizeHandler { public static ImageSize createTargetImageSize(ImageSize[] imageSizes) { String identifier = ""; int startOffset = Integer.MAX_VALUE; int trackOffset = Integer.MAX_VALUE; int highestStart = Integer.MIN_VALUE; int highestTrack = Integer.MIN_VALUE; for (ImageSize imageSize : imageSizes) { if (imageSize == null) { continue; } if (imageSize.getStartOffset() < startOffset) { startOffset = imageSize.getStartOffset(); } if (imageSize.getTrackOffset() < trackOffset) { trackOffset = imageSize.getTrackOffset(); } if (imageSize.getStartOffset() + imageSize.getRows() > highestStart) { highestStart = imageSize.getStartOffset() + imageSize.getRows(); } if (imageSize.getTrackOffset() + imageSize.getColumns() > highestTrack) { highestTrack = imageSize.getTrackOffset() + imageSize.getColumns(); } identifier = imageSize.getIdentifier(); } return new ImageSize(identifier, startOffset, trackOffset, highestStart - startOffset, highestTrack - trackOffset); }  static ImageSize createTargetImageSize(ImageSize[] imageSizes); static ImageSize[] extractImageSizes(Document manifestDocument); static ImageSize extractImageSizeFromNode(Node element, String idExtension);  }
@Test public void testCreateTargetImageSize() { ImageSize[] imageSizes = new ImageSize[]{ new ImageSize("in", 21687, 998, 2000, 1500), new ImageSize("in", 23687, 445, 2000, 1500), new ImageSize("in", 25687, 1443, 2000, 1500)}; final ImageSize targetImageSize = ImageSizeHandler.createTargetImageSize(imageSizes); Assert.assertNotNull(targetImageSize); assertEquals("in", targetImageSize.getIdentifier()); assertEquals(21687, targetImageSize.getStartOffset()); assertEquals(445, targetImageSize.getTrackOffset()); assertEquals(6000, targetImageSize.getRows()); assertEquals(2498, targetImageSize.getColumns()); }