Calculate stuff for pagination
@throws Exception
519515
public function calculate(): Pagination
    {
        // calculate how many page
        $this->pages_count = 1;
        if ($this->items_count > 0 && $this->items_per_page > 0) {
            $this->pages_count = ceil(($this->items_count / $this->items_per_page));
        } elseif ($this->items_count == 0) {
            $this->pages_count = 0;
        }
        
        // generate pages array
        $this->pages = [];
        if ($this->pages_count > 0) {
            $this->pages = range(1, $this->pages_count);
        }

        // check current page
        if (!$this->isPage($this->current_page)) {
            throw new Exception(__CLASS__.': page '.$this->current_page.' doesn\'t exists');
        }

        $this->first_page = empty($this->pages) ? null : 1;
        $this->last_page = ($this->pages_count < 1) ? null : $this->pages_count;

        // prev/next page
        $this->prev_page = ($this->current_page > 1) ? $this->current_page  - 1 : null;
        $this->next_page = (($this->current_page + 1) <= $this->pages_count) ? $this->current_page + 1 : null;
        
        // item start/end page
        $this->item_start = (($this->current_page - 1) * $this->items_per_page);
        $this->item_end = $this->item_start + $this->items_per_page;
        
        if (($this->items_count != 0)) {
            ++$this->item_start;
        }
        if ($this->item_end > $this->items_count) {
            $this->item_end = $this->items_count;
        }

        // item start offset
        $this->offset = $this->item_start - 1;

        return $this;
    }
111305
private function getPaginationPageSize()
    {
        $limitNode = $this->getPaginationLimitNode();

        if ($limitNode) {
            $limit = $limitNode->getLimit();

            if ($limit < 1) {
                throw new SyntaxErrorException('invalid limit in rql');
            }

            return $limit;
        }

        return $this->paginationDefaultLimit;
    }
427225
private final void applyPagination(final Query query,
            final PaginationData pagination) {
        query.setFirstResult(
                (pagination.getPageNumber() - 1) * pagination.getPageSize());
        query.setMaxResults(pagination.getPageSize());
    }
670726
protected function calculateNumbers()
	{
		// do we need to fetch or calculate the current page number?
		if (empty($this->config['current']))
		{
			// do we have a segment number?
			if ( ! empty($this->config['uriSegment']))
			{
				$segments = explode('/', trim($this->input->getPathInfo(),'/'));
				if (isset($segments[$this->config['uriSegment']]) and is_numeric($segments[$this->config['uriSegment']]))
				{
					$this->config['current'] = $segments[$this->config['uriSegment']];
				}
			}

			// do we have a getVariable set?
			if ( ! empty($this->config['getVariable']) and $get = $this->input->getQuery())
			{
				if (isset($get[$this->config['getVariable']]) and is_numeric($get[$this->config['getVariable']]))
				{
					$this->config['current'] = $get[$this->config['uriSegment']];
				}
			}

			// if none could be determine, try to calculate it
			if (empty($this->config['current']) and $this->config['offset'] and $this->config['limit'])
			{
				$this->config['current'] = (int) ($this->config['offset'] / $this->config['limit']) + 1;
			}

			// if all else fails, default to one
			if (empty($this->config['current']))
			{
				$this->config['current'] = 1;
			}
		}

		// do we need to calculate the total number of pages
		if (empty($this->config['totalPages']) and ! empty($this->config['totalItems']) and ! empty($this->config['limit']))
		{
			$this->config['totalPages'] = (int) ($this->config['totalItems'] / $this->config['limit']) + 1;
		}
	}
354611
public function count()
    {
        if ($this->count === null) {
            if ($this->dataSource instanceof \Countable) {
                $this->count = $this->dataSource->count();
            } elseif (is_array($this->dataSource)) {
                $this->count = count($this->dataSource);
            } else {
                throw new Exception\RuntimeException(sprintf(
                    'DataSource with type "%s" cannot be counted',
                    gettype($this->dataSource)
                ));
            }
        }
        return $this->count;
    }
1295214
private int calculatePageSize()
    {
        int meanColumnCount = hintStore.getMeanColumns();
        if (meanColumnCount <= 0)
            return PAGE_SIZE;

        int averageColumnSize = (int) (hintStore.getMeanRowSize() / meanColumnCount);
        if (averageColumnSize <= 0)
            return PAGE_SIZE;

        // page size of 1 does not allow actual paging b/c of >= behavior on startColumn
        return Math.max(2, Math.min(PAGE_SIZE, 4 * 1024 * 1024 / averageColumnSize));
    }
