Example usage for java.lang StringBuffer setLength

List of usage examples for java.lang StringBuffer setLength

Introduction

In this page you can find the example usage for java.lang StringBuffer setLength.

Prototype

@Override
public synchronized void setLength(int newLength) 

Source Link

Usage

From source file:nz.co.jsrsolutions.ds3.command.GetExchangeSymbolQuotesCommand.java

public boolean execute(Context context) throws Exception {

    logger.info("Executing: getexchangesymbolquotes");

    EodDataProvider eodDataProvider = (EodDataProvider) context.get(CommandContext.EODDATAPROVIDER_KEY);
    EodDataSink eodDataSink = (EodDataSink) context.get(CommandContext.EODDATASINK_KEY);
    String exchange = (String) context.get(CommandContext.EXCHANGE_KEY);
    String symbol = (String) context.get(CommandContext.SYMBOL_KEY);

    if (exchange == null) {
        throw new CommandException("Must supply --exchange [exchangecode]");
    }//  w  ww. jav a 2  s .  c o  m

    if (symbol == null) {
        throw new CommandException("Must supply --symbol [symbolcode]");
    }

    @SuppressWarnings("unused")
    long nQuotesWritten = 0;

    final int availableMonths = eodDataProvider.getExchangeMonths(exchange);
    // final SYMBOL[] symbols = eodDataProvider.getSymbols(exchange);
    final String[] symbols = eodDataSink.readExchangeSymbols(exchange);

    if (symbols == null) {
        logger.info("No symbols associated with this exchange...");
        return false;
    }

    final Calendar firstAvailableDateTime = Calendar.getInstance();

    if (availableMonths > 0) {
        firstAvailableDateTime.add(Calendar.MONTH, -1 * 1);
        firstAvailableDateTime.add(Calendar.DATE, 1);
    }

    final Calendar plusOneDay = (Calendar) firstAvailableDateTime.clone();
    plusOneDay.add(Calendar.DAY_OF_MONTH, 1);

    if (logger.isInfoEnabled()) {

        StringBuffer logMessageBuffer = new StringBuffer();
        logMessageBuffer.setLength(0);
        logMessageBuffer.append(" Attempting to retrieve quotes on [ ");
        logMessageBuffer.append(exchange);
        logMessageBuffer.append(" ] for [ ");
        logMessageBuffer.append(symbol);
        logMessageBuffer.append(" ] between [ ");
        logMessageBuffer.append(firstAvailableDateTime.getTime().toString());
        logMessageBuffer.append(" ] and [ ");
        logMessageBuffer.append(plusOneDay.getTime().toString());
        logMessageBuffer.append(" ] ");
        logger.info(logMessageBuffer.toString());

    }

    final QUOTE[] quotes = eodDataProvider.getQuotes(exchange, symbol, firstAvailableDateTime, plusOneDay,
            DEFAULT_FREQUENCY);

    if (quotes == null || quotes.length == 0) {
        logger.info("Quote array from provider was empty!");
        return false;
    }

    for (QUOTE quote : quotes) {
        StringBuffer logMessageBuffer = new StringBuffer();
        logMessageBuffer.append("Quote date: [ ");
        logMessageBuffer.append(quote.getDateTime().getTime().toString());
        logMessageBuffer.append(" ]");
        logger.info(logMessageBuffer.toString());

    }

    return false;

}

From source file:org.jbpm.bpel.xml.util.XmlUtil.java

public static String generatePrefix(String base, Element contextElem) {
    // check possible collision with namespace declarations
    if (!contextElem.hasAttributeNS(BpelConstants.NS_XMLNS, base))
        return base;

    // collision detected, append a discriminator number
    StringBuffer prefixBuffer = new StringBuffer(base);

    for (int i = 1; i < Integer.MAX_VALUE; i++) {
        String prefix = prefixBuffer.append(i).toString();

        if (!contextElem.hasAttributeNS(BpelConstants.NS_XMLNS, prefix))
            return prefix;

        // remove appended number
        prefixBuffer.setLength(base.length());
    }/*from   w w  w . j  a  va2  s  . c om*/

    throw new Error("could not generate prefix from base: " + base);
}

