View Javadoc
1   package ca.uhn.fhir.model.api;
2   
3   /*
4    * #%L
5    * HAPI FHIR - Core Library
6    * %%
7    * Copyright (C) 2014 - 2018 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  	MINUTE(Calendar.MINUTE) {
50  		@Override
51  		public Date add(Date theInput, int theAmount) {
52  			return DateUtils.addMinutes(theInput, theAmount);
53  		}
54  		
55  	},
56  	SECOND(Calendar.SECOND) {
57  		@Override
58  		public Date add(Date theInput, int theAmount) {
59  			return DateUtils.addSeconds(theInput, theAmount);
60  		}
61  	},
62  	
63  	MILLI(Calendar.MILLISECOND) {
64  		@Override
65  		public Date add(Date theInput, int theAmount) {
66  			return DateUtils.addMilliseconds(theInput, theAmount);
67  		}
68  	}, 
69  	
70  	;
71  	
72  	private int myCalendarConstant;
73  
74  	TemporalPrecisionEnum(int theCalendarConstant) {
75  		myCalendarConstant = theCalendarConstant;
76  	}
77  
78  	public abstract Date add(Date theInput, int theAmount);
79  	
80  	public int getCalendarConstant() {
81  		return myCalendarConstant;
82  	}
83  
84  }