package com.tagtraum.perf.gcviewer;

import java.io.Serializable;

/**
 * GCEvent.
 *
 * Date: Jan 30, 2002
 * Time: 5:05:43 PM
 * @author <a href="mailto:hs@tagtraum.com">Hendrik Schreiber</a>
 * @version $Id: $
 */
public class GCEvent implements Serializable {

    private double timestamp;
    private long preUsed;
    private long postUsed;
    private long total;
    private double pause;
    private GCEvent.Type type = GCEvent.Type.GC;

    public GCEvent() {
    }

    public GCEvent(double timestamp, long preUsed, long postUsed, long total, double pause, GCEvent.Type type) {
        this.timestamp = timestamp;
        this.preUsed = preUsed;
        this.postUsed = postUsed;
        this.total = total;
        this.pause = pause;
        this.type = type;
    }

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

    public void setPreUsed(long preUsed) {
        this.preUsed = preUsed;
    }

    public void setPostUsed(long postUsed) {
        this.postUsed = postUsed;
    }

    public void setTotal(long total) {
        this.total = total;
    }

    public void setPause(double pause) {
        this.pause = pause;
    }

    public boolean isFull() {
        return type == GCEvent.Type.FULL_GC;
    }

    public boolean isInc() {
        return type == GCEvent.Type.INC_GC;
    }

    public void setType(GCEvent.Type type) {
        this.type = type;
    }

    public GCEvent.Type getType() {
        return type;
    }

    public double getPause() {
        return pause;
    }

    public double getTimestamp() {
        return timestamp;
    }

    public long getPreUsed() {
        return preUsed;
    }

    public long getPostUsed() {
        return postUsed;
    }

    public long getTotal() {
        return total;
    }

    // better than nothing hashcode
    public int hashCode() {
        return toString().hashCode();
    }

    // better than nothing equals
    public boolean equals(Object obj) {
        return toString().equals(obj.toString());
    }

    public String toString() {
        return timestamp + ": [" + type + " " + preUsed + "K->" + postUsed + "K(" + total + "K), " + pause + " secs]";
    }

    public static class Type implements Serializable {
        private final String type;

        private Type(String type) {
            this.type = type.intern();
        }

        public String toString() {
            return type;
        }

        public static final Type FULL_GC = new Type("Full GC");
        public static final Type GC = new Type("GC");
        public static final Type INC_GC = new Type("Inc GC");
    }
}
