Package io.microsphere.reflect
Class MemberUtils
- java.lang.Object
-
- io.microsphere.reflect.MemberUtils
-
-
Field Summary
Fields Modifier and Type Field Description static java.util.function.Predicate<? super java.lang.reflect.Member>FINAL_MEMBER_PREDICATEThePredicatereference toisFinal(Member)static java.util.function.Predicate<? super java.lang.reflect.Member>NON_PRIVATE_MEMBER_PREDICATEThePredicatereference toisNonPrivate(Member)static java.util.function.Predicate<? super java.lang.reflect.Member>NON_STATIC_MEMBER_PREDICATEThePredicatereference toisNonStatic(Member)static java.util.function.Predicate<? super java.lang.reflect.Member>PUBLIC_MEMBER_PREDICATEThePredicatereference toisPublic(Member)static java.util.function.Predicate<? super java.lang.reflect.Member>STATIC_MEMBER_PREDICATEThePredicatereference toisStatic(Member)
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.reflect.MemberasMember(java.lang.Object object)Attempts to cast the provided object to an instance ofMember.static booleanisAbstract(java.lang.reflect.Member member)Checks whether the specifiedMemberis declared asabstract.static booleanisFinal(java.lang.reflect.Member member)Checks whether the specifiedMemberis declared asfinal.static booleanisNonPrivate(java.lang.reflect.Member member)Checks whether the specifiedMemberis declared as non-private.static booleanisNonStatic(java.lang.reflect.Member member)Checks whether the specifiedMemberis declared as non-static.static booleanisPrivate(java.lang.reflect.Member member)Checks whether the specifiedMemberis declared asprivate.static booleanisPublic(java.lang.reflect.Member member)Checks whether the specifiedMemberis declared aspublic.static booleanisStatic(java.lang.reflect.Member member)Checks whether the specifiedMemberis declared asstatic.
-
-
-
Field Detail
-
STATIC_MEMBER_PREDICATE
public static final java.util.function.Predicate<? super java.lang.reflect.Member> STATIC_MEMBER_PREDICATE
ThePredicatereference toisStatic(Member)
-
NON_STATIC_MEMBER_PREDICATE
public static final java.util.function.Predicate<? super java.lang.reflect.Member> NON_STATIC_MEMBER_PREDICATE
ThePredicatereference toisNonStatic(Member)
-
FINAL_MEMBER_PREDICATE
public static final java.util.function.Predicate<? super java.lang.reflect.Member> FINAL_MEMBER_PREDICATE
ThePredicatereference toisFinal(Member)
-
PUBLIC_MEMBER_PREDICATE
public static final java.util.function.Predicate<? super java.lang.reflect.Member> PUBLIC_MEMBER_PREDICATE
ThePredicatereference toisPublic(Member)
-
NON_PRIVATE_MEMBER_PREDICATE
public static final java.util.function.Predicate<? super java.lang.reflect.Member> NON_PRIVATE_MEMBER_PREDICATE
ThePredicatereference toisNonPrivate(Member)
-
-
Method Detail
-
isStatic
public static boolean isStatic(java.lang.reflect.Member member)
Checks whether the specifiedMemberis declared asstatic.Example Usage
public class Example { static int staticField; int instanceField; static void staticMethod() {} void instanceMethod() {} } Field staticField = Example.class.getField("staticField"); boolean result1 = MemberUtils.isStatic(staticField); // true Field instanceField = Example.class.getField("instanceField"); boolean result2 = MemberUtils.isStatic(instanceField); // false Method staticMethod = Example.class.getMethod("staticMethod"); boolean result3 = MemberUtils.isStatic(staticMethod); // true Method instanceMethod = Example.class.getMethod("instanceMethod"); boolean result4 = MemberUtils.isStatic(instanceMethod); // false- Parameters:
member- theMemberinstance to check, such as aConstructor,Method, orField- Returns:
trueif the member is static;falseotherwise
-
isAbstract
public static boolean isAbstract(java.lang.reflect.Member member)
Checks whether the specifiedMemberis declared asabstract.Example Usage
public abstract class AbstractExample { abstract void abstractMethod(); } public class ConcreteExample extends AbstractExample { void abstractMethod() {} } Method abstractMethod = AbstractExample.class.getMethod("abstractMethod"); boolean result1 = MemberUtils.isAbstract(abstractMethod); // true Method concreteMethod = ConcreteExample.class.getMethod("abstractMethod"); boolean result2 = MemberUtils.isAbstract(concreteMethod); // false Class<AbstractExample> abstractClass = AbstractExample.class; boolean result3 = MemberUtils.isAbstract(abstractClass); // true Class<ConcreteExample> concreteClass = ConcreteExample.class; boolean result4 = MemberUtils.isAbstract(concreteClass); // false- Parameters:
member- theMemberinstance to check, such as aMethodorClass- Returns:
trueif the member is abstract;falseotherwise
-
isNonStatic
public static boolean isNonStatic(java.lang.reflect.Member member)
Checks whether the specifiedMemberis declared as non-static.Example Usage
public class Example { static int staticField; int instanceField; static void staticMethod() {} void instanceMethod() {} } Field staticField = Example.class.getField("staticField"); boolean result1 = MemberUtils.isNonStatic(staticField); // false Field instanceField = Example.class.getField("instanceField"); boolean result2 = MemberUtils.isNonStatic(instanceField); // true Method staticMethod = Example.class.getMethod("staticMethod"); boolean result3 = MemberUtils.isNonStatic(staticMethod); // false Method instanceMethod = Example.class.getMethod("instanceMethod"); boolean result4 = MemberUtils.isNonStatic(instanceMethod); // true- Parameters:
member- theMemberinstance to check, such as aConstructor,Method, orField- Returns:
trueif the member is non-static;falseotherwise
-
isFinal
public static boolean isFinal(java.lang.reflect.Member member)
Checks whether the specifiedMemberis declared asfinal.Example Usage
public class Example { final int finalField = 0; int nonFinalField; final void finalMethod() {} void nonFinalMethod() {} } Field finalField = Example.class.getField("finalField"); boolean result1 = MemberUtils.isFinal(finalField); // true Field nonFinalField = Example.class.getField("nonFinalField"); boolean result2 = MemberUtils.isFinal(nonFinalField); // false Method finalMethod = Example.class.getMethod("finalMethod"); boolean result3 = MemberUtils.isFinal(finalMethod); // true Method nonFinalMethod = Example.class.getMethod("nonFinalMethod"); boolean result4 = MemberUtils.isFinal(nonFinalMethod); // false- Parameters:
member- theMemberinstance to check, such as aConstructor,Method, orField- Returns:
trueif the member is final;falseotherwise
-
isPrivate
public static boolean isPrivate(java.lang.reflect.Member member)
Checks whether the specifiedMemberis declared asprivate.Example Usage
public class Example { private int privateField; int defaultField; private void privateMethod() {} void defaultMethod() {} } Field privateField = Example.class.getDeclaredField("privateField"); boolean result1 = MemberUtils.isPrivate(privateField); // true Field defaultField = Example.class.getField("defaultField"); boolean result2 = MemberUtils.isPrivate(defaultField); // false Method privateMethod = Example.class.getDeclaredMethod("privateMethod"); boolean result3 = MemberUtils.isPrivate(privateMethod); // true Method defaultMethod = Example.class.getMethod("defaultMethod"); boolean result4 = MemberUtils.isPrivate(defaultMethod); // false- Parameters:
member- theMemberinstance to check, such as aConstructor,Method, orField- Returns:
trueif the member is private;falseotherwise
-
isPublic
public static boolean isPublic(java.lang.reflect.Member member)
Checks whether the specifiedMemberis declared aspublic.Example Usage
public class Example { public int publicField; private void privateMethod() {} public void publicMethod() {} } Field publicField = Example.class.getField("publicField"); boolean result1 = MemberUtils.isPublic(publicField); // true Method privateMethod = Example.class.getDeclaredMethod("privateMethod"); boolean result2 = MemberUtils.isPublic(privateMethod); // false Method publicMethod = Example.class.getMethod("publicMethod"); boolean result3 = MemberUtils.isPublic(publicMethod); // true- Parameters:
member- theMemberinstance to check, such as aConstructor,Method, orField- Returns:
trueif the member is public;falseotherwise
-
isNonPrivate
public static boolean isNonPrivate(java.lang.reflect.Member member)
Checks whether the specifiedMemberis declared as non-private.Example Usage
public class Example { private int privateField; int defaultField; protected int protectedField; public int publicField; private void privateMethod() {} void defaultMethod() {} protected void protectedMethod() {} public void publicMethod() {} } Field privateField = Example.class.getDeclaredField("privateField"); boolean result1 = MemberUtils.isNonPrivate(privateField); // false Field defaultField = Example.class.getField("defaultField"); boolean result2 = MemberUtils.isNonPrivate(defaultField); // true Field protectedField = Example.class.getField("protectedField"); boolean result3 = MemberUtils.isNonPrivate(protectedField); // true Field publicField = Example.class.getField("publicField"); boolean result4 = MemberUtils.isNonPrivate(publicField); // true Method privateMethod = Example.class.getDeclaredMethod("privateMethod"); boolean result5 = MemberUtils.isNonPrivate(privateMethod); // false Method defaultMethod = Example.class.getMethod("defaultMethod"); boolean result6 = MemberUtils.isNonPrivate(defaultMethod); // true Method protectedMethod = Example.class.getMethod("protectedMethod"); boolean result7 = MemberUtils.isNonPrivate(protectedMethod); // true Method publicMethod = Example.class.getMethod("publicMethod"); boolean result8 = MemberUtils.isNonPrivate(publicMethod); // true- Parameters:
member- theMemberinstance to check, such as aConstructor,Method, orField- Returns:
trueif the member is non-private;falseotherwise
-
asMember
public static java.lang.reflect.Member asMember(java.lang.Object object)
Attempts to cast the provided object to an instance ofMember.This method checks whether the given object is an instance of the
Memberinterface. If it is, the object is casted and returned as aMember. Otherwise, this method returnsnull.Example Usage
Field field = Example.class.getField("publicField"); Member member1 = MemberUtils.asMember(field); System.out.println(member1 == field); // true Method method = Example.class.getMethod("publicMethod"); Member member2 = MemberUtils.asMember(method); System.out.println(member2 == method); // true String notAMember = "This is not a Member"; Member member3 = MemberUtils.asMember(notAMember); System.out.println(member3 == null); // true- Parameters:
object- the object to be casted to aMember, may benull- Returns:
- the casted
Memberinstance if the object is a validMember; otherwise, returnsnull
-
-