Rev 264 | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 264 | espaco | 1 | package br.com.ec.domain.dto.grafico; |
| 2 | |||
| 3 | import java.util.ArrayList; |
||
| 4 | import java.util.List; |
||
| 705 | blopes | 5 | import java.util.stream.Collectors; |
| 6 | import java.util.stream.IntStream; |
||
| 264 | espaco | 7 | |
| 8 | public class GraficoDadoDTO { |
||
| 9 | |||
| 10 | private List<Number> valores; |
||
| 11 | private List<String> cores; |
||
| 12 | private List<String> bordas; |
||
| 13 | private List<String> marcadores; |
||
| 14 | |||
| 15 | public GraficoDadoDTO() { |
||
| 16 | limparEntidade(); |
||
| 17 | } |
||
| 18 | |||
| 19 | private void limparEntidade() { |
||
| 20 | setValores(new ArrayList<>()); |
||
| 21 | setCores(new ArrayList<>()); |
||
| 22 | setBordas(new ArrayList<>()); |
||
| 23 | setMarcadores(new ArrayList<>()); |
||
| 24 | } |
||
| 25 | |||
| 26 | public List<Number> getValores() { |
||
| 27 | return valores; |
||
| 28 | } |
||
| 29 | public void setValores(List<Number> valores) { |
||
| 30 | this.valores = valores; |
||
| 31 | } |
||
| 32 | |||
| 33 | public List<String> getCores() { |
||
| 34 | return cores; |
||
| 35 | } |
||
| 36 | public void setCores(List<String> cores) { |
||
| 37 | this.cores = cores; |
||
| 38 | } |
||
| 39 | |||
| 40 | public List<String> getBordas() { |
||
| 41 | return bordas; |
||
| 42 | } |
||
| 43 | public void setBordas(List<String> bordas) { |
||
| 44 | this.bordas = bordas; |
||
| 45 | } |
||
| 46 | |||
| 47 | public void setMarcadores(List<String> marcadores) { |
||
| 48 | this.marcadores = marcadores; |
||
| 49 | } |
||
| 50 | public List<String> getMarcadores() { |
||
| 51 | return marcadores; |
||
| 52 | } |
||
| 53 | |||
| 54 | /********************************************/ |
||
| 55 | |||
| 56 | public void adicionarDados(Number valor, String cor, String borda, String marcador) { |
||
| 57 | getValores().add(valor); |
||
| 58 | getCores().add(cor); |
||
| 59 | getBordas().add(borda); |
||
| 60 | getMarcadores().add(marcador); |
||
| 61 | } |
||
| 62 | |||
| 705 | blopes | 63 | public void ordenarPorValor() { |
| 64 | List<Integer> indices = IntStream.range(0, this.getValores().size()) |
||
| 65 | .boxed() |
||
| 66 | .sorted((i, j) -> Double.compare( |
||
| 67 | this.getValores().get(j).doubleValue(), |
||
| 68 | this.getValores().get(i).doubleValue())) |
||
| 69 | .collect(Collectors.toList()); |
||
| 70 | |||
| 71 | // Cria novas listas ordenadas conforme os índices |
||
| 72 | List<Number> novosValores = new ArrayList<>(); |
||
| 73 | List<String> novasCores = new ArrayList<>(); |
||
| 74 | List<String> novasBordas = new ArrayList<>(); |
||
| 75 | List<String> novosMarcadores = new ArrayList<>(); |
||
| 76 | |||
| 77 | for (int i : indices) { |
||
| 78 | novosValores.add(this.getValores().get(i)); |
||
| 79 | novasCores.add(this.getCores().get(i)); |
||
| 80 | novasBordas.add(this.getBordas().get(i)); |
||
| 81 | novosMarcadores.add(this.getMarcadores().get(i)); |
||
| 82 | } |
||
| 83 | |||
| 84 | // Substitui as listas antigas |
||
| 85 | this.setValores(novosValores); |
||
| 86 | this.setCores(novasCores); |
||
| 87 | this.setBordas(novasBordas); |
||
| 88 | this.setMarcadores(novosMarcadores); |
||
| 89 | } |
||
| 90 | |||
| 264 | espaco | 91 | } |