View Javadoc

1   /*
2    * Copyright 2012-2013 smartics, Kronseder & Reiner GmbH
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package de.smartics.properties.api.core.domain;
17  
18  import java.io.Serializable;
19  
20  /**
21   * The comment to a property.
22   */
23  public final class PropertyComment implements Serializable
24  {
25    // ********************************* Fields *********************************
26  
27    // --- constants ------------------------------------------------------------
28  
29    /**
30     * The class version identifier.
31     */
32    private static final long serialVersionUID = 1L;
33  
34    /**
35     * The empty comment instance. Can be used if no comment for a property is
36     * accessible.
37     */
38    public static final PropertyComment EMPTY_COMMENT = new PropertyComment(
39        new Builder());
40  
41    // --- members --------------------------------------------------------------
42  
43    /**
44     * The text of the comment.
45     *
46     * @serial
47     */
48    private final String text;
49  
50    /**
51     * The comment of the property values.
52     *
53     * @serial
54     */
55    private final PropertyValueComment valueComment;
56  
57    // ****************************** Initializer *******************************
58  
59    // ****************************** Constructors ******************************
60  
61    private PropertyComment(final Builder builder)
62    {
63      this.text = builder.text;
64      this.valueComment = builder.valueComment;
65    }
66  
67    // ****************************** Inner Classes *****************************
68  
69    /**
70     * The property comment instance builder.
71     */
72    public static final class Builder
73    {
74      // ******************************** Fields ********************************
75  
76      // --- constants ----------------------------------------------------------
77  
78      // --- members ------------------------------------------------------------
79  
80      /**
81       * The text of the comment.
82       */
83      private String text;
84  
85      /**
86       * The comment of the property values.
87       */
88      private PropertyValueComment valueComment;
89  
90      // ***************************** Initializer ******************************
91  
92      // ***************************** Constructors *****************************
93  
94      // ***************************** Inner Classes ****************************
95  
96      // ******************************** Methods *******************************
97  
98      // --- init ---------------------------------------------------------------
99  
100     // --- get&set ------------------------------------------------------------
101 
102     /**
103      * Sets the text of the comment.
104      *
105      * @param text the text of the comment.
106      * @return the reference to the builder instance.
107      */
108     public Builder withText(final String text)
109     {
110       this.text = text;
111       return this;
112     }
113 
114     /**
115      * Sets the comment of the property values.
116      *
117      * @param valueComment the comment of the property values.
118      * @return the reference to the builder instance.
119      */
120     public Builder with(final PropertyValueComment valueComment)
121     {
122       this.valueComment = valueComment;
123       return this;
124     }
125 
126     // --- business -----------------------------------------------------------
127 
128     /**
129      * Creates the property comment instance.
130      *
131      * @return the property comment instance.
132      */
133     public PropertyComment build()
134     {
135       return new PropertyComment(this);
136     }
137 
138     // --- object basics ------------------------------------------------------
139   }
140 
141   // ********************************* Methods ********************************
142 
143   // --- init -----------------------------------------------------------------
144 
145   // --- get&set --------------------------------------------------------------
146 
147   /**
148    * Returns the text of the comment.
149    *
150    * @return the text of the comment.
151    */
152   public String getText()
153   {
154     return text;
155   }
156 
157   /**
158    * Returns the comment of the property values.
159    *
160    * @return the comment of the property values.
161    */
162   public PropertyValueComment getValueComment()
163   {
164     return valueComment;
165   }
166 
167   // --- business -------------------------------------------------------------
168 
169   // --- object basics --------------------------------------------------------
170 
171   /**
172    * Returns the comment text.
173    *
174    * @return the comment text.
175    */
176   @Override
177   public String toString()
178   {
179     return text;
180   }
181 }