1 package com.xtremelabs.robolectric.shadows; 2 3 import static com.xtremelabs.robolectric.Robolectric.shadowOf; 4 5 import com.xtremelabs.robolectric.internal.Implementation; 6 import com.xtremelabs.robolectric.internal.Implements; 7 import com.xtremelabs.robolectric.internal.RealObject; 8 9 import android.util.SparseArray; 10 import android.util.SparseBooleanArray; 11 12 @Implements(SparseBooleanArray.class) 13 public class ShadowSparseBooleanArray { 14 private SparseArray<Boolean> sparseArray = new SparseArray<Boolean>(); 15 16 @RealObject 17 private SparseBooleanArray realObject; 18 19 @Implementation get(int key)20 public boolean get(int key) { 21 return get(key, false); 22 } 23 24 @Implementation get(int key, boolean valueIfKeyNotFound)25 public boolean get(int key, boolean valueIfKeyNotFound) { 26 return sparseArray.get(key, valueIfKeyNotFound); 27 } 28 29 @Implementation delete(int key)30 public void delete(int key) { 31 sparseArray.delete(key); 32 } 33 34 @Implementation put(int key, boolean value)35 public void put(int key, boolean value) { 36 sparseArray.put(key, value); 37 } 38 39 @Implementation size()40 public int size() { 41 return sparseArray.size(); 42 } 43 44 @Implementation keyAt(int index)45 public int keyAt(int index) { 46 return sparseArray.keyAt(index); 47 } 48 49 @Implementation valueAt(int index)50 public boolean valueAt(int index) { 51 return sparseArray.valueAt(index); 52 } 53 54 @Implementation indexOfKey(int key)55 public int indexOfKey(int key) { 56 return sparseArray.indexOfKey(key); 57 } 58 59 @Implementation indexOfValue(boolean value)60 public int indexOfValue(boolean value) { 61 return sparseArray.indexOfValue(value); 62 } 63 64 @Implementation clear()65 public void clear() { 66 sparseArray.clear(); 67 } 68 69 @Implementation append(int key, boolean value)70 public void append(int key, boolean value) { 71 sparseArray.append(key, value); 72 } 73 74 @Implementation 75 @Override clone()76 public SparseBooleanArray clone() { 77 SparseBooleanArray clone = new SparseBooleanArray(); 78 for (int i = 0, length = size(); i < length; i++) { 79 clone.put(keyAt(i), valueAt(i)); 80 } 81 return clone; 82 } 83 84 @Implementation 85 @Override hashCode()86 public int hashCode() { 87 return sparseArray.hashCode(); 88 } 89 90 @Implementation 91 @Override equals(Object o)92 public boolean equals(Object o) { 93 if (o == null || o.getClass() != realObject.getClass()) 94 return false; 95 96 ShadowSparseBooleanArray target = (ShadowSparseBooleanArray) shadowOf((SparseBooleanArray) o); 97 return sparseArray.equals(target.sparseArray); 98 } 99 } 100