org.reflections.Store.getAll()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(14.1k)|赞(0)|评价(0)|浏览(140)

本文整理了Java中org.reflections.Store.getAll()方法的一些代码示例,展示了Store.getAll()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Store.getAll()方法的具体详情如下:
包路径:org.reflections.Store
类名称:Store
方法名:getAll

Store.getAll介绍

[英]recursively get the values stored for the given index and keys, not including keys
[中]递归地获取为给定索引和键(不包括键)存储的值

代码示例

代码示例来源:origin: ronmamo/reflections

/** get all types scanned. this is effectively similar to getting all subtypes of Object.
 * <p>depends on SubTypesScanner configured with {@code SubTypesScanner(false)}, otherwise {@code ReflectionsException} is thrown
 * <p><i>note using this might be a bad practice. it is better to get types matching some criteria,
 * such as {@link #getSubTypesOf(Class)} or {@link #getTypesAnnotatedWith(Class)}</i>
 * @return Set of String, and not of Class, in order to avoid definition of all types in PermGen
 */
public Set<String> getAllTypes() {
  Set<String> allTypes = Sets.newHashSet(store.getAll(index(SubTypesScanner.class), Object.class.getName()));
  if (allTypes.isEmpty()) {
    throw new ReflectionsException("Couldn't find subtypes of Object. " +
        "Make sure SubTypesScanner initialized to include Object class - new SubTypesScanner(false)");
  }
  return allTypes;
}

代码示例来源:origin: org.reflections/reflections

/** get all types scanned. this is effectively similar to getting all subtypes of Object.
 * <p>depends on SubTypesScanner configured with {@code SubTypesScanner(false)}, otherwise {@code ReflectionsException} is thrown
 * <p><i>note using this might be a bad practice. it is better to get types matching some criteria,
 * such as {@link #getSubTypesOf(Class)} or {@link #getTypesAnnotatedWith(Class)}</i>
 * @return Set of String, and not of Class, in order to avoid definition of all types in PermGen
 */
public Set<String> getAllTypes() {
  Set<String> allTypes = Sets.newHashSet(store.getAll(index(SubTypesScanner.class), Object.class.getName()));
  if (allTypes.isEmpty()) {
    throw new ReflectionsException("Couldn't find subtypes of Object. " +
        "Make sure SubTypesScanner initialized to include Object class - new SubTypesScanner(false)");
  }
  return allTypes;
}

代码示例来源:origin: ronmamo/reflections

/**
 * gets all sub types in hierarchy of a given type
 * <p/>depends on SubTypesScanner configured
 */
public <T> Set<Class<? extends T>> getSubTypesOf(final Class<T> type) {
  return Sets.newHashSet(ReflectionUtils.<T>forNames(
      store.getAll(index(SubTypesScanner.class), Arrays.asList(type.getName())), loaders()));
}

代码示例来源:origin: org.reflections/reflections

/**
 * gets all sub types in hierarchy of a given type
 * <p/>depends on SubTypesScanner configured
 */
public <T> Set<Class<? extends T>> getSubTypesOf(final Class<T> type) {
  return Sets.newHashSet(ReflectionUtils.<T>forNames(
      store.getAll(index(SubTypesScanner.class), Arrays.asList(type.getName())), loaders()));
}

代码示例来源:origin: ronmamo/reflections

protected Iterable<String> getAllAnnotated(Iterable<String> annotated, boolean inherited, boolean honorInherited) {
  if (honorInherited) {
    if (inherited) {
      Iterable<String> subTypes = store.get(index(SubTypesScanner.class), filter(annotated, new Predicate<String>() {
        public boolean apply(@Nullable String input) {
          final Class<?> type = forName(input, loaders());
          return type != null && !type.isInterface();
        }
      }));
      return concat(subTypes, store.getAll(index(SubTypesScanner.class), subTypes));
    } else {
      return annotated;
    }
  } else {
    Iterable<String> subTypes = concat(annotated, store.getAll(index(TypeAnnotationsScanner.class), annotated));
    return concat(subTypes, store.getAll(index(SubTypesScanner.class), subTypes));
  }
}

