Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Yay, Java!

Name: Anonymous 2008-04-14 2:01

Doing a validator method for RNA complements:

private static boolean isComplementar(final char a, final char b) {
  boolean s1 = (a == 'A' && b == 'U');
  boolean s2 = (a == 'U' && b == 'A');
  boolean s3 = (a == 'C' && b == 'G');
  boolean s4 = (a == 'G' && b == 'C');
  return (s1 || s2 || s3 || s4);
}


LULZ

Name: Anonymous 2008-04-14 8:02

If you can use a String instead of chars, you could make the valid complements static final. Then the JVM will intern them and you can legitimately do a == comparison to check if it matches.


public static final String s1 = "AU".intern();
public static final String s2 = "UA".intern();
public static final String s3 = "CG".intern();
public static final String s4 = "GC".intern();

private static final boolean isComplementar(String aPlusB) {
  return (aPlusB == s1 || aPlusB == s2 || aPlusB == s3 || aPlusB == s4)
}


Note the .intern() here is redundant, I just included it for clarity.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List