KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jicengine > operation > NegationOperation


1 package org.jicengine.operation;
2
3 /**
4  * <p> </p>
5  *
6  * <p> </p>
7  *
8  * <p> </p>
9  *
10  * <p> </p>
11  *
12  * @author timo laitinen
13  */

14 public class NegationOperation implements Operation {
15     private Operation operation;
16     public NegationOperation(Operation operation)
17     {
18         this.operation = operation;
19     }
20
21     /**
22      * <p> executes the operation in a given context.
23      *
24      * @param context Context
25      * @throws OperationException
26      * @return Object
27      */

28     public Object JavaDoc execute(Context context) throws OperationException
29     {
30         Object JavaDoc result = this.operation.execute(context);
31         if( result == null ){
32             // null means true to here.
33
return Boolean.TRUE;
34         }
35         else if( result instanceof Boolean JavaDoc ){
36             // negate the boolean
37
return new Boolean JavaDoc(!((Boolean JavaDoc)result).booleanValue());
38         }
39         else {
40             // non-null, non-boolean means false
41
return Boolean.FALSE;
42         }
43
44     }
45
46     /**
47      * <p> So clients may query if this operation needs a particular parameter.
48      *
49      * @param name String
50      * @return boolean
51      */

52     public boolean needsParameter(String JavaDoc name)
53     {
54         return this.operation.needsParameter(name);
55     }
56
57     /**
58      * So clients may query whether this operation needs any parameters at all.
59      *
60      * @return boolean
61      */

62     public boolean needsParameters()
63     {
64         return this.operation.needsParameters();
65     }
66 }
67
Popular Tags