Java Comma Separated List extractCommandsFromLine(final String line, final String delimiter, final StringBuilder bufferedCommand, final List extractedCommands)

Here you can find the source of extractCommandsFromLine(final String line, final String delimiter, final StringBuilder bufferedCommand, final List extractedCommands)

Description

Extracts SQL commands from string.

License

Apache License

Parameter

Parameter Description
line Line which is searched for SQL commands.
delimiter Delimiter that ends SQL command. Used for dividing specified string (line).
bufferedCommand Already buffered command from previous searches. If there's some buffered command, this method appends the first found delimited occurence to buffered command. If there's no buffered command and the string (line) not ends with delimiter, the last part is buffered.
extractedCommands Results list to which are found SQL commands added.

Declaration

private static void extractCommandsFromLine(final String line, final String delimiter,
        final StringBuilder bufferedCommand, final List<String> extractedCommands) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.List;

public class Main {
    /**/*from  www.  java2 s  .com*/
     * Extracts SQL commands from string. Divides the string (line) by specified delimiter
     * and adds found whole commands to extractedCommands or buffers unfinished commands.
     * @param line Line which is searched for SQL commands.
     * @param delimiter Delimiter that ends SQL command. Used for dividing specified string (line).
     * @param bufferedCommand Already buffered command from previous searches.
     *                        If there's some buffered command, this method appends the first
     *                        found delimited occurence to buffered command.
     *                        If there's no buffered command and the string (line) not ends
     *                        with delimiter, the last part is buffered.
     * @param extractedCommands Results list to which are found SQL commands added.
     */
    private static void extractCommandsFromLine(final String line, final String delimiter,
            final StringBuilder bufferedCommand, final List<String> extractedCommands) {
        final String[] lineParts = line.split(delimiter);
        for (int i = 0; i < lineParts.length; i++) {
            // If there's some buffered command, append first found line part to it.
            if (i == 0) {
                extractedCommands.add(bufferedCommand.toString() + " " + lineParts[i]);
                bufferedCommand.setLength(0);
                bufferedCommand.trimToSize();
            } else {
                // If the line doesn't end with delimiter, buffer the last line part.
                if (i == (lineParts.length - 1) && !line.endsWith(delimiter)) {
                    bufferedCommand.append(lineParts[i]);
                } else {
                    extractedCommands.add(lineParts[i]);
                }
            }
        }
    }
}

Related

  1. commaStringToList(String inputString)
  2. convertCommaDelimitedStringToList(String s)
  3. ConvertDiscussionGroupListToCommaString( List list)
  4. convertToStringList(String valuesCommaSeparated)
  5. extractCommaItems(List list, String tags)
  6. formatCommand(List arguments)
  7. getAsCommaDelimitedString(List coll)
  8. getCommaList(List V)
  9. getCommandLine(List command)