1 /*******************************************************************************
2 * Copyright (c) 2009 Ericsson
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
10 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.event
;
16 * <b><u>TmfTimeRange</u></b>
18 * A utility class to define time ranges.
20 public class TmfTimeRange
{
22 // ------------------------------------------------------------------------
24 // ------------------------------------------------------------------------
26 public static final TmfTimeRange Eternity
= new TmfTimeRange(TmfTimestamp
.BigBang
, TmfTimestamp
.BigCrunch
);
28 // ------------------------------------------------------------------------
30 // ------------------------------------------------------------------------
32 private final TmfTimestamp fStartTime
;
33 private final TmfTimestamp fEndTime
;
35 // ------------------------------------------------------------------------
37 // ------------------------------------------------------------------------
39 @SuppressWarnings("unused")
40 private TmfTimeRange() {
41 throw new AssertionError();
48 public TmfTimeRange(TmfTimestamp startTime
, TmfTimestamp endTime
) {
49 if (startTime
== null || endTime
== null) {
50 throw new IllegalArgumentException();
52 fStartTime
= new TmfTimestamp(startTime
);
53 fEndTime
= new TmfTimestamp(endTime
);
60 public TmfTimeRange(TmfTimeRange other
) {
62 throw new IllegalArgumentException();
64 fStartTime
= new TmfTimestamp(other
.fStartTime
);
65 fEndTime
= new TmfTimestamp(other
.fEndTime
);
68 // ------------------------------------------------------------------------
70 // ------------------------------------------------------------------------
73 * @return The time range start time
75 public TmfTimestamp
getStartTime() {
76 return new TmfTimestamp(fStartTime
);
80 * @return The time range end time
82 public TmfTimestamp
getEndTime() {
83 return new TmfTimestamp(fEndTime
);
86 // ------------------------------------------------------------------------
88 // ------------------------------------------------------------------------
91 * Check if the timestamp is within the time range
96 public boolean contains(TmfTimestamp ts
) {
97 return (fStartTime
.compareTo(ts
, true) <= 0) && (fEndTime
.compareTo(ts
, true) >= 0);
100 // ------------------------------------------------------------------------
102 // ------------------------------------------------------------------------
105 public int hashCode() {
107 result
= 37 * result
+ fStartTime
.hashCode();
108 result
= 37 * result
+ fEndTime
.hashCode();
113 public boolean equals(Object other
) {
114 if (!(other
instanceof TmfTimeRange
))
116 TmfTimeRange range
= (TmfTimeRange
) other
;
117 return range
.fStartTime
.equals(fStartTime
) && range
.fEndTime
.equals(fEndTime
);
121 public String
toString() {
122 return "[TmfTimeRange(" + fStartTime
+ ":" + fEndTime
+ ")]";
This page took 0.036986 seconds and 5 git commands to generate.