KickJava   Java API By Example, From Geeks To Geeks.

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


1 /* $Id: ObjectList.java,v 1.2 2004/05/20 14:23:51 bures Exp $ */
2 package SOFA.SOFAnode.Made.CodeGen;
3
4 import SOFA.SOFAnode.Made.TIR.Contained;
5 import SOFA.SOFAnode.Made.TIR.Identification;
6  
7 /** Collection of repository objects.
8   *
9   * @author Petr Hnetynka
10   */

11 class ObjectList extends java.util.ArrayList JavaDoc {
12    /** Returns the object at the specified position in this list.
13      *
14      * @exception IndexOutOfBoundsException if index out of range (index < 0 || index >= size()).
15      */

16    public Contained getObject(int index) {
17      return (Contained) get(index);
18    }
19
20    /** Returns specified object.
21      *
22      * @param absName absolute name of object whose presence in this List is to be tested.
23      * @param ver version identifier of object whose presence in this List is to be tested.
24      * @exception RemoteException remote exception
25      */

26    public Contained getObject(String JavaDoc absName, String JavaDoc ver) throws java.rmi.RemoteException JavaDoc {
27      Contained obj;
28      for (int i=0;i<size();i++) {
29        if ((obj = getObject(i)).get_identification().is_equal(absName, ver))
30          return obj;
31      }
32      return null;
33    }
34
35    /** Returns <tt>true</tt> if this list contains the specified object.
36      *
37      * @param absName absolute name of object whose presence in this List is to be tested.
38      * @param ver version identifier of object whose presence in this List is to be tested.
39      * @exception RemoteException remote exception
40      */

41    public boolean containsObject(String JavaDoc absName, String JavaDoc ver) throws java.rmi.RemoteException JavaDoc {
42      for (int i=0;i<size();i++) {
43        if (getObject(i).get_identification().is_equal(absName, ver))
44          return true;
45      }
46      return false;
47    }
48
49    /** Returns <tt>true</tt> if this list contains the specified object.
50      *
51      * @param obj repository object whose presence in this List is to be tested.
52      * @exception RemoteException remote exception
53      */

54    public boolean containsObject(Contained obj) throws java.rmi.RemoteException JavaDoc {
55      Identification idl = obj.get_identification();
56      for (int i=0;i<size();i++) {
57        if (getObject(i).get_identification().is_equal(idl.absolute_name().name(), idl.version()))
58          return true;
59      }
60      return false;
61    }
62
63    /** Adds object to list only if this object already is not in list (uses containsObject()).
64      *
65      * @param obj added object
66      * @exception RemoteException remote exception
67      */

68    public void addObject(Contained obj) throws java.rmi.RemoteException JavaDoc {
69      Identification idl = obj.get_identification();
70      Contained inObj;
71      if ((inObj=getObject(idl.absolute_name().name(), idl.version()))==null) {
72        add(obj);
73      }/* else {
74        remove(indexOfObject(idl.absolute_name().name(), idl.version()));
75        add(obj);
76      }*/

77    }
78
79    /** Returns index of the specified object if this list contains it.
80      *
81      * @param absName absolute name of object whose presence in this List is to be tested.
82      * @param ver version identifier of object whose presence in this List is to be tested.
83      * @exception RemoteException remote exception
84      * @return the index of the the argument in this list; returns -1 if the object is not found.
85      */

86    public int indexOfObject(String JavaDoc absName, String JavaDoc ver) throws java.rmi.RemoteException JavaDoc {
87      for (int i=0;i<size();i++) {
88        if (getObject(i).get_identification().is_equal(absName, ver))
89          return i;
90      }
91      return -1;
92    }
93    
94    /** Merge this lists together.
95      *
96      * @param obj list with new objects, which are added to this list
97      * @exception RemoteException remote exception
98      */

99    public void mergeTogether(ObjectList obj) throws java.rmi.RemoteException JavaDoc {
100      if (obj!=null) {
101        for (int i=0; i<obj.size();i++) {
102          addObject(obj.getObject(i));
103        }
104      }
105    }
106 }
107
Popular Tags