Package java.lang

Examples of java.lang.StringBuffer


   * @param sDelimiter Delimiter for elements in resulting String
   * @return List joined as a String
   */
  public static String join (Collection oList, String sDelimiter) {
    // Join a Collection into a single String
    StringBuffer oBuff = new StringBuffer(oList.size()*(32+sDelimiter.length())+1);
    Iterator oIter = oList.iterator();
    boolean bFirst = true;
   
    while (oIter.hasNext()) {
      if (bFirst) {
        bFirst = false;
      } else {
        oBuff.append(sDelimiter);
      }
      oBuff.append(oIter.next());
    } // wend()

    oIter = null;

    return oBuff.toString();
  } // join
View Full Code Here


    final int iCount = aList.length;
    if (iCount==0) return "";
    if (null==sDelimiter) sDelimiter="";

    // Join an array into a single String
    StringBuffer oBuff = new StringBuffer(iCount*(32+sDelimiter.length())+1);
    oBuff.append(aList[0]);
    for (int s=1; s<iCount; s++) {
      oBuff.append(sDelimiter);
      oBuff.append(aList[s]);
    }
    return oBuff.toString();
  } // join
View Full Code Here

    if (len<0)
      throw new IndexOutOfBoundsException("Gadgets.fill() numbers of characters must be greater than or equal to zero");
    else if (len==0)
      return "";
    else {
      StringBuffer oStrBuff = new StringBuffer(len);
      for (int i=0; i<len; i++) oStrBuff.append(c);
      return oStrBuff.toString();
    }
  } // fill
View Full Code Here

   */
  public static String repeat (String sSubStr, int nTimes)
    throws IndexOutOfBoundsException {
    if (null==sSubStr) return null;
    if (sSubStr.length()==0) return "";
    StringBuffer oStrBuff = new StringBuffer(sSubStr.length()*nTimes);
    for (int t=0; t<nTimes; t++) oStrBuff.append(sSubStr);
    return oStrBuff.toString();
  } // repeat
View Full Code Here

   */
  public static String replace(String sSource, char cSought, String sNewVal) throws NullPointerException {
    if (null==sSource) return null;
    int nLen = sSource.length();
  if (0==nLen) return "";
    StringBuffer oOut = new StringBuffer(nLen+100);
    if (sNewVal.length()==0) {
      for (int c=0; c<nLen; c++) {
        char cAt = sSource.charAt(c);
        if (cAt!=cSought) oOut.append(cAt);
      } // next
    } else {
      for (int c=0; c<nLen; c++) {
        char cAt = sSource.charAt(c);
        if (cAt==cSought)
          oOut.append(sNewVal);
        else
          oOut.append(cAt);
      } // next
    }
    return oOut.toString();
  } // replace
