// Path: src/main/java/com/ccreanga/bitbucket/rest/client/model/Page.java
// public class Page<T> implements Serializable {
//     private int size;
//     private int limit;
//     private boolean lastPage;
//     private int start;
//     @Nullable
//     private Integer nextPageStart;
//     @Nonnull
//     private List<T> values;
// 
//     private Page() {
//     }
// 
//     public Page(int size, int limit, boolean lastPage, int start, @Nullable Integer nextPageStart, @Nonnull Iterable<T> values) {
//         if ((!lastPage) && (nextPageStart==null))
//             throw new IllegalArgumentException("nextPageStart should be not null if lastPage is false");
//         this.size = size;
//         this.limit = limit;
//         this.lastPage = lastPage;
//         this.values = ImmutableList.copyOf(values);
//         this.start = start;
//         this.nextPageStart = nextPageStart;
//     }
// 
//     public int getSize() {
//         return size;
//     }
// 
//     public int getLimit() {
//         return limit;
//     }
// 
//     public boolean isLastPage() {
//         return lastPage;
//     }
// 
//     @Nonnull
//     public List<T> getValues() {
//         return values;
//     }
// 
//     public int getStart() {
//         return start;
//     }
// 
//     @Nullable
//     public Integer getNextPageStart() {
//         return nextPageStart;
//     }
// 
//     @Override
//     public String toString() {
//         return "Page{" +
//                 "size=" + size +
//                 ", limit=" + limit +
//                 ", lastPage=" + lastPage +
//                 ", start=" + start +
//                 ", nextPageStart=" + nextPageStart +
//                 ", values=" + values +
//                 '}';
//     }
// 
//     @Override
//     public boolean equals(Object o) {
//         if (this == o) return true;
//         if (o == null || getClass() != o.getClass()) return false;
//         Page<?> page = (Page<?>) o;
//         return java.util.Objects.equals(size, page.size) &&
//                 java.util.Objects.equals(limit, page.limit) &&
//                 java.util.Objects.equals(lastPage, page.lastPage) &&
//                 java.util.Objects.equals(start, page.start) &&
//                 java.util.Objects.equals(nextPageStart, page.nextPageStart) &&
//                 java.util.Objects.equals(values, page.values);
//     }
// 
//     @Override
//     public int hashCode() {
//         return java.util.Objects.hash(size, limit, lastPage, start, nextPageStart, values);
//     }
// }
// 
// Path: src/main/java/com/ccreanga/bitbucket/rest/client/http/responseparsers/ParserUtil.java
// public static boolean optionalJsonBoolean(JsonObject json, String name) {
//     JsonElement element = json.get(name);
//     if ((element == null) || (element.isJsonNull()))
//         return false;
//     return element.getAsBoolean();
// }
// 
// Path: src/main/java/com/ccreanga/bitbucket/rest/client/http/responseparsers/ParserUtil.java
// public static long optionalJsonLong(JsonObject json, String name) {
//     JsonElement element = json.get(name);
//     if ((element == null) || (element.isJsonNull()))
//         return -1;
//     return element.getAsLong();
// }


