code: public static boolean checkCollision(CmsPositionBean posA, CmsPositionBean posB, int margin) {
  
          // check for non collision is easier
          if ((posA.getLeft() - margin) >= (posB.getLeft() + posB.getWidth())) {
              // posA is right of posB
              return false;
          }
          if ((posA.getLeft() + posA.getWidth()) <= (posB.getLeft() - margin)) {
              // posA is left of posB
              return false;
          }
          if ((posA.getTop() - margin) >= (posB.getTop() + posB.getHeight())) {
              // posA is bellow posB
              return false;
          }
          if ((posA.getTop() + posA.getHeight()) <= (posB.getTop() - margin)) {
              // posA is above posB
              return false;
          }
  
          // in any other case the position rectangles collide
          return true;
      }
docs: Checks whether the two position rectangles collide.<p>
  
  @param posA the first position to check
  @param posB the second position to check
  @param margin the required margin
  
  @return <code>true</code> if the two position rectangles collide