View Javadoc
1   /*
2    * Copyright (C) 2025 Alberto Irurueta Carro (alberto@irurueta.com)
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *         http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package com.irurueta.hermes;
18  
19  /**
20   * Class to represent a change in a collection item that has been updated.
21   *
22   * @param <T> type of items in the collection.
23   */
24  public class UpdatedCollectionItemChange<T> extends CollectionItemChange {
25  
26      /**
27       * Item before being updated.
28       */
29      private final T oldItem;
30  
31      /**
32       * Item after being updated.
33       */
34      private final T newItem;
35  
36      /**
37       * Constructor.
38       *
39       * @param oldItem item that before being updated.
40       * @param newItem item after being updated.
41       * @throws IllegalArgumentException if either the old or new item is null.
42       */
43      public UpdatedCollectionItemChange(final T oldItem, final T newItem) {
44          super(CollectionItemChangeAction.UPDATED);
45          if (oldItem == null || newItem == null) {
46              throw new IllegalArgumentException();
47          }
48  
49          this.oldItem = oldItem;
50          this.newItem = newItem;
51      }
52  
53      /**
54       * Returns the item that before being updated.
55       * @return the item that before being updated.
56       */
57      public T getOldItem() {
58          return oldItem;
59      }
60  
61      /**
62       * Returns the item that after being updated.
63       * @return the item that after being updated.
64       */
65      public T getNewItem() {
66          return newItem;
67      }
68  }