List of usage examples for java.lang StringBuffer insert
@Override public StringBuffer insert(int offset, double d)
From source file:ExposedInt.java
void UpdateNumberFields() { decimalField.setText(Integer.toString(value)); int v = value; StringBuffer buf = new StringBuffer(); for (int i = 0; i < 8; ++i) { // Get lowest bit int remainder = v & 0xf; // Convert bit to a character and insert it into the beginning of the string switch (remainder) { case 0://from ww w .ja v a 2s . c o m buf.insert(0, "0"); break; case 1: buf.insert(0, "1"); break; case 2: buf.insert(0, "2"); break; case 3: buf.insert(0, "3"); break; case 4: buf.insert(0, "4"); break; case 5: buf.insert(0, "5"); break; case 6: buf.insert(0, "6"); break; case 7: buf.insert(0, "7"); break; case 8: buf.insert(0, "8"); break; case 9: buf.insert(0, "9"); break; case 10: buf.insert(0, "a"); break; case 11: buf.insert(0, "b"); break; case 12: buf.insert(0, "c"); break; case 13: buf.insert(0, "d"); break; case 14: buf.insert(0, "e"); break; case 15: buf.insert(0, "f"); break; } // Shift the int to the right one bit v >>>= 4; } hexField.setText(buf.toString()); v = value; buf.setLength(0); for (int i = 0; i < 32; ++i) { // Get lowest bit int remainder = v & 0x1; // Convert bit to a character and insert it into the beginning of the string if (remainder == 0) { buf.insert(0, "0"); } else { buf.insert(0, "1"); } // Shift the int to the right one bit v >>>= 1; } binaryField.setText(buf.toString()); }
From source file:com.huguesjohnson.sega32xcollector.ebay.EbayUtils.java
private String formatCurrency(String amount, String currencyCode) { StringBuffer formattedText = new StringBuffer(amount); try {/*from www. jav a 2 s.co m*/ //add trailing zeros int indexOf = formattedText.indexOf("."); if (indexOf >= 0) { if (formattedText.length() - indexOf == 2) { formattedText.append("0"); } } //add dollar sign if (currencyCode.equalsIgnoreCase("USD")) { formattedText.insert(0, "$"); } else { formattedText.append(" "); formattedText.append(currencyCode); } } catch (Exception x) { Log.e(TAG, "formatCurrency", x); } return (formattedText.toString()); }
From source file:com.dream.messaging.engine.fixformat.FixformatDataHandler.java
@Override public Object createValue(Object msgData, Node node) throws DataConvertException { Object result = null;//from w w w . j a va 2 s . c o m if (msgData instanceof byte[]) { // parser the byte[] to a String which presents the object value String clsname = QueryNode.getAttribute(node, ElementAttr.Attr_Class); boolean isNumber = this.isNumber(clsname); String encoding = (String) this.engine.getProperties().get(FixformatMessageEngine.ENCORDING); String type = isNumber ? FixformatMessageEngine.NUMBER : FixformatMessageEngine.TEXT; boolean fromLeft = Boolean.getBoolean( (String) this.engine.getProperties().get(type + FixformatMessageEngine.START_FROM_LEFT)); String fillUpWith = (String) this.engine.getProperties() .get(type + FixformatMessageEngine.FILL_UP_WITH); String aString = null; try { aString = new String((byte[]) msgData, encoding); } catch (UnsupportedEncodingException e) { throw new DataConvertException("encoding " + encoding + " is not supported,please check it.", e); } // remove fill up if (fromLeft) { aString = StringUtils.stripEnd(aString, fillUpWith); } else { aString = StringUtils.stripStart(aString, fillUpWith); } // check if the string empty if (StringUtils.isEmpty(aString)) { if (isNumber) { aString = "0"; } else { aString = ""; } return this.createValue(aString, node); } if (isNumber) { // remove sign String sign = ""; if (aString.equals("+") || aString.equals("-")) { aString = aString + "0"; } if (aString.endsWith("+") || aString.endsWith("-")) { sign = aString.substring(aString.length() - 1); aString = sign + aString.substring(0, aString.length() - 1); } if (clsname.equalsIgnoreCase(ElementClassType.CLASS_DECIMAL) || clsname.equalsIgnoreCase(ElementClassType.CLASS_FLOAT) || (clsname.equalsIgnoreCase(ElementClassType.CLASS_DOUBLE))) { String format = QueryNode.getAttribute(node, ElementAttr.Attr_Format); int index = format.indexOf('p'); if (index < 0) { index = format.indexOf('P'); } int fractionLen = Integer.valueOf(format.substring(index + 1)); if (aString.length() - fractionLen > 0) { aString = aString.substring(0, aString.length() - fractionLen) + "." + aString.substring(aString.length() - fractionLen); } else { StringBuffer sb = new StringBuffer(aString); while (sb.length() < fractionLen) { sb.insert(0, fillUpWith); } aString = sb.toString(); aString = "0." + aString; } } } result = this.createValue(aString, node); } else { throw new UnsupportedOperationException("The object for createValue must be a byte array"); } return result; }
From source file:net.sourceforge.dvb.projectx.common.Common.java
/** * *//*from w w w. j a v a 2 s . c om*/ public static String adaptString(String str, int len) { StringBuffer strbuf = new StringBuffer(str.trim()); while (strbuf.length() < len) strbuf.insert(0, "0"); return strbuf.toString(); }
From source file:com.esofthead.mycollab.utils.AuditLogPrinter.java
public String generateChangeSet(SimpleAuditLog auditLog) { StringBuffer str = new StringBuffer(""); boolean isAppended = false; List<AuditChangeItem> changeItems = auditLog.getChangeItems(); if (CollectionUtils.isNotEmpty(changeItems)) { for (AuditChangeItem item : changeItems) { String fieldName = item.getField(); FieldDisplayHandler fieldDisplayHandler = groupFormatter.getFieldDisplayHandler(fieldName); if (fieldDisplayHandler != null) { isAppended = true;/*from w w w . j ava 2 s . co m*/ str.append(fieldDisplayHandler.generateLogItem(item)); } } } if (isAppended) { str.insert(0, "<p>").insert(0, "<ul>"); str.append("</ul>").append("</p>"); } return str.toString(); }
From source file:org.elasticsoftware.elasterix.server.actors.User.java
private String generateNonce() { // a value between 10M and 100M long nonce = (10000000 + ((long) (Math.random() * 90000000.0))); // add 5 random characters at random places... StringBuffer sb = new StringBuffer(Long.toString(nonce)); for (int i = 0; i < 5; i++) { char c = CHARACTERS[(int) ((double) (CHARACTERS.length - 1) * Math.random())]; int idx = (int) (Math.random() * (double) (sb.length() - 1)); sb.insert(idx, c); }/* w w w . j a v a2 s.c om*/ return sb.toString(); }
From source file:org.osaf.cosmo.atom.generator.BaseItemFeedGenerator.java
protected void addPathInfo(StringBuffer iri, String pathInfo) { // if there's a query string, insert the projection just // before it/*from w w w . j a va 2 s.c o m*/ int qm = iri.indexOf("?"); if (qm > 0) iri.insert(qm, '/').insert(qm + 1, pathInfo); else iri.append('/').append(pathInfo); }
From source file:com.espertech.esper.epl.expression.ExprNode.java
private ExprNode resolveStaticMethodOrField(ExprIdentNode identNode, StreamTypeService streamTypeService, MethodResolutionService methodResolutionService, ExprValidationException propertyException, TimeProvider timeProvider, VariableService variableService, ExprEvaluatorContext exprEvaluatorContext) throws ExprValidationException { // Reconstruct the original string StringBuffer mappedProperty = new StringBuffer(identNode.getUnresolvedPropertyName()); if (identNode.getStreamOrPropertyName() != null) { mappedProperty.insert(0, identNode.getStreamOrPropertyName() + '.'); }/*from w w w . ja v a2 s. c om*/ // Parse the mapped property format into a class name, method and single string parameter MappedPropertyParseResult parse = parseMappedProperty(mappedProperty.toString()); if (parse == null) { ExprConstantNode constNode = resolveIdentAsEnumConst(mappedProperty.toString(), methodResolutionService); if (constNode == null) { throw propertyException; } else { return constNode; } } // If there is a class name, assume a static method is possible if (parse.getClassName() != null) { List<ExprNode> parameters = Collections .singletonList((ExprNode) new ExprConstantNode(parse.getArgString())); List<ExprChainedSpec> chain = Collections .singletonList(new ExprChainedSpec(parse.getMethodName(), parameters)); ExprNode result = new ExprStaticMethodNode(parse.getClassName(), chain, methodResolutionService.isUdfCache()); // Validate try { result.validate(streamTypeService, methodResolutionService, null, timeProvider, variableService, exprEvaluatorContext); } catch (ExprValidationException e) { throw new ExprValidationException("Failed to resolve " + mappedProperty + " as either an event property or as a static method invocation"); } return result; } // There is no class name, try a single-row function String functionName = parse.getMethodName(); try { Pair<Class, String> classMethodPair = methodResolutionService.resolveSingleRow(functionName); List<ExprNode> params = Collections .singletonList((ExprNode) new ExprConstantNode(parse.getArgString())); List<ExprChainedSpec> chain = Collections .singletonList(new ExprChainedSpec(classMethodPair.getSecond(), params)); ExprNode result = new ExprPlugInSingleRowNode(functionName, classMethodPair.getFirst(), chain, false); // Validate try { result.validate(streamTypeService, methodResolutionService, null, timeProvider, variableService, exprEvaluatorContext); } catch (RuntimeException e) { throw new ExprValidationException("Plug-in aggregation function '" + parse.getMethodName() + "' failed validation: " + e.getMessage()); } return result; } catch (EngineImportUndefinedException e) { // Not an single-row function } catch (EngineImportException e) { throw new IllegalStateException("Error resolving single-row function: " + e.getMessage(), e); } // There is no class name, try an aggregation function try { AggregationSupport aggregation = methodResolutionService.resolveAggregation(parse.getMethodName()); ExprNode result = new ExprPlugInAggFunctionNode(false, aggregation, parse.getMethodName()); result.addChildNode(new ExprConstantNode(parse.getArgString())); // Validate try { result.validate(streamTypeService, methodResolutionService, null, timeProvider, variableService, exprEvaluatorContext); } catch (RuntimeException e) { throw new ExprValidationException("Plug-in aggregation function '" + parse.getMethodName() + "' failed validation: " + e.getMessage()); } return result; } catch (EngineImportUndefinedException e) { // Not an aggregation function } catch (EngineImportException e) { throw new IllegalStateException("Error resolving aggregation: " + e.getMessage(), e); } // absolutly cannot be resolved throw propertyException; }
From source file:gov.medicaid.screening.dao.impl.ChiropracticLicenseDAOBean.java
/** * Parses the Chiropractic license details page. * // w w w . j a v a2 s.c om * @param page * the details page * @param licenseType * if user has multiple licenses, this one will be used * @return the parsed license details * @throws ParsingException * if the expected tags were not found */ private License parseLicense(Document page, String licenseType) throws ParsingException { License license = new License(); ProviderProfile profile = new ProviderProfile(); license.setProfile(profile); User user = new User(); profile.setUser(user); Elements tables = page.select("table"); for (Element cell : tables.get(0).select("td")) { if (cell.text().equals("First Name")) { user.setFirstName(cell.nextElementSibling().text()); } else if (cell.text().equals("Middle Name")) { user.setMiddleName(cell.nextElementSibling().text()); } else if (cell.text().equals("Last Name")) { user.setLastName(cell.nextElementSibling().text()); } else if (cell.text().equals("Gender")) { String gender = cell.nextElementSibling().text(); if (Util.isNotBlank(gender)) { if ("M".equalsIgnoreCase(gender)) { profile.setSex(Sex.MALE); } else { profile.setSex(Sex.FEMALE); } } } } List<Address> addresses = new ArrayList<Address>(); Address address = new Address(); addresses.add(address); profile.setAddresses(addresses); StringBuffer locBuffer = new StringBuffer(); for (Element cell : tables.get(1).select("td")) { if (cell.text().equals("Address Line1")) { locBuffer.insert(0, cell.nextElementSibling().text() + " "); } else if (cell.text().equals("Address Line2")) { locBuffer.append(cell.nextElementSibling().text()); } else if (cell.text().equals("City")) { address.setCity(cell.nextElementSibling().text()); } else if (cell.text().equals("State")) { address.setState(cell.nextElementSibling().text()); } else if (cell.text().equals("ZIP")) { address.setZipcode(cell.nextElementSibling().text()); } else if (cell.text().equals("Phone Number")) { profile.setContactPhoneNumber(cell.nextElementSibling().text()); } } address.setLocation(locBuffer.toString().trim()); for (Element row : tables.get(2).select("tr")) { String lType = row.select("td:eq(0)").text(); if (licenseType != null && !lType.startsWith(licenseType)) { // user has multiple licenses, the results will show this user twice (search by name) continue; } LicenseType type = new LicenseType(); type.setName(row.select("td:eq(0)").text()); license.setType(type); license.setLicenseNumber(row.select("td:eq(1)").text()); LicenseStatus status = new LicenseStatus(); status.setName(row.select("td:eq(2)").text()); license.setStatus(status); String issueDate = row.select("td:eq(3)").text(); if (Util.isNotBlank(issueDate)) { license.setOriginalIssueDate(parseDate(issueDate, DATE_FORMAT)); } String renewalDate = row.select("td:eq(4)").text(); if (Util.isNotBlank(renewalDate)) { license.setRenewalDate(parseDate(renewalDate, DATE_FORMAT)); } String expirationDate = row.select("td:eq(5)").text(); if (Util.isNotBlank(expirationDate)) { license.setExpireDate(parseDate(expirationDate, DATE_FORMAT)); } } return license; }
From source file:org.infoscoop.util.Xml2Json.java
private String getXPath(Element element) { if (element == null) return null; StringBuffer xpath = new StringBuffer(); xpath.append("/"); String uri = element.getNamespaceURI(); String prefix = (String) namespaceResolvers.get(uri); if (prefix != null) xpath.append(prefix).append(":"); xpath.append(getTagName(element));/*from w w w .ja v a 2 s .c om*/ Element parent = element; try { while (true) { parent = (Element) parent.getParentNode(); if (parent == null) break; xpath.insert(0, getTagName(parent)); uri = parent.getNamespaceURI(); prefix = (String) namespaceResolvers.get(uri); if (prefix != null) xpath.insert(0, prefix + ":"); xpath.insert(0, "/"); } } catch (ClassCastException e) { } String xpathStr = xpath.toString(); if (this.basePath != null) xpathStr = xpathStr.replaceFirst("^" + this.basePath, ""); return xpathStr; }