1 /*******************************************************************************
2 * Copyright (c) 2009, 2014 Ericsson
4 * All rights reserved. This program and the accompanying materials are made
5 * 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
10 * Francois Chouinard - Initial API and implementation
11 * Francois Chouinard - Updated as per TMF Event Model 1.0
12 *******************************************************************************/
14 package org
.eclipse
.tracecompass
.tmf
.core
.timestamp
;
16 import org
.eclipse
.jdt
.annotation
.NonNull
;
17 import org
.eclipse
.jdt
.annotation
.NonNullByDefault
;
18 import org
.eclipse
.jdt
.annotation
.Nullable
;
21 * A utility class to define and manage time ranges.
23 * @author Francois Chouinard
28 public class TmfTimeRange
{
30 // ------------------------------------------------------------------------
32 // ------------------------------------------------------------------------
35 * The full possible time range
37 public static final TmfTimeRange ETERNITY
= new EternityTimeRange();
42 public static final TmfTimeRange NULL_RANGE
= new TmfTimeRange(TmfTimestamp
.BIG_BANG
, TmfTimestamp
.BIG_BANG
);
44 // ------------------------------------------------------------------------
46 // ------------------------------------------------------------------------
48 private final ITmfTimestamp fStartTime
;
49 private final ITmfTimestamp fEndTime
;
51 // ------------------------------------------------------------------------
53 // ------------------------------------------------------------------------
58 * @param startTime start of the time range
59 * @param endTime end of the time range
61 public TmfTimeRange(final ITmfTimestamp startTime
, final ITmfTimestamp endTime
) {
62 fStartTime
= startTime
;
66 // ------------------------------------------------------------------------
68 // ------------------------------------------------------------------------
71 * @return the time range start time
73 public ITmfTimestamp
getStartTime() {
78 * @return the time range end time
80 public ITmfTimestamp
getEndTime() {
84 // ------------------------------------------------------------------------
86 // ------------------------------------------------------------------------
89 * Check if the timestamp is within the time range
92 * The timestamp to check
93 * @return True if [startTime] <= [ts] <= [endTime]
95 public boolean contains(final ITmfTimestamp ts
) {
96 return (fStartTime
.compareTo(ts
) <= 0) && (fEndTime
.compareTo(ts
) >= 0);
100 * Check if the time range is within the time range
103 * The other time range
104 * @return True if [range] is fully contained
106 public boolean contains(final TmfTimeRange range
) {
107 final ITmfTimestamp startTime
= range
.getStartTime();
108 final ITmfTimestamp endTime
= range
.getEndTime();
109 return (fStartTime
.compareTo(startTime
) <= 0) && (fEndTime
.compareTo(endTime
) >= 0);
112 // ------------------------------------------------------------------------
114 // ------------------------------------------------------------------------
117 * Get intersection of two time ranges
119 * @param range the other time range
120 * @return the intersection time range, or null if no intersection exists
122 public @Nullable TmfTimeRange
getIntersection(final TmfTimeRange range
) {
123 if (fStartTime
.compareTo(range
.fEndTime
) > 0 || fEndTime
.compareTo(range
.fStartTime
) < 0) {
124 return null; // no intersection
127 return new TmfTimeRange(fStartTime
.compareTo(range
.fStartTime
) < 0
129 : fStartTime
, fEndTime
.compareTo(range
.fEndTime
) > 0
134 // ------------------------------------------------------------------------
136 // ------------------------------------------------------------------------
139 public int hashCode() {
140 final int prime
= 31;
142 result
= prime
* result
+ fEndTime
.hashCode();
143 result
= prime
* result
+ fStartTime
.hashCode();
148 public boolean equals(final @Nullable Object obj
) {
155 if (!(obj
instanceof TmfTimeRange
)) {
158 final TmfTimeRange other
= (TmfTimeRange
) obj
;
159 if (!fEndTime
.equals(other
.fEndTime
)) {
162 if (!fStartTime
.equals(other
.fStartTime
)) {
169 @SuppressWarnings("nls")
170 public String
toString() {
171 return "TmfTimeRange [fStartTime=" + fStartTime
+ ", fEndTime=" + fEndTime
+ "]";
174 // ------------------------------------------------------------------------
176 // ------------------------------------------------------------------------
179 * "Eternity" time range, representing the largest time range possible,
180 * which includes any other time range or timestamp.
182 private static final class EternityTimeRange
extends TmfTimeRange
{
184 public EternityTimeRange() {
185 super(TmfTimestamp
.BIG_BANG
, TmfTimestamp
.BIG_CRUNCH
);
189 public boolean contains(ITmfTimestamp ts
) {
194 public boolean contains(TmfTimeRange range
) {
199 public @NonNull TmfTimeRange
getIntersection(TmfTimeRange range
) {
This page took 0.033584 seconds and 5 git commands to generate.