List of usage examples for com.google.common.base Strings emptyToNull
@Nullable public static String emptyToNull(@Nullable String string)
From source file:org.gbif.registry2.ws.guice.StringTrimInterceptor.java
private void trimStringsOf(Object target) { WrapDynaBean wrapped = new WrapDynaBean(target); DynaClass dynaClass = wrapped.getDynaClass(); for (DynaProperty dynaProp : dynaClass.getDynaProperties()) { // Only operate on strings if (String.class.isAssignableFrom(dynaProp.getType())) { String prop = dynaProp.getName(); String orig = (String) wrapped.get(prop); if (orig != null) { String trimmed = Strings.emptyToNull(orig.trim()); if (!Objects.equal(orig, trimmed)) { LOG.debug("Overriding value of [{}] from [{}] to [{}]", prop, orig, trimmed); wrapped.set(prop, trimmed); }//ww w. j a v a2 s. c om } } } }
From source file:io.github.jonestimd.swing.validation.Validator.java
/** * Apply another validation after this validation. * @param other the other validator/* ww w.j a v a2s.c om*/ * @param separator the separator to use when joining the error messages * @return a new {@code Validator} that returns the combined messages of {@code this} and {@code other} */ default Validator<T> add(Validator<T> other, String separator) { return value -> Strings.emptyToNull(Stream.of(validate(value), other.validate(value)) .filter(Objects::nonNull).collect(Collectors.joining(separator))); }
From source file:org.n52.shetland.ogc.ows.OwsCapabilities.java
public void setUpdateSequence(String updateSequence) { this.updateSequence = Optional.ofNullable(Strings.emptyToNull(updateSequence)); }
From source file:de.bund.bfr.knime.pmm.js.common.Matrix.java
/** * Sets the detail of this {@link Matrix}. * /*from w w w. j a va 2 s . com*/ * Empty strings are converted to null. * * @param detail * the detail to be set */ public void setDetail(String detail) { this.detail = Strings.emptyToNull(detail); }
From source file:ratpack.server.internal.InferringPublicAddress.java
private HostAndPort getForwardedHostData(Request request) { Headers headers = request.getHeaders(); String forwardedHostHeader = Strings.emptyToNull(headers.get(X_FORWARDED_HOST.toString())); String hostPortString = forwardedHostHeader != null ? Iterables.getFirst(FORWARDED_HOST_SPLITTER.split(forwardedHostHeader), null) : null;/* w w w. j a v a2s. com*/ return hostPortString != null ? HostAndPort.fromString(hostPortString) : null; }
From source file:de.bund.bfr.knime.pmm.js.common.Agent.java
/** * Sets the detail of this {@link Agent}. * /*from w w w . j a va2 s.c o m*/ * Empty strings are converted to null. * * @param detail * the detail to be set */ public void setDetail(final String detail) { this.detail = Strings.emptyToNull(detail); }
From source file:fathom.realm.MemoryRealm.java
protected Account parseAccount(Config accountConfig) { // all accounts require a username String username = Strings.emptyToNull(accountConfig.getString("username")); Preconditions.checkNotNull(username, "The 'username' setting may not be null nor empty!"); String name = null;/* w w w .ja v a 2 s .c o m*/ if (accountConfig.hasPath("name")) { name = accountConfig.getString("name"); } String password = null; if (accountConfig.hasPath("password")) { password = accountConfig.getString("password"); } StandardCredentials credentials = new StandardCredentials(username, password); Account account = new Account(name, credentials); if (accountConfig.hasPath("emailAddresses")) { account.addEmailAddresses(accountConfig.getStringList("emailAddresses")); } if (accountConfig.hasPath("tokens")) { account.addTokens(accountConfig.getStringList("tokens")); for (String token : account.getTokens()) { if (tokens.containsKey(token)) { String otherAccount = tokens.get(token).getUsername(); log.error("Token collision: {} has the same token as {}", account.getUsername(), otherAccount); } else { tokens.put(token, account); } } } if (accountConfig.hasPath("disabled") && accountConfig.getBoolean("disabled")) { account.setDisabled(); } // add account roles if (accountConfig.hasPath("roles")) { for (String role : accountConfig.getStringList("roles")) { if (definedRoles.containsKey(role)) { Role definedRole = definedRoles.get(role); account.getAuthorizations().addRole(definedRole); } else { account.getAuthorizations().addRole(role); } } } // add discrete account permissions if (accountConfig.hasPath("permissions")) { for (String permission : accountConfig.getStringList("permissions")) { account.getAuthorizations().addPermission(permission); } } return account; }
From source file:org.javahispano.javaleague.client.application.cars.CarsView.java
@UiHandler("filter") void onFilter(ClickEvent event) { String color = Strings.emptyToNull(Window.prompt("Enter a color:", "")); getUiHandlers().filter(color, 0, pager.getPageSize()); }
From source file:org.sonatype.nexus.jmx.reflect.ReflectionMBeanBuilder.java
/** * Discover managed attributes and operations for the given type. * * Target must have been previously configured. *///from ww w . j a v a2 s.c om public ReflectionMBeanBuilder discover() throws Exception { checkNotNull(target); log.debug("Discovering managed members of type: {}", type); ManagedObject managedDescriptor = type.getAnnotation(ManagedObject.class); assert managedDescriptor != null; // track attribute builders for getter/setter correlation Map<String, ReflectionMBeanAttribute.Builder> attributeBuilders = Maps.newHashMap(); // discover attributes and operations for (Method method : type.getMethods()) { // skip non-manageable methods if (method.isBridge() || method.isSynthetic()) { continue; } log.trace("Scanning for managed annotations on method: {}", method); ManagedAttribute attributeDescriptor = method.getAnnotation(ManagedAttribute.class); ManagedOperation operationDescriptor = method.getAnnotation(ManagedOperation.class); // skip if no configuration if (attributeDescriptor == null && operationDescriptor == null) { continue; } // complain if method marked as both attribute and operation if (attributeDescriptor != null && operationDescriptor != null) { log.warn("Confusing managed annotations on method: {}", method); continue; } if (attributeDescriptor != null) { log.trace("Processing attribute descriptor: {}", attributeDescriptor); // add attribute String name = Strings.emptyToNull(attributeDescriptor.name()); if (name == null) { name = attributeName(method); } boolean getter = isGetter(method); boolean setter = isSetter(method); // complain if method is not a valid getter or setter if (name == null || (!getter && !setter)) { log.warn("Invalid attribute getter or setter method: {}", method); continue; } // lookup or create a new attribute builder ReflectionMBeanAttribute.Builder builder = attributeBuilders.get(name); if (builder == null) { builder = new ReflectionMBeanAttribute.Builder().name(name).target(target); attributeBuilders.put(name, builder); } // do not clobber description if set on only one attribute method if (Strings.emptyToNull(attributeDescriptor.description()) != null) { builder.description(attributeDescriptor.description()); } if (getter) { log.debug("Found attribute getter: {} -> {}", name, method); builder.getter(method); } else { log.debug("Found attribute setter: {} -> {}", name, method); builder.setter(method); } } else { log.trace("Processing operation descriptor: {}", operationDescriptor); // add operation String name = Strings.emptyToNull(operationDescriptor.name()); if (name == null) { name = method.getName(); } log.debug("Found operation: {} -> {}", name, method); operation(new ReflectionMBeanOperation.Builder().name(name).target(target) .impact(operationDescriptor.impact()) .description(Strings.emptyToNull(operationDescriptor.description())).method(method) .build()); } } // build all discovered attributes for (ReflectionMBeanAttribute.Builder builder : attributeBuilders.values()) { attribute(builder.build()); } // add descriptor descriptor(DescriptorHelper.build(type)); return this; }
From source file:org.gbif.metadata.eml.KeywordSet.java
/** * @param separator the separator to use between keywords *//*from ww w . j a va 2s . c o m*/ public void setKeywordsString(String keywords, String separator) { this.keywords.clear(); if (keywords != null) { for (String k : Splitter.on(separator).split(keywords)) { k = Strings.emptyToNull(k.trim()); this.keywords.add(k); } } }