Example usage for com.google.common.base Strings nullToEmpty

List of usage examples for com.google.common.base Strings nullToEmpty

Introduction

In this page you can find the example usage for com.google.common.base Strings nullToEmpty.

Prototype

public static String nullToEmpty(@Nullable String string) 

Source Link

Document

Returns the given string if it is non-null; the empty string otherwise.

Usage

From source file:com.streamsets.datacollector.execution.runner.cluster.SlaveCallbackManager.java

public void updateSlaveCallbackInfo(CallbackInfo callbackInfo) {
    String sdcToken = Strings.nullToEmpty(this.clusterToken);
    if (sdcToken.equals(callbackInfo.getSdcClusterToken())
            && !RuntimeInfo.UNDEF.equals(callbackInfo.getSdcURL())) {
        callbackCacheLock.lock();/*from ww  w  .java 2  s .  c o m*/
        try {
            slaveCallbackList.put(callbackInfo.getSdcURL(), callbackInfo);
        } finally {
            callbackCacheLock.unlock();
        }
    } else {
        LOG.warn("SDC Cluster token not matched");
    }
}

From source file:io.druid.query.expression.RegexpExtractExprMacro.java

@Override
public Expr apply(final List<Expr> args) {
    if (args.size() < 2 || args.size() > 3) {
        throw new IAE("Function[%s] must have 2 to 3 arguments", name());
    }//from w w w  .  j ava2 s . com

    final Expr arg = args.get(0);
    final Expr patternExpr = args.get(1);
    final Expr indexExpr = args.size() > 2 ? args.get(2) : null;

    if (!patternExpr.isLiteral() || (indexExpr != null && !indexExpr.isLiteral())) {
        throw new IAE("Function[%s] pattern and index must be literals", name());
    }

    // Precompile the pattern.
    final Pattern pattern = Pattern.compile(String.valueOf(patternExpr.getLiteralValue()));

    final int index = indexExpr == null ? 0 : ((Number) indexExpr.getLiteralValue()).intValue();
    class RegexpExtractExpr implements Expr {
        @Nonnull
        @Override
        public ExprEval eval(final ObjectBinding bindings) {
            final Matcher matcher = pattern.matcher(Strings.nullToEmpty(arg.eval(bindings).asString()));
            final String retVal = matcher.find() ? matcher.group(index) : null;
            return ExprEval.of(Strings.emptyToNull(retVal));
        }

        @Override
        public void visit(final Visitor visitor) {
            arg.visit(visitor);
            visitor.visit(this);
        }
    }
    return new RegexpExtractExpr();
}

From source file:com.sleepcamel.bsoneer.processor.generators.AnnotationInfo.java

public AnnotationInfo(TypeMirror tm, String idProperty, boolean keepNonIdProperty, TypeMirror idGeneratorType,
        boolean customGenerator) {
    this.tm = tm;
    if (tm.getKind() != TypeKind.DECLARED) {
        throw new RuntimeException(tm + " should be declared");
    }//from www.j a v a2 s  .  c om
    DeclaredType dt = (DeclaredType) tm;
    List<? extends TypeMirror> typeArguments = dt.getTypeArguments();
    if (typeArguments != null) {
        for (TypeMirror tms : typeArguments) {
            if (tms instanceof TypeVariable) {
                typeVariables.add((TypeVariable) tms);
            } else if (tms instanceof WildcardType) {
                typeWildcards.add((WildcardType) tms);
            }
        }
    }
    this.idGeneratorType = idGeneratorType;
    this.customGenerator = customGenerator;
    this.idProperty = Strings.nullToEmpty(idProperty).trim();
    this.keepNonIdProperty = keepNonIdProperty;
}

From source file:tech.sirwellington.alchemy.http.Step3Impl.java

@Override
public AlchemyRequest.Step3 usingHeader(String key, String value) throws IllegalArgumentException {
    checkThat(key).usingMessage("missing key").is(nonEmptyString());

    //Value of an HTTP Header can be empty ?
    value = Strings.nullToEmpty(value);

    Map<String, String> requestHeaders = Maps.newHashMap();

    //Keep existing headers
    if (request.getRequestHeaders() != null) {
        requestHeaders.putAll(request.getRequestHeaders());
    }/*from   w  w  w. j  av  a  2 s  .c om*/

    requestHeaders.put(key, value);

    this.request = HttpRequest.Builder.from(request).usingRequestHeaders(requestHeaders).build();

    return this;
}

