/** * <p> * Checks if a CharSequence is not empty ("") and not null. * </p> * * <pre> * Strings.isNotEmpty(null) = false * Strings.isNotEmpty("") = false * Strings.isNotEmpty(" ") = true * Strings.isNotEmpty("bob") = true * Strings.isNotEmpty(" bob ") = true * </pre> * * <p> * Copied from Apache Commons Lang org.apache.commons.lang3.StringUtils.isNotEmpty(CharSequence) * </p> * * @param cs the CharSequence to check, may be null * @return {@code true} if the CharSequence is not empty and not null */ public static boolean isNotEmpty(final CharSequence cs) { return !isEmpty(cs); }
/** * <p> * Removes control characters (char <= 32) from both ends of this String returning {@code null} if the String is * empty ("") after the trim or if it is {@code null}. * * <p> * The String is trimmed using {@link String#trim()}. Trim removes start and end characters <= 32. * </p> * * <pre> * Strings.trimToNull(null) = null * Strings.trimToNull("") = null * Strings.trimToNull(" ") = null * Strings.trimToNull("abc") = "abc" * Strings.trimToNull(" abc ") = "abc" * </pre> * * <p> * Copied from Apache Commons Lang org.apache.commons.lang3.StringUtils.trimToNull(String) * </p> * * @param str the String to be trimmed, may be null * @return the trimmed String, {@code null} if only chars <= 32, empty or null String input */ public static String trimToNull(final String str) { final String ts = str == null ? null : str.trim(); return isEmpty(ts) ? null : ts; }
private Level(final String name, final int intLevel) { if (Strings.isEmpty(name)) { throw new IllegalArgumentException("Illegal null or empty Level name."); } if (intLevel < 0) { throw new IllegalArgumentException("Illegal Level int less than zero."); } this.name = name; this.intLevel = intLevel; this.standardLevel = StandardLevel.getStandardLevel(intLevel); if (LEVELS.putIfAbsent(name, this) != null) { throw new IllegalStateException("Level " + name + " has already been defined."); } }
protected EntryMessage entryMsg(final String format, final Object... params) { final int count = params == null ? 0 : params.length; if (count == 0) { if (Strings.isEmpty(format)) { return flowMessageFactory.newEntryMessage(null); } return flowMessageFactory.newEntryMessage(new SimpleMessage(format)); } if (format != null) { return flowMessageFactory.newEntryMessage(new ParameterizedMessage(format, params)); } final StringBuilder sb = new StringBuilder(); sb.append("params("); for (int i = 0; i < count; i++) { if (i > 0) { sb.append(", "); } final Object parm = params[i]; sb.append(parm instanceof Message ? ((Message) parm).getFormattedMessage() : String.valueOf(parm)); } sb.append(')'); return flowMessageFactory.newEntryMessage(new SimpleMessage(sb)); }
private StatusLogger(final String name, final MessageFactory messageFactory) { super(name, messageFactory); final String dateFormat = PROPS.getStringProperty(STATUS_DATE_FORMAT, Strings.EMPTY); final boolean showDateTime = !Strings.isEmpty(dateFormat); this.logger = new SimpleLogger("StatusLogger", Level.ERROR, false, true, showDateTime, false, dateFormat, messageFactory, PROPS, System.err); this.listenersLevel = Level.toLevel(DEFAULT_STATUS_LEVEL, Level.WARN).intLevel(); // LOG4J2-1813 if system property "log4j2.debug" is defined, print all status logging if (isDebugPropertyEnabled()) { logger.setLevel(Level.TRACE); } }
@Override public void contextDestroyed(final ServletContextEvent event) { if (this.servletContext == null || this.initializer == null) { LOGGER.warn("Context destroyed before it was initialized."); return; } LOGGER.debug("Log4jServletContextListener ensuring that Log4j shuts down properly."); this.initializer.clearLoggerContext(); // the application is finished // shutting down now if (initializer instanceof LifeCycle2) { final String stopTimeoutStr = servletContext.getInitParameter(KEY_STOP_TIMEOUT); final long stopTimeout = Strings.isEmpty(stopTimeoutStr) ? DEFAULT_STOP_TIMEOUT : Long.parseLong(stopTimeoutStr); final String timeoutTimeUnitStr = servletContext.getInitParameter(KEY_STOP_TIMEOUT_TIMEUNIT); final TimeUnit timeoutTimeUnit = Strings.isEmpty(timeoutTimeUnitStr) ? DEFAULT_STOP_TIMEOUT_TIMEUNIT : TimeUnit.valueOf(timeoutTimeUnitStr.toUpperCase(Locale.ROOT)); ((LifeCycle2) this.initializer).stop(stopTimeout, timeoutTimeUnit); } else { this.initializer.stop(); } } }
public static void main(String[] args) { if (Strings.isEmpty(System.getProperty(AbstractEnvironment.ACTIVE_PROFILES_PROPERTY_NAME))) { /*System.setProperty(AbstractEnvironment.ACTIVE_PROFILES_PROPERTY_NAME, "oauth2-extractors-baeldung");*/ System.setProperty(AbstractEnvironment.ACTIVE_PROFILES_PROPERTY_NAME, "oauth2-extractors-github"); } SpringApplication.run(ExtractorsApplication.class, args); }
private MongoClient getConnectedClient() { if (Strings.isEmpty(username)) { return new MongoClient(host, port); } else { MongoCredential credential = MongoCredential.createCredential(username, databaseName, password.toCharArray()); return new MongoClient(new ServerAddress(host, port), Lists.newArrayList(credential)); } } }
private MongoClient getConnectedClient() { if (Strings.isEmpty(username)) { return new MongoClient(host, port); } else { MongoCredential credential = MongoCredential.createCredential(username, databaseName, password.toCharArray()); return new MongoClient(new ServerAddress(host, port), Lists.newArrayList(credential)); } } }
@Override public StackTraceElement convertToEntityAttribute(final String s) { if (Strings.isEmpty(s)) { return null; } return StackTraceElementAttributeConverter.convertString(s); }
@Override public Map<String, String> convertToEntityAttribute(final String s) { if (Strings.isEmpty(s)) { return null; } try { return OBJECT_MAPPER.readValue(s, new TypeReference<Map<String, String>>() { }); } catch (final IOException e) { throw new PersistenceException("Failed to convert JSON string to map.", e); } } }
@Override public Level convertToEntityAttribute(final String s) { if (Strings.isEmpty(s)) { return null; } return Level.toLevel(s, null); } }
private String getSystemProperty(final String prefix, final String name) { final String value = getSystemProperty(name); if (Strings.isEmpty(value)) { return Strings.EMPTY; } return prefix + value; }
public void setLocaleCode(String localeCode) { Iterator<Locale> locales = FacesContext.getCurrentInstance().getApplication().getSupportedLocales(); while (locales.hasNext()) { Locale locale = locales.next(); if (!Strings.isEmpty(locale.getLanguage()) && locale.getLanguage().equals(localeCode)) { this.localeCode = localeCode; FacesContext.getCurrentInstance().getViewRoot().setLocale(new Locale(localeCode)); setCookieValue(localeCode); break; } } }
@Override public Marker convertToEntityAttribute(final String s) { if (Strings.isEmpty(s)) { return null; } final int bracket = s.indexOf("["); return bracket < 1 ? MarkerManager.getMarker(s) : MarkerManager.getMarker(s.substring(0, bracket)); } }
private FilterComponentBuilder createFilter(final String key, final Properties properties) { final String type = (String) properties.remove(CONFIG_TYPE); if (Strings.isEmpty(type)) { throw new ConfigurationException("No type attribute provided for Appender " + key); } final String onMatch = (String) properties.remove("onMatch"); final String onMisMatch = (String) properties.remove("onMisMatch"); final FilterComponentBuilder filterBuilder = builder.newFilter(type, onMatch, onMisMatch); return processRemainingProperties(filterBuilder, properties); }
@Override public Message convertToEntityAttribute(final String s) { if (Strings.isEmpty(s)) { return null; } return LOGGER.getMessageFactory().newMessage(s); } }
@PluginFactory public static GelfDynamicMdcLogFields createField(@PluginConfiguration final Configuration config, @PluginAttribute("regex") String regex) { if (Strings.isEmpty(regex)) { LOGGER.error("The regex is empty"); return null; } return new GelfDynamicMdcLogFields(regex); } }
@PluginFactory public static GelfDynamicMdcLogFields createField(@PluginConfiguration final Configuration config, @PluginAttribute("regex") String regex) { if (Strings.isEmpty(regex)) { LOGGER.error("The regex is empty"); return null; } return new GelfDynamicMdcLogFields(regex); } }
@PluginFactory public static GelfDynamicMdcLogFields createField(@PluginConfiguration final Configuration config, @PluginAttribute("regex") String regex) { if (Strings.isEmpty(regex)) { LOGGER.error("The regex is empty"); return null; } return new GelfDynamicMdcLogFields(regex); } }