Hii,
I am not very experienced in java and i have the following question. I need to clone the following class...i m using this class as nested class in my other class. But, still first i need to understand the cloning for this class.
public class Iterator implements Cloneable
{
/**
* constructor that sets current index to <code>0</code>
*/
public Iterator () { m_nCurrentIndex = 0; }
/**
* gets value of the current column by column index
* @param nColumnIdx column that contains the value
* @return returns the value of the current column or <code>""</code> if <code>nColumnIdx</code> is <code>null</code>
*/
public String getValue (int nColumnIdx)
{
String outValue = ( getColumn ().get (nColumnIdx)!=null ) ? getColumn ().get (nColumnIdx) : "";
return outValue;
}
/**
* gets value of the current column by column name
* @param nColumnName column that contains the value
* @return returns the value of the current column
*/
public String getValue (String sColumnName)
{ return getColumn ().get (getColumnIndex (sColumnName)); }
// access column
/**
* gets the column
* @return returns current index
*/
public StringArray getColumn ()
// StringArray is another class...and i already have it cloneable...
{ return (StringArray)(m_ValueMatrix.get (m_nCurrentIndex)); }
/**
* sets a value to the given position
* @param nColumnIdx columnindex where the new value should be stored
* @param sColumnValue the new value
*/
public void setValue(int nColumnIdx, String sColumnValue){
if (getColumn ().get (nColumnIdx)!=null){
getColumn().set(nColumnIdx, sColumnValue);
}
}
/**
* checks if iterator is still valid
* @return returns true if iterator is valid
*/
public boolean isValid ()
{ return m_nCurrentIndex < m_ValueMatrix.size (); }
/**
* moves iterator to the next index
*/
public void moveNext ()
{ ++m_nCurrentIndex; }
// attributes
/**
* current index
*/
private int m_nCurrentIndex;
public Object clone(){
Iterator iter_clone = new Iterator();
// here i got stucked????????????
// how to make cloneable...
return iter_clone;
}
}
I have already done with the cloning of StringArray class i m using.
Can someone help me to do the cloning.
Thanks and regards
newtosql