Exemplo n.º 1
0
  /**
   * Filters a Collection of <code>Class</code> objects. The returned collection only contains those
   * classes that have an attribute of the specified type. That is, for each Class clazz in the
   * returned collection, <code>clazz != null && Attributes.hasAttributeType (clazz, attributeClass)
   * </code> is true.
   *
   * @param classes Collection of Classes to filter. May contain <code>null</code> references, but
   *     may not itself be <code>null</code>.
   * @param attributeClass the class to filter based on.
   * @since 2.1
   */
  public static Collection getClassesWithAttributeType(Collection classes, Class attributeClass) {
    if (classes == null) {
      throw new NullPointerException("classes");
    }

    if (attributeClass == null) {
      throw new NullPointerException("attributeClass");
    }

    ArrayList result = new ArrayList();
    Iterator iter = classes.iterator();
    while (iter.hasNext()) {
      Class clazz = (Class) iter.next();
      if (clazz != null) {
        if (Attributes.hasAttributeType(clazz, attributeClass)) {
          result.add(clazz);
        }
      }
    }

    return result;
  }
Exemplo n.º 2
0
  /**
   * Filters a collection of objects. The returned collection only contains those objects whose
   * class have an attribute of the specified type. That is, for each Object o in the returned
   * collection, <code>o != null && Attributes.hasAttributeType (o.getClass (), attributeClass)
   * </code> is true.
   *
   * @param objects Collection of objects to filter. May contain <code>null</code> references, but
   *     may not itself be <code>null</code>.
   * @param attributeClass the class to filter based on.
   * @since 2.1
   */
  public static Collection getObjectsWithAttributeType(Collection objects, Class attributeClass) {
    if (objects == null) {
      throw new NullPointerException("objects");
    }

    if (attributeClass == null) {
      throw new NullPointerException("attributeClass");
    }

    ArrayList result = new ArrayList();
    Iterator iter = objects.iterator();
    while (iter.hasNext()) {
      Object object = iter.next();
      if (object != null) {
        Class clazz = object.getClass();
        if (Attributes.hasAttributeType(clazz, attributeClass)) {
          result.add(object);
        }
      }
    }

    return result;
  }