|
@@ -2,7 +2,7 @@ |
2 |
2 |
|
|
3 |
3 |
|
/** |
4 |
4 |
|
* A Class to replace two booleans: Saved (unchanged) and Update (New vs Updating). |
5 |
|
- |
* |
|
5 |
+ |
* <p/> |
6 |
6 |
|
* This class carries two states about some other object: |
7 |
7 |
|
* <OL> |
8 |
8 |
|
* <LI> which CRUD operation is currently active</LI> |
|
@@ -16,15 +16,15 @@ |
16 |
16 |
|
* CRUD w/ supporting change management support flags |
17 |
17 |
|
*/ |
18 |
18 |
|
public enum Operation { |
19 |
|
- |
Create(false, true), // |
20 |
|
- |
Read(false, false), // |
21 |
|
- |
Update(false, true), // |
22 |
|
- |
Delete(true, false); |
|
19 |
+ |
Create( false, true ), // |
|
20 |
+ |
Read( false, false ), // |
|
21 |
+ |
Update( false, true ), // |
|
22 |
+ |
Delete( true, false ); |
23 |
23 |
|
|
24 |
24 |
|
private boolean initialChangedState; |
25 |
25 |
|
private boolean allowsOtherChanges; |
26 |
26 |
|
|
27 |
|
- |
Operation(boolean initialChangedState, boolean allowsOtherChanges) { |
|
27 |
+ |
Operation( boolean initialChangedState, boolean allowsOtherChanges ) { |
28 |
28 |
|
this.initialChangedState = initialChangedState; |
29 |
29 |
|
this.allowsOtherChanges = allowsOtherChanges; |
30 |
30 |
|
} |
|
@@ -49,44 +49,44 @@ |
49 |
49 |
|
return operation; |
50 |
50 |
|
} |
51 |
51 |
|
|
52 |
|
- |
private void setOperation(Operation operation) { |
|
52 |
+ |
private void setOperation( Operation operation ) { |
53 |
53 |
|
this.operation = operation; |
54 |
54 |
|
resetChanges(); |
55 |
55 |
|
} |
56 |
56 |
|
|
57 |
57 |
|
public void resetToCreate() { |
58 |
|
- |
setOperation(Operation.Create); |
|
58 |
+ |
setOperation( Operation.Create ); |
59 |
59 |
|
} |
60 |
60 |
|
|
61 |
61 |
|
public void resetToRead() { |
62 |
|
- |
setOperation(Operation.Read); |
|
62 |
+ |
setOperation( Operation.Read ); |
63 |
63 |
|
} |
64 |
64 |
|
|
65 |
65 |
|
public void resetToUpdate() { |
66 |
|
- |
setOperation(Operation.Update); |
|
66 |
+ |
setOperation( Operation.Update ); |
67 |
67 |
|
} |
68 |
68 |
|
|
69 |
69 |
|
public void resetToDelete() { |
70 |
|
- |
setOperation(Operation.Delete); |
|
70 |
+ |
setOperation( Operation.Delete ); |
71 |
71 |
|
} |
72 |
72 |
|
|
73 |
73 |
|
public boolean isCreate() { |
74 |
|
- |
return operation.equals(Operation.Create); |
|
74 |
+ |
return operation.equals( Operation.Create ); |
75 |
75 |
|
} |
76 |
76 |
|
|
77 |
77 |
|
public boolean isRead() { |
78 |
|
- |
return operation.equals(Operation.Read); |
|
78 |
+ |
return operation.equals( Operation.Read ); |
79 |
79 |
|
} |
80 |
80 |
|
|
81 |
81 |
|
public boolean isUpdate() { |
82 |
|
- |
return operation.equals(Operation.Update); |
|
82 |
+ |
return operation.equals( Operation.Update ); |
83 |
83 |
|
} |
84 |
84 |
|
|
85 |
85 |
|
public boolean isDelete() { |
86 |
|
- |
return operation.equals(Operation.Delete); |
|
86 |
+ |
return operation.equals( Operation.Delete ); |
87 |
87 |
|
} |
88 |
88 |
|
|
89 |
|
- |
public void resetChanges(){ |
|
89 |
+ |
public void resetChanges() { |
90 |
90 |
|
changed = operation.getInitialChangedState(); |
91 |
91 |
|
} |
92 |
92 |
|
|
|
@@ -95,8 +95,8 @@ |
95 |
95 |
|
} |
96 |
96 |
|
|
97 |
97 |
|
public void changed() { |
98 |
|
- |
if (!operation.allowsOtherChanges) { |
99 |
|
- |
throw new IllegalStateException("The " + operation + " does NOT allow the data to be changed!"); |
|
98 |
+ |
if ( !operation.allowsOtherChanges ) { |
|
99 |
+ |
throw new IllegalStateException( "The " + operation + " does NOT allow the data to be changed!" ); |
100 |
100 |
|
} |
101 |
101 |
|
changed = true; |
102 |
102 |
|
} |