private static int bitMask( LongerShortString[] encoders ) { int result = 0; for ( LongerShortString encoder : encoders ) { result |= encoder.bitMask(); } return result; }
static int invertedBitMask( LongerShortString... encoders ) { return ~bitMask( encoders ); }
private static boolean tryEncode( int encodings, int keyId, PropertyBlock target, int payloadSize, byte[] data, final int length ) { // find encoders in order that are still selected and try to encode the data for ( LongerShortString encoding : ENCODINGS ) { if ( (encoding.bitMask() & encodings) == 0 ) { continue; } if ( encoding.doEncode( keyId, data, target, payloadSize, length ) ) { return true; } } return false; }
@Test public void testMasks() { assertEquals( 0, 1 & LongerShortString.invertedBitMask( LongerShortString.NUMERICAL ) ); assertEquals( 0, 2 & LongerShortString.invertedBitMask( LongerShortString.DATE ) ); assertEquals( LongerShortString.NUMERICAL.bitMask(), 3 & LongerShortString.invertedBitMask( LongerShortString.DATE ) ); assertEquals( 0, LongerShortString.NUMERICAL.bitMask() & LongerShortString.invertedBitMask( LongerShortString.NUMERICAL, LongerShortString.DATE ) ); }
private static int bitMask( LongerShortString[] encoders ) { int result = 0; for ( LongerShortString encoder : encoders ) { result |= encoder.bitMask(); } return result; }
static int invertedBitMask( LongerShortString... encoders ) { return ~bitMask( encoders ); }
private static boolean tryEncode( int encodings, int keyId, PropertyBlock target, int payloadSize, byte[] data, final int length ) { // find encoders in order that are still selected and try to encode the data for ( LongerShortString encoding : ENCODINGS ) { if ( (encoding.bitMask() & encodings) == 0 ) { continue; } if ( encoding.doEncode( keyId, data, target, payloadSize, length ) ) { return true; } } return false; }