Skip to content

Commit

Permalink
新增Command操作工具类
Browse files Browse the repository at this point in the history
  • Loading branch information
chaojian committed Aug 28, 2016
1 parent 7246ef3 commit a9375e9
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions app/src/main/java/com/rdc/lichaojian/note/utils/CommandUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.rdc.lichaojian.note.utils;

import com.rdc.lichaojian.note.command.Command;

import java.util.ArrayList;
import java.util.List;

/**
* Created by lichaojian on 16-8-28.
*/
public class CommandUtils {
private static final String TAG = "CommandUtils";
private static CommandUtils mCommandUtils = null;
private List<Command> mUndoCommandList = null;
private List<Command> mRedoCommandList = null;

private CommandUtils() {
mUndoCommandList = new ArrayList<>();
mRedoCommandList = new ArrayList<>();
}

public static CommandUtils getInstance() {
if (mCommandUtils == null) {
mCommandUtils = new CommandUtils();
}
return mCommandUtils;
}

public List<Command> getUndoCommandList() {
return mUndoCommandList;
}

public List<Command> getRedoCommandList() {
return mRedoCommandList;
}

/**
* 撤销
*
* @return 返回需要撤销的指令
*/
public Command undo() {
Command command = null;
int size = mUndoCommandList.size();
if (mUndoCommandList != null && size > 0) {
command = mUndoCommandList.get(size - 1);
mRedoCommandList.add(command);
mUndoCommandList.remove(size - 1);
}
return command;
}

/**
* 恢复操作
*
* @return 返回恢复的指令
*/
public Command redo() {
Command command = null;
int size = mRedoCommandList.size();
if (mRedoCommandList != null && size > 0) {
command = mRedoCommandList.get(size - 1);
mUndoCommandList.add(command);
mRedoCommandList.remove(size - 1);
}
return command;
}
}

0 comments on commit a9375e9

Please sign in to comment.