1183232
public function pagination()
    {
        $pageCount = ceil($this->totalItems / $this->itemPerPage);
        if ($this->current >= 1 && $this->current <= $pageCount) {
            $current_range = [($this->current - 2 < 1 ? 1 : $this->current - 2), ($this->current + 2 > $pageCount ? $pageCount : $this->current + 2)];
            $first_page = $this->current > 5 ? '<li><a href="'.$this->baseUrl.$this->urlAppend.'1'.'" class="'.$this->aClass.'">'.printl('first:page:pagination').'</a></li>'.($this->current < 5 ? ', ' : ' <li class="'.$this->liClass.'"><a href="#!" class="'.$this->aClass.' disable" disabled >...</a></li> ') : null;
            $last_page = $this->current < $pageCount - 2 ? ($this->current > $pageCount - 4 ? ', ' : ' <li class="'.$this->liClass.' disable"><a href="#!" class="'.$this->aClass.'" disabled >...</a></li>  ').'<li><a href="'.$this->baseUrl.$this->urlAppend.$pageCount.'" class="'.$this->aClass.'">'.printl('last:page:pagination').'</a></li>' : null;
            $previous_page = $this->current > 1 ? '<li class="'.$this->liClass.'"><a class="'.$this->aClass.'"href="'.$this->baseUrl.$this->urlAppend.($this->current - 1).'">'.printl('prev:page:pagination').'</a></li>  ' : null;
            $next_page = $this->current < $pageCount ? '  <li class="'.$this->liClass.'"><a class="'.$this->aClass.'" href="'.$this->baseUrl.$this->urlAppend.($this->current + 1).'">'.printl('next:page:pagination').'</a></li>' : null;
            for ($x = $current_range[0]; $x <= $current_range[1]; $x++) {
                $pages[] = '<li class="'.$this->liClass.'"active"><a class="'.$this->aClass.'" href="'.$this->baseUrl.$this->urlAppend.$x.'" '.($x == $this->current ? 'class="'.$this->aClass.'"' : '').'>'.$x.'</a></li>';
            }
            if ($pageCount > 1) {
                return '<ul class="'.$this->ulCLass.'"> '.$previous_page.$first_page.implode(', ', $pages).$last_page.$next_page.'</ul>';
            }
        }
    }
198382
static double callLegacy(PageContext pc, Array array, Object value) throws PageException {
	String str = Caster.toString(value, null);
	if (str != null) return ArrayUtil.arrayContainsIgnoreEmpty(array, str, false) + 1;
	return ArrayFind.call(pc, array, value);
    }
698887
@Execute
    public void process() throws Exception {
        if (!concatOr(outFlow == null, doReset)) {
            return;
        }
        checkNull(inFlow, inPit);

        RegionMap regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(inPit);
        cols = regionMap.getCols();
        rows = regionMap.getRows();
        xRes = regionMap.getXres();
        yRes = regionMap.getYres();
        dxySqrt = Math.sqrt(xRes * xRes + yRes * yRes);

        RenderedImage pitfillerRI = inPit.getRenderedImage();
        WritableRaster pitfillerWR = CoverageUtilities.renderedImage2DoubleWritableRaster(pitfillerRI, true);
        RenderedImage flowRI = inFlow.getRenderedImage();
        WritableRaster flowWR = CoverageUtilities.renderedImage2ShortWritableRaster(flowRI, true);

        RandomIter pitRandomIter = RandomIterFactory.create(pitfillerWR, null);

        // create new matrix
        double[] orderedelev = new double[cols * rows];
        int[] indexes = new int[cols * rows];

        int nelev = 0;
        for( int r = 0; r < rows; r++ ) {
            if (pm.isCanceled()) {
                return;
            }
            for( int c = 0; c < cols; c++ ) {
                double pitValue = pitRandomIter.getSampleDouble(c, r, 0);
                int pos = (r * cols) + c;
                orderedelev[pos] = pitValue;
                indexes[pos] = pos + 1;
                if (!isNovalue(pitValue)) {
                    nelev = nelev + 1;
                }
            }
        }

        QuickSortAlgorithm t = new QuickSortAlgorithm(pm);
        t.sort(orderedelev, indexes);

        pm.message(msg.message("draindir.initializematrix"));

        // Initialize new RasterData and set value
        WritableRaster tcaWR = CoverageUtilities.createWritableRaster(cols, rows, Integer.class, null, HMConstants.intNovalue);
        WritableRaster dirWR = CoverageUtilities.createWritableRaster(cols, rows, Short.class, null, HMConstants.shortNovalue);

        // it contains the analyzed cells
        WritableRaster deviationsWR = CoverageUtilities.createWritableRaster(cols, rows, Double.class, null, null);
        BitMatrix analizedMatrix = new BitMatrix(cols, rows);

        if (doLad) {
            orlandiniD8LAD(indexes, deviationsWR, analizedMatrix, pitfillerWR, flowWR, tcaWR, dirWR, nelev);
        } else {
            orlandiniD8LTD(indexes, deviationsWR, analizedMatrix, pitfillerWR, flowWR, tcaWR, dirWR, nelev);
            if (pm.isCanceled()) {
                return;
            }
            // only if required executes this method
            if (inFlownet != null) {
                newDirections(pitfillerWR, dirWR);
            }
        }
        if (pm.isCanceled()) {
            return;
        }
        outFlow = CoverageUtilities.buildCoverage("draindir", dirWR, regionMap, inPit.getCoordinateReferenceSystem());
        outTca = CoverageUtilities.buildCoverage("tca", tcaWR, regionMap, inPit.getCoordinateReferenceSystem());
    }
