Example usage for java.lang.reflect Modifier isAbstract

List of usage examples for java.lang.reflect Modifier isAbstract

Introduction

In this page you can find the example usage for java.lang.reflect Modifier isAbstract.

Prototype

public static boolean isAbstract(int mod) 

Source Link

Document

Return true if the integer argument includes the abstract modifier, false otherwise.

Usage

From source file:game.utils.Utils.java

public static boolean isConcrete(Class type) {
    return type.isPrimitive()
            || (!Modifier.isAbstract(type.getModifiers()) && !Modifier.isInterface(type.getModifiers()));
}

From source file:SampleModifier.java

public static void printModifiers(Object o) {
    Class c = o.getClass();//w  w  w  .j a  va2  s  . c o m
    int m = c.getModifiers();
    if (Modifier.isPublic(m))
        System.out.println("public");
    if (Modifier.isAbstract(m))
        System.out.println("abstract");
    if (Modifier.isFinal(m))
        System.out.println("final");
}

From source file:org.jiemamy.utils.reflect.ModifierUtil.java

/**
 * {@code abstract}??????// w  w  w .  j  av  a2 s  . co  m
 * 
 * @param clazz 
 * @return {@code abstract}????{@code true}?????????{@code false}
 * @throws IllegalArgumentException ?{@code null}???
 */
public static boolean isAbstract(Class<?> clazz) {
    Validate.notNull(clazz);
    return Modifier.isAbstract(clazz.getModifiers());
}

From source file:Main.java

/**
 * Converts the given array to a set with the given type. Works like
 * {@link Arrays#asList(Object...)}.//from  w  w  w  .j a v a  2  s.  c  om
 *
 * @param <T>
 *            The type of the set values.
 * @param setType
 *            The set type to return.
 * @param arr
 *            The array to convert into a set.
 * @return An object of the given set or, if, and only if, an error
 *         occurred, <code>null</code>.
 */
@SuppressWarnings("unchecked")
public static <T> Set<T> toSet(@SuppressWarnings("rawtypes") final Class<? extends Set> setType,
        final T... arr) {
    assert setType != null : "SetType cannot be null!";
    assert !Modifier.isAbstract(setType.getModifiers()) : "SetType cannot be abstract!";
    assert !setType.isInterface() : "SetType cannot be an interface!";
    assert arr != null : "Arr cannot be null!";

    Set<T> result = null;
    try {
        result = setType.newInstance();

        for (final T t : arr) {
            result.add(t);
        }
    } catch (final InstantiationException ex) {
        ex.printStackTrace();
    } catch (final IllegalAccessException ex) {
        ex.printStackTrace();
    }

    return result;
}

From source file:therian.Operation.java

private static boolean init(Class<?> type) {
    final boolean valid;
    synchronized (type) {
        if (VALID_INFO.containsKey(type)) {
            valid = VALID_INFO.get(type).booleanValue();
        } else if (Modifier.isAbstract(type.getModifiers())) {
            valid = true;/*from  www.ja v  a2  s  .  c  om*/
        } else {
            final Type resultType = TypeUtils.unrollVariables(TypeUtils.getTypeArguments(type, Operation.class),
                    TYPE_VARIABLE_RESULT);
            valid = !TypeUtils.containsTypeVariables(resultType);
            Validate.isTrue(valid, "%s does not fully bind type parameter %s from %s", type,
                    TYPE_VARIABLE_RESULT.getName(), Operation.class);
            VALID_INFO.put(type, Boolean.valueOf(valid));
        }
    }

    final Class<?> parent = type.getSuperclass();
    if (!Operation.class.equals(parent)) {
        init(parent.asSubclass(Operation.class));
    }
    return valid;
}

From source file:org.lunarray.model.descriptor.creational.util.CreationalScanUtil.java

/**
 * Find a no-args public constructor.//from w  ww .j  a v  a 2s  .co m
 * 
 * @param source
 *            The source class. May not be null.
 * @return The constructor, or null.
 * @param <E>
 *            The entity type.
 */
