Example usage for org.apache.commons.lang3 StringUtils isBlank

List of usage examples for org.apache.commons.lang3 StringUtils isBlank

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils isBlank.

Prototype

public static boolean isBlank(final CharSequence cs) 

Source Link

Document

Checks if a CharSequence is whitespace, empty ("") or null.

 StringUtils.isBlank(null)      = true StringUtils.isBlank("")        = true StringUtils.isBlank(" ")       = true StringUtils.isBlank("bob")     = false StringUtils.isBlank("  bob  ") = false 

Usage

From source file:com.thoughtworks.go.validation.PresenceValidator.java

@Override
public ValidationBean validate(String value) {
    if (StringUtils.isBlank(value)) {
        return ValidationBean.notValid(errorMessage);
    } else {/* w  ww.  j  a va 2s  .  com*/
        return ValidationBean.valid();
    }
}

From source file:gov.va.oia.terminology.converters.sharedUtils.umlsUtils.AbbreviationExpansion.java

public static HashMap<String, AbbreviationExpansion> load(InputStream is) throws IOException {
    HashMap<String, AbbreviationExpansion> results = new HashMap<>();

    BufferedReader br = new BufferedReader(new InputStreamReader(is, StandardCharsets.ISO_8859_1));
    String line = br.readLine();//from www  .  j a v  a2 s  .  c  om
    while (line != null) {
        if (StringUtils.isBlank(line) || line.startsWith("#")) {
            line = br.readLine();
            continue;
        }
        String[] cols = line.split("\t");

        AbbreviationExpansion ae = new AbbreviationExpansion(cols[0], cols[1],
                (cols.length > 2 ? cols[2] : null));

        results.put(ae.getAbbreviation(), ae);
        line = br.readLine();
    }
    return results;
}

From source file:com.j2.cs.webservices.metrofax.server.json.JsonIntegerTypeAdapter.java

@Override
public Number read(JsonReader in) throws IOException {
    if (in.peek() == JsonToken.NULL) {
        in.nextNull();/*w w w .ja  va  2  s  . com*/
        return null;
    }

    try {
        String result = in.nextString();
        if (StringUtils.isBlank(result)) {
            return null;
        }
        return Integer.parseInt(result);
    } catch (NumberFormatException e) {
        return null;
    }
}

From source file:cpcc.core.utils.RealVehicleUtils.java

/**
 * @param areaOfOperation the area of operation as a {@code String}.
 * @return the list of {@code LngLatAlt} depot positions.
 * @throws IOException in case of errors.
 *//*from   ww  w .  j  a  v a  2s  .  co m*/
public static List<PolarCoordinate> getDepotPositions(String areaOfOperation) throws IOException {
    if (StringUtils.isBlank(areaOfOperation)) {
        return Collections.emptyList();
    }

    List<PolarCoordinate> list = new ArrayList<>();
    FeatureCollection fc = new ObjectMapper().readValue(areaOfOperation.replace("\\n", "\n"),
            FeatureCollection.class);

    for (Feature feature : fc.getFeatures()) {
        if (!"depot".equals(feature.getProperty("type"))) {
            continue;
        }

        GeoJsonObject geom = feature.getGeometry();
        LngLatAlt coordinates = ((Point) geom).getCoordinates();
        list.add(new PolarCoordinate(coordinates.getLatitude(), coordinates.getLongitude(), 0.0));
    }

    return list;
}

From source file:com.monarchapis.driver.util.MediaTypeUtils.java

/**
 * Returns the best media type for a specific API request.
 * // ww w  .j  a v  a2s . c  o  m
 * @return the media type.
 */
public static String getBestMediaType(ApiRequest request) {
    String mediaType = null;
    String accept = request.getHeader("Accept");

    if (StringUtils.isNotBlank(accept)) {
        mediaType = MIMEParse.bestMatch(supportedMimeTypes, accept);
    }

    if (StringUtils.isBlank(mediaType)) {
        mediaType = MediaType.APPLICATION_JSON;
    }

    return mediaType;
}

From source file:com.dgtlrepublic.model.test.DataTest.java

