/** * @throws Exception If failed. */ @Test public void testClassNamesSimpleNameMapper() throws Exception { checkClassNames(new BinaryBasicNameMapper(true), new BinaryBasicIdMapper(true)); }
/** * @param nameMapper Name mapper. * @param idMapper ID mapper. * @return Mapper. */ private static BinaryInternalMapper resolveMapper(BinaryNameMapper nameMapper, BinaryIdMapper idMapper) { if ((nameMapper == null || (DFLT_MAPPER.nameMapper().equals(nameMapper))) && (idMapper == null || DFLT_MAPPER.idMapper().equals(idMapper))) return DFLT_MAPPER; if (nameMapper != null && nameMapper instanceof BinaryBasicNameMapper && ((BinaryBasicNameMapper)nameMapper).isSimpleName() && idMapper != null && idMapper instanceof BinaryBasicIdMapper && ((BinaryBasicIdMapper)idMapper).isLowerCase()) return SIMPLE_NAME_LOWER_CASE_MAPPER; if (nameMapper == null) nameMapper = DFLT_MAPPER.nameMapper(); if (idMapper == null) idMapper = DFLT_MAPPER.idMapper(); return new BinaryInternalMapper(nameMapper, idMapper, true); }
/** * Get type ID. * * @param typeName Type name. * @return Type ID. */ @Override public int typeId(String typeName) { A.notNull(typeName, "typeName"); int id = isLowerCase ? lowerCaseHashCode(typeName) : typeName.hashCode(); if (id != 0) return id; else { throw new BinaryObjectException("Binary ID mapper resolved type ID to zero " + "(either change type's name or use custom ID mapper) " + "[name=" + typeName + ", isLowerCase=" + isLowerCase + "]"); } }
/** * @throws Exception If failed. */ @Test public void testLowerCase() throws Exception { BinaryBasicIdMapper mapper = new BinaryBasicIdMapper(true); assertEquals(GridBinaryTestClass1.class.getName().toLowerCase().hashCode(), mapper.typeId(GridBinaryTestClass1.class.getName())); assertEquals((GridBinaryTestClass1.class.getName() + "$InnerClass").toLowerCase().hashCode(), mapper.typeId(GridBinaryTestClass1.class.getName() + "$InnerClass")); }
/** * @throws Exception If failed. */ @Test public void testDefaultCase() throws Exception { BinaryBasicIdMapper mapper = new BinaryBasicIdMapper(false); assertEquals(GridBinaryTestClass1.class.getName().hashCode(), mapper.typeId(GridBinaryTestClass1.class.getName())); assertEquals((GridBinaryTestClass1.class.getName() + "$InnerClass").hashCode(), mapper.typeId(GridBinaryTestClass1.class.getName() + "$InnerClass")); } }
/** * @throws Exception If failed. */ @Test public void testTypeConfigurationsFullNameIdMapper() throws Exception { checkTypeConfigurations(new BinaryBasicNameMapper(false), new BinaryBasicIdMapper(false)); }
/** * Get field ID. * * @param typeId Type ID. * @param fieldName Field name. * @return Field ID. */ @Override public int fieldId(int typeId, String fieldName) { A.notNull(fieldName, "fieldName"); int id = isLowerCase ? lowerCaseHashCode(fieldName) : fieldName.hashCode(); if (id != 0) return id; else { throw new BinaryObjectException("Binary ID mapper resolved field ID to zero " + "(either change filed's name or use custom ID mapper) " + "[name=" + fieldName + ", isLowerCase=" + isLowerCase + "]"); } }
/** * @param nameMapper Name mapper. * @param idMapper ID mapper. * @return Mapper. */ private static BinaryInternalMapper resolveMapper(BinaryNameMapper nameMapper, BinaryIdMapper idMapper) { if ((nameMapper == null || (DFLT_MAPPER.nameMapper().equals(nameMapper))) && (idMapper == null || DFLT_MAPPER.idMapper().equals(idMapper))) return DFLT_MAPPER; if (nameMapper != null && nameMapper instanceof BinaryBasicNameMapper && ((BinaryBasicNameMapper)nameMapper).isSimpleName() && idMapper != null && idMapper instanceof BinaryBasicIdMapper && ((BinaryBasicIdMapper)idMapper).isLowerCase()) return SIMPLE_NAME_LOWER_CASE_MAPPER; if (nameMapper == null) nameMapper = DFLT_MAPPER.nameMapper(); if (idMapper == null) idMapper = DFLT_MAPPER.idMapper(); return new BinaryInternalMapper(nameMapper, idMapper, true); }
/** * @throws Exception If failed. */ @Test public void testOverrideNameMapperSimpleNameMapper() throws Exception { checkOverrideNameMapper(new BinaryBasicNameMapper(true), new BinaryBasicIdMapper(true)); }
/** * Get type ID. * * @param typeName Type name. * @return Type ID. */ @Override public int typeId(String typeName) { A.notNull(typeName, "typeName"); int id = isLowerCase ? lowerCaseHashCode(typeName) : typeName.hashCode(); if (id != 0) return id; else { throw new BinaryObjectException("Binary ID mapper resolved type ID to zero " + "(either change type's name or use custom ID mapper) " + "[name=" + typeName + ", isLowerCase=" + isLowerCase + "]"); } }
/** * @throws Exception If failed. */ @Test public void testClassNamesJarFullNameMapper() throws Exception { checkClassNamesJar(new BinaryBasicNameMapper(false), new BinaryBasicIdMapper(false)); }
/** * Get field ID. * * @param typeId Type ID. * @param fieldName Field name. * @return Field ID. */ @Override public int fieldId(int typeId, String fieldName) { A.notNull(fieldName, "fieldName"); int id = isLowerCase ? lowerCaseHashCode(fieldName) : fieldName.hashCode(); if (id != 0) return id; else { throw new BinaryObjectException("Binary ID mapper resolved field ID to zero " + "(either change filed's name or use custom ID mapper) " + "[name=" + fieldName + ", isLowerCase=" + isLowerCase + "]"); } }
/** * @throws Exception If failed. */ @Test public void testClassNamesJarSimpleNameMapper() throws Exception { checkClassNamesJar(new BinaryBasicNameMapper(true), new BinaryBasicIdMapper(true)); }
/** * @throws Exception If failed. */ @Test public void testClassNamesFullNameMapper() throws Exception { checkClassNames(new BinaryBasicNameMapper(false), new BinaryBasicIdMapper(false)); }
/** * @throws Exception If failed. */ @Test public void testClassNamesMixedMappers() throws Exception { checkClassNames(new BinaryBasicNameMapper(false), new BinaryBasicIdMapper(true)); }
/** * @throws Exception If failed. */ @Test public void testTypeConfigurationsJarSimpleNameMapper() throws Exception { checkTypeConfigurationJar(new BinaryBasicNameMapper(true), new BinaryBasicIdMapper(true)); }
/** * @throws Exception If failed. */ @Test public void testOverrideJarFullNameMapper() throws Exception { checkOverrideJar(new BinaryBasicNameMapper(false), new BinaryBasicIdMapper(false)); }
/** * @throws Exception If failed. */ @Test public void testTypeConfigurationsSimpleNameIdMapper() throws Exception { checkTypeConfigurations(new BinaryBasicNameMapper(true), new BinaryBasicIdMapper(true)); }
/** * @throws Exception If failed. */ @Test public void testOverrideIdMapperFullNameMapper() throws Exception { checkOverrideNameMapper(new BinaryBasicNameMapper(false), new BinaryBasicIdMapper(false)); }
/** * @throws Exception If failed. */ @Test public void testOverrideIdMapperSimpleNameMapper() throws Exception { checkOverrideNameMapper(new BinaryBasicNameMapper(true), new BinaryBasicIdMapper(true)); }