View Javadoc
1   /**
2    * This file is part of Indicators.
3    *
4    * Indicators is free software: you can redistribute it and/or modify
5    * it under the terms of the GNU General Public License as published by
6    * the Free Software Foundation, either version 3 of the License, or
7    * (at your option) any later version.
8    *
9    * Indicators is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   * GNU General Public License for more details.
13   *
14   * You should have received a copy of the GNU General Public License
15   * along with Indicators. If not, see <https://www.gnu.org/licenses/>.
16   */
17  package fr.inrae.agroclim.indicators.model;
18  
19  import java.io.Serializable;
20  import java.util.ArrayList;
21  import java.util.List;
22  
23  import jakarta.xml.bind.annotation.XmlAccessType;
24  import jakarta.xml.bind.annotation.XmlAccessorType;
25  import jakarta.xml.bind.annotation.XmlElement;
26  import lombok.EqualsAndHashCode;
27  import lombok.Getter;
28  import lombok.Setter;
29  
30  /**
31   * Parameter for indicator or indicator criteria.
32   *
33   * Last change $Date$
34   *
35   * @author $Author$
36   * @version $Revision$
37   */
38  @XmlAccessorType(XmlAccessType.FIELD)
39  @EqualsAndHashCode(
40          callSuper = false,
41          of = {"id", "attribute", "descriptions"}
42          )
43  public final class Parameter implements Cloneable, Serializable {
44  
45      /**
46       * UUID for Serializable.
47       */
48      private static final long serialVersionUID = 9205643160821888601L;
49  
50      /**
51       * Attribute to change.
52       */
53      @XmlElement
54      @Getter
55      @Setter
56      private String attribute;
57  
58      /**
59       * Localized descriptions.
60       */
61      @XmlElement(name = "description")
62      @Getter
63      @Setter
64      private List<LocalizedString> descriptions;
65  
66      /**
67       * Parameter id.
68       */
69      @XmlElement
70      @Getter
71      @Setter
72      private String id;
73  
74      /**
75       * Constructor.
76       */
77      public Parameter() {
78          // Do nothing
79      }
80  
81      @Override
82      public Parameter clone() throws CloneNotSupportedException {
83          final Parameter clone = (Parameter) super.clone();
84          clone.attribute = attribute;
85          if (descriptions != null) {
86              clone.descriptions = new ArrayList<>();
87              for (final LocalizedString description : descriptions) {
88                  clone.descriptions.add(description.clone());
89              }
90          }
91          clone.id = id;
92          return clone;
93      }
94  
95      /**
96       * @param languageCode lang code
97       * @return description for the lang
98       */
99      public String getDescription(final String languageCode) {
100         return LocalizedString.getString(descriptions, languageCode);
101     }
102 
103 }