com.introproventures.graphql.jpa.query.schema.impl.PagedResult Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of graphql-jpa-query-schema Show documentation
Show all versions of graphql-jpa-query-schema Show documentation
Provides GraphQL JPA Query Schema Generation and Execution Support
The newest version!
/*
* Copyright 2017 IntroPro Ventures Inc. and/or its affiliates.
*
* 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.
*/
package com.introproventures.graphql.jpa.query.schema.impl;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
public class PagedResult {
private final long limit;
private final long total;
private final long pages;
private final int offset;
private final List select;
private final Map aggregate;
private PagedResult(Builder builder) {
this.limit = builder.limit;
this.total = builder.total;
this.offset = builder.offset;
this.select = builder.select;
this.pages = ((Double) Math.ceil(total / (double) limit)).longValue();
this.aggregate = builder.aggregate;
}
public Long getTotal() {
return total;
}
public Long getPages() {
return pages;
}
public Integer getOffset() {
return offset;
}
public List getSelect() {
return select;
}
public long getLimit() {
return limit;
}
public Map getAggregate() {
return aggregate;
}
/**
* Creates builder to build {@link PagedResult}.
* @return created builder
*/
public static Builder builder() {
return new Builder<>();
}
/**
* Builder to build {@link PagedResult}.
*/
public static final class Builder {
private long limit;
private long total;
private long pages;
private int offset;
private List select = Collections.emptyList();
private Map aggregate = new LinkedHashMap<>();
private Builder() {}
/**
* Builder method for limit parameter.
* @param limit field to set
* @return builder
*/
public Builder withLimit(long limit) {
this.limit = limit;
return this;
}
/**
* Builder method for total parameter.
* @param total field to set
* @return builder
*/
public Builder withTotal(long total) {
this.total = total;
return this;
}
/**
* Builder method for pages parameter.
* @param pages field to set
* @return builder
*/
public Builder withPages(long pages) {
this.pages = pages;
return this;
}
/**
* Builder method for offset parameter.
* @param offset field to set
* @return builder
*/
public Builder withOffset(int offset) {
this.offset = offset;
return this;
}
/**
* Builder method for select parameter.
* @param select field to set
* @return builder
*/
public Builder withSelect(List select) {
this.select = select;
return this;
}
/**
* Builder method for select parameter.
* @param select field to set
* @return builder
*/
public Builder withAggregate(Map aggregate) {
this.aggregate.putAll(aggregate);
return this;
}
/**
* Builder method of the builder.
* @return built class
*/
public PagedResult build() {
return new PagedResult<>(this);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy