Example #1
0
  /**
   * Inserts the entry, given that its ID is not already in use. use Util.createId(...) to make up a
   * unique ID for an entry.
   */
  public synchronized boolean insertEntry(BibtexEntry entry) throws KeyCollisionException {
    String id = entry.getId();
    if (getEntryById(id) != null) {
      throw new KeyCollisionException("ID is already in use, please choose another");
    }

    entry.addPropertyChangeListener(listener);

    _entries.put(id, entry);

    fireDatabaseChanged(
        new DatabaseChangeEvent(this, DatabaseChangeEvent.ChangeType.ADDED_ENTRY, entry));

    return checkForDuplicateKeyAndAdd(null, entry.getCiteKey(), false);
  }
Example #2
0
  private void index() {

    /*  Old version, from when set was a TreeSet.

    // The boolean "changing" is true in the situation that an entry is about to change,
    // and has temporarily been removed from the entry set in this sorter. So, if we index
    // now, we will cause exceptions other places because one entry has been left out of
    // the indexed array. Simply waiting foth this to change can lead to deadlocks,
    // so we have no other choice than to return without indexing.
    if (changing)
        return;
    */

    synchronized (set) {

      // Resort if necessary:
      if (changed) {
        Collections.sort(set, comp);
        changed = false;
      }

      // Create an array of IDs for quick access, since getIdAt() is called by
      // getValueAt() in EntryTableModel, which *has* to be efficient.

      int count = set.size();
      idArray = new String[count];
      entryArray = new BibtexEntry[count];
      int piv = 0;
      for (BibtexEntry entry : set) {
        //        for (int i=0; i<idArray.length; i++) {
        idArray[piv] = entry.getId();
        entryArray[piv] = entry;
        piv++;
      }
    }
  }
Example #3
0
 public int compare(BibtexEntry one, BibtexEntry two) {
   return one.getId().compareTo(two.getId());
 }