001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (https://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: https://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: https://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     * Calculates the result pages.<p>
082     *
083     * @param pageIndex the index of the current page
084     * @param matchesPerPage the matches per page
085     */
086    public void calculatePages(int pageIndex, int matchesPerPage) {
087
088        m_pageIndex = pageIndex;
089        // calculate the number of pages for this search result
090        m_pageCount = m_hitCount / matchesPerPage;
091        if ((m_hitCount % matchesPerPage) != 0) {
092            m_pageCount++;
093        }
094    }
095
096    /**
097     * Returns the hit count of all results found in the last search.<p>
098     *
099     * Since this list will only contain the result objects for the current display page,
100     * the size of the list is usually much less then the hit count of all results found.<p>
101     *
102     * @return the hit count of all results found in the last search
103     */
104    public int getHitCount() {
105
106        return m_hitCount;
107    }
108
109    /**
110     * Returns the total number of search result pages.<p>
111     *
112     * @return the total number of search result pages
113     *
114     * @see #getHitCount()
115     * @see #getResultPage()
116     */
117    public int getPageCount() {
118
119        return m_pageCount;
120    }
121
122    /**
123     * Returns the index of the current result page.<p>
124     *
125     * @return the index of the current result page
126     *
127     * @see #getHitCount()
128     * @see #getPageCount()
129     */
130    public int getResultPage() {
131
132        return m_pageIndex;
133    }
134
135    /**
136     * Sets the hit count of all results found in the last search.<p>
137     *
138     * Since this list will only contain the result objects for the current display page,
139     * the size of the list is usually much less then the hit count of all results found.<p>
140     *
141     *  @param hitCount the hit count to set
142     */
143    public void setHitCount(int hitCount) {
144
145        m_hitCount = hitCount;
146    }
147}