Example #1
0
  /*
   * (non-Javadoc)
   *
   * @see org.crosswire.jsword.passage.AbstractPassage#optimizeReads()
   */
  @Override
  public void optimizeReads() {
    raiseEventSuppresion();

    // We have to create the cached versions of these separately
    // so that the calculations made by addAll(this) can
    // safely call methods like countVerses() without any
    // danger of them being optimized before the optimizations
    // are ready for use.

    DistinctPassage dtemp = new DistinctPassage(getVersification());
    dtemp.raiseEventSuppresion();
    dtemp.addAll(this);
    dtemp.lowerEventSuppressionAndTest();

    RangedPassage rtemp = new RangedPassage(getVersification());
    rtemp.raiseEventSuppresion();
    rtemp.addAll(this);
    rtemp.lowerEventSuppressionAndTest();

    distinct = dtemp;
    ranged = rtemp;

    // This is just an optimization so we dont need to fire any events
    lowerEventSuppressionAndTest();
  }
  /**
   * Get a copy of ourselves. Points to note:
   *
   * <ul>
   *   <li>Call clone() not new() on member Objects, and on us.
   *   <li>Do not use Copy Constructors! - they do not inherit well.
   *   <li>Think about this needing to be synchronized
   *   <li>If this is not cloneable then writing cloneable children is harder
   * </ul>
   *
   * @return A complete copy of ourselves
   */
  public Object clone() {
    // This gets us a shallow copy
    DistinctPassage copy = (DistinctPassage) super.clone();

    // I want to just do the following
    //   copy.store = (SortedSet) store.clone();
    // However SortedSet is not Clonable so I can't
    // Watch out for this, I'm not sure if it breaks anything.
    copy.store = new TreeSet();
    copy.store.addAll(store);

    return copy;
  }