@Test public void testInjective() throws NettyBsonReaderException { BsonType[] types = BsonType.values(); Map<Byte, BsonType> foundBytes = new HashMap<>(types.length); for (BsonType value : types) { byte asByte = ParsingTools.getByte(value); BsonType old = foundBytes.put(asByte, value); assertNull(old + " and " + value + " has the same associated byte (" + asByte + ")", old); } assert foundBytes.size() == types.length : "The invariant of the test has been broken"; }
protected static byte getByte(BsonType bsonType) throws NettyBsonReaderException { switch (bsonType) { case DOUBLE: return 0x01; case STRING: return 0x02; case DOCUMENT: return 0x03; case ARRAY: return 0x04; case BINARY: return 0x05; case UNDEFINED: return 0x06; case OBJECT_ID: return 0x07; case BOOLEAN: return 0x08; case DATETIME: return 0x09; case NULL: return 0x0A; case REGEX: return 0x0B; case DB_POINTER: return 0x0C; case JAVA_SCRIPT: return 0x0D; case DEPRECATED: return 0x0E; case JAVA_SCRIPT_WITH_SCOPE: return 0x0F; case INT32: return 0x10; case TIMESTAMP: return 0x11; case INT64: return 0x12; case DECIMAL128: return 0x13; case MIN: return UnsignedBytes.MAX_VALUE; case MAX: return 0x7F; default: throw new NettyBsonReaderException("It is not defined the byte associated with the type " + bsonType); } }
ParsingTools { protected static byte getByte(BsonType bsonType) throws NettyBsonReaderException { switch (bsonType) { case DOUBLE: return 0x01; case STRING: return 0x02; case DOCUMENT: return 0x03; case ARRAY: return 0x04; case BINARY: return 0x05; case UNDEFINED: return 0x06; case OBJECT_ID: return 0x07; case BOOLEAN: return 0x08; case DATETIME: return 0x09; case NULL: return 0x0A; case REGEX: return 0x0B; case DB_POINTER: return 0x0C; case JAVA_SCRIPT: return 0x0D; case DEPRECATED: return 0x0E; case JAVA_SCRIPT_WITH_SCOPE: return 0x0F; case INT32: return 0x10; case TIMESTAMP: return 0x11; case INT64: return 0x12; case DECIMAL128: return 0x13; case MIN: return UnsignedBytes.MAX_VALUE; case MAX: return 0x7F; default: throw new NettyBsonReaderException("It is not defined the byte associated with the type " + bsonType); } } }
ParsingTools { protected static byte getByte(BsonType bsonType) throws NettyBsonReaderException { switch (bsonType) { case DOUBLE: return 0x01; case STRING: return 0x02; case DOCUMENT: return 0x03; case ARRAY: return 0x04; case BINARY: return 0x05; case UNDEFINED: return 0x06; case OBJECT_ID: return 0x07; case BOOLEAN: return 0x08; case DATETIME: return 0x09; case NULL: return 0x0A; case REGEX: return 0x0B; case DB_POINTER: return 0x0C; case JAVA_SCRIPT: return 0x0D; case DEPRECATED: return 0x0E; case JAVA_SCRIPT_WITH_SCOPE: return 0x0F; case INT32: return 0x10; case TIMESTAMP: return 0x11; case INT64: return 0x12; case DECIMAL128: return 0x13; case MIN: return UnsignedBytes.MAX_VALUE; case MAX: return 0x7F; default: throw new NettyBsonReaderException("It is not defined the byte associated with the type " + bsonType); } }  }
ParsingTools { protected static byte getByte(BsonType bsonType) throws NettyBsonReaderException { switch (bsonType) { case DOUBLE: return 0x01; case STRING: return 0x02; case DOCUMENT: return 0x03; case ARRAY: return 0x04; case BINARY: return 0x05; case UNDEFINED: return 0x06; case OBJECT_ID: return 0x07; case BOOLEAN: return 0x08; case DATETIME: return 0x09; case NULL: return 0x0A; case REGEX: return 0x0B; case DB_POINTER: return 0x0C; case JAVA_SCRIPT: return 0x0D; case DEPRECATED: return 0x0E; case JAVA_SCRIPT_WITH_SCOPE: return 0x0F; case INT32: return 0x10; case TIMESTAMP: return 0x11; case INT64: return 0x12; case DECIMAL128: return 0x13; case MIN: return UnsignedBytes.MAX_VALUE; case MAX: return 0x7F; default: throw new NettyBsonReaderException("It is not defined the byte associated with the type " + bsonType); } }   }
ParsingTools { protected static byte getByte(BsonType bsonType) throws NettyBsonReaderException { switch (bsonType) { case DOUBLE: return 0x01; case STRING: return 0x02; case DOCUMENT: return 0x03; case ARRAY: return 0x04; case BINARY: return 0x05; case UNDEFINED: return 0x06; case OBJECT_ID: return 0x07; case BOOLEAN: return 0x08; case DATETIME: return 0x09; case NULL: return 0x0A; case REGEX: return 0x0B; case DB_POINTER: return 0x0C; case JAVA_SCRIPT: return 0x0D; case DEPRECATED: return 0x0E; case JAVA_SCRIPT_WITH_SCOPE: return 0x0F; case INT32: return 0x10; case TIMESTAMP: return 0x11; case INT64: return 0x12; case DECIMAL128: return 0x13; case MIN: return UnsignedBytes.MAX_VALUE; case MAX: return 0x7F; default: throw new NettyBsonReaderException("It is not defined the byte associated with the type " + bsonType); } }    }