示例#1
0
 /**
  * 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 = new HashSet<>();
   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;
 }
示例#2
0
 /**
  * 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 = new HashSet<>();
   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;
 }