Exemplo n.º 1
0
 /**
  * Merge two Maps of (IPath->MarkerSet) representing changes. Use the old map to store the result
  * so we don't have to build a new map to return.
  */
 public static Map merge(Map oldChanges, Map newChanges) {
   if (oldChanges == null)
     // don't worry about copying since the new changes are no longer used
     return newChanges;
   if (newChanges == null) return oldChanges;
   for (Iterator it = newChanges.keySet().iterator(); it.hasNext(); ) {
     IPath key = (IPath) it.next();
     MarkerSet oldSet = (MarkerSet) oldChanges.get(key);
     MarkerSet newSet = (MarkerSet) newChanges.get(key);
     if (oldSet == null) oldChanges.put(key, newSet);
     else merge(oldSet, newSet.elements());
   }
   return oldChanges;
 }
Exemplo n.º 2
0
  /**
   * Merge two sets of marker changes. Both sets must be on the same resource. Use the original set
   * of changes to store the result so we don't have to build a completely different set to return.
   *
   * <p>add + add = N/A add + remove = nothing (no delta) add + change = add remove + add = N/A
   * remove + remove = N/A remove + change = N/A change + add = N/A change + change = change (note:
   * info held onto by the marker delta should be that of the oldest change, and not replaced when
   * composed) change + remove = remove (note: info held onto by the marker delta should be that of
   * the oldest change, and not replaced when changed to a remove)
   */
  protected static MarkerSet merge(MarkerSet oldChanges, IMarkerSetElement[] newChanges) {
    if (oldChanges == null) {
      MarkerSet result = new MarkerSet(newChanges.length);
      for (int i = 0; i < newChanges.length; i++) result.add(newChanges[i]);
      return result;
    }
    if (newChanges == null) return oldChanges;

    for (int i = 0; i < newChanges.length; i++) {
      MarkerDelta newDelta = (MarkerDelta) newChanges[i];
      MarkerDelta oldDelta = (MarkerDelta) oldChanges.get(newDelta.getId());
      if (oldDelta == null) {
        oldChanges.add(newDelta);
        continue;
      }
      switch (oldDelta.getKind()) {
        case IResourceDelta.ADDED:
          switch (newDelta.getKind()) {
            case IResourceDelta.ADDED:
              // add + add = N/A
              break;
            case IResourceDelta.REMOVED:
              // add + remove = nothing
              // Remove the original ADD delta.
              oldChanges.remove(oldDelta);
              break;
            case IResourceDelta.CHANGED:
              // add + change = add
              break;
          }
          break;
        case IResourceDelta.REMOVED:
          switch (newDelta.getKind()) {
            case IResourceDelta.ADDED:
              // remove + add = N/A
              break;
            case IResourceDelta.REMOVED:
              // remove + remove = N/A
              break;
            case IResourceDelta.CHANGED:
              // remove + change = N/A
              break;
          }
          break;
        case IResourceDelta.CHANGED:
          switch (newDelta.getKind()) {
            case IResourceDelta.ADDED:
              // change + add = N/A
              break;
            case IResourceDelta.REMOVED:
              // change + remove = remove
              // Change the delta kind.
              oldDelta.setKind(IResourceDelta.REMOVED);
              break;
            case IResourceDelta.CHANGED:
              // change + change = change
              break;
          }
          break;
      }
    }
    return oldChanges;
  }