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