001    package biweekly.property;
002    
003    /*
004     Copyright (c) 2013, Michael Angstadt
005     All rights reserved.
006    
007     Redistribution and use in source and binary forms, with or without
008     modification, are permitted provided that the following conditions are met: 
009    
010     1. Redistributions of source code must retain the above copyright notice, this
011     list of conditions and the following disclaimer. 
012     2. Redistributions in binary form must reproduce the above copyright notice,
013     this list of conditions and the following disclaimer in the documentation
014     and/or other materials provided with the distribution. 
015    
016     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
017     ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
018     WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
019     DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
020     ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
021     (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
022     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
023     ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
024     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
025     SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
026     */
027    
028    /**
029     * <p>
030     * Defines the level of sensitivity of the iCalendar data. If not specified, the
031     * data within the iCalendar object should be considered "public".
032     * </p>
033     * <p>
034     * <b>Examples:</b>
035     * 
036     * <pre>
037     * Classification clazz = Classification.public_();
038     * 
039     * if (clazz.isPublic()) {
040     *       ...
041     * }
042     * </pre>
043     * 
044     * </p>
045     * @author Michael Angstadt
046     * @see <a href="http://tools.ietf.org/html/rfc5545#page-82">RFC 5545 p.82-3</a>
047     */
048    public class Classification extends TextProperty {
049            private static final String PUBLIC = "PUBLIC";
050            private static final String PRIVATE = "PRIVATE";
051            private static final String CONFIDENTIAL = "CONFIDENTIAL";
052    
053            /**
054             * Creates a new classification property. Use the static factory methods to
055             * create a property with a standard classification level.
056             * @param classification the classification level (e.g. "PUBLIC")
057             */
058            public Classification(String classification) {
059                    super(classification);
060            }
061    
062            /**
063             * Creates a "public" classification property.
064             * @return the property
065             */
066            public static Classification public_() {
067                    return create(PUBLIC);
068            }
069    
070            /**
071             * Determines if the classification level is "public".
072             * @return true if it's "public", false if not
073             */
074            public boolean isPublic() {
075                    return is(PUBLIC);
076            }
077    
078            /**
079             * Creates a "private" classification property.
080             * @return the property
081             */
082            public static Classification private_() {
083                    return create(PRIVATE);
084            }
085    
086            /**
087             * Determines if the classification level is "private".
088             * @return true if it's "private", false if not
089             */
090            public boolean isPrivate() {
091                    return is(PRIVATE);
092            }
093    
094            /**
095             * Creates a "confidential" classification property.
096             * @return the property
097             */
098            public static Classification confidential() {
099                    return create(CONFIDENTIAL);
100            }
101    
102            /**
103             * Determines if the classification level is "confidential".
104             * @return true if it's "confidential", false if not
105             */
106            public boolean isConfidential() {
107                    return is(CONFIDENTIAL);
108            }
109    
110            private static Classification create(String classification) {
111                    return new Classification(classification);
112            }
113    
114            private boolean is(String classification) {
115                    return classification.equalsIgnoreCase(value);
116            }
117    }