/** * <p>Returns either the passed in String, * or if the String is {@code null}, an empty String ("").</p> * * <pre> * StringUtils.defaultString(null) = "" * StringUtils.defaultString("") = "" * StringUtils.defaultString("bat") = "bat" * </pre> * * @see ObjectUtils#toString(Object) * @see String#valueOf(Object) * @param str the String to check, may be null * @return the passed in String, or the empty String if it * was {@code null} */ public static String defaultString(final String str) { return defaultString(str, EMPTY); }
/** * @param propertyWordDelimiters * a string containing all of the characters that should be * considered as word delimiters when creating Java Bean property * names from JSON property names. If blank or not set, JSON * properties will be considered to contain a single word when * creating Java Bean property names. */ public void setPropertyWordDelimiters(String propertyWordDelimiters) { this.propertyWordDelimiters = defaultString(propertyWordDelimiters).toCharArray(); }
@Override public char[] getPropertyWordDelimiters() { return defaultString(propertyWordDelimiters).toCharArray(); }
@Override public String[] getFileExtensions() { return defaultString(fileExtensions).split(" "); }
@Override public String[] getToStringExcludes() { return defaultString(toStringExcludes).split(" "); }
public boolean isAbsolutePath(String artifactsDir) { return new File(StringUtils.defaultString(artifactsDir)).isAbsolute(); }
public Map json() { Map<String, Object> model = new LinkedHashMap<>(); model.put("hostName", defaultString(hostName)); model.put("port", port == 0 ? "" : valueOf(port)); model.put("username", defaultString(username)); model.put("password", defaultString(getPassword())); model.put("tls", tls == null ? "false" : tls.toString()); model.put("from", defaultString(getFrom())); model.put("adminMail", defaultString(getAdminMail())); return model; }
/** * Gets a short message summarising the exception. * <p> * The message returned is of the form * {ClassNameWithoutPackage}: {ThrowableMessage} * * @param th the throwable to get a message for, null returns empty string * @return the message, non-null * @since 2.2 */ public static String getMessage(final Throwable th) { if (th == null) { return StringUtils.EMPTY; } final String clsName = ClassUtils.getShortClassName(th, null); final String msg = th.getMessage(); return clsName + ": " + StringUtils.defaultString(msg); }
/** * Get current time - joda * @param timezone time zone of current time * @return current datetime in the given timezone */ public static DateTime getCurrentTime(String timezone) { String tz = StringUtils.defaultString(timezone, ConfigurationKeys.DEFAULT_SOURCE_TIMEZONE); DateTimeZone dateTimeZone = getTimeZone(tz); DateTime currentTime = new DateTime(dateTimeZone); return currentTime; }
/** * 拼装 短异常类名: 异常信息 <-- RootCause的短异常类名: 异常信息 */ public static String toStringWithRootCause(@Nullable Throwable t) { if (t == null) { return StringUtils.EMPTY; } final String clsName = ClassUtils.getShortClassName(t, null); final String message = StringUtils.defaultString(t.getMessage()); Throwable cause = getRootCause(t); StringBuilder sb = new StringBuilder(128).append(clsName).append(": ").append(message); if (cause != t) { sb.append("; <---").append(toStringWithShortName(cause)); } return sb.toString(); }
/** * 拼装 短异常类名: 异常信息 <-- RootCause的短异常类名: 异常信息 */ public static String toStringWithRootCause(@Nullable Throwable t) { if (t == null) { return StringUtils.EMPTY; } final String clsName = ClassUtils.getShortClassName(t, null); final String message = StringUtils.defaultString(t.getMessage()); Throwable cause = getRootCause(t); StringBuilder sb = new StringBuilder(128).append(clsName).append(": ").append(message); if (cause != t) { sb.append("; <---").append(toStringWithShortName(cause)); } return sb.toString(); }
private static void generateRecursive(GenerationConfig config, SchemaMapper mapper, JCodeModel codeModel, String packageName, List<File> schemaFiles) throws IOException { Collections.sort(schemaFiles, config.getSourceSortOrder().getComparator()); for (File child : schemaFiles) { if (child.isFile()) { mapper.generate(codeModel, getNodeName(child.toURI().toURL(), config), defaultString(packageName), child.toURI().toURL()); } else { generateRecursive(config, mapper, codeModel, childQualifiedName(packageName, child.getName()), Arrays.asList(child.listFiles(config.getFileFilter()))); } } }
public String apply(String definitionName) { String defaultResolver = super.apply(definitionName); if (defaultResolver != null && config.isSeparatedOperationsEnabled()) return defaultString(config.getInterDocumentCrossReferencesPrefix()) + new File("..", defaultResolver).getPath(); else return defaultResolver; } }
@Test public void testDefault_StringString() { assertEquals("NULL", StringUtils.defaultString(null, "NULL")); assertEquals("", StringUtils.defaultString("", "NULL")); assertEquals("abc", StringUtils.defaultString("abc", "NULL")); }
@Test public void testDefault_String() { assertEquals("", StringUtils.defaultString(null)); assertEquals("", StringUtils.defaultString("")); assertEquals("abc", StringUtils.defaultString("abc")); }
/** * Returns the basePath which should be prepended to the relative path * * @return either the relative or the full path */ private String getBasePath() { if (config.isBasePathPrefixEnabled()) { return StringUtils.defaultString(context.getSwagger().getBasePath()); } return ""; }
public String apply(PathOperation operation) { if (!config.isInterDocumentCrossReferencesEnabled() || context.getOutputPath() == null) return null; else return defaultString(config.getInterDocumentCrossReferencesPrefix()) + operationDocumentNameResolver.apply(operation); } }
public String apply(String definitionName) { if (!config.isInterDocumentCrossReferencesEnabled() || context.getOutputPath() == null) return null; else return defaultString(config.getInterDocumentCrossReferencesPrefix()) + definitionDocumentNameResolver.apply(definitionName); } }
public String apply(String definitionName) { String defaultResolver = super.apply(definitionName); if (defaultResolver != null && config.isSeparatedDefinitionsEnabled()) return defaultString(config.getInterDocumentCrossReferencesPrefix()) + markupDocBuilder.addFileExtension(normalizeName(definitionName)); else return defaultResolver; } }
public String apply(String definitionName) { if (!config.isInterDocumentCrossReferencesEnabled() || context.getOutputPath() == null) return null; else return defaultString(config.getInterDocumentCrossReferencesPrefix()) + markupDocBuilder.addFileExtension(config.getSecurityDocument()); } }