001/*
002 * (C) Copyright 2006-2011 Nuxeo SA (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 *     Bogdan Stefanescu
018 *     Florent Guillaume
019 */
020
021package org.nuxeo.ecm.core.api.impl;
022
023import java.util.ArrayList;
024import java.util.List;
025
026import org.nuxeo.ecm.core.api.DocumentModel;
027import org.nuxeo.ecm.core.api.DocumentModelList;
028
029/**
030 * @author Bogdan Stefanescu
031 * @author Florent Guillaume
032 */
033public class DocumentModelListImpl extends ArrayList<DocumentModel> implements DocumentModelList {
034
035    private static final long serialVersionUID = 4214422534444037559L;
036
037    protected long totalSize = -1;
038
039    public DocumentModelListImpl() {
040    }
041
042    public DocumentModelListImpl(int size) {
043        super(size);
044    }
045
046    public DocumentModelListImpl(List<DocumentModel> list) {
047        super(list);
048    }
049
050    /**
051     * Constructs a DocumentModelListImpl and sets the "total size" information.
052     * <p>
053     * The total size is additional information that can be provided in some cases where the list returned is a slice of
054     * a bigger list, this is used when getting paged results from a database for instance.
055     *
056     * @param list the list of documents
057     * @param totalSize the total size, with -1 meaning "same as the list's size"
058     */
059    public DocumentModelListImpl(List<DocumentModel> list, long totalSize) {
060        super(list);
061        this.totalSize = totalSize;
062    }
063
064    public void setTotalSize(long totalSize) {
065        this.totalSize = totalSize;
066    }
067
068    @Override
069    public long totalSize() {
070        if (totalSize == -1) {
071            return size();
072        }
073        return totalSize;
074    }
075
076}