Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- interface PositionInterface
- {
- double getPosition(PageAreaInterface pArea);
- }
- private double getMinPosition(Collection<PageAreaInterface> pAreas, PositionInterface pPosition)
- {
- double lMinPosition = Double.MAX_VALUE;
- for (PageAreaInterface lArea : pAreas)
- {
- lMinPosition = Math.min(lMinPosition, pPosition.getPosition(lArea));
- }
- return lMinPosition;
- }
- private double getTop(Collection<PageAreaInterface> pAreas)
- {
- return getMinPosition(
- pAreas,
- new PositionInterface()
- {
- @Override
- public double getPosition(PageAreaInterface pArea)
- {
- return pArea.getBoundingBox().getTop();
- }
- }
- );
- }
- private double getLeft(Collection<PageAreaInterface> pAreas)
- {
- return getMinPosition(
- pAreas,
- new PositionInterface()
- {
- @Override
- public double getPosition(PageAreaInterface pArea)
- {
- return pArea.getBoundingBox().getLeft();
- }
- }
- );
- }
- private double getMaxPosition(Collection<PageAreaInterface> pAreas, PositionInterface pPosition)
- {
- double lMaxPosition = Double.MIN_VALUE;
- for (PageAreaInterface lArea : pAreas)
- {
- lMaxPosition = Math.max(lMaxPosition, pPosition.getPosition(lArea));
- }
- return lMaxPosition;
- }
- private double getBottom(Collection<PageAreaInterface> pAreas)
- {
- return getMaxPosition(
- pAreas,
- new PositionInterface()
- {
- @Override
- public double getPosition(PageAreaInterface pArea)
- {
- return pArea.getBoundingBox().getBottom();
- }
- }
- );
- }
- private double getRight(Collection<PageAreaInterface> pAreas)
- {
- return getMaxPosition(
- pAreas,
- new PositionInterface()
- {
- @Override
- public double getPosition(PageAreaInterface pArea)
- {
- return pArea.getBoundingBox().getRight();
- }
- }
- );
- }
- min = PageAreaUtils.findMinimum(pageAreas, TOP); // Contrast with...
- min = pageAreas.findMinimum(TOP);
- min = findMinimum(pageAreas, TOP); // Minimum pageAreas?! No...
- min = findMinimumTop(pageAreas); // Doesn't read right.
- min = findMinimumTopIn(pageAreas); // Better?
- min = findMinimum(TOP).in(pageAreas); // Better?
- // In bounding box, collection, or standalone.
- public enum POSITION { TOP, LEFT, BOTTOM, RIGHT }
- // In bounding box or collection.
- public double getPosition(POSITION pos) {
- switch (pos) {
- case TOP: return getTop();
- case LEFT: return getLeft();
- case BOTTOM: return getBottom();
- case RIGHT: return getRight();
- }
- throw new RuntimeException("Bad position provided: " + pos);
- }
- Collection<PageArea> pageAreas;
- public double getMinimumPosition(MyRect.POSITION pos) {
- double min = Double.MAX_VALUE;
- for (PageArea area : pageAreas) {
- min = Math.min(min, area.getBoundingBox().getPosition(pos));
- }
- return min;
- }
- public double getMaximumPosition(MyRect.POSITION pos) {
- double max = Double.MIN_VALUE;
- for (PageArea area : pageAreas) {
- max = Math.min(max, area.getBoundingBox().getPosition(pos));
- }
- return max;
- }
- area.getBoundingBox(pos) // or area.getBoundingBoxPosition(pos)?
- public abstract class PareAreaComparator implements Comparator<PageAreaInterface> {
- public PareAreaComparator() {
- }
- @Override
- public int compare(final PageAreaInterface o1, final PageAreaInterface o2) {
- final BouningBox boundingBox1 = o1.getBoundingBox();
- final BouningBox boundingBox2 = o2.getBoundingBox();
- return compare(boundingBox1, boundingBox2);
- }
- protected abstract int compare(BouningBox boundingBox1, BouningBox boundingBox2);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement