1 22 package org.jboss.cache.util; 23 24 import java.util.HashMap ; 25 import java.util.Map ; 26 27 33 public final class Util 34 { 35 47 public static Class loadClass(String classname) throws ClassNotFoundException 48 { 49 ClassLoader cl = Thread.currentThread().getContextClassLoader(); 50 if (cl == null) 51 cl = ClassLoader.getSystemClassLoader(); 52 return cl.loadClass(classname); 53 } 54 55 58 private Util() 59 { 60 } 61 62 71 public static MapModifications diffNodeData(Map <Object , Object > pre, Map <Object , Object > post) 72 { 73 MapModifications mods = new MapModifications(); 74 75 for (Object key : post.keySet()) 77 { 78 if (pre.containsKey(key)) 79 { 80 if (!post.get(key).equals(pre.get(key))) 81 { 82 mods.modifiedEntries.put(key, post.get(key)); 83 } 84 } 85 else 86 { 87 mods.addedEntries.put(key, post.get(key)); 88 } 89 } 90 91 for (Object key : pre.keySet()) 93 { 94 if (!post.containsKey(key)) 95 { 96 mods.removedEntries.put(key, pre.get(key)); 97 } 98 } 99 100 return mods; 101 } 102 103 106 public static class MapModifications 107 { 108 public final Map <Object , Object > addedEntries = new HashMap <Object , Object >(); 109 public final Map <Object , Object > removedEntries = new HashMap <Object , Object >(); 110 public final Map <Object , Object > modifiedEntries = new HashMap <Object , Object >(); 111 112 113 public boolean equals(Object o) 114 { 115 if (this == o) return true; 116 if (o == null || getClass() != o.getClass()) return false; 117 118 MapModifications that = (MapModifications) o; 119 120 if (addedEntries != null ? !addedEntries.equals(that.addedEntries) : that.addedEntries != null) return false; 121 if (modifiedEntries != null ? !modifiedEntries.equals(that.modifiedEntries) : that.modifiedEntries != null) 122 return false; 123 if (removedEntries != null ? !removedEntries.equals(that.removedEntries) : that.removedEntries != null) 124 return false; 125 126 return true; 127 } 128 129 public int hashCode() 130 { 131 int result; 132 result = (addedEntries != null ? addedEntries.hashCode() : 0); 133 result = 31 * result + (removedEntries != null ? removedEntries.hashCode() : 0); 134 result = 31 * result + (modifiedEntries != null ? modifiedEntries.hashCode() : 0); 135 return result; 136 } 137 138 public String toString() 139 { 140 return "Added Entries " + addedEntries + " Removeed Entries " + removedEntries + " Modified Entries " + modifiedEntries; 141 } 142 } 143 144 } 145 | Popular Tags |