Kenmegne
7 days ago b3d0580439b9a00c7eb918085de1694151066004
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
package com.megatim.fdxconvert.util;
 
import com.megatim.fdxconvert.App;
import java.io.FileInputStream;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Properties;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
 
/**
 *
 * @author ASUS
 */
public class Utilities {
 
    private Utilities() {
    }
 
    //Mots reservĂ©s de Java
    private final static Set<String> reservedWords = new HashSet<>(Arrays.asList("abstract", "assert", "boolean", "break", "byte", "case", "catch", "char",
            "class", "continue", "const", "default", "do", "double", "else", "enum", "exports", "extends", "final", "finally",
            "false", "float", "for", "goto", "if", "implements", "import", "instanceof", "int", "interface", "long", "module", "native",
            "new", "null", "package", "private", "protected", "public", "requires", "return", "short", "static", "strictfp", "super", "switch",
            "synchronized", "this", "throw", "throws", "transient", "true", "try", "var", "void", "volatile", "while"));
 
    public static StringBuilder validateName(String name, String libelle) {
        StringBuilder message = new StringBuilder("");
 
        if (reservedWords.contains(name)) {
            message.append("\"").append(name).append("\"").append(" est un mot reservĂ©\n");
        }
 
        if (!name.matches("^([a-zA-Z]|_|\\$)(\\w|\\$)*$")) {
            message.append(libelle).append(" doit commencer par une lettre [a-zA-Z], par le signe dollar( $ ) "
                    + "ou par un trait de soulignement( _ ) et ne doit pas contenir d'espace\n");
 
        }
 
        return message;
    }
 
    public static int getNbThreads() {
 
        Properties appProps = new Properties();
        int nbThreads = 1;
 
        try {
            appProps.load(new FileInputStream("./app.properties"));
            nbThreads = Integer.parseInt(appProps.getProperty("nbThreads"));
        } catch (Exception ex) {
            Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex);
        }
        return nbThreads;
    }
}