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.util.*;
27  import zeus.util.*;
28  
29  
30  public class Acquaintance extends Relationship {
31    protected Vector abilities = new Vector(100);
32  
33    public Acquaintance () { 
34    }
35  
36    public Acquaintance(Acquaintance child) {
37      setName(child.getName());
38      setRelation(child.getRelation());
39      setAbilities(child.getAbilities());
40    }
41  
42    public Acquaintance(String name, String relation) {
43      super(name,relation);
44    }
45  
46    public Acquaintance(String name, String relation, AbilitySpec[] abilities) {
47      super(name,relation);
48      setAbilities(abilities);
49    }
50  
51    public Acquaintance(String name, String relation, Vector abilities) {
52      super(name,relation);
53      setAbilities(abilities);
54    }
55  
56    public void setAbilities( Vector in ) {
57       abilities.removeAllElements();
58       for( int i = 0; in != null && i < in.size(); i++ )
59          abilities.addElement( new AbilitySpec( (AbilitySpec)in.elementAt(i)) );
60    }
61  
62    public void setAbilities( AbilitySpec[] in ) {
63       abilities.removeAllElements();
64       for( int i = 0; in != null && i < in.length; i++ )
65          abilities.addElement( new AbilitySpec(in[i]) );
66    }
67  
68    public AbilitySpec[] getAbilities() {
69      AbilitySpec[] out = new AbilitySpec[abilities.size()];    
70      for( int i = 0; i < abilities.size(); i++ )
71         out[i] = (AbilitySpec)abilities.elementAt(i);
72      return out;
73    }
74    
75    public String toString() {
76      String s = new String("(");
77      
78      s += ":name " + name + " ";
79      s += ":relation " + relation + " ";
80      
81      if ( !abilities.isEmpty() ) {
82        s += ":abilities (";
83        for( int i = 0; i < abilities.size(); i++ )
84  	s += ((AbilitySpec)abilities.elementAt(i)).toString() + " ";
85        s = s.trim() + ")";
86      }
87      s = s.trim() + ")";
88      return s;
89    }
90    
91    public String pprint() {
92      return pprint(0);
93    }
94  
95    public String pprint(int sp) {
96      String tabs = Misc.spaces(sp);
97      String eol  = "\n" + tabs + " ";
98      
99      String s = new String("(");
100     s += ":name " + name + eol;
101     s += ":relation " + relation + eol;
102     
103     if ( !abilities.isEmpty() ) {
104       String prefix = ":abilities ";
105       String suffix = Misc.spaces(1+ sp + prefix.length());
106       s += prefix + "(";
107       for( int i = 0; i < abilities.size(); i++ )
108 	s += ((AbilitySpec)
109 	      abilities.elementAt(i)).pprint(1+suffix.length());
110       s = s.trim() + "\n" + suffix + ")" + eol;
111     }
112     return s.trim() + "\n" + tabs + ")";
113   }
114 }