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.floreantpos.bo.ui.explorer.ModifierExplorer.java

private String doDuplicateName(MenuModifier existingModifier) {
    String existingName = existingModifier.getName();
    String newName = new String();
    int lastIndexOf = existingName.lastIndexOf(" ");
    if (lastIndexOf == -1) {
        newName = existingName + " 1";
    } else {//from ww w . j  a va2s  .c om
        String processName = existingName.substring(lastIndexOf + 1, existingName.length());
        if (StringUtils.isNumeric(processName)) {
            Integer count = Integer.valueOf(processName);
            count += 1;
            newName = existingName.replace(processName, String.valueOf(count));
        } else {
            newName = existingName + " 1";
        }
    }
    return newName;
}

From source file:hk.newsRecommender.Classify.java

public static void test(Configuration conf, String testFile, int labelIndex) throws IOException {
    System.out.println("~~~ begin to test ~~~");
    AbstractNaiveBayesClassifier classifier = new StandardNaiveBayesClassifier(naiveBayesModel);

    FileSystem fsopen = FileSystem.get(conf);
    FSDataInputStream in = fsopen.open(new Path(testFile));
    CSVReader csv = new CSVReader(new InputStreamReader(in));
    csv.readNext(); // skip header

    String[] line = null;/*  www .  j  av a2  s .co m*/
    double totalSampleCount = 0.;
    double correctClsCount = 0.;
    //       String str="10,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,12,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,14,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10,0,0,0,0,0,9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16,0,0,0,0,0,14,0,8";
    //       List<String> newsList=new ArrayList<String>();
    //       newsList.add(str);
    //       for(int j=0;j<newsList.size();j++){
    //          line=newsList.get(j).split(",");
    while ((line = csv.readNext()) != null) {
        //          ??ID???ID?
        //          ????
        List<String> tmpList = Lists.newArrayList(line);
        String label = tmpList.get(labelIndex);
        tmpList.remove(labelIndex);
        totalSampleCount++;
        Vector vector = new RandomAccessSparseVector(tmpList.size(), tmpList.size());
        for (int i = 0; i < tmpList.size(); i++) {
            String tempStr = tmpList.get(i);
            if (StringUtils.isNumeric(tempStr)) {
                vector.set(i, Double.parseDouble(tempStr));
            } else {
                Long id = strOptionMap.get(tempStr);
                if (id != null)
                    vector.set(i, id);
                else {
                    System.out.println(StringUtils.join(tempStr, ","));
                    continue;
                }
            }
        }
        Vector resultVector = classifier.classifyFull(vector);
        int classifyResult = resultVector.maxValueIndex();
        if (StringUtils.equals(label, strLabelList.get(classifyResult))) {
            correctClsCount++;
        } else {
            //             line[labelIndex]????ID??
            //             ???????
            //             
            System.out.println("CorrectORItem=" + label + "\tClassify=" + strLabelList.get(classifyResult));
        }
    }
    //       System.out.println("Correct Ratio:" + (correctClsCount / totalSampleCount));
}

From source file:com.glaf.report.web.rest.MxReportResource.java