From source file:com.concursive.connect.web.modules.search.utils.SearchUtils.java

/**
 * Description of the Method// w w w. j  a  v  a 2s  . co  m
 *
 * @param searchText Description of the Parameter
 * @return Description of the Return Value
 */
public static ArrayList<String> parseSearchTerms(String searchText) {
    ArrayList<String> terms = new ArrayList<String>();
    StringBuffer sb = new StringBuffer();
    boolean returnTokens = true;
    String currentDelims = WHITESPACE_AND_QUOTES;
    StringTokenizer parser = new StringTokenizer(searchText, currentDelims, returnTokens);
    String token = null;
    while (parser.hasMoreTokens()) {
        token = parser.nextToken(currentDelims);
        if (!isDoubleQuote(token)) {
            if (hasText(token)) {
                String gotToken = token.trim().toLowerCase();
                if ("and".equals(gotToken) || "or".equals(gotToken) || "not".equals(gotToken)) {
                } else {
                    if (sb.length() > 0) {
                        sb.append(" ");
                    }
                    sb.append(gotToken);
                    terms.add(sb.toString());
                    sb.setLength(0);
                }
            }
        } else {
            currentDelims = flipDelimiters(currentDelims);
        }
    }
    return terms;
}

From source file:org.gcaldaemon.core.ldap.ContactLoader.java

private static final GmailContact parseLine(String line) {
    if (line.length() == 0) {
        return null;
    }//from w ww  . j a  v  a 2  s  .  c o  m

    // Create contact container (GmailContact)
    GmailContact contact = new GmailContact();
    StringBuffer buffer = new StringBuffer();
    int offset = 0;
    int index = 0;
    String value;
    do {
        buffer.setLength(0);
        if (offset < line.length() && line.charAt(offset) == '"') {

            // Parse quoted value (e.g. "Tom McCain", "xy@foo.com")
            offset = parseSeparatedValue(line, buffer, ++offset);
        } else {

            // Parse simple value (e.g. Tom, xy@foo.com, etc)
            offset = parsePlainValue(line, buffer, offset);
        }
        value = buffer.toString();
        switch (index) {
        case 0:

            // Set the 'name' field
            contact.name = value;
            break;
        case 1:

            // Set the 'email' field
            contact.email = value;
            break;
        case 2:

            // Set the 'notes' field
            contact.notes = value;
            break;
        case 3:

            // Set the 'description' field
            contact.description = value;
            break;
        case 4:

            // Set the 'mail' field
            contact.mail = value;
            break;
        case 5:

            // Set the 'im' field
            contact.im = value;
            break;
        case 6:

            // Set the 'phone' field
            contact.phone = value;
            break;
        case 7:

            // Set the 'mobile' field
            contact.mobile = value;
            break;
        case 8:

            // Set the 'pager' field
            contact.pager = value;
            break;
        case 9:

            // Set the 'fax' field
            contact.fax = value;
            break;
        case 10:

            // Set the 'company' field
            contact.company = value;
            break;
        case 11:

            // Set the 'title' field
            contact.title = value;
            break;
        case 12:

            // Set the 'other' field
            contact.other = value;
            break;
        case 13:

            // Set the 'address' field
            contact.address = value;
            break;
        }
        offset++;
        index++;
        if (index == 14) {
            break;
        }
    } while (offset < line.length());
    return contact;
}

From source file:org.springmodules.validation.valang.functions.BeanPropertyFunction.java

private String concat(String[] path) {
    StringBuffer sb = new StringBuffer();

    for (int i = 0; i < path.length; i++) {
        sb.append(path[i]);/*from   w  w  w .ja  v a2s.  com*/
        sb.append(".");
    }

    sb.setLength(sb.length() - 1);
    return sb.toString();
}

