View Javadoc
1   /**
2    * Copyright (C) 2003-2007 eXo Platform SAS.
3    *
4    * This program is free software; you can redistribute it and/or
5    * modify it under the terms of the GNU Affero General Public License
6    * as published by the Free Software Foundation; either version 3
7    * of the License, or (at your option) any later version.
8    *
9    * This program is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   * GNU General Public License for more details.
13   *
14   * You should have received a copy of the GNU General Public License
15   * along with this program; if not, see<http://www.gnu.org/licenses/>.
16   **/
17  package org.exoplatform.calendar.service;
18  
19  import java.util.ArrayList;
20  import java.util.List;
21  
22  /**
23   * @author Hung Nguyen (hung.nguyen@exoplatform.com)
24   * @since July 25, 2007
25   */
26  public class EventPageList<T> extends JCRPageList<T> {
27  
28    private List<T> eventList_ = null;
29  
30    public EventPageList(List<T> eventList, long pageSize) throws Exception {
31      super(pageSize);
32      eventList_ = eventList;
33      setAvailablePage(eventList_.size());
34    }
35  
36    protected void populateCurrentPage(long page, String username) throws Exception {
37      setAvailablePage(eventList_.size());
38      long pageSize = getPageSize();
39      long position = 0;
40      if (page == 1)
41        position = 0;
42      else {
43        position = (page - 1) * pageSize;
44      }
45      currentListPage_ = new ArrayList<T>();
46      Long objPos = position;
47      if (position + pageSize > eventList_.size()) {
48        currentListPage_ = eventList_.subList(objPos.intValue(), eventList_.size());
49      } else {
50        Long objPageSize = pageSize;
51        currentListPage_ = eventList_.subList(objPos.intValue(), objPos.intValue() + objPageSize.intValue());
52      }
53    }
54  
55    @Override
56    public List<T> getAll() throws Exception {
57      return eventList_;
58    }
59  
60  }