public CostMatrix(Reader reader) throws Exception { LineNumberReader lnr = new LineNumberReader(reader); String line; int currentRow = -1;  while ((line = lnr.readLine()) != null) {   if (line.startsWith("%")) { continue; }  StringTokenizer st = new StringTokenizer(line);  if (!st.hasMoreTokens()) { continue; }  if (currentRow < 0) { int rows = Integer.parseInt(st.nextToken()); if (!st.hasMoreTokens()) { throw new Exception("Line " + lnr.getLineNumber() + ": expected number of columns"); }  int cols = Integer.parseInt(st.nextToken()); if (rows != cols) { throw new Exception("Trying to create a non-square cost " +"matrix"); }  m_size = rows; initialize(); currentRow++; continue;  } else { if (currentRow == m_size) { throw new Exception("Line " + lnr.getLineNumber() + ": too many rows provided"); }  for (int i = 0; i < m_size; i++) { if (!st.hasMoreTokens()) { throw new Exception("Line " + lnr.getLineNumber() + ": too few matrix elements provided"); }  setCell(currentRow, i, st.nextToken()); } currentRow++; } }  if (currentRow == -1) { throw new Exception("Line " + lnr.getLineNumber() + ": expected number of rows"); } else if (currentRow != m_size) { throw new Exception("Line " + lnr.getLineNumber() + ": too few rows provided"); }
public CostMatrix(int numOfClasses) { m_size = numOfClasses; initialize();
  public CostMatrix(Reader reader) throws Exception {    LineNumberReader lnr = new LineNumberReader(reader);    String line;    int currentRow = -1;    while ((line = lnr.readLine()) != null) {      // Comments      if (line.startsWith("%")) {          continue;      }            StringTokenizer st = new StringTokenizer(line);      // Ignore blank lines      if (!st.hasMoreTokens()) {        continue;      }      if (currentRow < 0) {        int rows = Integer.parseInt(st.nextToken());        if (!st.hasMoreTokens()) {          throw new Exception("Line " + lnr.getLineNumber()               + ": expected number of columns");        }        int cols = Integer.parseInt(st.nextToken());        if (rows != cols) {          throw new Exception("Trying to create a non-square cost "                              +"matrix");        }        //        m_matrix = new Object[rows][cols];        m_size = rows;        initialize();        currentRow++;        continue;      } else {        if (currentRow == m_size) {          throw new Exception("Line " + lnr.getLineNumber()               + ": too many rows provided");        }        for (int i = 0; i < m_size; i++) {          if (!st.hasMoreTokens()) {            throw new Exception("Line " + lnr.getLineNumber()                 + ": too few matrix elements provided");          }          setCell(currentRow, i, st.nextToken());        }        currentRow++;      }    }        if (currentRow == -1) {      throw new Exception("Line " + lnr.getLineNumber()                           + ": expected number of rows");    } else if (currentRow != m_size) {      throw new Exception("Line " + lnr.getLineNumber()                           + ": too few rows provided");    }  }