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.juneau.objecttools; 018 019import static java.util.Optional.*; 020 021/** 022 * Arguments passed to {@link ObjectPaginator}. 023 * 024 * <h5 class='section'>See Also:</h5><ul> 025 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/ObjectTools">Object Tools</a> 026 * </ul> 027 */ 028public class PageArgs { 029 030 //----------------------------------------------------------------------------------------------------------------- 031 // Static 032 //----------------------------------------------------------------------------------------------------------------- 033 034 /** 035 * Static creator. 036 * 037 * @param position The zero-indexed position to start the page on. 038 * @param limit The number of rows to return. 039 * 040 * @return A new {@link PageArgs} object. 041 */ 042 public static PageArgs create(Integer position, Integer limit) { 043 if (position == null && limit == null) return null; 044 return new PageArgs(ofNullable(position).orElse(0), ofNullable(limit).orElse(-1)); 045 } 046 047 //----------------------------------------------------------------------------------------------------------------- 048 // Instance 049 //----------------------------------------------------------------------------------------------------------------- 050 051 final int position, limit; 052 053 /** 054 * Constructor. 055 * 056 * @param position The zero-indexed position to start the page on. 057 * @param limit The number of rows to return. 058 */ 059 public PageArgs(int position, int limit) { 060 this.position = position; 061 this.limit = limit; 062 } 063 064 /** 065 * Returns the number of rows to return. 066 * 067 * @return The number of rows to return. 068 */ 069 public int getLimit() { 070 return limit; 071 } 072 073 /** 074 * Returns the zero-indexed position to start the page on. 075 * 076 * @return The zero-indexed position to start the page on. 077 */ 078 public int getPosition() { 079 return position; 080 } 081}