@GET
@POST//  w ww . j a  va2s .  co  m
@Path("/treeJson")
@ResponseBody
@Produces({ MediaType.APPLICATION_OCTET_STREAM })
public byte[] treeJson(@Context HttpServletRequest request) throws IOException {
    JSONArray array = new JSONArray();
    Long nodeId = RequestUtils.getLong(request, "nodeId");
    String nodeCode = request.getParameter("nodeCode");
    String selected = request.getParameter("selected");

    logger.debug(RequestUtils.getParameterMap(request));
    List<TreeModel> treeModels = new java.util.ArrayList<TreeModel>();
    List<String> chooseList = new java.util.ArrayList<String>();
    if (StringUtils.isNotEmpty(selected)) {
        chooseList = StringTools.split(selected);
    }

    TreeModel treeNode = null;

    if (nodeId != null && nodeId > 0) {
        treeNode = treeModelService.getTreeModel(nodeId);
    } else if (StringUtils.isNotEmpty(nodeCode)) {
        treeNode = treeModelService.getTreeModelByCode(nodeCode);
    }

    if (treeNode != null) {
        ReportQuery query = new ReportQuery();
        List<TreeModel> subTrees = treeModelService.getSubTreeModels(treeNode.getId());
        if (subTrees != null && !subTrees.isEmpty()) {
            for (TreeModel tree : subTrees) {
                tree.getDataMap().put("nocheck", "true");
                tree.getDataMap().put("iconSkin", "tree_folder");
                tree.getDataMap().put("isParent", "true");
                tree.setIconCls("folder");
                tree.setLevel(0);
                treeModels.add(tree);
                query.nodeId(tree.getId());
                List<Report> reports = reportService.list(query);
                for (Report report : reports) {
                    if (StringUtils.isNumeric(report.getId())) {
                        TreeModel t = new BaseTree();
                        t.setId(Long.parseLong(report.getId()));
                        t.setParentId(tree.getId());
                        t.setName(report.getSubject());
                        t.setCode(report.getId());
                        t.setTreeId(report.getId());
                        t.setIconCls("leaf");
                        t.getDataMap().put("iconSkin", "tree_leaf");
                        if (chooseList.contains(report.getId())) {
                            t.setChecked(true);
                        }
                        treeModels.add(t);
                    }
                }
            }
        }
        TreeHelper treeHelper = new TreeHelper();
        array = treeHelper.getTreeJSONArray(treeModels);
    }

    return array.toJSONString().getBytes("UTF-8");
}

From source file:com.aol.one.patch.DefaultPatcher.java

private void invokeRemoveMethod(Object object, String fieldName)
        throws IllegalAccessException, InvocationTargetException, PatchException {

    if (object instanceof Patchable) {
        Patchable patchable = (Patchable) object;
        patchable.removeValue(fieldName);
        return;//from www. j a v  a2s  .  c  om
    }

    boolean isFieldNameNumeric = StringUtils.isNumeric(fieldName);

    if (isFieldNameNumeric && object instanceof java.util.List) {
        List tmpList = (List) object;
        tmpList.remove(Integer.parseInt(fieldName));
        return;
    }

    if (isFieldNameNumeric && object instanceof java.util.Map) {
        Map tmpMap = (Map) object;
        tmpMap.remove(fieldName);
        return;
    }

    // first try to find remove+CapitalizedField
    List<String> methodNames = new ArrayList<>();
    methodNames.add("remove" + StringUtils.capitalize(fieldName));

    List<MethodData> methodDataList = generateMethodData(methodNames);

    // final try, standard method
    List<Class<?>> argTypes = new ArrayList<>();
    argTypes.add(String.class);

    List<Object> params = new ArrayList<>();
    params.add(fieldName);

    MethodData standardMethodData = new MethodData(STANDARD_REMOVE_METHOD, argTypes, params);
    methodDataList.add(standardMethodData);

    invokeMethodFromMethodDataList(object, methodDataList);
}

From source file:com.opendesign.utils.CmnUtil.java

/**
 * ? format "#,###"/*  w ww  . java  2  s.  c o m*/
 * 
 * @param number
 * @return
 */
public static String getDisplayNumber(String number) {
    if (StringUtils.isEmpty(number) || !StringUtils.isNumeric(number)) {
        return "0";
    }
    Double dNum = Double.valueOf(number);
    DecimalFormat fm = new DecimalFormat("#,###");
    return fm.format(dNum);
}

From source file:com.moviejukebox.scanner.artwork.FanartScanner.java

/**
 * Get the Fanart for the movie from TheMovieDB.org
 *
 * @author Stuart.Boston/*from  w  w w . j  av a 2  s. co m*/
 * @param movie The movie to get the fanart for
 * @return A string URL pointing to the fanart
 */
