1 /*
2 * Metis: Java Data Framework
3 * Copyright 2012-2026. Tony Washer
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
6 * use this file except in compliance with the License. You may obtain a copy
7 * of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 * License for the specific language governing permissions and limitations under
15 * the License.
16 */
17 package io.github.tonywasher.joceanus.metis.data;
18
19 import io.github.tonywasher.joceanus.oceanus.format.OceanusDataFormatter;
20 import io.github.tonywasher.joceanus.metis.data.MetisDataItem.MetisDataObjectFormat;
21
22 /**
23 * Delta class.
24 */
25 public class MetisDataDelta
26 implements MetisDataObjectFormat {
27 /**
28 * The object itself.
29 */
30 private final Object theObject;
31
32 /**
33 * The difference.
34 */
35 private final MetisDataDifference theDifference;
36
37 /**
38 * Constructor.
39 *
40 * @param pObject the object
41 * @param pDifference the difference
42 */
43 public MetisDataDelta(final Object pObject,
44 final MetisDataDifference pDifference) {
45 theObject = pObject;
46 theDifference = pDifference;
47 }
48
49 /**
50 * Obtain the object.
51 *
52 * @return the object
53 */
54 public Object getObject() {
55 return theObject;
56 }
57
58 /**
59 * Obtain the difference.
60 *
61 * @return the difference
62 */
63 public MetisDataDifference getDifference() {
64 return theDifference;
65 }
66
67 @Override
68 public String formatObject(final OceanusDataFormatter pFormatter) {
69 return theDifference.isDifferent()
70 ? theDifference + "(" + pFormatter.formatObject(theObject) + ")"
71 : pFormatter.formatObject(theObject);
72 }
73 }