GridUtils { public static int getGridIndexByDimensionItem( List<Object> row, List<DimensionalItemObject> items, int defaultIndex ) { List<String> valid = items.stream().map( DimensionalItemObject::getDimensionItem ) .collect( Collectors.toList() ); for ( int i = 0; i < row.size() -1 ; i++ ) { final String value = (String) row.get( i ); if ( valid.contains( value ) ) { return i; } } return defaultIndex; }  static void toPdf( Grid grid, OutputStream out ); static void toPdf( List<Grid> grids, OutputStream out ); static void toXls( List<Grid> grids, OutputStream out ); static void toXls( Grid grid, OutputStream out ); static void toCsv( Grid grid, Writer writer ); static void toJasperReport( Grid grid, Map<String, Object> params, OutputStream out ); static void toJrxml( Grid grid, Map<?, ?> params, Writer writer ); static void toHtml( Grid grid, Writer writer ); static void toHtmlCss( Grid grid, Writer writer ); static void toHtmlInlineCss( Grid grid, Writer writer ); static void toXml( Grid grid, OutputStream out ); static void addRows( Grid grid, SqlRowSet rs ); static int getGridIndexByDimensionItem( List<Object> row, List<DimensionalItemObject> items, int defaultIndex ); static List<Grid> fromHtml( String html, String title ); static String getValue( TagNode cell ); static Map<String, Object> getMetaValueMapping( Grid grid, int valueIndex );  }
@Test public void testGetGridIndexByDimensionItem() { Period period1 = PeriodType.getPeriodFromIsoString( "202010" ); period1.setUid( CodeGenerator.generateUid() ); Period period2 = PeriodType.getPeriodFromIsoString( "202011" ); period2.setUid( CodeGenerator.generateUid() ); Period period3 = PeriodType.getPeriodFromIsoString( "202012" ); period3.setUid( CodeGenerator.generateUid() ); List<DimensionalItemObject> periods = Lists.newArrayList( period1, period2, period3); List<Object> row = new ArrayList<>( 3 ); row.add( CodeGenerator.generateUid() ); row.add( period2.getIsoDate()); row.add( 10.22D ); assertEquals( 1, GridUtils.getGridIndexByDimensionItem( row, periods, 2 ) ); List<Object> row2 = new ArrayList<>( 3 ); row2.add( CodeGenerator.generateUid() ); row2.add( "201901" ); row2.add( 10.22D ); assertEquals( 2, GridUtils.getGridIndexByDimensionItem( row2, periods, 2 ) ); }