Commit | Line | Data |
---|---|---|
8c8bf09f ASL |
1 | /******************************************************************************* |
2 | * Copyright (c) 2009 Ericsson | |
3 | * | |
4 | * All rights reserved. This program and the accompanying materials are | |
5 | * made available under the terms of the Eclipse Public License v1.0 which | |
6 | * accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
8 | * | |
9 | * Contributors: | |
10 | * Francois Chouinard - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
13 | package org.eclipse.linuxtools.tmf.event; | |
14 | ||
15 | /** | |
1f506a43 | 16 | * <b><u>TmfTimeWindow</u></b> |
8c8bf09f ASL |
17 | * <p> |
18 | * A utility class to define time ranges. | |
19 | */ | |
20 | public class TmfTimeRange { | |
21 | ||
62d1696a FC |
22 | // ======================================================================== |
23 | // Constants | |
24 | // ======================================================================== | |
25 | ||
26 | public static TmfTimeRange Eternity = new TmfTimeRange(TmfTimestamp.BigBang, TmfTimestamp.BigCrunch); | |
27 | ||
1f506a43 | 28 | // ======================================================================== |
8c8bf09f | 29 | // Attributes |
1f506a43 | 30 | // ======================================================================== |
8c8bf09f ASL |
31 | |
32 | private final TmfTimestamp fStartTime; | |
33 | private final TmfTimestamp fEndTime; | |
34 | ||
1f506a43 | 35 | // ======================================================================== |
8c8bf09f | 36 | // Constructors |
1f506a43 | 37 | // ======================================================================== |
8c8bf09f | 38 | |
28b94d61 FC |
39 | /** |
40 | * | |
41 | */ | |
42 | @SuppressWarnings("unused") | |
43 | private TmfTimeRange() { | |
44 | fStartTime = null; | |
45 | fEndTime = null; | |
46 | } | |
47 | ||
8c8bf09f ASL |
48 | /** |
49 | * @param startTime | |
50 | * @param endTime | |
51 | */ | |
52 | public TmfTimeRange(TmfTimestamp startTime, TmfTimestamp endTime) { | |
1f506a43 FC |
53 | fStartTime = startTime; |
54 | fEndTime = endTime; | |
8c8bf09f | 55 | } |
28b94d61 FC |
56 | |
57 | /** | |
58 | * @param other | |
59 | */ | |
60 | public TmfTimeRange(TmfTimeRange other) { | |
61 | assert(other != null); | |
62 | fStartTime = other.fStartTime; | |
63 | fEndTime = other.fEndTime; | |
64 | } | |
8c8bf09f | 65 | |
1f506a43 | 66 | // ======================================================================== |
8c8bf09f | 67 | // Accessors |
1f506a43 | 68 | // ======================================================================== |
8c8bf09f ASL |
69 | |
70 | /** | |
71 | * @return The time range start time | |
72 | */ | |
73 | public TmfTimestamp getStartTime() { | |
1f506a43 | 74 | return fStartTime; |
8c8bf09f ASL |
75 | } |
76 | ||
77 | /** | |
78 | * @return The time range end time | |
79 | */ | |
80 | public TmfTimestamp getEndTime() { | |
1f506a43 | 81 | return fEndTime; |
8c8bf09f ASL |
82 | } |
83 | ||
1f506a43 | 84 | // ======================================================================== |
8c8bf09f | 85 | // Predicates |
1f506a43 | 86 | // ======================================================================== |
8c8bf09f ASL |
87 | |
88 | /** | |
89 | * Check if the timestamp is within the time range | |
90 | * | |
91 | * @param ts | |
92 | * @return | |
93 | */ | |
94 | public boolean contains(TmfTimestamp ts) { | |
1f506a43 FC |
95 | boolean result = (fStartTime.compareTo(ts, true) <= 0) && (fEndTime.compareTo(ts, true) >= 0); |
96 | return result; | |
8c8bf09f ASL |
97 | } |
98 | ||
8d2e2848 FC |
99 | /* (non-Javadoc) |
100 | * @see java.lang.Object#toString() | |
101 | */ | |
102 | @Override | |
103 | public String toString() { | |
28b94d61 | 104 | return "[TmfTimeRange(" + fStartTime.toString() + ":" + fEndTime.toString() + ")]"; |
8d2e2848 FC |
105 | } |
106 | ||
8c8bf09f | 107 | } |