1 11 package org.eclipse.ui.internal.preferences; 12 13 import java.util.Iterator ; 14 import java.util.Set ; 15 16 19 public class PropertyUtil { 20 private PropertyUtil() { 21 } 22 23 public static boolean isEqual(IPropertyMap map1, IPropertyMap map2) { 24 Set map1Keys = map1.keySet(); 25 Set map2Keys = map2.keySet(); 26 27 if (!map1Keys.equals(map2Keys)) { 28 return false; 29 } 30 31 for (Iterator iter = map1Keys.iterator(); iter.hasNext();) { 32 String next = (String ) iter.next(); 33 34 if (!map1.getValue(next, Object .class).equals(map2.getValue(next, Object .class))) { 35 return false; 36 } 37 } 38 39 return true; 40 } 41 42 49 public static void copy(IPropertyMap destination, IPropertyMap source) { 50 Set keys = source.keySet(); 51 52 for (Iterator iter = keys.iterator(); iter.hasNext();) { 53 String key = (String ) iter.next(); 54 55 destination.setValue(key, source.getValue(key, Object .class)); 56 } 57 } 58 59 71 public static IPropertyMap union(IPropertyMap[] sources) { 72 PropertyMapUnion result = new PropertyMapUnion(); 73 74 for (int i = 0; i < sources.length; i++) { 75 IPropertyMap map = sources[i]; 76 77 result.addMap(map); 78 } 79 80 return result; 81 } 82 83 public static boolean get(IPropertyMap toRead, String propertyId, boolean defaultValue) { 84 Boolean result = ((Boolean )toRead.getValue(propertyId, Boolean .class)); 85 86 if (result == null) { 87 return defaultValue; 88 } 89 90 return result.booleanValue(); 91 } 92 93 public static int get(IPropertyMap toRead, String propertyId, int defaultValue) { 94 Integer result = ((Integer )toRead.getValue(propertyId, Integer .class)); 95 96 if (result == null) { 97 return defaultValue; 98 } 99 100 return result.intValue(); 101 } 102 } 103 | Popular Tags |