public class CFltArray
{
private int size = 0;
private float[] value;
public void reSize(int size)
{
if(size <= this.size)
{
this.size = size;
}
else
{
float[] tmp = new float[size];
for(int i=0;i < this.size;i++)
{
tmp[i] = value[i];
}
this.value = tmp;
this.size = size;
}
}
public int getSize()
{
return size;
}
public float get(int index) throws IllegalArgumentException
{
if(index < 0 || index >= size)
{
throw new IllegalArgumentException(String.valueOf(index));
}
return value[index];
}
public void set(float[] value)
{
this.size = value.length;
this.value = value;
}
public String toString()
{
StringBuilder tmp = new StringBuilder("[");
for(int i=0;i< size;i++)
{
if(i>0)
{
tmp.append(",");
}
tmp.append(value[i]);
}
tmp.append("]");
return tmp.toString();
}
public static void main(String args[])
{
CFltArray array = new CFltArray();
System.out.println(array);
array.set(new float[]{2.4f,43.3f,3.3f});
System.out.println(array);
System.out.println(array.get(2));
array.reSize(2);
System.out.println(array);
array.reSize(5);
System.out.println(array);
System.out.println(array.get(100));
}
}