<commit_before>package com.telekom.m2m.cot.restsdk.measurement;

import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.telekom.m2m.cot.restsdk.CloudOfThingsRestClient;
import com.telekom.m2m.cot.restsdk.util.ExtensibleObject;
import com.telekom.m2m.cot.restsdk.util.Filter;
import com.telekom.m2m.cot.restsdk.util.GsonUtils;

/**
 * Represents a pageable Measurement collection.
 * <p>
 * Collection can be scrolled with next() and prev().
 * <p>
 *
 * @since 0.1.0
 * Created by breucking on 14.02.16.
 */
public class MeasurementCollection /*implements Iterable<Measurement>*/ {

    private Filter.FilterBuilder criteria = null;
    private CloudOfThingsRestClient cloudOfThingsRestClient;
    private int pageCursor = 1;

    private Gson gson = GsonUtils.createGson();

    private static final String CONTENT_TYPE = "application/vnd.com.nsn.cumulocity.measurementCollection+json;charset=UTF-8;ver=0.9";
    private boolean nextAvailable = false;
    private boolean previousAvailable = false;
    private int pageSize = 5;

    /**
     * Creates a MeasurementCollection.
     * Use {@link MeasurementApi} to get MeasurementCollections.
     *
     * @param resultSize              size of the results (Max. 2000)
     * @param cloudOfThingsRestClient the necessary REST client to send requests to the CoT.
     */
    MeasurementCollection(int resultSize, CloudOfThingsRestClient cloudOfThingsRestClient) {
        this.cloudOfThingsRestClient = cloudOfThingsRestClient;
        this.pageSize = resultSize;
    }

    /**
     * Creates a MeasurementCollection with filters.
     * Use {@link MeasurementApi} to get MeasurementCollections.
     *
     * @param filterBuilder           the build criteria.
     * @param resultSize              size of the results (Max. 2000)
     * @param cloudOfThingsRestClient the necessary REST client to send requests to the CoT.
     */
    MeasurementCollection(Filter.FilterBuilder filterBuilder, int resultSize, CloudOfThingsRestClient cloudOfThingsRestClient) {
        this.criteria = filterBuilder;
        this.cloudOfThingsRestClient = cloudOfThingsRestClient;
        this.pageSize = resultSize;
    }

    /**
     * Retrieves the current page.
     *
     * @return array of found Measurements.
     * @since 0.1.0
     */
    public Measurement[] getMeasurements() {
        JsonObject object = getJsonObject(pageCursor);

        previousAvailable = object.has("prev");

        if (object.has("measurements")) {
            JsonArray jsonMeasurements = object.get("measurements").getAsJsonArray();
            Measurement[] arrayOfMeasurements = new Measurement[jsonMeasurements.size()];
            for (int i = 0; i < jsonMeasurements.size(); i++) {<commit_msg>Minor refactoring: parameter renaming<commit_after>package com.telekom.m2m.cot.restsdk.measurement;

import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.telekom.m2m.cot.restsdk.CloudOfThingsRestClient;
import com.telekom.m2m.cot.restsdk.util.ExtensibleObject;
import com.telekom.m2m.cot.restsdk.util.Filter;
import com.telekom.m2m.cot.restsdk.util.GsonUtils;

/**
 * Represents a pageable Measurement collection.
 * <p>
 * Collection can be scrolled with next() and prev().
 * <p>
 *
 * @since 0.1.0
 * Created by breucking on 14.02.16.
 */
public class MeasurementCollection /*implements Iterable<Measurement>*/ {

    private Filter.FilterBuilder criteria = null;
    private CloudOfThingsRestClient cloudOfThingsRestClient;
    private int pageCursor = 1;

    private Gson gson = GsonUtils.createGson();

    private static final String CONTENT_TYPE = "application/vnd.com.nsn.cumulocity.measurementCollection+json;charset=UTF-8;ver=0.9";
    private boolean nextAvailable = false;
    private boolean previousAvailable = false;
    private int pageSize = 5;

    /**
     * Creates a MeasurementCollection.
     * Use {@link MeasurementApi} to get MeasurementCollections.
     *
     * @param resultSize              size of the results (Max. 2000)
     * @param cloudOfThingsRestClient the necessary REST client to send requests to the CoT.
     */
    MeasurementCollection(int resultSize, CloudOfThingsRestClient cloudOfThingsRestClient) {
        this.cloudOfThingsRestClient = cloudOfThingsRestClient;
        this.pageSize = resultSize;
    }

    /**
     * Creates a MeasurementCollection with filters.
     * Use {@link MeasurementApi} to get MeasurementCollections.
     *
     * @param filters           the build criteria.
     * @param resultSize              size of the results (Max. 2000)
     * @param cloudOfThingsRestClient the necessary REST client to send requests to the CoT.
     */
    MeasurementCollection(Filter.FilterBuilder filters, int resultSize, CloudOfThingsRestClient cloudOfThingsRestClient) {
        this.criteria = filters;
        this.cloudOfThingsRestClient = cloudOfThingsRestClient;
        this.pageSize = resultSize;
    }

    /**
     * Retrieves the current page.
     *
     * @return array of found Measurements.
     * @since 0.1.0
     */
    public Measurement[] getMeasurements() {
        JsonObject object = getJsonObject(pageCursor);

        previousAvailable = object.has("prev");

        if (object.has("measurements")) {
            JsonArray jsonMeasurements = object.get("measurements").getAsJsonArray();
            Measurement[] arrayOfMeasurements = new Measurement[jsonMeasurements.size()];
            for (int i = 0; i < jsonMeasurements.size(); i++) {
{'fraction_non_alphanumeric': 0.09318423855165069, 'fraction_numerical': 0.011004614838480652, 'mean_word_length': 3.308103975535168, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '5015492', 'n_tokens_mistral': 1712, 'n_tokens_neox': 1559, 'n_words': 399}