001package biweekly.property;
002
003import java.util.Arrays;
004import java.util.Collection;
005
006import biweekly.ICalVersion;
007
008/*
009 Copyright (c) 2013-2017, 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 * <p>
040 * <b>Code sample (creating):</b>
041 * </p>
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 * <b>Code sample (retrieving):</b>
055 * </p>
056 * 
057 * <pre class="brush:java">
058 * ICalendar ical = ...
059 * for (VEvent event : ical.getEvents()) {
060 *   Transparency transp = event.getTransparency();
061 *   if (transp.isOpaque()) {
062 *     //...
063 *   } else if (transp.isTransparent()) {
064 *     //...
065 *   }
066 * }
067 * </pre>
068 * @author Michael Angstadt
069 * @see <a href="http://tools.ietf.org/html/rfc5545#page-101">RFC 5545
070 * p.101-2</a>
071 * @see <a href="http://tools.ietf.org/html/rfc2445#page-96">RFC 2445 p.96-7</a>
072 * @see <a href="http://www.imc.org/pdi/vcal-10.doc">vCal 1.0 p.36-7</a>
073 */
074public class Transparency extends EnumProperty {
075        public static final String OPAQUE = "OPAQUE";
076        public static final String TRANSPARENT = "TRANSPARENT";
077
078        /**
079         * Creates a new transparency property.
080         * @param value the value
081         */
082        public Transparency(String value) {
083                super(value);
084        }
085
086        /**
087         * Copy constructor.
088         * @param original the property to make a copy of
089         */
090        public Transparency(Transparency original) {
091                super(original);
092        }
093
094        /**
095         * Creates a property that marks the event as being visible to free/busy
096         * time searches.
097         * @return the property
098         */
099        public static Transparency opaque() {
100                return create(OPAQUE);
101        }
102
103        /**
104         * Determines if the event is visible to free/busy time searches.
105         * @return true if it's visible, false if not
106         */
107        public boolean isOpaque() {
108                return is(OPAQUE);
109        }
110
111        /**
112         * Creates a property that marks the event as being hidden from free/busy
113         * time searches.
114         * @return the property
115         */
116        public static Transparency transparent() {
117                return create(TRANSPARENT);
118        }
119
120        /**
121         * Determines if the event is hidden from free/busy time searches.
122         * @return true if it's hidden, false if not
123         */
124        public boolean isTransparent() {
125                return is(TRANSPARENT);
126        }
127
128        private static Transparency create(String value) {
129                return new Transparency(value);
130        }
131
132        @Override
133        protected Collection<String> getStandardValues(ICalVersion version) {
134                return Arrays.asList(OPAQUE, TRANSPARENT);
135        }
136
137        @Override
138        public Transparency copy() {
139                return new Transparency(this);
140        }
141}