001// *************************************************************************************************************************** 002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * 003// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * 004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * 005// * with the License. You may obtain a copy of the License at * 006// * * 007// * http://www.apache.org/licenses/LICENSE-2.0 * 008// * * 009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * 010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * 011// * specific language governing permissions and limitations under the License. * 012// *************************************************************************************************************************** 013package org.apache.juneau.objecttools; 014 015import static java.util.Optional.*; 016 017/** 018 * Arguments passed to {@link ObjectPaginator}. 019 * 020 * <h5 class='section'>See Also:</h5><ul> 021 * <li class='link'><a class="doclink" href="../../../../index.html#jm.ObjectTools">Overview > juneau-marshall > Object Tools</a> 022 * </ul> 023 */ 024public class PageArgs { 025 026 //----------------------------------------------------------------------------------------------------------------- 027 // Static 028 //----------------------------------------------------------------------------------------------------------------- 029 030 /** 031 * Static creator. 032 * 033 * @param position The zero-indexed position to start the page on. 034 * @param limit The number of rows to return. 035 * 036 * @return A new {@link PageArgs} object. 037 */ 038 public static PageArgs create(Integer position, Integer limit) { 039 if (position == null && limit == null) return null; 040 return new PageArgs(ofNullable(position).orElse(0), ofNullable(limit).orElse(-1)); 041 } 042 043 //----------------------------------------------------------------------------------------------------------------- 044 // Instance 045 //----------------------------------------------------------------------------------------------------------------- 046 047 final int position, limit; 048 049 /** 050 * Constructor. 051 * 052 * @param position The zero-indexed position to start the page on. 053 * @param limit The number of rows to return. 054 */ 055 public PageArgs(int position, int limit) { 056 this.position = position; 057 this.limit = limit; 058 } 059 060 /** 061 * Returns the number of rows to return. 062 * 063 * @return The number of rows to return. 064 */ 065 public int getLimit() { 066 return limit; 067 } 068 069 /** 070 * Returns the zero-indexed position to start the page on. 071 * 072 * @return The zero-indexed position to start the page on. 073 */ 074 public int getPosition() { 075 return position; 076 } 077}