@SuppressWarnings({ "unchecked", "rawtypes" })
  protected Object set(CachingPojoPath currentPath, PojoPathContext context, PojoPathState state, Object parentPojo, Object value) {

    Object result;
    String functionName = currentPath.getFunction();
    if (functionName != null) {
      // current segment is a function...
      PojoPathFunction function = getFunction(functionName, context);
      Class<?> valueClass = function.getValueClass();
      currentPath.pojoClass = valueClass;
      Object convertedValue = convert(currentPath, context, value, valueClass, null);
      result = function.set(parentPojo, functionName, convertedValue, context);
    } else {
      // current segment is NOT a function
      if (parentPojo instanceof Map) {
        Map map = (Map) parentPojo;
        String key = currentPath.getSegment();
        Object convertedKey = key;
        Object convertedValue = value;
        if (currentPath.parent != null) {
          GenericType<?> mapType = currentPath.parent.pojoType;
          if (mapType != null) {
            GenericType<?> valueType = mapType.getComponentType();
            convertedValue = convert(currentPath, context, value, valueType.getAssignmentClass(), valueType);
            GenericType<?> keyType = mapType.getKeyType();
            convertedKey = convert(currentPath, context, key, keyType.getAssignmentClass(), keyType);
          }
        }
        result = map.put(convertedKey, convertedValue);
      } else {
        Integer index = currentPath.getIndex();
        if (index != null) {
          // handle indexed segment for list or array...
          result = setInList(currentPath, context, state, parentPojo, value, index.intValue());
        } else {
          // in all other cases get via reflection from POJO...
          result = setInPojo(currentPath, context, state, parentPojo, value);
        }
      }
    }
    return result;
  }
@ SuppressWarnings ( { "unchecked" , "rawtypes" } ) protected Object set ( CachingPojoPath currentPath , PojoPathContext context , PojoPathState state , Object parentPojo , Object value ) { Object result ; String functionName = currentPath . getFunction ( ) ; if ( functionName != null ) { PojoPathFunction function = getFunction ( functionName , context ) ; Class < ? > valueClass = function . getValueClass ( ) ; currentPath . pojoClass = valueClass ; Object convertedValue = convert ( currentPath , context , value , valueClass , null ) ; result = function . set ( parentPojo , functionName , convertedValue , context ) ; } else { if ( parentPojo instanceof Map ) { Map map = ( Map ) parentPojo ; String key = currentPath . getSegment ( ) ; Object convertedKey = key ; Object convertedValue = value ; if ( currentPath . parent != null ) { GenericType < ? > mapType = currentPath . parent . pojoType ; if ( mapType != null ) { GenericType < ? > valueType = mapType . getComponentType ( ) ; convertedValue = convert ( currentPath , context , value , valueType . getAssignmentClass ( ) , valueType ) ; GenericType < ? > keyType = mapType . getKeyType ( ) ; convertedKey = convert ( currentPath , context , key , keyType . getAssignmentClass ( ) , keyType ) ; } } result = map . put ( convertedKey , convertedValue ) ; } else { Integer index = currentPath . getIndex ( ) ; if ( index != null ) { result = setInList ( currentPath , context , state , parentPojo , value , index . intValue ( ) ) ; } else { result = setInPojo ( currentPath , context , state , parentPojo , value ) ; } } } return result ; }
This method sets the single {@link CachingPojoPath#getSegment() segment} of the given {@code currentPath} from the
{@link net.sf.mmm.util.pojo.api.Pojo} given by {@code parentPojo}. If the result is {@code null} and {@code mode}
is {@link PojoPathMode#CREATE_IF_NULL} it creates and attaches (sets) the missing object.

@param currentPath is the current {@link CachingPojoPath} to set.
@param context is the {@link PojoPathContext context} for this operation.
@param state is the {@link #createState(Object, String, PojoPathMode, PojoPathContext) cache} to use or
{@code null} to disable caching.
@param parentPojo is the parent {@link net.sf.mmm.util.pojo.api.Pojo} to work on.
@param value is the value to set in {@code parentPojo}.
@return the replaced value. It may be {@code null}.