1 2 23 package org.enhydra.tool.common; 24 25 import java.util.ArrayList ; 27 import java.util.Arrays ; 28 import java.util.ResourceBundle ; 29 30 33 public class ReplacementSet { 34 static ResourceBundle res = 35 ResourceBundle.getBundle("org.enhydra.tool.common.Res"); 37 private Replacement[] replacements = new Replacement[0]; 39 40 43 public ReplacementSet() {} 44 45 public ReplacementSet(Replacement[] reps) { 46 replacements = reps; 47 } 48 49 60 public Replacement lookup(String find) throws ToolException { 61 Replacement replacement = null; 62 63 for (int i = 0; i < replacements.length; i++) { 64 if (replacements[i].getFind().equalsIgnoreCase(find)) { 65 replacement = replacements[i]; 66 break; 67 } 68 } 69 if (replacement == null) { 70 throw new ToolException(ResUtil.format(res.getString("Unable_to_lookup"), 71 find)); 72 } 73 return replacement; 74 } 75 76 84 public void delete(String find) throws ToolException {} 85 86 94 public void add(Replacement newRep) throws ToolException { 95 ArrayList list = null; 96 97 list = new ArrayList (Arrays.asList(replacements)); 98 list.add(newRep); 99 list.trimToSize(); 100 replacements = new Replacement[list.size()]; 101 replacements = (Replacement[]) list.toArray(replacements); 102 } 103 104 111 public Replacement[] toArray() { 112 return replacements; 113 } 114 115 public String [][] toStringArray() { 116 String [][] strings = new String [replacements.length][2]; 117 118 for (int i = 0; i < replacements.length; i++) { 119 strings[i][0] = replacements[i].getFind(); 120 strings[i][1] = replacements[i].getReplaceWith()[0]; 121 } 122 return strings; 123 } 124 125 } 126 | Popular Tags |