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.pojotools;
014
015import org.apache.juneau.*;
016
017/**
018 * Designed to provide paging on POJOs consisting of arrays and collections.
019 *
020 * <p>
021 * Allows you to quickly return subsets of arrays and collections based on position/limit arguments.
022 */
023public final class PojoPaginator implements PojoTool<Object> {
024
025   @Override /* PojoTool */
026   public Object run(BeanSession session, Object input, Object args) {
027
028//    if (input == null)
029//       return null;
030//
031//    ClassMeta type = session.getClassMetaForObject(input);
032//
033//    if (! type.isCollectionOrArray())
034//       return input;
035//
036//    int pos = args.getPosition();
037//    int limit = args.getLimit();
038//
039//    if (type.isArray()) {
040//       int size = Array.getLength(input);
041//       int end = (limit+pos >= size) ? size : limit + pos;
042//       pos = Math.min(pos, size);
043//       ClassMeta<?> et = type.getElementType();
044//          if (! et.isPrimitive())
045//          return copyOfRange((Object[])input, pos, end);
046//       if (et.isType(boolean.class))
047//          return copyOfRange((boolean[])input, pos, end);
048//       if (et.isType(byte.class))
049//          return copyOfRange((byte[])input, pos, end);
050//       if (et.isType(char.class))
051//          return copyOfRange((char[])input, pos, end);
052//       if (et.isType(double.class))
053//          return copyOfRange((double[])input, pos, end);
054//       if (et.isType(float.class))
055//          return copyOfRange((float[])input, pos, end);
056//       if (et.isType(int.class))
057//          return copyOfRange((int[])input, pos, end);
058//       if (et.isType(long.class))
059//          return copyOfRange((long[])input, pos, end);
060//       if (et.isType(short.class))
061//          return copyOfRange((short[])input, pos, end);
062//       return null;
063//    }
064//
065//    List l = type.isList() ? (List)input : new ArrayList((Collection)input);
066//    int end = (limit+pos >= l.size()) ? l.size() : limit + pos;
067//    pos = Math.min(pos, l.size());
068//    return l.subList(pos, end);
069      return null;
070   }
071}