1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package zeus.concepts;
25
26 import java.io.*;
27 import java.util.*;
28 import zeus.util.*;
29
30 /***
31 Change Log
32 ----------
33 07/06/01 () init added
34 * 21/06/02 - DAML-S changes
35 * 26/9/02 - DAML-s changes back - moved to a name so that a URL can be
36 *generated that is used in the service registration
37 *
38 */
39 public class AbilitySpec {
40 protected Fact fact;
41 protected int time;
42 protected double cost;
43 protected String name = "noname";
44
45 public AbilitySpec () {
46
47 }
48
49
50 public AbilitySpec(String name, Fact fact, int time, double cost) {
51 this.fact = new Fact(fact);
52 this.time = time;
53 this.cost = cost;
54 this.name = name;
55 }
56
57 public AbilitySpec( Fact fact, int time, double cost) {
58 this.fact = new Fact(fact);
59 this.time = time;
60 this.cost = cost;
61 }
62
63
64 public AbilitySpec(AbilitySpec ability) {
65 fact = new Fact(ability.getFact());
66 time = ability.getTime();
67 cost = ability.getCost();
68 }
69
70
71 public AbilitySpec duplicate(String name, GenSym genSym) {
72 DuplicationTable table = new DuplicationTable(name,genSym);
73 return duplicate(table);
74 }
75
76
77 public AbilitySpec duplicate(DuplicationTable table) {
78 return new AbilitySpec(name,fact.duplicate(table), time, cost);
79 }
80
81
82 public String getType() { return fact.getType(); }
83 public String getId() { return fact.getId(); }
84 public Fact getFact() { return fact; }
85 public int getTime() { return time; }
86 public double getCost() { return cost; }
87
88 public String getName () { return name;}
89
90 public void setTime(int t) { time = t; }
91 public void setCost(double c) { cost = c; }
92
93 public void setName(String s) { name = s; }
94
95 public boolean resolve(Bindings b) {
96 return fact.resolve(b);
97 }
98
99 public boolean equals(AbilitySpec ability ) {
100 return fact.equals(ability.getFact()) &&
101 time == ability.getTime() &&
102 Math.abs(cost - ability.getCost()) < 1.0e-12;
103
104
105
106 }
107
108 public String toString() {
109 String front = ( "(" +":fact " + fact + " " + ":time " + time + " " + ":cost " + cost + " " );
110 if (name != null) {
111 front += ":name " + name + ")";}
112 else front += ")";
113 return front;
114 }
115
116 public String pprint() {
117 return pprint(0);
118 }
119
120 public String pprint(int sp) {
121 String prefix;
122 String tabs = Misc.spaces(sp);
123 String eol = "\n" + tabs + " ";
124
125 prefix = "(:fact ";
126 String s = prefix + fact.pprint(sp+prefix.length()) + eol +
127 ":time " + time + eol +
128 ":cost " + cost + eol;
129 return s.trim() + "\n" + tabs + ")";
130 }
131 }