Source Code
Infrared Signal Coding Schemes
home top contents previous up next

//Manual implementation of ArrayList for common compatibility
//1.4 and 1.4+ Java versions.

public class ArrayListObj {

		private static final int startupSize=2;
		
		/**
		 * Array which stores Objects.
		 */
		public Object[] obj;
		/**
		 * Length of array cells occupied by subarrays int[].
		 */
		public int length;
		
		public ArrayListObj(){
			obj=new Object[startupSize];
			length=0;
		}
		
		public Object add(Object ob){
			if(length>=obj.length){
				int formerLength=obj.length;
				//Increase memory allocation.
				Object[] obNew=new Object[formerLength*2];
				//GUInt.con("New array length "+ (formerLength*2));
				//Copy array:
				for(int i=0; i<formerLength; i++){
				   obNew[i]=obj[i];	
				}
				obj=obNew;
				//do2 Dispose former arr. 
				//Hope, Java will do this for us.
			}
			obj[length++]=ob;
			return ob;
		}
		
		
		//Sugar:
		public int size(){
			return length;
		}
		//Sugar:
		public Object get(int iX){
			return obj[iX];
		}
		public Object getLast(){
			if(0==length)return null;
			return obj[length-1];
		}
		//Sugar:
		public int getCycledNext(int iX){
			if(0==length) return -1;
			return (iX+1)%length;
		}
		//Sugar:
		public int getNext(int iX){
			return (iX+1<length) ? iX+1  :  -1; 
		}
}


Copyright (C) 2009 Konstantin Kirillov