View Javadoc
1   /*
2    * The contents of this file are subject to the terms of the Common Development and
3    * Distribution License (the License). You may not use this file except in compliance with the
4    * License.
5    *
6    * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
7    * specific language governing permission and limitations under the License.
8    *
9    * When distributing Covered Software, include this CDDL Header Notice in each file and include
10   * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
11   * Header, with the fields enclosed by brackets [] replaced by your own identifying
12   * information: "Portions copyright [year] [name of copyright owner]".
13   *
14   * Copyright 2016 ForgeRock AS.
15   */
16  
17  package org.forgerock.api.transform;
18  
19  import java.util.Objects;
20  
21  import org.forgerock.util.i18n.LocalizableString;
22  
23  import io.swagger.models.properties.DateTimeProperty;
24  import io.swagger.models.properties.Property;
25  
26  /**
27   * Localizable {@link DateTimeProperty}.
28   */
29  class LocalizableDateTimeProperty extends DateTimeProperty implements LocalizableProperty<Property> {
30      private LocalizableString title;
31      private LocalizableString description;
32      private String defaultValue;
33  
34      @Override
35      public LocalizableDateTimeProperty title(LocalizableString title) {
36          this.title = title;
37          return this;
38      }
39  
40      @Override
41      public LocalizableDateTimeProperty description(LocalizableString desc) {
42          this.description = desc;
43          return this;
44      }
45  
46      @Override
47      public LocalizableDateTimeProperty title(String title) {
48          setTitle(title);
49          return this;
50      }
51  
52      @Override
53      public void setTitle(String title) {
54          super.setTitle(title);
55          this.title = new LocalizableString(title);
56      }
57  
58      @Override
59      public LocalizableDateTimeProperty description(String description) {
60          setDescription(description);
61          return this;
62      }
63  
64      @Override
65      public void setDescription(String description) {
66          super.setDescription(description);
67          this.description = new LocalizableString(description);
68      }
69  
70      @Override
71      public LocalizableString getLocalizableTitle() {
72          return title;
73      }
74  
75      @Override
76      public LocalizableString getLocalizableDescription() {
77          return description;
78      }
79  
80      /**
81       * Sets the default value, which should be in ISO 8601 date-time format.
82       *
83       * @param defaultValue Default value or {@code null}
84       */
85      @Override
86      public void setDefault(String defaultValue) {
87          this.defaultValue = defaultValue;
88      }
89  
90      /**
91       * Gets the default value.
92       *
93       * @return Default value or {@code null}
94       */
95      public String getDefault() {
96          return defaultValue;
97      }
98  
99      @Override
100     public boolean equals(final Object o) {
101         if (!super.equals(o)) {
102             return false;
103         }
104         if (!(o instanceof LocalizableDateTimeProperty)) {
105             return false;
106         }
107         final LocalizableDateTimeProperty other = (LocalizableDateTimeProperty) o;
108         if (!Objects.equals(defaultValue, other.defaultValue)) {
109             return false;
110         }
111         if (!Objects.equals(title, other.title)) {
112             return false;
113         }
114         if (!Objects.equals(description, other.description)) {
115             return false;
116         }
117         return true;
118     }
119 
120     @Override
121     public int hashCode() {
122         return Objects.hash(super.hashCode(), title, description, defaultValue);
123     }
124 
125 }