Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.04 KB | None | 0 0
  1. interface PositionInterface
  2. {
  3. double getPosition(PageAreaInterface pArea);
  4. }
  5.  
  6. private double getMinPosition(Collection<PageAreaInterface> pAreas, PositionInterface pPosition)
  7. {
  8. double lMinPosition = Double.MAX_VALUE;
  9. for (PageAreaInterface lArea : pAreas)
  10. {
  11. lMinPosition = Math.min(lMinPosition, pPosition.getPosition(lArea));
  12. }
  13. return lMinPosition;
  14. }
  15.  
  16. private double getTop(Collection<PageAreaInterface> pAreas)
  17. {
  18. return getMinPosition(
  19. pAreas,
  20. new PositionInterface()
  21. {
  22. @Override
  23. public double getPosition(PageAreaInterface pArea)
  24. {
  25. return pArea.getBoundingBox().getTop();
  26. }
  27. }
  28. );
  29. }
  30.  
  31. private double getLeft(Collection<PageAreaInterface> pAreas)
  32. {
  33. return getMinPosition(
  34. pAreas,
  35. new PositionInterface()
  36. {
  37. @Override
  38. public double getPosition(PageAreaInterface pArea)
  39. {
  40. return pArea.getBoundingBox().getLeft();
  41. }
  42. }
  43. );
  44. }
  45.  
  46. private double getMaxPosition(Collection<PageAreaInterface> pAreas, PositionInterface pPosition)
  47. {
  48. double lMaxPosition = Double.MIN_VALUE;
  49. for (PageAreaInterface lArea : pAreas)
  50. {
  51. lMaxPosition = Math.max(lMaxPosition, pPosition.getPosition(lArea));
  52. }
  53. return lMaxPosition;
  54. }
  55.  
  56. private double getBottom(Collection<PageAreaInterface> pAreas)
  57. {
  58. return getMaxPosition(
  59. pAreas,
  60. new PositionInterface()
  61. {
  62. @Override
  63. public double getPosition(PageAreaInterface pArea)
  64. {
  65. return pArea.getBoundingBox().getBottom();
  66. }
  67. }
  68. );
  69. }
  70.  
  71. private double getRight(Collection<PageAreaInterface> pAreas)
  72. {
  73. return getMaxPosition(
  74. pAreas,
  75. new PositionInterface()
  76. {
  77. @Override
  78. public double getPosition(PageAreaInterface pArea)
  79. {
  80. return pArea.getBoundingBox().getRight();
  81. }
  82. }
  83. );
  84. }
  85.  
  86. min = PageAreaUtils.findMinimum(pageAreas, TOP); // Contrast with...
  87. min = pageAreas.findMinimum(TOP);
  88.  
  89. min = findMinimum(pageAreas, TOP); // Minimum pageAreas?! No...
  90. min = findMinimumTop(pageAreas); // Doesn't read right.
  91. min = findMinimumTopIn(pageAreas); // Better?
  92. min = findMinimum(TOP).in(pageAreas); // Better?
  93.  
  94. // In bounding box, collection, or standalone.
  95. public enum POSITION { TOP, LEFT, BOTTOM, RIGHT }
  96.  
  97. // In bounding box or collection.
  98. public double getPosition(POSITION pos) {
  99. switch (pos) {
  100. case TOP: return getTop();
  101. case LEFT: return getLeft();
  102. case BOTTOM: return getBottom();
  103. case RIGHT: return getRight();
  104. }
  105. throw new RuntimeException("Bad position provided: " + pos);
  106. }
  107.  
  108. Collection<PageArea> pageAreas;
  109.  
  110. public double getMinimumPosition(MyRect.POSITION pos) {
  111. double min = Double.MAX_VALUE;
  112. for (PageArea area : pageAreas) {
  113. min = Math.min(min, area.getBoundingBox().getPosition(pos));
  114. }
  115. return min;
  116. }
  117.  
  118. public double getMaximumPosition(MyRect.POSITION pos) {
  119. double max = Double.MIN_VALUE;
  120. for (PageArea area : pageAreas) {
  121. max = Math.min(max, area.getBoundingBox().getPosition(pos));
  122. }
  123. return max;
  124. }
  125.  
  126. area.getBoundingBox(pos) // or area.getBoundingBoxPosition(pos)?
  127.  
  128. public abstract class PareAreaComparator implements Comparator<PageAreaInterface> {
  129.  
  130. public PareAreaComparator() {
  131. }
  132.  
  133. @Override
  134. public int compare(final PageAreaInterface o1, final PageAreaInterface o2) {
  135. final BouningBox boundingBox1 = o1.getBoundingBox();
  136. final BouningBox boundingBox2 = o2.getBoundingBox();
  137. return compare(boundingBox1, boundingBox2);
  138. }
  139.  
  140. protected abstract int compare(BouningBox boundingBox1, BouningBox boundingBox2);
  141. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement