[quote user="asuffield"]
With gperf, or something like it. This is not a WTF. This is software-generated code. It's the easiest way to automatically generate an efficient string matcher from a table. It was more common years ago, when computers were slow enough to care... nowadays you don't see it so much, except in legacy code, because nobody worries about the performance of their string lookup tables any more.
I'm not really sure why somebody bothered to implement one for Java.
[/quote]
This code was definately written by hand, and has comments above it explaining how it was written, how they tested what hardcoded magic numbers to use, and etc:
/*
Case values determine by args[0] a psuedo hash code algorithm on the
args string. (Doesn't use regular old hashcode because that might
be VM dependent)
helpCase: 89747534
multiCase: -964127032
singleCase: -919304285
...
This code figures them out:
System.out.println("getHashValue(-help) " +getHashValue("-help".toCharArray()));
System.out.println("getHashValue(-multi) " +getHashValue("-multi".toCharArray()));
System.out.println("getHashValue(-single) " +getHashValue("-single".toCharArray()));
...
*/
The hash codes might be VM dependant so we should write our own hash algorithm! Brilliance.