<commit_before>/*<license>
Copyright 2004 - $Date$ by PeopleWare n.v..

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
</license>*/

package org.ppwcode.vernacular.persistence_III.dao;


import static org.ppwcode.metainfo_I.License.Type.APACHE_V2;

import java.io.Serializable;
import java.util.AbstractSequentialList;
import java.util.ConcurrentModificationException;
import java.util.List;
import java.util.ListIterator;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.ppwcode.metainfo_I.Copyright;
import org.ppwcode.metainfo_I.License;
import org.ppwcode.metainfo_I.vcs.SvnInfo;
import org.ppwcode.vernacular.persistence_III.PersistenceExternalError;
import org.ppwcode.vernacular.persistence_III.PersistentBean;



/**
 * A list of lists, that contains the result of a query
 * using paging. Each page, except for the last,
 * has size {@link #getPageSize()}.
 * When the virtual resultset on the DB changes during iteration,
 * we throw a {@link ConcurrentModificationException} when the next
 * page is requested.
 *
 * @author <NAME>
 * @author <NAME>
 * @author Peopleware n.v.
 *
 * @invar getPageSize() > 0;
 */
@Copyright("2004 - $Date$, PeopleWare n.v.")
@License(APACHE_V2)
@SvnInfo(revision = "$Revision$",
         date     = "$Date$")

