List of usage examples for com.google.common.base Strings emptyToNull
@Nullable public static String emptyToNull(@Nullable String string)
From source file:net.es.nsi.pce.pf.PfUtils.java
public static String getDestinationStpOrFail(P2PServiceBaseType p2ps) { Optional<String> destStp = Optional.fromNullable(Strings.emptyToNull(p2ps.getDestSTP())); if (destStp.isPresent()) { return destStp.get(); }/*from w w w . java2 s .c o m*/ throw Exceptions.missingParameter(Point2PointTypes.getSourceStp().getNamespace(), Point2PointTypes.getDestStp().getType(), "null"); }
From source file:eu.arkitech.logback.common.DefaultLoggingEventMutator.java
@Override public void mutate(final ILoggingEvent event_) { final SLoggingEvent1 event = (SLoggingEvent1) event_; final String application = Strings .emptyToNull(Objects.firstNonNull(this.application, DefaultLoggingEventMutator.defaultApplication)); final String component = Strings .emptyToNull(Objects.firstNonNull(this.component, DefaultLoggingEventMutator.defaultComponent)); final String node = Strings .emptyToNull(Objects.firstNonNull(this.node, DefaultLoggingEventMutator.defaultNode)); long sequence; synchronized (this) { sequence = this.sequence; this.sequence++; }//w w w .j av a 2s .c om if (event.mdcPropertyMap == null) event.mdcPropertyMap = new HashMap<String, String>(3); else event.mdcPropertyMap = new HashMap<String, String>(event.mdcPropertyMap); if ((application != null) && !event.mdcPropertyMap.containsKey(DefaultLoggingEventMutator.defaultApplicationMdcName)) event.mdcPropertyMap.put(DefaultLoggingEventMutator.defaultApplicationMdcName, application); if ((component != null) && !event.mdcPropertyMap.containsKey(DefaultLoggingEventMutator.defaultComponentMdcName)) event.mdcPropertyMap.put(DefaultLoggingEventMutator.defaultComponentMdcName, component); if ((node != null) && !event.mdcPropertyMap.containsKey(DefaultLoggingEventMutator.defaultNodeMdcName)) event.mdcPropertyMap.put(DefaultLoggingEventMutator.defaultNodeMdcName, node); event.mdcPropertyMap.put(DefaultLoggingEventMutator.defaultSequenceMdcKey, Long.toString(sequence)); final LinkedList<String> mdcInvalidKeys = new LinkedList<String>(); for (final String mdcKey : event.mdcPropertyMap.keySet()) { final Object mdcValue = event.mdcPropertyMap.get(mdcKey); if (!(mdcValue instanceof String)) mdcInvalidKeys.add(mdcKey); } for (final String mdcInvalidKey : mdcInvalidKeys) event.mdcPropertyMap.remove(mdcInvalidKey); if (event.argumentArray != null) for (int index = 0; index < event.argumentArray.length; index++) if ((event.argumentArray[index] != null) && !(event.argumentArray[index] instanceof Serializable)) event.argumentArray[index] = String.valueOf(event.argumentArray[index]); }
From source file:com.parallax.server.blocklyprop.servlets.RegisterServlet.java
@Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.setContentType("application/json"); String screenname = Strings.emptyToNull(req.getParameter("screenname")); String email = Strings.emptyToNull(req.getParameter("email")); String password = Strings.emptyToNull(req.getParameter("password")); String confirmPassword = Strings.emptyToNull(req.getParameter("confirmpassword")); req.setAttribute("screenname", screenname == null ? "" : screenname); req.setAttribute("email", email == null ? "" : email); Long idUser;//from w w w.j a v a 2s. c o m try { idUser = securityService.register(screenname, email, password, confirmPassword); if (idUser != null && idUser > 0) { req.getRequestDispatcher("WEB-INF/servlet/register/registered.jsp").forward(req, resp); } else { req.setAttribute("error", true); req.getRequestDispatcher("WEB-INF/servlet/register/register.jsp").forward(req, resp); } } catch (NonUniqueEmailException ex) { req.setAttribute("emailAlreadyUsed", true); req.getRequestDispatcher("WEB-INF/servlet/register/register.jsp").forward(req, resp); } catch (PasswordVerifyException ex) { req.setAttribute("passwordsDontMatch", true); req.getRequestDispatcher("WEB-INF/servlet/register/register.jsp").forward(req, resp); } catch (NullPointerException npe) { req.setAttribute("missingFields", true); req.getRequestDispatcher("WEB-INF/servlet/register/register.jsp").forward(req, resp); } catch (PasswordComplexityException pce) { req.setAttribute("passwordComplexity", true); req.getRequestDispatcher("WEB-INF/servlet/register/register.jsp").forward(req, resp); } catch (ScreennameUsedException sue) { req.setAttribute("screennameUsed", true); req.getRequestDispatcher("WEB-INF/servlet/register/register.jsp").forward(req, resp); } }
From source file:com.google.gerrit.server.project.CommentLinkInfo.java
public CommentLinkInfo(String name, String match, String link, String html, Boolean enabled) { checkArgument(name != null, "invalid commentlink.name"); checkArgument(!Strings.isNullOrEmpty(match), "invalid commentlink.%s.match", name); link = Strings.emptyToNull(link); html = Strings.emptyToNull(html);// w ww. j a v a 2s. c o m checkArgument((link != null && html == null) || (link == null && html != null), "commentlink.%s must have either link or html", name); this.name = name; this.match = match; this.link = link; this.html = html; this.enabled = enabled; }
From source file:org.n52.shetland.util.StringHelper.java
public static String convertStreamToString(InputStream is, String charset) throws IOException { try (InputStreamReader reader = new InputStreamReader(is, Strings.emptyToNull(charset))) { return CharStreams.toString(reader); } catch (IOException ex) { throw new IOException("Error while reading content of HTTP request", ex); }//www . ja va 2 s .c om }
From source file:com.skcraft.launcher.swing.ObjectSwingMapper.java
public void map(@NonNull final JTextComponent textComponent, String name) { final MutatorAccessorField<String> field = getField(name, String.class); add(new FieldMapping() { @Override/*from w w w . jav a 2 s.c o m*/ public void copyFromObject() { textComponent.setText(field.get()); } @SuppressWarnings("unchecked") @Override public void copyFromSwing() { field.set(Strings.emptyToNull(textComponent.getText())); } }); }
From source file:com.mattring.flink.nats.NatsSource.java
public NatsSource(NatsConfig natsConfig, String optionalDelimiter) { this.natsConfig = natsConfig; this.delimiter = Strings.emptyToNull(optionalDelimiter); this.isRunning = false; }
From source file:org.n52.shetland.ogc.ows.OwsRequestMethod.java
public OwsRequestMethod(URI href, String httpMethod, Collection<OwsDomain> constraints) { super(href);//from w w w .ja va2 s. c o m this.httpMethod = Objects.requireNonNull(Strings.emptyToNull(httpMethod)); this.constraints = CollectionHelper.newSortedSet(constraints); }
From source file:com.reprezen.swagedit.model.Model.java
/** * Returns a model build by parsing a YAML content. * //from www .j a v a 2 s . co m * @param text * @return model */ public static Model parseYaml(SwaggerSchema schema, String text) { if (Strings.emptyToNull(text) == null) { return empty(schema); } Model model = new Model(schema); try { reader(model).readValue(text); } catch (IllegalArgumentException | IOException e) { e.printStackTrace(); } for (AbstractNode node : model.allNodes()) { node.setType(model.schema.getType(node)); } return model; }
From source file:org.obiba.git.command.AbstractGitWriteCommand.java
protected AbstractGitWriteCommand(@NotNull File repositoryPath, @Nullable File workPath, String commitMessage) { super(repositoryPath, workPath); // Current JGit API does not account for empty string and ignores an empty commit message this.commitMessage = Strings.emptyToNull(commitMessage); }