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

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

Introduction

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

Prototype

public static boolean isNumeric(final CharSequence cs) 

Source Link

Document

Checks if the CharSequence contains only Unicode digits.

Usage

From source file:com.moviejukebox.plugin.poster.MovieDbPosterPlugin.java

@Override
public IImage getPosterUrl(String id) {
    URL posterURL;// w w w  .j  a  v a2  s . com

    if (StringUtils.isNumeric(id)) {
        try {
            MovieInfo moviedb = tmdb.getMovieInfo(Integer.parseInt(id), languageCode);
            LOG.debug("Movie found on TheMovieDB.org: http://www.themoviedb.org/movie/{}", id);
            posterURL = tmdb.createImageUrl(moviedb.getPosterPath(), DEFAULT_POSTER_SIZE);
            return new Image(posterURL.toString());
        } catch (MovieDbException ex) {
            LOG.warn("Failed to get the poster URL for TMDB ID {} {}", id, ex.getMessage());
        }
    }
    return Image.UNKNOWN;
}

From source file:com.glaf.activiti.extension.model.ExtensionEntity.java

public double getDoubleFieldValue(String name) {
    if (fields != null) {
        ExtensionFieldEntity extensionField = fields.get(name);
        if (extensionField != null && extensionField.getValue() != null) {
            String value = extensionField.getValue();
            if (StringUtils.isNumeric(value)) {
                return Double.parseDouble(value);
            }// w  w w .  j a v  a  2s . com
        }
    }
    return 0;
}

From source file:edu.usu.sdl.openstorefront.core.sort.BeanComparator.java

@Override
public int compare(T o1, T o2) {
    T obj1 = o1;/*  www.  j a v  a  2s.c  o  m*/
    T obj2 = o2;
    if (OpenStorefrontConstant.SORT_ASCENDING.equals(sortDirection)) {
        obj1 = o2;
        obj2 = o1;
    }

    if (obj1 != null && obj2 == null) {
        return 1;
    } else if (obj1 == null && obj2 != null) {
        return -1;
    } else if (obj1 != null && obj2 != null) {
        if (StringUtils.isNotBlank(sortField)) {
            try {
                Object o = obj1;
                Class<?> c = o.getClass();

                Field f = c.getDeclaredField(sortField);
                f.setAccessible(true);
                if (f.get(o) instanceof Date) {
                    int compare = 0;
                    DateFormat format = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy", Locale.ENGLISH);
                    if (BeanUtils.getProperty(obj1, sortField) != null
                            && BeanUtils.getProperty(obj2, sortField) == null) {
                        return 1;
                    } else if (BeanUtils.getProperty(obj1, sortField) == null
                            && BeanUtils.getProperty(obj2, sortField) != null) {
                        return -1;
                    } else if (BeanUtils.getProperty(obj1, sortField) != null
                            && BeanUtils.getProperty(obj2, sortField) != null) {
                        Date value1 = format.parse(BeanUtils.getProperty(obj1, sortField));
                        Date value2 = format.parse(BeanUtils.getProperty(obj2, sortField));
                        if (value1 != null && value2 == null) {
                            return 1;
                        } else if (value1 == null && value2 != null) {
                            return -1;
                        } else if (value1 != null && value2 != null) {

                            compare = value1.compareTo(value2);
                        }
                    }
                    return compare;
                } else {
                    try {
                        String value1 = BeanUtils.getProperty(obj1, sortField);
                        String value2 = BeanUtils.getProperty(obj2, sortField);
                        if (value1 != null && value2 == null) {
                            return 1;
                        } else if (value1 == null && value2 != null) {
                            return -1;
                        } else if (value1 != null && value2 != null) {

                            if (StringUtils.isNotBlank(value1) && StringUtils.isNotBlank(value2)
                                    && StringUtils.isNumeric(value1) && StringUtils.isNumeric(value2)) {

                                BigDecimal numValue1 = new BigDecimal(value1);
                                BigDecimal numValue2 = new BigDecimal(value2);
                                return numValue1.compareTo(numValue2);
                            } else {
                                return value1.toLowerCase().compareTo(value2.toLowerCase());
                            }
                        }
                    } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException ex) {
                        log.log(Level.FINER, MessageFormat.format("Sort field doesn''t exist: {0}", sortField));
                    }
                }
            } catch (ParseException | NoSuchFieldException | SecurityException | IllegalArgumentException
                    | IllegalAccessException | InvocationTargetException | NoSuchMethodException ex) {
                try {
                    String value1 = BeanUtils.getProperty(obj1, sortField);
                    String value2 = BeanUtils.getProperty(obj2, sortField);
                    if (value1 != null && value2 == null) {
                        return 1;
                    } else if (value1 == null && value2 != null) {
                        return -1;
                    } else if (value1 != null && value2 != null) {

                        if (StringUtils.isNotBlank(value1) && StringUtils.isNotBlank(value2)
                                && StringUtils.isNumeric(value1) && StringUtils.isNumeric(value2)) {

                            BigDecimal numValue1 = new BigDecimal(value1);
                            BigDecimal numValue2 = new BigDecimal(value2);
                            return numValue1.compareTo(numValue2);
                        } else {
                            return value1.toLowerCase().compareTo(value2.toLowerCase());
                        }
                    }
                } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException ex2) {
                    log.log(Level.FINER, MessageFormat.format("Sort field doesn''t exist: {0}", sortField));
                }
            }
        }
    }
    return 0;
}

