001/* 002 * SonarQube 003 * Copyright (C) 2009-2017 SonarSource SA 004 * mailto:info AT sonarsource DOT com 005 * 006 * This program is free software; you can redistribute it and/or 007 * modify it under the terms of the GNU Lesser General Public 008 * License as published by the Free Software Foundation; either 009 * version 3 of the License, or (at your option) any later version. 010 * 011 * This program is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 * Lesser General Public License for more details. 015 * 016 * You should have received a copy of the GNU Lesser General Public License 017 * along with this program; if not, write to the Free Software Foundation, 018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 019 */ 020package org.sonar.api.design; 021 022import org.sonar.api.resources.Resource; 023import org.sonar.graph.Edge; 024 025/** 026 * @deprecated since 5.2 No more design features 027 */ 028@Deprecated 029public class Dependency implements Edge<Resource> { 030 031 private Resource from; 032 private Resource to; 033 private String usage; 034 private int weight; 035 private Dependency parent; 036 private Long id; 037 038 public Dependency(Resource from, Resource to) { 039 if (from == null) { 040 throw new IllegalArgumentException("Dependency source is null"); 041 } 042 if (to == null) { 043 throw new IllegalArgumentException("Dependency target is null"); 044 } 045 this.from = from; 046 this.to = to; 047 } 048 049 @Override 050 public Resource getFrom() { 051 return from; 052 } 053 054 /** 055 * For internal use only 056 */ 057 public void setFrom(Resource from) { 058 this.from = from; 059 } 060 061 @Override 062 public Resource getTo() { 063 return to; 064 } 065 066 /** 067 * For internal use only 068 */ 069 public void setTo(Resource to) { 070 this.to = to; 071 } 072 073 public String getUsage() { 074 return usage; 075 } 076 077 public Dependency setUsage(String usage) { 078 this.usage = usage; 079 return this; 080 } 081 082 @Override 083 public int getWeight() { 084 return weight; 085 } 086 087 public Dependency setWeight(int weight) { 088 this.weight = weight; 089 return this; 090 } 091 092 public Dependency getParent() { 093 return parent; 094 } 095 096 public Dependency setParent(Dependency parent) { 097 this.parent = parent; 098 return this; 099 } 100 101 public Long getId() { 102 return id; 103 } 104 105 /** 106 * Internal use only. 107 */ 108 public Dependency setId(Long id) { 109 this.id = id; 110 return this; 111 } 112 113 @Override 114 public boolean equals(Object o) { 115 if (this == o) { 116 return true; 117 } 118 if (o == null || getClass() != o.getClass()) { 119 return false; 120 } 121 Dependency that = (Dependency) o; 122 if (!from.equals(that.from)) { 123 return false; 124 } 125 return to.equals(that.to); 126 } 127 128 @Override 129 public int hashCode() { 130 int result = from.hashCode(); 131 result = 31 * result + to.hashCode(); 132 return result; 133 } 134 135 @Override 136 public String toString() { 137 StringBuilder sb = new StringBuilder("Dependency{"); 138 sb.append("from=").append(from); 139 sb.append(", to=").append(to); 140 sb.append(", usage='").append(usage).append('\''); 141 sb.append(", weight=").append(weight); 142 sb.append(", parent=").append(parent); 143 sb.append(", id=").append(id); 144 sb.append('}'); 145 return sb.toString(); 146 } 147}