List of usage examples for java.lang StringBuffer insert
@Override public StringBuffer insert(int offset, double d)
From source file:edu.scripps.fl.curves.plot.GCurvePlot.java
public void addCurve(Curve curve, FitFunction function) { double[] yValues = (double[]) ConvertUtils.convert(curve.getResponses(), double[].class); double curveMinY = NumberUtils.min(yValues); double curveMaxY = NumberUtils.max(yValues); this.minY = Math.min(minY, curveMinY); this.maxY = Math.min(maxY, curveMaxY); Data yData = DataUtil.scaleWithinRange(curveMinY, curveMaxY, yValues); double[] xValues = (double[]) ConvertUtils.convert(curve.getConcentrations(), double[].class); for (int ii = 0; ii < xValues.length; ii++) { double x = Math.log10(xValues[ii]); xValues[ii] = x;/*from w ww.j a v a 2s.c om*/ } double curveMinX = NumberUtils.min(xValues); double curveMaxX = NumberUtils.max(xValues); this.minX = Math.min(minX, curveMinX); this.maxX = Math.min(maxX, curveMaxX); Data xData = DataUtil.scaleWithinRange(NumberUtils.min(xValues), NumberUtils.max(xValues), xValues); String hexColor = Integer .toHexString(((java.awt.Color) drawingSupplier.getNextPaint()).getRGB() & 0x00ffffff); StringBuffer sb = new StringBuffer(); sb.append(hexColor); while (sb.length() < 6) sb.insert(0, "0"); Color color = Color.newColor(sb.toString()); XYLine line1 = Plots.newXYLine(xData, yData, getBackgroundColor(), ""); // line1.setLineStyle(LineStyle.newLineStyle(3, 1, 0)); line1.addShapeMarkers(Shape.CIRCLE, color, 5); XYLine fittedLine = sampleFunctionToLine(curve, function, curveMinX, curveMaxX, 100); // fittedLine.setLineStyle(LineStyle.newLineStyle(3, 1, 0)); fittedLine.setColor(color); lines.add(line1); lines.add(fittedLine); }
From source file:corner.orm.hibernate.impl.PaginatedEntityService.java
License:asdf
public long count(final Class<?> persistClass, final Object conditions) { return (Long) this.template.execute(new HibernateCallback() { /**//w w w . j a va 2 s.c om * @see org.springframework.orm.hibernate3.HibernateCallback#doInHibernate(org.hibernate.Session) */ @Override public Object doInHibernate(Session session) throws HibernateException, SQLException { Iterable con = typeCoercer.coerce(conditions, Iterable.class); final Iterator it = con == null ? null : con.iterator(); final StringBuffer sb = buildConditionHQL(persistClass, it); sb.insert(0, "select count(*) "); Query query = session.createQuery(sb.toString()); if (it != null) { int i = 0; while (it.hasNext()) { query.setParameter(i++, it.next()); } } return query.iterate().next(); } }); }
From source file:Main.java
/** /* FindAndReplace - finds and replaces in StringBuffer theSBuffer, /* starts at fromIndex, returns index of find. * // www . j ava 2 s . com * @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:org.ourbeehive.mbp.util.MapperFormatter.java
public static void insertAndStatement(StringBuffer statement) { StringBuffer prefix = new StringBuffer(); StringHelper.newLine(prefix, JavaSrcElm.UNIT_OF_INDENT, 3); prefix.append(MapperElm.SQL_AND_FULL); statement.insert(0, prefix.toString()); }
From source file:org.ourbeehive.mbp.util.MapperFormatter.java
public static void insertWhereStatement(StringBuffer statement) { StringBuffer prefix = new StringBuffer(); StringHelper.newLine(prefix, JavaSrcElm.UNIT_OF_INDENT, 3); prefix.append(MapperElm.SQL_WHERE_FULL); statement.insert(0, prefix.toString()); }
From source file:corner.orm.gae.impl.PaginatedJapEntityService.java
License:asdf
public Iterator find(final Class<?> persistClass, final Object conditions, final String order, final int start, final int offset) { return (Iterator) this.template.execute(new JpaCallback() { @Override/* w ww . j a v a 2 s .c o m*/ public Object doInJpa(EntityManager entityManager) throws PersistenceException { Iterable con = typeCoercer.coerce(conditions, Iterable.class); final Iterator it = con == null ? null : con.iterator(); final StringBuffer sb = buildConditionJPQL(persistClass, it); appendOrder(sb, order); sb.insert(0, "select root." + EntityConstants.ID_PROPERTY_NAME); Query query = entityManager.createQuery(sb.toString()); if (it != null) { int i = 0; while (it.hasNext()) { query.setParameter(String.valueOf(++i), it.next()); } } query.setFirstResult(start); query.setMaxResults(offset); return query.getResultList().iterator(); } }); }
From source file:org.primefaces.extensions.showcase.util.FileContentMarkerUtil.java
private static String readFileContent(InputStream inputStream, FileContentSettings settings) throws IOException { if (inputStream == null) { return null; }/*w w w .j a v a 2 s . co m*/ StringBuffer sbBeforeStartMarker = new StringBuffer(); StringBuffer sbBeforeEndMarker = new StringBuffer(); String markerLineStart = null; String markerLineEnd = null; BufferedReader br = new BufferedReader(new InputStreamReader(inputStream)); String line; StringBuffer sb = sbBeforeStartMarker; while ((line = br.readLine()) != null) { // if is before first start marker if (markerLineStart == null && containMarker(line, settings.getStartMarkers())) { markerLineStart = "\n" + line; sb = sbBeforeEndMarker; continue; } // if is before first end marker if (containMarker(line, settings.getEndMarkers())) { markerLineEnd = "\n" + line; break; // other content file is ignored } sb.append("\n"); sb.append(line); } // if both (START and END) markers are in file if (markerLineStart != null && markerLineEnd != null) { if (settings.isShowLineWithMarker()) { sbBeforeEndMarker.append(markerLineEnd); sbBeforeEndMarker.insert(0, markerLineStart); } return sbBeforeEndMarker.toString().trim(); } // if only START marker is in file if (markerLineStart != null) { if (settings.isShowLineWithMarker()) { sbBeforeEndMarker.insert(0, markerLineStart); } return sbBeforeEndMarker.toString().trim(); } // if only END marker is in file if (settings.isShowLineWithMarker()) { sbBeforeStartMarker.append(markerLineEnd); } return sbBeforeStartMarker.toString().trim(); }
From source file:org.wso2.andes.management.ui.views.ViewUtility.java
/** * Converts the input string to displayable format by converting some character case or inserting space * @param input//from w ww . ja v a 2s .c o m * @return formatted string */ public static String getDisplayText(String input) { StringBuffer result = new StringBuffer(input); if (Character.isLowerCase(result.charAt(0))) { result.setCharAt(0, Character.toUpperCase(result.charAt(0))); } for (int i = 1; i < input.length(); i++) { if (Character.isUpperCase(result.charAt(i)) && !Character.isWhitespace(result.charAt(i - 1)) && Character.isLowerCase(result.charAt(i - 1))) { result.insert(i, " "); i++; } else if (Character.isLowerCase(result.charAt(i)) && Character.isWhitespace(result.charAt(i - 1))) { result.setCharAt(i, Character.toUpperCase(result.charAt(i))); } } return result.toString(); }
From source file:com.cubusmail.mail.text.MessageTextUtil.java
/** * Convert a plaint text to html.//from www . ja v a 2 s .com * * @param plainText * @return */ public static String convertPlainText2Html(String plainText, MessageTextMode mode) { try { plainText = HtmlUtils.htmlEscape(plainText).replaceAll(REPL_LINEBREAK, HTML_BR); final Matcher m = PATTERN_HREF.matcher(plainText); final StringBuffer sb = new StringBuffer(plainText.length()); final StringBuilder tmp = new StringBuilder(256); while (m.find()) { final String nonHtmlLink = m.group(1); if ((nonHtmlLink == null) || (hasSrcAttribute(plainText, m.start(1)))) { m.appendReplacement(sb, Matcher.quoteReplacement(checkTarget(m.group()))); } else { tmp.setLength(0); m.appendReplacement(sb, tmp.append("<a href=\"").append( (nonHtmlLink.startsWith("www") || nonHtmlLink.startsWith("news") ? "http://" : "")) .append("$1\" target=\"_blank\">$1</a>").toString()); } } m.appendTail(sb); if (mode == MessageTextMode.DISPLAY) { sb.insert(0, "<p style=\"font-family: monospace; font-size: 10pt;\">"); sb.append("</p>"); } return sb.toString(); } catch (final Exception e) { log.error(e.getMessage(), e); } catch (final StackOverflowError error) { log.error(StackOverflowError.class.getName(), error); } return plainText; }
From source file:com.jaspersoft.studio.data.querydesigner.json.JsonDataManager.java
private String getAbsoluteQueryExpression(JsonSupportNode selectedNode) { StringBuffer queryBuff = new StringBuffer(); queryBuff.insert(0, selectedNode.getNodeText()); JsonSupportNode tmpNode = selectedNode; while (tmpNode.getParent() != null && !(tmpNode.getParent() instanceof MRoot)) { tmpNode = (JsonSupportNode) tmpNode.getParent(); queryBuff.insert(0, tmpNode.getNodeText() + "."); }//from ww w .j ava 2 s .com return queryBuff.toString(); }