From source file:Main.java

/**
/* FindAndReplace - finds and replaces in StringBuffer theSBuffer,
/*   starts at fromIndex, returns index of find.
 * //from  ww w  .  j  a va  2  s.c om
 * @param findString, replaceString, sBuffer, index
 * @return int
 * 
 */
public static int FindAndReplace(String find, String replace, StringBuffer theSBuffer, int fromIndex) {

    String interString;
    int theIndex, i, j;

    if (find == null)
        return -1;
    if (replace == null)
        return -1;
    if (theSBuffer == null)
        return -1;
    int theSBufferLength = theSBuffer.length();
    int findLength = find.length();
    if (theSBufferLength == 0)
        return -1;
    if (findLength == 0)
        return -1;
    if (theSBufferLength < findLength)
        return -1;
    if ((fromIndex < 0) || (fromIndex > theSBufferLength))
        return -1;

    interString = theSBuffer.toString();
    theIndex = interString.indexOf(find, fromIndex);
    if (theIndex == -1)
        return -1;

    //// on 9210 the following code ...
    for (i = theIndex; i < theSBufferLength - findLength; i++) {
        theSBuffer.setCharAt(i, theSBuffer.charAt(i + findLength));
    }
    for (j = theSBufferLength - 1; j >= (theSBufferLength - findLength); j--) {
        theSBuffer.setCharAt(j, (char) (0));
    }
    int newLength = theSBufferLength - findLength;
    theSBuffer.setLength(newLength);
    theSBuffer.insert(theIndex, replace);
    return theIndex;
}

From source file:com.github.guava.JoinerPractice.java

private String mapJoinWith(Map<?, ?> map, String keyValueSeparator, String separator) {
    StringBuffer stringBuffer = new StringBuffer();
    for (Object key : map.keySet()) {
        stringBuffer.append(key).append(keyValueSeparator).append(map.get(key)).append(separator);
    }/*from ww  w.jav  a  2 s  . c o  m*/
    stringBuffer.setLength(stringBuffer.length() - separator.length());
    return stringBuffer.toString();
}

From source file:CreateEmployeeFile.java

void write(RandomAccessFile raf) throws IOException {
    StringBuffer sb;
    if (lastName != null)
        sb = new StringBuffer(lastName);
    else//from   ww  w  . j  av a2  s. com
        sb = new StringBuffer();

    sb.setLength(15);
    raf.writeChars(sb.toString());

    if (firstName != null)
        sb = new StringBuffer(firstName);
    else
        sb = new StringBuffer();

    sb.setLength(15);
    raf.writeChars(sb.toString());

    if (address != null)
        sb = new StringBuffer(address);
    else
        sb = new StringBuffer();

    sb.setLength(30);
    raf.writeChars(sb.toString());
    raf.writeByte(age);
    raf.writeDouble(salary);
}

From source file:edu.northwestern.bioinformatics.studycalendar.web.taglibs.jsgenerator.ElementUpdatingGenerator.java

protected String call(String method, Object... parameters) {
    StringBuffer call = new StringBuffer(method).append('(');
    for (Object parameter : parameters) {
        call.append(createJavascriptLiteralRepresentation(parameter)).append(", ");
    }/*from   w w w.j  ava2  s  .  c  o m*/
    call.setLength(call.length() - 2);
    call.append(')');
    return call.toString();
}

From source file:com.digitalgeneralists.assurance.model.compare.file.FileCompareValidator.java

protected boolean areFilesComparable(File file1, File file2) {
    if ((file1 == null) || (file2 == null)) {
        StringBuffer message = new StringBuffer(512);
        logger.info(message.append("One or more files is not a valid file instance - File 1: ").append(file1)
                .append(" File 2: ").append(file2));
        message.setLength(0);
        message = null;/*ww w  .  j a  va2 s . com*/
        return false;
    }

    return true;
}