1 20 21 22 package org.openi.stat.r; 23 24 import java.util.List ; 25 import java.util.Iterator ; 26 import java.util.ArrayList ; 27 28 35 36 public class RFunctionList { 37 38 private List RFunctions; 39 40 43 public RFunctionList(){ 44 45 } 46 47 51 public RFunctionList(List rFunctions) { 52 this.RFunctions = rFunctions; 53 } 54 55 56 61 public RFunction getFunction(String functionName) { 62 63 Iterator 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 79 public RFunction getFunctionByFile(String rfile) { 80 Iterator 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 93 public void removeFunction(String functionName){ 94 if(RFunctions != null) 95 RFunctions.remove(getFunction(functionName)); 96 } 97 98 102 public void addFunction(RFunction rFunction){ 103 if(!isFunctionExist(rFunction.getName())){ 104 if(RFunctions == null) 105 RFunctions = new ArrayList (); 106 RFunctions.add(rFunction); 107 } 108 109 } 110 111 115 public void updateFunction(RFunction rFunction){ 116 removeFunction(rFunction.getName()); 117 addFunction(rFunction); 118 119 } 120 121 126 private boolean isFunctionExist(String functionName){ 127 boolean exists = false; 128 129 if(RFunctions == null) return exists; 130 131 Iterator 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 149 public List getRFunctions() { 150 return RFunctions; 151 } 152 153 157 public void setRFunctions(List RFunctions) { 158 this.RFunctions = RFunctions; 159 } 160 161 162 } 163 | Popular Tags |