001 /*
002 * Sonar, open source software quality management tool.
003 * Copyright (C) 2009 SonarSource SA
004 * mailto:contact AT sonarsource DOT com
005 *
006 * Sonar 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 * Sonar 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
017 * License along with Sonar; if not, write to the Free Software
018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
019 */
020 package org.sonar.api.resources;
021
022 /**
023 * Inherit this class to define a new language like PLSQL, PHP or C#
024 *
025 * @since 1.10
026 */
027 public abstract class AbstractLanguage implements Language {
028 private final String key;
029 private String name;
030
031 /**
032 * Better to use AbstractLanguage(key, name). In this case, key and name will be the same
033 */
034 public AbstractLanguage(String key) {
035 this(key, key);
036 }
037
038 /**
039 * Should be the constructor used to build an AbstractLanguage.
040 *
041 * @param key the key that will be used to retrieve the language. This key is important as it will be used to teint rules repositories...
042 * @param name the display name of the language in the interface
043 */
044 public AbstractLanguage(String key, String name) {
045 this.key = key.toLowerCase();
046 this.name = name;
047 }
048
049 /**
050 * {@inheritDoc}
051 */
052 public String getKey() {
053 return key;
054 }
055
056 /**
057 * {@inheritDoc}
058 */
059 public String getName() {
060 return name;
061 }
062
063 /**
064 * Sets the language name
065 */
066 public void setName(String name) {
067 this.name = name;
068 }
069
070 @Override
071 public boolean equals(Object o) {
072 if (this == o) {
073 return true;
074 }
075 if (o == null || getClass() != o.getClass()) {
076 return false;
077 }
078
079 Language language = (Language) o;
080 return !(key != null ? !key.equals(language.getKey()) : language.getKey() != null);
081
082 }
083
084 @Override
085 public int hashCode() {
086 return (key != null ? key.hashCode() : 0);
087 }
088
089 @Override
090 public String toString() {
091 return name;
092 }
093 }