code: public static boolean overlaps(final Map.Entry<Double, Double> first,
                                     final Map.Entry<Double, Double> second) {
          return second.getValue() > first.getKey() && second.getKey() < first.getValue();
      }
docs: Method to check if two  segment overlaps.
  @param first first segment
  @param second second segment
  @return true if they overlap, false otherwise