001/*
002 * SonarQube, open source software quality management tool.
003 * Copyright (C) 2008-2013 SonarSource
004 * mailto:contact AT sonarsource DOT com
005 *
006 * SonarQube 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 * SonarQube 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.resources;
021
022import org.apache.commons.lang.builder.ToStringBuilder;
023
024public final class Library extends Resource {
025
026  private String name;
027  private String description;
028  private String version;
029
030  public Library(String key, String version) {
031    setKey(key);
032    setDeprecatedKey(key);
033    this.version = version;
034  }
035
036  public String getVersion() {
037    return version;
038  }
039
040  public Library setName(String name) {
041    this.name = name;
042    return this;
043  }
044
045  public Library setDescription(String description) {
046    this.description = description;
047    return this;
048  }
049
050  @Override
051  public String getName() {
052    return name;
053  }
054
055  @Override
056  public String getLongName() {
057    return null;
058  }
059
060  @Override
061  public String getDescription() {
062    return description;
063  }
064
065  @Override
066  public Language getLanguage() {
067    return null;
068  }
069
070  @Override
071  public String getScope() {
072    return Scopes.PROJECT;
073  }
074
075  @Override
076  public String getQualifier() {
077    return Qualifiers.LIBRARY;
078  }
079
080  @Override
081  public Resource getParent() {
082    return null;
083  }
084
085  @Override
086  public boolean matchFilePattern(String antPattern) {
087    return false;
088  }
089
090  @Override
091  public boolean equals(Object o) {
092    if (this == o) {
093      return true;
094    }
095    if (o == null || getClass() != o.getClass()) {
096      return false;
097    }
098    Library library = (Library) o;
099    if (!getKey().equals(library.getKey())) {
100      return false;
101    }
102    return version.equals(library.version);
103  }
104
105  @Override
106  public int hashCode() {
107    int result = super.hashCode();
108    result = 31 * result + getKey().hashCode();
109    result = 31 * result + version.hashCode();
110    return result;
111  }
112
113  @Override
114  public String toString() {
115    return new ToStringBuilder(this)
116      .append("key", getKey())
117      .append("name", getName())
118      .append("version", version)
119      .toString();
120  }
121}