From source file:net.mindengine.galen.config.GalenConfig.java

public int getLogLevel() {
    String value = readProperty("galen.log.level", "10");
    if (StringUtils.isNumeric(value)) {
        return Integer.parseInt(value);
    } else/*from w ww  . ja  v a  2s  . co m*/
        return 10;
}

From source file:com.glaf.jbpm.model.Extension.java

public int getIntFieldValue(String name) {
    if (fields != null) {
        ExtensionField extensionField = fields.get(name);
        if (extensionField != null && extensionField.getValue() != null) {
            String value = extensionField.getValue();
            if (StringUtils.isNumeric(value)) {
                return Integer.parseInt(value);
            }/* ww  w.ja v a  2 s.  c o m*/
        }
    }
    return 0;
}

From source file:com.thinkbiganalytics.policy.standardization.DateTimeStandardizer.java

/**
 * Unix timestamp is in seconds.. not ms.  detect if the string has only 10 chars being its in seconds, not ms
 *///from   w w  w . jav a  2s  . c o m
private boolean isInputUnixTimestamp(String value) {
    return StringUtils.isNotBlank(value) && StringUtils.isNumeric(value) && value.length() == 10;
}

From source file:com.trenako.values.DeliveryDate.java

/**
 * Parses the string argument as a {@code DeliveryDate}.
 * <p>/* ww  w .j a v a2s  . c  o m*/
 * A valid instance of {@code DeliveryDate} can have two formats:
 * <ul>
 * <li>{@code YYYY}, where {@code YYYY} is a valid year (ie {@code year>=1900 && year<2999});</li>
 * <li>{@code YYYY + '/Q' + N}, where {@code YYYY} is a valid year (ie {@code year>=1900 && year<2999})
 * and {@code N} is the quarter number (ie {@code quarter>=1 && quarter<4}).
 * </li>
 * </ul>
 * </p>
 *
 * @param s the string to be parsed
 * @return a {@code DeliveryDate} represented by the string argument
 * @throws IllegalArgumentException    if {@code s} is empty or {@code null}
 * @throws DeliveryDateFormatException if {@code s} doesn't represent a valid {@code DeliveryDate}
 */
