Created
August 9, 2012 18:50
-
-
Save roberto-filho/3307063 to your computer and use it in GitHub Desktop.
Usando multimaps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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