308c98eabb2ba3016b7c730075920c45f2a0f101
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
;
19 * A utility class to define and manage time ranges.
21 * @author Francois Chouinard
25 public class TmfTimeRange
{
27 // ------------------------------------------------------------------------
29 // ------------------------------------------------------------------------
32 * The full possible time range
34 public static final @NonNull TmfTimeRange ETERNITY
= new EternityTimeRange();
39 public static final @NonNull TmfTimeRange NULL_RANGE
= new TmfTimeRange();
41 // ------------------------------------------------------------------------
43 // ------------------------------------------------------------------------
45 private final ITmfTimestamp fStartTime
;
46 private final ITmfTimestamp fEndTime
;
48 // ------------------------------------------------------------------------
50 // ------------------------------------------------------------------------
55 private TmfTimeRange() {
56 fStartTime
= TmfTimestamp
.BIG_BANG
;
57 fEndTime
= TmfTimestamp
.BIG_BANG
;
63 * @param startTime start of the time range
64 * @param endTime end of the time range
66 public TmfTimeRange(final ITmfTimestamp startTime
, final ITmfTimestamp endTime
) {
67 if (startTime
== null || endTime
== null) {
68 throw new IllegalArgumentException();
70 fStartTime
= startTime
;
77 * @param range the other time range
79 public TmfTimeRange(final TmfTimeRange range
) {
81 throw new IllegalArgumentException();
83 fStartTime
= range
.getStartTime();
84 fEndTime
= range
.getEndTime();
87 // ------------------------------------------------------------------------
89 // ------------------------------------------------------------------------
92 * @return the time range start time
94 public ITmfTimestamp
getStartTime() {
99 * @return the time range end time
101 public ITmfTimestamp
getEndTime() {
105 // ------------------------------------------------------------------------
107 // ------------------------------------------------------------------------
110 * Check if the timestamp is within the time range
113 * The timestamp to check
114 * @return True if [startTime] <= [ts] <= [endTime]
116 public boolean contains(final ITmfTimestamp ts
) {
117 return (fStartTime
.compareTo(ts
) <= 0) && (fEndTime
.compareTo(ts
) >= 0);
121 * Check if the time range is within the time range
124 * The other time range
125 * @return True if [range] is fully contained
127 public boolean contains(final TmfTimeRange range
) {
128 final ITmfTimestamp startTime
= range
.getStartTime();
129 final ITmfTimestamp endTime
= range
.getEndTime();
130 return (fStartTime
.compareTo(startTime
) <= 0) && (fEndTime
.compareTo(endTime
) >= 0);
133 // ------------------------------------------------------------------------
135 // ------------------------------------------------------------------------
138 * Get intersection of two time ranges
140 * @param range the other time range
141 * @return the intersection time range, or null if no intersection exists
143 public TmfTimeRange
getIntersection(final TmfTimeRange range
) {
144 if (fStartTime
.compareTo(range
.fEndTime
) > 0 || fEndTime
.compareTo(range
.fStartTime
) < 0) {
145 return null; // no intersection
148 return new TmfTimeRange(fStartTime
.compareTo(range
.fStartTime
) < 0
150 : fStartTime
, fEndTime
.compareTo(range
.fEndTime
) > 0
155 // ------------------------------------------------------------------------
157 // ------------------------------------------------------------------------
160 public int hashCode() {
161 final int prime
= 31;
163 result
= prime
* result
+ fEndTime
.hashCode();
164 result
= prime
* result
+ fStartTime
.hashCode();
169 public boolean equals(final Object obj
) {
176 if (!(obj
instanceof TmfTimeRange
)) {
179 final TmfTimeRange other
= (TmfTimeRange
) obj
;
180 if (!fEndTime
.equals(other
.fEndTime
)) {
183 if (!fStartTime
.equals(other
.fStartTime
)) {
190 @SuppressWarnings("nls")
191 public String
toString() {
192 return "TmfTimeRange [fStartTime=" + fStartTime
+ ", fEndTime=" + fEndTime
+ "]";
195 // ------------------------------------------------------------------------
197 // ------------------------------------------------------------------------
200 * "Eternity" time range, representing the largest time range possible,
201 * which includes any other time range or timestamp.
203 private static final class EternityTimeRange
extends TmfTimeRange
{
205 public EternityTimeRange() {
206 super(TmfTimestamp
.BIG_BANG
, TmfTimestamp
.BIG_CRUNCH
);
210 public boolean contains(ITmfTimestamp ts
) {
215 public boolean contains(TmfTimeRange range
) {
220 public TmfTimeRange
getIntersection(TmfTimeRange range
) {
This page took 0.043449 seconds and 4 git commands to generate.