Revert "Bug 4640: Change semantic-version to openconfig-version"
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / effective / ModuleImportImpl.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
9
10 import com.google.common.base.Preconditions;
11 import java.util.Date;
12 import java.util.Objects;
13 import org.opendaylight.yangtools.concepts.SemVer;
14 import org.opendaylight.yangtools.yang.model.api.Module;
15 import org.opendaylight.yangtools.yang.model.api.ModuleImport;
16
17 final class ModuleImportImpl implements ModuleImport {
18     private final String moduleName;
19     private final Date revision;
20     private final SemVer semVer;
21     private final String prefix;
22
23     public ModuleImportImpl(final String moduleName, final Date revision, final String prefix) {
24         this(moduleName, revision, prefix, Module.DEFAULT_SEMANTIC_VERSION);
25     }
26
27     public ModuleImportImpl(final String moduleName, final Date revision, final String prefix, final SemVer semVer) {
28         this.moduleName = Preconditions.checkNotNull(moduleName, "Module name must not be null.");
29         this.revision = revision;
30         this.prefix = Preconditions.checkNotNull(prefix, "Import prefix must not be null.");
31         this.semVer = Preconditions.checkNotNull(semVer, "Semantic version of module must not be null.");
32     }
33
34     @Override
35     public String getModuleName() {
36         return moduleName;
37     }
38
39     @Override
40     public Date getRevision() {
41         return revision;
42     }
43
44     @Override
45     public SemVer getSemanticVersion() {
46         return semVer;
47     }
48
49     @Override
50     public String getPrefix() {
51         return prefix;
52     }
53
54     @Override
55     public int hashCode() {
56         final int prime = 31;
57         int result = 1;
58         result = prime * result + Objects.hashCode(moduleName);
59         result = prime * result + Objects.hashCode(revision);
60         result = prime * result + Objects.hashCode(prefix);
61         result = prime * result + Objects.hashCode(semVer);
62         return result;
63     }
64
65     @Override
66     public boolean equals(final Object obj) {
67         if (this == obj) {
68             return true;
69         }
70         if (obj == null) {
71             return false;
72         }
73         if (getClass() != obj.getClass()) {
74             return false;
75         }
76         ModuleImport other = (ModuleImport) obj;
77         if (!Objects.equals(getModuleName(), other.getModuleName())) {
78             return false;
79         }
80         if (!Objects.equals(getRevision(), other.getRevision())) {
81             return false;
82         }
83         if (!Objects.equals(getPrefix(), other.getPrefix())) {
84             return false;
85         }
86         if (!Objects.equals(getSemanticVersion(), other.getSemanticVersion())) {
87             return false;
88         }
89         return true;
90     }
91
92     @Override
93     public String toString() {
94         return "ModuleImport[moduleName=" + moduleName + ", revision=" + revision + ", prefix=" + prefix + "]";
95     }
96
97 }
98