コード例 #1
0
 @Override
 public IUndoableOperation getUndoOperation(IUndoContext context) {
   Assert.isNotNull(context);
   synchronized (undoRedoHistoryLock) {
     for (int i = undoList.size() - 1; i >= 0; i--) {
       IUndoableOperation operation = undoList.get(i);
       if (operation.hasContext(context)) {
         return operation;
       }
     }
   }
   return null;
 }
コード例 #2
0
  /*
   * Filter the specified list to include only the specified undo context.
   */
  private IUndoableOperation[] filter(List<IUndoableOperation> list, IUndoContext context) {
    /*
     * This method is used whenever there is a need to filter the undo or
     * redo history on a particular context. Currently there are no caches
     * kept to optimize repeated requests for the same filter. If benchmarks
     * show this to be a common pattern that causes performances problems,
     * we could implement a filtered cache here that is nullified whenever
     * the global history changes.
     */

    List<IUndoableOperation> filtered = new ArrayList<>();
    synchronized (undoRedoHistoryLock) {
      Iterator<IUndoableOperation> iterator = list.iterator();
      while (iterator.hasNext()) {
        IUndoableOperation operation = iterator.next();
        if (operation.hasContext(context)) {
          filtered.add(operation);
        }
      }
    }
    return filtered.toArray(new IUndoableOperation[filtered.size()]);
  }