private static String getMovieFanartURL(Movie movie) {
    // Unable to scan for fanart because TheMovieDB wasn't initialised
    if (TMDB == null) {
        return Movie.UNKNOWN;
    }

    String language = PropertiesUtil.getProperty("themoviedb.language", "en-US");
    MovieInfo moviedb = null;

    String imdbID = movie.getId(ImdbPlugin.IMDB_PLUGIN_ID);
    String tmdbIDstring = movie.getId(TheMovieDbPlugin.TMDB_PLUGIN_ID);
    int tmdbID;

    if (StringUtils.isNumeric(tmdbIDstring)) {
        tmdbID = Integer.parseInt(tmdbIDstring);
    } else {
        tmdbID = 0;
    }

    if (tmdbID > 0) {
        try {
            moviedb = TMDB.getMovieInfo(tmdbID, language);
        } catch (MovieDbException ex) {
            LOG.debug("Failed to get fanart using TMDB ID: {} - {}", tmdbID, ex.getMessage());
        }
    }

    if (moviedb == null && StringTools.isValidString(imdbID)) {
        try {
            // The ImdbLookup contains images
            moviedb = TMDB.getMovieInfoImdb(imdbID, language);
        } catch (MovieDbException ex) {
            LOG.debug("Failed to get fanart using IMDB ID: {} - {}", imdbID, ex.getMessage());
        }
    }

    if (moviedb == null) {
        try {
            ResultList<MovieInfo> result = TMDB.searchMovie(movie.getOriginalTitle(), 0, language,
                    TheMovieDbPlugin.INCLUDE_ADULT, 0, 0, SearchType.PHRASE);
            List<MovieInfo> movieList = result.getResults();

            for (MovieInfo m : movieList) {
                if (m.getTitle().equals(movie.getTitle())
                        || m.getTitle().equalsIgnoreCase(movie.getOriginalTitle())
                        || m.getOriginalTitle().equalsIgnoreCase(movie.getTitle())
                        || m.getOriginalTitle().equalsIgnoreCase(movie.getOriginalTitle())) {
                    if (StringTools.isNotValidString(movie.getYear())) {
                        // We don't have a year for the movie, so assume this is the correct movie
                        moviedb = m;
                        break;
                    } else if (m.getReleaseDate().contains(movie.getYear())) {
                        // found the movie name and year
                        moviedb = m;
                        break;
                    }
                }
            }
        } catch (MovieDbException ex) {
            LOG.debug("Failed to get fanart using IMDB ID: {} - {}", imdbID, ex.getMessage());
        }
    }

    // Check that the returned movie isn't null
    if (moviedb == null) {
        LOG.debug("Error getting fanart from TheMovieDB.org for {}", movie.getBaseFilename());
        return Movie.UNKNOWN;
    }

    try {
        URL fanart = TMDB.createImageUrl(moviedb.getBackdropPath(), "original");
        if (fanart == null) {
            return Movie.UNKNOWN;
        }
        return fanart.toString();
    } catch (MovieDbException ex) {
        LOG.debug("Error getting fanart from TheMovieDB.org for {}", movie.getBaseFilename());
        return Movie.UNKNOWN;
    }
}

From source file:com.streamsets.pipeline.lib.jdbc.multithread.util.OffsetQueryUtil.java

public static Map<String, String> getOffsetsFromColumns(TableRuntimeContext tableContext,
        Map<String, Field> fields) {
    final Map<String, String> offsets = new HashMap<>();
    for (String offsetColumn : tableContext.getSourceTableContext().getOffsetColumns()) {
        Field field = fields.get(offsetColumn);
        String value;//from  w w  w .  j  a  v a2 s.  c o m
        if (field.getType().isOneOf(Field.Type.DATE, Field.Type.TIME)) {
            //For DATE/TIME fields store the long in string format and convert back to date when using offset
            //in query
            value = String.valueOf(field.getValueAsDatetime().getTime());
        } else if (field.getType() == Field.Type.DATETIME) {
            //DATETIME is similar to above, but there may also be a nanosecond portion (stored in field attr)
            String nanosAttr = field.getAttribute(JdbcUtil.FIELD_ATTRIBUTE_NANOSECONDS);
            int nanos;
            if (StringUtils.isNotBlank(nanosAttr) && StringUtils.isNumeric(nanosAttr)) {
                nanos = Integer.parseInt(nanosAttr);
            } else {
                nanos = 0;
            }
            value = TableContextUtil.getOffsetValueForTimestampParts(field.getValueAsDatetime().getTime(),
                    nanos);
        } else {
            value = field.getValueAsString();
        }
        offsets.put(offsetColumn, value);
    }
    return offsets;
}

