001/*
002 *  Copyright 2015 Anyware Services
003 *
004 *  Licensed under the Apache License, Version 2.0 (the "License");
005 *  you may not use this file except in compliance with the License.
006 *  You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 *  Unless required by applicable law or agreed to in writing, software
011 *  distributed under the License is distributed on an "AS IS" BASIS,
012 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 *  See the License for the specific language governing permissions and
014 *  limitations under the License.
015 */
016package org.ametys.cms.search;
017
018/**
019 * Class representing a sort criterion.
020 */
021public class Sort
022{
023    
024    /**
025     * Sort order.
026     */
027    public enum Order
028    {
029        /** Ascending sort order. */
030        ASC,
031        /** Descending sort order. */
032        DESC
033    }
034    
035    /** The sort field. */
036    protected String _field;
037    
038    /** The sort order. */
039    protected Order _order;
040    
041    private SearchField _searchField;
042    
043    /**
044     * Build a new Sort criterion.
045     * @param field The sort field as a String.
046     * @param order The sort order.
047     */
048    public Sort(String field, Order order)
049    {
050        this._field = field;
051        this._order = order;
052    }
053    
054    /**
055     * Build a new Sort criterion.
056     * @param field The sort field as a {@link SearchField}.
057     * @param order The sort order.
058     */
059    public Sort(SearchField field, Order order)
060    {
061        this._searchField = field;
062        this._order = order;
063    }
064    
065    /**
066     * Get the sort field.
067     * @return The sort field.
068     */
069    public String getField()
070    {
071        return _field != null ? _field : _searchField.getSortField();
072    }
073    
074    /**
075     * Set the sort field.
076     * @param field The sort field.
077     */
078    public void setField(String field)
079    {
080        this._field = field;
081    }
082    
083    /**
084     * Get the sort order.
085     * @return The sort order.
086     */
087    public Order getOrder()
088    {
089        return _order;
090    }
091    
092    /**
093     * Set the sort order.
094     * @param order The sort order.
095     */
096    public void setOrder(Order order)
097    {
098        this._order = order;
099    }
100    
101}