List of usage examples for java.lang StringBuilder insert
@Override public StringBuilder insert(int offset, double d)
From source file:eu.esdihumboldt.hale.io.xslt.XslTransformationUtil.java
/** * Create a XPath statement to select instances specified by the given type * entity definition.// w w w. j av a 2 s . c om * * @param ted the type entity definition * @param context the context for the XPath expression, e.g. the empty * string for the document root or <code>/</code> for anywhere in * the document * @param namespaces the namespace context * @return the XPath expression or <code>null</code> if there are no * elements that match the type */ public static String selectInstances(TypeEntityDefinition ted, String context, NamespaceContext namespaces) { TypeDefinition type = ted.getDefinition(); // get the XML elements associated to the type XmlElements elements = type.getConstraint(XmlElements.class); if (elements.getElements().isEmpty()) { /* * XXX dirty hack * * In CityGML 1.0 no element for AppearanceType is defined, only a * property that is not detected in this way. The source route * element is not known here, so we also cannot do a search based on * the type. Thus for now we handle it as a special case. */ QName typeName = ted.getDefinition().getName(); if ("http://www.opengis.net/citygml/appearance/1.0".equals(typeName.getNamespaceURI()) && "AppearanceType".equals(typeName.getLocalPart())) { // create a dummy XML element elements = new XmlElements(); elements.addElement( new XmlElement(new QName("http://www.opengis.net/citygml/appearance/1.0", "Appearance"), ted.getDefinition(), null)); } else // XXX dirty hack end return null; } // XXX which elements should be used? // for now use all elements StringBuilder select = new StringBuilder(); boolean first = true; for (XmlElement element : elements.getElements()) { if (first) { first = false; } else { select.append(" | "); } select.append(context); select.append('/'); String ns = element.getName().getNamespaceURI(); if (ns != null && !ns.isEmpty()) { String prefix = namespaces.getPrefix(ns); if (prefix != null && !prefix.isEmpty()) { select.append(prefix); select.append(':'); } } select.append(element.getName().getLocalPart()); } // filter if (ted.getFilter() != null) { String filterxpath = FilterToXPath.toXPath(ted.getDefinition(), namespaces, ted.getFilter()); if (filterxpath != null && !filterxpath.isEmpty()) { select.insert(0, '('); select.append(")["); select.append(StringEscapeUtils.escapeXml(filterxpath)); select.append(']'); } } return select.toString(); }
From source file:net.ymate.framework.core.taglib.bootstrap.PaginationTag.java
@Override protected StringBuilder __doTagContent(StringBuilder tagContent, StringBuilder bodyContent) { if (!nonNav) { return super.__doTagContent(tagContent.insert(0, "<nav>"), bodyContent).append("</nav>"); }//from w w w . j ava2 s. c om return super.__doTagContent(tagContent, bodyContent); }
From source file:uk.ac.kcl.mutators.StringMutatorService.java
public Mutant generateMutantDocument(String[] stringsToMutate, String[] nonMutantStrings, int severity) { LoremIpsum loremIpsum = new LoremIpsum(); int loremStart = 0; int loremEnd = random.nextInt(loremLength); StringBuilder sb = new StringBuilder(); sb.insert(0, loremIpsum.getWords(random.nextInt(loremLength))); Mutant parentMutant = new Mutant(); for (int i = 0; i < stringsToMutate.length; i++) { Mutant childMutant = mutate(stringsToMutate[i], severity); parentMutant.getInputTokens().addAll(childMutant.getInputTokens()); parentMutant.getOutputTokens().addAll(childMutant.getOutputTokens()); sb.append(childMutant.getFinalText()).append(" ").append(loremIpsum.getWords(loremEnd, loremStart)) .append(" "); loremStart = loremEnd + 1;//from w ww.j a va 2 s . c om loremEnd = loremStart + random.nextInt(loremLength); if (loremEnd > 49 || loremStart > 49) { loremStart = 0; loremEnd = random.nextInt(loremLength); } for (int j = 0; j < nonMutantStrings.length; j++) { sb.append(nonMutantStrings[j]).append(" ").append(loremIpsum.getWords(loremEnd, loremStart)) .append(" "); loremStart = loremEnd + 1; loremEnd = loremStart + random.nextInt(loremLength); if (loremEnd > 49 || loremStart > 49) { loremStart = 0; loremEnd = random.nextInt(loremLength); } } } parentMutant.setFinalText(sb.toString()); return parentMutant; }
From source file:net.ymate.platform.webmvc.view.impl.JsonView.java
protected void __doRenderView() throws Exception { HttpServletResponse _response = WebContext.getResponse(); if (StringUtils.isNotBlank(getContentType())) { _response.setContentType(getContentType()); } else if (this.__withContentType) { if (__jsonCallback == null) { _response.setContentType(Type.ContentType.JSON.getContentType()); } else {//from ww w .j a v a2 s.c o m _response.setContentType(Type.ContentType.JAVASCRIPT.getContentType()); } } StringBuilder _jsonStr = new StringBuilder(__jsonObj.toString()); if (__jsonCallback != null) { _jsonStr.insert(0, __jsonCallback + "(").append(");"); } IOUtils.write(_jsonStr.toString(), _response.getOutputStream(), _response.getCharacterEncoding()); }
From source file:ngmep.procesos.ComparaCadenas.java
public static boolean distanciaUnaLetra(final String cad1, final String cad2) { if (cad1.length() == cad2.length()) { final String cadena1 = cad1.toUpperCase(LOCALE_ES); final String cadena2 = cad2.toUpperCase(LOCALE_ES); for (int i = 0; i < cad1.length(); i++) { final StringBuilder test1 = new StringBuilder(); final StringBuilder test2 = new StringBuilder(); test1.append(cadena1);/*from w w w . j a v a 2s .c o m*/ test2.append(cadena2); test1.setCharAt(i, 'X'); test2.setCharAt(i, 'X'); if (test1.toString().equals(test2.toString())) { return true; } } } else if (Math.abs(cad1.length() - cad2.length()) == 1) { String mayor = cad1.toUpperCase(LOCALE_ES); String menor = cad2.toUpperCase(LOCALE_ES); if (mayor.length() < menor.length()) { final String tmp = mayor; mayor = menor; menor = tmp; } for (int i = 0; i < mayor.length(); i++) { final StringBuilder test1 = new StringBuilder(); final StringBuilder test2 = new StringBuilder(); test1.append(mayor); test2.append(menor); test1.setCharAt(i, 'X'); test2.insert(i, 'X'); if (test1.toString().equals(test2.toString())) { return true; } } } return false; }
From source file:net.ymate.platform.mvc.web.view.impl.JsonView.java
protected void renderView() throws Exception { HttpServletResponse response = WebContext.getResponse(); if (StringUtils.isNotBlank(getContentType())) { response.setContentType(getContentType()); } else if (this.withContentType) { if (this.jsonpCallback == null) { response.setContentType(JSON_CONTENT_TYPE); } else {/*from ww w .j a va 2s. com*/ response.setContentType(JAVASCRIPT_CONTENT_TYPE); } } StringBuilder _jsonStr = new StringBuilder(jsonObj.toString()); if (this.jsonpCallback != null) { _jsonStr.insert(0, this.jsonpCallback + "(").append(");"); } IOUtils.write(_jsonStr.toString(), response.getOutputStream(), StringUtils .defaultIfEmpty(WebMVC.getConfig().getCharsetEncoding(), response.getCharacterEncoding())); }
From source file:com.apt.ajax.controller.AjaxUpload.java
private File checkExist(String filename, String uploadDir) { File file = new File(uploadDir + File.separator + filename); if (file.exists()) { StringBuilder sb = new StringBuilder(filename); sb.insert(sb.lastIndexOf("."), new Date().getTime()); file = new File(uploadDir + File.separator + sb.toString()); }/*from w ww .ja v a 2 s . co m*/ return file; }
From source file:LongListTest.java
public Object getElementAt(int n) { StringBuilder r = new StringBuilder(); ;//from w w w.jav a 2s.c o m for (int i = 0; i < length; i++) { char c = (char) (FIRST + n % (LAST - FIRST + 1)); r.insert(0, c); n = n / (LAST - FIRST + 1); } return r; }
From source file:com.prowidesoftware.swift.model.field.Field.java
/** * A formatted amount with a fixed format nnnn-nnnnn-nnn-n * @param a string with an account number or <code>null</code> * @return the formatted account or an empty String if param is <code>null</code> *///from ww w . j a v a 2 s . co m // TODO support user formatting masks from property file protected static String formatAccount(final String a) { if (a == null) { //be gentle with null return StringUtils.EMPTY; } final StringBuilder result = new StringBuilder(a); try { result.insert(4, '-'); result.insert(9, '-'); result.insert(12, '-'); } catch (final Exception ignored) { } return result.toString(); }
From source file:fr.shywim.antoinedaniel.ui.fragment.SoundFragment.java
@Override public void filter(String constraint) { if (!isAdded()) { return;//from w w w. j a v a2 s . co m } StringBuilder sb = new StringBuilder(constraint); sb.insert(0, '%'); sb.append('%'); Bundle args = new Bundle(); args.putString(ARG_FILTER, sb.toString()); getLoaderManager().restartLoader(mContentId, args, this); }