/*
 * Copyright 2014 Google Inc. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.google.devtools.kythe.util;

/** Structure representing some arbitrary offset span. */
public class Span implements Comparable<Span> {
  private final int start, end;

  public Span(int startOffset, int endOffset) {
    this.start = startOffset;
    this.end = endOffset;
  }

  public int getStart() {
    return start;
  }

  public int getEnd() {
    return end;
  }

  public boolean valid() {
    return start <= end && start >= 0;
  }

  /** Determines if the given integer is contained within {@code this} {@link Span}. */
  public boolean contains(int n) {
    return getStart() <= n && n < getEnd();
  }

  @Override
  public int compareTo(Span other) {
    if (other.start == this.start) {
      return this.end - other.end;
    }
    return this.start - other.start;
  }

  @Override
  public String toString() {
    return String.format("Span{%d, %d}", start, end);
  }
}

@@ -649,16 +649,43 @@
 .util;%0A%0A
+import java.util.Objects;%0A%0A
 /** Stru
@@ -741,16 +741,22 @@
 %0Apublic 
+final 
 class Sp
@@ -809,25 +809,45 @@
 al int start
-,
+;%0A  private final int
  end;%0A%0A  pub
@@ -1554,11 +1554,344 @@
 nd);%0A  %7D
+%0A%0A  @Override%0A  public boolean equals(Object o) %7B%0A    if (this == o) %7B%0A      return true;%0A    %7D%0A    if (o == null %7C%7C getClass() != o.getClass()) %7B%0A      return false;%0A    %7D%0A    Span span = (Span) o;%0A    return start == span.start && end == span.end;%0A  %7D%0A%0A  @Override%0A  public int hashCode() %7B%0A    return Objects.hash(start, end);%0A  %7D
 %0A%7D%0A

Add hashcode and equals so Span could be used in hash sets and maps.