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 RangeIntArray { 21 private int[] mData; 22 private int mOffset; 23 RangeIntArray(int min, int max)24 public RangeIntArray(int min, int max) { 25 mData = new int[max - min + 1]; 26 mOffset = min; 27 } 28 29 // Wraps around an existing array RangeIntArray(int[] src, int min, int max)30 public RangeIntArray(int[] src, int min, int max) { 31 mData = src; 32 mOffset = min; 33 } 34 put(int i, int object)35 public void put(int i, int object) { 36 mData[i - mOffset] = object; 37 } 38 get(int i)39 public int get(int i) { 40 return mData[i - mOffset]; 41 } 42 indexOf(int object)43 public int indexOf(int 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