@Test public void testDecodePacketTypeCode() throws Exception { Field allPacketTypesField = I2PBotePacket.class.getDeclaredField("ALL_PACKET_TYPES"); allPacketTypesField.setAccessible(true); @SuppressWarnings("unchecked") Class<? extends I2PBotePacket>[] allPacketTypes = (Class<? extends I2PBotePacket>[])allPacketTypesField.get(null); for (Class<? extends I2PBotePacket> packetType: allPacketTypes) { TypeCode typeCode = packetType.getAnnotation(TypeCode.class); assertTrue(I2PBotePacket.decodePacketTypeCode(typeCode.value()).equals(packetType)); } }
protected static Class<? extends I2PBotePacket> decodePacketTypeCode(char packetTypeCode) { for (Class<? extends I2PBotePacket> packetType: ALL_PACKET_TYPES) if (packetType.getAnnotation(TypeCode.class).value() == packetTypeCode) return packetType; Log log = new Log(I2PBotePacket.class); log.debug("Invalid type code for I2PBotePacket: <" + packetTypeCode + ">"); return null; }
I2PBotePacket { protected static Class<? extends I2PBotePacket> decodePacketTypeCode(char packetTypeCode) { for (Class<? extends I2PBotePacket> packetType: ALL_PACKET_TYPES) if (packetType.getAnnotation(TypeCode.class).value() == packetTypeCode) return packetType; Log log = new Log(I2PBotePacket.class); log.debug("Invalid type code for I2PBotePacket: <" + packetTypeCode + ">"); return null; } }
I2PBotePacket { protected static Class<? extends I2PBotePacket> decodePacketTypeCode(char packetTypeCode) { for (Class<? extends I2PBotePacket> packetType: ALL_PACKET_TYPES) if (packetType.getAnnotation(TypeCode.class).value() == packetTypeCode) return packetType; Log log = new Log(I2PBotePacket.class); log.debug("Invalid type code for I2PBotePacket: <" + packetTypeCode + ">"); return null; } protected  I2PBotePacket(); protected  I2PBotePacket(int protocolVersion); }
I2PBotePacket { protected static Class<? extends I2PBotePacket> decodePacketTypeCode(char packetTypeCode) { for (Class<? extends I2PBotePacket> packetType: ALL_PACKET_TYPES) if (packetType.getAnnotation(TypeCode.class).value() == packetTypeCode) return packetType; Log log = new Log(I2PBotePacket.class); log.debug("Invalid type code for I2PBotePacket: <" + packetTypeCode + ">"); return null; } protected  I2PBotePacket(); protected  I2PBotePacket(int protocolVersion); static I2PBotePacket createPacket(File file); void writeTo(OutputStream outputStream); abstract byte[] toByteArray(); int getSize(); boolean isTooBig(); char getPacketTypeCode(); int getProtocolVersion(); boolean isProtocolVersionOk(); @Override String toString(); }
I2PBotePacket { protected static Class<? extends I2PBotePacket> decodePacketTypeCode(char packetTypeCode) { for (Class<? extends I2PBotePacket> packetType: ALL_PACKET_TYPES) if (packetType.getAnnotation(TypeCode.class).value() == packetTypeCode) return packetType; Log log = new Log(I2PBotePacket.class); log.debug("Invalid type code for I2PBotePacket: <" + packetTypeCode + ">"); return null; } protected  I2PBotePacket(); protected  I2PBotePacket(int protocolVersion); static I2PBotePacket createPacket(File file); void writeTo(OutputStream outputStream); abstract byte[] toByteArray(); int getSize(); boolean isTooBig(); char getPacketTypeCode(); int getProtocolVersion(); boolean isProtocolVersionOk(); @Override String toString(); static final int MAX_DATAGRAM_SIZE; }