/** * Returns the first non-empty value in the list of objects. * * @param o The objects to check. * @return The first object whose call to {@link #isEmpty(Object)} returns <jk>false</jk>, otherwise <jk>null</jk>. */ @SafeVarargs public static <T> T firstNonEmpty(T...o) { for (T oo : o) if (! isEmpty(oo)) return oo; return null; } }
/** * Returns the first non-empty value in the list of objects. * * @param o The objects to check. * @return The first object whose call to {@link #isEmpty(Object)} returns <jk>false</jk>, otherwise <jk>null</jk>. */ @SafeVarargs public static <T> T firstNonEmpty(T...o) { for (T oo : o) if (! isEmpty(oo)) return oo; return null; } }
/** * Returns the first non-empty value in the list of objects. * * @param o The objects to check. * @return The first object whose call to {@link #isEmpty(Object)} returns <jk>false</jk>, otherwise <jk>null</jk>. */ @SafeVarargs public static <T> T firstNonEmpty(T...o) { for (T oo : o) if (! isEmpty(oo)) return oo; return null; } }
/** * Conditionally appends a value to this map. * * @param overwrite Overwrite the previous value if there was one. * @param skipNullValue Skip adding the value if the value is <jk>null</jk>. * @param skipEmptyValue Skip adding the value if the value is an empty string. * @param key The key. * @param value The value. * @return This object (for method chaining). */ public ObjectMap appendIf(boolean overwrite, boolean skipNullValue, boolean skipEmptyValue, String key, Object value) { if (value == null && skipNullValue) return this; if (skipEmptyValue && ObjectUtils.isEmpty(value)) return this; Object current = get(key); if (current == null || overwrite) put(key, value); return this; }
/** * Conditionally appends a value to this map. * * @param overwrite Overwrite the previous value if there was one. * @param skipNullValue Skip adding the value if the value is <jk>null</jk>. * @param skipEmptyValue Skip adding the value if the value is an empty string. * @param key The key. * @param value The value. * @return This object (for method chaining). */ public ObjectMap appendIf(boolean overwrite, boolean skipNullValue, boolean skipEmptyValue, String key, Object value) { if (value == null && skipNullValue) return this; if (skipEmptyValue && ObjectUtils.isEmpty(value)) return this; Object current = get(key); if (current == null || overwrite) put(key, value); return this; }
/** * Conditionally appends a value to this map. * * @param overwrite Overwrite the previous value if there was one. * @param skipNullValue Skip adding the value if the value is <jk>null</jk>. * @param skipEmptyValue Skip adding the value if the value is an empty string. * @param key The key. * @param value The value. * @return This object (for method chaining). */ public ObjectMap appendIf(boolean overwrite, boolean skipNullValue, boolean skipEmptyValue, String key, Object value) { if (value == null && skipNullValue) return this; if (skipEmptyValue && ObjectUtils.isEmpty(value)) return this; Object current = get(key); if (current == null || overwrite) put(key, value); return this; }
/** * Specifies that the following value can be added as an HTTP part. */ private boolean canAdd(Object value, HttpPartSchema schema, boolean skipIfEmpty) { if (value != null) { if (ObjectUtils.isEmpty(value) && skipIfEmpty) return false; return true; } if (schema == null) return false; if (schema.isRequired()) return true; String def = schema.getDefault(); if (def == null) return false; if (StringUtils.isEmpty(def) && skipIfEmpty) return false; return true; } }
/** * Specifies that the following value can be added as an HTTP part. */ private boolean canAdd(Object value, HttpPartSchema schema, boolean skipIfEmpty) { if (value != null) { if (ObjectUtils.isEmpty(value) && skipIfEmpty) return false; return true; } if (schema == null) return false; if (schema.isRequired()) return true; String def = schema.getDefault(); if (def == null) return false; if (StringUtils.isEmpty(def) && skipIfEmpty) return false; return true; } }
/** * Specifies that the following value can be added as an HTTP part. */ private boolean canAdd(Object value, HttpPartSchema schema, boolean skipIfEmpty) { if (value != null) { if (ObjectUtils.isEmpty(value) && skipIfEmpty) return false; return true; } if (schema == null) return false; if (schema.isRequired()) return true; String def = schema.getDefault(); if (def == null) return false; if (StringUtils.isEmpty(def) && skipIfEmpty) return false; return true; } }
/** * Renders the contents of the <code><xt><body></xt>/<xt><article></xt></code> element. * * @param session The current serializer session. * @param w The writer being written to. * @param o The object being serialized. * @throws Exception Any exception can be thrown. */ protected void article(HtmlDocSerializerSession session, HtmlWriter w, Object o) throws Exception { // To allow for page formatting using CSS, we encapsulate the data inside two div tags: // <div class='outerdata'><div class='data' id='data'>...</div></div> w.oTag(4, "div").attr("class","outerdata").append('>').nl(4); w.oTag(5, "div").attr("class","data").attr("id", "data").append('>').nl(5); if (o == null) { w.append(6, "<null/>").nl(6); } else if (ObjectUtils.isEmpty(o)){ String m = session.getNoResultsMessage(); if (exists(m)) w.append(6, m).nl(6); } else { session.indent = 6; w.flush(); session.parentSerialize(w, o); } w.ie(5).eTag("div").nl(5); w.ie(4).eTag("div").nl(4); }
/** * Renders the contents of the <code><xt><body></xt>/<xt><article></xt></code> element. * * @param session The current serializer session. * @param w The writer being written to. * @param o The object being serialized. * @throws Exception Any exception can be thrown. */ protected void article(HtmlDocSerializerSession session, HtmlWriter w, Object o) throws Exception { // To allow for page formatting using CSS, we encapsulate the data inside two div tags: // <div class='outerdata'><div class='data' id='data'>...</div></div> w.oTag(4, "div").attr("class","outerdata").append('>').nl(4); w.oTag(5, "div").attr("class","data").attr("id", "data").append('>').nl(5); if (o == null) { w.append(6, "<null/>").nl(6); } else if (ObjectUtils.isEmpty(o)){ String m = session.getNoResultsMessage(); if (exists(m)) w.append(6, m).nl(6); } else { session.indent = 6; w.flush(); session.parentSerialize(w, o); } w.ie(5).eTag("div").nl(5); w.ie(4).eTag("div").nl(4); }
/** * Renders the contents of the <code><xt><body></xt>/<xt><article></xt></code> element. * * @param session The current serializer session. * @param w The writer being written to. * @param o The object being serialized. * @throws Exception Any exception can be thrown. */ protected void article(HtmlDocSerializerSession session, HtmlWriter w, Object o) throws Exception { // To allow for page formatting using CSS, we encapsulate the data inside two div tags: // <div class='outerdata'><div class='data' id='data'>...</div></div> w.oTag(4, "div").attr("class","outerdata").append('>').nl(4); w.oTag(5, "div").attr("class","data").attr("id", "data").append('>').nl(5); if (o == null) { w.append(6, "<null/>").nl(6); } else if (ObjectUtils.isEmpty(o)){ String m = session.getNoResultsMessage(); if (exists(m)) w.append(6, m).nl(6); } else { session.indent = 6; w.flush(); session.parentSerialize(w, o); } w.ie(5).eTag("div").nl(5); w.ie(4).eTag("div").nl(4); }