MaskHistoryEntry.java
2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package osp;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;
/**
* Represents an entry in the history with a list of actions that have to be undone with the entry.<br/>
* Each action should appear only once per entry, even if there is no limitation.
* @see MaskHistory
*/
public class MaskHistoryEntry
{
/**
* The name of the entry.
*/
private final String name;
/**
* The list of pairs [action, value] corresponding to the entry.
*/
private HashMap<String, Object> actions;
/**
* Constructs an entry with a given name and an empty list of actions.
* @param entryName The name of the entry.
*/
public MaskHistoryEntry(String entryName)
{
name = entryName;
actions = new HashMap<String, Object>();
}
/**
* Get the name of the entry.
* @return The name of the entry.
*/
public String getName()
{
return name;
}
/**
* Put a new action in this entry. This should not be used directly.
* MaskHistory's <a href="./MaskHistory.html#addAction(java.lang.String, java.lang.Object)">addAction</a>
* method should be called instead.
* @param action The action to add to the entry.
* @param value The value to be restored by the action.
*/
void putAction(String action, Object value)
{
actions.put(action, value);
}
/**
* Get the list of actions in this entry.
* @return A <a href="http://docs.oracle.com/javase/6/docs/api/java/util/Set.html">Set</a> of all the actions present in the entry.
*/
public Set<String> getActions()
{
return actions.keySet();
}
/**
* Get the value corresponding to an action.
* @param action The action to get the value for.
* @return The value that corresponds to the given action.
*/
public Object getValue(String action)
{
return actions.get(action);
}
/**
* Delete a given action in the entry.
* @param action The action to delete.
*/
public void deleteAction(String action)
{
actions.remove(action);
}
/**
* Returns a <a href="http://docs.oracle.com/javase/6/docs/api/java/lang/String.html">String</a> in the form "MaskHistoryEntry '<i>name</i>' Actions: <i>actions</i>", where <i>name</i> is the name of the entry
* and <i>actions</i> is a list of [<i>action</i>, <i>value</i>] pairs.
*/
@Override
public String toString()
{
StringBuilder str = new StringBuilder("MaskHistoryEntry '" + name + "', Actions: ");
for ( Iterator<String> itr = actions.keySet().iterator(); itr.hasNext(); )
{
String action = itr.next();
str.append("[");
str.append(action);
str.append(", ");
str.append( actions.get(action) );
str.append( "]" );
}
return str.toString();
}
/**
* Tests if the entry is empty.
* @return true if the list of actions is empty.
*/
public boolean isEmpty()
{
return actions.isEmpty();
}
}