src/net/fortuna/ical4j/model/property/Version.java

changeset 0
fb9019fb1bf7
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/net/fortuna/ical4j/model/property/Version.java	Tue Feb 10 18:12:00 2015 +0100
     1.3 @@ -0,0 +1,198 @@
     1.4 +/**
     1.5 + * Copyright (c) 2012, Ben Fortuna
     1.6 + * All rights reserved.
     1.7 + *
     1.8 + * Redistribution and use in source and binary forms, with or without
     1.9 + * modification, are permitted provided that the following conditions
    1.10 + * are met:
    1.11 + *
    1.12 + *  o Redistributions of source code must retain the above copyright
    1.13 + * notice, this list of conditions and the following disclaimer.
    1.14 + *
    1.15 + *  o Redistributions in binary form must reproduce the above copyright
    1.16 + * notice, this list of conditions and the following disclaimer in the
    1.17 + * documentation and/or other materials provided with the distribution.
    1.18 + *
    1.19 + *  o Neither the name of Ben Fortuna nor the names of any other contributors
    1.20 + * may be used to endorse or promote products derived from this software
    1.21 + * without specific prior written permission.
    1.22 + *
    1.23 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    1.24 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    1.25 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    1.26 + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
    1.27 + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
    1.28 + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
    1.29 + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
    1.30 + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
    1.31 + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
    1.32 + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    1.33 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    1.34 + */
    1.35 +package net.fortuna.ical4j.model.property;
    1.36 +
    1.37 +import net.fortuna.ical4j.model.ParameterList;
    1.38 +import net.fortuna.ical4j.model.Property;
    1.39 +import net.fortuna.ical4j.model.PropertyFactoryImpl;
    1.40 +import net.fortuna.ical4j.model.ValidationException;
    1.41 +
    1.42 +/**
    1.43 + * $Id$
    1.44 + *
    1.45 + * Created: [Apr 6, 2004]
    1.46 + *
    1.47 + * Defines a VERSION iCalendar property. When creating a new calendar you should always add a version property with
    1.48 + * value "2.0". There is actually a constant defined in the Version class for this. e.g:
    1.49 + * <code>    Calendar calendar = new Calendar();</code>
    1.50 + * <code>    calendar.getProperties().add(Version.VERSION_2_0);</code>
    1.51 + * @author Ben Fortuna
    1.52 + */
    1.53 +public class Version extends Property {
    1.54 +
    1.55 +    private static final long serialVersionUID = 8872508067309087704L;
    1.56 +
    1.57 +    /**
    1.58 +     * iCalendar version 2.0.
    1.59 +     */
    1.60 +    public static final Version VERSION_2_0 = new ImmutableVersion("2.0");
    1.61 +
    1.62 +    /**
    1.63 +     * @author Ben Fortuna An immutable instance of Version.
    1.64 +     */
    1.65 +    private static final class ImmutableVersion extends Version {
    1.66 +
    1.67 +        private static final long serialVersionUID = -5040679357859594835L;
    1.68 +
    1.69 +        private ImmutableVersion(final String value) {
    1.70 +            super(new ParameterList(true), value);
    1.71 +        }
    1.72 +
    1.73 +        public void setValue(final String aValue) {
    1.74 +            throw new UnsupportedOperationException(
    1.75 +                    "Cannot modify constant instances");
    1.76 +        }
    1.77 +
    1.78 +        public void setMaxVersion(final String maxVersion) {
    1.79 +            throw new UnsupportedOperationException(
    1.80 +                    "Cannot modify constant instances");
    1.81 +        }
    1.82 +
    1.83 +        public void setMinVersion(final String minVersion) {
    1.84 +            throw new UnsupportedOperationException(
    1.85 +                    "Cannot modify constant instances");
    1.86 +        }
    1.87 +    }
    1.88 +
    1.89 +    private String minVersion;
    1.90 +
    1.91 +    private String maxVersion;
    1.92 +
    1.93 +    /**
    1.94 +     * Default constructor.
    1.95 +     */
    1.96 +    public Version() {
    1.97 +        super(VERSION, PropertyFactoryImpl.getInstance());
    1.98 +    }
    1.99 +
   1.100 +    /**
   1.101 +     * @param aList a list of parameters for this component
   1.102 +     * @param aValue a value string for this component
   1.103 +     */
   1.104 +    public Version(final ParameterList aList, final String aValue) {
   1.105 +        super(VERSION, aList, PropertyFactoryImpl.getInstance());
   1.106 +        if (aValue.indexOf(';') >= 0) {
   1.107 +            this.minVersion = aValue.substring(0, aValue.indexOf(';') - 1);
   1.108 +            this.maxVersion = aValue.substring(aValue.indexOf(';'));
   1.109 +        }
   1.110 +        else {
   1.111 +            this.maxVersion = aValue;
   1.112 +        }
   1.113 +    }
   1.114 +
   1.115 +    /**
   1.116 +     * @param minVersion a string representation of the minimum version
   1.117 +     * @param maxVersion a string representation of the maximum version
   1.118 +     */
   1.119 +    public Version(final String minVersion, final String maxVersion) {
   1.120 +        super(VERSION, PropertyFactoryImpl.getInstance());
   1.121 +        this.minVersion = minVersion;
   1.122 +        this.maxVersion = maxVersion;
   1.123 +    }
   1.124 +
   1.125 +    /**
   1.126 +     * @param aList a list of parameters for this component
   1.127 +     * @param aVersion1 a string representation of the minimum version
   1.128 +     * @param aVersion2 a string representation of the maximum version
   1.129 +     */
   1.130 +    public Version(final ParameterList aList, final String aVersion1,
   1.131 +            final String aVersion2) {
   1.132 +        super(VERSION, aList, PropertyFactoryImpl.getInstance());
   1.133 +        minVersion = aVersion1;
   1.134 +        maxVersion = aVersion2;
   1.135 +    }
   1.136 +
   1.137 +    /**
   1.138 +     * @return Returns the maxVersion.
   1.139 +     */
   1.140 +    public final String getMaxVersion() {
   1.141 +        return maxVersion;
   1.142 +    }
   1.143 +
   1.144 +    /**
   1.145 +     * @return Returns the minVersion.
   1.146 +     */
   1.147 +    public final String getMinVersion() {
   1.148 +        return minVersion;
   1.149 +    }
   1.150 +
   1.151 +    /**
   1.152 +     * {@inheritDoc}
   1.153 +     */
   1.154 +    public void setValue(final String aValue) {
   1.155 +        if (aValue.indexOf(';') >= 0) {
   1.156 +            this.minVersion = aValue.substring(0, aValue.indexOf(';') - 1);
   1.157 +            this.maxVersion = aValue.substring(aValue.indexOf(';'));
   1.158 +        }
   1.159 +        else {
   1.160 +            this.maxVersion = aValue;
   1.161 +        }
   1.162 +    }
   1.163 +
   1.164 +    /**
   1.165 +     * {@inheritDoc}
   1.166 +     */
   1.167 +    public final String getValue() {
   1.168 +        final StringBuffer b = new StringBuffer();
   1.169 +        if (getMinVersion() != null) {
   1.170 +            b.append(getMinVersion());
   1.171 +            if (getMaxVersion() != null) {
   1.172 +                b.append(';');
   1.173 +            }
   1.174 +        }
   1.175 +        if (getMaxVersion() != null) {
   1.176 +            b.append(getMaxVersion());
   1.177 +        }
   1.178 +        return b.toString();
   1.179 +    }
   1.180 +
   1.181 +    /**
   1.182 +     * @param maxVersion The maxVersion to set.
   1.183 +     */
   1.184 +    public void setMaxVersion(final String maxVersion) {
   1.185 +        this.maxVersion = maxVersion;
   1.186 +    }
   1.187 +
   1.188 +    /**
   1.189 +     * @param minVersion The minVersion to set.
   1.190 +     */
   1.191 +    public void setMinVersion(final String minVersion) {
   1.192 +        this.minVersion = minVersion;
   1.193 +    }
   1.194 +
   1.195 +    /**
   1.196 +     * {@inheritDoc}
   1.197 +     */
   1.198 +    public final void validate() throws ValidationException {
   1.199 +        // TODO: Auto-generated method stub
   1.200 +    }
   1.201 +}

mercurial