001 package biweekly; 002 003 import java.util.Collection; 004 005 import biweekly.util.CaseClasses; 006 007 /* 008 Copyright (c) 2013, Michael Angstadt 009 All rights reserved. 010 011 Redistribution and use in source and binary forms, with or without 012 modification, are permitted provided that the following conditions are met: 013 014 1. Redistributions of source code must retain the above copyright notice, this 015 list of conditions and the following disclaimer. 016 2. Redistributions in binary form must reproduce the above copyright notice, 017 this list of conditions and the following disclaimer in the documentation 018 and/or other materials provided with the distribution. 019 020 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 021 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 022 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 023 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 024 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 025 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 026 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 027 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 028 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 029 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 030 */ 031 032 /** 033 * Defines the data type of a property's value. 034 * @author Michael Angstadt 035 * @rfc 5545 p.29-50 036 */ 037 public class ICalDataType { 038 private static final CaseClasses<ICalDataType, String> enums = new CaseClasses<ICalDataType, String>(ICalDataType.class) { 039 @Override 040 protected ICalDataType create(String value) { 041 return new ICalDataType(value); 042 } 043 044 @Override 045 protected boolean matches(ICalDataType dataType, String value) { 046 return dataType.name.equalsIgnoreCase(value); 047 } 048 }; 049 050 public static final ICalDataType BINARY = new ICalDataType("BINARY"); 051 public static final ICalDataType BOOLEAN = new ICalDataType("BOOLEAN"); 052 public static final ICalDataType CAL_ADDRESS = new ICalDataType("CAL-ADDRESS"); 053 public static final ICalDataType DATE = new ICalDataType("DATE"); 054 public static final ICalDataType DATE_TIME = new ICalDataType("DATE-TIME"); 055 public static final ICalDataType DURATION = new ICalDataType("DURATION"); 056 public static final ICalDataType FLOAT = new ICalDataType("FLOAT"); 057 public static final ICalDataType INTEGER = new ICalDataType("INTEGER"); 058 public static final ICalDataType PERIOD = new ICalDataType("PERIOD"); 059 public static final ICalDataType RECUR = new ICalDataType("RECUR"); 060 public static final ICalDataType TEXT = new ICalDataType("TEXT"); 061 public static final ICalDataType TIME = new ICalDataType("TIME"); 062 public static final ICalDataType URI = new ICalDataType("URI"); 063 public static final ICalDataType UTC_OFFSET = new ICalDataType("UTC-OFFSET"); 064 065 private final String name; 066 067 private ICalDataType(String name) { 068 this.name = name; 069 } 070 071 /** 072 * Gets the name of the data type. 073 * @return the name of the data type (e.g. "text") 074 */ 075 public String getName() { 076 return name; 077 } 078 079 @Override 080 public String toString() { 081 return name; 082 } 083 084 /** 085 * Searches for a parameter value that is defined as a static constant in 086 * this class. 087 * @param value the parameter value 088 * @return the object or null if not found 089 */ 090 public static ICalDataType find(String value) { 091 return enums.find(value); 092 } 093 094 /** 095 * Searches for a parameter value and creates one if it cannot be found. All 096 * objects are guaranteed to be unique, so they can be compared with 097 * {@code ==} equality. 098 * @param value the parameter value 099 * @return the object 100 */ 101 public static ICalDataType get(String value) { 102 return enums.get(value); 103 } 104 105 /** 106 * Gets all of the parameter values that are defined as static constants in 107 * this class. 108 * @return the parameter values 109 */ 110 public static Collection<ICalDataType> all() { 111 return enums.all(); 112 } 113 }