mev-4.0.01/source/org/tigr/remote/protocol/parser/IntVectorParser.java

Code
Comments
Other
Rev Date Author Line
2 26 Feb 07 jari 1 /*
2 26 Feb 07 jari 2 Copyright @ 1999-2003, The Institute for Genomic Research (TIGR).
2 26 Feb 07 jari 3 All rights reserved.
2 26 Feb 07 jari 4 */
2 26 Feb 07 jari 5 /*
2 26 Feb 07 jari 6  * $RCSfile: IntVectorParser.java,v $
2 26 Feb 07 jari 7  * $Revision: 1.3 $
2 26 Feb 07 jari 8  * $Date: 2005/03/10 15:28:22 $
2 26 Feb 07 jari 9  * $Author: braistedj $
2 26 Feb 07 jari 10  * $State: Exp $
2 26 Feb 07 jari 11  */
2 26 Feb 07 jari 12 package org.tigr.remote.protocol.parser;
2 26 Feb 07 jari 13
2 26 Feb 07 jari 14 import java.util.StringTokenizer;
2 26 Feb 07 jari 15
2 26 Feb 07 jari 16 import org.tigr.util.IntArray;
2 26 Feb 07 jari 17
2 26 Feb 07 jari 18 class IntVectorParser {
2 26 Feb 07 jari 19
2 26 Feb 07 jari 20     /**
2 26 Feb 07 jari 21      * Constructs a <code>IntVectorParser</code>
2 26 Feb 07 jari 22      */
2 26 Feb 07 jari 23     public IntVectorParser() {}
2 26 Feb 07 jari 24
2 26 Feb 07 jari 25     /**
2 26 Feb 07 jari 26      * Parses space separated string of integers.
2 26 Feb 07 jari 27      */
2 26 Feb 07 jari 28     public int[] parse( String str ) throws ParserException {
2 26 Feb 07 jari 29         IntArray array = new IntArray(100);
2 26 Feb 07 jari 30         StringTokenizer st = new StringTokenizer(str);
2 26 Feb 07 jari 31         String token = null;
2 26 Feb 07 jari 32         try {
2 26 Feb 07 jari 33             while (st.hasMoreTokens()) {
2 26 Feb 07 jari 34                 token = st.nextToken();
2 26 Feb 07 jari 35                 array.add(Integer.parseInt(token));
2 26 Feb 07 jari 36             }
2 26 Feb 07 jari 37         } catch (NumberFormatException ex) {
2 26 Feb 07 jari 38             throw new ParserException( "Cannot parse " + token + " as integer value ", ex );
2 26 Feb 07 jari 39         }
2 26 Feb 07 jari 40         return array.toArray();
2 26 Feb 07 jari 41     }
2 26 Feb 07 jari 42 }
2 26 Feb 07 jari 43