ConverterUtils.java
Upload User: rhdiban
Upload Date: 2013-08-09
Package Size: 15085k
Code Size: 3k
Category:

Windows Develop

Development Platform:

Java

  1. /*
  2.  *    This program is free software; you can redistribute it and/or modify
  3.  *    it under the terms of the GNU General Public License as published by
  4.  *    the Free Software Foundation; either version 2 of the License, or
  5.  *    (at your option) any later version.
  6.  *
  7.  *    This program is distributed in the hope that it will be useful,
  8.  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
  9.  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  10.  *    GNU General Public License for more details.
  11.  *
  12.  *    You should have received a copy of the GNU General Public License
  13.  *    along with this program; if not, write to the Free Software
  14.  *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15.  */
  16. /*
  17.  *    ConverterUtils.java
  18.  *    Copyright (C) 2000 Mark Hall
  19.  *
  20.  */
  21. package weka.core.converters;
  22. import java.io.StreamTokenizer;
  23. import java.io.Serializable;
  24. import java.io.IOException;
  25. /**
  26.  * Utility routines for the converter package.
  27.  *
  28.  * @author Mark Hall (mhall@cs.waikato.ac.nz)
  29.  * @version $Revision 1.0 $
  30.  * @see Serializable
  31.  */
  32. public class ConverterUtils implements Serializable {
  33.   /**
  34.    * Gets token, skipping empty lines.
  35.    *
  36.    * @param tokenizer the stream tokenizer
  37.    * @exception IOException if reading the next token fails
  38.    */
  39.   public static void getFirstToken(StreamTokenizer tokenizer) 
  40.     throws IOException {
  41.     
  42.     while (tokenizer.nextToken() == StreamTokenizer.TT_EOL){};
  43.     if ((tokenizer.ttype == ''') ||
  44. (tokenizer.ttype == '"')) {
  45.       tokenizer.ttype = StreamTokenizer.TT_WORD;
  46.     } else if ((tokenizer.ttype == StreamTokenizer.TT_WORD) &&
  47.        (tokenizer.sval.equals("?"))) {
  48.       tokenizer.ttype = '?';
  49.     }
  50.   }
  51.   /**
  52.    * Gets token.
  53.    *
  54.    * @param tokenizer the stream tokenizer
  55.    * @exception IOException if reading the next token fails
  56.    */
  57.   public static void getToken(StreamTokenizer tokenizer) throws IOException {
  58.     
  59.     tokenizer.nextToken();
  60.     if (tokenizer.ttype== StreamTokenizer.TT_EOL) {
  61.       return;
  62.     }
  63.     if ((tokenizer.ttype == ''') ||
  64. (tokenizer.ttype == '"')) {
  65.       tokenizer.ttype = StreamTokenizer.TT_WORD;
  66.     } else if ((tokenizer.ttype == StreamTokenizer.TT_WORD) &&
  67.        (tokenizer.sval.equals("?"))) {
  68.       tokenizer.ttype = '?';
  69.     }
  70.   }
  71.   /**
  72.    * Throws error message with line number and last token read.
  73.    *
  74.    * @param theMsg the error message to be thrown
  75.    * @param tokenizer the stream tokenizer
  76.    * @exception IOExcpetion containing the error message
  77.    */
  78.   public static void errms(StreamTokenizer tokenizer, String theMsg) 
  79.     throws IOException {
  80.     
  81.     throw new IOException(theMsg + ", read " + tokenizer.toString());
  82.   }
  83. }