001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.wicket.extensions.markup.html.repeater.util; 018 019import org.apache.wicket.util.io.IClusterable; 020import org.apache.wicket.util.lang.Args; 021 022/** 023 * Represents sorting information of a property 024 * 025 * @author Igor Vaynberg ( ivaynberg ) 026 * @param <T> 027 * the type of the sort property 028 */ 029public class SortParam<T> implements IClusterable 030{ 031 private static final long serialVersionUID = 1L; 032 033 private final T property; 034 private final boolean ascending; 035 036 /** 037 * @param property 038 * sort property 039 * @param ascending 040 * <code>true<code> if sort order is ascending, <code>false</code> if sort order is 041 * descending 042 */ 043 public SortParam(final T property, final boolean ascending) 044 { 045 Args.notNull(property, "property"); 046 this.property = property; 047 this.ascending = ascending; 048 } 049 050 /** 051 * @return sort property 052 */ 053 public T getProperty() 054 { 055 return property; 056 } 057 058 /** 059 * check if sort order is ascending 060 * 061 * @return <code>true<code> if sort order is ascending, <code>false</code> if sort order is 062 * descending 063 */ 064 public boolean isAscending() 065 { 066 return ascending; 067 } 068 069 @Override 070 public boolean equals(final Object o) 071 { 072 if (this == o) 073 { 074 return true; 075 } 076 if (!(o instanceof SortParam)) 077 { 078 return false; 079 } 080 081 @SuppressWarnings("unchecked") 082 SortParam<T> sortParam = (SortParam<T>)o; 083 084 return (ascending == sortParam.ascending) && property.equals(sortParam.property); 085 } 086 087 @Override 088 public int hashCode() 089 { 090 int result = property.hashCode(); 091 result = 31 * result + (ascending ? 1 : 0); 092 return result; 093 } 094 095 /** 096 * @see java.lang.Object#toString() 097 */ 098 @Override 099 public String toString() 100 { 101 return new StringBuilder().append("[SortParam property=") 102 .append(getProperty()) 103 .append(" ascending=") 104 .append(ascending) 105 .append("]") 106 .toString(); 107 } 108}