EMMA Coverage Report (generated Tue May 01 18:46:53 CEST 2007)
[all classes][dk.deepthought.sidious.goalhandler]

COVERAGE SUMMARY FOR SOURCE FILE [Goal.java]

nameclass, %method, %block, %line, %
Goal.java100% (1/1)89%  (8/9)76%  (148/196)75%  (32,8/44)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class Goal100% (1/1)89%  (8/9)76%  (148/196)75%  (32,8/44)
toString (): String 0%   (0/1)0%   (0/22)0%   (0/1)
equals (Object): boolean 100% (1/1)62%  (33/53)50%  (9/18)
hashCode (): int 100% (1/1)88%  (28/32)96%  (4,8/5)
compareTo (Goal): int 100% (1/1)89%  (16/18)80%  (4/5)
<static initializer> 100% (1/1)100% (4/4)100% (1/1)
Goal (State, double, SuperLinkID): void 100% (1/1)100% (58/58)100% (11/11)
getDesire (): double 100% (1/1)100% (3/3)100% (1/1)
getGoalState (): State 100% (1/1)100% (3/3)100% (1/1)
getOrigin (): SuperLinkID 100% (1/1)100% (3/3)100% (1/1)

1package dk.deepthought.sidious.goalhandler;
2 
3import net.jcip.annotations.Immutable;
4 
5import org.apache.commons.logging.Log;
6import org.apache.commons.logging.LogFactory;
7 
8import dk.deepthought.sidious.supportsystem.State;
9import dk.deepthought.sidious.supportsystem.SuperLinkID;
10 
11/**
12 * This class represents a goal.
13 * 
14 * @author Deepthought
15 * 
16 */
17@Immutable
18public class Goal implements Comparable<Goal> {
19        /**
20         * Logger for this class
21         */
22        private static final Log logger = LogFactory.getLog(Goal.class);
23 
24        /**
25         * The parent of this goal. I.e. the requester to whom it belongs.
26         */
27        private final SuperLinkID origin;
28 
29        /**
30         * The goal state.
31         */
32        private final State goalState;
33 
34        /**
35         * The desire of this goal. 
36         */
37        private final double desire;
38 
39        /**
40         * Constructor; returns a new instance of Goal.
41         * 
42         * @param goalState
43         *            the desired goal state
44         * @param desire
45         *            the desire of the goal
46         * @param origin
47         *            id of the originating plan requester of this goal
48         */
49        public Goal(State goalState, double desire, SuperLinkID origin) {
50                if (goalState == null) {
51                        logger.error("Goal(State goalState=null, double desire=" + desire
52                                        + ", SuperLinkID origin=" + origin
53                                        + ") - goalState invalid!");
54                        throw new IllegalArgumentException("Invalid goalState!");
55                }
56                if (origin == null) {
57                        logger.error("Goal(State goalState=" + goalState
58                                        + ", double desire=" + desire + ", SuperLinkID origin=null) - origin invalid!");
59                        throw new IllegalArgumentException("Invalid origin!");
60                }
61 
62                this.goalState = goalState;
63                this.desire = desire;
64                this.origin = origin;
65        }
66 
67        /**
68         * Returns the desire of this goal.
69         * 
70         * @return the desire of this goal
71         */
72        public double getDesire() {
73                return desire;
74        }
75 
76        /**
77         * Returns the goal state of this goal.
78         * 
79         * @return the goal state of this goal
80         */
81        public State getGoalState() {
82                return goalState;
83        }
84 
85        /**
86         * Returns the id of the originating <code>PlanRequester</code> of this
87         * goal.
88         * 
89         * @return id of the origin of this goal
90         */
91        public SuperLinkID getOrigin() {
92                return origin;
93        }
94 
95        @Override
96        public int hashCode() {
97                final int PRIME = 31;
98                int result = 1;
99                result = PRIME * result
100                                + ((goalState == null) ? 0 : goalState.hashCode());
101                result = PRIME * result + ((origin == null) ? 0 : origin.hashCode());
102                return result;
103        }
104 
105        @Override
106        public boolean equals(Object obj) {
107                if (this == obj)
108                        return true;
109                if (obj == null)
110                        return false;
111                if (getClass() != obj.getClass())
112                        return false;
113                final Goal other = (Goal) obj;
114                if (goalState == null) {
115                        if (other.goalState != null)
116                                return false;
117                } else if (!goalState.equals(other.goalState))
118                        return false;
119                if (origin == null) {
120                        if (other.origin != null)
121                                return false;
122                } else if (!origin.equals(other.origin))
123                        return false;
124                return true;
125        }
126 
127        @Override
128        public String toString() {
129                return "Goal[origin=" + origin + ", goalState=" + goalState
130                                + ", desire=" + desire + "]";
131        }
132 
133        /* (non-Javadoc)
134         * @see java.lang.Comparable#compareTo(java.lang.Object)
135         */
136        public int compareTo(Goal other) {
137                if (this.getDesire() > other.getDesire()) {
138                        return -1;
139                } else if (this.getDesire() < other.getDesire()) {
140                        return 1;
141                } else {
142                        return 0;
143                }
144        }
145 
146}

[all classes][dk.deepthought.sidious.goalhandler]
EMMA 2.0.5312 (C) Vladimir Roubtsov