From source file:com.aol.one.patch.DefaultPatcher.java

private Object invokeAccessorMethod(Object object, String fieldName)
        throws PatchException, IllegalAccessException, InvocationTargetException {

    Class<?> clazz = object.getClass();

    boolean isFieldNameNumeric = StringUtils.isNumeric(fieldName);

    if (isFieldNameNumeric && object instanceof java.util.List) {
        List tmpList = (List) object;
        return tmpList.get(Integer.parseInt(fieldName));
    }/*from w w w . j a  v a2  s  .c om*/

    if (isFieldNameNumeric && object instanceof java.util.Map) {
        Map tmpMap = (Map) object;
        return tmpMap.get(fieldName);
    }

    // try to find get+CapitalizedField
    // TODO: improve this to convert from snake_case to CamelCase
    List<String> methodNames = new ArrayList<>();
    methodNames.add("get" + StringUtils.capitalize(fieldName));
    methodNames.add(STANDARD_PATCH_OBJ_GETTER);

    List<MethodData> methodDataList = generateMethodData(methodNames);

    Set<String> triedMethodNames = new LinkedHashSet<>();

    for (MethodData methodData : methodDataList) {
        Method method;
        if (methodData.hasParameters()) {
            method = MethodUtils.getAccessibleMethod(clazz, methodData.methodName,
                    methodData.getParameterTypes().toArray(new Class<?>[0]));
            if (method != null && methodData.hasArguments()) {
                return method.invoke(object, methodData.arguments.toArray());
            }
        } else {
            method = MethodUtils.getAccessibleMethod(clazz, methodData.methodName);
            if (method != null) {
                return method.invoke(object);
            }
        }

        triedMethodNames.add(methodData.methodName);
    }

    String exMsg = getExMsgForMethodsNotFound(clazz,
            triedMethodNames.toArray(new String[triedMethodNames.size()]));
    throw new PatchException(ErrorCodes.ERR_METHOD_TO_PATCH_NOT_FOUND, exMsg);
}

From source file:com.moviejukebox.plugin.KinopoiskPlugin.java

/**
 * Retrieve Kinopoisk matching the specified movie name and year. This routine is base on a Google request.
 *
 * @param movieName//w  w  w. j a v  a 2s  .  co m
 * @param year
 * @param season
 * @return
 */
