1 17 18 package org.objectweb.jac.util; 19 20 import java.util.Vector ; 21 import org.objectweb.jac.util.ExtArrays; 22 23 26 27 33 34 public class OrderedRepository extends Repository { 35 36 42 public static Repository get() { 43 if (repository == null) 44 repository = new OrderedRepository(); 45 return repository; 46 } 47 48 55 protected static Repository repository = null; 56 57 59 public Vector orderedObjects = new Vector (); 60 61 63 public Vector orderedNames = new Vector (); 64 65 75 public boolean register(String logicalName, Object object) { 76 int index = 0; 77 index = orderedNames.indexOf(logicalName); 78 if (index != -1) { 79 orderedNames.remove(index); 80 orderedObjects.remove(index); 81 } 82 orderedObjects.add(object); 83 orderedNames.add(logicalName); 84 super.register(logicalName, object); 85 return true; 86 } 87 88 95 public void unregister(String logicalName) { 96 int index = 0; 97 index = orderedNames.indexOf(logicalName); 98 if (index == -1) { 99 return; 100 } 101 orderedNames.remove(index); 102 orderedObjects.remove(index); 103 super.unregister(logicalName); 104 } 105 106 116 public Object [] getObjects() { 117 return orderedObjects.toArray(); 118 } 119 120 132 public String [] getNames() { 133 return (String [])orderedNames.toArray(ExtArrays.emptyStringArray); 134 } 135 136 public String getPrintableString() { 137 String s=""; 138 for (int i=0; i<orderedNames.size(); i++) { 139 s = s+" - "+orderedNames.get(i)+" : "+orderedObjects.get(i)+"\n"; 140 } 141 return s; 142 } 143 144 } 145 146 147 | Popular Tags |