001/* 002 * Copyright (c) 2006-2011 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the Eclipse Public License v1.0 006 * which accompanies this distribution, and is available at 007 * http://www.eclipse.org/legal/epl-v10.html 008 * 009 * Contributors: 010 * Bogdan Stefanescu 011 * Florent Guillaume 012 */ 013 014package org.nuxeo.ecm.core.api.impl; 015 016import java.util.ArrayList; 017import java.util.List; 018 019import org.nuxeo.ecm.core.api.DocumentModel; 020import org.nuxeo.ecm.core.api.DocumentModelList; 021 022/** 023 * @author Bogdan Stefanescu 024 * @author Florent Guillaume 025 */ 026public class DocumentModelListImpl extends ArrayList<DocumentModel> implements DocumentModelList { 027 028 private static final long serialVersionUID = 4214422534444037559L; 029 030 protected long totalSize = -1; 031 032 public DocumentModelListImpl() { 033 } 034 035 public DocumentModelListImpl(int size) { 036 super(size); 037 } 038 039 public DocumentModelListImpl(List<DocumentModel> list) { 040 super(list); 041 } 042 043 /** 044 * Constructs a DocumentModelListImpl and sets the "total size" information. 045 * <p> 046 * The total size is additional information that can be provided in some cases where the list returned is a slice of 047 * a bigger list, this is used when getting paged results from a database for instance. 048 * 049 * @param list the list of documents 050 * @param totalSize the total size, with -1 meaning "same as the list's size" 051 */ 052 public DocumentModelListImpl(List<DocumentModel> list, long totalSize) { 053 super(list); 054 this.totalSize = totalSize; 055 } 056 057 public void setTotalSize(long totalSize) { 058 this.totalSize = totalSize; 059 } 060 061 @Override 062 public long totalSize() { 063 if (totalSize == -1) { 064 return size(); 065 } 066 return totalSize; 067 } 068 069}