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.parallax.server.blocklyprop.jsp.GetUrl.java

@Override
public void doTag() throws JspException, IOException {
    if (!Strings.isNullOrEmpty(url)) {
        // System.out.println("Geturl: " + url);

        PageContext pageContext = (PageContext) getJspContext();
        JspWriter out = pageContext.getOut();

        out.write(pageContext.getServletContext().getContextPath() + url);
    } else {//w w  w .j  a  v  a2 s.  c om
        System.out.println("Url = null or empty");
    }
}

From source file:com.hpcloud.mon.app.validation.MetricNameValidation.java

/**
 * Validates the {@code metricName} for the character constraints.
 * /*from   w w w . jav  a2s .  c om*/
 * @throws WebApplication if validation fails
 */
public static void validate(String metricName, @Nullable String service) {
    // General validations
    if (Strings.isNullOrEmpty(metricName))
        throw Exceptions.unprocessableEntity("Metric name is required");
    if (metricName.length() > 64)
        throw Exceptions.unprocessableEntity("Metric name %s must be 64 characters or less", metricName);
    if (!Services.isReserved(metricName) && !VALID_METRIC_NAME.matcher(metricName).matches())
        throw Exceptions.unprocessableEntity("Metric name %s may only contain: a-z A-Z 0-9 _ - .", metricName);

    // Service specific validations
    if (service != null && Services.isReserved(service)) {
        if (!Strings.isNullOrEmpty(metricName) && !Services.isValidMetricName(service, metricName)) {
            throw Exceptions.unprocessableEntity("%s is not a valid metric name for namespace %s", metricName,
                    service);
        }
    }
}

From source file:net.ltgt.guice.neo4j.Neo4jIndexProviders.java

public static Provider<Index<Node>> indexForNodes(final String name, Map<String, String> config) {
    Preconditions.checkArgument(!Strings.isNullOrEmpty(name));
    Preconditions.checkNotNull(config);// w  w w . java2  s.  co m

    final Map<String, String> configToUse = ImmutableMap.copyOf(config);

    return new Provider<Index<Node>>() {

        @Inject
        IndexManager indexManager;

        @Override
        public Index<Node> get() {
            return indexManager.forNodes(name, configToUse);
        }
    };
}

From source file:com.github.nbyl.xfdcontrol.service.Application.java

private static void installConfigLocation() throws FileNotFoundException {
    if (Strings.isNullOrEmpty(System.getProperty(SPRING_CONFIG_LOCATION))) {
        File configFile = new File(StandardSystemProperty.USER_HOME.value(), ".xfdcontrol.properties");
        LOGGER.debug("Loading configuration from file {}.", configFile.getAbsolutePath());

        if (!configFile.exists()) {
            throw new FileNotFoundException("Config file " + configFile.getPath() + " does not exist.");
        }/*from   w w  w . j  a va  2 s.co m*/

        System.setProperty(SPRING_CONFIG_LOCATION, configFile.getAbsolutePath());
    } else {
        LOGGER.debug("Configuration location already set.");
    }
}

From source file:com.parallax.server.blocklyprop.jsp.SetLocale.java

@Override
public void doTag() throws JspException, IOException {
    if (!Strings.isNullOrEmpty(locale)) {
        //            System.out.println("Set locale: " + locale);
        UserServiceImpl.getUserService().setLocale(locale);
    } else {/*  ww w. j  a  v a  2s  . c  o  m*/
        System.out.println("Locale = null or empty");
    }
}

From source file:org.apache.beam.sdk.metrics.MetricName.java

public static MetricName named(String namespace, String name) {
    checkArgument(!Strings.isNullOrEmpty(namespace), "Metric namespace must be non-empty");
    checkArgument(!Strings.isNullOrEmpty(name), "Metric name must be non-empty");
    return new AutoValue_MetricName(namespace, name);
}

From source file:org.opendaylight.netconf.sal.connect.util.MessageCounter.java

public String getNewMessageId(final String prefix) {
    Preconditions.checkArgument(Strings.isNullOrEmpty(prefix) == false, "Null or empty prefix");
    return String.format(messageIdBlueprint, prefix, getNewMessageId());
}

From source file:com.github.jcustenborder.kafka.connect.cdc.Assertions.java

public static void assertSchema(final Schema expected, final Schema actual, String message) {
    String prefix = Strings.isNullOrEmpty(message) ? "" : message + ": ";
    assertNotNull(expected, prefix + "expected schema should not be null.");
    assertNotNull(actual, prefix + "actual schema should not be null.");
    assertEquals(expected.name(), actual.name(), prefix + "schema.name() should match.");
    assertEquals(expected.type(), actual.type(), prefix + "schema.type() should match.");
    assertEquals(expected.defaultValue(), actual.defaultValue(),
            prefix + "schema.defaultValue() should match.");
    assertEquals(expected.isOptional(), actual.isOptional(), prefix + "schema.isOptional() should match.");
    assertEquals(expected.doc(), actual.doc(), prefix + "schema.doc() should match.");
    assertEquals(expected.version(), actual.version(), prefix + "schema.version() should match.");
    //    assertMap(expected.parameters(), actual.parameters(), prefix + "schema.parameters() should match.");
    assertEquals(expected.parameters(), actual.parameters(), prefix + "schema.parameters() should match.");
    switch (expected.type()) {
    case ARRAY:/*from www.ja  v a 2  s  .  co  m*/
        assertSchema(expected.valueSchema(), actual.valueSchema(), message + "valueSchema does not match.");
        break;
    case MAP:
        assertSchema(expected.keySchema(), actual.keySchema(), message + "keySchema does not match.");
        assertSchema(expected.valueSchema(), actual.valueSchema(), message + "valueSchema does not match.");
        break;
    case STRUCT:
        assertEquals(expected.fields().size(), actual.fields().size(),
                message + "fields().size() does not match.");
        for (Field expectedField : expected.fields()) {
            Field actualField = actual.field(expectedField.name());
            assertField(expectedField, actualField, "field(" + expectedField.name() + ") does not match.");
        }
    }
}

From source file:org.apache.james.mailbox.model.BlobId.java

public static BlobId fromString(String raw) {
    Preconditions.checkArgument(!Strings.isNullOrEmpty(raw));
    return new BlobId(raw);
}

From source file:com.google.gitiles.FormatType.java

public static FormatType getFormatType(HttpServletRequest req) {
    FormatType result = (FormatType) req.getAttribute(FORMAT_TYPE_ATTRIBUTE);
    if (result != null) {
        return result;
    }//w w  w  .  j a v a2s  .c om

    String format = req.getParameter("format");
    if (format != null) {
        for (FormatType type : FormatType.values()) {
            if (format.equalsIgnoreCase(type.name())) {
                return set(req, type);
            }
        }
        throw new IllegalArgumentException("Invalid format " + format);
    }

    String accept = req.getHeader(HttpHeaders.ACCEPT);
    if (Strings.isNullOrEmpty(accept)) {
        return set(req, DEFAULT);
    }

    for (String p : accept.split("[ ,;][ ,;]*")) {
        for (FormatType type : FormatType.values()) {
            if (p.equals(type.mimeType)) {
                return set(req, type != HTML ? type : DEFAULT);
            }
        }
    }
    return set(req, DEFAULT);
}