001package biweekly.property;
002
003import java.util.Arrays;
004import java.util.Collection;
005
006import biweekly.ICalVersion;
007
008/*
009 Copyright (c) 2013-2015, Michael Angstadt
010 All rights reserved.
011
012 Redistribution and use in source and binary forms, with or without
013 modification, are permitted provided that the following conditions are met: 
014
015 1. Redistributions of source code must retain the above copyright notice, this
016 list of conditions and the following disclaimer. 
017 2. Redistributions in binary form must reproduce the above copyright notice,
018 this list of conditions and the following disclaimer in the documentation
019 and/or other materials provided with the distribution. 
020
021 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
022 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
023 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
024 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
025 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
026 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
027 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
028 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
029 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
030 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
031 */
032
033/**
034 * <p>
035 * Defines whether an event is visible to free/busy time searches or not. If an
036 * event does not have this property, the event should be considered opaque
037 * (visible) to searches.
038 * </p>
039 * 
040 * <p>
041 * <b>Code sample (creating):</b>
042 * 
043 * <pre class="brush:java">
044 * VEvent event = new VEvent();
045 * 
046 * Transparency transp = Transparency.opaque();
047 * event.setTransparency(transp);
048 * 
049 * event.setTransparency(true); //hidden from searches
050 * event.setTransparency(false); //visible to searches
051 * </pre>
052 * 
053 * </p>
054 * 
055 * <p>
056 * <b>Code sample (retrieving):</b>
057 * 
058 * <pre class="brush:java">
059 * ICalendar ical = ...
060 * for (VEvent event : ical.getEvents()){
061 *   Transparency transp = event.getTransparency();
062 *   if (transp.isOpaque()) {
063 *         ...
064 *   } else if (transp.isTransparent()){
065 *     ...
066 *   }
067 * }
068 * </pre>
069 * 
070 * </p>
071 * @author Michael Angstadt
072 * @see <a href="http://tools.ietf.org/html/rfc5545#page-101">RFC 5545
073 * p.101-2</a>
074 * @see <a href="http://tools.ietf.org/html/rfc2445#page-96">RFC 2445 p.96-7</a>
075 * @see <a href="http://www.imc.org/pdi/vcal-10.doc">vCal 1.0 p.36-7</a>
076 */
077public class Transparency extends EnumProperty {
078        private static final String OPAQUE = "OPAQUE";
079        private static final String TRANSPARENT = "TRANSPARENT";
080
081        /**
082         * Creates a new transparency property.
083         * @param value the value
084         */
085        public Transparency(String value) {
086                super(value);
087        }
088
089        /**
090         * Creates a property that marks the event as being visible to free/busy
091         * time searches.
092         * @return the property
093         */
094        public static Transparency opaque() {
095                return create(OPAQUE);
096        }
097
098        /**
099         * Determines if the event is visible to free/busy time searches.
100         * @return true if it's visible, false if not
101         */
102        public boolean isOpaque() {
103                return is(OPAQUE);
104        }
105
106        /**
107         * Creates a property that marks the event as being hidden from free/busy
108         * time searches.
109         * @return the property
110         */
111        public static Transparency transparent() {
112                return create(TRANSPARENT);
113        }
114
115        /**
116         * Determines if the event is hidden from free/busy time searches.
117         * @return true if it's hidden, false if not
118         */
119        public boolean isTransparent() {
120                return is(TRANSPARENT);
121        }
122
123        private static Transparency create(String value) {
124                return new Transparency(value);
125        }
126
127        @Override
128        protected Collection<String> getStandardValues(ICalVersion version) {
129                return Arrays.asList(OPAQUE, TRANSPARENT);
130        }
131}