001/* 002 * #%L 003 * Netarchivesuite - common 004 * %% 005 * Copyright (C) 2005 - 2014 The Royal Danish Library, the Danish State and University Library, 006 * the National Library of France and the Austrian National Library. 007 * %% 008 * This program is free software: you can redistribute it and/or modify 009 * it under the terms of the GNU Lesser General Public License as 010 * published by the Free Software Foundation, either version 2.1 of the 011 * License, or (at your option) any later version. 012 * 013 * This program is distributed in the hope that it will be useful, 014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 016 * GNU General Lesser Public License for more details. 017 * 018 * You should have received a copy of the GNU General Lesser Public 019 * License along with this program. If not, see 020 * <http://www.gnu.org/licenses/lgpl-2.1.html>. 021 * #L% 022 */ 023package dk.netarkivet.common.utils; 024 025import dk.netarkivet.common.exceptions.ArgumentNotValid; 026 027/** 028 * Contains the data about how a table is sorted. 029 */ 030public class TableSort { 031 032 /** list of the sort order. */ 033 public enum SortOrder { 034 NONE, INCR, DESC 035 } 036 037 ; 038 039 /** id of the sorted column. */ 040 private int columnIdent = -1; 041 042 /** order of the sort. */ 043 private SortOrder order = TableSort.SortOrder.NONE; 044 045 /** 046 * Constructor. 047 * 048 * @param columnId the id of the sorted column 049 * @param sortOrder the order of the sort 050 */ 051 public TableSort(final int columnId, final SortOrder sortOrder) { 052 ArgumentNotValid.checkTrue(sortOrder == TableSort.SortOrder.DESC || sortOrder == TableSort.SortOrder.INCR 053 || sortOrder == TableSort.SortOrder.NONE, "set order invalid"); 054 055 columnIdent = columnId; 056 order = sortOrder; 057 } 058 059 /** 060 * Return the id of the sorted column. 061 * 062 * @return the id of the sorted column 063 */ 064 public final int getColumnIdent() { 065 return columnIdent; 066 } 067 068 /** 069 * Set the id of the sorted column. 070 * 071 * @param columnident the id of the sorted column 072 */ 073 public final void setColumnIdent(final int columnident) { 074 columnIdent = columnident; 075 } 076 077 /** 078 * Return the order of the sort. 079 * 080 * @return the order of the sort 081 */ 082 public final SortOrder getOrder() { 083 return order; 084 } 085 086 /** 087 * Set the order of the sort. 088 * 089 * @param sortorder the order of the sort 090 */ 091 public final void setOrder(final SortOrder sortorder) { 092 ArgumentNotValid.checkTrue(sortorder == TableSort.SortOrder.DESC || sortorder == TableSort.SortOrder.INCR 093 || sortorder == TableSort.SortOrder.NONE, "set order invalid"); 094 order = sortorder; 095 } 096 097}