Exemplo n.º 1
0
  /**
   * Replaces the {@link AddeEntry}s within {@code trie} with the contents of {@code newEntries}.
   *
   * @param oldEntries Entries to be replaced. Cannot be {@code null}.
   * @param newEntries Entries to use as replacements. Cannot be {@code null}.
   * @throws NullPointerException if either of {@code oldEntries} or {@code newEntries} is {@code
   *     null}.
   */
  public void replaceEntries(
      final Collection<? extends AddeEntry> oldEntries,
      final Collection<? extends AddeEntry> newEntries) {
    notNull(oldEntries, "Cannot replace a null set");
    notNull(newEntries, "Cannot add a null set");

    for (AddeEntry oldEntry : oldEntries) {
      trie.remove(oldEntry.asStringId());
    }
    for (AddeEntry newEntry : newEntries) {
      trie.put(newEntry.asStringId(), newEntry);
    }
    lastAdded.clear();
    lastAdded.addAll(newEntries); // should probably be more thorough
    saveEntries();
    EventBus.publish(Event.REPLACEMENT);
  }
Exemplo n.º 2
0
 /**
  * Adds a single {@link AddeEntry} to {@link #trie}.
  *
  * @param entry Entry to add. Cannot be {@code null}.
  * @throws NullPointerException if {@code entry} is {@code null}.
  */
 public void addEntry(final AddeEntry entry) {
   notNull(entry, "Cannot add a null entry");
   trie.put(entry.asStringId(), entry);
   saveEntries();
   lastAdded.clear();
   lastAdded.add(entry);
   EventBus.publish(Event.ADDITION);
 }
Exemplo n.º 3
0
 /**
  * Removes a single {@link AddeEntry} from the set of available entries.
  *
  * @param entry Entry to remove. Cannot be {@code null}.
  * @return {@code true} if something was removed, {@code false} otherwise.
  */
 public boolean removeEntry(final AddeEntry entry) {
   notNull(entry);
   boolean val = trie.remove(entry.asStringId()) != null;
   logger.trace("attempted remove={} status={}", entry, val);
   Event evt = val ? Event.REMOVAL : Event.FAILURE;
   saveEntries();
   EventBus.publish(evt);
   return val;
 }
Exemplo n.º 4
0
 /**
  * Adds {@link AddeEntry} objects to a given {@link PatriciaTrie}.
  *
  * @param trie Cannot be {@code null}.
  * @param newEntries Cannot be {@code null}.
  */
 private static void putEntries(
     final PatriciaTrie<String, AddeEntry> trie,
     final Collection<? extends AddeEntry> newEntries) {
   notNull(trie);
   notNull(newEntries);
   for (AddeEntry e : newEntries) {
     trie.put(e.asStringId(), e);
   }
 }
Exemplo n.º 5
0
 /**
  * Adds a {@link Set} of {@link AddeEntry}s to {@link #trie}.
  *
  * @param newEntries New entries to add to the server manager. Cannot be {@code null}.
  * @throws NullPointerException if {@code newEntries} is {@code null}.
  */
 public void addEntries(final Collection<? extends AddeEntry> newEntries) {
   notNull(newEntries, "Cannot add a null set");
   for (AddeEntry newEntry : newEntries) {
     trie.put(newEntry.asStringId(), newEntry);
   }
   saveEntries();
   lastAdded.clear();
   lastAdded.addAll(newEntries);
   EventBus.publish(Event.ADDITION);
 }
Exemplo n.º 6
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;
  }