Class ValueUtils

java.lang.Object
org.apache.commons.jxpath.util.ValueUtils

public class ValueUtils extends Object
Collection and property access utilities.
  • Constructor Details

    • ValueUtils

      Deprecated.
      Will be private in the next major version.
      Constructs a new instance.
  • Method Details

    • expandCollection

      public static Object expandCollection(Object collection, int size)
      Grows the collection if necessary to the specified size. Returns the new, expanded collection.
      Parameters:
      collection - to expand
      size - desired size
      Returns:
      collection or array
    • getAccessibleMethod

      public static Method getAccessibleMethod(Method method)
      Gets an accessible method (that is, one that can be invoked via reflection) that implements the specified Method. If no such method can be found, return null.
      Parameters:
      method - The method that we wish to call
      Returns:
      Method
    • getCollectionHint

      public static int getCollectionHint(Class clazz)
      Returns 1 if the type is a collection, -1 if it is definitely not and 0 if it may be a collection in some cases.
      Parameters:
      clazz - to test
      Returns:
      int
    • getDynamicPropertyHandler

      Returns a shared instance of the dynamic property handler class returned by getDynamicPropertyHandlerClass().
      Parameters:
      clazz - to handle
      Returns:
      DynamicPropertyHandler
    • getIndexedPropertyLength

      If there is a regular non-indexed read method for this property, uses this method to obtain the collection and then returns its length. Otherwise, attempts to guess the length of the collection by calling the indexed get method repeatedly. The method is supposed to throw an exception if the index is out of bounds.
      Parameters:
      object - collection
      pd - IndexedPropertyDescriptor
      Returns:
      int
    • getLength

      public static int getLength(Object collection)
      Returns the length of the supplied collection. If the supplied object is not a collection, returns 1. If collection is null, returns 0.
      Parameters:
      collection - to check
      Returns:
      int
    • getValue

      public static Object getValue(Object object)
      If the parameter is a container, opens the container and return the contents. The method is recursive.
      Parameters:
      object - to read
      Returns:
      Object
    • getValue

      public static Object getValue(Object collection, int index)
      Returns the index'th element of the supplied collection.
      Parameters:
      collection - to read
      index - int
      Returns:
      collection[index]
    • getValue

      public static Object getValue(Object bean, PropertyDescriptor propertyDescriptor)
      Returns the value of the bean's property represented by the supplied property descriptor.
      Parameters:
      bean - to read
      propertyDescriptor - indicating what to read
      Returns:
      Object value
    • getValue

      public static Object getValue(Object bean, PropertyDescriptor propertyDescriptor, int index)
      Returns the index'th element of the bean's property represented by the supplied property descriptor.
      Parameters:
      bean - to read
      propertyDescriptor - indicating what to read
      index - int
      Returns:
      Object
    • isCollection

      public static boolean isCollection(Object value)
      Returns true if the object is an array or a Collection.
      Parameters:
      value - to test
      Returns:
      boolean
    • iterate

      public static Iterator iterate(Object collection)
      Returns an iterator for the supplied collection. If the argument is null, returns an empty iterator. If the argument is not a collection, returns an iterator that produces just that one object.
      Parameters:
      collection - to iterate
      Returns:
      Iterator
    • remove

      public static Object remove(Object collection, int index)
      Remove the index'th element from the supplied collection.
      Parameters:
      collection - to edit
      index - int
      Returns:
      the resulting collection
    • setValue

      public static void setValue(Object collection, int index, Object value)
      Modifies the index'th element of the supplied collection. Converts the value to the required type if necessary.
      Parameters:
      collection - to edit
      index - to replace
      value - new value
    • setValue

      public static void setValue(Object bean, PropertyDescriptor propertyDescriptor, int index, Object value)
      Modifies the index'th element of the bean's property represented by the supplied property descriptor. Converts the value to the required type if necessary.
      Parameters:
      bean - to edit
      propertyDescriptor - indicating what to set
      index - int
      value - to set
    • setValue

      public static void setValue(Object bean, PropertyDescriptor propertyDescriptor, Object value)
      Modifies the value of the bean's property represented by the supplied property descriptor.
      Parameters:
      bean - to read
      propertyDescriptor - indicating what to read
      value - to set