001/* 002 * Copyright 2011-2016 UnboundID Corp. 003 * 004 * This program is free software; you can redistribute it and/or modify 005 * it under the terms of the GNU General Public License (GPLv2 only) 006 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only) 007 * as published by the Free Software Foundation. 008 * 009 * This program is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 012 * GNU General Public License for more details. 013 * 014 * You should have received a copy of the GNU General Public License 015 * along with this program; if not, see <http://www.gnu.org/licenses>. 016 */ 017 018package com.unboundid.scim.sdk; 019 020 021 022/** 023 * This class represents the sorting parameters in a SCIM request. 024 */ 025public final class SortParameters 026{ 027 /** 028 * The attribute or sub-attribute whose value is used to order the returned 029 * resources. 030 */ 031 private final AttributePath sortBy; 032 033 /** 034 * The order in which the sortBy parameter is applied. e.g. ascending or 035 * descending, or {@code null} if no sort order was specified. 036 */ 037 private final String sortOrder; 038 039 /** 040 * Indicates whether the sort order implies ascending or descending order. 041 */ 042 private final boolean isAscendingOrder; 043 044 045 046 /** 047 * Create a new instance of sort parameters. 048 * 049 * @param sortBy The attribute or sub-attribute whose value is used to 050 * order the returned resources. 051 * @param sortOrder The order in which the sortBy parameter is applied. e.g. 052 * ascending or descending, or {@code null} if no sort order 053 * was specified. 054 */ 055 public SortParameters(final String sortBy, final String sortOrder) 056 { 057 this(sortBy, sortOrder, SCIMConstants.SCHEMA_URI_CORE); 058 } 059 060 061 062 /** 063 * Create a new instance of sort parameters. 064 * 065 * @param sortBy The attribute or sub-attribute whose value is used to 066 * order the returned resources. 067 * @param sortOrder The order in which the sortBy parameter is applied. e.g. 068 * ascending or descending, or {@code null} if no sort order 069 * was specified. 070 * @param defaultSchema The default schema that should be assumed when parsing 071 * attributes without the schema explicitly defined in 072 * the URN. 073 */ 074 public SortParameters(final String sortBy, final String sortOrder, 075 final String defaultSchema) 076 { 077 this(AttributePath.parse(sortBy, defaultSchema), sortOrder); 078 } 079 080 081 082 /** 083 * Create a new instance of sort parameters. 084 * 085 * @param sortBy The attribute or sub-attribute whose value is used to 086 * order the returned resources. 087 * @param sortOrder The order in which the sortBy parameter is applied. e.g. 088 * ascending or descending, or {@code null} if no sort order 089 * was specified. 090 */ 091 public SortParameters(final AttributePath sortBy, final String sortOrder) 092 { 093 this.sortBy = sortBy; 094 this.sortOrder = sortOrder; 095 this.isAscendingOrder = 096 sortOrder == null || !sortOrder.equalsIgnoreCase("descending"); 097 } 098 099 100 101 /** 102 * Retrieve the attribute or sub-attribute whose value is used to order the 103 * returned resources. 104 * 105 * @return The attribute or sub-attribute whose value is used to order the 106 * returned resources. 107 */ 108 public AttributePath getSortBy() 109 { 110 return sortBy; 111 } 112 113 114 115 /** 116 * Retrieve order in which the sortBy parameter is applied. e.g. ascending or 117 * descending. 118 * 119 * @return The order in which the sortBy parameter is applied. e.g. ascending 120 * or descending. 121 */ 122 public String getSortOrder() 123 { 124 return sortOrder; 125 } 126 127 128 129 /** 130 * Determine whether the sort order implies ascending or descending order. 131 * 132 * @return {@code true} if the sort order implies ascending order. 133 */ 134 public boolean isAscendingOrder() 135 { 136 return isAscendingOrder; 137 } 138}