commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Henri Biestro (JIRA)" <j...@apache.org>
Subject [jira] [Closed] (JEXL-139) Loop over an iterable, evalaute and expression per row, and return concatenated results
Date Mon, 21 Mar 2016 14:18:25 GMT

     [ https://issues.apache.org/jira/browse/JEXL-139?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Henri Biestro closed JEXL-139.
------------------------------
    Assignee: Henri Biestro

Post 3.0 clean up

> Loop over an iterable, evalaute and expression per row, and return concatenated results
> ---------------------------------------------------------------------------------------
>
>                 Key: JEXL-139
>                 URL: https://issues.apache.org/jira/browse/JEXL-139
>             Project: Commons JEXL
>          Issue Type: New Feature
>            Reporter: Manoj Mokashi
>            Assignee: Henri Biestro
>            Priority: Minor
>   Original Estimate: 24h
>  Remaining Estimate: 24h
>
> Code below.
> /**
> 	 * Iterates over the iterable represented by iterExpression
> 	 * For each row, evaluate the row-expression
> 	 * Return a string of all row-results, concatenated by separator.
> 	 * The current current row is indicated by $$__EVAL_ROW and the current index by $$__EVAL_ROWNUM
> 	 * @param enumExpression
> 	 * @param expression
> 	 * @return
> 	 */
> 	public String evalExprOverIter( String iterExpression, String rowExpression, String
separator){
> 		Object objIter = evalExpr( iterExpression);
> 		if( objIter == null ){ return "";}
> 		Iterable iterabl = null;
> 		if( objIter.getClass().isArray()){
> 			iterabl = Arrays.asList( (Object[]) objIter ); 	
> 		}
> 		else if( objIter instanceof Map){
> 			iterabl = ((Map) objIter).entrySet();
> 		}
> 		else {
> 			iterabl = (Iterable) objIter; 
> 		}
> 		Iterator iter = iterabl.iterator();
> 		StringBuilder sbld = new StringBuilder();
> 		int rownum = 0;
> 		while( iter.hasNext()){
> 			Object row = iter.next(); 
> 			setVar( "$$__EVAL_ROW", row );
> 			setVar( "$$__EVAL_ROWNUM", rownum );
> 			sbld.append( evalExpr( rowExpression) );
> 			sbld.append( separator );
> 			rownum++;
> 		}
> 		// remove the temp variables we used.
> 		remVar( "$$__EVAL_ROWNUM" );
> 		remVar( "$$__EVAL_ROW" );
> 		return sbld.deleteCharAt( sbld.length()-1).toString();



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message