title: Interval intersection
body: <p>I wrote a class that checks whether two integer intevals overlap.
  However I don't like this solution to much. I think that it's possible to do it in a better and simpler way.</p>
  
  <pre><code>public class IntegerInterval implements Interval {
  private Integer start;
  private Integer end;
  
  public IntegerInterval(Integer start, Integer end) {
      this.start = start;
      this.end = end;
  }
  
  public Integer getStart() {
      return start;
  }
  
  public Integer getEnd() {
      return end;
  }
  
  public boolean isOverlapping(IntegerInterval other) {
      if (other != null) {
          return isInInterval(start, other) || isInInterval(end, other)
                  || isInInterval(other.start, this) || isInInterval(other.end, this);
      }
      return false;
  }
  
  public boolean isInInterval(Integer number, IntegerInterval interval) {
      if (number != null &amp;&amp; interval != null) {
          if(interval.getStart() == null &amp;&amp; interval.getEnd() != null) {
              return number.intValue() &lt;= interval.getEnd().intValue();
          }
          if(interval.getStart() != null &amp;&amp; interval.getEnd() == null) {
              return number.intValue() &gt;= interval.getStart().intValue();
          }
          if(interval.getStart() == null &amp;&amp; interval.getEnd() == null) {
              return true;
          }
          return interval.getStart() &lt;= number &amp;&amp; number &lt;= interval.getEnd();
      }
      else if(number == null &amp;&amp; interval != null) {
          return interval.getStart() == null &amp;&amp; interval.getEnd() == null;
      }
      return false;
  }
  </code></pre>
  
  <p>}</p>