@Override public Map<Key<?>, Binding<?>> getBindings() { return this.delegateInjector.getBindings(); }
/** * Returns the binding for the given key or null if there is no such binding */ public static Binding<?> getBinding(Injector injector, Key<?> key) { Map<Key<?>, Binding<?>> bindings = injector.getBindings(); Binding<?> binding = bindings.get(key); return binding; }
/** * Returns a collection of all bindings of the given base type * * @param baseClass the base type of objects required * @return a set of objects returned from this injector */ public static Set<Binding<?>> getBindingsOf(Injector injector, Class<?> baseClass) { Set<Binding<?>> answer = Sets.newHashSet(); Set<Entry<Key<?>, Binding<?>>> entries = injector.getBindings().entrySet(); for (Entry<Key<?>, Binding<?>> entry : entries) { Key<?> key = entry.getKey(); Class<?> keyType = getKeyType(key); if (keyType != null && baseClass.isAssignableFrom(keyType)) { answer.add(entry.getValue()); } } return answer; }
/** * Returns a collection of all providers of the given base type * * @param baseClass the base type of objects required * @param <T> the base type * @return a set of objects returned from this injector */ public static <T> Set<Provider<T>> getProvidersOf(Injector injector, Class<T> baseClass) { Set<Provider<T>> answer = Sets.newHashSet(); Set<Entry<Key<?>, Binding<?>>> entries = injector.getBindings().entrySet(); for (Entry<Key<?>, Binding<?>> entry : entries) { Key<?> key = entry.getKey(); Class<?> keyType = getKeyType(key); if (keyType != null && baseClass.isAssignableFrom(keyType)) { Binding<?> binding = entry.getValue(); answer.add((Provider<T>) binding.getProvider()); } } return answer; }
/** * Returns a collection of all of the bindings matching the given matcher * * @param matcher matches the types to return instances * @return a set of objects returned from this injector */ public static Set<Binding<?>> getBindingsOf(Injector injector, Matcher<Class> matcher) { Set<Binding<?>> answer = Sets.newHashSet(); Set<Entry<Key<?>, Binding<?>>> entries = injector.getBindings().entrySet(); for (Entry<Key<?>, Binding<?>> entry : entries) { Key<?> key = entry.getKey(); Class<?> keyType = getKeyType(key); if (keyType != null && matcher.matches(keyType)) { answer.add(entry.getValue()); } } return answer; }
/** * Returns a collection of all instances of the given base type * * @param baseClass the base type of objects required * @param <T> the base type * @return a set of objects returned from this injector */ public static <T> Set<T> getInstancesOf(Injector injector, Class<T> baseClass) { Set<T> answer = Sets.newHashSet(); Set<Entry<Key<?>, Binding<?>>> entries = injector.getBindings().entrySet(); for (Entry<Key<?>, Binding<?>> entry : entries) { Key<?> key = entry.getKey(); Class<?> keyType = getKeyType(key); if (keyType != null && baseClass.isAssignableFrom(keyType)) { Binding<?> binding = entry.getValue(); Object value = binding.getProvider().get(); if (value != null) { T castValue = baseClass.cast(value); answer.add(castValue); } } } return answer; }
/** * Returns a collection of all of the providers matching the given matcher * * @param matcher matches the types to return instances * @return a set of objects returned from this injector */ public static <T> Set<Provider<T>> getProvidersOf(Injector injector, Matcher<Class> matcher) { Set<Provider<T>> answer = Sets.newHashSet(); Set<Entry<Key<?>, Binding<?>>> entries = injector.getBindings().entrySet(); for (Entry<Key<?>, Binding<?>> entry : entries) { Key<?> key = entry.getKey(); Class<?> keyType = getKeyType(key); if (keyType != null && matcher.matches(keyType)) { Binding<?> binding = entry.getValue(); answer.add((Provider<T>) binding.getProvider()); } } return answer; }
/** * Returns a collection of all instances matching the given matcher * * @param matcher matches the types to return instances * @return a set of objects returned from this injector */ public static <T> Set<T> getInstancesOf(Injector injector, Matcher<Class> matcher) { Set<T> answer = Sets.newHashSet(); Set<Entry<Key<?>, Binding<?>>> entries = injector.getBindings().entrySet(); for (Entry<Key<?>, Binding<?>> entry : entries) { Key<?> key = entry.getKey(); Class<?> keyType = getKeyType(key); if (keyType != null && matcher.matches(keyType)) { Binding<?> binding = entry.getValue(); Object value = binding.getProvider().get(); answer.add((T) value); } } return answer; }