class PeriodOffsetUtils {

    public static List<Object> getPeriodOffsetRow( Grid grid, DimensionalItemObject dimItem, String isoPeriod,
        int offset )
    {
        if ( grid == null || dimItem == null )
        {
            return null;
        }

        BiFunction<Integer, Integer, Integer> replaceIndexIfMissing = (Integer index, Integer defaultIndex )
                -> index == -1 ? defaultIndex : index;

        final int dataIndex = replaceIndexIfMissing.apply( grid.getIndexOfHeader( DATA_X_DIM_ID ), 0 );
        final int periodIndex = replaceIndexIfMissing.apply( grid.getIndexOfHeader( PERIOD_DIM_ID ), 1 );

        Period shifted = offset != 0 ? shiftPeriod( PeriodType.getPeriodFromIsoString( isoPeriod ), offset ) :
            PeriodType.getPeriodFromIsoString( isoPeriod );

        for ( List<Object> row : grid.getRows() )
        {
            final String rowUid = (String) row.get( dataIndex );
            final String rowPeriod = (String) row.get( periodIndex );

            if ( rowUid.equals( dimItem.getUid() ) && rowPeriod.equals( shifted.getIsoDate() ) )
            {
                return row;
            }
        }

        return null;
    }

}