Rev 264 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 264 | Rev 705 | ||
|---|---|---|---|
| Line 4... | Line 4... | ||
| 4 | import java.util.List; |
4 | import java.util.List; |
| - | 5 | import java.util.stream.Collectors; |
|
| - | 6 | import java.util.stream.IntStream; |
|
| 5 | 7 | ||
| 6 | public class GraficoDadoDTO { |
8 | public class GraficoDadoDTO { |
| 7 | 9 | ||
| 8 | private List<Number> valores; |
10 | private List<Number> valores; |
| 9 | private List<String> cores; |
11 | private List<String> cores; |
| Line 54... | Line 56... | ||
| 54 | public void adicionarDados(Number valor, String cor, String borda, String marcador) { |
56 | public void adicionarDados(Number valor, String cor, String borda, String marcador) { |
| 55 | getValores().add(valor); |
57 | getValores().add(valor); |
| 56 | getCores().add(cor); |
58 | getCores().add(cor); |
| 57 | getBordas().add(borda); |
59 | getBordas().add(borda); |
| 58 | getMarcadores().add(marcador); |
60 | getMarcadores().add(marcador); |
| - | 61 | }
|
|
| - | 62 | ||
| - | 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); |
|
| 59 | }
|
89 | }
|
| 60 | 90 | ||
| 61 | }
|
91 | }
|