From source file:org.attribyte.api.pubsub.impl.server.util.ServerUtil.java

/**
 * Gets an integer value from a servlet request.
 * @param request The request.//from  www  .j a  v a2 s. c  o m
 * @param name The parameter name.
 * @param defaultValue The default value.
 * @return The request or default value.
 */
public static int getParameter(final HttpServletRequest request, final String name, final int defaultValue) {
    String intVal = Strings.nullToEmpty(request.getParameter(name)).trim();
    try {
        return intVal.isEmpty() ? defaultValue : Integer.parseInt(intVal);
    } catch (NumberFormatException nfe) {
        return defaultValue;
    }
}

From source file:ealvatag.tag.id3.valuepair.EventTimingTimestampTypes.java

@Override
public String getValue(final int key) {
    if (!EVENT_TIMING_ID_RANGE.contains(key)) {
        return "";
    }/*www  .  j ava  2  s.co m*/
    return Strings.nullToEmpty(values[key - EVENT_TIMING_ID_RANGE.getLowerBounds()]);
}

From source file:com.google.devtools.treeshaker.TreeShaker.java

public TreeShaker(Options options) throws IOException {
    this.options = options;
    j2objcOptions = new com.google.devtools.j2objc.Options();
    j2objcOptions.load(new String[] { "-sourcepath", Strings.nullToEmpty(options.getSourcepath()), "-classpath",
            Strings.nullToEmpty(options.getClasspath()), "-encoding", options.fileEncoding(), "-source",
            options.sourceVersion().flag() });
}

From source file:io.druid.query.expression.LikeExprMacro.java

@Override
public Expr apply(final List<Expr> args) {
    if (args.size() < 2 || args.size() > 3) {
        throw new IAE("Function[%s] must have 2 or 3 arguments", name());
    }//from w w  w  . j a v a2 s  .  c o m

    final Expr arg = args.get(0);
    final Expr patternExpr = args.get(1);
    final Expr escapeExpr = args.size() > 2 ? args.get(2) : null;

    if (!patternExpr.isLiteral() || (escapeExpr != null && !escapeExpr.isLiteral())) {
        throw new IAE("pattern and escape must be literals");
    }

    final String escape = escapeExpr == null ? null : (String) escapeExpr.getLiteralValue();
    final Character escapeChar;

    if (escape != null && escape.length() != 1) {
        throw new IllegalArgumentException("Escape must be null or a single character");
    } else {
        escapeChar = escape == null ? null : escape.charAt(0);
    }

    final LikeDimFilter.LikeMatcher likeMatcher = LikeDimFilter.LikeMatcher
            .from(Strings.nullToEmpty((String) patternExpr.getLiteralValue()), escapeChar);

    class LikeExtractExpr implements Expr {
        @Nonnull
        @Override
        public ExprEval eval(final ObjectBinding bindings) {
            return ExprEval.of(likeMatcher.matches(arg.eval(bindings).asString()), ExprType.LONG);
        }

        @Override
        public void visit(final Visitor visitor) {
            arg.visit(visitor);
            visitor.visit(this);
        }
    }
    return new LikeExtractExpr();
}

From source file:fathom.xmlrpc.XmlRpcMethodRegistrar.java

public void addMethodGroup(String methodGroup, Class<?> methodGroupClass) {
    Object methodsObject = injector.getInstance(methodGroupClass);
    methodGroups.put(Strings.nullToEmpty(methodGroup),
            new XmlRpcMethodInvoker(methodGroup, methodGroupClass, methodsObject));
}

From source file:com.zimbra.cs.redolog.op.CreateFolderPath.java

public CreateFolderPath(int mailboxId, String path, Folder.FolderOptions fopt) {
    this();//from   w w w  .  j  a  va2  s  .  c om
    setMailboxId(mailboxId);
    this.path = path == null ? "" : path;
    this.attrs = fopt.getAttributes();
    this.defaultView = fopt.getDefaultView();
    this.flags = fopt.getFlags();
    this.color = fopt.getColor().getValue();
    this.url = Strings.nullToEmpty(fopt.getUrl());
    this.date = fopt.getDate();
    this.custom = fopt.getCustomMetadata();
}