Tue, 10 Feb 2015 19:58:00 +0100
Upgrade the upgraded ical4j component to use org.apache.commons.lang3.
1 /**
2 * Copyright (c) 2012, Ben Fortuna
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * o Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * o Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * o Neither the name of Ben Fortuna nor the names of any other contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32 package net.fortuna.ical4j.model.property;
34 import net.fortuna.ical4j.model.ParameterList;
35 import net.fortuna.ical4j.model.Property;
36 import net.fortuna.ical4j.model.PropertyFactoryImpl;
37 import net.fortuna.ical4j.model.ValidationException;
39 /**
40 * $Id$
41 *
42 * Created: [Apr 6, 2004]
43 *
44 * Defines a VERSION iCalendar property. When creating a new calendar you should always add a version property with
45 * value "2.0". There is actually a constant defined in the Version class for this. e.g:
46 * <code> Calendar calendar = new Calendar();</code>
47 * <code> calendar.getProperties().add(Version.VERSION_2_0);</code>
48 * @author Ben Fortuna
49 */
50 public class Version extends Property {
52 private static final long serialVersionUID = 8872508067309087704L;
54 /**
55 * iCalendar version 2.0.
56 */
57 public static final Version VERSION_2_0 = new ImmutableVersion("2.0");
59 /**
60 * @author Ben Fortuna An immutable instance of Version.
61 */
62 private static final class ImmutableVersion extends Version {
64 private static final long serialVersionUID = -5040679357859594835L;
66 private ImmutableVersion(final String value) {
67 super(new ParameterList(true), value);
68 }
70 public void setValue(final String aValue) {
71 throw new UnsupportedOperationException(
72 "Cannot modify constant instances");
73 }
75 public void setMaxVersion(final String maxVersion) {
76 throw new UnsupportedOperationException(
77 "Cannot modify constant instances");
78 }
80 public void setMinVersion(final String minVersion) {
81 throw new UnsupportedOperationException(
82 "Cannot modify constant instances");
83 }
84 }
86 private String minVersion;
88 private String maxVersion;
90 /**
91 * Default constructor.
92 */
93 public Version() {
94 super(VERSION, PropertyFactoryImpl.getInstance());
95 }
97 /**
98 * @param aList a list of parameters for this component
99 * @param aValue a value string for this component
100 */
101 public Version(final ParameterList aList, final String aValue) {
102 super(VERSION, aList, PropertyFactoryImpl.getInstance());
103 if (aValue.indexOf(';') >= 0) {
104 this.minVersion = aValue.substring(0, aValue.indexOf(';') - 1);
105 this.maxVersion = aValue.substring(aValue.indexOf(';'));
106 }
107 else {
108 this.maxVersion = aValue;
109 }
110 }
112 /**
113 * @param minVersion a string representation of the minimum version
114 * @param maxVersion a string representation of the maximum version
115 */
116 public Version(final String minVersion, final String maxVersion) {
117 super(VERSION, PropertyFactoryImpl.getInstance());
118 this.minVersion = minVersion;
119 this.maxVersion = maxVersion;
120 }
122 /**
123 * @param aList a list of parameters for this component
124 * @param aVersion1 a string representation of the minimum version
125 * @param aVersion2 a string representation of the maximum version
126 */
127 public Version(final ParameterList aList, final String aVersion1,
128 final String aVersion2) {
129 super(VERSION, aList, PropertyFactoryImpl.getInstance());
130 minVersion = aVersion1;
131 maxVersion = aVersion2;
132 }
134 /**
135 * @return Returns the maxVersion.
136 */
137 public final String getMaxVersion() {
138 return maxVersion;
139 }
141 /**
142 * @return Returns the minVersion.
143 */
144 public final String getMinVersion() {
145 return minVersion;
146 }
148 /**
149 * {@inheritDoc}
150 */
151 public void setValue(final String aValue) {
152 if (aValue.indexOf(';') >= 0) {
153 this.minVersion = aValue.substring(0, aValue.indexOf(';') - 1);
154 this.maxVersion = aValue.substring(aValue.indexOf(';'));
155 }
156 else {
157 this.maxVersion = aValue;
158 }
159 }
161 /**
162 * {@inheritDoc}
163 */
164 public final String getValue() {
165 final StringBuffer b = new StringBuffer();
166 if (getMinVersion() != null) {
167 b.append(getMinVersion());
168 if (getMaxVersion() != null) {
169 b.append(';');
170 }
171 }
172 if (getMaxVersion() != null) {
173 b.append(getMaxVersion());
174 }
175 return b.toString();
176 }
178 /**
179 * @param maxVersion The maxVersion to set.
180 */
181 public void setMaxVersion(final String maxVersion) {
182 this.maxVersion = maxVersion;
183 }
185 /**
186 * @param minVersion The minVersion to set.
187 */
188 public void setMinVersion(final String minVersion) {
189 this.minVersion = minVersion;
190 }
192 /**
193 * {@inheritDoc}
194 */
195 public final void validate() throws ValidationException {
196 // TODO: Auto-generated method stub
197 }
198 }