Tue, 10 Feb 2015 18:12:00 +0100
Import initial revisions of existing project AndroidCaldavSyncAdapater,
forked from upstream repository at 27e8a0f8495c92e0780d450bdf0c7cec77a03a55.
michael@0 | 1 | /** |
michael@0 | 2 | * Copyright (c) 2012, Ben Fortuna |
michael@0 | 3 | * All rights reserved. |
michael@0 | 4 | * |
michael@0 | 5 | * Redistribution and use in source and binary forms, with or without |
michael@0 | 6 | * modification, are permitted provided that the following conditions |
michael@0 | 7 | * are met: |
michael@0 | 8 | * |
michael@0 | 9 | * o Redistributions of source code must retain the above copyright |
michael@0 | 10 | * notice, this list of conditions and the following disclaimer. |
michael@0 | 11 | * |
michael@0 | 12 | * o Redistributions in binary form must reproduce the above copyright |
michael@0 | 13 | * notice, this list of conditions and the following disclaimer in the |
michael@0 | 14 | * documentation and/or other materials provided with the distribution. |
michael@0 | 15 | * |
michael@0 | 16 | * o Neither the name of Ben Fortuna nor the names of any other contributors |
michael@0 | 17 | * may be used to endorse or promote products derived from this software |
michael@0 | 18 | * without specific prior written permission. |
michael@0 | 19 | * |
michael@0 | 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
michael@0 | 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
michael@0 | 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
michael@0 | 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
michael@0 | 24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
michael@0 | 25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
michael@0 | 26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
michael@0 | 27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
michael@0 | 28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
michael@0 | 29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
michael@0 | 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
michael@0 | 31 | */ |
michael@0 | 32 | package net.fortuna.ical4j.model.property; |
michael@0 | 33 | |
michael@0 | 34 | import java.math.BigDecimal; |
michael@0 | 35 | |
michael@0 | 36 | import org.apache.commons.lang.StringUtils; |
michael@0 | 37 | |
michael@0 | 38 | import net.fortuna.ical4j.model.ParameterList; |
michael@0 | 39 | import net.fortuna.ical4j.model.Property; |
michael@0 | 40 | import net.fortuna.ical4j.model.PropertyFactoryImpl; |
michael@0 | 41 | import net.fortuna.ical4j.model.ValidationException; |
michael@0 | 42 | |
michael@0 | 43 | /** |
michael@0 | 44 | * $Id$ |
michael@0 | 45 | * |
michael@0 | 46 | * Created: [Apr 6, 2004] |
michael@0 | 47 | * |
michael@0 | 48 | * Defines a GEO iCalendar component property. |
michael@0 | 49 | * |
michael@0 | 50 | * <pre> |
michael@0 | 51 | * 4.8.1.6 Geographic Position |
michael@0 | 52 | * |
michael@0 | 53 | * Property Name: GEO |
michael@0 | 54 | * |
michael@0 | 55 | * Purpose: This property specifies information related to the global |
michael@0 | 56 | * position for the activity specified by a calendar component. |
michael@0 | 57 | * |
michael@0 | 58 | * Value Type: FLOAT. The value MUST be two SEMICOLON separated FLOAT |
michael@0 | 59 | * values. |
michael@0 | 60 | * |
michael@0 | 61 | * Property Parameters: Non-standard property parameters can be |
michael@0 | 62 | * specified on this property. |
michael@0 | 63 | * |
michael@0 | 64 | * Conformance: This property can be specified in "VEVENT" or "VTODO" |
michael@0 | 65 | * calendar components. |
michael@0 | 66 | * |
michael@0 | 67 | * Description: The property value specifies latitude and longitude, in |
michael@0 | 68 | * that order (i.e., "LAT LON" ordering). The longitude represents the |
michael@0 | 69 | * location east or west of the prime meridian as a positive or negative |
michael@0 | 70 | * real number, respectively. The longitude and latitude values MAY be |
michael@0 | 71 | * specified up to six decimal places, which will allow for accuracy to |
michael@0 | 72 | * within one meter of geographical position. Receiving applications |
michael@0 | 73 | * MUST accept values of this precision and MAY truncate values of |
michael@0 | 74 | * greater precision. |
michael@0 | 75 | * |
michael@0 | 76 | * Values for latitude and longitude shall be expressed as decimal |
michael@0 | 77 | * fractions of degrees. Whole degrees of latitude shall be represented |
michael@0 | 78 | * by a two-digit decimal number ranging from 0 through 90. Whole |
michael@0 | 79 | * degrees of longitude shall be represented by a decimal number ranging |
michael@0 | 80 | * from 0 through 180. When a decimal fraction of a degree is specified, |
michael@0 | 81 | * it shall be separated from the whole number of degrees by a decimal |
michael@0 | 82 | * point. |
michael@0 | 83 | * |
michael@0 | 84 | * Latitudes north of the equator shall be specified by a plus sign (+), |
michael@0 | 85 | * or by the absence of a minus sign (-), preceding the digits |
michael@0 | 86 | * designating degrees. Latitudes south of the Equator shall be |
michael@0 | 87 | * designated by a minus sign (-) preceding the digits designating |
michael@0 | 88 | * degrees. A point on the Equator shall be assigned to the Northern |
michael@0 | 89 | * Hemisphere. |
michael@0 | 90 | * |
michael@0 | 91 | * Longitudes east of the prime meridian shall be specified by a plus |
michael@0 | 92 | * sign (+), or by the absence of a minus sign (-), preceding the digits |
michael@0 | 93 | * designating degrees. Longitudes west of the meridian shall be |
michael@0 | 94 | * designated by minus sign (-) preceding the digits designating |
michael@0 | 95 | * degrees. A point on the prime meridian shall be assigned to the |
michael@0 | 96 | * Eastern Hemisphere. A point on the 180th meridian shall be assigned |
michael@0 | 97 | * to the Western Hemisphere. One exception to this last convention is |
michael@0 | 98 | * permitted. For the special condition of describing a band of latitude |
michael@0 | 99 | * around the earth, the East Bounding Coordinate data element shall be |
michael@0 | 100 | * assigned the value +180 (180) degrees. |
michael@0 | 101 | * |
michael@0 | 102 | * Any spatial address with a latitude of +90 (90) or -90 degrees will |
michael@0 | 103 | * specify the position at the North or South Pole, respectively. The |
michael@0 | 104 | * component for longitude may have any legal value. |
michael@0 | 105 | * |
michael@0 | 106 | * With the exception of the special condition described above, this |
michael@0 | 107 | * form is specified in Department of Commerce, 1986, Representation of |
michael@0 | 108 | * geographic point locations for information interchange (Federal |
michael@0 | 109 | * Information Processing Standard 70-1): Washington, Department of |
michael@0 | 110 | * Commerce, National Institute of Standards and Technology. |
michael@0 | 111 | * |
michael@0 | 112 | * The simple formula for converting degrees-minutes-seconds into |
michael@0 | 113 | * decimal degrees is: |
michael@0 | 114 | * |
michael@0 | 115 | * decimal = degrees + minutes/60 + seconds/3600. |
michael@0 | 116 | * |
michael@0 | 117 | * Format Definition: The property is defined by the following notation: |
michael@0 | 118 | * |
michael@0 | 119 | * geo = "GEO" geoparam ":" geovalue CRLF |
michael@0 | 120 | * |
michael@0 | 121 | * geoparam = *(";" xparam) |
michael@0 | 122 | * |
michael@0 | 123 | * geovalue = float ";" float |
michael@0 | 124 | * ;Latitude and Longitude components |
michael@0 | 125 | * |
michael@0 | 126 | * Example: The following is an example of this property: |
michael@0 | 127 | * |
michael@0 | 128 | * GEO:37.386013;-122.082932 |
michael@0 | 129 | * </pre> |
michael@0 | 130 | * |
michael@0 | 131 | * @author Ben Fortuna |
michael@0 | 132 | */ |
michael@0 | 133 | public class Geo extends Property { |
michael@0 | 134 | |
michael@0 | 135 | private static final long serialVersionUID = -902100715801867636L; |
michael@0 | 136 | |
michael@0 | 137 | private BigDecimal latitude; |
michael@0 | 138 | |
michael@0 | 139 | private BigDecimal longitude; |
michael@0 | 140 | |
michael@0 | 141 | /** |
michael@0 | 142 | * Default constructor. |
michael@0 | 143 | */ |
michael@0 | 144 | public Geo() { |
michael@0 | 145 | super(GEO, PropertyFactoryImpl.getInstance()); |
michael@0 | 146 | latitude = BigDecimal.valueOf(0); |
michael@0 | 147 | longitude = BigDecimal.valueOf(0); |
michael@0 | 148 | } |
michael@0 | 149 | |
michael@0 | 150 | /** |
michael@0 | 151 | * Creates a new instance by parsing the specified string representation. |
michael@0 | 152 | * @param value a geo value |
michael@0 | 153 | */ |
michael@0 | 154 | public Geo(final String value) { |
michael@0 | 155 | super(GEO, PropertyFactoryImpl.getInstance()); |
michael@0 | 156 | setValue(value); |
michael@0 | 157 | } |
michael@0 | 158 | |
michael@0 | 159 | /** |
michael@0 | 160 | * @param aList a list of parameters for this component |
michael@0 | 161 | * @param aValue a value string for this component |
michael@0 | 162 | */ |
michael@0 | 163 | public Geo(final ParameterList aList, final String aValue) { |
michael@0 | 164 | super(GEO, aList, PropertyFactoryImpl.getInstance()); |
michael@0 | 165 | setValue(aValue); |
michael@0 | 166 | } |
michael@0 | 167 | |
michael@0 | 168 | /** |
michael@0 | 169 | * @param latitude a latitudinal value |
michael@0 | 170 | * @param longitude a longitudinal value |
michael@0 | 171 | */ |
michael@0 | 172 | public Geo(final BigDecimal latitude, final BigDecimal longitude) { |
michael@0 | 173 | super(GEO, PropertyFactoryImpl.getInstance()); |
michael@0 | 174 | this.latitude = latitude; |
michael@0 | 175 | this.longitude = longitude; |
michael@0 | 176 | } |
michael@0 | 177 | |
michael@0 | 178 | /** |
michael@0 | 179 | * @param aList a list of parameters for this component |
michael@0 | 180 | * @param latitude a latitudinal value |
michael@0 | 181 | * @param longitude a longitudinal value |
michael@0 | 182 | */ |
michael@0 | 183 | public Geo(final ParameterList aList, final BigDecimal latitude, |
michael@0 | 184 | final BigDecimal longitude) { |
michael@0 | 185 | super(GEO, aList, PropertyFactoryImpl.getInstance()); |
michael@0 | 186 | this.latitude = latitude; |
michael@0 | 187 | this.longitude = longitude; |
michael@0 | 188 | } |
michael@0 | 189 | |
michael@0 | 190 | /** |
michael@0 | 191 | * @return Returns the latitude. |
michael@0 | 192 | */ |
michael@0 | 193 | public final BigDecimal getLatitude() { |
michael@0 | 194 | return latitude; |
michael@0 | 195 | } |
michael@0 | 196 | |
michael@0 | 197 | /** |
michael@0 | 198 | * @return Returns the longitude. |
michael@0 | 199 | */ |
michael@0 | 200 | public final BigDecimal getLongitude() { |
michael@0 | 201 | return longitude; |
michael@0 | 202 | } |
michael@0 | 203 | |
michael@0 | 204 | /** |
michael@0 | 205 | * {@inheritDoc} |
michael@0 | 206 | */ |
michael@0 | 207 | public final void setValue(final String aValue) { |
michael@0 | 208 | final String latitudeString = aValue.substring(0, aValue.indexOf(';')); |
michael@0 | 209 | if (StringUtils.isNotBlank(latitudeString)) { |
michael@0 | 210 | latitude = new BigDecimal(latitudeString); |
michael@0 | 211 | } |
michael@0 | 212 | else { |
michael@0 | 213 | latitude = BigDecimal.valueOf(0); |
michael@0 | 214 | } |
michael@0 | 215 | |
michael@0 | 216 | final String longitudeString = aValue.substring(aValue.indexOf(';') + 1); |
michael@0 | 217 | if (StringUtils.isNotBlank(longitudeString)) { |
michael@0 | 218 | longitude = new BigDecimal(longitudeString); |
michael@0 | 219 | } |
michael@0 | 220 | else { |
michael@0 | 221 | longitude = BigDecimal.valueOf(0); |
michael@0 | 222 | } |
michael@0 | 223 | } |
michael@0 | 224 | |
michael@0 | 225 | /** |
michael@0 | 226 | * {@inheritDoc} |
michael@0 | 227 | */ |
michael@0 | 228 | public final String getValue() { |
michael@0 | 229 | return String.valueOf(getLatitude()) + ";" |
michael@0 | 230 | + String.valueOf(getLongitude()); |
michael@0 | 231 | } |
michael@0 | 232 | |
michael@0 | 233 | /** |
michael@0 | 234 | * @param latitude The latitude to set. |
michael@0 | 235 | */ |
michael@0 | 236 | public final void setLatitude(final BigDecimal latitude) { |
michael@0 | 237 | this.latitude = latitude; |
michael@0 | 238 | } |
michael@0 | 239 | |
michael@0 | 240 | /** |
michael@0 | 241 | * @param longitude The longitude to set. |
michael@0 | 242 | */ |
michael@0 | 243 | public final void setLongitude(final BigDecimal longitude) { |
michael@0 | 244 | this.longitude = longitude; |
michael@0 | 245 | } |
michael@0 | 246 | |
michael@0 | 247 | /** |
michael@0 | 248 | * {@inheritDoc} |
michael@0 | 249 | */ |
michael@0 | 250 | public final void validate() throws ValidationException { |
michael@0 | 251 | // TODO: Auto-generated method stub |
michael@0 | 252 | } |
michael@0 | 253 | } |