@SuppressWarnings("unchecked")
private static void verify(Map entry) throws Exception {
    String fileName = (String) entry.getOrDefault("file_name", "");
    boolean ignore = (Boolean) entry.getOrDefault("ignore", false);
    int id = (Integer) entry.getOrDefault("id", -1);
    HashMap<String, Object> testCases = (HashMap<String, Object>) entry.getOrDefault("results",
            new HashMap<String, Object>());
    if (ignore || StringUtils.isBlank(fileName) || testCases.size() == 0) {
        System.out.println(String.format("Ignoring [%s] : { id: %s | results: %s | explicit: %s }", fileName,
                id, testCases.size(), ignore));
        return;//from  w w  w.j  a  v a2s. c o  m
    }

    System.out.println("Parsing: " + fileName);
    HashMap<String, Object> parseResults = (HashMap<String, Object>) DataJsonConverter.toTestCaseMap(fileName)
            .getOrDefault("results", null);

    for (Entry<String, Object> testCase : testCases.entrySet()) {
        Object elValue = parseResults.get(testCase.getKey());
        if (elValue == null) {
            throw new Exception(String.format("%n[%s] Missing Element: %s [%s]", fileName, testCase.getKey(),
                    testCase.getValue()));
        } else if (elValue instanceof String && !elValue.equals(testCase.getValue())) {
            throw new Exception(String.format("%n[%s] Incorrect Value:(%s) [%s] { required: [%s] } ", fileName,
                    testCase.getKey(), elValue, testCase.getValue()));
        } else if (elValue instanceof List
                && !((List) elValue).containsAll((Collection<?>) testCase.getValue())) {
            throw new Exception(String.format("%n[%s] Incorrect List Values:(%s) [%s] { required: [%s] } ",
                    fileName, testCase.getKey(), elValue, testCase.getValue()));
        }
    }
}

From source file:com.alibaba.event.EventListener.java

@Override
public boolean addEvent(String eventName, IEventCallBack eventCallBack) throws EventException {
    if (StringUtils.isBlank(eventName)) {
        return false;
    }//  w  ww .  j  a  v  a  2s.c o m

    // 
    for (EventModel event : eventList) {
        if (event.getEventName().equals(eventName)) {
            log.error(String.format("add event=%s for listener=%s duplicated!!!", eventName, this.getClass()));
            return false;
        }
    }
    EventModel eventModel = new EventModel();
    eventModel.setEventName(eventName);
    eventModel.setEventCallBack(eventCallBack);
    eventList.add(eventModel);
    return true;
}

From source file:com.oodlemud.appengine.counter.data.CounterShardData.java

/**
 * Helper method to set the internal identifier for this entity.
 * //from  w  ww.  jav a2 s  .co m
 * 
 * 
 * @param counterName
 * 
 * @param shardNumber
 *            A unique identifier to distinguish shards for the same
 * 
 *            {@code counterName} from each other.
 */
private static String constructCounterShardIdentifier(final String counterName, final int shardNumber) {
    Preconditions.checkArgument(!StringUtils.isBlank(counterName),
            "CounterData Names may not be null, blank, or empty!");
    Preconditions.checkArgument(shardNumber >= 0, "shardNumber must be greater than or equal to 0!");
    return counterName + COUNTER_SHARD_KEY_SEPARATOR + shardNumber;
}

From source file:com.github.rvesse.airline.model.AliasMetadata.java

public AliasMetadata(String name, List<String> arguments) {
    if (StringUtils.isBlank(name))
        throw new IllegalArgumentException("Alias name cannot be null/empty/whitespace");
    this.name = name;
    this.arguments = AirlineUtils.unmodifiableListCopy(arguments);
}

From source file:chat.viska.xmpp.Jid.java

private static List<String> parseJidParts(final String rawJid) {
    final List<String> result = Arrays.asList("", "", "");
    if (StringUtils.isBlank(rawJid)) {
        return result;
    }// w  w  w  .j  a v a 2s.c o m

    final int indexOfSlash = rawJid.indexOf("/");

    if (indexOfSlash > 0) {
        result.set(2, rawJid.substring(indexOfSlash + 1, rawJid.length()));
    } else if (indexOfSlash < 0) {
        result.set(2, "");
    } else {
        throw new InvalidJidSyntaxException();
    }

    final String bareJid = indexOfSlash > 0 ? rawJid.substring(0, indexOfSlash) : rawJid;
    final int indexOfAt = rawJid.indexOf("@");
    if (indexOfAt > 0) {
        result.set(0, bareJid.substring(0, indexOfAt));
        result.set(1, bareJid.substring(indexOfAt + 1));
    } else if (indexOfAt < 0) {
        result.set(0, "");
        result.set(1, rawJid);
    } else {
        throw new InvalidJidSyntaxException();
    }
    return result;
}