001 /*
002 * Copyright 2011-2012 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
018 package com.unboundid.scim.sdk;
019
020
021
022 /**
023 * This class represents the sorting parameters in a SCIM request.
024 */
025 public 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(AttributePath.parse(sortBy), sortOrder);
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 */
071 public SortParameters(final AttributePath sortBy, final String sortOrder)
072 {
073 this.sortBy = sortBy;
074 this.sortOrder = sortOrder;
075 this.isAscendingOrder =
076 sortOrder == null || !sortOrder.equalsIgnoreCase("descending");
077 }
078
079
080
081 /**
082 * Retrieve the attribute or sub-attribute whose value is used to order the
083 * returned resources.
084 *
085 * @return The attribute or sub-attribute whose value is used to order the
086 * returned resources.
087 */
088 public AttributePath getSortBy()
089 {
090 return sortBy;
091 }
092
093
094
095 /**
096 * Retrieve order in which the sortBy parameter is applied. e.g. ascending or
097 * descending.
098 *
099 * @return The order in which the sortBy parameter is applied. e.g. ascending
100 * or descending.
101 */
102 public String getSortOrder()
103 {
104 return sortOrder;
105 }
106
107
108
109 /**
110 * Determine whether the sort order implies ascending or descending order.
111 *
112 * @return {@code true} if the sort order implies ascending order.
113 */
114 public boolean isAscendingOrder()
115 {
116 return isAscendingOrder;
117 }
118 }