public static DeliveryDate parseString(String s) {
    if (StringUtils.isBlank(s)) {
        throw new IllegalArgumentException("Empty string is not valid");
    }

    int year = 0;
    int quarter = 0;

    String[] tokens = s.split("/");

    String sYear = tokens[0];
    if (!StringUtils.isNumeric(sYear)) {
        throw new DeliveryDateFormatException("'" + sYear + "' is not a valid year");
    }

    year = Integer.parseInt(sYear);
    if (year < 1900 || year > 2999) {
        throw new DeliveryDateFormatException("'" + sYear + "' is not a valid year");
    }

    if (tokens.length == 2) {
        String sQuarter = tokens[1];
        if (sQuarter.length() != 2 && !sQuarter.startsWith(QUARTER_PREFIX)) {
            throw new DeliveryDateFormatException("'" + sQuarter + "' is not a valid quarter");
        }

        quarter = Integer.parseInt(sQuarter.substring(1));
        if (!QUARTERS.contains(quarter)) {
            throw new DeliveryDateFormatException("'" + sQuarter + "' is not a valid quarter");
        }
    }

    if (quarter == 0)
        return new DeliveryDate(year);
    else
        return new DeliveryDate(year, quarter);
}

From source file:com.glaf.core.domain.SystemProperty.java

public long getLongValue() {
    if (StringUtils.isNotEmpty(value) && StringUtils.isNumeric(value)) {
        return Long.parseLong(value);
    }/*w ww .  java2  s.com*/
    if (StringUtils.isNotEmpty(initValue) && StringUtils.isNumeric(initValue)) {
        return Long.parseLong(initValue);
    }
    return -1;
}

From source file:com.omertron.yamjtrakttv.tools.TraktTools.java

public static TvEntity getEpisodeSummary(Video video, Episode episode) {
    TvEntity tvEntity;// w  ww  .j  a  v a  2 s  .c o m

    episode.setSearchOnTrakt(Boolean.TRUE);
    try {
        if (StringUtils.isNumeric(video.getId(Video.ID_TVDB))) {
            tvEntity = MANAGER.showService()
                    .episodeSummary(video.getId(Video.ID_TVDB), episode.getSeason(), episode.getEpisode())
                    .fire();
        } else {
            tvEntity = MANAGER.showService()
                    .episodeSummary(video.getTitle(), episode.getSeason(), episode.getEpisode()).fire();
            video.addId(Video.ID_TVDB, tvEntity.show.tvdbId);
            video.addId(Video.ID_IMDB, tvEntity.show.imdbId);
        }
    } catch (TraktException ex) {
        LOG.debug("Error getting information for TV show: " + video.getTitle() + " Episode: "
                + episode.getEpisode() + " - Error: " + ex.getMessage());
        episode.setFoundOnTrakt(Boolean.FALSE);
        tvEntity = null;
    }

    if (tvEntity != null) {
        episode.getSummaryInfo().addSummaryInfo(tvEntity);
        episode.setFoundOnTrakt(Boolean.TRUE);
    }

    return tvEntity;
}

From source file:com.vigglet.util.ModelUtilBase.java

public Collection<T> findByCompany(int company, int pageSize, int page, String searchText, int limit) {
    int skip = (pageSize * (page - 1));

    if (page > 0 || (searchText != null && !searchText.isEmpty()
            && searchText.length() >= getMinLenghtOfSearchText())) {
        Collection<T> result = getOrderdList(company);
        if (searchText != null && !searchText.isEmpty() && searchText.length() >= getMinLenghtOfSearchText()) {
            String[] searchTextSplit = searchText.split(" ");
            if (searchTextSplit.length > 1 || !StringUtils.isNumeric(searchText)) {
                result = result.stream().filter((T t) -> t.matchesSearchableFields(searchTextSplit))
                        .collect(Collectors.toList());
            }/*from ww  w.j  a v a  2 s. c o  m*/
        }

        int i = 0;
        if (page > 0) {
            Collection<T> result2 = new ArrayList<>(pageSize);
            for (T t : result) {
                if (++i < skip) {
                    continue;
                }

                if (i == (skip + pageSize)) {
                    break;
                }

                if (i >= skip && i <= (skip + pageSize)) {
                    result2.add(t);
                }
            }
            return result2;
        }

        return result;
    }

    if (limit > 0) {
        return getLimitedList(company, limit);
    }

    return findByCompany(company);
}