So I have an ArrayList which contains String values in my main method.
And I want to go and search in the enum class the reference of each element of my ArrayList and set it in the same index .
So lets say my arrayList is ["GUA", "AUG", "CUA"] I want to have in my output [Val, Met, Leu].
So I am trying to fix my find() method so that it returns an arrayList not just a string, and without using a 'for' loop in main().But it will always give me an error when I try to change my return type.
Any ideas?
public enum Abreviation {
Ala("GCU", "GCC", "GCA", "GCG"),
Arg("CGU", "CGC", "CGA", "CGG", "AGA", "AGG"),
Asn("AAU", "AAC"),
Asp("GAU", "GAC"),
Cys("UGU", "UGC"),
Glu("GAG", "GAA"),
Gln("CAG", "CAA"),
Gly("GGU", "GGC", "GGA", "GGG"),
His("CAC", "CAU"),
Ile("AUU", "AUC", "AUA"),
Leu("UUA", "UUG", "CUU", "CUC", "CUA", "CUG"),
Lys("AAA", "AAG"),
Met("AUG"),
Phe("UUU", "UUC"),
Pro("CCU", "CCC", "CCA", "CCG"),
Pyl("UAG"),
Sec("UGA"),
Ser("UCU", "UCC", "UCA", "UCG", "AGU", "AGC"),
Thr("ACU", "ACG", "ACA", "ACC"),
Trp("UGG"),
Tyr("UAU", "UAC"),
Val("GUU", "GUC", "GUA", "GUG"),
Fin("UAA")
;
private final List<String> arn;
private Abreviation(final String... arn) {
this.arn = Arrays.asList(arn);
}
public boolean contains(final String codon) {
return this.arn.contains(codon);
}
}
public class MainMain {
public static void main(String[] args) {
ArrayList <String> strings = new ArrayList<String>();
strings.add("GUA");
strings.add("AUG");
strings.add("CUA");
for (int i = 0; i < strings.size(); i++) {
System.out.println(find(strings.get(i), strings));
}
}
public static List<String> find(final String codon, List<String> strings) {
for (final Abreviation abb : Abreviation.values()){
if (abb.contains(codon)) {
int arn = strings.indexOf(codon);
strings.set(arn, abb.name());
return strings;
}
}
throw new IllegalArgumentException("Erreur");
}
}