View Full Code Here

    } else {
      final int iLen = sSource.length();
      ArrayList oTokens = new ArrayList();
      char cTextQualifier = (char) 0;
      char cCurrentChar;
      StringBuffer oCurrentToken = new StringBuffer(256);
      for (int p=0; p<iLen; p++) {
        cCurrentChar = sSource.charAt(p);
        switch (cCurrentChar) {
          case ' ':
            if (0!=cTextQualifier) {
              oCurrentToken.append(cCurrentChar);
            } else if (oCurrentToken.length()>0) {
              oTokens.add(oCurrentToken.toString());
              oCurrentToken.setLength(0);
            }
            break;
          case '\\':
            if (p==iLen-1) throw new StringIndexOutOfBoundsException("Input string terminated with a single backslash character");
            switch (sSource.charAt(++p)) {
              case 'n':
                oCurrentToken.append('\n');
                break;
              case 't':
                oCurrentToken.append('\t');
                break;
              case '\\':
                oCurrentToken.append('\\');
                break;
              case '"':
                oCurrentToken.append('"');
                break;
              default:
                throw new StringIndexOutOfBoundsException("Unrecognized escape sequence \\"+sSource.charAt(p)+" at "+sSource.substring(p-5>=0 ? p-5 : 0, p+5<=sSource.length()-1 ? p+5 : sSource.length()-1));
            } // end switch (charAt(++p))
            break;
          case '"':
            if (0==cTextQualifier) {
              cTextQualifier='"';
            } else if ('"'==cTextQualifier) {
              cTextQualifier=(char)0;
            }
            break;
          case '\'':
            if (0==cTextQualifier) {
              cTextQualifier='\'';
            } else if ('\''==cTextQualifier) {
              cTextQualifier=(char)0;
            }
            break;
          case ',':
          case ';':
          case '(':
          case ')':
          case '[':
          case ']':
          case '{':
          case '}':
          case '-':
          case '+':
          case '/':
          case '*':
          case '=':
          case '&':
          case '!':
          case '?':
            if (0!=cTextQualifier) {
              oCurrentToken.append(cCurrentChar);
            }
            else  {
              if (oCurrentToken.length()>0) {
                oTokens.add(oCurrentToken.toString());
                oCurrentToken.setLength(0);
              }
              oTokens.add(new String(new char[]{cCurrentChar}));
            }
            break;
          default:
            oCurrentToken.append(cCurrentChar);
        }
      } // next
      if (oCurrentToken.length()>0) {
        oTokens.add(oCurrentToken.toString());
      }
      aTokens=new String[oTokens.size()];
      System.arraycopy(oTokens.toArray(),0,aTokens,0,aTokens.length);
    }

    if (DebugFile.trace) {
      StringBuffer oOutput = new StringBuffer();
      if (aTokens!=null)
        for (int t=0; t<aTokens.length; t++)
          oOutput.append(aTokens[t]+(t<aTokens.length-1 ? "ΒΆ" :""));
      DebugFile.decIdent();
      DebugFile.writeln("End Gadgets.tokenizeCmdLine() : " + oOutput.toString());
    }

    return aTokens;
  } // tokenizeCmdLine
View Full Code Here

  public static String removeChar(String sInput, char cRemove) {
    if (null==sInput) return null;
    if (sInput.length()==0) return sInput;

    final int iLen = sInput.length();
    StringBuffer oOutput = new StringBuffer(iLen);

    for (int i=0; i<iLen; i++) {
      char c = sInput.charAt(i);
      if (cRemove!=c)
        oOutput.append(c);
    } // next

    return oOutput.toString();
  } // removeChar
View Full Code Here

    if (null==sRemove) return sInput;
    if (sInput.length()==0) return sInput;
    if (sRemove.length()==0) return sInput;

    final int iLen = sInput.length();
    StringBuffer oOutput = new StringBuffer(iLen);

    for (int i=0; i<iLen; i++) {
      char c = sInput.charAt(i);
      if (sRemove.indexOf(c)<0)
        oOutput.append(c);
    } // next

    return oOutput.toString();
  } // removeChars
View Full Code Here

    if (null==sInput) return null;
   
    final int nLen = sInput.length();
    if (nLen==0) return "";
   
    StringBuffer oOutput = new StringBuffer(nLen+100);
  char cAt;
  for (int c=0; c<nLen; c++) {
    cAt = sInput.charAt(c);
    if (sSpecialSet.indexOf(cAt)>=0)
    oOutput.append(cEsc);
    oOutput.append(cAt);
  } // next
  return oOutput.toString();
  } // escapeChars
View Full Code Here

        }
        return false;
    }
   
    public String getDescription() {
        StringBuffer buf = new StringBuffer();
        for (int i = 0; i < _extensions.size(); i++) {
            buf.append(_descriptions.get(i));
            buf.append(" (*.");
            buf.append(_extensions.get(i));
            buf.append(")");
            if (i < _extensions.size() - 1)
                buf.append("; ");
        }
        return buf.toString();
    }
View Full Code Here

TOP

Related Classes of java.lang.StringBuffer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.