List of usage examples for java.lang StringBuffer insert
@Override public StringBuffer insert(int offset, double d)
From source file:cn.org.awcp.core.utils.DateUtils.java
/** * ?<br>/*from w w w . j av a 2 s .c o m*/ * ??<br> * generate by: vakin jiang at 2012-3-1 * * @param dateStr * @return */ public static Date parseDate(String dateStr) { SimpleDateFormat format = null; if (StringUtils.isBlank(dateStr)) { return null; } String _dateStr = dateStr.trim(); try { if (_dateStr.matches("\\d{1,2}[A-Z]{3}")) { _dateStr = _dateStr + (Calendar.getInstance().get(Calendar.YEAR) - 2000); } // 01OCT12 if (_dateStr.matches("\\d{1,2}[A-Z]{3}\\d{2}")) { format = new SimpleDateFormat("ddMMMyy", Locale.ENGLISH); } else if (_dateStr.matches("\\d{1,2}[A-Z]{3}\\d{4}.*")) {// 01OCT2012 // ,01OCT2012 // 1224,01OCT2012 // 12:24 _dateStr = _dateStr.replaceAll("[^0-9A-Z]", "").concat("000000").substring(0, 15); format = new SimpleDateFormat("ddMMMyyyyHHmmss", Locale.ENGLISH); } else { StringBuffer sb = new StringBuffer(_dateStr); String[] tempArr = _dateStr.split("\\s+"); tempArr = tempArr[0].split("-|\\/"); if (tempArr.length == 3) { if (tempArr[1].length() == 1) { sb.insert(5, "0"); } if (tempArr[2].length() == 1) { sb.insert(8, "0"); } } _dateStr = sb.append("000000").toString().replaceAll("[^0-9]", "").substring(0, 14); if (_dateStr.matches("\\d{14}")) { format = new SimpleDateFormat("yyyyMMddHHmmss"); } } Date date = format.parse(_dateStr); return date; } catch (Exception e) { throw new RuntimeException("?[" + dateStr + "]"); } }
From source file:org.squale.squalecommon.util.mapping.Mapping.java
/** * Obtention du getter d'une mtrique La mthode est recherche dans la classe correspondante, la mthode est du * type getXxxx//from w w w . j a v a 2 s . c o m * * @param pMetric mtrique (par exemple mccabe.class.dit) * @return mthode d'accs cette mtrique (par exemple McCabeQAClassMetricsBO.getDit) * @throws IllegalArgumentException si pMetric mal form */ public static Method getMetricGetter(String pMetric) throws IllegalArgumentException { Method result = null; int index = pMetric.lastIndexOf('.'); if (index < 0) { throw new IllegalArgumentException("Metric name should be named tool.component.name"); } String measure = pMetric.substring(0, index); String metric = pMetric.substring(index + 1); // Obtention de la classe Class cl = getMeasureClass(measure); // Un log d'erreur aura t fait par la mthode // auparavant, inutile d'engorger le log if (cl != null) { try { // On forme le nom du getter StringBuffer methodName = new StringBuffer(metric); // Respect de la norme javabean pour le caractre en majuscules methodName.setCharAt(0, Character.toTitleCase(methodName.charAt(0))); methodName.insert(0, "get"); result = cl.getMethod(methodName.toString(), null); } catch (SecurityException e) { LOG.error("Getter not found " + pMetric, e); } catch (NoSuchMethodException e) { LOG.error("Getter not found " + pMetric, e); } } return result; }
From source file:com.nloko.android.Utils.java
public static String getMd5Hash(byte[] input) { if (input == null) { throw new IllegalArgumentException("input"); }/*www . ja v a 2 s . co m*/ try { MessageDigest md = MessageDigest.getInstance("MD5"); byte[] messageDigest = md.digest(input); BigInteger number = new BigInteger(1, messageDigest); //String md5 = number.toString(16); StringBuffer md5 = new StringBuffer(); md5.append(number.toString(16)); while (md5.length() < 32) { //md5 = "0" + md5; md5.insert(0, "0"); } return md5.toString(); } catch (NoSuchAlgorithmException e) { Log.e("MD5", e.getMessage()); return null; } }
From source file:pl.baczkowicz.spy.formatting.FormattingUtils.java
/** * Formats the given number into one where thousands are separated by a space. * //from w w w . j a v a 2 s.c om * @param number The number to format * @return Formatted string (e.g. "1 315 124" for 1315124) */ public static String formatNumber(final long number) { long divided = number; final StringBuffer sb = new StringBuffer(); while (divided > 1000) { long rest = divided % 1000; sb.insert(0, " " + String.format("%03d", rest)); divided = divided / 1000; } long rest = divided % 1000; sb.insert(0, rest); return sb.toString(); }
From source file:org.broadinstitute.sting.queue.extensions.gatk.GATKExtensionsGenerator.java
/** * Generates scala content using CLASS_TEMPLATE or TRAIT_TEMPLATE. * @param scalaTemplate CLASS_TEMPLATE or TRAIT_TEMPLATE * @param baseClass The class to extend from. * @param className The class name to generate. * @param constructor Additional logic for the constructor, or an empty string. * @param isScatter True if the class is scatter/gatherable. * @param commandLinePrefix Additional logic to prefix to the QCommandLine.commandLine, or an empty string. * @param argumentFields The list of argument fields for the generated class. * @param dependents A set that should be updated with explicit dependencies that need to be packaged. * @return The populated template./*w ww. ja va 2s .co m*/ */ private static String getContent(String scalaTemplate, String baseClass, String className, String constructor, boolean isScatter, String commandLinePrefix, List<? extends ArgumentField> argumentFields, Set<Class<?>> dependents) { StringBuilder arguments = new StringBuilder(); StringBuilder commandLine = new StringBuilder(commandLinePrefix); Set<String> importSet = new HashSet<String>(); boolean isGather = false; List<String> freezeFields = new ArrayList<String>(); for (ArgumentField argumentField : argumentFields) { arguments.append(argumentField.getArgumentAddition()); commandLine.append(argumentField.getCommandLineAddition()); importSet.addAll(argumentField.getImportStatements()); freezeFields.add(argumentField.getFreezeFields()); dependents.addAll(argumentField.getDependentClasses()); isGather |= argumentField.isGather(); } if (isScatter) { importSet.add("import org.broadinstitute.sting.queue.function.scattergather.ScatterGatherableFunction"); baseClass += " with ScatterGatherableFunction"; } if (isGather) importSet.add("import org.broadinstitute.sting.commandline.Gather"); // Sort the imports so that the are always in the same order. List<String> sortedImports = new ArrayList<String>(importSet); Collections.sort(sortedImports); StringBuffer freezeFieldOverride = new StringBuffer(); for (String freezeField : freezeFields) freezeFieldOverride.append(freezeField); if (freezeFieldOverride.length() > 0) { freezeFieldOverride.insert(0, String.format("override def freezeFieldValues() {%nsuper.freezeFieldValues()%n")); freezeFieldOverride.append(String.format("}%n%n")); } String importText = sortedImports.size() == 0 ? "" : NEWLINE + StringUtils.join(sortedImports, NEWLINE) + NEWLINE; // see CLASS_TEMPLATE and TRAIT_TEMPLATE below return String.format(scalaTemplate, GATK_EXTENSIONS_PACKAGE_NAME, importText, className, baseClass, constructor, arguments, freezeFieldOverride, commandLine); }
From source file:org.kuali.ext.mm.utility.BeanDDCreator.java
public static String camelCaseToString(String className) { StringBuffer newName = new StringBuffer(className); // upper case the 1st letter newName.replace(0, 1, newName.substring(0, 1).toUpperCase()); // loop through, inserting spaces when cap for (int i = 0; i < newName.length(); i++) { if (Character.isUpperCase(newName.charAt(i))) { newName.insert(i, ' '); i++;// www .j av a 2s.co m } } return newName.toString().trim().replace("Uc", "UC"); }
From source file:org.openkoala.koala.monitor.common.KoalaDateUtils.java
/** * ?<br>// w w w . j a v a 2 s. com * ??<br> * generate by: vakin jiang at 2012-3-1 * * @param dateStr * @return */ public static Date parseDate(String dateStr) { SimpleDateFormat format = null; if (StringUtils.isBlank(dateStr)) return null; String _dateStr = dateStr.trim(); try { if (_dateStr.matches("\\d{1,2}[A-Z]{3}")) { _dateStr = _dateStr + (Calendar.getInstance().get(Calendar.YEAR) - 2000); } // 01OCT12 if (_dateStr.matches("\\d{1,2}[A-Z]{3}\\d{2}")) { format = new SimpleDateFormat("ddMMMyy", Locale.ENGLISH); } else if (_dateStr.matches("\\d{1,2}[A-Z]{3}\\d{4}.*")) {// 01OCT2012 // ,01OCT2012 // 1224,01OCT2012 // 12:24 _dateStr = _dateStr.replaceAll("[^0-9A-Z]", "").concat("000000").substring(0, 15); format = new SimpleDateFormat("ddMMMyyyyHHmmss", Locale.ENGLISH); } else if (_dateStr.matches("\\d{4}.*")) { StringBuffer sb = new StringBuffer(_dateStr); String[] tempArr = _dateStr.split("\\s+"); tempArr = tempArr[0].split("-|\\/"); //2013-01 if (tempArr.length == 2) { if (tempArr[1].length() == 1) { sb.insert(5, "0"); } sb.append("01"); } else if (tempArr.length == 3) { if (tempArr[1].length() == 1) { sb.insert(5, "0"); } if (tempArr[2].length() == 1) { sb.insert(8, "0"); } } _dateStr = sb.append("00000000000000").toString().replaceAll("[^0-9]", "").substring(0, 14); if (_dateStr.matches("\\d{14}")) { format = new SimpleDateFormat("yyyyMMddHHmmss"); } } else { throw new RuntimeException("Not Support Date String format!"); } Date date = format.parse(_dateStr); return date; } catch (Exception e) { throw new RuntimeException("?[" + dateStr + "]"); } }
From source file:Main.java
public static String toHref(String title) { StringBuffer sb = new StringBuffer(title); Pattern pat = Pattern.compile(regex, Pattern.CASE_INSENSITIVE); Matcher mat = pat.matcher(title); int index = 0; int index1 = 0; while (mat.find()) { String url = mat.group(); //System.out.println(url); if (url.indexOf("http://") != 0) url = "http://" + url; Object obj[] = { "'" + url + "'" }; String a = MessageFormat.format(A1, obj); int l = a.length(); index += index1;// ww w .j av a 2 s . com sb.insert(mat.start() + index, a); index += l; sb.insert((mat.end()) + index, A2); index1 = A2.length(); } return sb.toString(); }
From source file:org.broadinstitute.gatk.queue.extensions.gatk.GATKExtensionsGenerator.java
/** * Generates scala content using CLASS_TEMPLATE or TRAIT_TEMPLATE. * @param scalaTemplate CLASS_TEMPLATE or TRAIT_TEMPLATE * @param baseClass The class to extend from. * @param className The class name to generate. * @param constructor Additional logic for the constructor, or an empty string. * @param isScatter True if the class is scatter/gatherable. * @param commandLinePrefix Additional logic to prefix to the QCommandLine.commandLine, or an empty string. * @param argumentFields The list of argument fields for the generated class. * @param dependents A set that should be updated with explicit dependencies that need to be packaged. * @return The populated template./* w w w. j av a2s .c om*/ */ private static String getContent(String scalaTemplate, String baseClass, String className, String constructor, boolean isScatter, String commandLinePrefix, List<? extends ArgumentField> argumentFields, Set<Class<?>> dependents) { StringBuilder arguments = new StringBuilder(); StringBuilder commandLine = new StringBuilder(commandLinePrefix); Set<String> importSet = new HashSet<String>(); boolean isGather = false; List<String> freezeFields = new ArrayList<String>(); for (ArgumentField argumentField : argumentFields) { arguments.append(argumentField.getArgumentAddition()); commandLine.append(argumentField.getCommandLineAddition()); importSet.addAll(argumentField.getImportStatements()); freezeFields.add(argumentField.getFreezeFields()); dependents.addAll(argumentField.getDependentClasses()); isGather |= argumentField.isGather(); } if (isScatter) { importSet.add("import org.broadinstitute.gatk.queue.function.scattergather.ScatterGatherableFunction"); baseClass += " with ScatterGatherableFunction"; } if (isGather) importSet.add("import org.broadinstitute.gatk.utils.commandline.Gather"); // Sort the imports so that the are always in the same order. List<String> sortedImports = new ArrayList<String>(importSet); Collections.sort(sortedImports); StringBuffer freezeFieldOverride = new StringBuffer(); for (String freezeField : freezeFields) freezeFieldOverride.append(freezeField); if (freezeFieldOverride.length() > 0) { freezeFieldOverride.insert(0, String.format("override def freezeFieldValues() {%nsuper.freezeFieldValues()%n")); freezeFieldOverride.append(String.format("}%n%n")); } String importText = sortedImports.size() == 0 ? "" : NEWLINE + StringUtils.join(sortedImports, NEWLINE) + NEWLINE; // see CLASS_TEMPLATE and TRAIT_TEMPLATE below return String.format(scalaTemplate, GATK_EXTENSIONS_PACKAGE_NAME, importText, className, baseClass, constructor, arguments, freezeFieldOverride, commandLine); }
From source file:ch.qos.logback.core.pattern.parser2.PatternParser.java
/** * Escapes regex characters in a substring. This is used to escape any regex * special chars in a layout pattern, which could be unintentionally * interpreted by the Java regex engine. * * @param s string buffer, containing the substring to be escaped; escape sequences are * inserted for literals in this buffer// w w w. j av a 2s . co m * @param start zero-based starting character position within {@code s} to be escaped * @param length number of characters of substring * @return number of new characters added to string buffer */ static private int escapeRegexChars(StringBuffer s, int start, int length) { String substr = s.substring(start, start + length); Matcher matcher = REGEX_CHARS_PATTERN.matcher(substr); int numNewChars = 0; while (matcher.find()) { s.insert(matcher.start() + numNewChars + start, ESC_SEQ); numNewChars += ESC_SEQ_LEN; } return numNewChars; }