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.apache.commons.lang.builder.EqualsBuilder;
023import org.apache.commons.lang.builder.HashCodeBuilder;
024import org.apache.commons.lang.builder.ToStringBuilder;
025import org.sonar.api.resources.Resource;
026import org.sonar.graph.Edge;
027
028/**
029 * @deprecated since 5.2 No more design features
030 */
031@Deprecated
032public class Dependency implements Edge<Resource> {
033
034  private Resource from;
035  private Resource to;
036  private String usage;
037  private int weight;
038  private Dependency parent;
039  private Long id;
040
041  public Dependency(Resource from, Resource to) {
042    if (from == null) {
043      throw new IllegalArgumentException("Dependency source is null");
044    }
045    if (to == null) {
046      throw new IllegalArgumentException("Dependency target is null");
047    }
048    this.from = from;
049    this.to = to;
050  }
051
052  @Override
053  public Resource getFrom() {
054    return from;
055  }
056
057  /**
058   * For internal use only
059   */
060  public void setFrom(Resource from) {
061    this.from = from;
062  }
063
064  @Override
065  public Resource getTo() {
066    return to;
067  }
068
069  /**
070   * For internal use only
071   */
072  public void setTo(Resource to) {
073    this.to = to;
074  }
075
076  public String getUsage() {
077    return usage;
078  }
079
080  public Dependency setUsage(String usage) {
081    this.usage = usage;
082    return this;
083  }
084
085  @Override
086  public int getWeight() {
087    return weight;
088  }
089
090  public Dependency setWeight(int weight) {
091    this.weight = weight;
092    return this;
093  }
094
095  public Dependency getParent() {
096    return parent;
097  }
098
099  public Dependency setParent(Dependency parent) {
100    this.parent = parent;
101    return this;
102  }
103
104  public Long getId() {
105    return id;
106  }
107
108  /**
109   * Internal use only.
110   */
111  public Dependency setId(Long id) {
112    this.id = id;
113    return this;
114  }
115
116  @Override
117  public boolean equals(Object obj) {
118    if (!(obj instanceof Dependency)) {
119      return false;
120    }
121    if (this == obj) {
122      return true;
123    }
124    Dependency other = (Dependency) obj;
125    return new EqualsBuilder()
126      .append(from, other.from)
127      .append(to, other.to)
128      .isEquals();
129  }
130
131  @Override
132  public int hashCode() {
133    return new HashCodeBuilder(17, 37)
134      .append(from)
135      .append(to)
136      .toHashCode();
137  }
138
139  @Override
140  public String toString() {
141    return new ToStringBuilder(this)
142      .append("from", from)
143      .append("to", to)
144      .append("weight", weight)
145      .append("usage", usage)
146      .toString();
147  }
148}