SessionInfo.java

    1/*******************************************************************************
    2 * Copyright (c) 2009, 2010 Mountainminds GmbH & Co. KG and Contributors
    3 * All rights reserved. This program and the accompanying materials
    4 * are made available under the terms of the Eclipse Public License v1.0
    5 * which accompanies this distribution, and is available at
    6 * http://www.eclipse.org/legal/epl-v10.html
    7 *
    8 * Contributors:
    9 *    Marc R. Hoffmann - initial API and implementation
   10 *    
   11 *******************************************************************************/
   12package org.jacoco.core.data;
   13
   14
   15/**
   16 * Data object describing a session which was the source of execution data.
   17 * {@link SessionInfo} instances can be sorted by dump date through the
   18 * {@link Comparable} interface.
   19 * 
   20 * @author Marc R. Hoffmann
   21 * @version 0.4.1.20101007204400
   22 */
   23public class SessionInfo implements Comparable<SessionInfo> {
   24
   25    private final String id;
   26
   27    private final long start;
   28
   29    private final long dump;
   30
   31    /**
   32     * Create a immutable session info with the given data.
   33     * 
   34     * @param id
   35     *            arbitrary session identifier, must not be <code>null</code>
   36     * @param start
   37     *            the epoc based time stamp when execution data recording has
   38     *            been started
   39     * @param dump
   40     *            the epoc based time stamp when execution data was collected
   41     */
   42    public SessionInfo(final String id, final long start, final long dump) {
   43        if (id == null) {
   44            throw new NullPointerException();
   45        }
   46        this.id = id;
   47        this.start = start;
   48        this.dump = dump;
   49    }
   50
   51    /**
   52     * @return identifier for this session
   53     */
   54    public String getId() {
   55        return id;
   56    }
   57
   58    /**
   59     * @return the epoc based time stamp when execution data recording has been
   60     *         started
   61     */
   62    public long getStartTimeStamp() {
   63        return start;
   64    }
   65
   66    /**
   67     * @return the epoc based time stamp when execution data was collected
   68     */
   69    public long getDumpTimeStamp() {
   70        return dump;
   71    }
   72
   73    public int compareTo(final SessionInfo other) {
   74        if (this.dump < other.dump) {
   75            return -1;
   76        }
   77        if (this.dump > other.dump) {
   78            return +1;
   79        }
   80        return 0;
   81    }
   82
   83    @Override
   84    public String toString() {
   85        return "SessionInfo [" + id + "]";
   86    }
   87}