class 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);
    }

}