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

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

Introduction

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

Prototype

public static boolean isNullOrEmpty(@Nullable String string) 

Source Link

Document

Returns true if the given string is null or is the empty string.

Usage

From source file:com.android.tools.idea.gradle.project.GradleModelVersionCheck.java

@Nullable
static FullRevision getModelVersion(@NotNull AndroidProject androidProject) {
    String modelVersion = androidProject.getModelVersion();
    if (Strings.isNullOrEmpty(modelVersion)) {
        return null;
    }//from w  w  w  . j av  a 2  s  .co m
    int snapshotIndex = modelVersion.indexOf("-");
    if (snapshotIndex != -1) {
        modelVersion = modelVersion.substring(0, snapshotIndex);
    }
    try {
        return FullRevision.parseRevision(modelVersion);
    } catch (NumberFormatException e) {
        LOG.info(String.format("Unable to parse Gradle model version '%1$s'", modelVersion), e);
        return null;
    }
}

From source file:org.apache.druid.java.util.common.parsers.TimestampParser.java

public static Function<String, DateTime> createTimestampParser(final String format) {
    if ("auto".equalsIgnoreCase(format)) {
        // Could be iso or millis
        final DateTimes.UtcFormatter parser = DateTimes.wrapFormatter(createAutoParser());
        return (String input) -> {
            Preconditions.checkArgument(!Strings.isNullOrEmpty(input), "null timestamp");

            for (int i = 0; i < input.length(); i++) {
                if (input.charAt(i) < '0' || input.charAt(i) > '9') {
                    input = ParserUtils.stripQuotes(input);
                    int lastIndex = input.lastIndexOf(' ');
                    DateTimeZone timeZone = DateTimeZone.UTC;
                    if (lastIndex > 0) {
                        DateTimeZone timeZoneFromString = ParserUtils
                                .getDateTimeZone(input.substring(lastIndex + 1));
                        if (timeZoneFromString != null) {
                            timeZone = timeZoneFromString;
                            input = input.substring(0, lastIndex);
                        }//from  w  w w .  jav  a 2s  .c  o  m
                    }

                    return parser.parse(input).withZone(timeZone);
                }
            }

            return DateTimes.utc(Long.parseLong(input));
        };
    } else if ("iso".equalsIgnoreCase(format)) {
        return input -> {
            Preconditions.checkArgument(!Strings.isNullOrEmpty(input), "null timestamp");
            return DateTimes.of(ParserUtils.stripQuotes(input));
        };
    } else if ("posix".equalsIgnoreCase(format) || "millis".equalsIgnoreCase(format)
            || "micro".equalsIgnoreCase(format) || "nano".equalsIgnoreCase(format)) {
        final Function<Number, DateTime> numericFun = createNumericTimestampParser(format);
        return input -> {
            Preconditions.checkArgument(!Strings.isNullOrEmpty(input), "null timestamp");
            return numericFun.apply(Long.parseLong(ParserUtils.stripQuotes(input)));
        };
    } else if ("ruby".equalsIgnoreCase(format)) {
        final Function<Number, DateTime> numericFun = createNumericTimestampParser(format);
        return input -> {
            Preconditions.checkArgument(!Strings.isNullOrEmpty(input), "null timestamp");
            return numericFun.apply(Double.parseDouble(ParserUtils.stripQuotes(input)));
        };
    } else {
        try {
            final DateTimes.UtcFormatter formatter = DateTimes.wrapFormatter(DateTimeFormat.forPattern(format));
            return input -> {
                Preconditions.checkArgument(!Strings.isNullOrEmpty(input), "null timestamp");
                return formatter.parse(ParserUtils.stripQuotes(input));
            };
        } catch (Exception e) {
            throw new IAE(e, "Unable to parse timestamps with format [%s]", format);
        }
    }
}

From source file:org.haiku.haikudepotserver.dataobjects.User.java

public static List<User> findByEmail(ObjectContext context, String email) {
    Preconditions.checkArgument(null != context, "the context must be supplied");
    Preconditions.checkArgument(!Strings.isNullOrEmpty(email), "the email must be supplied");
    return ObjectSelect.query(User.class).where(EMAIL.eq(email)).select(context);
}

