@Override @Test public void appendString() { Appendable builder = new StringBuilder(); this.newWith(1, 2, 3).appendString(builder); Assert.assertEquals("1, 2, 3", builder.toString()); }
/** Verify injecting multiple components using a single Integration Object. */ @UnAdaptableTest public void testInjectingMultipleComponents() throws Exception { DefDescriptor<ComponentDef> cmp1 = addSourceAutoCleanup(ComponentDef.class, String.format(baseComponentTag, "", "")); DefDescriptor<ComponentDef> cmp2 = addSourceAutoCleanup(ComponentDef.class, String.format(baseComponentTag, "", "")); Map<String, Object> attributes = Maps.newHashMap(); Appendable out = new StringBuffer(); Integration integration = service.createIntegration("", Mode.UTEST, true, null); try { integration.injectComponent(cmp1.getDescriptorName(), attributes, "", "", out); integration.injectComponent(cmp2.getDescriptorName(), attributes, "", "", out); } catch (Exception unexpected) { fail("Failed to inject multiple component. Exception:" + unexpected.getMessage()); } // Verify that the boot strap was written only once assertNotNull(out); Pattern frameworkJS = Pattern.compile( "<script src=\"/auraFW/javascript/[^/]+/aura_.{4}.js\\?aura.fwuid=[-0-9A-Za-z_]*\" ></script>"); Matcher m = frameworkJS.matcher(out.toString()); int counter = 0; while (m.find()) { counter++; } assertEquals("Bootstrap template should be written out only once.", 1, counter); }
@Override public void appendValue( T instance, Appendable buffy, boolean needsEscaping, TranslationContext serializationContext, Format format) throws IOException { String instanceString = ""; if (instance != null && serializationContext != null) instanceString = marshall(instance, serializationContext); // andruid 1/4/10 // instance.toString(); if (needsEscaping) { switch (format) { case JSON: buffy.append(JSONObject.escape(instanceString)); ; break; case XML: XMLTools.escapeXML(buffy, instanceString); break; default: XMLTools.escapeXML(buffy, instanceString); break; } } else buffy.append(instanceString); }
private void addSourcesContentMap(Appendable out) throws IOException { boolean found = false; List<String> contents = new ArrayList<>(); contents.addAll(Collections.nCopies(sourceFileMap.size(), "")); for (Map.Entry<String, String> entry : sourceFileContentMap.entrySet()) { Integer index = sourceFileMap.get(entry.getKey()); if (index != null && index < contents.size()) { contents.set(index, entry.getValue()); found = true; } } if (!found) { return; } appendFieldStart(out, "sourcesContent"); out.append("["); for (int i = 0; i < contents.size(); i++) { if (i != 0) { out.append(","); } out.append(escapeString(contents.get(i))); } out.append("]"); appendFieldEnd(out); }
/* ------------------------------------------------------------ */ public void dump(Appendable out, String indent) throws IOException { out.append(this.getClass().getSimpleName()) .append("@") .append(Long.toHexString(this.hashCode())) .append("\n"); int size = _bindings.size(); int i = 0; for (Map.Entry<String, Binding> entry : ((Map<String, Binding>) _bindings).entrySet()) { boolean last = ++i == size; out.append(indent).append(" +- ").append(entry.getKey()).append(": "); Binding binding = entry.getValue(); Object value = binding.getObject(); if ("comp".equals(entry.getKey()) && value instanceof Reference && "org.eclipse.jetty.jndi.ContextFactory" .equals(((Reference) value).getFactoryClassName())) { ContextFactory.dump(out, indent + (last ? " " : " | ")); } else if (value instanceof Dumpable) { ((Dumpable) value).dump(out, indent + (last ? " " : " | ")); } else { out.append(value.getClass().getSimpleName()).append("="); out.append(String.valueOf(value).replace('\n', '|').replace('\r', '|')); out.append("\n"); } } }
public static void appendContentUrl( Appendable writer, String location, HttpServletRequest request) throws IOException { StringBuilder buffer = new StringBuilder(); ContentUrlTag.appendContentPrefix(request, buffer); writer.append(buffer.toString()); writer.append(location); }
public void appendScript(Appendable target) throws IOException { target.append(name).append('('); boolean first = true; List<?> parameters = getParameters(); if (null != parameters) { for (Iterator<?> param = parameters.iterator(); param.hasNext(); ) { Object element = param.next(); if (!first) { target.append(','); } if (null != element) { ScriptUtils.appendScript(target, element); } else { target.append("null"); } first = false; } } target.append(")"); }
/** * Construit une chaîne de caractères qui contiendra le noeud spécifié ainsi que tous les noeuds * enfants. * * @param model Arborescence à écrire. * @param node Noeud de l'arborescence à écrire. * @param buffer Buffer dans lequel écrire le noeud. * @param level Niveau d'indentation (à partir de 0). * @param last Indique si les niveaux précédents sont en train d'écrire leurs derniers items. * @return Le tableau {@code last}, qui peut éventuellement avoir été agrandit. */ private static boolean[] format( final TreeModel model, final Object node, final Appendable buffer, final int level, boolean[] last, final String lineSeparator) throws IOException { for (int i = 0; i < level; i++) { if (i != level - 1) { buffer.append(last[i] ? '\u00A0' : '\u2502').append("\u00A0\u00A0\u00A0"); } else { buffer.append(last[i] ? '\u2514' : '\u251C').append("\u2500\u2500\u2500"); } } buffer.append(String.valueOf(node)).append(lineSeparator); if (level >= last.length) { last = XArray.resize(last, level * 2); } final int count = model.getChildCount(node); for (int i = 0; i < count; i++) { last[level] = (i == count - 1); last = format(model, model.getChild(node, i), buffer, level + 1, last, lineSeparator); } return last; }
@Override public ValidationState getValidationState(Appendable errMsg) { try { // TODO: check duplicate columns here!!! if (ntmp.getSourceIndex() == -1) { if (ntmp.getTargetIndex() == -1) { errMsg.append( "The network cannot be created without selecting the source and target columns."); return ValidationState.INVALID; } else { errMsg.append( "No edges will be created in the network; the target column is not selected.\nDo you want to continue?"); return ValidationState.REQUEST_CONFIRMATION; } } else { if (ntmp.getTargetIndex() == -1) { errMsg.append( "No edges will be created in the network; the source column is not selected.\nDo you want to continue?"); return ValidationState.REQUEST_CONFIRMATION; } else { return ValidationState.OK; } } } catch (IOException ioe) { ioe.printStackTrace(); return ValidationState.INVALID; } }
/** Dumps messages to the given output stream, returning the highest message level seen. */ static MessageLevel dumpMessages(MessageQueue mq, MessageContext mc, Appendable out) { MessageLevel maxLevel = MessageLevel.values()[0]; for (Message m : mq.getMessages()) { MessageLevel level = m.getMessageLevel(); if (maxLevel.compareTo(level) < 0) { maxLevel = level; } } MessageLevel ignoreLevel = null; if (maxLevel.compareTo(MessageLevel.LINT) < 0) { // If there's only checkpoints, be quiet. ignoreLevel = MessageLevel.LOG; } try { for (Message m : mq.getMessages()) { MessageLevel level = m.getMessageLevel(); if (ignoreLevel != null && level.compareTo(ignoreLevel) <= 0) { continue; } out.append(level.name() + ": "); m.format(mc, out); out.append("\n"); if (maxLevel.compareTo(level) < 0) { maxLevel = level; } } } catch (IOException ex) { ex.printStackTrace(); } return maxLevel; }
@Test public void forEach() { InternalIterable<Boolean> select = this.newPrimitiveWith(true, false, true, false, true); Appendable builder = new StringBuilder(); Procedure<Boolean> appendProcedure = Procedures.append(builder); select.forEach(appendProcedure); Assert.assertEquals("truefalsetruefalsetrue", builder.toString()); }
@Test public void appendString_with_start_separator_end() { ImmutableBag<String> bag = this.newBag(); Appendable builder = new StringBuilder(); bag.appendString(builder, "[", ", ", "]"); Assert.assertEquals(bag.toString(), builder.toString()); }
@Test public void appendString_with_separator() { ImmutableBag<String> bag = this.newBag(); Appendable builder = new StringBuilder(); bag.appendString(builder, ", "); Assert.assertEquals(bag.toString(), '[' + builder.toString() + ']'); }
@Test public void appendString() { ImmutableBag<String> bag = this.newBag(); Appendable builder = new StringBuilder(); bag.appendString(builder); Assert.assertEquals(FastList.newList(bag).makeString(), builder.toString()); }
protected static void unicodeEscape(Appendable out, int ch) throws IOException { out.append('\\'); out.append('u'); out.append(hexdigits[(ch >>> 12)]); out.append(hexdigits[(ch >>> 8) & 0xf]); out.append(hexdigits[(ch >>> 4) & 0xf]); out.append(hexdigits[(ch) & 0xf]); }
private static void appendFirstField(Appendable out, String name, CharSequence value) throws IOException { out.append("\""); out.append(name); out.append("\""); out.append(":"); out.append(value); }
@Override @Test public void appendString() { MutableCollection<Object> collection = this.newWith(1, 2, 3); Appendable builder = new StringBuilder(); collection.appendString(builder); Assert.assertEquals(collection.toString(), '[' + builder.toString() + ']'); }
public void appendString(Appendable appendable, String start, String separator, String end) { try { appendable.append(start); appendable.append(end); } catch (IOException e) { throw new RuntimeException(e); } }
/** {@inheritDoc} */ @Override protected void toTextInternal(Appendable writer) throws IOException { writer.append(getArithmeticSign()); if (stateObject != null) { writer.append(SPACE); stateObject.toString(writer); } }
public void complete() { try { if (c == '{') _buffer.append("{}"); else if (c != 0) _buffer.append("}"); } catch (IOException e) { throw new RuntimeException(e); } }
private static void writeJSONValue(Appendable sb, Object o, int indentFactor, int indent) throws Exception { if (o == null) sb.append("null"); else if (o instanceof String) sb.append(JSONObject.quote((String) o)); else if (o instanceof JSONObject) writeJSON(sb, (JSONObject) o, indentFactor, indent); else if (o instanceof JSONArray) writeJSON(sb, (JSONArray) o, indentFactor, indent); else sb.append(o.toString()); }
public void write(Appendable out) throws IOException { out.append('<'); for (Iterator<Parameter> iter = parameters.iterator(); iter.hasNext(); ) { iter.next().write(out); if (iter.hasNext()) out.append(", "); } out.append("> "); getType().write(out); }
public void formatShort(Appendable out) throws IOException { if (!FilePosition.PREDEFINED.equals(this)) { MessageContext mc = new MessageContext(); mc.addInputSource(source); out.append(mc.abbreviate(source)).append(":").append(String.valueOf(this.startLineNo)); } else { out.append("predefined"); } }
@Test public void writeFile() { MetaRepository m3 = MetaRepository.createFM3(); Appendable stream = new StringBuilder(); m3.accept(new MSEPrinter(stream)); String mse = stream.toString(); assertTrue(mse.length() != 0); // out(mse); }
@Override public void addEndText(final Appendable out, final Object... data) { try { out.append("</applet>"); out.append("\n"); } catch (IOException e) { throw new RuntimeException(e); } }
@Override public void printMalformedExpression(Appendable a, int flags) throws IOException { a.append("-("); if (negated == null) { a.append("null"); } else { negated.print(a, flags); } a.append(')'); }
@Override protected void toString(Appendable sb, Escaper escaper) throws IOException { if (isString()) { sb.append('"'); sb.append(escaper.escapeJsonString(value.toString())); sb.append('"'); } else { sb.append(value.toString()); } }
/* ------------------------------------------------------------ */ public static void toHex(byte b, Appendable buf) { try { int d = 0xf & ((0xF0 & b) >> 4); buf.append((char) ((d > 9 ? ('A' - 10) : '0') + d)); d = 0xf & b; buf.append((char) ((d > 9 ? ('A' - 10) : '0') + d)); } catch (IOException e) { throw new RuntimeException(e); } }
public static void writeReplaceWhitespaces( final String str, final char replacement, final Appendable writer) throws IOException { for (char c : steal(str)) { if (Character.isWhitespace(c)) { writer.append(replacement); } else { writer.append(c); } } }
void appendAnnotation( final Unit<?> unit, final CharSequence symbol, final CharSequence annotation, final Appendable appendable) throws IOException { appendable.append('{'); appendable.append(annotation); appendable.append('}'); }