コード例 #1
0
ファイル: VerseRange.java プロジェクト: saintfish/jsword
  /**
   * Create a VerseRange that is the stuff left of VerseRange a when you remove the stuff in
   * VerseRange b.
   *
   * @param a Verses at the start or end of b
   * @param b All the verses
   * @return A list of the Verses outstanding
   */
  public static VerseRange[] remainder(VerseRange a, VerseRange b) {
    VerseRange rstart = null;
    VerseRange rend = null;

    Versification v11n = a.getVersification();

    // If a starts before b get the Range of the prequel
    if (v11n.distance(a.getStart(), b.getStart()) > 0) {
      rstart = new VerseRange(v11n, a.getStart(), v11n.subtract(b.getEnd(), 1));
    }

    // If a ends after b get the Range of the sequel
    if (v11n.distance(a.getEnd(), b.getEnd()) < 0) {
      rend = new VerseRange(v11n, v11n.add(b.getEnd(), 1), a.getEnd());
    }

    if (rstart == null) {
      if (rend == null) {
        return new VerseRange[] {};
      }
      return new VerseRange[] {rend};
    }

    if (rend == null) {
      return new VerseRange[] {rstart};
    }
    return new VerseRange[] {rstart, rend};
  }
コード例 #2
0
ファイル: VerseRange.java プロジェクト: saintfish/jsword
 /**
  * Merge 2 VerseRanges together. The resulting range will encompass Everything in-between the
  * extremities of the 2 ranges.
  *
  * @param a The first verse range to be merged
  * @param b The second verse range to be merged
  */
 public VerseRange(VerseRange a, VerseRange b) {
   v11n = a.v11n;
   shaper = new NumberShaper();
   start = v11n.min(a.getStart(), b.getStart());
   end = v11n.max(a.getEnd(), b.getEnd());
   verseCount = calcVerseCount();
 }
コード例 #3
0
ファイル: VerseRange.java プロジェクト: saintfish/jsword
  /**
   * Create a VerseRange that is the stuff in VerseRange a that is also in VerseRange b.
   *
   * @param a The verses that you might want
   * @param b The verses that you definitely don't
   * @return A list of the Verses outstanding
   */
  public static VerseRange intersection(VerseRange a, VerseRange b) {
    Versification v11n = a.getVersification();
    Verse new_start = v11n.max(a.getStart(), b.getStart());
    Verse new_end = v11n.min(a.getEnd(), b.getEnd());

    if (v11n.distance(new_start, new_end) <= 0) {
      return new VerseRange(a.getVersification(), new_start, new_end);
    }

    return null;
  }
コード例 #4
0
ファイル: VerseRange.java プロジェクト: saintfish/jsword
  /**
   * Do the 2 VerseRanges in question actually overlap. This is slightly more restrictive than the
   * adjacentTo() test which could be satisfied by ranges like Gen 1:1-2 and Gen 1:3-4. overlaps()
   * however would return false given these ranges. For example Gen 1:1-2 is adjacent to Gen 1:1-5
   * but not to Gen 1:3-4 not to Gen 1:4-10. Also Gen 1:29-30 does not overlap Gen 2:1-10
   *
   * @param that The VerseRange to compare to
   * @return true if the ranges are adjacent
   */
  public boolean overlaps(VerseRange that) {
    int thatStart = that.getStart().getOrdinal();
    int thatEnd = that.getEnd().getOrdinal();
    int thisStart = getStart().getOrdinal();
    int thisEnd = getEnd().getOrdinal();

    // if that starts inside this we are adjacent.
    if (thatStart >= thisStart && thatStart <= thisEnd) {
      return true;
    }

    // if this starts inside that we are adjacent.
    if (thisStart >= thatStart && thisStart <= thatEnd) {
      return true;
    }

    // otherwise we're not adjacent
    return false;
  }
コード例 #5
0
ファイル: VerseRange.java プロジェクト: saintfish/jsword
 /**
  * Is the given range within our range. For example if this = "Gen 1:1-31" then:
  * <tt>this.contains(Verse("Gen 1:3-10")) == true</tt> <tt>this.contains(Verse("Gen 2:1-1")) ==
  * false</tt>
  *
  * @param that The Verse to compare to
  * @return true if we contain it.
  */
 public boolean contains(VerseRange that) {
   return v11n.distance(start, that.getStart()) >= 0 && v11n.distance(that.getEnd(), end) >= 0;
 }