CompoundKey extends Key { public static byte[] encode(byte[]... keyParts) { if ((keyParts.length == 0) || (keyParts.length > 255)) { throw new IllegalArgumentException( "The number of key pars needs to be greater than zero and less than or equal 255."); } int keySize = 1; for (byte[] keyPart : keyParts) { keySize += 4 + keyPart.length; } byte[] key = new byte[keySize]; key[0] = (byte) keyParts.length; int pos = 1; for (byte[] keyPart : keyParts) { System.arraycopy(Bytes.fromInt(keyPart.length), 0, key, pos, 4); pos += 4; System.arraycopy(keyPart, 0, key, pos, keyPart.length); pos += keyPart.length; } return key; } private  CompoundKey(boolean encoded, byte[]... keyParts); static byte[][] decode(byte[] key); static byte[] encode(byte[]... keyParts); static CompoundKey create(byte[]... keyParts); static CompoundKey of(byte[] compoundKey); static CompoundKey create(Key... keyParts); static CompoundKey of(Key compoundKey); int getPartNum(); byte[] getPart(int i);  }
@Test(expected = NullPointerException.class) public void testNullKeyParts() { CompoundKey.encode((byte[][]) null); }
@Test(expected = IllegalArgumentException.class) public void testEmptyKeyParts() { CompoundKey.encode(); }
@Test(expected = IllegalArgumentException.class) public void testTooManyKeyParts() { byte[][] keyParts = new byte[256][]; for (int i = 0; i < 256; ++i) { keyParts[i] = new byte[] { (byte) i }; } CompoundKey.encode(keyParts); }