Harvid brainfart moment of the day:

So, I'm coding up this fix that AT&T is demanding, and I've solved the problem with a little hack WAY down inside this one module. Without going into too much detail, what I have to do is invert the array that I was returning from this one function (I said it was a hack!)

In java, to do that, you need to use a java.util.Comparator class inside the Arrays.sort() method call. Inside the comparator, I need to change the sign of the return value of the java.lang.String class's compareTo() method.

So, genius me, I'm sitting here for like 15 minutes trying to figure this out, so I code-up something like this:


int ordinal = fileName1.compareTo(fileName2);

switch( ordinal )
{
case -1: return 1;
case 1: return -1;
case 0: return 0;

}


Which is just about the most ridiculous code I've ever seen....so I say to Patrick: "What's the easiest way to flip the sign of an integer?" and he goes: "Uhh...multiply by negative 1?"

Yup. Monstrous code becomes nice and neat:


return -1 * fileName1.compareTo(fileName2);

Comments

Popular posts from this blog

Review: The Southeast Christian Church Easter Pageant

Rant On getting smacked down...

"Spiderman 3"...WHY?!