All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hecloud.runtime.common.query.GridBuilder Maven / Gradle / Ivy

package com.hecloud.runtime.common.query;

import com.hecloud.runtime.common.query.Grid;
import lombok.Builder;

import java.util.List;
import java.util.Optional;

/**
 * @author LoveinBJ
 */
@Builder
public class GridBuilder {

    public Grid build(Integer page, Integer rows, Integer total, List data) {
        page = Optional.ofNullable(page).orElse(0);
        rows = Optional.ofNullable(rows).orElse(10);
        total = Optional.ofNullable(total).orElse(0);
        int pages;
        if (total % rows == 0) {
            pages = total / rows;
        } else {
            pages = total / rows + 1;
        }
        pages = pages < 1 ? 1 : pages;
        return new Grid(page, pages, total, data);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy