package jxl.biff.formula;

public class FormulaErrorCode {
  private int errorCode;
  
  private String description;
  
  private static FormulaErrorCode[] codes = new FormulaErrorCode[0];
  
  FormulaErrorCode(int code, String desc) {
    this.errorCode = code;
    this.description = desc;
    FormulaErrorCode[] newcodes = new FormulaErrorCode[codes.length + 1];
    System.arraycopy(codes, 0, newcodes, 0, codes.length);
    newcodes[codes.length] = this;
    codes = newcodes;
  }
  
  public int getCode() {
    return this.errorCode;
  }
  
  public String getDescription() {
    return this.description;
  }
  
  public static FormulaErrorCode getErrorCode(int code) {
    boolean found = false;
    FormulaErrorCode ec = UNKNOWN;
    for (int i = 0; i < codes.length && !found; i++) {
      if ((codes[i]).errorCode == code) {
        found = true;
        ec = codes[i];
      } 
    } 
    return ec;
  }
  
  public static FormulaErrorCode UNKNOWN = new FormulaErrorCode(255, "?");
  
  public static FormulaErrorCode NULL = new FormulaErrorCode(0, "#NULL");
  
  public static FormulaErrorCode DIV0 = new FormulaErrorCode(7, "#DIV/0");
  
  public static FormulaErrorCode VALUE = new FormulaErrorCode(15, "#VALUE");
  
  public static FormulaErrorCode REF = new FormulaErrorCode(23, "#REF");
  
  public static FormulaErrorCode NAME = new FormulaErrorCode(29, "#NAME");
  
  public static FormulaErrorCode NUM = new FormulaErrorCode(36, "#NUM");
  
  public static FormulaErrorCode NA = new FormulaErrorCode(42, "#N/A");
}
