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