aboutsummaryrefslogtreecommitdiff
path: root/v1/src/main/java/com/xtremelabs/robolectric/shadows/ShadowSparseIntArray.java
blob: fe7c8d185d8d313c67e5d1ca2484203cd14edc98 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package com.xtremelabs.robolectric.shadows;

import android.util.SparseArray;
import android.util.SparseIntArray;

import com.xtremelabs.robolectric.internal.Implementation;
import com.xtremelabs.robolectric.internal.Implements;
import com.xtremelabs.robolectric.internal.RealObject;

@Implements(SparseIntArray.class)
public class ShadowSparseIntArray {

	private SparseArray<Integer> sparseArray = new SparseArray<Integer>();
	
	@RealObject
	private SparseIntArray realObject;
	
	@Implementation
	public int get( int key ){
		return get( key, 0 );
	}
	
	@Implementation
	public int get(int key, int valueIfKeyNotFound){
		return sparseArray.get( key, valueIfKeyNotFound );
	}
	
	@Implementation
	public void put( int key, int value ){
		sparseArray.put( key, value );
	}
	
	@Implementation
	public int size() {
		return sparseArray.size();
	}
	
	@Implementation
	public int indexOfValue( int value ) {
		return sparseArray.indexOfValue( value );
	}
	
	@Implementation
	public int keyAt( int index ){
		return sparseArray.keyAt( index );
	}
	
	@Implementation
	public int valueAt( int index ){
		return sparseArray.valueAt( index );
	}
	
	@Implementation
	@Override
	public SparseIntArray clone() {
		SparseIntArray clone = new SparseIntArray();
		for (int i = 0, length = size(); i < length; i++) {
			clone.put( keyAt(i), valueAt(i) );
		}
		return clone;
	}
}