public class ChenqiArray { /** * @param args */ public static void main(String[] args) { // TODO Autogenerated method stub RisingsoftArray raOne=new RisingsoftArray(); int newLength=raOnegetArrayCount()+; for(int i=;i<newLength;i++){ raOnesetItem(inew Integer(i)); Systemoutprintln(ems[+i+]=+raOnegetItem(i)); } newLength=raOnegetArrayCount()+; for(int i=;i<newLength;i++){ raOnesetItem(inew Integer(i)); Systemoutprintln(ems[+i+]=+raOnegetItem(i)); } newLength=raOnegetArrayCount()+; raOnesetItem(newLengthnew Integer(newLength)); for(int i=;i<raOnegetArrayCount();i++){ Systemoutprintln(ems[+i+]=+raOnegetItem(i)); } } } class RisingsoftArray{ private Object[] obj; //constructor public RisingsoftArray(int ArrayLength){ if(ArrayLength>=){ obj=new Object[ArrayLength]; } } public RisingsoftArray(){ this(); } public RisingsoftArray(Object[] obj){ thisobj=RisingsoftArraycloneArray(obj); } //get the Array items count public int getArrayCount(){ return (obj!=null)?objlength:; } //auto expand the Array and copy the items public void expandArray(int n){ if(n> && n>getArrayCount()){ Object[] newObj=new Object[n]; for(int i=;i<getArrayCount();newObj[i]=obj[i++]){} obj=newObj; } } //get access public Object getItem(int pos){ return (pos>= && pos<getArrayCount())?obj[pos]:null; } //set access public void setItem(int posObject obj){ if(pos>= && pos<getArrayCount()){ thisobj[pos]=obj; } else if (pos>||(pos==getArrayCount())) { expandArray(pos+); setItem(posobj); } } //clone a Array public static Object[] cloneArray(Object[] obj){ if(objlength<){ return null; } else{ Object[] newObj=new Object[objlength]; for(int i=;i<objlength;newObj[i]=obj[i++]){} return newObj; } } } |