87216e452b97186b7e7b9d33d22a15b404fcef6d
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
.linuxtools
.tmf
.core
.timestamp
;
17 * A utility class to define and manage time ranges.
19 * @author Francois Chouinard
25 public final class TmfTimeRange
{
27 // ------------------------------------------------------------------------
29 // ------------------------------------------------------------------------
32 * The full possible time range
34 public static final TmfTimeRange ETERNITY
=
35 new TmfTimeRange(TmfTimestamp
.BIG_BANG
, TmfTimestamp
.BIG_CRUNCH
);
40 public static final TmfTimeRange NULL_RANGE
= new TmfTimeRange();
42 // ------------------------------------------------------------------------
44 // ------------------------------------------------------------------------
46 private final ITmfTimestamp fStartTime
;
47 private final ITmfTimestamp fEndTime
;
49 // ------------------------------------------------------------------------
51 // ------------------------------------------------------------------------
56 private TmfTimeRange() {
57 fStartTime
= TmfTimestamp
.BIG_BANG
;
58 fEndTime
= TmfTimestamp
.BIG_BANG
;
64 * @param startTime start of the time range
65 * @param endTime end of the time range
67 public TmfTimeRange(final ITmfTimestamp startTime
, final ITmfTimestamp endTime
) {
68 if (startTime
== null || endTime
== null) {
69 throw new IllegalArgumentException();
71 fStartTime
= startTime
;
78 * @param range the other time range
80 public TmfTimeRange(final TmfTimeRange range
) {
82 throw new IllegalArgumentException();
84 fStartTime
= range
.getStartTime();
85 fEndTime
= range
.getEndTime();
88 // ------------------------------------------------------------------------
90 // ------------------------------------------------------------------------
93 * @return the time range start time
95 public ITmfTimestamp
getStartTime() {
100 * @return the time range end time
102 public ITmfTimestamp
getEndTime() {
106 // ------------------------------------------------------------------------
108 // ------------------------------------------------------------------------
111 * Check if the timestamp is within the time range
113 * @param ts the timestamp to check
114 * @return true if [startTime] <= [ts] <= [endTime]
116 public boolean contains(final ITmfTimestamp ts
) {
117 // Zero acts as a "universal donor" timestamp
118 if (ts
.equals(TmfTimestamp
.ZERO
)) {
121 return (fStartTime
.compareTo(ts
, true) <= 0) && (fEndTime
.compareTo(ts
, true) >= 0);
125 * Check if the time range is within the time range
127 * @param range the other time range
128 * @return true if [range] is fully contained
130 public boolean contains(final TmfTimeRange range
) {
131 final ITmfTimestamp startTime
= range
.getStartTime();
132 final ITmfTimestamp endTime
= range
.getEndTime();
133 return (fStartTime
.compareTo(startTime
, true) <= 0) && (fEndTime
.compareTo(endTime
, true) >= 0);
136 // ------------------------------------------------------------------------
138 // ------------------------------------------------------------------------
141 * Get intersection of two time ranges
143 * @param range the other time range
144 * @return the intersection time range, or null if no intersection exists
146 public TmfTimeRange
getIntersection(final TmfTimeRange range
) {
147 if (fStartTime
.compareTo(range
.fEndTime
, true) > 0 || fEndTime
.compareTo(range
.fStartTime
, true) < 0) {
148 return null; // no intersection
151 return new TmfTimeRange(fStartTime
.compareTo(range
.fStartTime
, true) < 0
153 : fStartTime
, fEndTime
.compareTo(range
.fEndTime
, true) > 0
158 // ------------------------------------------------------------------------
160 // ------------------------------------------------------------------------
163 public int hashCode() {
164 final int prime
= 31;
166 result
= prime
* result
+ fEndTime
.hashCode();
167 result
= prime
* result
+ fStartTime
.hashCode();
172 public boolean equals(final Object obj
) {
179 if (!(obj
instanceof TmfTimeRange
)) {
182 final TmfTimeRange other
= (TmfTimeRange
) obj
;
183 if (!fEndTime
.equals(other
.fEndTime
)) {
186 if (!fStartTime
.equals(other
.fStartTime
)) {
193 @SuppressWarnings("nls")
194 public String
toString() {
195 return "TmfTimeRange [fStartTime=" + fStartTime
+ ", fEndTime=" + fEndTime
+ "]";
This page took 0.034211 seconds and 5 git commands to generate.