/** * 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>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(); }
/** * 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 parseDoubleDefaultParam( String defaultValue, CSVTokenizer csvt ) { if ( csvt.countTokens() == 1 ) { return Double.parseDouble( csvt.nextToken() ); } else { ArrayList<Double> vals = new ArrayList<Double>(); while ( csvt.hasMoreTokens() ) { String token = csvt.nextToken(); vals.add( Double.parseDouble( token ) ); } return vals.toArray( new Double[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; }
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] ); } }
/** * 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; }
private static String continueLookupVariable( final CSVTokenizer tokenizer, final Object parent ) throws BeanException { if ( tokenizer.hasMoreTokens() ) { final String name = tokenizer.nextToken(); final Object base = ConverterRegistry.toPropertyValue( name, parent.getClass() ); if ( tokenizer.hasMoreTokens() ) { return continueLookupVariable( tokenizer, base ); } else { return ConverterRegistry.toAttributeValue( base ); } } return null; }
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] ); } }
while ( tokenizer.hasMoreTokens() ) { final String token = tokenizer.nextToken(); if ( token == null || token.length() == 0 ) {
public List<List<String>> parseSampleContents() { String delim = getDelimiter(); if ( contents == null ) { throw new IllegalStateException( "Sample Contents is null, nothing to parse" ); //$NON-NLS-1$ } else if ( delim == null || "".equals( delim ) ) { //$NON-NLS-1$ // use a random delimiter that will result in an un-parsed list delim = "~!@#$%"; } List<List<String>> sample = new ArrayList<List<String>>(); CSVTokenizer csvTokenizer; String enclosure = null; if ( !"".equals( getEnclosure() ) ) { enclosure = getEnclosure(); } for ( String line : contents ) { csvTokenizer = new CSVTokenizer( line, delim, enclosure ); List<String> rowData = new ArrayList<String>(); while ( csvTokenizer.hasMoreTokens() ) { // get next token and store it in the list rowData.add( csvTokenizer.nextToken() ); } sample.add( rowData ); } return sample; }
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; }
/** * Splits a given string at the given separator string. Duplicate separators will be merged into a single separator * occurance. * * @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[] split( 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(); if ( token.length() > 0 ) { tokens[ i ] = ( token ); i += 1; } } if ( i == tokens.length ) { return tokens; } final String[] retval = new String[ i ]; System.arraycopy( tokens, 0, retval, 0, i ); return retval; }
final String[] tokens = new String[strtok.countTokens()]; int i = 0; while (strtok.hasMoreTokens())
/** * Creates the list of column names that should be mapped into the method or constructor parameters. * * @param query * the query-string. * @param parameterStartIdx * the index from where to read the parameter list. * @return an array with column names. * @throws ReportDataFactoryException * if something goes wrong. */ private String[] createParameterList( final String query, final int parameterStartIdx ) throws ReportDataFactoryException { final int parameterEndIdx = query.lastIndexOf( ')' ); if ( parameterEndIdx < parameterStartIdx ) { throw new ReportDataFactoryException( "Malformed query: " + query ); //$NON-NLS-1$ } final String parameterText = query.substring( parameterStartIdx + 1, parameterEndIdx ); final CSVTokenizer tokenizer = new CSVTokenizer( parameterText, ",", "\"", false ); final int size = tokenizer.countTokens(); final String[] parameterNames = new String[size]; int i = 0; while ( tokenizer.hasMoreTokens() ) { parameterNames[i] = tokenizer.nextToken(); i += 1; } return parameterNames; }
/** * 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; }
/** * 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; }
count = 0; while ( csvt.hasMoreTokens() ) {
/** * Boots modules, which have been spcified in the "org.pentaho.reporting.engine.classic.core.boot.Modules" * configuration parameter. */ private void bootAdditionalModules() { try { final String bootModules = getGlobalConfig().getConfigProperty( "org.pentaho.reporting.engine.classic.core.boot.Modules" ); // NON-NLS if ( bootModules != null ) { final CSVTokenizer csvToken = new CSVTokenizer( bootModules, "," ); while ( csvToken.hasMoreTokens() ) { final String token = csvToken.nextToken(); getPackageManager().load( token ); } } } catch ( SecurityException se ) { // we'll ignore any Security exception .. ClassicEngineBoot.logger.info( "Security settings forbid to check the system properties for extension modules." ); // NON-NLS } catch ( Exception se ) { ClassicEngineBoot.logger.error( "An error occured while checking the system properties for extension modules.", // NON-NLS se ); } }
public void testCSVTokenizer() { final String example = "\"Test\""; final CSVTokenizer tokenizer = new CSVTokenizer( example, false ); assertTrue( "Tokenizer has at least one element", tokenizer.hasMoreTokens() ); assertEquals( tokenizer.nextToken(), "Test" ); }