Example usage for java.lang String isEmpty

List of usage examples for java.lang String isEmpty

Introduction

In this page you can find the example usage for java.lang String isEmpty.

Prototype

public boolean isEmpty() 

Source Link

Document

Returns true if, and only if, #length() is 0 .

Usage

From source file:edu.byu.nlp.crowdsourcing.app.Baseline.java

private static boolean exists(String path) {
    return path != null && !path.isEmpty() && Files.exists(Paths.get(path));
}

From source file:api.JsonAPI.java

/**
 * Guardar un pegote//from w ww . j  a v  a  2  s .  c  om
 */
@BodyParser.Of(BodyParser.Json.class)
public static Result save() {
    JsonNode json = request().body().asJson();
    ObjectNode result = Json.newObject();
    if (json == null) {
        result.put("message", "Se esperaba Json");
        return badRequest(result);
    } else {
        String content = json.findPath("content").asText();
        ;
        if (content == null || content.isEmpty()) {
            result.put("message", "Se esperaba Json con algn contenido");
            return badRequest(result);
        } else {
            String key = PastesManager.getAviableKey();
            PastesManager.save(key, content, request().remoteAddress());
            result.put("key", key);
            return created(result);
        }
    }
}

From source file:com.amazonaws.codepipeline.jenkinsplugin.Validation.java

private static boolean regionIsValid(final String region) {
    return region != null && !region.isEmpty();
}

From source file:com.alibaba.jstorm.utils.PathUtils.java

/**
 * split path as list//from   w w w  .ja  v  a  2 s.c  om
 * 
 * @param path
 * @return
 */
public static List<String> tokenize_path(String path) {
    String[] toks = path.split(SEPERATOR);
    ArrayList<String> rtn = new ArrayList<String>();
    for (String str : toks) {
        if (!str.isEmpty()) {
            rtn.add(str);
        }
    }
    return rtn;
}

From source file:io.ssc.trackthetrackers.extraction.resources.URLHandler.java

public static String extractHost(String candidateUrl) throws MalformedURLException {

    if (candidateUrl.isEmpty()) { // permit empty
        return candidateUrl;
    }//from   w  ww.  j  a  v  a 2s  . c om

    String url = candidateUrl;

    //add protocol if not existent
    if (url.startsWith(".")) {
        url = url.substring(1);
    }

    if (!url.contains(":")) {
        if (!url.startsWith("//")) {
            url = "//" + url;
        }
        url = ":" + url;
    }

    if (url.startsWith(":")) {
        url = "http" + url;
    }

    return new URL(url).getHost().toLowerCase();
}

From source file:com.github.autermann.wps.streaming.ProcessConfiguration.java

/**
 * Normalizes a path by returning {@code null} for {@code null}, {@code /}
 * or empty paths and transforming all other paths to {@code /path}.
 * @param path the path/*from  w w  w.  j  a v  a  2  s.com*/
 * @return the normalized path
 */
private static String normalizePath(String path) {
    if (path == null || path.isEmpty() || path.equals("/")) {
        return null;
    }
    String s = path;
    if (s.endsWith("/")) {
        s = s.substring(0, s.length() - 1);
    }
    return s.charAt(0) == '/' ? s : '/' + s;
}

From source file:de.tudarmstadt.ukp.dkpro.argumentation.sequence.feature.meta.AbstractSequenceMetaDataFeatureGenerator.java

@SuppressWarnings("unchecked")
public static List<String> decodeFromString(String featureValue) throws TextClassificationException {
    if (featureValue == null || featureValue.isEmpty()) {
        throw new TextClassificationException(
                "MetaData feature value is empty. Maybe " + "you forgot to add the feature generator "
                        + AbstractSequenceMetaDataFeatureGenerator.class.getName());
    }/*from  w  ww.j  a  v a 2 s  .  c  o m*/

    try {
        byte[] bytes = Base64.decodeBase64(featureValue);
        ObjectInputStream objectInputStream = new ObjectInputStream(new ByteArrayInputStream(bytes));

        return (List<String>) objectInputStream.readObject();

    } catch (IOException | ClassNotFoundException e) {
        throw new TextClassificationException(e);
    }
}

From source file:com.cloudera.director.google.TestFixture.java

public static TestFixture newTestFixture(boolean sshPublicKeyAndUserNameAreRequired) throws IOException {
    String projectId = TestUtils.readRequiredSystemProperty("GCP_PROJECT_ID");
    String jsonKey = TestUtils.readFileIfSpecified(System.getProperty("JSON_KEY_PATH", ""));

    // If the path to a json key file was not provided, check if the key was passed explicitly.
    if (jsonKey == null) {
        String jsonKeyInline = System.getProperty("JSON_KEY_INLINE", "");

        if (!jsonKeyInline.isEmpty()) {
            // If so, we must base64-decode it.
            jsonKey = new String(Base64.decodeBase64(jsonKeyInline));
        }/*from   w  ww.  j av a 2s  . c o  m*/
    }

    String sshPublicKey = null;
    String userName = null;

    if (sshPublicKeyAndUserNameAreRequired) {
        sshPublicKey = TestUtils.readFile(TestUtils.readRequiredSystemProperty("SSH_PUBLIC_KEY_PATH"),
                Charset.defaultCharset());
        userName = TestUtils.readRequiredSystemProperty("SSH_USER_NAME");
    }

    boolean haltAfterAllocation = Boolean.parseBoolean(System.getProperty("HALT_AFTER_ALLOCATION", "false"));

    return new TestFixture(projectId, jsonKey, sshPublicKey, userName, haltAfterAllocation);
}

From source file:io.selendroid.server.inspector.TreeUtil.java

private static String getNodeTitle(JSONObject node) throws JSONException {
    StringBuilder b = new StringBuilder();
    b.append("[" + node.optString("type") + "]");
    String name = node.optString("id");
    if (name != null && name.isEmpty() == false) {
        if (name.length() > 18) {
            name = name.substring(0, 15) + "...";
        }/*from www  .ja va2  s . c o  m*/
        b.append("-" + name);
    }
    return b.toString();
}

From source file:Main.java

public static String serializeOpenTag(String nsUri, String qname, Map<String, String> nsMappings,
        Attributes attrs, boolean optimizeNs) {
    String result = "<" + qname;
    if (nsUri != null && nsUri.length() > 0) {
        int idx = Math.max(qname.indexOf(':'), 0);
        nsMappings.put(qname.substring(0, idx), nsUri);
    }// w w w.  j  a  v a2  s.  co  m
    for (int i = 0; i < attrs.getLength(); i++) {
        result += " " + attrs.getQName(i) + "=\"" + attrs.getValue(i) + "\"";
    }
    for (String key : nsMappings.keySet()) {
        if (optimizeNs) {
            boolean found = key.isEmpty() && qname.indexOf(':') == -1
                    || key.length() > 0 && qname.startsWith(key + ":");
            for (int i = 0; i < attrs.getLength(); i++) {
                String aqn = attrs.getQName(i);
                if (aqn.startsWith("xml")) {
                    continue;
                }
                if (key.isEmpty() && aqn.indexOf(':') == -1 || key.length() > 0 && aqn.startsWith(key + ":")) {
                    found = true;
                    break;
                }
            }
            if (!found) {
                continue;
            }
        }

        if (key.isEmpty()) {
            String value = nsMappings.get(key);
            result += " xmlns=\"" + value + "\"";
        } else {
            result += " xmlns:" + key + "=\"" + nsMappings.get(key) + "\"";
        }
    }
    result += ">";
    return result;
}