001/* 002 * (C) Copyright 2006-2017 Nuxeo (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Florent Guillaume 018 */ 019package org.nuxeo.ecm.core.api; 020 021import java.util.AbstractList; 022import java.util.Comparator; 023import java.util.List; 024 025/** 026 * The bundling of a list and a total size. 027 */ 028public class PartialList<E> extends AbstractList<E> { 029 030 protected final List<E> list; 031 032 protected final long totalSize; 033 034 /** 035 * Constructs a partial list. 036 * 037 * @param list the list 038 * @param totalSize the total size 039 */ 040 public PartialList(List<E> list, long totalSize) { 041 this.list = list; 042 this.totalSize = totalSize; 043 } 044 045 @Override 046 public E get(int index) { 047 return list.get(index); 048 } 049 050 @Override 051 public int size() { 052 return list.size(); 053 } 054 055 @Override 056 public void sort(Comparator<? super E> c) { 057 list.sort(c); 058 } 059 060 @Override 061 public PartialList<E> subList(int fromIndex, int toIndex) { 062 return new PartialList<>(list.subList(fromIndex, toIndex), totalSize); 063 } 064 065 /** 066 * Returns the total size of the bigger list this is a part of. 067 * 068 * @since 9.3 069 */ 070 public long totalSize() { 071 return totalSize; 072 } 073}