001package ca.uhn.fhir.rest.api; 002 003import java.io.Serializable; 004 005/* 006 * #%L 007 * HAPI FHIR - Core Library 008 * %% 009 * Copyright (C) 2014 - 2022 Smile CDR, Inc. 010 * %% 011 * Licensed under the Apache License, Version 2.0 (the "License"); 012 * you may not use this file except in compliance with the License. 013 * You may obtain a copy of the License at 014 * 015 * http://www.apache.org/licenses/LICENSE-2.0 016 * 017 * Unless required by applicable law or agreed to in writing, software 018 * distributed under the License is distributed on an "AS IS" BASIS, 019 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 020 * See the License for the specific language governing permissions and 021 * limitations under the License. 022 * #L% 023 */ 024 025/** 026 * Represents values for <a href="http://hl7.org/implement/standards/fhir/search.html#sort">sorting</a> resources 027 * returned by a server. 028 */ 029public class SortSpec implements Serializable { 030 031 private static final long serialVersionUID = 2866833099879713467L; 032 033 private SortSpec myChain; 034 private String myParamName; 035 private SortOrderEnum myOrder; 036 037 /** 038 * Constructor 039 */ 040 public SortSpec() { 041 super(); 042 } 043 044 /** 045 * Constructor 046 * 047 * @param theParamName 048 * The search name to sort on. See {@link #setParamName(String)} for more information. 049 */ 050 public SortSpec(String theParamName) { 051 super(); 052 myParamName = theParamName; 053 } 054 055 /** 056 * Constructor 057 * 058 * @param theParamName 059 * The search name to sort on. See {@link #setParamName(String)} for more information. 060 * @param theOrder 061 * The order, or <code>null</code>. See {@link #setOrder(SortOrderEnum)} for more information. 062 */ 063 public SortSpec(String theParamName, SortOrderEnum theOrder) { 064 super(); 065 myParamName = theParamName; 066 myOrder = theOrder; 067 } 068 069 /** 070 * Constructor 071 * 072 * @param theParamName 073 * The search name to sort on. See {@link #setParamName(String)} for more information. 074 * @param theOrder 075 * The order, or <code>null</code>. See {@link #setOrder(SortOrderEnum)} for more information. 076 * @param theChain 077 * The next sorting spec, to be applied only when this spec makes two entries equal. See 078 * {@link #setChain(SortSpec)} for more information. 079 */ 080 public SortSpec(String theParamName, SortOrderEnum theOrder, SortSpec theChain) { 081 super(); 082 myParamName = theParamName; 083 myOrder = theOrder; 084 myChain = theChain; 085 } 086 087 /** 088 * Gets the chained sort specification, or <code>null</code> if none. If multiple sort parameters are chained 089 * (indicating a sub-sort), the second level sort is chained via this property. 090 */ 091 public SortSpec getChain() { 092 return myChain; 093 } 094 095 /** 096 * Returns the actual name of the search param to sort by 097 */ 098 public String getParamName() { 099 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}