View Javadoc

1   /*
2   * The contents of this file are subject to the BT "ZEUS" Open Source 
3   * Licence (L77741), Version 1.0 (the "Licence"); you may not use this file 
4   * except in compliance with the Licence. You may obtain a copy of the Licence
5   * from $ZEUS_INSTALL/licence.html or alternatively from
6   * http://www.labs.bt.com/projects/agents/zeus/licence.htm
7   * 
8   * Except as stated in Clause 7 of the Licence, software distributed under the
9   * Licence is distributed WITHOUT WARRANTY OF ANY KIND, either express or 
10  * implied. See the Licence for the specific language governing rights and 
11  * limitations under the Licence.
12  * 
13  * The Original Code is within the package zeus.*.
14  * The Initial Developer of the Original Code is British Telecommunications
15  * public limited company, whose registered office is at 81 Newgate Street, 
16  * London, EC1A 7AJ, England. Portions created by British Telecommunications 
17  * public limited company are Copyright 1996-9. All Rights Reserved.
18  * 
19  * THIS NOTICE MUST BE INCLUDED ON ANY COPY OF THIS FILE
20  */
21  
22  
23  
24  package zeus.concepts;
25  
26  import java.io.*;
27  import java.util.*;
28  import zeus.util.*;
29  
30  public class TaskSummary extends Summary {
31     protected AbstractTask task;
32  
33     public TaskSummary(AbstractTask task, String status) {
34        setTask(task);
35        setStatus(status);
36     }
37  
38     public TaskSummary(TaskSummary s) {
39        setTask(s.getTask());
40        setStatus(s.getStatus());
41     }
42  
43     public String       getId()   { return task.getName(); }
44     public AbstractTask getTask() { return task; }
45  
46     public String[] summarize() {
47        String[] data = { task.getName(), status };
48        return data;
49     }
50  
51     public void setStatus(String status) {
52        Assert.notNull(status);
53        Assert.notFalse( status.equals(OK) || status.equals(UNKNOWN) );
54        this.status = status;
55     }
56     public void setTask(AbstractTask task) {
57        Assert.notNull(task);
58        this.task = task;
59     }
60  
61     public boolean equals(TaskSummary s ) {
62        return task.equals(s.getTask()) &&
63               status.equals(s.getStatus());
64     }
65  
66     public String toString() {
67        return( "(" +
68                 ":task " + task.toString() + " " +
69                 ":status " + status +
70                ")"
71              );
72     }
73  
74     public String pprint() {
75        return pprint(0);
76     }
77     public String pprint(int sp) {
78        String prefix;
79        String tabs = Misc.spaces(sp);
80        String eol  = "\n" + tabs + " ";
81  
82        prefix = "(:task ";
83        String s = prefix + task.pprint(sp+prefix.length()) + eol +
84                   ":status " + status + eol;
85        return s.trim() + "\n" + tabs + ")";
86     }
87  }