public abstract class PagingList<_Id_ extends Serializable, _PersistentBean_ extends PersistentBean<_Id_>>
  extends AbstractSequentialList<List<_PersistentBean_>>{

  private static final Log LOG = LogFactory.getLog(PagingList.class);


  /*<construction>*/
  //------------------------------------------------------------------

  /**
   * @pre pageSize > 0;
   * @pre recordCount >= 0;
   * @post new.getPageSize() == pageSize;
   *
   * @throws TechnicalException
   */
  protected PagingList(int pageSize, int recordCount) throws PersistenceExternalError {
    assert pageSize > 0;
    assert recordCount >= 0;
    $pageSize = pageSize;
    $recordCount = recordCount;
    $size = ($recordCount == 0) ? 0 : (($recordCount - 1) / getPageSize()) + 1;
  }

  /*</construction>*/



  protected abstract int retrieveRecordCount() throws PersistenceExternalError;

  protected abstract List<_PersistentBean_> retrievePage(int retrieveSize, int startOfPage) throws PersistenceExternalError;



  /*<property name="page size">*/
  //------------------------------------------------------------------

  /**
   * @basic
   */
  public final int getPageSize() {
    return $pageSize;
  }

  /**
   * @invar $pageSize > 0;
   */
  private int $pageSize;

  /*</property>*/



  /*<property name="record count">*/
  //------------------------------------------------------------------

  /**
   * This must be the same on the next DB access,
   * or we give a {@link java.util.ConcurrentModificationException}.
   *
   * @basic
   */
  public final int getRecordCount() {
    return $recordCount;
  }

  /**
   * @invar $recordCount >= 0;
   */
  private int $recordCount;

  /*</property>*/



  /*<property name="size">*/
  //------------------------------------------------------------------

  /**
   * The number of pages. This might change,
   * when a next page is requested.
   *
   * @basic
   */
  @Override
  public final int size() {
    return $size;
  }

  /**
   * @invar $pageSize > 0;
   */
  private int $size;

  /*</property>*/



  /**
   * @result result instanceof PagesIterator;
   */
  @Override
  public final ListIterator<List<_PersistentBean_>> listIterator(int index) {
    return new PagesIterator(index);
  }

  public final class PagesIterator
    implements ListIterator<List<_PersistentBean_>> {

    /*<construction>*/
    //------------------------------------------------------------------

    /**
     * @pre page >= 0;
     * @pre page < size();<commit_msg>listIterator returns PageIterator (more strict return type than superclass)<commit_after>/*<license>
Copyright 2004 - $Date$ by PeopleWare n.v..

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
</license>*/

package org.ppwcode.vernacular.persistence_III.dao;


import static org.ppwcode.metainfo_I.License.Type.APACHE_V2;

import java.io.Serializable;
import java.util.AbstractSequentialList;
import java.util.ConcurrentModificationException;
import java.util.List;
import java.util.ListIterator;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.ppwcode.metainfo_I.Copyright;
import org.ppwcode.metainfo_I.License;
import org.ppwcode.metainfo_I.vcs.SvnInfo;
import org.ppwcode.vernacular.persistence_III.PersistenceExternalError;
import org.ppwcode.vernacular.persistence_III.PersistentBean;



/**
 * A list of lists, that contains the result of a query
 * using paging. Each page, except for the last,
 * has size {@link #getPageSize()}.
 * When the virtual resultset on the DB changes during iteration,
 * we throw a {@link ConcurrentModificationException} when the next
 * page is requested.
 *
 * @author <NAME>
 * @author <NAME>
 * @author Peopleware n.v.
 *
 * @invar getPageSize() > 0;
 */
@Copyright("2004 - $Date$, PeopleWare n.v.")
@License(APACHE_V2)
@SvnInfo(revision = "$Revision$",
         date     = "$Date$")

public abstract class PagingList<_Id_ extends Serializable, _PersistentBean_ extends PersistentBean<_Id_>>
  extends AbstractSequentialList<List<_PersistentBean_>>{

  private static final Log LOG = LogFactory.getLog(PagingList.class);


  /*<construction>*/
  //------------------------------------------------------------------

  /**
   * @pre pageSize > 0;
   * @pre recordCount >= 0;
   * @post new.getPageSize() == pageSize;
   *
   * @throws TechnicalException
   */
  protected PagingList(int pageSize, int recordCount) throws PersistenceExternalError {
    assert pageSize > 0;
    assert recordCount >= 0;
    $pageSize = pageSize;
    $recordCount = recordCount;
    $size = ($recordCount == 0) ? 0 : (($recordCount - 1) / getPageSize()) + 1;
  }

  /*</construction>*/



  protected abstract int retrieveRecordCount() throws PersistenceExternalError;

  protected abstract List<_PersistentBean_> retrievePage(int retrieveSize, int startOfPage) throws PersistenceExternalError;



  /*<property name="page size">*/
  //------------------------------------------------------------------

  /**
   * @basic
   */
  public final int getPageSize() {
    return $pageSize;
  }

  /**
   * @invar $pageSize > 0;
   */
  private int $pageSize;

  /*</property>*/



  /*<property name="record count">*/
  //------------------------------------------------------------------

  /**
   * This must be the same on the next DB access,
   * or we give a {@link java.util.ConcurrentModificationException}.
   *
   * @basic
   */
  public final int getRecordCount() {
    return $recordCount;
  }

  /**
   * @invar $recordCount >= 0;
   */
  private int $recordCount;

  /*</property>*/



  /*<property name="size">*/
  //------------------------------------------------------------------

  /**
   * The number of pages. This might change,
   * when a next page is requested.
   *
   * @basic
   */
  @Override
  public final int size() {
    return $size;
  }

  /**
   * @invar $pageSize > 0;
   */
  private int $size;

  /*</property>*/



  @Override
  public final PagesIterator listIterator(int index) {
    return new PagesIterator(index);
  }

  public final class PagesIterator
    implements ListIterator<List<_PersistentBean_>> {

    /*<construction>*/
    //------------------------------------------------------------------

    /**
     * @pre page >= 0;
     * @pre page < size();
{'fraction_non_alphanumeric': 0.186832531393029, 'fraction_numerical': 0.006337284356296209, 'mean_word_length': 2.553794829024187, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 63, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '382482', 'n_tokens_mistral': 2535, 'n_tokens_neox': 2404, 'n_words': 711}