Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1 | espaco | 1 | package br.gov.al.saude.test.util; |
| 2 | |||
| 3 | import java.text.ParseException; |
||
| 4 | import java.text.SimpleDateFormat; |
||
| 5 | import java.util.ArrayList; |
||
| 6 | import java.util.Date; |
||
| 7 | import java.util.List; |
||
| 8 | |||
| 9 | import br.gov.al.saude.framework.core.util.VerificadorUtil; |
||
| 10 | |||
| 11 | public class StringUtils { |
||
| 12 | |||
| 13 | public static Long valueLong(String valor) { |
||
| 14 | return VerificadorUtil.naoEstaNuloOuVazio(valor)? Long.parseLong(valor) : null; |
||
| 15 | } |
||
| 16 | |||
| 17 | public static Integer valueInt(String valor) { |
||
| 18 | return VerificadorUtil.naoEstaNuloOuVazio(valor)? Integer.parseInt(valor) : null; |
||
| 19 | } |
||
| 20 | |||
| 21 | public static Date valueDate(String valor) { |
||
| 22 | return VerificadorUtil.naoEstaNuloOuVazio(valor)? parseDate(valor) : null; |
||
| 23 | } |
||
| 24 | |||
| 25 | public static Boolean valueBoolean(String valor) { |
||
| 26 | return VerificadorUtil.naoEstaNuloOuVazio(valor)? parseBoolean(valor) : null; |
||
| 27 | } |
||
| 28 | |||
| 29 | public static char valueChar(String valor) { |
||
| 30 | return VerificadorUtil.naoEstaNuloOuVazio(valor)? valor.charAt(0) : null; |
||
| 31 | } |
||
| 32 | |||
| 33 | private static Boolean parseBoolean(String indicadorAtivo) { |
||
| 34 | if("SIM".equalsIgnoreCase(indicadorAtivo)) |
||
| 35 | return true; |
||
| 36 | if("NAO".equalsIgnoreCase(indicadorAtivo)) |
||
| 37 | return false; |
||
| 38 | return null; |
||
| 39 | } |
||
| 40 | |||
| 41 | private static Date parseDate(String dataString) { |
||
| 42 | SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy"); |
||
| 43 | try { |
||
| 44 | return format.parse(dataString); |
||
| 45 | } catch (ParseException e) { |
||
| 46 | throw new RuntimeException("Não foi possível converter String data para Date"); |
||
| 47 | } |
||
| 48 | } |
||
| 49 | |||
| 50 | public static List<Long> valueListaLong(String[] valores) { |
||
| 51 | List<Long> listaLong = new ArrayList<Long>(); |
||
| 52 | for (String valor : valores) { |
||
| 53 | if (VerificadorUtil.naoEstaNuloOuVazio(valor)) { |
||
| 54 | listaLong.add(Long.parseLong(valor)); |
||
| 55 | } |
||
| 56 | } |
||
| 57 | return listaLong; |
||
| 58 | } |
||
| 59 | |||
| 60 | public static Object valueDouble(String valor) { |
||
| 61 | return VerificadorUtil.naoEstaNulo(valor) ? parseDouble(valor) : null; |
||
| 62 | } |
||
| 63 | |||
| 64 | public static String valueString(Object valor) { |
||
| 65 | return VerificadorUtil.naoEstaNulo(valor) ? valor.toString() : null; |
||
| 66 | } |
||
| 67 | |||
| 68 | public static String parseDate(Date data) { |
||
| 69 | return new SimpleDateFormat("dd/MM/yyyy").format(data); |
||
| 70 | } |
||
| 71 | |||
| 72 | public static Double parseDouble(String valor) { |
||
| 73 | return Double.parseDouble(valor); |
||
| 74 | } |
||
| 75 | |||
| 76 | public static String anoCorrente() { |
||
| 77 | return new SimpleDateFormat("yyyy").format(new Date()); |
||
| 78 | } |
||
| 79 | |||
| 80 | public static String getDataAtual() { |
||
| 81 | return new SimpleDateFormat("dd/MM/yyyy").format(new Date()); |
||
| 82 | } |
||
| 83 | |||
| 84 | |||
| 85 | |||
| 86 | |||
| 87 | |||
| 88 | |||
| 89 | } |