Skip to content

Instantly share code, notes, and snippets.

@roberto-filho
Created August 9, 2012 18:50
Show Gist options
  • Save roberto-filho/3307063 to your computer and use it in GitHub Desktop.
Save roberto-filho/3307063 to your computer and use it in GitHub Desktop.
Usando multimaps
private class GroupingKey implements Comparable<GroupingKey> {
private Date dataVencimento;
private Empresa cliente;
private GroupingKey(Date dataVencimento, Empresa cliente) {
super();
this.dataVencimento = dataVencimento;
this.cliente = cliente;
}
public Empresa getCliente() {
return cliente;
}
public Date getDataVencimento() {
return dataVencimento;
}
@Override
public int compareTo(GroupingKey o) {
// TODO Auto-generated method stub
return 0;
}
@Override
public boolean equals(Object obj) {
if (obj instanceof GroupingKey) {
GroupingKey key = (GroupingKey) obj;
if(dataVencimento.equals(key.getDataVencimento()) && cliente.equals(key.getCliente()))
return true;
}
return false;
}
}
public static void main(String[] args) {
List<Debito> lista = newArrayList();
Multimap<GroupingKey, Debito> grouped = Multimaps.index(lista, new Function<Debito, GroupingKey>() {
@Override
public GroupingKey apply(Debito input) {
return new GroupingKey(input.getDataVencimento(), input.getCliente());
}
});
for (GroupingKey chave : grouped.keySet()) {
List<Debito> debs = newArrayList(grouped.get(chave));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment