@ SuppressWarnings ( { "rawtypes" , "unchecked" } ) private static String insertEmptyObjectInContext ( final String fullName , final Collection lastCollection , final EachCommand eachCommand , final int lastCollectionIndex , final Map < String , Object > dataContext ) { if ( ! ( lastCollection instanceof List ) ) { throw new EvaluationException ( "Collection must be list in order to insert/delete." ) ; } List collectionList = ( List ) lastCollection ; // the object must support empty constructor. Object currentObj = collectionList . get ( lastCollectionIndex ) ; Object insertObj ; try { insertObj = currentObj . getClass ( ) . newInstance ( ) ; collectionList . add ( lastCollectionIndex + 1 , insertObj ) ; dataContext . put ( eachCommand . getVar ( ) , insertObj ) ; return fullName . substring ( 0 , fullName . lastIndexOf ( ' ' ) + 1 ) + ( lastCollectionIndex + 1 ) ; } catch ( InstantiationException | IllegalAccessException e ) { throw new EvaluationException ( e ) ; } }
Insert empty object in context .