Java Code Examples for org.apache.ibatis.reflection.property.PropertyTokenizer#getName()

The following examples show how to use org.apache.ibatis.reflection.property.PropertyTokenizer#getName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaseWrapper.java    From mybaties with Apache License 2.0 5 votes vote down vote up
protected Object getCollectionValue(PropertyTokenizer prop, Object collection) {
  if (collection instanceof Map) {
      //map['name']
    return ((Map) collection).get(prop.getIndex());
  } else {
    int i = Integer.parseInt(prop.getIndex());
    if (collection instanceof List) {
        //list[0]
      return ((List) collection).get(i);
    } else if (collection instanceof Object[]) {
      return ((Object[]) collection)[i];
    } else if (collection instanceof char[]) {
      return ((char[]) collection)[i];
    } else if (collection instanceof boolean[]) {
      return ((boolean[]) collection)[i];
    } else if (collection instanceof byte[]) {
      return ((byte[]) collection)[i];
    } else if (collection instanceof double[]) {
      return ((double[]) collection)[i];
    } else if (collection instanceof float[]) {
      return ((float[]) collection)[i];
    } else if (collection instanceof int[]) {
      return ((int[]) collection)[i];
    } else if (collection instanceof long[]) {
      return ((long[]) collection)[i];
    } else if (collection instanceof short[]) {
      return ((short[]) collection)[i];
    } else {
      throw new ReflectionException("The '" + prop.getName() + "' property of " + collection + " is not a List or Array.");
    }
  }
}
 
Example 2
Source File: BaseWrapper.java    From mybaties with Apache License 2.0 5 votes vote down vote up
protected void setCollectionValue(PropertyTokenizer prop, Object collection, Object value) {
  if (collection instanceof Map) {
    ((Map) collection).put(prop.getIndex(), value);
  } else {
    int i = Integer.parseInt(prop.getIndex());
    if (collection instanceof List) {
      ((List) collection).set(i, value);
    } else if (collection instanceof Object[]) {
      ((Object[]) collection)[i] = value;
    } else if (collection instanceof char[]) {
      ((char[]) collection)[i] = (Character) value;
    } else if (collection instanceof boolean[]) {
      ((boolean[]) collection)[i] = (Boolean) value;
    } else if (collection instanceof byte[]) {
      ((byte[]) collection)[i] = (Byte) value;
    } else if (collection instanceof double[]) {
      ((double[]) collection)[i] = (Double) value;
    } else if (collection instanceof float[]) {
      ((float[]) collection)[i] = (Float) value;
    } else if (collection instanceof int[]) {
      ((int[]) collection)[i] = (Integer) value;
    } else if (collection instanceof long[]) {
      ((long[]) collection)[i] = (Long) value;
    } else if (collection instanceof short[]) {
      ((short[]) collection)[i] = (Short) value;
    } else {
      throw new ReflectionException("The '" + prop.getName() + "' property of " + collection + " is not a List or Array.");
    }
  }
}
 
Example 3
Source File: BaseWrapper.java    From mybatis with Apache License 2.0 5 votes vote down vote up
protected Object getCollectionValue(PropertyTokenizer prop, Object collection) {
  if (collection instanceof Map) {
      //map['name']
    return ((Map) collection).get(prop.getIndex());
  } else {
    int i = Integer.parseInt(prop.getIndex());
    if (collection instanceof List) {
        //list[0]
      return ((List) collection).get(i);
    } else if (collection instanceof Object[]) {
      return ((Object[]) collection)[i];
    } else if (collection instanceof char[]) {
      return ((char[]) collection)[i];
    } else if (collection instanceof boolean[]) {
      return ((boolean[]) collection)[i];
    } else if (collection instanceof byte[]) {
      return ((byte[]) collection)[i];
    } else if (collection instanceof double[]) {
      return ((double[]) collection)[i];
    } else if (collection instanceof float[]) {
      return ((float[]) collection)[i];
    } else if (collection instanceof int[]) {
      return ((int[]) collection)[i];
    } else if (collection instanceof long[]) {
      return ((long[]) collection)[i];
    } else if (collection instanceof short[]) {
      return ((short[]) collection)[i];
    } else {
      throw new ReflectionException("The '" + prop.getName() + "' property of " + collection + " is not a List or Array.");
    }
  }
}
 
Example 4
Source File: BaseWrapper.java    From mybatis with Apache License 2.0 5 votes vote down vote up
protected void setCollectionValue(PropertyTokenizer prop, Object collection, Object value) {
  if (collection instanceof Map) {
    ((Map) collection).put(prop.getIndex(), value);
  } else {
    int i = Integer.parseInt(prop.getIndex());
    if (collection instanceof List) {
      ((List) collection).set(i, value);
    } else if (collection instanceof Object[]) {
      ((Object[]) collection)[i] = value;
    } else if (collection instanceof char[]) {
      ((char[]) collection)[i] = (Character) value;
    } else if (collection instanceof boolean[]) {
      ((boolean[]) collection)[i] = (Boolean) value;
    } else if (collection instanceof byte[]) {
      ((byte[]) collection)[i] = (Byte) value;
    } else if (collection instanceof double[]) {
      ((double[]) collection)[i] = (Double) value;
    } else if (collection instanceof float[]) {
      ((float[]) collection)[i] = (Float) value;
    } else if (collection instanceof int[]) {
      ((int[]) collection)[i] = (Integer) value;
    } else if (collection instanceof long[]) {
      ((long[]) collection)[i] = (Long) value;
    } else if (collection instanceof short[]) {
      ((short[]) collection)[i] = (Short) value;
    } else {
      throw new ReflectionException("The '" + prop.getName() + "' property of " + collection + " is not a List or Array.");
    }
  }
}