KickJava   Java API By Example, From Geeks To Geeks.

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


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.*;
25
26 /**
27  * @author Uddhab Pant <br>
28  * @version $Revision: 1.3 $ $Date: 2006/04/12 00:39:12 $ <br>
29  *
30  * This class defines a R function.
31  * R function contains function name, display name, function file and list of parameters
32  *
33  */

34
35 public class RFunction {
36     private String JavaDoc name;
37     private String JavaDoc displayName;
38     private String JavaDoc file;
39     private String JavaDoc dataSetFile;
40     private List params;
41
42     /**
43      * Default constructor
44      */

45     public RFunction() {
46     }
47
48     /**
49      * Initializes RFunction with task name, display name and parameter list
50      * @param functionName String
51      * @param displayName String
52      * @param params List
53      */

54     public RFunction(String JavaDoc functionName, String JavaDoc displayName, String JavaDoc functionFile, List params) {
55         this.name = functionName;
56         this.displayName = displayName;
57         this.file = functionFile;
58         this.params = params;
59
60     }
61
62     /**
63      * Returns RFunctionParam object from the task for paramName
64      * @param paramName String
65      * @return RFunctionParam returns RFunctionParam object if found, otherwise null
66      */

67     public RFunctionParam getFunctionParam(String JavaDoc paramName) {
68
69         Iterator items = params.iterator();
70
71         while (items.hasNext()) {
72             RFunctionParam rFunctionParam = (RFunctionParam) items.next();
73             if (paramName.equalsIgnoreCase(rFunctionParam.getName())) {
74                 return rFunctionParam;
75             }
76         }
77
78         return null;
79     }
80
81     /**
82      * Removes a parameter from the function
83      * @param paramName String
84      */

85     public void removeParam(String JavaDoc paramName) {
86         if(params != null)
87             params.remove(getFunctionParam(paramName));
88     }
89
90     /**
91      * Adds a rFunctionParam object to the list
92      * @param param RFunctionParam
93      */

94     public void addParam(RFunctionParam rFunctionParam) {
95         if (!isParamExist(rFunctionParam.getName())) {
96             if(params == null)
97                 params = new ArrayList();
98             params.add(rFunctionParam);
99         }
100     }
101
102     /**
103      * Updates a RFunctionParam object in the function
104      * @param rFunctionParam RFunctionParam
105      */

106     public void updateParam(RFunctionParam rFunctionParam) {
107         removeParam(rFunctionParam.getName());
108         addParam(rFunctionParam);
109
110     }
111
112
113     /**
114      * Checks if a parameter is exist in the function
115      * @param paramName String
116      * @return boolean returns true if exists, null if not exists
117      */

118     private boolean isParamExist(String JavaDoc paramName) {
119         boolean exists = false;
120
121         if(params == null) return exists;
122
123         Iterator items = params.iterator();
124
125         while (items.hasNext()) {
126             RFunctionParam rFunctionParam = (RFunctionParam) items.next();
127             if (paramName.equalsIgnoreCase(rFunctionParam.getName())) {
128                 exists = true;
129                 break;
130             }
131         }
132
133         return exists;
134
135     }
136
137     public String JavaDoc getDisplayName() {
138         return displayName;
139     }
140
141     public String JavaDoc getFile() {
142         return file;
143     }
144
145     public String JavaDoc getName() {
146         return name;
147     }
148
149     public List getParams() {
150         return params;
151     }
152
153     public String JavaDoc getDataSetFile() {
154         return dataSetFile;
155     }
156
157     public void setDisplayName(String JavaDoc displayName) {
158         this.displayName = displayName;
159     }
160
161     public void setFile(String JavaDoc file) {
162         this.file = file;
163     }
164
165     public void setName(String JavaDoc name) {
166         this.name = name;
167     }
168
169     public void setParams(List params) {
170         this.params = params;
171     }
172
173     public void setDataSetFile(String JavaDoc dataSetFile) {
174         this.dataSetFile = dataSetFile;
175     }
176
177
178 }
179
Popular Tags