List of usage examples for org.apache.commons.lang3 StringUtils trimToEmpty
public static String trimToEmpty(final String str)
Removes control characters (char <= 32) from both ends of this String returning an empty String ("") if the String is empty ("") after the trim or if it is null .
From source file:de.jfachwert.math.PackedDecimal.java
/** * Liefert den uebergebenen String als {@link PackedDecimal} zurueck. * Diese Methode ist dem Konstruktor vorzuziehen, da fuer gaengige Zahlen * wie "0" oder "1" immer das gleiche Objekt zurueckgegeben wird. * <p>/*w ww. ja v a2 s .c o m*/ * Im Gegensatz zum String-Konstruktor darf man hier auch 'null' als Wert * uebergeben. In diesem Fall wird dies in {@link #EMPTY} uebersetzt. * </p> * <p> * Die erzeugten PackedDecimals werden intern in einem "weak" Cache * abgelegt, damit bei gleichen Zahlen auch die gleichen PackedDecimals * zurueckgegeben werden. Dies dient vor allem zur Reduktion des * Speicherverbrauchs. * </p> * * @param zahl String aus Zahlen * @return Zahl als {@link PackedDecimal} */ public static PackedDecimal valueOf(String zahl) { String trimmed = StringUtils.trimToEmpty(zahl); if (StringUtils.isEmpty(trimmed)) { return EMPTY; } if ((trimmed.length() == 1 && Character.isDigit(trimmed.charAt(0)))) { return CACHE[Character.getNumericValue(trimmed.charAt(0))]; } else { return WEAK_CACHE.computeIfAbsent(zahl, PackedDecimal::new); } }
From source file:gov.ca.cwds.data.persistence.cms.BaseSubstituteCareProvider.java
/** * @return the streetNumber */ public String getStreetNumber() { return StringUtils.trimToEmpty(streetNumber); }
From source file:com.jiangyifen.ec2.globaldata.license.LicenseManagerMain.java
/** * license//www .j a v a 2 s . co m * * @param localmd5 * @param mac * @param date * @param count * @return */ private static Boolean licenseValidate(String localmd5, String mac, String date, String count) { // ?md5 ?? localmd5 = StringUtils.trimToEmpty(localmd5); // ? mac = StringUtils.trimToEmpty(mac); date = StringUtils.trimToEmpty(date); count = StringUtils.trimToEmpty(count); // mac?date?count?? Boolean isWellformat = regexMatchCheck(mac, date, count); if (isWellformat) { // continue } else { return false; } // 32?md5 String saltedLicense = mac + LicenseManagerMain.LICENSE_SALT + date + count; String bit32_md5_result = bit32_md5(saltedLicense); // ? if (localmd5.equals(bit32_md5_result)) { // ? // LicenseManager.LICENSE_DATE try { Date expiredate = simpleDateFormat.parse(date); if (new Date().after(expiredate)) { logger.warn("chb: License expires, license expiredate is " + date); return false; } } catch (ParseException e) { e.printStackTrace(); logger.warn("chb: License date parse exception"); return false; } return true; } else { logger.warn("chb: License and bit32_md5_result not match , changed !!!"); return false; } }
From source file:com.feilong.core.date.DateUtilTest.java
@Test public void testToDate2() { DateUtil.toDate(StringUtils.trimToEmpty("2016-06-30 15:36 "), COMMON_DATE_AND_TIME_WITHOUT_SECOND); }
From source file:it.jaschke.alexandria.model.view.BookDetailViewModel.java
/** * Retrieves the data from the cursor passed as argument and sets it onto the * {@link BookDetailViewModel}'s current {@link Book}. The projection used * must be {@link BookDetailQuery#PROJECTION}. This method also notifies the * data binding of the change, so the visual elements can be updated. * * @param cursor the {@link Cursor} containing the data to load. * @throws IllegalStateException if there is no {@link Book} currently set * in the {@link BookDetailViewModel}. * @throws IllegalArgumentException if the data passed does not belong to * the {@link Book} currently set (i.e. does not have the same id). *///from ww w . jav a 2 s . c o m public void setBookData(Cursor cursor) { if (mBook == null) { throw new IllegalStateException("No book currently set in BookDetailViewModel."); } if (cursor == null) { return; } if (!cursor.moveToFirst()) { Log.w(LOG_TAG, "The cursor contains no data. Ignoring book details."); return; } if (mBook.getId() != cursor.getLong(BookDetailQuery.COL_ID)) { throw new IllegalArgumentException("The data passed does not belong to the book"); } mBook.setTitle(cursor.getString(BookDetailQuery.COL_TITLE)); mBook.setSubtitle(cursor.getString(BookDetailQuery.COL_SUBTITLE)); mBook.setDescription(cursor.getString(BookDetailQuery.COL_DESCRIPTION)); String coverUrl = cursor.getString(BookDetailQuery.COL_COVER_IMAGE_URL); mBook.setCoverUri(Uri.parse(StringUtils.trimToEmpty(coverUrl))); notifyPropertyChanged(BR._all); }
From source file:kenh.xscript.impl.BaseElement.java
/** * Get the parsed text.//www. j av a 2 s .c om * @return */ protected Object getParsedText() throws UnsupportedScriptException { if (this.getText() == null) return ""; String text = this.getText(); Text t = this.getClass().getAnnotation(Text.class); if (t != null) { Text.Type type = t.value(); if (type == Text.Type.FULL) { try { return this.getEnvironment().parse(text); } catch (UnsupportedExpressionException e) { throw new UnsupportedScriptException(this, e); } } else if (type == Text.Type.TRIM) { try { text = StringUtils.trimToEmpty(text); Object obj = this.getEnvironment().parse(text); if (obj instanceof String) { return StringUtils.trimToEmpty((String) obj); } else { return obj; } } catch (UnsupportedExpressionException e) { throw new UnsupportedScriptException(this, e); } } return ""; } else { return ""; } }
From source file:de.micromata.genome.util.types.Converter.java
/** * Normalize number string.//from w w w .j a v a 2 s .c o m * * @param source the source * @param scale the scale * @param decimalChar the decimal char * @param unit the unit * @return the string */ public static String normalizeNumberString(String source, int scale, char decimalChar, String unit) { source = StringUtils.trimToEmpty(source); if (StringUtils.isEmpty(source) == true) { return ""; } return buildNormalizedNumberString(new BigDecimal(source.replace(',', '.')), 0, scale, decimalChar, unit); }
From source file:com.github.binlee1990.spider.movie.spider.MovieCrawler.java
private void setFilmReviewDoubanGrade(Document doc, FilmReview filmReview) { Elements doubanElements = doc.select(".fm-title .fm-green"); if (CollectionUtils.isNotEmpty(doubanElements) && doubanElements.size() == 1) { Element doubanElement = doubanElements.get(0); if (null != doubanElement) { String doubanGradeStr = doubanElement.text(); if (StringUtils.isNotBlank(doubanGradeStr) && StringUtils.contains(doubanGradeStr, "")) { String gradeStr = StringUtils.trimToEmpty( doubanGradeStr.substring(doubanGradeStr.indexOf("") + "".length())); if (StringUtils.isNotBlank(gradeStr)) { float grade = getGrade(gradeStr); filmReview.setGradeDouban(grade); }/*from w w w. ja v a2s .c om*/ } } } }
From source file:com.erudika.para.utils.Utils.java
/** * Converts spaces to dashes.// w w w . j a v a2 s . c om * @param str a string with spaces * @param replaceWith a string to replace spaces with * @return a string with dashes */ public static String noSpaces(String str, String replaceWith) { return StringUtils.isBlank(str) ? "" : str.trim().replaceAll("[\\p{C}\\p{Z}]+", StringUtils.trimToEmpty(replaceWith)).toLowerCase(); }
From source file:com.open.cas.shiro.util.CollectionsUtils.java
public static List<String> clean2List(String[] arr) { if (!isEmpty(arr)) { List<String> list = new ArrayList<String>(); for (String string : arr) { String trim = StringUtils.trimToEmpty(string); if (StringUtils.isNotEmpty(trim)) { list.add(trim);// www . j a va2 s . c o m } } return list; } return Collections.emptyList(); }