Trow_Games

Identificadores

Jul 15th, 2020
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.33 KB | None | 0 0
  1.  
  2.    
  3.     /**
  4.      * Identificar o valor do campo Novo limite de credito, no arquivo .txt
  5.      * @author Renato Henrique Mendes Silva ~ ValeCard
  6.      * @param linha que esta sendo lida no arquivo, no formato: Matrícula Nome Novo limite de credito
  7.      * @return BigDecimal referente ao valor do campo ou 0.
  8.      */
  9.     public static BigDecimal identificaNovoLimiteCredito(String linha, int pos) {
  10.         try {
  11.             String valorLimite = linha.split("  ")[pos].split(" ")[0];
  12. /*          boolean passouDoNome = false;
  13.             for(int i = 0; i < linha.length(); i++){
  14.                 String caracter = linha.charAt(i)+"";
  15.                 if(caracter.equals(" ")) continue;
  16.                 if(!isInt(caracter) && !(caracter.equals(".") || caracter.equals(",") || caracter.equals(";"))) {
  17.                     passouDoNome = true;
  18.                     continue;
  19.                 } else if(passouDoNome){
  20.                     valorLimite = valorLimite+caracter;
  21.                 }
  22.             }*/
  23.             return new BigDecimal(valorLimite);
  24.         } catch (Exception e) {
  25.             return new BigDecimal(0);
  26.         }
  27.     }
  28.    
  29.     /**
  30.      * Identificar o valor do campo Nome, no arquivo .txt
  31.      * @author Renato Henrique Mendes Silva ~ ValeCard
  32.      * @param Linha que esta sendo lida no arquivo, no formato: Matrícula Nome Novo limite de credito
  33.      * @return Nome do beneficiário ou "".
  34.      */
  35.     public static String identificaNome(String a) {
  36.         try {
  37.             String nome = "";
  38.             boolean contouEspacoEntreNome = false;
  39.             for(int i = 0; i < a.length(); i++){
  40.                 String caracter = a.charAt(i)+"";
  41.                 if(isInt(caracter)) continue;
  42.                 if(!StringUtils.isEmpty(nome) && caracter.contains(" ") && !contouEspacoEntreNome){
  43.                     contouEspacoEntreNome = true;
  44.                 } else if(caracter.equals(" ")) {
  45.                     continue;
  46.                 } else if(caracter.equals(".") || caracter.equals(",") || caracter.equals(";")){
  47.                     continue;
  48.                 }
  49.                 contouEspacoEntreNome = false;
  50.                 nome = nome + caracter;
  51.             }
  52.             return nome.trim();
  53.         } catch (Exception e) {
  54.             return null;
  55.         }
  56.     }
  57.    
  58.     /**
  59.      * Identificar o valor do campo Matrícula, no arquivo .txt
  60.      * @author Renato Henrique Mendes Silva ~ ValeCard
  61.      * @param linha que esta sendo lida no arquivo, no formato: Matrícula Nome Novo limite de credito
  62.      * @param pos Posição onde o campo Matricula está.
  63.      * @return BigDecimal referente ao valor do campo Matrícula ou "".
  64.      */
  65.     public static String identificaMatricula(String linha, int pos) {
  66.         try {
  67.             return linha.split("  ")[pos];
  68.         } catch (Exception e) {
  69.             return "";
  70.         }
  71.     }
  72.    
  73.     /**
  74.      * Formata a linha que esta sendo para remover os espaços entre os campos.
  75.      * @author Renato Henrique Mendes Silva ~ ValeCard
  76.      * @param a Linha que esta sendo lida e será formatada.
  77.      * @return A linha informada formatada e separada em blocos de 2 espaços
  78.      */
  79.     public static String formataLinha(String a){
  80.         String novaLinha = "";
  81.         boolean contouEspaco = false;
  82.         boolean separouBloco = false;
  83.         for(int i = 0; i < a.length(); i++){
  84.             String c = a.charAt(i)+"";
  85.             if(c.equals(" ") && !contouEspaco) {
  86.                 contouEspaco = true;
  87.                 novaLinha += c;
  88.                 continue;
  89.             } else if(c.equals(" ")){
  90.                 if(!separouBloco){
  91.                     separouBloco = true;
  92.                     novaLinha += c;
  93.                 }
  94.                 continue;
  95.             } else {
  96.                 separouBloco = false;
  97.                 contouEspaco = false;
  98.                 novaLinha += c;
  99.             }
  100.         }
  101.         return novaLinha;
  102.     }
  103.  
  104.     public static boolean isInt(String a) {
  105.         try {
  106.             Integer.parseInt(a);
  107.             return true;
  108.         } catch (Exception e) {
  109.         }
  110.         return false;
  111.     }
Add Comment
Please, Sign In to add comment