001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * For further information about Alkacon Software, please see the
018 * company website: http://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: http://www.opencms.org
022 *
023 * You should have received a copy of the GNU Lesser General Public
024 * License along with this library; if not, write to the Free Software
025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
026 */
027
028package org.opencms.search.galleries;
029
030import java.util.ArrayList;
031
032/**
033 * The search result list for the gallery search index.<p>
034 *
035 * @since 8.0.0
036 */
037public class CmsGallerySearchResultList extends ArrayList<CmsGallerySearchResult> {
038
039    /** Serial version UID required for safe serialization. */
040    private static final long serialVersionUID = 115646669707330088L;
041
042    /** The total number of search results matching the query. */
043    private int m_hitCount;
044
045    /** The number of pages for the result list. */
046    private int m_pageCount;
047
048    /** The current result-page-index. */
049    private int m_pageIndex;
050
051    /**
052     * Creates a new result list with a default initial capacity of 100.<p>
053     */
054    public CmsGallerySearchResultList() {
055
056        this(100);
057    }
058
059    /**
060     * Creates a new result list with the specified initial capacity.<p>
061     *
062     * @param initialCapacity the initial capacity
063     */
064    public CmsGallerySearchResultList(int initialCapacity) {
065
066        super(initialCapacity);
067    }
068
069    /**
070     * Appends the results from another search result list.<p>
071     *
072     * @param moreResults the second search result list
073     */
074    public void append(CmsGallerySearchResultList moreResults) {
075
076        addAll(moreResults);
077        m_hitCount = moreResults.getHitCount();
078    }
079
080    /**
081     * Returns the hit count of all results found in the last search.<p>
082     *
083     * Since this list will only contain the result objects for the current display page,
084     * the size of the list is usually much less then the hit count of all results found.<p>
085     *
086     * @return the hit count of all results found in the last search
087     */
088    public int getHitCount() {
089
090        return m_hitCount;
091    }
092
093    /**
094     * Returns the total number of search result pages.<p>
095     *
096     * @return the total number of search result pages
097     *
098     * @see #getHitCount()
099     * @see #getResultPage()
100     */
101    public int getPageCount() {
102
103        return m_pageCount;
104    }
105
106    /**
107     * Returns the index of the current result page.<p>
108     *
109     * @return the index of the current result page
110     *
111     * @see #getHitCount()
112     * @see #getPageCount()
113     */
114    public int getResultPage() {
115
116        return m_pageIndex;
117    }
118
119    /**
120     * Sets the hit count of all results found in the last search.<p>
121     *
122     * Since this list will only contain the result objects for the current display page,
123     * the size of the list is usually much less then the hit count of all results found.<p>
124     *
125     *  @param hitCount the hit count to set
126     */
127    public void setHitCount(int hitCount) {
128
129        m_hitCount = hitCount;
130    }
131
132    /**
133     * Calculates the result pages.<p>
134     *
135     * @param pageIndex the index of the current page
136     * @param matchesPerPage the matches per page
137     */
138    public void calculatePages(int pageIndex, int matchesPerPage) {
139
140        m_pageIndex = pageIndex;
141        // calculate the number of pages for this search result
142        m_pageCount = m_hitCount / matchesPerPage;
143        if ((m_hitCount % matchesPerPage) != 0) {
144            m_pageCount++;
145        }
146    }
147}