예제 #1
0
  @Override
  public boolean equals(Object obj) {
    // Since this can not be null
    if (obj == null) {
      return false;
    }

    // Check that that is the same as this
    // Don't use instanceOf since that breaks inheritance
    if (!obj.getClass().equals(this.getClass())) {
      return false;
    }

    VerseRange vr = (VerseRange) obj;

    // The real tests
    if (!vr.getStart().equals(getStart())) {
      return false;
    }

    if (vr.getCardinality() != getCardinality()) {
      return false;
    }

    // We don't really need to check this one too.
    // if (!vr.getEnd().equals(getEnd())) return false;

    return true;
  }
예제 #2
0
 /**
  * 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
  /**
   * 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};
  }
예제 #4
0
  /**
   * 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;
  }
  /**
   * Customize something to display the Passage component
   *
   * @return The customized component
   */
  public Component getListCellRendererComponent(
      JList list, Object value, int index, boolean selected, boolean focus) {
    if (selected) {
      label.setBackground(list.getSelectionBackground());
      label.setForeground(list.getSelectionForeground());
    } else {
      label.setBackground(list.getBackground());
      label.setForeground(list.getForeground());
    }

    if (value instanceof VerseRange) {
      try {
        VerseRange range = (VerseRange) value;
        String text = (String) hash.get(range);

        if (text == null) {
          BookData bdata = new BookData(bible, range);
          String simple = OSISUtil.getCanonicalText(bdata.getOsisFragment());
          text = "<html><b>" + range.getName() + "</b> " + simple;
          hash.put(range, text);
        }

        label.setText(text);
      } catch (Exception ex) {
        Reporter.informUser(this, ex);
        // TRANSLATOR: Unexpected error condition.
        label.setText(Msg.gettext("Error"));
      }
    } else {
      label.setText((value == null) ? "" : value.toString());
    }

    label.setEnabled(list.isEnabled());
    label.setFont(list.getFont());
    label.setBorder(focus ? UIManager.getBorder("List.focusCellHighlightBorder") : border);

    return label;
  }
예제 #6
0
  /**
   * 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;
  }
예제 #7
0
  @Override
  public VerseRange clone() {
    // This gets us a shallow copy
    VerseRange copy = null;
    try {
      copy = (VerseRange) super.clone();
      copy.start = start;
      copy.end = end;
      copy.verseCount = verseCount;
      copy.originalName = originalName;
      copy.shaper = new NumberShaper();
      copy.v11n = v11n;
    } catch (CloneNotSupportedException e) {
      assert false : e;
    }

    return copy;
  }
예제 #8
0
 /** Ctor */
 protected VerseIterator(VerseRange range) {
   v11n = range.getVersification();
   nextVerse = range.getStart();
   total = range.getCardinality();
   count = 0;
 }
예제 #9
0
 /**
  * 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;
 }