1 8 9 package com.sleepycat.persist.evolve; 10 11 import java.io.Serializable ; 12 import java.util.Collection ; 13 import java.util.HashMap ; 14 import java.util.Map ; 15 16 import com.sleepycat.persist.EntityStore; 17 import com.sleepycat.persist.StoreConfig; 18 19 45 public class Mutations implements Serializable { 46 47 private static final long serialVersionUID = -1744401530444812916L; 48 49 private Map <Mutation,Renamer> renamers; 50 private Map <Mutation,Deleter> deleters; 51 private Map <Mutation,Converter> converters; 52 53 56 public Mutations() { 57 renamers = new HashMap <Mutation,Renamer>(); 58 deleters = new HashMap <Mutation,Deleter>(); 59 converters = new HashMap <Mutation,Converter>(); 60 } 61 62 65 public boolean isEmpty() { 66 return renamers.isEmpty() && 67 deleters.isEmpty() && 68 converters.isEmpty(); 69 } 70 71 74 public void addRenamer(Renamer renamer) { 75 renamers.put(new Key(renamer), renamer); 76 } 77 78 83 public Renamer getRenamer(String className, 84 int classVersion, 85 String fieldName) { 86 return renamers.get(new Key(className, classVersion, fieldName)); 87 } 88 89 92 public Collection <Renamer> getRenamers() { 93 return renamers.values(); 94 } 95 96 99 public void addDeleter(Deleter deleter) { 100 deleters.put(new Key(deleter), deleter); 101 } 102 103 108 public Deleter getDeleter(String className, 109 int classVersion, 110 String fieldName) { 111 return deleters.get(new Key(className, classVersion, fieldName)); 112 } 113 114 117 public Collection <Deleter> getDeleters() { 118 return deleters.values(); 119 } 120 121 124 public void addConverter(Converter converter) { 125 converters.put(new Key(converter), converter); 126 } 127 128 133 public Converter getConverter(String className, 134 int classVersion, 135 String fieldName) { 136 return converters.get(new Key(className, classVersion, fieldName)); 137 } 138 139 142 public Collection <Converter> getConverters() { 143 return converters.values(); 144 } 145 146 private static class Key extends Mutation { 147 148 Key(String className, int classVersion, String fieldName) { 149 super(className, classVersion, fieldName); 150 } 151 152 Key(Mutation mutation) { 153 super(mutation.getClassName(), 154 mutation.getClassVersion(), 155 mutation.getFieldName()); 156 } 157 } 158 159 163 @Override 164 public boolean equals(Object other) { 165 if (other instanceof Mutations) { 166 Mutations o = (Mutations) other; 167 return renamers.equals(o.renamers) && 168 deleters.equals(o.deleters) && 169 converters.equals(o.converters); 170 } else { 171 return false; 172 } 173 } 174 175 @Override 176 public int hashCode() { 177 return renamers.hashCode() + 178 deleters.hashCode() + 179 converters.hashCode(); 180 } 181 182 @Override 183 public String toString() { 184 StringBuffer buf = new StringBuffer (); 185 if (renamers.size() > 0) { 186 buf.append(renamers.values()); 187 } 188 if (deleters.size() > 0) { 189 buf.append(deleters.values()); 190 } 191 if (converters.size() > 0) { 192 buf.append(converters.values()); 193 } 194 if (buf.length() > 0) { 195 return buf.toString(); 196 } else { 197 return "[Empty Mutations]"; 198 } 199 } 200 } 201 | Popular Tags |