1 2 3 package Jt; 4 import java.util.*; 5 import java.lang.reflect.*; 6 import java.beans.*; 7 import java.io.*; 8 9 12 13 public class JtList extends JtCollection { 14 private LinkedList col = null; 16 17 public JtList() { 18 } 19 20 21 24 public LinkedList getLinkedList () { 25 return (col); 26 } 27 28 29 30 33 34 public void setLinkedList (LinkedList col) { 35 this.col = col; 36 } 37 38 41 42 public Object getIterator () { 43 JtIterator jit; 44 Collection values; 45 46 jit = new JtIterator (); 47 48 if (col == null) 49 return (null); 50 56 jit.setIterator(col.iterator ()); 57 58 return (jit); 59 } 60 61 64 65 public void setSize (int size) { 66 } 68 69 72 73 public int getSize () { 74 return (col != null ? col.size (): 0); 75 } 76 77 78 89 90 public Object processMessage (Object message) { 91 92 String msgid = null; 93 JtMessage e = (JtMessage) message; 94 Object content; 95 Object data; 96 97 98 if (e == null) 99 return null; 100 101 msgid = (String ) e.getMsgId (); 102 103 if (msgid == null) 104 return null; 105 106 content = e.getMsgContent(); 107 109 if (msgid.equals ("JtREMOVE")) { 111 return (null); 112 } 113 114 if (msgid.equals ("JtADD")) { 115 117 if (content == null) { 118 handleWarning 119 ("JtCollection.processMessage(JtADD):invalid content (null)"); 120 return (this); 121 122 } 123 if (col == null) 124 col = new LinkedList (); 125 127 col.add (content); 129 return (this); 130 } 131 132 133 if (msgid.equals ("JtCLEAR")) { 134 135 if (col != null) { 136 col.clear (); 137 } 138 140 return (this); 141 } 142 143 if (msgid.equals ("JtFIRST")) { 144 145 if (col == null) 146 return (null); 147 148 if (col.size () < 1) { 149 return (null); 150 } 151 152 return (col.getFirst ()); 153 } 154 155 156 if (msgid.equals ("JtLAST")) { 157 158 if (col == null) 159 return (null); 160 161 if (col.size () < 1) { 162 return (null); 163 } 164 165 return (col.getLast ()); 166 } 167 168 169 if (msgid.equals ("JtREMOVE_FIRST")) { 170 171 if (col == null) 172 return (null); 173 174 if (col.size () < 1) { 175 return (null); 176 } 177 178 return (col.removeFirst ()); 179 } 180 181 handleError ("JtList.processMessage: invalid message id:" + msgid); 182 return (null); 183 184 } 185 186 187 190 191 public static void main(String [] args) { 192 193 JtObject main = new JtObject (); 194 JtMessage msg, msg1; 195 Integer count; 196 JtIterator it; 197 Object obj; 198 199 202 203 205 main.createObject ("Jt.JtList", "list"); 206 207 208 msg = (JtMessage) main.createObject ("Jt.JtMessage", "message"); 209 main.setValue (msg, "msgId", "JtADD"); 210 main.setValue (msg, "msgContent", new Integer (1)); 211 212 214 main.sendMessage ("list", msg); 215 216 217 main.setValue (msg, "msgId", "JtADD"); 218 main.setValue (msg, "msgContent", new Integer (2)); 219 220 221 223 main.sendMessage ("list", msg); 224 225 System.out.println ("Size=" + main.getValue ("list", "size")); 226 227 228 obj = (Object ) main.sendMessage ("list", new JtMessage ("JtFIRST")); 229 230 System.out.println ("First=" + obj); 231 232 obj = (Object ) main.sendMessage ("list", new JtMessage ("JtLAST")); 233 234 System.out.println ("Last=" + obj); 235 236 it = (JtIterator) main.getValue ("list", "iterator"); 237 238 for (;;) { 239 obj = (Object ) main.sendMessage (it, new JtMessage ("JtNEXT")); 240 if (obj == null) 241 break; 242 System.out.println (obj); 243 } 244 245 246 248 main.setValue ("message", "msgId", "JtCLEAR"); 249 main.sendMessage ("list", "message"); 250 main.removeObject ("list"); 251 } 252 253 } 254 255 256
| Popular Tags
|