org.jiemamy.utils.reflect.ModifierUtil.java Source code

Java tutorial

Introduction

Here is the source code for org.jiemamy.utils.reflect.ModifierUtil.java

Source

/*
 * Copyright 2007-2012 Jiemamy Project and the Others.
 *
 * This file is part of Jiemamy.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */
package org.jiemamy.utils.reflect;

import java.lang.reflect.Field;
import java.lang.reflect.Member;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

import org.apache.commons.lang.Validate;

/**
 * {@link Modifier}???
 * 
 * @version $Id$
 * @author j5ik2o
 */
public final class ModifierUtil {

    /**
     * {@code abstract}??????
     * 
     * @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());
    }

    /**
     * {@code abstract}??????
     * 
     * @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);
    }

    /**
     * {@code final}???????
     * 
     * @param member 
     * @return {@code final}????{@code true}?????????{@code false}
     * @throws IllegalArgumentException ?{@code null}???
     */
    public static boolean isFinal(Member member) {
        Validate.notNull(member);
        return Modifier.isFinal(member.getModifiers());
    }

    /**
     * ????????
     * 
     * @param member 
     * @return ?????{@code true}?????????{@code false}
     * @throws IllegalArgumentException ?{@code null}???
     */
    public static boolean isInstanceMember(Member member) {
        Validate.notNull(member);
        int mod = member.getModifiers();
        return Modifier.isStatic(mod) == false;
    }

    /**
     * {@code public}???????
     * 
     * @param member 
     * @return ????{@code true}?????????{@code false}
     * @throws IllegalArgumentException ?{@code null}???
     */
    public static boolean isPublic(Member member) {
        Validate.notNull(member);
        return Modifier.isPublic(member.getModifiers());
    }

    /**
     * {@code public},{@code static},{@code final}????{@code true}?????????{@code false}??
     * 
     * @param modifier ?
     * @return {@code public},{@code static},{@code final}????{@code true}?????????{@code false}
     */
    public static boolean isPublicStaticFinal(int modifier) {
        return Modifier.isPublic(modifier) && Modifier.isStatic(modifier) && Modifier.isFinal(modifier);
    }

    /**
     * {@code public},{@code static},{@code final}????{@code true}?????????{@code false}??
     * 
     * @param member 
     * @return {@code public},{@code static},{@code final}????{@code true}?????????{@code false}
     * @throws IllegalArgumentException ?{@code null}???
     */
    public static boolean isPublicStaticFinal(Member member) {
        Validate.notNull(member);
        return isPublicStaticFinal(member.getModifiers());
    }

    /**
     * {@code transient}????{@code true}?????????{@code false}??
     * 
     * @param field 
     * @return {@code transient}????{@code true}?????????{@code false}
     * @throws IllegalArgumentException ?{@code null}???
     */
    public static boolean isTransient(Field field) {
        Validate.notNull(field);
        return Modifier.isTransient(field.getModifiers());
    }

    private ModifierUtil() {
    }
}