Package org.linkki.util
Class BeanUtils
- java.lang.Object
-
- org.linkki.util.BeanUtils
-
public class BeanUtils extends Object
-
-
Field Summary
Fields Modifier and Type Field Description static StringGET_PREFIXstatic StringIS_PREFIXstatic StringSET_PREFIX
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static BeanInfogetBeanInfo(Class<?> clazz)Returns the bean info for the given class.static FieldgetDeclaredField(Class<?> clazz, String name)Returns the class' declared field with the given name.static FieldgetField(Class<?> clazz, String name)Returns the class' field with the given name.static MethodgetMethod(Class<?> clazz, String name, Class<?>... parameterTypes)Returns the method with the given name and parameter types.static Optional<Method>getMethod(Class<?> clazz, Predicate<Method> predicate)Returns an optional containing the class' method matching the given predicate (empty optional if none matches).static Stream<Method>getMethods(Class<?> clazz, Predicate<Method> predicate)Returns the class' methods matching the given predicate.static StringgetPropertyName(Method method)Returns the property name from the given method:String getFoo()-> "foo"boolean isBar()-> "bar"void fooBar()-> "fooBar"static StringgetPropertyName(Type returnType, String methodName)Returns the property name from the given method name:getFoo-> "foo"isBar-> "bar"fooBar-> "fooBar"static ObjectgetValueFromField(Object object, Field field)Returns the object's value for the field with the given name.static ObjectgetValueFromField(Object object, String name)Returns the object's value for the field with the given name.
-
-
-
Field Detail
-
GET_PREFIX
public static final String GET_PREFIX
- See Also:
- Constant Field Values
-
SET_PREFIX
public static final String SET_PREFIX
- See Also:
- Constant Field Values
-
IS_PREFIX
public static final String IS_PREFIX
- See Also:
- Constant Field Values
-
-
Method Detail
-
getBeanInfo
public static BeanInfo getBeanInfo(Class<?> clazz)
Returns the bean info for the given class.
-
getMethod
public static Method getMethod(Class<?> clazz, String name, Class<?>... parameterTypes)
Returns the method with the given name and parameter types.- See Also:
Class.getMethod(String, Class...)
-
getMethod
public static Optional<Method> getMethod(Class<?> clazz, Predicate<Method> predicate)
Returns an optional containing the class' method matching the given predicate (empty optional if none matches). If you expect more than one match,getMethods(Class, Predicate)might be what you're looking for.- Throws:
IllegalStateException- If more than one method matches the predicate.
-
getMethods
public static Stream<Method> getMethods(Class<?> clazz, Predicate<Method> predicate)
Returns the class' methods matching the given predicate.
-
getDeclaredField
public static Field getDeclaredField(Class<?> clazz, String name)
Returns the class' declared field with the given name. Declared field means that the field is declared in the given class, any super classes are not searched.- See Also:
Class.getDeclaredField(String)
-
getField
public static Field getField(Class<?> clazz, String name)
Returns the class' field with the given name. In contrast togetDeclaredField(Class, String)this method searches the type's hierarchy (if the class extends a super class)- Throws:
RuntimeException- wrapping a NoSuchFieldException if no such field exists.- See Also:
Class.getDeclaredField(String)
-
getValueFromField
@CheckForNull public static Object getValueFromField(Object object, String name)
Returns the object's value for the field with the given name.- See Also:
Class.getDeclaredField(String)
-
getValueFromField
@CheckForNull public static Object getValueFromField(Object object, Field field)
Returns the object's value for the field with the given name.- See Also:
Class.getDeclaredField(String)
-
getPropertyName
public static String getPropertyName(Method method)
Returns the property name from the given method:String getFoo()-> "foo"boolean isBar()-> "bar"void fooBar()-> "fooBar"
-
-