public String getKinopoiskId(String movieName, String year, int season) {
    try {
        String kinopoiskId;
        String sb = movieName;
        // Unaccenting letters
        sb = Normalizer.normalize(sb, Normalizer.Form.NFD);
        sb = sb.replaceAll("\\p{InCombiningDiacriticalMarks}+", "");

        sb = "&m_act[find]=" + URLEncoder.encode(sb, "UTF-8").replace(" ", "+");

        if (season != -1) {
            sb = sb + "&m_act[content_find]=serial";
        } else if (StringTools.isValidString(year)) {
            if (year.indexOf('-') > -1) {
                String[] years = year.split("-");
                sb = sb + "&m_act[from_year]=" + years[0];
                sb = sb + "&m_act[to_year]=" + years[1];
            } else {
                sb = sb + "&m_act[year]=" + year;
            }
        }

        sb = "http://kinopoisk.ru/index.php?level=7&from=forma&result=adv&m_act[from]=forma&m_act[what]=content"
                + sb;
        String xml = httpClient.request(sb, CHARSET);

        // Checking for zero results
        if (!xml.contains("class=\"search_results\"")) {
            // Checking direct movie page
            if (xml.contains("class=\"moviename-big\"")) {
                return HTMLTools.extractTag(xml, "id_film = ", ";");
            }
            return Movie.UNKNOWN;
        }

        // Checking if we got the movie page directly
        int beginIndex = xml.indexOf("id_film = ");
        if (beginIndex == -1) {
            // It's search results page, searching a link to the movie page
            beginIndex = xml.indexOf("class=\"search_results\"");
            if (beginIndex == -1) {
                return Movie.UNKNOWN;
            }

            beginIndex = xml.indexOf("/level/1/film/", beginIndex);
            if (beginIndex == -1) {
                return Movie.UNKNOWN;
            }

            StringTokenizer st = new StringTokenizer(xml.substring(beginIndex + 14), "/\"");
            kinopoiskId = st.nextToken();
        } else {
            // It's the movie page
            StringTokenizer st = new StringTokenizer(xml.substring(beginIndex + 10), ";");
            kinopoiskId = st.nextToken();
        }

        if (StringTools.isValidString(kinopoiskId) && StringUtils.isNumeric(kinopoiskId)) {
            return kinopoiskId;
        }
    } catch (IOException error) {
        LOG.error("Failed retreiving Kinopoisk Id for movie : {}", movieName);
        LOG.error("Error : {}", error.getMessage());
    }
    return Movie.UNKNOWN;
}

From source file:com.glaf.chart.web.rest.ChartResource.java

@GET
@POST/*from   w ww  . j a va2s . c  o m*/
@Path("/treeJson")
@ResponseBody
@Produces({ MediaType.APPLICATION_OCTET_STREAM })
public byte[] treeJson(@Context HttpServletRequest request) throws IOException {
    JSONArray array = new JSONArray();
    Long nodeId = RequestUtils.getLong(request, "nodeId");
    String nodeCode = request.getParameter("nodeCode");
    String selected = request.getParameter("selected");

    logger.debug(RequestUtils.getParameterMap(request));
    List<TreeModel> treeModels = new java.util.ArrayList<TreeModel>();
    List<String> chooseList = new java.util.ArrayList<String>();
    if (StringUtils.isNotEmpty(selected)) {
        chooseList = StringTools.split(selected);
    }

    TreeModel treeNode = null;

    if (nodeId != null && nodeId > 0) {
        treeNode = treeModelService.getTreeModel(nodeId);
    } else if (StringUtils.isNotEmpty(nodeCode)) {
        treeNode = treeModelService.getTreeModelByCode(nodeCode);
    }

    if (treeNode != null) {
        ChartQuery query = new ChartQuery();
        List<TreeModel> subTrees = treeModelService.getSubTreeModels(treeNode.getId());
        if (subTrees != null && !subTrees.isEmpty()) {
            for (TreeModel tree : subTrees) {
                tree.getDataMap().put("nocheck", "true");
                tree.getDataMap().put("iconSkin", "tree_folder");
                tree.getDataMap().put("isParent", "true");
                tree.setIconCls("folder");
                tree.setLevel(0);
                treeModels.add(tree);
                query.nodeId(tree.getId());
                List<Chart> charts = chartService.list(query);
                for (Chart chart : charts) {
                    if (StringUtils.isNumeric(chart.getId())) {
                        TreeModel t = new BaseTree();
                        t.setId(Long.parseLong(chart.getId()));
                        t.setParentId(tree.getId());
                        t.setName(chart.getChartTitle());
                        t.setCode(chart.getId());
                        t.setTreeId(chart.getId());
                        t.setIconCls("leaf");
                        t.getDataMap().put("iconSkin", "tree_leaf");
                        if (chooseList.contains(chart.getId())) {
                            t.setChecked(true);
                        }
                        treeModels.add(t);
                    }
                }
            }
        }
        TreeHelper treeHelper = new TreeHelper();
        array = treeHelper.getTreeJSONArray(treeModels);
    }

    return array.toJSONString().getBytes("UTF-8");
}