1 /*******************************************************************************
2 * Copyright (c) 2009, 2013 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
27 public class TmfTimeRange
{
29 // ------------------------------------------------------------------------
31 // ------------------------------------------------------------------------
34 * The full possible time range
36 public static final @NonNull TmfTimeRange ETERNITY
= new EternityTimeRange();
41 public static final @NonNull TmfTimeRange NULL_RANGE
= new TmfTimeRange();
43 // ------------------------------------------------------------------------
45 // ------------------------------------------------------------------------
47 private final ITmfTimestamp fStartTime
;
48 private final ITmfTimestamp fEndTime
;
50 // ------------------------------------------------------------------------
52 // ------------------------------------------------------------------------
57 private TmfTimeRange() {
58 fStartTime
= TmfTimestamp
.BIG_BANG
;
59 fEndTime
= TmfTimestamp
.BIG_BANG
;
65 * @param startTime start of the time range
66 * @param endTime end of the time range
68 public TmfTimeRange(final ITmfTimestamp startTime
, final ITmfTimestamp endTime
) {
69 if (startTime
== null || endTime
== null) {
70 throw new IllegalArgumentException();
72 fStartTime
= startTime
;
79 * @param range the other time range
81 public TmfTimeRange(final TmfTimeRange range
) {
83 throw new IllegalArgumentException();
85 fStartTime
= range
.getStartTime();
86 fEndTime
= range
.getEndTime();
89 // ------------------------------------------------------------------------
91 // ------------------------------------------------------------------------
94 * @return the time range start time
96 public ITmfTimestamp
getStartTime() {
101 * @return the time range end time
103 public ITmfTimestamp
getEndTime() {
107 // ------------------------------------------------------------------------
109 // ------------------------------------------------------------------------
112 * Check if the timestamp is within the time range
115 * The timestamp to check
116 * @return True if [startTime] <= [ts] <= [endTime]
118 public boolean contains(final ITmfTimestamp ts
) {
119 return (fStartTime
.compareTo(ts
, true) <= 0) && (fEndTime
.compareTo(ts
, true) >= 0);
123 * Check if the time range is within the time range
126 * The other time range
127 * @return True if [range] is fully contained
129 public boolean contains(final TmfTimeRange range
) {
130 final ITmfTimestamp startTime
= range
.getStartTime();
131 final ITmfTimestamp endTime
= range
.getEndTime();
132 return (fStartTime
.compareTo(startTime
, true) <= 0) && (fEndTime
.compareTo(endTime
, true) >= 0);
135 // ------------------------------------------------------------------------
137 // ------------------------------------------------------------------------
140 * Get intersection of two time ranges
142 * @param range the other time range
143 * @return the intersection time range, or null if no intersection exists
145 public TmfTimeRange
getIntersection(final TmfTimeRange range
) {
146 if (fStartTime
.compareTo(range
.fEndTime
, true) > 0 || fEndTime
.compareTo(range
.fStartTime
, true) < 0) {
147 return null; // no intersection
150 return new TmfTimeRange(fStartTime
.compareTo(range
.fStartTime
, true) < 0
152 : fStartTime
, fEndTime
.compareTo(range
.fEndTime
, true) > 0
157 // ------------------------------------------------------------------------
159 // ------------------------------------------------------------------------
162 public int hashCode() {
163 final int prime
= 31;
165 result
= prime
* result
+ fEndTime
.hashCode();
166 result
= prime
* result
+ fStartTime
.hashCode();
171 public boolean equals(final Object obj
) {
178 if (!(obj
instanceof TmfTimeRange
)) {
181 final TmfTimeRange other
= (TmfTimeRange
) obj
;
182 if (!fEndTime
.equals(other
.fEndTime
)) {
185 if (!fStartTime
.equals(other
.fStartTime
)) {
192 @SuppressWarnings("nls")
193 public String
toString() {
194 return "TmfTimeRange [fStartTime=" + fStartTime
+ ", fEndTime=" + fEndTime
+ "]";
197 // ------------------------------------------------------------------------
199 // ------------------------------------------------------------------------
202 * "Eternity" time range, representing the largest time range possible,
203 * which includes any other time range or timestamp.
205 private static final class EternityTimeRange
extends TmfTimeRange
{
207 public EternityTimeRange() {
208 super(TmfTimestamp
.BIG_BANG
, TmfTimestamp
.BIG_CRUNCH
);
212 public boolean contains(ITmfTimestamp ts
) {
217 public boolean contains(TmfTimeRange range
) {
222 public TmfTimeRange
getIntersection(TmfTimeRange range
) {
This page took 0.036165 seconds and 5 git commands to generate.