代码示例来源:origin: org.reflections/reflections

protected Iterable<String> getAllAnnotated(Iterable<String> annotated, boolean inherited, boolean honorInherited) {
  if (honorInherited) {
    if (inherited) {
      Iterable<String> subTypes = store.get(index(SubTypesScanner.class), filter(annotated, new Predicate<String>() {
        public boolean apply(@Nullable String input) {
          final Class<?> type = forName(input, loaders());
          return type != null && !type.isInterface();
        }
      }));
      return concat(subTypes, store.getAll(index(SubTypesScanner.class), subTypes));
    } else {
      return annotated;
    }
  } else {
    Iterable<String> subTypes = concat(annotated, store.getAll(index(TypeAnnotationsScanner.class), annotated));
    return concat(subTypes, store.getAll(index(SubTypesScanner.class), subTypes));
  }
}

代码示例来源:origin: org.rapidpm/rapidpm-dependencies-core-reflections

public Set<String> getAllTypes() {
 final String index = index(SubTypesScanner.class);
 final Iterable<String> storeAll = store.getAll(index , Object.class.getName());
 final Set<String> allTypes = StreamSupport
   .stream(storeAll.spliterator() , false)
   .collect(Collectors.toSet());
 if (allTypes.isEmpty()) {
  throw new ReflectionsException("Couldn't find subtypes of Object. " +
                  "Make sure SubTypesScanner initialized to include Object class - new SubTypesScanner(false)");
 }
 return allTypes;
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.reflections

/** get all types scanned. this is effectively similar to getting all subtypes of Object.
 * <p>depends on SubTypesScanner configured with {@code SubTypesScanner(false)}, otherwise {@code ReflectionsException} is thrown
 * <p><i>note using this might be a bad practice. it is better to get types matching some criteria,
 * such as {@link #getSubTypesOf(Class)} or {@link #getTypesAnnotatedWith(Class)}</i>
 * @return Set of String, and not of Class, in order to avoid definition of all types in PermGen
 */
public Set<String> getAllTypes() {
  Set<String> allTypes = Sets.newHashSet(store.getAll(index(SubTypesScanner.class), Object.class.getName()));
  if (allTypes.isEmpty()) {
    throw new ReflectionsException("Couldn't find subtypes of Object. " +
        "Make sure SubTypesScanner initialized to include Object class - new SubTypesScanner(false)");
  }
  return allTypes;
}

代码示例来源:origin: ai.h2o/reflections

/** get all types scanned. this is effectively similar to getting all subtypes of Object.
 * <p>depends on SubTypesScanner configured with {@code SubTypesScanner(false)}, otherwise {@code ReflectionsException} is thrown
 * <p><i>note using this might be a bad practice. it is better to get types matching some criteria,
 * such as {@link #getSubTypesOf(Class)} or {@link #getTypesAnnotatedWith(Class)}</i>
 * @return Set of String, and not of Class, in order to avoid definition of all types in PermGen
 */
public Set<String> getAllTypes() {
  Set<String> allTypes = Sets.newHashSet(store.getAll(index(SubTypesScanner.class), Object.class.getName()));
  if (allTypes.isEmpty()) {
    throw new ReflectionsException("Couldn't find subtypes of Object. " +
        "Make sure SubTypesScanner initialized to include Object class - new SubTypesScanner(false)");
  }
  return allTypes;
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.reflections

/**
 * gets all sub types in hierarchy of a given type
 * <p/>depends on SubTypesScanner configured
 */
public <T> Set<Class<? extends T>> getSubTypesOf(final Class<T> type) {
  return Sets.newHashSet(ReflectionUtils.<T>forNames(
      store.getAll(index(SubTypesScanner.class), Arrays.asList(type.getName())), loaders()));
}

代码示例来源:origin: ai.h2o/reflections

/**
 * gets all sub types in hierarchy of a given type
 * <p/>depends on SubTypesScanner configured
 */
public <T> Set<Class<? extends T>> getSubTypesOf(final Class<T> type) {
  return Sets.newHashSet(ReflectionUtils.<T>forNames(
      store.getAll(index(SubTypesScanner.class), Arrays.asList(type.getName())), loaders()));
}

代码示例来源:origin: eventsourcing/es4j

Set<Class<? extends T>> scan(Class<? extends T> aClass) {
  Configuration configuration = ConfigurationBuilder.build((Object[]) packages).addClassLoaders(classLoaders)
                           .addScanners(new AssignableScanner(aClass));
  Reflections reflections = new Reflections(configuration);
  Predicate<Class<? extends T>> classPredicate = klass ->
      Modifier.isPublic(klass.getModifiers()) &&
          (!klass.isMemberClass() || (klass.isMemberClass() && Modifier
              .isStatic(klass.getModifiers()))) &&
          !Modifier.isInterface(klass.getModifiers()) &&
          !Modifier.isAbstract(klass.getModifiers());
  HashSet<Class<? extends T>> subtypes = Sets.newHashSet(
      ReflectionUtils.forNames(
          reflections.getStore()
                .getAll(AssignableScanner.class.getSimpleName(),
                    Collections.singletonList(aClass.getName())), classLoaders));
  return subtypes.stream().filter(classPredicate).collect(Collectors.toSet());
}

代码示例来源:origin: org.deeplearning4j/deeplearning4j-play

private List<UIModule> getCustomUIModules(List<Class<?>> excludeClasses) {
  //Scan classpath for UI module instances, but ignore the 'excludeClasses' classes
  List<String> classNames = Collections.singletonList(UIModule.class.getName());
  Reflections reflections = new Reflections();
  org.reflections.Store store = reflections.getStore();
  Iterable<String> subtypesByName =
          store.getAll(org.reflections.scanners.SubTypesScanner.class.getSimpleName(), classNames);
  Set<? extends Class<?>> subtypeClasses = Sets.newHashSet(ReflectionUtils.forNames(subtypesByName));
  List<Class<?>> toCreate = new ArrayList<>();
  for (Class<?> c : subtypeClasses) {
    if (excludeClasses.contains(c))
      continue;;
    toCreate.add(c);
  }
  List<UIModule> ret = new ArrayList<>(toCreate.size());
  for (Class<?> c : toCreate) {
    UIModule m;
    try {
      m = (UIModule) c.newInstance();
    } catch (Exception e) {
      log.warn("Could not create instance of custom UIModule of type {}; skipping", c, e);
      continue;
    }
    log.debug("Created instance of custom UI module: {}", c);
    ret.add(m);
  }
  return ret;
}

代码示例来源:origin: org.rapidpm/rapidpm-dependencies-core-reflections

public <T> Set<Class<? extends T>> getSubTypesOf(final Class<T> type) {
 final Iterable<String> all = store.getAll(index(SubTypesScanner.class) , Arrays.asList(type.getName()));
 return new HashSet<>(ReflectionUtils.<T>forNames(all , loaders()));
}

代码示例来源:origin: org.deeplearning4j/deeplearning4j-play_2.10

private List<UIModule> getCustomUIModules(List<Class<?>> excludeClasses) {
  //Scan classpath for UI module instances, but ignore the 'excludeClasses' classes
  List<String> classNames = Collections.singletonList(UIModule.class.getName());
  Reflections reflections = new Reflections();
  org.reflections.Store store = reflections.getStore();
  Iterable<String> subtypesByName =
          store.getAll(org.reflections.scanners.SubTypesScanner.class.getSimpleName(), classNames);
  Set<? extends Class<?>> subtypeClasses = Sets.newHashSet(ReflectionUtils.forNames(subtypesByName));
  List<Class<?>> toCreate = new ArrayList<>();
  for (Class<?> c : subtypeClasses) {
    if (excludeClasses.contains(c))
      continue;;
    toCreate.add(c);
  }
  List<UIModule> ret = new ArrayList<>(toCreate.size());
  for (Class<?> c : toCreate) {
    UIModule m;
    try {
      m = (UIModule) c.newInstance();
    } catch (Exception e) {
      log.warn("Could not create instance of custom UIModule of type {}; skipping", c, e);
      continue;
    }
    log.debug("Created instance of custom UI module: {}", c);
    ret.add(m);
  }
  return ret;
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.reflections

protected Iterable<String> getAllAnnotated(Iterable<String> annotated, boolean inherited, boolean honorInherited) {
  if (honorInherited) {
    if (inherited) {
      Iterable<String> subTypes = store.get(index(SubTypesScanner.class), filter(annotated, new Predicate<String>() {
        public boolean apply(@Nullable String input) {
          final Class<?> type = forName(input, loaders());
          return type != null && !type.isInterface();
        }
      }));
      return concat(subTypes, store.getAll(index(SubTypesScanner.class), subTypes));
    } else {
      return annotated;
    }
  } else {
    Iterable<String> subTypes = concat(annotated, store.getAll(index(TypeAnnotationsScanner.class), annotated));
    return concat(subTypes, store.getAll(index(SubTypesScanner.class), subTypes));
  }
}

代码示例来源:origin: ai.h2o/reflections

protected Iterable<String> getAllAnnotated(Iterable<String> annotated, boolean inherited, boolean honorInherited) {
  if (honorInherited) {
    if (inherited) {
      Iterable<String> subTypes = store.get(index(SubTypesScanner.class), filter(annotated, new Predicate<String>() {
        public boolean apply(@Nullable String input) {
          return !ReflectionUtils.forName(input, loaders()).isInterface();
        }
      }));
      return concat(subTypes, store.getAll(index(SubTypesScanner.class), subTypes));
    } else {
      return annotated;
    }
  } else {
    Iterable<String> subTypes = concat(annotated, store.getAll(index(TypeAnnotationsScanner.class), annotated));
    return concat(subTypes, store.getAll(index(SubTypesScanner.class), subTypes));
  }
}

代码示例来源:origin: org.deeplearning4j/deeplearning4j-play_2.11

private List<UIModule> getCustomUIModules(List<Class<?>> excludeClasses) {
  //Scan classpath for UI module instances, but ignore the 'excludeClasses' classes
  List<String> classNames = Collections.singletonList(UIModule.class.getName());
  Reflections reflections = new Reflections();
  org.reflections.Store store = reflections.getStore();
  Iterable<String> subtypesByName =
          store.getAll(org.reflections.scanners.SubTypesScanner.class.getSimpleName(), classNames);
  Set<? extends Class<?>> subtypeClasses = Sets.newHashSet(ReflectionUtils.forNames(subtypesByName));
  List<Class<?>> toCreate = new ArrayList<>();
  for (Class<?> c : subtypeClasses) {
    if (excludeClasses.contains(c))
      continue;;
    toCreate.add(c);
  }
  List<UIModule> ret = new ArrayList<>(toCreate.size());
  for (Class<?> c : toCreate) {
    UIModule m;
    try {
      m = (UIModule) c.newInstance();
    } catch (Exception e) {
      log.warn("Could not create instance of custom UIModule of type {}; skipping", c, e);
      continue;
    }
    log.debug("Created instance of custom UI module: {}", c);
    ret.add(m);
  }
  return ret;
}

代码示例来源:origin: org.rapidpm/rapidpm-dependencies-core-reflections

protected Iterable<String> getAllAnnotated(Iterable<String> annotated , boolean inherited , boolean honorInherited) {
 if (honorInherited) {
  if (inherited) {
   Iterable<String> subTypes = store.get(index(SubTypesScanner.class) , filter(annotated , (Predicate<String>) input -> ! ReflectionUtils.forName(input , loaders()).isInterface()));
   return concat(subTypes , store.getAll(index(SubTypesScanner.class) , subTypes));
  } else {
   return annotated;
  }
 } else {
  Iterable<String> subTypes = concat(annotated , store.getAll(index(TypeAnnotationsScanner.class) , annotated));
  return concat(subTypes , store.getAll(index(SubTypesScanner.class) , subTypes));
 }
}

代码示例来源:origin: org.datavec/datavec-data-image

org.reflections.Store store = reflections.getStore();
Iterable<String> subtypesByName = store.getAll(DataVecSubTypesScanner.class.getSimpleName(), classNames);

相关文章