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

com.eg.agent.android.harvest.ActivitySighting Maven / Gradle / Ivy

There is a newer version: 2.1.3
Show newest version
package com.eg.agent.android.harvest;
/*
import com.newrelic.agent.android.harvest.type.HarvestableArray;
import com.newrelic.agent.android.util.SafeJsonPrimitive;
import com.newrelic.com.google.gson.JsonArray;*/

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

public class ActivitySighting extends HarvestableArray {
    private long durationMs = 0;
    private String name;
    private final long timestampMs;

    public ActivitySighting(long timestampMs, String name) {
        this.timestampMs = timestampMs;
        this.name = name;
    }

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        synchronized (this) {
            this.name = name;
        }
    }

    public long getTimestampMs() {
        return this.timestampMs;
    }

    public long getDuration() {
        return this.durationMs;
    }

    public void end(long endTimestampMs) {
        synchronized (this) {
            this.durationMs = endTimestampMs - this.timestampMs;
        }
    }

    public JsonArray asJsonArray() {
        JsonArray data = new JsonArray();
        synchronized (this) {
            data.add(SafeJsonPrimitive.factory(this.name));
            data.add(SafeJsonPrimitive.factory(Long.valueOf(this.timestampMs)));
            data.add(SafeJsonPrimitive.factory(Long.valueOf(this.durationMs)));
        }
        return data;
    }

    public JsonArray asJsonArrayWithoutDuration() {
        JsonArray data = new JsonArray();
        synchronized (this) {
            data.add(SafeJsonPrimitive.factory(Long.valueOf(this.timestampMs)));
            data.add(SafeJsonPrimitive.factory(this.name));
        }
        return data;
    }

    public static ActivitySighting newFromJson(JsonArray jsonArray) {
        return new ActivitySighting(jsonArray.get(0).getAsLong(), jsonArray.get(1).getAsString());
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy