コード例 #1
0
 /**
  * Searches {@code entries} for {@link AddeEntry} objects with two characteristics:
  *
  * <ul>
  *   <li>the object source is {@link EntrySource#SYSTEM}
  *   <li>the object is <b>not</b> in {@code systemEntries}
  * </ul>
  *
  * <p>The intent behind this method is to safely remove {@literal "system"} entries that have been
  * stored to a user's preferences. {@code entries} can be generated from anywhere you like, but
  * {@code systemEntries} should almost always be created from {@literal "addeservers.xml"}.
  *
  * @param entries Cannot be {@code null}.
  * @param systemEntries Cannot be {@code null}.
  * @return {@code Set} of entries that are not system resources that have been removed, or an
  *     empty {@code Set}.
  */
 private static Set<AddeEntry> removeDeletedSystemEntries(
     final Collection<? extends AddeEntry> entries,
     final Collection<? extends AddeEntry> systemEntries) {
   Set<AddeEntry> pruned = newLinkedHashSet(entries.size());
   for (AddeEntry entry : entries) {
     if (entry.getEntrySource() != EntrySource.SYSTEM) {
       pruned.add(entry);
     } else if (systemEntries.contains(entry)) {
       pruned.add(entry);
     } else {
       continue;
     }
   }
   return pruned;
 }
コード例 #2
0
  public boolean removeEntries(final Collection<? extends AddeEntry> removedEntries) {
    notNull(removedEntries);

    boolean val = true;
    boolean tmpVal = true;
    for (AddeEntry entry : removedEntries) {
      if (entry.getEntrySource() != EntrySource.SYSTEM) {
        tmpVal = trie.remove(entry.asStringId()) != null;
        logger.trace("attempted bulk remove={} status={}", entry, tmpVal);
        if (!tmpVal) {
          val = tmpVal;
        }
      }
    }
    Event evt = (val) ? Event.REMOVAL : Event.FAILURE;
    saveEntries();
    EventBus.publish(evt);
    return val;
  }