¿ªÔÆÌåÓý

ctrl + shift + ? for shortcuts
© 2025 Groups.io

Re: Java switch/case, TickType Enum, and tickPrice()


 

I wouldn't be too concerned about the overhead from converting integers to TickType constants (spoken by someone who was brought up hand-optimizing MC68K code because coding in C was too much overhead). Just tested with a laptop from the early 2010s and it was able to perform 19Mio such conversions per second.

But if you want the switch and you do not want to convert the int to TickType constants, something like this would work with protection for the case that TickType constants would ever change in the future:

static {
?? ?if ( TickType.BID.index() != 1 ) {
?? ???? throw new Error( "Expected TickType.BID.index() == 1 but got " + TickType.BID.index() );
?? ?}
?? ?if ( TickType.ASK.index() != 2 ) {
?? ???? throw new Error( "Expected TickType.ASK.index() == 2 but got " + TickType.ASK.index() );
?? ?}
}

public void tickPrice( int tickerId, int field, double price, TickAttrib attrib )
{
?? ?switch ( field ) {
?? ???? case 1:??? ??? //??? BID
?? ???? ??? ...
?? ???? ??? break;
?? ???? case 2:??? ??? //??? ASK
?? ???? ??? ...
?? ???? ??? break;

?? ???? ...
?? ?}
}

Join [email protected] to automatically receive all group messages.