import com.ccreanga.bitbucket.rest.client.model.Page;
import java.util.function.Function;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import java.util.List;
import static com.ccreanga.bitbucket.rest.client.http.responseparsers.ParserUtil.optionalJsonBoolean;
import static com.ccreanga.bitbucket.rest.client.http.responseparsers.ParserUtil.optionalJsonLong;
/*
 *
 *  *
 *  * 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.ccreanga.bitbucket.rest.client.http.responseparsers;




class PageParser<T> implements Function<JsonElement, Page<T>> {
    Function<JsonElement, T> valueParser;

    public PageParser(Function<JsonElement, T> valueParser) {
        this.valueParser = valueParser;
    }

    @Override
    public Page<T> apply(JsonElement jsonElement) {
        JsonObject json = jsonElement.getAsJsonObject();
        List<T> values = Parsers.listParser(valueParser).apply(json.getAsJsonArray("values"));

        return new Page<>(
                json.get("size").getAsInt(),
                json.get("limit").getAsInt(),
                optionalJsonBoolean(json, "isLastPage"),
                json.get("start").getAsInt(),
// Path: src/main/java/com/ccreanga/bitbucket/rest/client/model/Page.java
// public class Page<T> implements Serializable {
//     private int size;
//     private int limit;
//     private boolean lastPage;
//     private int start;
//     @Nullable
//     private Integer nextPageStart;
//     @Nonnull
//     private List<T> values;
// 
//     private Page() {
//     }
// 
//     public Page(int size, int limit, boolean lastPage, int start, @Nullable Integer nextPageStart, @Nonnull Iterable<T> values) {
//         if ((!lastPage) && (nextPageStart==null))
//             throw new IllegalArgumentException("nextPageStart should be not null if lastPage is false");
//         this.size = size;
//         this.limit = limit;
//         this.lastPage = lastPage;
//         this.values = ImmutableList.copyOf(values);
//         this.start = start;
//         this.nextPageStart = nextPageStart;
//     }
// 
//     public int getSize() {
//         return size;
//     }
// 
//     public int getLimit() {
//         return limit;
//     }
// 
//     public boolean isLastPage() {
//         return lastPage;
//     }
// 
//     @Nonnull
//     public List<T> getValues() {
//         return values;
//     }
// 
//     public int getStart() {
//         return start;
//     }
// 
//     @Nullable
//     public Integer getNextPageStart() {
//         return nextPageStart;
//     }
// 
//     @Override
//     public String toString() {
//         return "Page{" +
//                 "size=" + size +
//                 ", limit=" + limit +
//                 ", lastPage=" + lastPage +
//                 ", start=" + start +
//                 ", nextPageStart=" + nextPageStart +
//                 ", values=" + values +
//                 '}';
//     }
// 
//     @Override
//     public boolean equals(Object o) {
//         if (this == o) return true;
//         if (o == null || getClass() != o.getClass()) return false;
//         Page<?> page = (Page<?>) o;
//         return java.util.Objects.equals(size, page.size) &&
//                 java.util.Objects.equals(limit, page.limit) &&
//                 java.util.Objects.equals(lastPage, page.lastPage) &&
//                 java.util.Objects.equals(start, page.start) &&
//                 java.util.Objects.equals(nextPageStart, page.nextPageStart) &&
//                 java.util.Objects.equals(values, page.values);
//     }
// 
//     @Override
//     public int hashCode() {
//         return java.util.Objects.hash(size, limit, lastPage, start, nextPageStart, values);
//     }
// }
// 
// Path: src/main/java/com/ccreanga/bitbucket/rest/client/http/responseparsers/ParserUtil.java
// public static boolean optionalJsonBoolean(JsonObject json, String name) {
//     JsonElement element = json.get(name);
//     if ((element == null) || (element.isJsonNull()))
//         return false;
//     return element.getAsBoolean();
// }
// 
// Path: src/main/java/com/ccreanga/bitbucket/rest/client/http/responseparsers/ParserUtil.java
// public static long optionalJsonLong(JsonObject json, String name) {
//     JsonElement element = json.get(name);
//     if ((element == null) || (element.isJsonNull()))
//         return -1;
//     return element.getAsLong();
// }


// Path: src/main/java/com/ccreanga/bitbucket/rest/client/http/responseparsers/PageParser.java
import com.ccreanga.bitbucket.rest.client.model.Page;
import java.util.function.Function;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import java.util.List;
import static com.ccreanga.bitbucket.rest.client.http.responseparsers.ParserUtil.optionalJsonBoolean;
import static com.ccreanga.bitbucket.rest.client.http.responseparsers.ParserUtil.optionalJsonLong;

/*
 *
 *  *
 *  * 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.ccreanga.bitbucket.rest.client.http.responseparsers;




class PageParser<T> implements Function<JsonElement, Page<T>> {
    Function<JsonElement, T> valueParser;

    public PageParser(Function<JsonElement, T> valueParser) {
        this.valueParser = valueParser;
    }

    @Override
    public Page<T> apply(JsonElement jsonElement) {
        JsonObject json = jsonElement.getAsJsonObject();
        List<T> values = Parsers.listParser(valueParser).apply(json.getAsJsonArray("values"));

        return new Page<>(
                json.get("size").getAsInt(),
                json.get("limit").getAsInt(),
                optionalJsonBoolean(json, "isLastPage"),
                json.get("start").getAsInt(),
                (int) optionalJsonLong(json, "nextPageStart"),