/** * Splits a given string at the given separator string. Duplicate separators will result in empty strings thus * preserving the number of fields specified in the original string. * * @param string the text to be split. * @param separator the separator chacters used for the split. * @param quate the quoting character. * @return the splitted array. */ public static String[] splitCSV( final String string, final String separator, final String quate ) { final CSVTokenizer strtok = new CSVTokenizer( string, separator, quate, false ); final String[] tokens = new String[ strtok.countTokens() ]; int i = 0; while ( strtok.hasMoreTokens() ) { final String token = strtok.nextToken(); tokens[ i ] = ( token ); i += 1; } return tokens; }
/** * Returns the schema portion of the serialized ResourceKey string. If the string is invalid, <code>null</code> will * be returned. * * @param data the String serialized version of a <code>ResourceKey</code> * @return the schema object. */ public static Object readSchemaFromString( final String data ) { if ( data == null ) { return null; } final CSVTokenizer tokenizer = new CSVTokenizer( data, DELIMITER, "\"", false ); if ( tokenizer.hasMoreElements() == false ) { return null; } final String tempData = tokenizer.nextToken(); if ( tempData.startsWith( SERIALIZATION_PREFIX ) ) { return tempData.substring( SERIALIZATION_PREFIX.length() ); } return null; }
/** * Calculates the number of times that this tokenizer's <code>nextToken</code> method can be called before it * generates an exception. The current position is not advanced. * * @return the number of tokens remaining in the string using the current delimiter set. * @see CSVTokenizer#nextToken() */ public int countTokens() { int count = 0; final int preserve = this.currentIndex; final boolean preserveStart = this.beforeStart; while ( this.hasMoreTokens() ) { this.nextToken(); count++; } this.currentIndex = preserve; this.beforeStart = preserveStart; return count; }
private Object parseStringDefaultParam( String defaultValue, CSVTokenizer csvt ) { if ( csvt.countTokens() == 1 ) { return csvt.nextToken(); } else { ArrayList<String> vals = new ArrayList<String>(); while ( csvt.hasMoreTokens() ) { String token = csvt.nextToken(); vals.add( token ); } return vals.toArray( new String[0] ); } }
/** * Looks up the property with the given name. This replaces the name with the current index position. * * @param name * the name of the property to look up. * @return the translated value. */ protected String lookupVariable( final String name ) { final CSVTokenizer tokenizer = new CSVTokenizer( name, false ); if ( tokenizer.hasMoreTokens() == false ) { return null; } final String varName = tokenizer.nextToken(); final StringBuilder b = new StringBuilder( name.length() ); b.append( '{' ); b.append( String.valueOf( fields.size() ) ); while ( tokenizer.hasMoreTokens() ) { b.append( ',' ); b.append( tokenizer.nextToken() ); } b.append( '}' ); final String formatString = b.toString(); fields.add( varName ); return formatString; }
final CSVTokenizer tokenizer = new CSVTokenizer( factoryParameters, ":", "\"", false ); while ( tokenizer.hasMoreTokens() ) { final String entry = tokenizer.nextToken(); final CSVTokenizer innerTokenizer = new CSVTokenizer( entry, "=", "\"", false ); final ParameterKey key; if ( innerTokenizer.hasMoreElements() ) { final String keyString = innerTokenizer.nextToken(); if ( keyString.startsWith( "f:" ) ) { key = new FactoryParameterKey( keyString.substring( 2 ) ); if ( innerTokenizer.hasMoreElements() ) { final Object value = innerTokenizer.nextToken(); if ( "".equals( value ) ) { params.put( key, null );
final CSVTokenizer csvTokenizer = new CSVTokenizer( String.valueOf( s ), ",", "\"", false ); final int length = csvTokenizer.countTokens(); final String[] rolesArray = new String[length]; for ( int i = 0; i < length; i += 1 ) { rolesArray[i] = csvTokenizer.nextToken();
strtok = strtokenizer; } else { final CSVTokenizer strtokenizer = new CSVTokenizer( sequence, separator, quote, false ); resultList = new ArrayList( strtokenizer.countTokens() ); strtok = strtokenizer;
private String[] splitLine( final String line, final boolean trim ) { final ArrayList row = new ArrayList(); final CSVTokenizer tokenizer = new CSVTokenizer( line, getSeparator(), "\"", trim ); while ( tokenizer.hasMoreElements() ) { final String o = (String) tokenizer.nextElement(); if ( trim ) { row.add( o.trim() ); } else { row.add( o ); } } return (String[]) row.toArray( new String[row.size()] ); }
public String[] toArray() { final ArrayList<String> retval = new ArrayList<String>( 20 ); while ( hasMoreElements() ) { retval.add( nextToken() ); } return (String[]) retval.toArray(); } }
/** * Returns the same value as the <code>hasMoreTokens</code> method. It exists so that this class can implement the * <code>Enumeration</code> interface. * * @return <code>true</code> if there are more tokens; <code>false</code> otherwise. * @see Enumeration * @see CSVTokenizer#hasMoreTokens() */ public boolean hasMoreElements() { return hasMoreTokens(); }
/** * Returns the same value as the <code>nextToken</code> method, except that its declared return value is * <code>Object</code> rather than <code>String</code>. It exists so that this class can implement the * <code>Enumeration</code> interface. * * @return the next token in the string. * @throws NoSuchElementException if there are no more tokens in this tokenizer's string. * @see Enumeration * @see CSVTokenizer#nextToken() */ public Object nextElement() { return nextToken(); }
protected Object parseDefaultValue( String defaultValue, DataType dataType ) { if ( defaultValue == null ) { return null; } CSVTokenizer csvt = new CSVTokenizer( defaultValue, "|", "\"", true ); switch ( dataType ) { case BOOLEAN: return parseBooleanDefaultParam( defaultValue, csvt ); case NUMERIC: return parseDoubleDefaultParam( defaultValue, csvt ); default: return parseStringDefaultParam( defaultValue, csvt ); } }
protected String lookupVariable( final String entity ) { // first, split the entity into separate strings (separator is '.'). final CSVTokenizer tokenizer = new CSVTokenizer( entity, "." ); if ( tokenizer.hasMoreTokens() ) { final String name = tokenizer.nextToken(); final Object base = performInitialLookup( name ); try { if ( tokenizer.hasMoreTokens() ) { return BeanPropertyLookupParser.continueLookupVariable( tokenizer, base ); } else { return ConverterRegistry.toAttributeValue( base ); } } catch ( BeanException e ) { return entity; } } return entity; }
private Object parseBooleanDefaultParam( String defaultValue, CSVTokenizer csvt ) { if ( csvt.countTokens() == 1 ) { return Boolean.parseBoolean( csvt.nextToken() ); } else { ArrayList<Boolean> vals = new ArrayList<Boolean>(); while ( csvt.hasMoreTokens() ) { String token = csvt.nextToken(); vals.add( Boolean.parseBoolean( token ) ); } return vals.toArray( new Boolean[0] ); } }
/** * Calculates the number of times that this tokenizer's <code>nextToken</code> method can be called before it * generates an exception. The current position is not advanced. * * @return the number of tokens remaining in the string using the current delimiter set. * @see CSVTokenizer#nextToken() */ public int countTokens() { int count = 0; final int preserve = this.currentIndex; final boolean preserveStart = this.beforeStart; while (this.hasMoreTokens()) { this.nextToken(); count++; } this.currentIndex = preserve; this.beforeStart = preserveStart; return count; }
final CSVTokenizer strtokenizer = new CSVTokenizer(sequence, separator, quote, false); resultList = new ArrayList(strtokenizer.countTokens()); strtok = strtokenizer;
public String[] toArray() { final ArrayList<String> retval = new ArrayList<String>(20); while (hasMoreElements()) { retval.add(nextToken()); } return (String[]) retval.toArray(); } }
/** * Returns the same value as the <code>hasMoreTokens</code> method. It exists so that this class can implement the * <code>Enumeration</code> interface. * * @return <code>true</code> if there are more tokens; <code>false</code> otherwise. * @see Enumeration * @see CSVTokenizer#hasMoreTokens() */ public boolean hasMoreElements() { return hasMoreTokens(); }
/** * Returns the same value as the <code>nextToken</code> method, except that its declared return value is * <code>Object</code> rather than <code>String</code>. It exists so that this class can implement the * <code>Enumeration</code> interface. * * @return the next token in the string. * @throws NoSuchElementException if there are no more tokens in this tokenizer's string. * @see Enumeration * @see CSVTokenizer#nextToken() */ public Object nextElement() { return nextToken(); }