View Javadoc
1   package ca.uhn.fhir.model.api;
2   
3   /*
4    * #%L
5    * HAPI FHIR - Core Library
6    * %%
7    * Copyright (C) 2014 University Health Network
8    * %%
9    * Licensed under the Apache License, Version 2.0 (the "License");
10   * you may not use this file except in compliance with the License.
11   * You may obtain a copy of the License at
12   * 
13   *      http://www.apache.org/licenses/LICENSE-2.0
14   * 
15   * Unless required by applicable law or agreed to in writing, software
16   * distributed under the License is distributed on an "AS IS" BASIS,
17   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18   * See the License for the specific language governing permissions and
19   * limitations under the License.
20   * #L%
21   */
22  
23  import java.util.Calendar;
24  import java.util.Date;
25  
26  import org.apache.commons.lang3.time.DateUtils;
27  
28  public enum TemporalPrecisionEnum {
29  
30  	YEAR(Calendar.YEAR) {
31  		@Override
32  		public Date add(Date theInput, int theAmount) {
33  			return DateUtils.addYears(theInput, theAmount);
34  		}
35  	},
36  	
37  	MONTH(Calendar.MONTH) {
38  		@Override
39  		public Date add(Date theInput, int theAmount) {
40  			return DateUtils.addMonths(theInput, theAmount);
41  		}
42  	},
43  	DAY(Calendar.DATE) {
44  		@Override
45  		public Date add(Date theInput, int theAmount) {
46  			return DateUtils.addDays(theInput, theAmount);
47  		}
48  	},
49  	SECOND(Calendar.SECOND) {
50  		@Override
51  		public Date add(Date theInput, int theAmount) {
52  			return DateUtils.addSeconds(theInput, theAmount);
53  		}
54  	},
55  	
56  	MILLI(Calendar.MILLISECOND) {
57  		@Override
58  		public Date add(Date theInput, int theAmount) {
59  			return DateUtils.addMilliseconds(theInput, theAmount);
60  		}
61  	},
62  	
63  	;
64  	
65  	private int myCalendarConstant;
66  
67  	TemporalPrecisionEnum(int theCalendarConstant) {
68  		myCalendarConstant = theCalendarConstant;
69  	}
70  
71  	public abstract Date add(Date theInput, int theAmount);
72  	
73  	public int getCalendarConstant() {
74  		return myCalendarConstant;
75  	}
76  
77  }