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

com.eg.agent.android.trace.Sample Maven / Gradle / Ivy

There is a newer version: 2.1.3
Show newest version
package com.eg.agent.android.trace;

import com.eg.agent.android.harvest.type.HarvestableArray;
import com.eg.agent.android.util.SafeJsonPrimitive;
import com.eg.google.gson.JsonArray;

public class Sample extends HarvestableArray {
    private SampleValue sampleValue;
    private long timestamp;
    private SampleType type;

    public enum SampleType {
        MEMORY,
        CPU
    }

    public Sample(SampleType type) {
        setSampleType(type);
        setTimestamp(System.currentTimeMillis());
    }

    public Sample(long timestamp) {
        setTimestamp(timestamp);
    }

    public Sample(long timestamp, SampleValue sampleValue) {
        setTimestamp(timestamp);
        setSampleValue(sampleValue);
    }

    public long getTimestamp() {
        return this.timestamp;
    }

    public void setTimestamp(long timestamp) {
        this.timestamp = timestamp;
    }

    public SampleValue getSampleValue() {
        return this.sampleValue;
    }

    public void setSampleValue(SampleValue sampleValue) {
        this.sampleValue = sampleValue;
    }

    public void setSampleValue(double value) {
        this.sampleValue = new SampleValue(value);
    }

    public void setSampleValue(long value) {
        this.sampleValue = new SampleValue(value);
    }

    public Number getValue() {
        return this.sampleValue.getValue();
    }

    public SampleType getSampleType() {
        return this.type;
    }

    public void setSampleType(SampleType type) {
        this.type = type;
    }

    public JsonArray asJsonArray() {
        JsonArray jsonArray = new JsonArray();
        jsonArray.add(SafeJsonPrimitive.factory(Long.valueOf(this.timestamp)));
        jsonArray.add(SafeJsonPrimitive.factory(this.sampleValue.getValue()));
        return jsonArray;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy