1 7 8 package com.sun.corba.se.impl.orbutil ; 9 10 import java.util.ArrayList ; 11 12 17 public class DenseIntMapImpl 18 { 19 private ArrayList list = new ArrayList () ; 20 21 private void checkKey( int key ) 22 { 23 if (key < 0) 24 throw new IllegalArgumentException ( "Key must be >= 0." ) ; 25 } 26 27 30 public Object get( int key ) 31 { 32 checkKey( key ) ; 33 34 Object result = null ; 35 if (key < list.size()) 36 result = list.get( key ) ; 37 38 return result ; 39 } 40 41 44 public void set( int key, Object value ) 45 { 46 checkKey( key ) ; 47 extend( key ) ; 48 list.set( key, value ) ; 49 } 50 51 private void extend( int index ) 52 { 53 if (index >= list.size()) { 54 list.ensureCapacity( index + 1 ) ; 55 int max = list.size() ; 56 while (max++ <= index) 57 list.add( null ) ; 58 } 59 } 60 } 61 | Popular Tags |