7a5ebfd228d3b81cacf39765dd492012e1108889
[policy/apex-pdp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy 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,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  * 
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.apex.model.contextmodel.handling;
22
23 import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
24 import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbum;
25 import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbums;
26 import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema;
27 import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas;
28 import org.onap.policy.apex.model.utilities.comparison.KeyedMapComparer;
29 import org.onap.policy.apex.model.utilities.comparison.KeyedMapDifference;
30
31 /**
32  * This class compares the context in two AxContext objects and returns the differences. The
33  * differences are returned in a {@link KeyedMapDifference} object that contains the left, equal,
34  * and right context schemas or albums.
35  *
36  * @author Liam Fallon (liam.fallon@ericsson.com)
37  */
38 public class ContextComparer {
39
40     /**
41      * Compare two {@link AxContextAlbums} objects, comparing their context albums one after
42      * another.
43      *
44      * @param left the left context
45      * @param right the right context
46      * @return the difference
47      */
48     public KeyedMapDifference<AxArtifactKey, AxContextAlbum> compare(final AxContextAlbums left,
49             final AxContextAlbums right) {
50         // Find the difference between the AxContext objects
51         return new KeyedMapComparer<AxArtifactKey, AxContextAlbum>().compareMaps(left.getAlbumsMap(),
52                 right.getAlbumsMap());
53     }
54
55     /**
56      * Compare two {@link AxContextSchema} objects, comparing their context schemas one after
57      * another.
58      *
59      * @param left the left context
60      * @param right the right context
61      * @return the difference
62      */
63     public KeyedMapDifference<AxArtifactKey, AxContextSchema> compare(final AxContextSchemas left,
64             final AxContextSchemas right) {
65         // Find the difference between the AxContext objects
66         return new KeyedMapComparer<AxArtifactKey, AxContextSchema>().compareMaps(left.getSchemasMap(),
67                 right.getSchemasMap());
68     }
69
70 }