masklinn í dag viðrar vel til loftárása | deltamoins a écrit :
Je suis dac pour le 3/ mais c'est le 2/ que je n'arrive pas à faire. La est le soucis.
|
1. Quelle est la définition de Gene? 2. Pourquoi tu utilises des Iterator directement? 3. select is not broken Code :
import java.lang.Comparable; class Gene implements Comparable<Gene> { public Gene (final String name ) { this.name = name; } public int compareTo(Gene other) { return this.name.compareTo(other.name); } return "[Gene(" + this.name + " )]"; } }
|
Code :
import java.util.*; public class Test { public static Collection<Gene> getGenes() { return new ArrayList<Gene>() {{ add(new Gene("Foo" )); add(new Gene("Bar" )); add(new Gene("Baz" )); add(new Gene("Qux" )); add(new Gene("Quux" )); add(new Gene("Corge" )); add(new Gene("Grault" )); }}; } public static void main (String[] args ) { final List<Gene> sorted = new ArrayList<Gene>(); sorted.addAll(getGenes()); } }
|
> java Test [[Gene(Foo)], [Gene(Bar)], [Gene(Baz)], [Gene(Qux)], [Gene(Quux)], [Gene(Corge)], [Gene(Grault)]] [[Gene(Bar)], [Gene(Baz)], [Gene(Corge)], [Gene(Foo)], [Gene(Grault)], [Gene(Quux)], [Gene(Qux)]] |
marche très bien chez moi.
mr simon a écrit :
Pour que Collections.sort fonctionne correctement, il faut que tes elements, "Gene", soit comparable, i.e implemente l'interface Comparable, est-ce bien le cas?
|
Tu peux aussi implémenter un Comparator<Gene> et filer ça en 2e argument à Collections.sort, genre:
Code :
public int compare(Gene g1, Gene g2) { return g1.name.compareTo(g2.name); } });
|
et dans ce cas pas besoin que la classe implémente Comparable.
Message édité par masklinn le 11-05-2011 à 12:04:36 ---------------
I mean, true, a cancer will probably destroy its host organism. But what about the cells whose mutations allow them to think outside the box by throwing away the limits imposed by overbearing genetic regulations? Isn't that a good thing?
|