List of usage examples for org.apache.commons.lang3 StringUtils isEmpty
public static boolean isEmpty(final CharSequence cs)
Checks if a CharSequence is empty ("") or null.
StringUtils.isEmpty(null) = true StringUtils.isEmpty("") = true StringUtils.isEmpty(" ") = false StringUtils.isEmpty("bob") = false StringUtils.isEmpty(" bob ") = false
NOTE: This method changed in Lang version 2.0.
From source file:cherry.foundation.validator.TelNoValidator.java
@Override public boolean isValid(String value, ConstraintValidatorContext context) { if (StringUtils.isEmpty(value)) { return true; }/*from w w w. j a va2 s. c om*/ if (value.length() < 11) { return false; } if (value.length() > 13) { return false; } return value.matches("^0\\d{1,4}-\\d{1,4}-\\d{3,4}$"); }
From source file:de.micromata.genome.gwiki.page.impl.actionbean.ActionBeanUtils.java
@SuppressWarnings("rawtypes") public static Map getPrivateMap(ActionBean bean, Map<String, Object> reqMap) { String prefix = bean.getRequestPrefix(); if (StringUtils.isEmpty(prefix) == true) { return reqMap; }//from ww w . ja v a 2 s . c o m Map<String, Object> nm = new HashMap<String, Object>(); for (Map.Entry<String, Object> me : reqMap.entrySet()) { String k = me.getKey(); if (k.startsWith(prefix) == true) { k = k.substring(prefix.length()); nm.put(k, me.getValue()); } } return nm; }
From source file:Action.UserUpdatedProfileAction.java
@Override public void validate() { if (StringUtils.isEmpty(userupdated.getFirst_name())) addFieldError("userupdated.first_name", "First Name can not be blank"); if (StringUtils.isEmpty(userupdated.getPassword())) addFieldError("userupdated.password", "Password can not be blank "); if (StringUtils.isEmpty(userupdated.getGender())) addFieldError("userupdated.gender", "Gender can not be blank"); if (StringUtils.isEmpty(userupdated.getDob())) addFieldError("userupdated.dob", "Date Of Birth can not be blank"); if (StringUtils.isEmpty(userupdated.getEmail_id())) addFieldError("userupdated.email_id", "Email I'd can not be blank"); if (StringUtils.isEmpty(userupdated.getMob_no())) addFieldError("userupdated.mob_no", "Contact can not be blank"); if (StringUtils.isEmpty(userupdated.getCourse())) addFieldError("userupdated.course", "Course can not be blank"); if (StringUtils.isEmpty(userupdated.getEducation())) addFieldError("userupdated.education", "Education can not be blank"); if (StringUtils.isEmpty(userupdated.getYop())) addFieldError("userupdated.yop", "Year of pass can not be blank"); if (StringUtils.isEmpty(userupdated.getCollege())) addFieldError("userupdated.college", "College can not be blank"); }
From source file:com.glaf.core.entity.hibernate.HibernateBeanFactory.java
public static ClassPathXmlApplicationContext reload() { if (ctx != null) { ctx.close();/*from w ww . j a v a 2 s . c om*/ ctx = null; } String configLocation = CustomProperties.getString("hibernate.context"); if (StringUtils.isEmpty(configLocation)) { configLocation = SystemProperties.getString("hibernate.context"); } if (StringUtils.isEmpty(configLocation)) { configLocation = DEFAULT_CONFIG; } ctx = new ClassPathXmlApplicationContext(configLocation); logger.debug("start spring ioc from: " + configLocation); return ctx; }
From source file:com.t3.client.AppUtil.java
/** * Returns a {@link File} path that points to the AppHome base directory along with the subpath denoted in the * "subdir" argument.//ww w . ja va2 s . com * <p> * For example <code>getAppHome("cache")</code> will return the path <code>{APPHOME}/cache</code>. * <p> * As a side-effect the function creates the directory pointed to by File. * * @param subdir * of the tabletoptool home directory * @return the tabletoptool data directory name subdir * @see getAppHome() */ public static File getAppHome(String subdir) { File path = getDataDir(); if (!StringUtils.isEmpty(subdir)) { path = new File(path.getAbsolutePath(), subdir); } // Now check for characters known to cause problems. See getDataDir() for details. if (path.getAbsolutePath().matches("!")) throw new RuntimeException(I18N.getText("msg.error.unusableDir", path.getAbsolutePath())); if (!path.exists()) { path.mkdirs(); // Now check our work if (!path.exists()) { RuntimeException re = new RuntimeException( I18N.getText("msg.error.unableToCreateDataDir", path.getAbsolutePath())); if (log.isInfoEnabled()) log.info("msg.error.unableToCreateDataDir", re); throw re; } } return path; }
From source file:mtsar.api.csv.TaskCSV.java
public static Iterator<Task> parse(Stage stage, CSVParser csv) { final Set<String> header = csv.getHeaderMap().keySet(); checkArgument(!Sets.intersection(header, Sets.newHashSet(HEADER)).isEmpty(), "Unknown CSV header: %s", String.join(",", header)); return StreamSupport.stream(csv.spliterator(), false).map(row -> { final String id = row.isSet("id") ? row.get("id") : null; final String[] tags = row.isSet("tags") && !StringUtils.isEmpty(row.get("tags")) ? row.get("tags").split("\\|") : new String[0]; final String type = row.get("type"); final String description = row.isSet("description") ? row.get("description") : null; final String[] answers = row.isSet("answers") && !StringUtils.isEmpty(row.get("answers")) ? row.get("answers").split("\\|") : new String[0]; final String datetime = row.isSet("datetime") ? row.get("datetime") : null; return new Task.Builder().setId(StringUtils.isEmpty(id) ? null : Integer.valueOf(id)) .setStage(stage.getId()).addAllTags(Arrays.asList(tags)) .setDateTime(new Timestamp(StringUtils.isEmpty(datetime) ? System.currentTimeMillis() : Long.parseLong(datetime) * 1000L)) .setType(StringUtils.defaultIfEmpty(type, TaskDAO.TASK_TYPE_SINGLE)).setDescription(description) .addAllAnswers(Arrays.asList(answers)).build(); }).iterator();/* w ww .j a v a 2s . co m*/ }
From source file:com.dgtlrepublic.anitomyj.StringHelper.java
/** Returns whether or not the {@code string} is mostly a latin string. */ public static boolean isMostlyLatinString(String string) { double length = StringUtils.isNotEmpty(string) ? 1.0 : string.length(); return IntStream.range(0, StringUtils.isEmpty(string) ? 0 : string.length()) .filter(value -> isLatinChar(string.charAt(value))).count() / length >= 0.5; }
From source file:atg.tools.dynunit.util.PropertiesUtil.java
public static void setDynamoPropertyIfEmpty(final String key, final String value) { logger.entry(key, value);//from ww w. ja v a 2s.c om if (StringUtils.isEmpty(getDynamoProperty(key))) { setDynamoProperty(key, value); } logger.exit(); }
From source file:com.examples.with.different.packagename.WordUtils.java
/** * <p>Checks if the String contains all words in the given array.</p> * * <p>/*from w w w . j a va 2s . c om*/ * A {@code null} String will return {@code false}. A {@code null, zero * length search array or if one element of array is null will return {@code false}. * </p> * * <pre> * WordUtils.containsAllWords(null, *) = false * WordUtils.containsAllWords("", *) = false * WordUtils.containsAllWords(*, null) = false * WordUtils.containsAllWords(*, []) = false * WordUtils.containsAllWords("abcd", "ab", "cd") = false * WordUtils.containsAllWords("abc def", "def", "abc") = true * </pre> * * * @param str The str to check, may be null * @param words The array of String words to search for, may be null * @return {@code true} if all search words are found, {@code false} otherwise */ public static boolean containsAllWords(CharSequence word, CharSequence... words) { if (StringUtils.isEmpty(word) || ArrayUtils.isEmpty(words)) { return false; } for (CharSequence w : words) { if (StringUtils.isBlank(w)) { return false; } Pattern p = Pattern.compile(".*\\b" + w + "\\b.*"); if (!p.matcher(word).matches()) { return false; } } return true; }
From source file:com.webbfontaine.valuewebb.model.validators.tt.ContainersValidator.java
public void checkContainers(String requestedOperation) { List<Container> containers = ttGen.getTtTrans().getContainers(); for (int i = 0; i < containers.size(); i++) { if (!StringUtils.isEmpty(containers.get(i).getNumber())) { // if empty let mandatory rules work boolean tmpError = false; for (int j = i + 1; j < containers.size(); j++) { if (containers.get(i).getNumber().equals(containers.get(j).getNumber())) { tmpError = true;// www . j av a 2 s .c o m ErrorHandling.addFacesMessage("containers:" + i + ":number", "Container duplicated", FacesMessage.SEVERITY_ERROR); } } if (!tmpError) { errorHandling.removeErrorByFieldIdAndErrorMessage("containers:" + i + ":number", "Container duplicated"); } } } if (ACCEPT.equals(requestedOperation) || COMPLETE_VC.equals(requestedOperation)) { Integer fclNumber = ttGen.getTtTrans().getFclNum() == null ? 0 : ttGen.getTtTrans().getFclNum(); Integer lclNumber = ttGen.getTtTrans().getLclNum() == null ? 0 : ttGen.getTtTrans().getLclNum(); if (fclNumber + lclNumber == ttGen.getTtTrans().getContainers().size()) { errorHandling.removeErrorByFieldIdAndErrorMessage("number", "Wrong number of containers"); } else { ErrorHandling.addFacesMessage("number", "Wrong number of containers", FacesMessage.SEVERITY_ERROR); } } }