From source file:org.mayocat.jackson.OptionalStringDeserializer.java

@Override
public Optional<String> deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
        throws IOException, JsonProcessingException {
    if (Strings.isNullOrEmpty(jsonParser.getValueAsString())) {
        return Optional.absent();
    }//from  www  . j  a  v  a2  s  .c o m
    return Optional.fromNullable(jsonParser.getValueAsString());
}

From source file:org.haiku.haikudepotserver.support.URLHelper.java

public static long payloadLength(URL url) throws IOException {
    Preconditions.checkArgument(null != url, "the url must be supplied");

    long result = -1;
    HttpURLConnection connection = null;

    switch (url.getProtocol()) {

    case "http":
    case "https":

        try {// ww  w.  ja va2 s  . c  o  m
            connection = (HttpURLConnection) url.openConnection();

            connection.setConnectTimeout(PAYLOAD_LENGTH_CONNECT_TIMEOUT);
            connection.setReadTimeout(PAYLOAD_LENGTH_READ_TIMEOUT);
            connection.setRequestMethod(HttpMethod.HEAD.name());
            connection.connect();

            String contentLengthHeader = connection.getHeaderField(HttpHeaders.CONTENT_LENGTH);

            if (!Strings.isNullOrEmpty(contentLengthHeader)) {
                long contentLength;

                try {
                    contentLength = Long.parseLong(contentLengthHeader);

                    if (contentLength > 0) {
                        result = contentLength;
                    } else {
                        LOGGER.warn("bad content length; {}", contentLength);
                    }
                } catch (NumberFormatException nfe) {
                    LOGGER.warn("malformed content length; {}", contentLengthHeader);
                }
            } else {
                LOGGER.warn("unable to get the content length header");
            }

        } finally {
            if (null != connection) {
                connection.disconnect();
            }
        }
        break;

    case "file":
        File file = new File(url.getPath());

        if (file.exists() && file.isFile()) {
            result = file.length();
        } else {
            LOGGER.warn("unable to find the local file; {}", url.getPath());
        }
        break;

    }

    LOGGER.info("did obtain length for url; {} - {}", url, result);

    return result;
}

From source file:com.arto.core.config.MqConfigManager.java

public static int getInt(String name, int value) {
    String val = MqConfigManager.getInstance().getValue(name);
    int result = value;
    if (!Strings.isNullOrEmpty(val)) {
        result = Integer.parseInt(val);
    }// ww w  .  ja  v  a 2 s .c  o m
    log.info("Load property '" + name + "' = " + result);
    return result;
}

From source file:org.eclipse.che.ide.ext.openshift.client.util.OpenshiftValidator.java

/**
 *
 * @param name//  w  ww .  j ava2 s .  c  om
 *         OpenShift application name
 * @return true if application name is valid, false otherwise
 */
public static boolean isApplicationNameValid(String name) {
    return !(Strings.isNullOrEmpty(name) || name.length() > 24 || name.length() < 2
            || !name.matches(PROJECT_NAME));
}

From source file:io.dataplay.storm.util.StormUtil.java

/**
 * Tells us whether this is a shutdown tuple or not.
 *
 * @param tuple The tuple to check./*from  w  w  w.ja  v a  2 s .c o m*/
 * @return True if it's a shutdown tuple, otherwise false.
 */
public static boolean isShutdownTuple(final Tuple tuple) {
    if (tuple.getSourceStreamId().equals(Stream.BOLT_MANAGEMENT.getName())) {
        String command = tuple.getString(Stream.BOLT_MANAGEMENT.getFields().fieldIndex("command"));
        return !Strings.isNullOrEmpty(command) && command.equals(TopologyCommand.SHUTDOWN);
    }
    return false;
}

From source file:org.isisaddons.wicket.wizard.fixture.scripts.todo.DeleteToDoItemsFor.java

@Override
public String validateRun(final String parameters) {
    return Strings.isNullOrEmpty(parameters) ? "Specify the owner of the ToDoItems to be deleted" : null;
}