private void addNamespace(Namespace ns) { if (ns == defaultNamespace) return; for (Namespace n : namespaces) if (n == ns) return; if (defaultNamespace != null && (ns.uri.equals(defaultNamespace.uri) || ns.name.equals(defaultNamespace.name))) defaultNamespace = ns; else namespaces = append(namespaces, ns); }
private void addNamespace(Namespace ns) { if (ns == defaultNamespace) return; for (Namespace n : namespaces) if (n == ns) return; if (defaultNamespace != null && (ns.uri.equals(defaultNamespace.uri) || ns.name.equals(defaultNamespace.name))) defaultNamespace = ns; else namespaces = append(namespaces, ns); }
private void addNamespace(Namespace ns) { if (ns == defaultNamespace) return; for (Namespace n : namespaces) if (n == ns) return; if (defaultNamespace != null && (ns.uri.equals(defaultNamespace.uri) || ns.name.equals(defaultNamespace.name))) defaultNamespace = ns; else namespaces = append(namespaces, ns); }
private static void add(Map<String,String[]> m, String key, String val) { boolean b = m.containsKey(key); if (val == null) { if (! b) m.put(key, null); } else if (b && m.get(key) != null) { m.put(key, append(m.get(key), val)); } else { m.put(key, new String[]{val}); } }
private static void add(Map<String,String[]> m, String key, String val) { boolean b = m.containsKey(key); if (val == null) { if (! b) m.put(key, null); } else if (b && m.get(key) != null) { m.put(key, append(m.get(key), val)); } else { m.put(key, new String[]{val}); } }
private static void add(Map<String,String[]> m, String key, String val) { boolean b = m.containsKey(key); if (val == null) { if (! b) m.put(key, null); } else if (b && m.get(key) != null) { m.put(key, append(m.get(key), val)); } else { m.put(key, new String[]{val}); } }
@Override /* RestResourceResolver */ public <T> T resolve(Object parent, Class<T> c, RestContextBuilder builder, Object...args) { return resolve(parent, c, ArrayUtils.append(args, builder)); } }
@Override /* RestResourceResolver */ public <T> T resolve(Object parent, Class<T> c, RestContextBuilder builder, Object...args) { return resolve(parent, c, ArrayUtils.append(args, builder)); } }
@Override /* RestResourceResolver */ public <T> T resolve(Object parent, Class<T> c, RestContextBuilder builder, Object...args) { return resolve(parent, c, ArrayUtils.append(args, builder)); } }
/** * Adds a set of header values to this object. * * @param name The header name. * @param values The header values. * @return This object (for method chaining). */ public RequestHeaders put(String name, Enumeration<String> values) { // Optimized for enumerations of one entry, the most-common case. if (values.hasMoreElements()) { String v = values.nextElement(); String[] s = new String[]{v}; while (values.hasMoreElements()) s = append(s, values.nextElement()); put(name, s); } return this; }
/** * Adds a set of header values to this object. * * @param name The header name. * @param values The header values. * @return This object (for method chaining). */ public RequestHeaders put(String name, Enumeration<String> values) { // Optimized for enumerations of one entry, the most-common case. if (values.hasMoreElements()) { String v = values.nextElement(); String[] s = new String[]{v}; while (values.hasMoreElements()) s = append(s, values.nextElement()); put(name, s); } return this; }
/** * Adds a set of header values to this object. * * @param name The header name. * @param values The header values. * @return This object (for method chaining). */ public RequestHeaders put(String name, Enumeration<String> values) { // Optimized for enumerations of one entry, the most-common case. if (values.hasMoreElements()) { String v = values.nextElement(); String[] s = new String[]{v}; while (values.hasMoreElements()) s = append(s, values.nextElement()); put(name, s); } return this; }
/** * Adds a writer to this tee writer. * * @param w The writer to add to this tee writer. * @param close * If <jk>false</jk>, then calling {@link #close()} on this tee writer will not filter to the specified writer. * @return This object (for method chaining). */ public TeeWriter add(Writer w, boolean close) { if (w == null) return this; if (! close) w = new NoCloseWriter(w); if (w == this) throw new RuntimeException("Cannot add this writer to itself."); for (Writer w2 : writers) if (w2 == w) throw new RuntimeException("Cannot add this writer again."); if (w instanceof TeeWriter) { for (Writer w2 : ((TeeWriter)w).writers) add(w2, true); } else { writers = ArrayUtils.append(writers, w); } return this; }
/** * Adds an output stream to this tee output stream. * * @param os The output stream to add to this tee output stream. * @param close * If <jk>false</jk>, then calling {@link #close()} on this stream will not filter to the specified output stream. * @return This object (for method chaining). */ public TeeOutputStream add(OutputStream os, boolean close) { if (os == null) return this; if (! close) os = new NoCloseOutputStream(os); if (os == this) throw new RuntimeException("Cannot add this output stream to itself."); for (OutputStream os2 : outputStreams) if (os2 == os) throw new RuntimeException("Cannot add this output stream again."); if (os instanceof TeeOutputStream) { for (OutputStream os2 : ((TeeOutputStream)os).outputStreams) add(os2, true); } else { outputStreams = ArrayUtils.append(outputStreams, os); } return this; }
/** * Adds a writer to this tee writer. * * @param w The writer to add to this tee writer. * @param close * If <jk>false</jk>, then calling {@link #close()} on this tee writer will not filter to the specified writer. * @return This object (for method chaining). */ public TeeWriter add(Writer w, boolean close) { if (w == null) return this; if (! close) w = new NoCloseWriter(w); if (w == this) throw new RuntimeException("Cannot add this writer to itself."); for (Writer w2 : writers) if (w2 == w) throw new RuntimeException("Cannot add this writer again."); if (w instanceof TeeWriter) { for (Writer w2 : ((TeeWriter)w).writers) add(w2, true); } else { writers = ArrayUtils.append(writers, w); } return this; }
@Test public void testAppendCollectionToArray() throws Exception { String[] s = new String[0]; s = append(s, Arrays.asList(new String[]{"a","b"})); assertObjectEquals("['a','b']", s); s = append(s, Arrays.asList(new String[]{"c"})); assertObjectEquals("['a','b','c']", s); s = append(s, Arrays.asList(new String[0])); assertObjectEquals("['a','b','c']", s); try { append((Object[])null, Collections.emptyList()); fail(); } catch (IllegalArgumentException e) {} }
@Test public void testAppendArrayToArray() throws Exception { String[] s = new String[0]; s = append(s, "a", "b"); assertObjectEquals("['a','b']", s); s = append(s, "c"); assertObjectEquals("['a','b','c']", s); s = append(s); assertObjectEquals("['a','b','c']", s); Object[] o = append((Object[])null); assertObjectEquals("[]", o); s = append((String[])null, "a", "b"); assertObjectEquals("['a','b']", s); }
@Override /* SerializerSession */ protected void doSerialize(SerializerPipe out, Object o) throws Exception { if (isEnableNamespaces() && isAutoDetectNamespaces()) findNsfMappings(o); Namespace xs = getXsNamespace(); Namespace[] allNs = append(new Namespace[]{getDefaultNamespace()}, getNamespaces()); Schemas schemas = new Schemas(this, xs, getDefaultNamespace(), allNs); schemas.process(o); schemas.serializeTo(out.getWriter()); }
@Override /* SerializerSession */ protected void doSerialize(SerializerPipe out, Object o) throws Exception { if (isEnableNamespaces() && isAutoDetectNamespaces()) findNsfMappings(o); Namespace xs = getXsNamespace(); Namespace[] allNs = append(new Namespace[]{getDefaultNamespace()}, getNamespaces()); Schemas schemas = new Schemas(this, xs, getDefaultNamespace(), allNs); schemas.process(o); schemas.serializeTo(out.getWriter()); }
@Override /* SerializerSession */ protected void doSerialize(SerializerPipe out, Object o) throws Exception { if (isEnableNamespaces() && isAutoDetectNamespaces()) findNsfMappings(o); Namespace xs = getXsNamespace(); Namespace[] allNs = append(new Namespace[]{getDefaultNamespace()}, getNamespaces()); Schemas schemas = new Schemas(this, xs, getDefaultNamespace(), allNs); schemas.process(o); schemas.serializeTo(out.getWriter()); }