diff options
author | Xavier Ducrohet <xav@android.com> | 2010-11-18 21:00:59 -0800 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2010-11-18 21:00:59 -0800 |
commit | 60899fac2bf35086b0083bfbffa2f6bf5c18f2d9 (patch) | |
tree | d95dd83b1c8f8ac9d97b029d83e11fc765bfd9e3 /tools | |
parent | f532eec860a5b5c7e9897d1de84d57ab829c5b48 (diff) | |
parent | 755b46d597b8e8a616d53e2a7dfea295dd78d713 (diff) | |
download | frameworks_base-60899fac2bf35086b0083bfbffa2f6bf5c18f2d9.zip frameworks_base-60899fac2bf35086b0083bfbffa2f6bf5c18f2d9.tar.gz frameworks_base-60899fac2bf35086b0083bfbffa2f6bf5c18f2d9.tar.bz2 |
Merge "Layoutlib: use int[] wrapper to use as map keys."
Diffstat (limited to 'tools')
-rw-r--r-- | tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java | 46 |
1 files changed, 43 insertions, 3 deletions
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java index efa0f27..e691fdf 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java @@ -37,6 +37,7 @@ import android.util.Finalizers; import java.lang.ref.SoftReference; import java.lang.reflect.Field; import java.lang.reflect.Modifier; +import java.util.Arrays; import java.util.HashMap; import java.util.Map; @@ -62,7 +63,7 @@ public final class Bridge extends LayoutBridge { /** * Same as sRMap except for int[] instead of int resources. This is for android.R only. */ - private final static Map<int[], String> sRArrayMap = new HashMap<int[], String>(); + private final static Map<IntArray, String> sRArrayMap = new HashMap<IntArray, String>(); /** * Reverse map compared to sRMap, resource type -> (resource name -> id). * This is for android.R only. @@ -83,6 +84,44 @@ public final class Bridge extends LayoutBridge { private static Map<String, Map<String, Integer>> sEnumValueMap; /** + * int[] wrapper to use as keys in maps. + */ + private final static class IntArray { + private int[] mArray; + + private IntArray() { + // do nothing + } + + private IntArray(int[] a) { + mArray = a; + } + + private void set(int[] a) { + mArray = a; + } + + @Override + public int hashCode() { + return Arrays.hashCode(mArray); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null) return false; + if (getClass() != obj.getClass()) return false; + + IntArray other = (IntArray) obj; + if (!Arrays.equals(mArray, other.mArray)) return false; + return true; + } + } + + /** Instance of IntArrayWrapper to be reused in {@link #resolveResourceValue(int[])}. */ + private final static IntArray sIntArrayWrapper = new IntArray(); + + /** * A default logger than prints to stdout/stderr. */ private final static ILayoutLog sDefaultLogger = new ILayoutLog() { @@ -183,7 +222,7 @@ public final class Bridge extends LayoutBridge { Class<?> type = f.getType(); if (type.isArray() && type.getComponentType() == int.class) { // if the object is an int[] we put it in sRArrayMap - sRArrayMap.put((int[]) f.get(null), f.getName()); + sRArrayMap.put(new IntArray((int[]) f.get(null)), f.getName()); } else if (type == int.class) { Integer value = (Integer) f.get(null); sRMap.put(value, new String[] { f.getName(), resType }); @@ -319,7 +358,8 @@ public final class Bridge extends LayoutBridge { * @param array */ public static String resolveResourceValue(int[] array) { - return sRArrayMap.get(array); + sIntArrayWrapper.set(array); + return sRArrayMap.get(sIntArrayWrapper); } /** |