• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*******************************************************************************
2  * Copyright (c) 2009, 2017 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  *******************************************************************************/
12 package org.jacoco.core.data;
13 
14 /**
15  * Data object describing a session which was the source of execution data.
16  * {@link SessionInfo} instances can be sorted by dump date through the
17  * {@link Comparable} interface.
18  */
19 public class SessionInfo implements Comparable<SessionInfo> {
20 
21 	private final String id;
22 
23 	private final long start;
24 
25 	private final long dump;
26 
27 	/**
28 	 * Create a immutable session info with the given data.
29 	 *
30 	 * @param id
31 	 *            arbitrary session identifier, must not be <code>null</code>
32 	 * @param start
33 	 *            the epoc based time stamp when execution data recording has
34 	 *            been started
35 	 * @param dump
36 	 *            the epoc based time stamp when execution data was collected
37 	 */
SessionInfo(final String id, final long start, final long dump)38 	public SessionInfo(final String id, final long start, final long dump) {
39 		if (id == null) {
40 			throw new IllegalArgumentException();
41 		}
42 		this.id = id;
43 		this.start = start;
44 		this.dump = dump;
45 	}
46 
47 	/**
48 	 * @return identifier for this session
49 	 */
getId()50 	public String getId() {
51 		return id;
52 	}
53 
54 	/**
55 	 * @return the epoc based time stamp when execution data recording has been
56 	 *         started
57 	 */
getStartTimeStamp()58 	public long getStartTimeStamp() {
59 		return start;
60 	}
61 
62 	/**
63 	 * @return the epoc based time stamp when execution data was collected
64 	 */
getDumpTimeStamp()65 	public long getDumpTimeStamp() {
66 		return dump;
67 	}
68 
compareTo(final SessionInfo other)69 	public int compareTo(final SessionInfo other) {
70 		if (this.dump < other.dump) {
71 			return -1;
72 		}
73 		if (this.dump > other.dump) {
74 			return +1;
75 		}
76 		return 0;
77 	}
78 
79 	@Override
toString()80 	public String toString() {
81 		return "SessionInfo[" + id + "]";
82 	}
83 }
84