Rev 264 |
Blame |
Compare with Previous |
Last modification |
View Log
| Download
| RSS feed
package br.com.ec.domain.dto.grafico;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class GraficoDadoDTO
{
private List<Number> valores
;
private List<String> cores
;
private List<String> bordas
;
private List<String> marcadores
;
public GraficoDadoDTO
() {
limparEntidade
();
}
private void limparEntidade
() {
setValores
(new ArrayList<>());
setCores
(new ArrayList<>());
setBordas
(new ArrayList<>());
setMarcadores
(new ArrayList<>());
}
public List<Number> getValores
() {
return valores
;
}
public void setValores
(List<Number> valores
) {
this.
valores = valores
;
}
public List<String> getCores
() {
return cores
;
}
public void setCores
(List<String> cores
) {
this.
cores = cores
;
}
public List<String> getBordas
() {
return bordas
;
}
public void setBordas
(List<String> bordas
) {
this.
bordas = bordas
;
}
public void setMarcadores
(List<String> marcadores
) {
this.
marcadores = marcadores
;
}
public List<String> getMarcadores
() {
return marcadores
;
}
/********************************************/
public void adicionarDados
(Number valor,
String cor,
String borda,
String marcador
) {
getValores
().
add(valor
);
getCores
().
add(cor
);
getBordas
().
add(borda
);
getMarcadores
().
add(marcador
);
}
public void ordenarPorValor
() {
List<Integer> indices = IntStream.
range(0,
this.
getValores().
size())
.
boxed()
.
sorted((i, j
) -
> Double.
compare(
this.
getValores().
get(j
).
doubleValue(),
this.
getValores().
get(i
).
doubleValue()))
.
collect(Collectors.
toList());
// Cria novas listas ordenadas conforme os índices
List<Number> novosValores =
new ArrayList<>();
List<String> novasCores =
new ArrayList<>();
List<String> novasBordas =
new ArrayList<>();
List<String> novosMarcadores =
new ArrayList<>();
for (int i : indices
) {
novosValores.
add(this.
getValores().
get(i
));
novasCores.
add(this.
getCores().
get(i
));
novasBordas.
add(this.
getBordas().
get(i
));
novosMarcadores.
add(this.
getMarcadores().
get(i
));
}
// Substitui as listas antigas
this.
setValores(novosValores
);
this.
setCores(novasCores
);
this.
setBordas(novasBordas
);
this.
setMarcadores(novosMarcadores
);
}
}