KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SOFA > SOFAnode > Made > CodeGen > GenObjectList


1 /* $Id: GenObjectList.java,v 1.1.1.1 2003/02/11 16:19:40 bures Exp $ */
2 package SOFA.SOFAnode.Made.CodeGen;
3
4 /** Collection of allready enerated objects.
5   *
6   * @author Petr Hnetynka
7   */

8 public class GenObjectList extends java.util.ArrayList JavaDoc {
9
10   public static class ExistException extends CodeGenException {
11     public ExistException() { super(); };
12     public ExistException(String JavaDoc s) { super(s); };
13   }
14
15   /** Returns the object at the specified position in this list.
16     *
17     * @exception IndexOutOfBoundsException if index out of range (index < 0 || index >= size()).
18     */

19   public GeneratedObject getObject(int index) {
20     return (GeneratedObject) get(index);
21   }
22  
23   /** Returns the index of object with specified key.
24     *
25     * @param key key of the searched object
26     * @return the index of the the argument in this list; returns -1 if the object is not found.
27     */

28   public int indexOfObject(String JavaDoc key) {
29     for (int i=0; i<size(); i++) {
30       if (getObject(i).compareKey(key))
31         return i;
32     }
33     return -1;
34   }
35
36   /** Returns the object with specified key.
37     *
38     * @param key key of the searched object
39     * @return the searched object; returns <B>null</B> if the object is not found.
40     */

41   public GeneratedObject searchObject(String JavaDoc key) {
42     for (int i=0; i<size(); i++) {
43       if (getObject(i).compareKey(key))
44         return getObject(i);
45     }
46     return null;
47   }
48
49   /** Returns <tt>true</tt> if this list contains the specified object.
50     *
51     * @param key key of the searched object
52     */

53   public boolean containsObject(String JavaDoc key) {
54     for (int i=0;i<size();i++) {
55       if (getObject(i).compareKey(key))
56         return true;
57     }
58     return false;
59   }
60
61   /** Adds object to list only if this object already is not in list (uses containsObject()), else
62     * it throws exception.
63     *
64     * @param obj added object
65     * @exception ExistException object is allready in list
66     */

67   public void addObject(GeneratedObject obj) throws ExistException {
68     if (!containsObject(obj.key))
69       add(obj);
70     else
71       throw new ExistException(Res.res.getString("MSG_ObjIsInList"));
72   }
73 }
74
Popular Tags