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 UpdatedListItemChange<T> extends ListItemChange {
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       * Indicates the position where the item has been updated.
38       */
39      private final int position;
40  
41      /**
42       * Constructor.
43       *
44       * @param oldItem item that before being updated.
45       * @param newItem item after being updated.
46       * @param position position where the item has been updated.
47       * @throws IllegalArgumentException if either the old or new item is null.
48       */
49      public UpdatedListItemChange(final T oldItem, final T newItem, final int position) {
50          super(ListItemChangeAction.UPDATED);
51          if (oldItem == null || newItem == null) {
52              throw new IllegalArgumentException();
53          }
54  
55          this.oldItem = oldItem;
56          this.newItem = newItem;
57          this.position = position;
58      }
59  
60      /**
61       * Returns the item that before being updated.
62       * @return the item that before being updated.
63       */
64      public T getOldItem() {
65          return oldItem;
66      }
67  
68      /**
69       * Returns the item after being updated.
70       * @return the item after being updated.
71       */
72      public T getNewItem() {
73          return newItem;
74      }
75  
76      /**
77       * Returns the position where the item has been updated.
78       * @return the position where the item has been updated.
79       */
80      public int getPosition() {
81          return position;
82      }
83  }