1 /*
2  * Copyright (C) 2012 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.gallery3d.util;
18 
19 // This is an array whose index ranges from min to max (inclusive).
20 public class RangeBoolArray {
21     private boolean[] mData;
22     private int mOffset;
23 
RangeBoolArray(int min, int max)24     public RangeBoolArray(int min, int max) {
25         mData = new boolean[max - min + 1];
26         mOffset = min;
27     }
28 
29     // Wraps around an existing array
RangeBoolArray(boolean[] src, int min, int max)30     public RangeBoolArray(boolean[] src, int min, int max) {
31         mData = src;
32         mOffset = min;
33     }
34 
put(int i, boolean object)35     public void put(int i, boolean object) {
36         mData[i - mOffset] = object;
37     }
38 
get(int i)39     public boolean get(int i) {
40         return mData[i - mOffset];
41     }
42 
indexOf(boolean object)43     public int indexOf(boolean object) {
44         for (int i = 0; i < mData.length; i++) {
45             if (mData[i] == object) return i + mOffset;
46         }
47         return Integer.MAX_VALUE;
48     }
49 }
50