001    package ezvcard.types;
002    
003    import ezvcard.VCardSubTypes;
004    import ezvcard.VCardVersion;
005    import ezvcard.parameters.HobbyLevelParameter;
006    
007    /*
008     Copyright (c) 2012, Michael Angstadt
009     All rights reserved.
010    
011     Redistribution and use in source and binary forms, with or without
012     modification, are permitted provided that the following conditions are met: 
013    
014     1. Redistributions of source code must retain the above copyright notice, this
015     list of conditions and the following disclaimer. 
016     2. Redistributions in binary form must reproduce the above copyright notice,
017     this list of conditions and the following disclaimer in the documentation
018     and/or other materials provided with the distribution. 
019    
020     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
021     ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
022     WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
023     DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
024     ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
025     (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
026     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
027     ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
028     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
029     SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
030    
031     The views and conclusions contained in the software and documentation are those
032     of the authors and should not be interpreted as representing official policies, 
033     either expressed or implied, of the FreeBSD Project.
034     */
035    
036    /**
037     * Defines a recreational activity that the person actively engages in. For
038     * example, if a person has a HOBBY of "hockey", it would mean that he likes to
039     * play hockey. Someone who just likes to <i>watch</i> hockey would list
040     * "hockey" as an INTEREST (see {@link InterestType}) instead.
041     * 
042     * <pre>
043     * //someone who likes to wind surf during the summer, but rents a boat instead of owning one
044     * VCard vcard = new VCard();
045     * HobbyType hobby = new HobbyType(&quot;wind surfing&quot;);
046     * hobby.setLevel(HobbyLevelParameter.LOW);
047     * vcard.addHobby(hobby);
048     * </pre>
049     * 
050     * <p>
051     * vCard property name: HOBBY
052     * </p>
053     * <p>
054     * vCard versions: 4.0
055     * </p>
056     * @author Michael Angstadt
057     * @see <a href="http://tools.ietf.org/html/rfc6715">RFC 6715</a>
058     */
059    public class HobbyType extends TextType {
060            public static final String NAME = "HOBBY";
061    
062            public HobbyType() {
063                    super(NAME);
064            }
065    
066            /**
067             * @param hobby the hobby (e.g. "wind surfing")
068             */
069            public HobbyType(String hobby) {
070                    super(NAME, hobby);
071            }
072    
073            @Override
074            public VCardVersion[] getSupportedVersions() {
075                    return new VCardVersion[] { VCardVersion.V4_0 };
076            }
077    
078            /**
079             * Gets the level at which the person practices the hobby.
080             * @return the skill level (e.g. "low") or null if not set
081             * @see VCardSubTypes#getLevel
082             */
083            public HobbyLevelParameter getLevel() {
084                    String value = subTypes.getLevel();
085                    if (value == null) {
086                            return null;
087                    }
088                    HobbyLevelParameter p = HobbyLevelParameter.valueOf(value);
089                    if (p == null) {
090                            p = new HobbyLevelParameter(value);
091                    }
092                    return p;
093            }
094    
095            /**
096             * Sets the level at which the person practices the hobby.
097             * @param level the level (e.g. "low") or null to remove
098             * @see VCardSubTypes#setLevel
099             */
100            public void setLevel(HobbyLevelParameter level) {
101                    subTypes.setLevel(level.getValue());
102            }
103    
104            /**
105             * Gets the INDEX parameter.
106             * @return the INDEX or null if not set
107             * @see VCardSubTypes#getIndex
108             */
109            public Integer getIndex() {
110                    return subTypes.getIndex();
111            }
112    
113            /**
114             * Sets the INDEX parameter.
115             * @param index the INDEX or null to remove
116             * @see VCardSubTypes#setIndex
117             */
118            public void setIndex(Integer index) {
119                    subTypes.setIndex(index);
120            }
121    
122            /**
123             * Gets the TYPE parameter.
124             * @return the TYPE value (typically, this will be either "work" or "home")
125             * or null if it doesn't exist
126             */
127            public String getType() {
128                    return subTypes.getType();
129            }
130    
131            /**
132             * Sets the TYPE parameter.
133             * @param type the TYPE value (this should be either "work" or "home") or
134             * null to remove
135             */
136            public void setType(String type) {
137                    subTypes.setType(type);
138            }
139    
140            /**
141             * Gets the language that the skill description is written in.
142             * @return the language or null if not set
143             * @see VCardSubTypes#getLanguage
144             */
145            public String getLanguage() {
146                    return subTypes.getLanguage();
147            }
148    
149            /**
150             * Sets the language that the skill description is written in.
151             * @param language the language or null to remove
152             * @see VCardSubTypes#setLanguage
153             */
154            public void setLanguage(String language) {
155                    subTypes.setLanguage(language);
156            }
157    
158            /**
159             * Gets the preference value.
160             * <p>
161             * vCard versions: 4.0
162             * </p>
163             * @return the preference value or null if it doesn't exist
164             * @see VCardSubTypes#getPref
165             */
166            public Integer getPref() {
167                    return subTypes.getPref();
168            }
169    
170            /**
171             * Sets the preference value.
172             * <p>
173             * vCard versions: 4.0
174             * </p>
175             * @param pref the preference value or null to remove
176             * @see VCardSubTypes#setPref
177             */
178            public void setPref(Integer pref) {
179                    subTypes.setPref(pref);
180            }
181    
182            /**
183             * Gets the ALTID.
184             * <p>
185             * vCard versions: 4.0
186             * </p>
187             * @return the ALTID or null if it doesn't exist
188             * @see VCardSubTypes#getAltId
189             */
190            public String getAltId() {
191                    return subTypes.getAltId();
192            }
193    
194            /**
195             * Sets the ALTID.
196             * <p>
197             * vCard versions: 4.0
198             * </p>
199             * @param altId the ALTID or null to remove
200             * @see VCardSubTypes#setAltId
201             */
202            public void setAltId(String altId) {
203                    subTypes.setAltId(altId);
204            }
205    }