public void generate(Appendable appendable) throws IOException { int pos = this.fullyQualifiedName.lastIndexOf("."); String className; String packageName; if (pos > 0) { packageName = this.fullyQualifiedName.substring(0, pos); className = this.fullyQualifiedName.substring(pos + 1); } else { packageName = ""; className = this.fullyQualifiedName; } Builder classBuilder = TypeSpec.classBuilder(className); classBuilder.addModifiers(Modifier.PUBLIC, Modifier.FINAL); classBuilder.addSuperinterface(CodecProvider.class); addInstanceFields(classBuilder); addConstructor(classBuilder); addGetMethod(classBuilder); JavaFile javaFile = JavaFile.builder(packageName, classBuilder.build()).build(); javaFile.writeTo(appendable); }
@Test public void testMongoMapper() throws Exception { List<CodecProvider> providers = MongoMapper.getProviders(); Assert.assertFalse(providers.isEmpty()); int size = providers.size(); // Check for unmodifiable list. providers.add(new CustomFieldCodecProvider()); MongoMapper.addProvider(new CustomFieldCodecProvider()); providers = MongoMapper.getProviders(); Assert.assertEquals(size + 1, providers.size()); }
public static List<CodecProvider> getProviders() { return (ArrayList) providers.clone(); }
public static void addProvider(CodecProvider provider) { providers.add(provider); }