View Javadoc
1   package ca.uhn.fhir.rest.api;
2   
3   import java.io.Serializable;
4   
5   /*
6    * #%L
7    * HAPI FHIR - Core Library
8    * %%
9    * Copyright (C) 2014 - 2018 University Health Network
10   * %%
11   * Licensed under the Apache License, Version 2.0 (the "License");
12   * you may not use this file except in compliance with the License.
13   * You may obtain a copy of the License at
14   * 
15   *      http://www.apache.org/licenses/LICENSE-2.0
16   * 
17   * Unless required by applicable law or agreed to in writing, software
18   * distributed under the License is distributed on an "AS IS" BASIS,
19   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20   * See the License for the specific language governing permissions and
21   * limitations under the License.
22   * #L%
23   */
24  
25  /**
26   * Represents values for <a href="http://hl7.org/implement/standards/fhir/search.html#sort">sorting</a> resources
27   * returned by a server.
28   */
29  public class SortSpec implements Serializable {
30  
31  	private static final long serialVersionUID = 2866833099879713467L;
32  	
33  	private SortSpec myChain;
34  	private String myParamName;
35  	private SortOrderEnum myOrder;
36  
37  	/**
38  	 * Constructor
39  	 */
40  	public SortSpec() {
41  		super();
42  	}
43  
44  	/**
45  	 * Constructor
46  	 * 
47  	 * @param theParamName
48  	 *            The search name to sort on. See {@link #setParamName(String)} for more information.
49  	 */
50  	public SortSpec(String theParamName) {
51  		super();
52  		myParamName = theParamName;
53  	}
54  
55  	/**
56  	 * Constructor
57  	 * 
58  	 * @param theParamName
59  	 *            The search name to sort on. See {@link #setParamName(String)} for more information.
60  	 * @param theOrder
61  	 *            The order, or <code>null</code>. See {@link #setOrder(SortOrderEnum)} for more information.
62  	 */
63  	public SortSpec(String theParamName, SortOrderEnum theOrder) {
64  		super();
65  		myParamName = theParamName;
66  		myOrder = theOrder;
67  	}
68  
69  	/**
70  	 * Constructor
71  	 * 
72  	 * @param theParamName
73  	 *            The search name to sort on. See {@link #setParamName(String)} for more information.
74  	 * @param theOrder
75  	 *            The order, or <code>null</code>. See {@link #setOrder(SortOrderEnum)} for more information.
76  	 * @param theChain
77  	 *            The next sorting spec, to be applied only when this spec makes two entries equal. See
78  	 *            {@link #setChain(SortSpec)} for more information.
79  	 */
80  	public SortSpec(String theParamName, SortOrderEnum theOrder, SortSpec theChain) {
81  		super();
82  		myParamName = theParamName;
83  		myOrder = theOrder;
84  		myChain = theChain;
85  	}
86  
87  	/**
88  	 * Gets the chained sort specification, or <code>null</code> if none. If multiple sort parameters are chained
89  	 * (indicating a sub-sort), the second level sort is chained via this property.
90  	 */
91  	public SortSpec getChain() {
92  		return myChain;
93  	}
94  
95  	/**
96  	 * Returns the actual name of the search param to sort by
97  	 */
98  	public String getParamName() {
99  		return myParamName;
100 	}
101 
102 	/**
103 	 * Returns the sort order specified by this parameter, or <code>null</code> if none is explicitly provided (which
104 	 * means {@link SortOrderEnum#ASC} according to the <a
105 	 * href="http://hl7.org/implement/standards/fhir/search.html#sort">FHIR specification</a>)
106 	 */
107 	public SortOrderEnum getOrder() {
108 		return myOrder;
109 	}
110 
111 	/**
112 	 * Sets the chained sort specification, or <code>null</code> if none. If multiple sort parameters are chained
113 	 * (indicating a sub-sort), the second level sort is chained via this property.
114 	 */
115 	public SortSpec setChain(SortSpec theChain) {
116 		if (theChain == this) {
117 			throw new IllegalArgumentException("Can not chain this to itself");
118 		}
119 		myChain = theChain;
120 		return this;
121 	}
122 
123 	/**
124 	 * Sets the actual name of the search param to sort by
125 	 */
126 	public SortSpec setParamName(String theFieldName) {
127 		myParamName = theFieldName;
128 		return this;
129 	}
130 
131 	/**
132 	 * Sets the sort order specified by this parameter, or <code>null</code> if none should be explicitly defined (which
133 	 * means {@link SortOrderEnum#ASC} according to the <a
134 	 * href="http://hl7.org/implement/standards/fhir/search.html#sort">FHIR specification</a>)
135 	 */
136 	public SortSpec setOrder(SortOrderEnum theOrder) {
137 		myOrder = theOrder;
138 		return this;
139 	}
140 
141 }