@SuppressWarnings("unchecked")
public static <E> Constructor<E> findConstructor(final Class<E> source) {
    Validate.notNull(source, "Source may not be null.");
    Constructor<E> result = null;
    if (!Modifier.isAbstract(source.getModifiers()) && !source.isSynthetic()) {
        for (final Constructor<E> constructor : (Constructor<E>[]) source.getConstructors()) {
            if (!constructor.isSynthetic() && (constructor.getParameterTypes().length == 0)) {
                result = constructor;
            }
        }
    }
    return result;
}

From source file:org.apache.tajo.ws.rs.resources.outputs.RestOutputFactory.java

private static Map<String, String> load() {
    Map<String, String> outputClasses = Maps.newHashMap();
    Set<Class> restOutputClasses = ClassUtil.findClasses(AbstractStreamingOutput.class,
            "org.apache.tajo.ws.rs.resources.outputs");

    for (Class eachClass : restOutputClasses) {
        if (eachClass.isInterface() || Modifier.isAbstract(eachClass.getModifiers())) {
            continue;
        }//from  w w  w  .j a  v  a2  s.  c  o  m

        AbstractStreamingOutput streamingOutput = null;
        try {
            streamingOutput = (AbstractStreamingOutput) eachClass
                    .getDeclaredConstructor(
                            new Class[] { NonForwardQueryResultScanner.class, Integer.class, Integer.class })
                    .newInstance(null, 0, 0);
        } catch (Exception e) {
            LOG.warn(eachClass + " cannot instantiate Function class because of " + e.getMessage(), e);
            continue;
        }
        String className = streamingOutput.getClass().getCanonicalName();
        String headerType = streamingOutput.getClass().getAnnotation(RestReturnType.class).mimeType();

        if (StringUtils.isNotEmpty(headerType)) {
            outputClasses.put(headerType, className);
        }
    }

    return outputClasses;
}

From source file:org.jiemamy.utils.reflect.ModifierUtil.java

/**
 * {@code abstract}??????//from   w  w w  .ja v a  2  s. co  m
 * 
 * @param method 
 * @return {@code abstract}???{@code true}?????????{@code false}
 * @throws IllegalArgumentException ?{@code null}???
 */
public static boolean isAbstract(Method method) {
    Validate.notNull(method);
    int mod = method.getModifiers();
    return Modifier.isAbstract(mod);
}

From source file:alluxio.cli.CommandUtils.java

/**
 * Get instances of all subclasses of {@link Command} in a sub-package called "command" the given
 * package./* www  . j  av  a2 s . c om*/
 *
 * @param pkgName package prefix to look in
 * @param classArgs type of args to instantiate the class
 * @param objectArgs args to instantiate the class
 * @return a mapping from command name to command instance
 */
public static Map<String, Command> loadCommands(String pkgName, Class[] classArgs, Object[] objectArgs) {
    Map<String, Command> commandsMap = new HashMap<>();
    Reflections reflections = new Reflections(Command.class.getPackage().getName());
    for (Class<? extends Command> cls : reflections.getSubTypesOf(Command.class)) {
        // Add commands from <pkgName>.command.*
        if (cls.getPackage().getName().equals(pkgName + ".command")
                && !Modifier.isAbstract(cls.getModifiers())) {
            // Only instantiate a concrete class
            Command cmd = CommonUtils.createNewClassInstance(cls, classArgs, objectArgs);
            commandsMap.put(cmd.getCommandName(), cmd);
        }
    }
    return commandsMap;
}

From source file:jenkins.scm.api.MethodUtils.java

/**
 * Checks if the method is abstract or not.
 * @param clazz the class./*  w w w .j a  v a 2  s.c  o  m*/
 * @param methodName the method name.
 * @param parameterTypes the parameter types.
 * @return {@code true} if the method does not exist or is abstract.
 */
static boolean isAbstract(Class<?> clazz, String methodName, Class<?>... parameterTypes) {
    Method m = getMethodImpl(clazz, methodName, parameterTypes);
    return m == null || Modifier.isAbstract(m.getModifiers());
}