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 org.apache.juneau.commons.utils.Utils.*;
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    * Static creator.
031    *
032    * @param position The zero-indexed position to start the page on.
033    * @param limit The number of rows to return.
034    *
035    * @return A new {@link PageArgs} object.
036    */
037   public static PageArgs create(Integer position, Integer limit) {
038      if (position == null && limit == null)
039         return null;
040      return new PageArgs(opt(position).orElse(0), opt(limit).orElse(-1));
041   }
042
043   final int position, limit;
044
045   /**
046    * Constructor.
047    *
048    * @param position The zero-indexed position to start the page on.
049    * @param limit The number of rows to return.
050    */
051   public PageArgs(int position, int limit) {
052      this.position = position;
053      this.limit = limit;
054   }
055
056   /**
057    * Returns the number of rows to return.
058    *
059    * @return The number of rows to return.
060    */
061   public int getLimit() { return limit; }
062
063   /**
064    * Returns the zero-indexed position to start the page on.
065    *
066    * @return The zero-indexed position to start the page on.
067    */
068   public int getPosition() { return position; }
069}