22532
def paginate(self, skip, limit):
        """"""
        if not self.count() or not limit:
            return
        skip = skip or 0
        pages = int(ceil(self.count() / float(limit)))
        limits = {}
        last = 0
        for i in range(pages):
            current = limit * i
            limits[last] = current
            last = current
        # example with count == 62
        # {0: 20, 20: 40, 40: 60, 60: 62}
        if limit and limit < self.count():
            limit = limits.get(skip, self.count())
            self.cursordat = self.cursordat[skip: limit]
946419
public static int totalPage(int totalCount, int pageSize) {
		if (pageSize == 0) {
			return 0;
		}
		return totalCount % pageSize == 0 ? (totalCount / pageSize) : (totalCount / pageSize + 1);
	}
61482
public function balance() {
        $data = $this->getSend()->parameters([
            'method' => 'GetNum'
        ])->json();
        if ($data['code'] == 2) {
            return $data['num'];
        }
        throw new \Exception($data['msg']);
    }
1135586
public function pagination(): array
	{
		if(empty($this->pagination))
		{
			if(empty($this->request))
			{
				throw new RuntimeException('A [ Request ] instance is required to generate the pagination array.');
			}

			if(empty($this->urlBuilder))
			{
				throw new RuntimeException('A [ URLBuilder ] instance is required to generate the pagination array.');
			}

			$pagination = $this->toArray();

			if($this->options['max_page_links'] !== 0)
			{
				if($this->pages > $this->options['max_page_links'])
				{
					$start = (int) max(($this->currentPage) - ceil($this->options['max_page_links'] / 2), 0);

					$end = $start + $this->options['max_page_links'];

					if($end > $this->pages)
					{
						$end = $this->pages;
					}

					if($start > ($end - $this->options['max_page_links']))
					{
						$start = $end - $this->options['max_page_links'];
					}
				}
				else
				{
					$start = 0;

					$end = $this->pages;
				}

				$pagination['pages'] = [];

				for($i = $start + 1; $i <= $end; $i++)
				{
					$pagination['pages'][] =
					[
						'url'        => $this->buildPageUrl($i),
						'number'     => $i,
						'is_current' => $i === $this->currentPage,
					];
				}
			}

			$this->pagination = $pagination;
		}

		return $this->pagination;
	}
570330
protected function setPagerOrderIndexAccount()
    {
        $conditions = array(
            'count' => true,
            'user_id' => $this->data_user['user_id']
        );

        $pager = array(
            'query' => $this->query_filter,
            'total' => (int) $this->order->getList($conditions),
            'limit' => $this->config('account_order_limit', 10)
        );

        return $this->data_limit = $this->setPager($pager);
    }
298106
public function preparePaginationResponse()
    {
        return new Response($this->total, $this->perPage, $this->page, $this->lastPage);
    }
862088
@Override
  public int count() {

    int listSize = getList().size();
    int pageSize = getPageSize();
    int pageCount = listSize / pageSize;

    pageCount += listSize % pageSize > 0 ? 1 : 0;

    return pageCount;
  }
127929
public function paginate()
    {
        try {
            $this->query = $this->query->paginate($this->getPaginationConfig());
        } catch (\Exception $e) {
            throw new QueryException($e);
        }
    }