1
2
3
4
5
6
7
8 package zeus.concepts;
9 import java.util.*;
10 import JADE_SL.abs.*;
11
12 /***
13 * provide some commonly used functors to do formatting.
14 * @author Simon Thomposon
15 * @version
16 */
17 public class SL_Util {
18
19
20 /***
21 * turn AbsAggregate into a Vector
22 **/
23 public static Vector makeVector(AbsAggregate aggr) {
24 Iterator iter = aggr.iterator();
25 Vector vec=new Vector();
26 while (iter.hasNext()) {
27 vec.addElement (iter.next()); }
28 return vec;
29 }
30
31
32 /***
33 *used to turn a name and a set of addresses into a fipa agentid string
34 **/
35 public static String makeAddressString (AbsPrimitive name, AbsAggregate addresses) {
36 String retVal = new String ("(agent-identifier :name ");
37 retVal += name.toString() +" :addresses (sequence ";
38 Iterator iter = addresses.iterator();
39 while (iter.hasNext()) {
40 AbsPrimitive address = (AbsPrimitive) iter.next();
41 retVal += address.toString() +" ";
42 }
43 retVal +="))";
44 return retVal;
45 }
46
47 /***
48 * makeSet is used to convert the vectors full of data into SL formatted strings
49 **/
50 public static String makeSet (String name, Vector members) {
51 String retVal = new String();
52 String temp = new String();
53 retVal += name +" (set ";
54 Enumeration holderEnum = members.elements();
55 while (holderEnum.hasMoreElements()) {
56 Object current = holderEnum.nextElement();
57 if (current instanceof String) {
58 temp = (String) current;
59 retVal += temp + " ";
60 }
61 else if (current instanceof AbsPrimitive) {
62 temp = ((AbsPrimitive)current).toString();
63 retVal += temp + " " ;}
64 else if (current instanceof FIPA_Service_Description ) {
65 temp = ((FIPA_Service_Description)current).toString();
66 retVal += temp + " ";
67 }
68 }
69 retVal += ") ";
70 return retVal;
71 }
72
73 }