class PeriodOffsetUtils {

    public static DataQueryParams removeOffsetPeriodsIfNotNeeded( DataQueryParams params )
    {
        final List<DimensionalItemObject> dimensionalItemObjects = params.getDataElements();

        final boolean hasOffset = dimensionalItemObjects.stream().filter( dio -> dio.getDimensionItemType() != null )
            .filter( dio -> dio.getDimensionItemType().equals( DimensionItemType.DATA_ELEMENT ) )
            .anyMatch( dio -> dio.getPeriodOffset() != 0 );

        if ( !hasOffset )
        {
            final List<DimensionalItemObject> nonShiftedPeriods = params.getPeriods().stream()
                .filter( dio -> ( !( (Period) dio).isShifted() ) )
                .collect( Collectors.toList() );

            return DataQueryParams.newBuilder( params )
                .withPeriods( params.getDimension( PERIOD_DIM_ID ).getDimensionName(), nonShiftedPeriods )
                .build();
        }
        return params;
    }

}