001/* 002 * Licensed under the Apache License, Version 2.0 (the "License"); 003 * you may not use this file except in compliance with the License. 004 * You may obtain a copy of the License at 005 * 006 * http://www.apache.org/licenses/LICENSE-2.0 007 * 008 * Unless required by applicable law or agreed to in writing, software 009 * distributed under the License is distributed on an "AS IS" BASIS, 010 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 011 * See the License for the specific language governing permissions and 012 * limitations under the License. 013 */ 014 015package org.basepom.mojo.dvc.version; 016 017import org.basepom.mojo.dvc.QualifiedName; 018 019import java.util.Objects; 020 021import com.google.common.base.MoreObjects; 022 023public final class VersionResolutionElement 024 implements Comparable<VersionResolutionElement> { 025 026 /** 027 * Requesting Dependency name. 028 */ 029 private final QualifiedName requestingDependency; 030 031 /** 032 * True if the dependency was managed to this version. 033 */ 034 private final boolean managedDependency; 035 036 /** 037 * True if this version resolution is directly from the root project. 038 */ 039 private final boolean directDependency; 040 041 private boolean conflict = false; 042 043 VersionResolutionElement(final QualifiedName requestingDependency, final boolean managedDependency, final boolean directDependency) { 044 this.requestingDependency = requestingDependency; 045 this.managedDependency = managedDependency; 046 this.directDependency = directDependency; 047 } 048 049 public QualifiedName getRequestingDependency() { 050 return requestingDependency; 051 } 052 053 public boolean isManagedDependency() { 054 return managedDependency; 055 } 056 057 public boolean isDirectDependency() { 058 return directDependency; 059 } 060 061 public void conflict() { 062 this.conflict = true; 063 } 064 065 public boolean hasConflict() { 066 return conflict; 067 } 068 069 @Override 070 public boolean equals(final Object o) { 071 if (this == o) { 072 return true; 073 } 074 if (o == null || getClass() != o.getClass()) { 075 return false; 076 } 077 final VersionResolutionElement that = (VersionResolutionElement) o; 078 return managedDependency == that.managedDependency 079 && directDependency == that.directDependency 080 && requestingDependency.equals(that.requestingDependency); 081 } 082 083 @Override 084 public int hashCode() { 085 return Objects.hash(requestingDependency, managedDependency, directDependency); 086 } 087 088 @Override 089 public String toString() { 090 return MoreObjects.toStringHelper(this) 091 .add("requestingDependency", requestingDependency) 092 .add("managedDependency", managedDependency) 093 .add("directDependency", directDependency) 094 .add("conflict", conflict) 095 .toString(); 096 } 097 098 @Override 099 public int compareTo(final VersionResolutionElement other) { 100 if (other == null) { 101 return 1; 102 } else if (other == this || equals(other)) { 103 return 0; 104 } else { 105 return getRequestingDependency().getMinimalName().compareTo(other.getRequestingDependency().getMinimalName()); 106 } 107 } 108}