List of usage examples for java.lang StringBuilder insert
@Override public StringBuilder insert(int offset, double d)
From source file:istata.service.StataService.java
/** * produce a list with possible sidebar suggestions for the current context * //from w ww. j a va 2 s . com * @param filter * @param pos * @param from * @param to * @return */ public List<ContentLine> suggest(String filter, int pos, int from, int to) { LinkedHashSet<ContentLine> res = new LinkedHashSet<ContentLine>(); ArrayList<ContentLine> rescmd = new ArrayList<ContentLine>(); { int i = 0; for (ContentLine cl : cmdRepository.findAll()) { if (cl.getContent().startsWith(filter)) { ContentLine srl = new ContentLine(); Map<String, Object> model = new HashMap<String, Object>(); model.put("cmd", cl); model.put("from", from); model.put("to", to); String text = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, "items/cmd.vm", "UTF-8", model); srl.setContent(text); srl.setLine(i++); rescmd.add(srl); } } } Collections.reverse(rescmd); res.addAll(rescmd.subList(0, Math.min(10, rescmd.size()))); List<ContentLine> out = new ArrayList<ContentLine>(); try { IStata stata = stataFactory.getInstance(); /* * get files */ Collection<ContentLine> filesNames = filteredFiles(filter, pos, from, to); res.addAll(filesNames); /* * get VARS, should be a mothod call probably */ // current token StringBuilder token = new StringBuilder(""); StringBuilder rest = new StringBuilder(filter); int p = (pos == -1 || pos > filter.length()) ? filter.length() : pos; char ch = 'x'; while (p > 0 && (CharUtils.isAsciiAlphanumeric(ch = filter.charAt(p - 1)) || ch == '_')) { token.insert(0, ch); rest.deleteCharAt(p - 1); p--; } // remove rest of potential token while (rest.length() > 0 && p > 0 && p < rest.length() && (CharUtils.isAsciiAlphanumeric(rest.charAt(p)) || rest.charAt(p) == '_')) { rest.deleteCharAt(p); } String t = token.toString(); List<StataVar> list = new ArrayList<StataVar>(); List<StataVar> listfull = stata.getVars("", false); if (t.length() > 0) { for (StataVar sv : listfull) { if (sv.getName().startsWith(t)) { list.add(sv); } } } else { list = listfull; } for (int i = 0; i < list.size(); i++) { ContentLine srl = new ContentLine(); srl.setLine(i + 100); String vname = list.get(i).getName(); String cl = new StringBuilder(rest).insert(p, " ").insert(p, vname).toString(); try { String cc = URLEncoder.encode(cl, "UTF-8"); Map<String, Object> model = new HashMap<String, Object>(); model.put("var", vname); model.put("repl", cc); model.put("focuspos", p + 1 + vname.length()); model.put("from", from); model.put("to", to); String text = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, "items/var.vm", "UTF-8", model); srl.setContent(text); res.add(srl); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } catch (StataNotRunningException e) { ContentLine srl = new ContentLine(); srl.setLine(1); srl.setContent( "<div class='list-group-item sidebaritem error' >" + "Stata not running, you can try to start " + "an instance by clicking " + "<a target='_blank' href='/start'>here</a>" + "</div>"); out.add(srl); } catch (StataBusyException e1) { ContentLine srl = new ContentLine(); srl.setLine(1); srl.setContent("<div class='list-group-item sidebaritem error' >" + "Stata appears to by busy or not running, you can try to " + "start a new instance by clicking " + "<a target='_blank' href='/start'>here</a> " + "or wait for the current job to complete</div>"); out.add(srl); } out.addAll(res); return out; }
From source file:edu.ku.brc.specify.config.init.TreeDefSetupPanel.java
@Override public void updateBtnUI() { nextBtn.setEnabled(isUIValid());/*from www.j av a 2 s . c o m*/ String lastSep = ""; StringBuilder sb = new StringBuilder("<html>"); StringBuilder subbdlr = new StringBuilder(); for (TreeDefRow row : treeDefList) { if (row.isInFullName()) { subbdlr.setLength(0); subbdlr.append("<i>"); subbdlr.append(row.getTitle()); subbdlr.append("</i>"); subbdlr.append(row.getSeparator()); lastSep = row.getSeparator(); if (directionCBX.getSelectedIndex() == 0) { sb.append(subbdlr.toString()); } else { sb.insert(6, subbdlr.toString()); } } } if (sb.length() > 0) { sb.setLength(sb.length() - lastSep.length()); } if (fullnameDisplayTxt != null) { fullnameDisplayTxt.setText(sb.toString()); } }
From source file:com.archivas.clienttools.arcmover.cli.ManagedCLIJob.java
private String generateDetails(ManagedJobImpl.JobDetails jobDetails) { String newLine = NEWLINE;//from w w w .j ava2 s. c om StringBuilder sb = new StringBuilder(); List<FileStats> errors = jobDetails.getObjectsFailed(); for (FileStats fileStats : errors) { sb.append(fileStats.getDisplayUriRelativeToBasePath()); sb.append(getErrorMessage()); Throwable e = fileStats.getException(); if (e != null) { sb.append(e.getMessage()); sb.append(newLine); } } if (sb.length() > 0) { sb.insert(0, newLine).insert(0, "Job Details ").insert(0, newLine); } return sb.toString(); }
From source file:io.wcm.caravan.io.http.request.RequestTemplate.java
public String queryLine() { if (queries.isEmpty()) { return ""; }/*w w w . j av a 2 s. c om*/ StringBuilder queryBuilder = new StringBuilder(); for (String field : queries.keySet()) { for (String value : ObjectUtils.defaultIfNull(queries.get(field), Collections.<String>emptyList())) { queryBuilder.append('&'); queryBuilder.append(field); if (value != null) { queryBuilder.append('='); if (!value.isEmpty()) { queryBuilder.append(value); } } } } queryBuilder.deleteCharAt(0); return queryBuilder.insert(0, '?').toString(); }
From source file:net.ymate.framework.core.taglib.bootstrap.FormControlTag.java
@Override protected StringBuilder __doTagContent(StringBuilder tagContent, StringBuilder bodyContent) { StringBuilder _tmpSB = new StringBuilder(); if (StringUtils.isNotBlank(label)) { _tmpSB.append("<label class=\"control-label"); if (labelWidth != null && labelWidth > 0) { _tmpSB.append(" col-sm-").append(labelWidth); if (labelSrOnly) { _tmpSB.append(" sr-only"); }/*from w w w. ja va 2 s . co m*/ } _tmpSB.append("\""); if (StringUtils.isNotBlank(this.get_id()) && !StringUtils.equalsIgnoreCase(type, "static")) { _tmpSB.append(" for=\"").append(this.get_id()).append("\""); } _tmpSB.append(">").append(label).append("</label>"); if (labelWidth != null && labelWidth > 0) { _tmpSB.append("<div class=\"col-sm-").append(12 - labelWidth).append("\">"); } } tagContent.insert(0, _tmpSB).append(bodyContent); if (StringUtils.isNotBlank(type)) { tagContent = __doTagEnd(tagContent); } if (__formGroup != null && StringUtils.isNotBlank(__formGroup.getFeedbackIcon())) { tagContent.append("<span class=\"").append(__formGroup.getFeedbackIcon()) .append(" form-control-feedback\"></span>"); } if (StringUtils.isNotBlank(helpBlock) || StringUtils.isNotBlank(helpBlockClass)) { tagContent.append("<span class=\"help-block ").append(StringUtils.trimToEmpty(helpBlockClass)) .append("\">").append(StringUtils.trimToEmpty(helpBlock)).append("</span>"); } if (StringUtils.isNotBlank(label) && labelWidth != null && labelWidth > 0) { tagContent.append("</div>"); } return tagContent; }
From source file:net.sf.eclipsefp.haskell.ui.internal.editors.haskell.HaskellTextHover.java
@SuppressWarnings("unchecked") public static String computeProblemInfo(final ITextViewer textViewer, final IRegion hoverRegion, final IAnnotationAccessExtension fMarkerAnnotationAccess) { if (textViewer instanceof ISourceViewer) { IAnnotationModel annotationModel = ((ISourceViewer) textViewer).getAnnotationModel(); if (annotationModel != null) { // collect all messages StringBuilder sb = new StringBuilder(); Iterator<Annotation> i = annotationModel.getAnnotationIterator(); while (i.hasNext()) { Annotation a = i.next(); String type = a.getType(); if (a.getText() != null && (fMarkerAnnotationAccess.isSubtype(type, ERROR_ANNOTATION_TYPE) || fMarkerAnnotationAccess.isSubtype(type, WARNING_ANNOTATION_TYPE) || fMarkerAnnotationAccess.isSubtype(type, SPELLING_ANNOTATION_TYPE))) { Position p = annotationModel.getPosition(a); if (p.overlapsWith(hoverRegion.getOffset(), hoverRegion.getLength())) { // add a nice icon String img = ""; String txt = toHTMLString(a.getText()); try { URL url = FileLocator.toFileURL(HaskellUIPlugin.getDefault().getBundle() .getResource(fMarkerAnnotationAccess.isSubtype(type, ERROR_ANNOTATION_TYPE) ? "icons/obj16/error_obj.gif" : "icons/obj16/warning_obj.gif")); img = "<img src=\"" + url.toString() + "\" style=\"vertical-align:-4;\"/>"; } catch (IOException ioe) { HaskellUIPlugin.log(ioe); }/* w ww . j a v a2s . co m*/ String div = "<div style=\"font-family: verdana;padding:2px\">" + img + txt + "</div>"; // put errors first if (fMarkerAnnotationAccess.isSubtype(type, ERROR_ANNOTATION_TYPE)) { if (sb.length() > 0) { sb.insert(0, "<hr/>"); } sb.insert(0, div); } else { if (sb.length() > 0) { sb.append("<hr/>"); } sb.append(div); } } } } if (sb.length() > 0) { return sb.toString(); } } } return null; }
From source file:com.arksoft.epamms.EpammsTest.java
@Test public void testZeidonStringCopy() throws IOException { VmlTestOperation oper = new VmlTestOperation(task); String s;/* w w w . j av a 2 s. c o m*/ int nLth; StringBuilder sbTgt = new StringBuilder(); StringBuilder sbSrc = new StringBuilder(); sbSrc.setLength(0); sbSrc.insert(0, "2011"); nLth = oper.ZeidonStringCopy(sbTgt, 1, 4, sbSrc, 1, 4, 4); assertEquals("ZeidonStringCopy string copied invalid", sbTgt.toString(), "2011"); assertEquals("ZeidonStringCopy string copy length invalid", nLth, 4); sbSrc.setLength(0); sbSrc.insert(0, "N"); nLth = oper.ZeidonStringCopy(sbTgt, 1, 0, sbSrc, 1, 0, 2); assertEquals("ZeidonStringCopy string copied invalid", sbTgt.toString(), "N"); assertEquals("ZeidonStringCopy string copy length invalid", nLth, 1); }
From source file:com.sun.tools.xjc.addon.xew.XmlElementWrapperPlugin.java
/** * Create additional factory methods with a new scope for elements that should be scoped. * /*w ww .j ava 2 s .c o m*/ * @param targetClass * the class that is applied the transformation of properties * @return number of created methods * @see com.sun.tools.xjc.generator.bean.ObjectFactoryGenerator */ private int createScopedFactoryMethods(JCodeModel codeModel, JDefinedClass factoryClass, Collection<ScopedElementInfo> scopedElementInfos, JDefinedClass targetClass) { int createdMethods = 0; NEXT: for (ScopedElementInfo info : scopedElementInfos) { String dotClazz = targetClass.fullName() + ".class"; // First check that such factory method has not yet been created. It can be the case if target class // is substituted with e.g. two candidates, each candidate having a field with the same name. // FIXME: Could it be the case that these two fields have different namespaces? for (JMethod method : factoryClass.methods()) { JAnnotationUse xmlElementDeclAnnotation = getAnnotation(method, xmlElementDeclModelClass); JExpression scope = getAnnotationMemberExpression(xmlElementDeclAnnotation, "scope"); JExpression name = getAnnotationMemberExpression(xmlElementDeclAnnotation, "name"); if (scope != null && dotClazz.equals(generableToString(scope)) && generableToString(info.name).equals(generableToString(name))) { continue NEXT; } } // Generate the scoped factory method: // @XmlElementDecl(..., scope = T.class) // public JAXBElement<X> createT...(X value) { return new JAXBElement<...>(QNAME, X.class, T.class, value); } StringBuilder methodName = new StringBuilder(); JDefinedClass container = targetClass; // To avoid potential name conflicts method name starts with scope class name: while (true) { methodName.insert(0, container.name()); if (container.parentContainer().isClass()) { container = (JDefinedClass) container.parentContainer(); } else { break; } } methodName.insert(0, "create") .append(NameConverter.standard.toPropertyName(generableToString(info.name))); JClass wrapperType = codeModel.ref(JAXBElement.class).narrow(info.type); JMethod method = factoryClass.method(JMod.PUBLIC, wrapperType, methodName.toString()); method.annotate(xmlElementDeclModelClass).param("namespace", info.namespace).param("name", info.name) .param("scope", targetClass); // FIXME: Make a try to load constants and (a) rename it appropriately (b) use it? JInvocation qname = JExpr._new(codeModel.ref(QName.class)).arg(info.namespace).arg(info.name); method.body()._return(JExpr._new(wrapperType).arg(qname).arg(info.type.boxify().dotclass()) .arg(targetClass.dotclass()).arg(method.param(info.type, "value"))); createdMethods++; } return createdMethods; }
From source file:com.irccloud.android.CollapsedEventsList.java
private String was(CollapsedEvent e) { StringBuilder was = new StringBuilder(); String modes = e.getModes(false); if (e.old_nick != null && e.type != TYPE_MODE) was.append("was ").append(e.old_nick); if (modes != null && modes.length() > 0) { if (was.length() > 0) was.append("; "); was.append("\u00031").append(modes).append("\u000f"); }//from w w w . j av a2 s .c om if (was.length() > 0) was.insert(0, " (").append(")"); return was.toString(); }