
package examples;

import java.io.Serializable;

/**
 * The generic version of StrArray class<p>
 * There are 2 derived classes: one is RStrArray - for read-only,
 * WStrArray - for write operations
 */
public class StrArray implements Serializable {

  protected String a[];

  /** 
   * a simple constructor
   */
  protected StrArray(int size) {
    a=new String[size];
  }

  /**
   * a copy constructor: a swallow copy constructor.
   * We just copy the array itself. We do not copy the elements within
   * the array in this case, because java.lang.String itself is immutable.
   */
  protected StrArray(StrArray givenArray) {
    this.a=new String[givenArray.a.length];
    System.arraycopy(givenArray.a,0,this.a,0,givenArray.a.length);
  }

  protected void setStr(int i, String s) {
    a[i]=s;
  }

  protected String getStr(int i) {
    return a[i];
  }

  public String getInfo() {
    StringBuffer sb=new StringBuffer();
    for (int i=0; i<a.length; i++) {
      sb.append(i+":"+a[i]+" ");
    }
    return new String(sb);
  }

}

