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 20 public boolean get(int key) { 21 return get(key, false); 22 } 23 24 @Implementation 25 public boolean get(int key, boolean valueIfKeyNotFound) { 26 return sparseArray.get(key, valueIfKeyNotFound); 27 } 28 29 @Implementation 30 public void delete(int key) { 31 sparseArray.delete(key); 32 } 33 34 @Implementation 35 public void put(int key, boolean value) { 36 sparseArray.put(key, value); 37 } 38 39 @Implementation 40 public int size() { 41 return sparseArray.size(); 42 } 43 44 @Implementation 45 public int keyAt(int index) { 46 return sparseArray.keyAt(index); 47 } 48 49 @Implementation 50 public boolean valueAt(int index) { 51 return sparseArray.valueAt(index); 52 } 53 54 @Implementation 55 public int indexOfKey(int key) { 56 return sparseArray.indexOfKey(key); 57 } 58 59 @Implementation 60 public int indexOfValue(boolean value) { 61 return sparseArray.indexOfValue(value); 62 } 63 64 @Implementation 65 public void clear() { 66 sparseArray.clear(); 67 } 68 69 @Implementation 70 public void append(int key, boolean value) { 71 sparseArray.append(key, value); 72 } 73 74 @Implementation 75 @Override 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 86 public int hashCode() { 87 return sparseArray.hashCode(); 88 } 89 90 @Implementation 91 @Override 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