/** * Create a new default factory with an expected number of registered * classes and an interface provider. The interface provider is used when * registering an implementation without a specified interface {@link * #register(Class)}. * * @param interfaceProvider provides the interfaces of a given * implementation class * @param n the expected number of constructors that will be * stored. * @see #DynamicFactory(int) */ public DynamicFactory(InterfaceProvider interfaceProvider, int n) { if (n < 0) throw new IllegalArgumentException("cannot create factory with negative size"); if (interfaceProvider == null) throw new IllegalArgumentException("null interface provider"); this.interfaceProvider = interfaceProvider; int size = n > 3 ? n + n / 3 : n + 1; // double for the cache to account for subclass constructor caching // (e.g. Atom(Atom) -> Atom(Element) cache = new HashMap<ConstructorKey, Creator<?>>(size * 2); lookup = new ConstructorLookup(size); }
/** * Create a new default factory with an expected number of registered * classes and an interface provider. The interface provider is used when * registering an implementation without a specified interface {@link * #register(Class)}. * * @param interfaceProvider provides the interfaces of a given * implementation class * @param n the expected number of constructors that will be * stored. * @see #DynamicFactory(int) */ public DynamicFactory(InterfaceProvider interfaceProvider, int n) { if (n < 0) throw new IllegalArgumentException("cannot create factory with negative size"); if (interfaceProvider == null) throw new IllegalArgumentException("null interface provider"); this.interfaceProvider = interfaceProvider; int size = n > 3 ? n + n / 3 : n + 1; // double for the cache to account for subclass constructor caching // (e.g. Atom(Atom) -> Atom(Element) cache = new HashMap<ConstructorKey, Creator<?>>(size * 2); lookup = new ConstructorLookup(size); }