Class JKObjectUtil

java.lang.Object
com.jk.core.util.JKObjectUtil

public class JKObjectUtil extends Object
The Class JKObjectUtil.
  • Constructor Details

    • JKObjectUtil

      public JKObjectUtil()
  • Method Details

    • cloneBean

      public static <T> T cloneBean(Object bean)
      Clone bean.
      Type Parameters:
      T - the generic type
      Parameters:
      bean - the bean
      Returns:
      the t
    • getClass

      public static Class<?> getClass(String beanClassName)
      Gets the class.
      Parameters:
      beanClassName - the bean class name
      Returns:
      the class
    • getPropertyValue

      public static <T> T getPropertyValue(Object instance, String fieldName)
      Gets the property value.
      Type Parameters:
      T - the generic type
      Parameters:
      instance - the instance
      fieldName - the field name
      Returns:
      the property value
    • isBoolean

      public static boolean isBoolean(Class type)
      Checks if is boolean.
      Parameters:
      type - the type
      Returns:
      true, if is boolean
    • isDate

      public static boolean isDate(Class type)
      Checks if is date.
      Parameters:
      type - the type
      Returns:
      true, if is date
    • isFinal

      public static boolean isFinal(Field field)
      Checks if is final.
      Parameters:
      field - the field
      Returns:
      true, if is final
    • isStatic

      public static boolean isStatic(Field field)
      Checks if is static.
      Parameters:
      field - the field
      Returns:
      true, if is static
    • isTime

      public static boolean isTime(Class type)
      Checks if is time.
      Parameters:
      type - the type
      Returns:
      true, if is time
    • isTimeStamp

      public static boolean isTimeStamp(Class type)
      Checks if is time stamp.
      Parameters:
      type - the type
      Returns:
      true, if is time stamp
    • isTransient

      public static boolean isTransient(Field field)
      Checks if is transient.
      Parameters:
      field - the field
      Returns:
      true, if is transient
    • newInstance

      public static <T> T newInstance(Class<T> clas)
      New instance.
      Type Parameters:
      T - the generic type
      Parameters:
      clas - the clas
      Returns:
      the t
    • newInstance

      public static <T> T newInstance(Class<T> clas, Object... params)
      New instance.
      Type Parameters:
      T - the generic type
      Parameters:
      clas - the clas
      params - the params
      Returns:
      the t
    • newInstance

      public static <T> T newInstance(String className)
      New instance.
      Type Parameters:
      T - the generic type
      Parameters:
      className - the class name
      Returns:
      the t
    • setPeopertyValue

      public static void setPeopertyValue(Object target, String fieldName, Object value)
      Sets the peoperty value.
      Parameters:
      target - the target
      fieldName - the field name
      value - the value
    • addItemToList

      public static void addItemToList(Object target, String fieldName, Object value)
      Adds the item to list.
      Parameters:
      target - the target
      fieldName - the field name
      value - the value
    • toClass

      public static Class<?> toClass(String name)
      To class.
      Parameters:
      name - the name
      Returns:
      the class
    • toClassesFromObjects

      public static Class<?>[] toClassesFromObjects(Object[] params)
      To classes from objects.
      Parameters:
      params - the params
      Returns:
      the class[]
    • toString

      public static String toString(Object object, boolean useCurrentTostringIfAvailable)
      To string.
      Parameters:
      object - the object
      useCurrentTostringIfAvailable - the use current tostring if available
      Returns:
      the string
    • toString

      public static String toString(Object object)
      To string.
      Parameters:
      object - the object
      Returns:
      the string
    • isMethodDirectlyExists

      public static boolean isMethodDirectlyExists(Object object, String methodName, Class<?>... params)
      Checks if is method directly exists.
      Parameters:
      object - the object
      methodName - the method name
      params - the params
      Returns:
      true, if is method directly exists
    • equals

      public static boolean equals(Object source, Object target)
      Equals.
      Parameters:
      source - the source
      target - the target
      Returns:
      true, if successful
    • getFieldValue

      public static Object getFieldValue(Object instance, String fieldName)
      Gets the field value.
      Parameters:
      instance - the instance
      fieldName - the field name
      Returns:
      the field value
    • callStaticMethod

      public static Object callStaticMethod(Class clas, String methodName, Object... params)
      Call static method.
      Parameters:
      clas - the clas
      methodName - the method name
      params - the params
      Returns:
      the object
    • copy

      public static Object copy(Object source)
      Copy.
      Parameters:
      source - the source
      Returns:
      the object
    • toXml

      public static String toXml(Object obj)
      To xml.
      Parameters:
      obj - the obj
      Returns:
      the string
    • toObject

      public static Object toObject(String xml)
      To object.
      Parameters:
      xml - the xml
      Returns:
      the object
    • hash

      public static int hash(String name)
      Hash.
      Parameters:
      name - the name
      Returns:
      the int
    • getGenericParamter

      public static <T> Class<? extends T> getGenericParamter(String handler)
      Gets the generic paramter.
      Type Parameters:
      T - the generic type
      Parameters:
      handler - the handler
      Returns:
      the generic paramter
    • fixPropertyName

      public static String fixPropertyName(String name)
      Fix property name.
      Parameters:
      name - the name
      Returns:
      the string
    • populate

      public static void populate(Object instance, Map<String,Object> values)
      Populate.
      Parameters:
      instance - the instance
      values - the values
    • isClassAvilableInClassPath

      public static boolean isClassAvilableInClassPath(String string)
      Checks if is class avilable in class path.
      Parameters:
      string - the string
      Returns:
      true, if is class avilable in class path
    • callMethod

      public static Object callMethod(Object obj, String methodName, boolean includePrivateMehtods, Object... args) throws InvocationTargetException
      Call method.
      Parameters:
      obj - the obj
      methodName - the method name
      includePrivateMehtods - the include private mehtods
      args - the args
      Returns:
      the object
      Throws:
      InvocationTargetException - the invocation target exception
    • callMethod

      public static Object callMethod(Object obj, String methodName, Object... args)
      Call method.
      Parameters:
      obj - the obj
      methodName - the method name
      args - the args
      Returns:
      the object
    • getInstanceVariables

      public static <T> String getInstanceVariables(Class<T> clas)
      Gets the instance variables.
      Type Parameters:
      T - the generic type
      Parameters:
      clas - the clas
      Returns:
      the instance variables
    • getProperties

      public static <T> List<String> getProperties(Class<T> clas)
      Gets the properties.
      Type Parameters:
      T - the generic type
      Parameters:
      clas - the clas
      Returns:
      the properties
    • toJson

      public static String toJson(Object obj)
      To json.
      Parameters:
      obj - the obj
      Returns:
      the string
    • createMapper

      public static com.fasterxml.jackson.databind.ObjectMapper createMapper()
      Creates the mapper.
      Returns:
      the object mapper
    • createMapper

      public static com.fasterxml.jackson.databind.ObjectMapper createMapper(com.fasterxml.jackson.core.JsonFactory factory)
      Creates the mapper.
      Parameters:
      factory - the factory
      Returns:
      the object mapper
    • toYaml

      public static String toYaml(Object obj)
      To yaml.
      Parameters:
      obj - the obj
      Returns:
      the string
    • jsonToObject

      public static <T> T jsonToObject(String json, Class<T> clas)
      Json to object.
      Type Parameters:
      T - the generic type
      Parameters:
      json - the json
      clas - the clas
      Returns:
      the object
    • jsonToObjectList

      public static <T> List<T> jsonToObjectList(String json, Class<T> clas)
      Json to object list.
      Type Parameters:
      T - the generic type
      Parameters:
      json - the json
      clas - the clas
      Returns:
      the list
    • yamlToObject

      public static <T> T yamlToObject(String yaml, Class<T> clas)
      Yaml to object.
      Type Parameters:
      T - the generic type
      Parameters:
      yaml - the yaml
      clas - the clas
      Returns:
      the object
    • getWrapperForPrimitive

      public static Class<?> getWrapperForPrimitive(Class<?> clas)
      Gets the wrapper for primitive.
      Parameters:
      clas - the clas
      Returns:
      the wrapper for primitive
    • isPrimitive

      public static boolean isPrimitive(Class<?> type)
      Checks if is primitive.
      Parameters:
      type - the type
      Returns:
      true, if is primitive
    • getFieldNameByType

      public static String getFieldNameByType(Class<?> classType, Class<?> fieldType)
      Gets the field name by type.
      Parameters:
      classType - the class type
      fieldType - the field type
      Returns:
      the field name by type
    • getFieldByName

      public static Field getFieldByName(Class<?> classType, String name)
      Gets the field by name.
      Parameters:
      classType - the class type
      name - the name
      Returns:
      the field by name
    • isInteger

      public static boolean isInteger(Class<?> type)
      Checks if is integer.
      Parameters:
      type - the type
      Returns:
      true, if is integer
    • isFieldExists

      public static boolean isFieldExists(Class<?> clas, String fieldName)
      Checks if is field exists.
      Parameters:
      clas - the clas
      fieldName - the field name
      Returns:
      true, if is field exists
    • getAllClassesInPackage

      public static List<String> getAllClassesInPackage(String packageName)
      Gets the all classes in package.
      Parameters:
      packageName - the package name
      Returns:
      the all classes in package
    • getAllFields

      public static List<Field> getAllFields(Class<?> clas)
      Gets the all fields.
      Parameters:
      clas - the clas
      Returns:
      the all fields
    • createInstanceForGenericClass

      public static <T> T createInstanceForGenericClass(Object parent)
      Creates the instance for generic class.
      Type Parameters:
      T - the generic type
      Parameters:
      parent - the parent
      Returns:
      the t
    • getGenericClassFromParent

      public static Class getGenericClassFromParent(Object parent)
      Gets the generic class from parent.
      Parameters:
      parent - the parent
      Returns:
      the generic class from parent
    • getPrivateValue

      public static Object getPrivateValue(Object instance, String fieldName)
      Gets the private value.
      Parameters:
      instance - the instance
      fieldName - the field name
      Returns:
      the private value
    • getPrivateValue

      public static Object getPrivateValue(Class<?> clas, Object instance, String fieldName)
      Gets the private value.
      Parameters:
      clas - the clas
      instance - the instance
      fieldName - the field name
      Returns:
      the private value
    • evaluate

      public static Object evaluate(Object rootObject, String valueExpression)
      Evaluate.
      Parameters:
      rootObject - the root object
      valueExpression - the value expression
      Returns:
      the object
    • setPropertiesByOrder

      public static void setPropertiesByOrder(Object model, String[] names, String[] values)
      Sets the properties by order.
      Parameters:
      model - the model
      names - the names
      values - the values
    • getAllFieldNames

      public static <T> String[] getAllFieldNames(Class<T> modelClass)
      Gets the all field names.
      Type Parameters:
      T - the generic type
      Parameters:
      modelClass - the model class
      Returns:
      the all field names