View Javadoc

1   /*
2    * Copyright 2015 Data Archiving and Networked Services (an institute of
3    * Koninklijke Nederlandse Akademie van Wetenschappen), King's College London,
4    * Georg-August-Universitaet Goettingen Stiftung Oeffentlichen Rechts
5    *
6    * Licensed under the EUPL, Version 1.1 or – as soon they will be approved by
7    * the European Commission - subsequent versions of the EUPL (the "Licence");
8    * You may not use this work except in compliance with the Licence.
9    * You may obtain a copy of the Licence at:
10   *
11   * https://joinup.ec.europa.eu/software/page/eupl
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the Licence is distributed on an "AS IS" basis,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the Licence for the specific language governing
17   * permissions and limitations under the Licence.
18   */
19  
20  package eu.ehri.project.persistence;
21  
22  
23  import java.util.Optional;
24  
25  /**
26   * Class holding information about a create-or-update job. The item
27   * will either have been created, been updated, or remained unchanged.
28   */
29  public final class Mutation<T> {
30      private final T node;
31      private final MutationState state;
32      private final Optional<Bundle> prior;
33  
34      public Mutation(T node, MutationState state, Optional<Bundle> prior) {
35          this.node = node;
36          this.state = state;
37          this.prior = prior;
38      }
39  
40      public Mutation(T node, MutationState state) {
41          this(node, state, Optional.empty());
42      }
43  
44      public Mutation(T node, MutationState state, Bundle bundle) {
45          this(node, state, Optional.ofNullable(bundle));
46      }
47  
48      public T getNode() {
49          return node;
50      }
51  
52      public Optional<Bundle> getPrior() {
53          return this.prior;
54      }
55  
56      public MutationState getState() {
57          return state;
58      }
59  
60      public boolean hasChanged() {
61          return state != MutationState.UNCHANGED;
62      }
63  
64      public boolean created() {
65          return state == MutationState.CREATED;
66      }
67  
68      public boolean updated() {
69          return state == MutationState.UPDATED;
70      }
71  }