Example usage for org.apache.commons.lang3.math NumberUtils isNumber

List of usage examples for org.apache.commons.lang3.math NumberUtils isNumber

Introduction

In this page you can find the example usage for org.apache.commons.lang3.math NumberUtils isNumber.

Prototype

public static boolean isNumber(final String str) 

Source Link

Document

Checks whether the String a valid Java number.

Valid numbers include hexadecimal marked with the 0x or 0X qualifier, octal numbers, scientific notation and numbers marked with a type qualifier (e.g.

Usage

From source file:tds.dll.mysql.StudentDLL.java

/**
 * Description of Isgradeequiv(connection, grade1, grade2) Checks if a strings
 * - Grade1 & Grade2 are numerics/*from  w w w  . java  2s  . co m*/
 * 
 * @param connection
 *          - connection object
 * @param grade1
 *          - grade1(String)
 * @param grade2
 *          - grade2(String)
 * @return result - Boolean
 */
public boolean __IsGradeEquiv_FN(String grade1, String grade2) {
    boolean result = false;
    if (NumberUtils.isNumber(grade1.trim()) && NumberUtils.isNumber(grade2.trim())) {
        if (Float.parseFloat(grade1.trim()) == Float.parseFloat(grade2.trim())) {
            result = true;
        }
    } else if (DbComparator.isEqual(grade1, grade2))
        result = true;
    return result;
}

From source file:test.CountTopics.java

public static void main(String[] args) {

    try {/*from   w  w  w  .  java  2s.  c om*/
        File file = new File(
                "/Users/apple/Desktop/output/after-process/javadoc+comments/removeClassLibrary-noCopyright-originalWords-camel-stopwords/keys.txt");
        List<String> topicslist = new ArrayList<>();
        Map<String, Integer> map = new HashMap<>();
        if (!file.exists()) {
            System.out.println("File1 isn't exist");
        } else {
            try (InputStream in1 = new FileInputStream(file.getPath());
                    BufferedReader reader1 = new BufferedReader(new InputStreamReader(in1))) {

                String line1 = null;
                while ((line1 = reader1.readLine()) != null) {
                    String[] topics1 = line1.split("\t| ");

                    for (String t : topics1) {
                        if (!NumberUtils.isNumber(t)) {
                            topicslist.add(t);
                        }

                    }
                }
            }

            for (int i = 0; i < topicslist.size(); i++) {
                String word = topicslist.get(i);
                int index = 1;
                for (int j = 0; j < topicslist.size(); ++j) {
                    if (word.equals(topicslist.get(j))) {
                        ++index;
                    }
                }
                map.put(word, index);
            }

            Iterator iter = map.entrySet().iterator();
            int index = -1;
            while (iter.hasNext()) {
                ++index;
                Map.Entry entry = (Map.Entry) iter.next();
                Object key = entry.getKey();
                Object val = entry.getValue();
                System.out.println(key + ":" + val);
            }
        }

    } catch (IOException ex) {
        Logger.getLogger(CompareTopics.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:test.GenerateTopicsJson.java

public static void main(String[] args) {
    try {//from ww  w.  jav a 2s . co  m
        String topicCountFilePath = "/Users/apple/Desktop/output/after-process/javadoc-comments/demo/word_top.txt";
        String topicsFilePath = "/Users/apple/Desktop/output/after-process/javadoc-comments/demo/keys.txt";
        String outputFilePath = "/Users/apple/Desktop/test.json";
        File outputFile = new File(outputFilePath);
        if (outputFile.createNewFile()) {
            System.out.println(outputFile.getName() + " create successful...");
        }

        Map<String, Integer> topicMap = new HashMap<>();

        try (InputStream countIn = new FileInputStream(topicCountFilePath);
                BufferedReader countReader = new BufferedReader(new InputStreamReader(countIn));
                InputStream topicsIn = new FileInputStream(topicsFilePath);
                BufferedReader topicsReader = new BufferedReader(new InputStreamReader(topicsIn));
                BufferedWriter writer = new BufferedWriter(new FileWriter(outputFile))) {

            String countLine = "";
            while ((countLine = countReader.readLine()) != null) {
                String[] topics = countLine.split("\t| ");
                int count = 0;
                for (int i = 0; i < topics.length; ++i) {
                    if (topics[i].contains(":")) {
                        String[] label = topics[i].split(":");
                        count = count + Integer.parseInt(label[1]);
                    }

                }

                //                    System.out.println(topics[1] + " " + count);

                topicMap.put(topics[1], count);

            }

            JSONObject json = new JSONObject();
            json.put("name", "topics");

            JSONArray children = new JSONArray();
            json.put("children", children);

            String topicsLine = "";
            while ((topicsLine = topicsReader.readLine()) != null) {
                JSONObject topicGroup = new JSONObject();
                topicGroup.put("name", randomString(8));

                JSONArray topicArray = new JSONArray();
                topicGroup.put("children", topicArray);

                String[] topics = topicsLine.split("\\s");
                for (int i = 0; i < topics.length; ++i) {
                    if (topics.length > 2) {
                        if (!NumberUtils.isNumber(topics[i])) {
                            JSONObject topic = new JSONObject();
                            topic.put("name", topics[i]);
                            topic.put("size", topicMap.get(topics[i]));
                            topicArray.put(topic);
                        }
                    }
                }

                children.put(topicGroup);
            }

            json.write(writer);

            int index = -1;
            Map<String, Integer> topicMap2 = new HashMap<>();
            JSONObject json2 = json;

            JSONArray children2 = json2.getJSONArray("children");

            for (int i = 0; i < children2.length(); ++i) {
                JSONObject topicsGroup = children2.getJSONObject(i);

                JSONArray topicArray = topicsGroup.getJSONArray("children");
                for (int j = 0; j < topicArray.length(); ++j) {
                    JSONObject topic = topicArray.getJSONObject(j);
                    String topicName = topic.getString("name");
                    int size = topic.getInt("size");
                    //                        System.out.println(topicName + " " + size);
                    topicMap2.put(topicName, size);
                }

            }

            List<Map.Entry<String, Integer>> list = new ArrayList<>();
            list.addAll(topicMap2.entrySet());
            Collections.sort(list, new Comparator<Map.Entry<String, Integer>>() {
                public int compare(Map.Entry<String, Integer> m, Map.Entry<String, Integer> n) {
                    return n.getValue() - m.getValue();
                }
            });
            for (Iterator<Map.Entry<String, Integer>> it = list.iterator(); it.hasNext();) {
                ++index;
                System.out.println(index + ":" + it.next().getKey() + ":" + it.next().getValue());

            }

        } catch (JSONException ex) {
            Logger.getLogger(GenerateTopicsJson.class.getName()).log(Level.SEVERE, null, ex);
        }

    } catch (IOException ex) {
        Logger.getLogger(GenerateTopicsJson.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:test.Topics.java

public static void main(String[] args) {
    try {//from  w  ww  . j a v a  2s .  com
        String topicsFilePath = "/Users/apple/NetBeansProjects/TopicModelingTools/test/topic_keys.txt";

        try (InputStream topicsIn = new FileInputStream(topicsFilePath);
                BufferedReader topicsReader = new BufferedReader(new InputStreamReader(topicsIn));) {

            JSONObject json = new JSONObject();
            JSONArray children = new JSONArray();
            json.put("parent", children);

            String topicsLine = "";
            while ((topicsLine = topicsReader.readLine()) != null) {
                JSONObject topicGroup = new JSONObject();
                JSONArray topicArray = new JSONArray();
                topicGroup.put("children", topicArray);

                String[] topics = topicsLine.split("\\s");
                for (int i = 0; i < topics.length; ++i) {
                    if (topics.length > 2) {
                        if (!NumberUtils.isNumber(topics[i])) {
                            JSONObject topic = new JSONObject();
                            topic.put("name", topics[i]);
                            topicArray.put(topic);
                        }
                    }
                }
                children.put(topicGroup);
            }

            System.out.println(json);

            JSONObject json2 = json;
            JSONArray parent2 = json2.getJSONArray("parent");

            for (int i = 0; i < parent2.length(); ++i) {
                JSONObject topicGroup2 = parent2.getJSONObject(i);
                JSONArray children2 = topicGroup2.getJSONArray("children");

                for (int j = 0; j < children2.length(); ++j) {
                    JSONObject topic2 = children2.getJSONObject(j);
                    String name2 = topic2.getString("name");
                    System.out.print(name2 + " ");
                }
                System.out.println();
            }

        } catch (JSONException ex) {
            Logger.getLogger(Topics.class.getName()).log(Level.SEVERE, null, ex);
        }

    } catch (IOException ex) {
        Logger.getLogger(GenerateTopicsJson.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:tsuboneSystem.action.admin.MessageDeleteAjaxAction.java

@Execute(validator = false)
public String index() {
    //get?ID?//from ww w  . ja  va2s  .co m
    String id = request.getParameter("messageId");
    if (id == null || !NumberUtils.isNumber(id)) {
        return null;
    }
    TTempMessage tTempMessage = ttempMessageService.findById(Integer.parseInt(id));
    if (tTempMessage == null) {
        return null;
    }
    //????????
    if (tTempMessage.targetMemberId.equals(getLoginMemberId())) {

    }
    tTempMessage.deleteFlag = true;
    ttempMessageService.update(tTempMessage);
    return null;
}

From source file:View.Visualize.java

private void addDataFromTable(Table selectedTable, Integer nameColumn, Integer valueColumn, Boolean rowCount)
        throws NumberFormatException {

    for (List<String> a : selectedTable.filteredItems) {
        if (rowCount) {
            addNewDataPoint(a.get(nameColumn), 1);
        } //hvis ikke, bruker vi bare verdien fra kolonnen
        else {/*from ww  w.ja v a  2s .  c  o m*/

            if (!a.get(nameColumn).isEmpty() && NumberUtils.isNumber(a.get(valueColumn))) {
                //hvis brukeren nsker  telle hvor mange rader en kategori har, bruker vi bare 1
                //for eksempel, hvor mange produkter har varegruppe Vifte, legg til 1 for hver vare

                addNewDataPoint(a.get(nameColumn), Double.parseDouble(a.get(valueColumn)));
            } else {
                System.out.println(a.get(nameColumn));
                System.out.println(a.get(valueColumn));
                System.out.println("LEGG TIL FEILMELDING AT DETTE IKKE ER NUMMER");

            }

        }
    }
}