public final List < Change > diff ( final DayOpeningHours toOther ) { Contract . requireArgNotNull ( "toOther" , toOther ) ; if ( dayOfTheWeek != toOther . dayOfTheWeek ) { throw new ConstraintViolationException ( "Expected same day (" + dayOfTheWeek + ") for argument 'toOther', but was: " + toOther . dayOfTheWeek ) ; } final List < DayOpeningHours > fromDays = normalize ( ) ; final List < DayOpeningHours > toDays = toOther . normalize ( ) ; final List < Change > changes = new ArrayList <> ( ) ; if ( fromDays . size ( ) == 1 ) { if ( toDays . size ( ) == 1 ) { // Both only 1 day final DayOpeningHours from = fromDays . get ( 0 ) ; final DayOpeningHours to = toDays . get ( 0 ) ; changes . addAll ( changes ( this . dayOfTheWeek , from . hourRanges , to . hourRanges ) ) ; } else { // From 1 day / To 2 days final DayOpeningHours from = fromDays . get ( 0 ) ; final DayOpeningHours to1 = toDays . get ( 0 ) ; final DayOpeningHours to2 = toDays . get ( 1 ) ; changes . addAll ( changes ( this . dayOfTheWeek , from . hourRanges , to1 . hourRanges ) ) ; changes . addAll ( changes ( ChangeType . ADDED , to2 . dayOfTheWeek , to2 . hourRanges ) ) ; } } else { if ( toDays . size ( ) == 1 ) { // From 2 days / To 1 day final DayOpeningHours from1 = fromDays . get ( 0 ) ; final DayOpeningHours from2 = fromDays . get ( 1 ) ; final DayOpeningHours to = toDays . get ( 0 ) ; changes . addAll ( changes ( this . dayOfTheWeek , from1 . hourRanges , to . hourRanges ) ) ; changes . addAll ( changes ( ChangeType . REMOVED , from2 . dayOfTheWeek , from2 . hourRanges ) ) ; } else { // Both 2 days final DayOpeningHours from1 = fromDays . get ( 0 ) ; final DayOpeningHours from2 = fromDays . get ( 1 ) ; final DayOpeningHours to1 = toDays . get ( 0 ) ; final DayOpeningHours to2 = toDays . get ( 1 ) ; changes . addAll ( changes ( from1 . dayOfTheWeek , from1 . hourRanges , to1 . hourRanges ) ) ; changes . addAll ( changes ( from2 . dayOfTheWeek , from2 . hourRanges , to2 . hourRanges ) ) ; } } return changes ; }
Returns the difference when changing this opening hours to the other one . The day of the week must be equal for both compared instances .