• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*******************************************************************************
2  * Copyright (c) 2009, 2021 Mountainminds GmbH & Co. KG and Contributors
3  * This program and the accompanying materials are made available under
4  * the terms of the Eclipse Public License 2.0 which is available at
5  * http://www.eclipse.org/legal/epl-2.0
6  *
7  * SPDX-License-Identifier: EPL-2.0
8  *
9  * Contributors:
10  *    Marc R. Hoffmann - initial API and implementation
11  *
12  *******************************************************************************/
13 package org.jacoco.core.data;
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 public class SessionInfo implements Comparable<SessionInfo> {
21 
22 	private final String id;
23 
24 	private final long start;
25 
26 	private final long dump;
27 
28 	/**
29 	 * Create a immutable session info with the given data.
30 	 *
31 	 * @param id
32 	 *            arbitrary session identifier, must not be <code>null</code>
33 	 * @param start
34 	 *            the epoc based time stamp when execution data recording has
35 	 *            been started
36 	 * @param dump
37 	 *            the epoc based time stamp when execution data was collected
38 	 */
SessionInfo(final String id, final long start, final long dump)39 	public SessionInfo(final String id, final long start, final long dump) {
40 		if (id == null) {
41 			throw new IllegalArgumentException();
42 		}
43 		this.id = id;
44 		this.start = start;
45 		this.dump = dump;
46 	}
47 
48 	/**
49 	 * @return identifier for this session
50 	 */
getId()51 	public String getId() {
52 		return id;
53 	}
54 
55 	/**
56 	 * @return the epoc based time stamp when execution data recording has been
57 	 *         started
58 	 */
getStartTimeStamp()59 	public long getStartTimeStamp() {
60 		return start;
61 	}
62 
63 	/**
64 	 * @return the epoc based time stamp when execution data was collected
65 	 */
getDumpTimeStamp()66 	public long getDumpTimeStamp() {
67 		return dump;
68 	}
69 
compareTo(final SessionInfo other)70 	public int compareTo(final SessionInfo other) {
71 		if (this.dump < other.dump) {
72 			return -1;
73 		}
74 		if (this.dump > other.dump) {
75 			return +1;
76 		}
77 		return 0;
78 	}
79 
80 	@Override
toString()81 	public String toString() {
82 		return "SessionInfo[" + id + "]";
83 	}
84 }
85