KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openi > stat > r > RFunctionList


1 /*********************************************************************************
2  * The contents of this file are subject to the OpenI Public License Version 1.0
3  * ("License"); You may not use this file except in compliance with the
4  * License. You may obtain a copy of the License at
5  * http://www.openi.org/docs/LICENSE.txt
6  *
7  * Software distributed under the License is distributed on an "AS IS" basis,
8  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
9  * the specific language governing rights and limitations under the License.
10  *
11  * The Original Code is: OpenI Open Source
12  *
13  * The Initial Developer of the Original Code is Loyalty Matrix, Inc.
14  * Portions created by Loyalty Matrix, Inc. are
15  * Copyright (C) 2005 Loyalty Matrix, Inc.; All Rights Reserved.
16  *
17  * Contributor(s): ______________________________________.
18  *
19  ********************************************************************************/

20
21
22 package org.openi.stat.r;
23
24 import java.util.List JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.ArrayList JavaDoc;
27
28 /**
29  * @author Uddhab Pant <br>
30  * @version $Revision: 1.3 $ $Date: 2006/04/12 00:39:12 $ <br>
31  *
32  * This class contains R function list and helper methods.
33  *
34  */

35
36 public class RFunctionList {
37
38     private List JavaDoc RFunctions;
39
40     /**
41      * Default contructor
42      */

43     public RFunctionList(){
44
45     }
46
47     /**
48      * Contructor to initialize RFunctionList with R Functions
49      * @param rFunctions List
50      */

51     public RFunctionList(List JavaDoc rFunctions) {
52         this.RFunctions = rFunctions;
53     }
54
55
56     /**
57      * Returns RFunction instance for a function name
58      * @param functionName String
59      * @return RFunction returns RFunction if found, otherwise null
60      */

61     public RFunction getFunction(String JavaDoc functionName) {
62
63         Iterator JavaDoc functions = RFunctions.iterator();
64
65         while(functions.hasNext()){
66             RFunction rFunction = (RFunction)functions.next();
67             if(functionName.equalsIgnoreCase(rFunction.getName()))
68                 return rFunction;
69         }
70
71         return null;
72     }
73
74     /**
75      * returns R function releated with specified file
76      * @param rfile String
77      * @return RFunction
78      */

79     public RFunction getFunctionByFile(String JavaDoc rfile) {
80         Iterator JavaDoc functions = RFunctions.iterator();
81         while (functions.hasNext()) {
82             RFunction rFunction = (RFunction) functions.next();
83             if (rfile.equalsIgnoreCase(rFunction.getFile()))
84                 return rFunction;
85         }
86         return null;
87     }
88
89     /**
90      * Removes functionName from the function list
91      * @param functionName String
92      */

93     public void removeFunction(String JavaDoc functionName){
94         if(RFunctions != null)
95             RFunctions.remove(getFunction(functionName));
96     }
97
98     /**
99      * Adds a RFunction object to function list
100      * @param rFunction RFunction
101      */

102     public void addFunction(RFunction rFunction){
103         if(!isFunctionExist(rFunction.getName())){
104             if(RFunctions == null)
105                 RFunctions = new ArrayList JavaDoc();
106            RFunctions.add(rFunction);
107         }
108
109     }
110
111     /**
112      * Updates RFunction in the function list
113      * @param rFunction RFunction
114      */

115     public void updateFunction(RFunction rFunction){
116         removeFunction(rFunction.getName());
117         addFunction(rFunction);
118
119     }
120
121     /**
122      * Checks whether functionName is exist in the list
123      * @param functionName String
124      * @return boolean true if exists otherwise false
125      */

126     private boolean isFunctionExist(String JavaDoc functionName){
127         boolean exists = false;
128
129         if(RFunctions == null) return exists;
130
131         Iterator JavaDoc tasks = RFunctions.iterator();
132
133         while(tasks.hasNext()){
134             RFunction rFunction = (RFunction)tasks.next();
135             if(functionName.equalsIgnoreCase(rFunction.getName())){
136                 exists = true;
137                 break;
138             }
139         }
140
141         return exists;
142
143     }
144
145     /**
146      *
147      * @return List
148      */

149     public List JavaDoc getRFunctions() {
150         return RFunctions;
151     }
152
153     /**
154      *
155      * @param RFunctions List
156      */

157     public void setRFunctions(List JavaDoc RFunctions) {
158         this.RFunctions = RFunctions;
159     }
160
161
162 }
163
Popular Tags