SearchMetaParams.java
package com.tradecloud.repository;
import java.util.Objects;
/**
* Search meta params used for paging and ordering.
*/
public class SearchMetaParams {
private Integer rowIndex;
private Integer rowCount;
private String orderBy;
private boolean asc;
public SearchMetaParams(int rowIndex, int rowCount) {
this.rowIndex = rowIndex;
this.rowCount = rowCount;
}
public SearchMetaParams(int rowIndex, int rowCount, String orderBy, boolean asc) {
this.rowIndex = rowIndex;
this.rowCount = rowCount;
this.orderBy = orderBy;
this.asc = asc;
}
private SearchMetaParams(String orderBy, boolean asc) {
this.orderBy = orderBy;
this.asc = asc;
}
public int getRowIndex() {
return rowIndex;
}
public void setRowIndex(int rowIndex) {
this.rowIndex = rowIndex;
}
public int getRowCount() {
return rowCount;
}
public void setRowCount(int rowCount) {
this.rowCount = rowCount;
}
public String getOrderBy() {
return orderBy;
}
public void setOrderBy(String orderBy) {
this.orderBy = orderBy;
}
public boolean isAsc() {
return asc;
}
public void setAsc(boolean asc) {
this.asc = asc;
}
public SearchMetaParams clearPaging() {
this.rowCount = null;
this.rowIndex = null;
return this;
}
public static SearchMetaParams noPaging(String orderBy, boolean asc) {
return new SearchMetaParams(orderBy, asc);
}
public boolean isPaged() {
return rowCount != null && rowIndex != null;
}
@Override
public String toString() {
return "Row index=" + rowIndex + ". Row count=" + rowCount + ". Order by=" + orderBy + ". Ascending=" + asc + ". ";
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
SearchMetaParams that = (SearchMetaParams) o;
return isAsc() == that.isAsc() && Objects.equals(getRowIndex(), that.getRowIndex()) && Objects.equals(getRowCount(),
that.getRowCount()) && Objects.equals(getOrderBy(), that.getOrderBy());
}
@Override
public int hashCode() {
return Objects.hash(getRowIndex(), getRowCount(), getOrderBy(), isAsc());
}
}