2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.models.tosca.authorative.concepts;
23 import lombok.AllArgsConstructor;
25 import lombok.NoArgsConstructor;
26 import lombok.NonNull;
27 import org.apache.commons.lang3.ObjectUtils;
28 import org.onap.policy.models.base.PfConceptKey;
29 import org.onap.policy.models.base.PfKey;
32 * Concept with an optional name and version.
37 public class ToscaNameVersion {
41 private String version;
43 public ToscaNameVersion(@NonNull PfKey key) {
44 this.name = key.getName();
45 this.version = key.getVersion();
48 public ToscaNameVersion(ToscaNameVersion source) {
49 this.name = source.name;
50 this.version = source.version;
54 * Create a PfConcceptKey from the TOSCA identifier.
58 public PfConceptKey asConceptKey() {
59 return new PfConceptKey(name, version);
62 protected int commonCompareTo(ToscaNameVersion other) {
71 if (getClass() != other.getClass()) {
72 return getClass().getSimpleName().compareTo(other.getClass().getSimpleName());
75 int result = ObjectUtils.compare(getName(), other.getName());
80 return ObjectUtils.compare(getVersion(), other.getVersion());
84 public String toString() {
85 return this.name + " " + this.version;