tmf/lttng: Remove unneeded (non-Javadoc) comments
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / timestamp / TmfTimeRange.java
CommitLineData
8c8bf09f 1/*******************************************************************************
61759503 2 * Copyright (c) 2009, 2013 Ericsson
4593bd5b 3 *
bbc1c411 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
8c8bf09f
ASL
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
4593bd5b 8 *
8c8bf09f
ASL
9 * Contributors:
10 * Francois Chouinard - Initial API and implementation
bbc1c411 11 * Francois Chouinard - Updated as per TMF Event Model 1.0
8c8bf09f
ASL
12 *******************************************************************************/
13
3bd46eef 14package org.eclipse.linuxtools.tmf.core.timestamp;
8c8bf09f
ASL
15
16/**
4c564a2d 17 * A utility class to define and manage time ranges.
4593bd5b 18 *
b9e37ffd 19 * @author Francois Chouinard
3bd46eef
AM
20 * @version 1.0
21 * @since 2.0
4593bd5b 22 *
b9e37ffd 23 * @see ITmfTimestamp
8c8bf09f 24 */
4593bd5b 25public final class TmfTimeRange {
8c8bf09f 26
bbc1c411 27 // ------------------------------------------------------------------------
62d1696a 28 // Constants
bbc1c411 29 // ------------------------------------------------------------------------
62d1696a 30
d7dbf09a
FC
31 /**
32 * The full possible time range
33 */
a4115405 34 public static final TmfTimeRange ETERNITY =
085d898f 35 new TmfTimeRange(TmfTimestamp.BIG_BANG, TmfTimestamp.BIG_CRUNCH);
bbc1c411 36
d7dbf09a
FC
37 /**
38 * The null time range
39 */
4593bd5b 40 public static final TmfTimeRange NULL_RANGE = new TmfTimeRange();
bbc1c411 41
42 // ------------------------------------------------------------------------
8c8bf09f 43 // Attributes
bbc1c411 44 // ------------------------------------------------------------------------
8c8bf09f 45
4593bd5b
AM
46 private final ITmfTimestamp fStartTime;
47 private final ITmfTimestamp fEndTime;
8c8bf09f 48
bbc1c411 49 // ------------------------------------------------------------------------
8c8bf09f 50 // Constructors
bbc1c411 51 // ------------------------------------------------------------------------
52
53 /**
54 * Default constructor
55 */
bbc1c411 56 private TmfTimeRange() {
4593bd5b
AM
57 fStartTime = TmfTimestamp.BIG_BANG;
58 fEndTime = TmfTimestamp.BIG_BANG;
bbc1c411 59 }
60
61 /**
62 * Full constructor
4593bd5b 63 *
bbc1c411 64 * @param startTime start of the time range
65 * @param endTime end of the time range
66 */
085d898f 67 public TmfTimeRange(final ITmfTimestamp startTime, final ITmfTimestamp endTime) {
b9e37ffd 68 if (startTime == null || endTime == null) {
bbc1c411 69 throw new IllegalArgumentException();
b9e37ffd 70 }
d7dbf09a
FC
71 fStartTime = startTime;
72 fEndTime = endTime;
bbc1c411 73 }
74
75 /**
76 * Copy constructor
4593bd5b 77 *
bbc1c411 78 * @param range the other time range
79 */
085d898f 80 public TmfTimeRange(final TmfTimeRange range) {
b9e37ffd 81 if (range == null) {
bbc1c411 82 throw new IllegalArgumentException();
b9e37ffd 83 }
d7dbf09a
FC
84 fStartTime = range.getStartTime();
85 fEndTime = range.getEndTime();
bbc1c411 86 }
87
88 // ------------------------------------------------------------------------
4c564a2d 89 // Getters
bbc1c411 90 // ------------------------------------------------------------------------
91
92 /**
93 * @return the time range start time
94 */
95 public ITmfTimestamp getStartTime() {
96 return fStartTime;
97 }
98
99 /**
100 * @return the time range end time
101 */
102 public ITmfTimestamp getEndTime() {
103 return fEndTime;
104 }
105
106 // ------------------------------------------------------------------------
8c8bf09f 107 // Predicates
bbc1c411 108 // ------------------------------------------------------------------------
109
110 /**
111 * Check if the timestamp is within the time range
4593bd5b 112 *
bbc1c411 113 * @param ts the timestamp to check
114 * @return true if [startTime] <= [ts] <= [endTime]
115 */
085d898f 116 public boolean contains(final ITmfTimestamp ts) {
bbc1c411 117 // Zero acts as a "universal donor" timestamp
b9e37ffd 118 if (ts.equals(TmfTimestamp.ZERO)) {
bbc1c411 119 return true;
b9e37ffd 120 }
bbc1c411 121 return (fStartTime.compareTo(ts, true) <= 0) && (fEndTime.compareTo(ts, true) >= 0);
122 }
123
124 /**
125 * Check if the time range is within the time range
4593bd5b 126 *
bbc1c411 127 * @param range the other time range
128 * @return true if [range] is fully contained
129 */
085d898f
FC
130 public boolean contains(final TmfTimeRange range) {
131 final ITmfTimestamp startTime = range.getStartTime();
132 final ITmfTimestamp endTime = range.getEndTime();
bbc1c411 133 return (fStartTime.compareTo(startTime, true) <= 0) && (fEndTime.compareTo(endTime, true) >= 0);
134 }
135
136 // ------------------------------------------------------------------------
137 // Operations
138 // ------------------------------------------------------------------------
139
140 /**
141 * Get intersection of two time ranges
4593bd5b 142 *
bbc1c411 143 * @param range the other time range
144 * @return the intersection time range, or null if no intersection exists
145 */
085d898f 146 public TmfTimeRange getIntersection(final TmfTimeRange range) {
b9e37ffd 147 if (fStartTime.compareTo(range.fEndTime, true) > 0 || fEndTime.compareTo(range.fStartTime, true) < 0) {
bbc1c411 148 return null; // no intersection
b9e37ffd 149 }
bbc1c411 150
4593bd5b
AM
151 return new TmfTimeRange(fStartTime.compareTo(range.fStartTime, true) < 0
152 ? range.fStartTime
153 : fStartTime, fEndTime.compareTo(range.fEndTime, true) > 0
154 ? range.fEndTime
bbc1c411 155 : fEndTime);
156 }
157
bbc1c411 158 // ------------------------------------------------------------------------
cbd4ad82 159 // Object
bbc1c411 160 // ------------------------------------------------------------------------
cbd4ad82 161
bbc1c411 162 @Override
cbd4ad82 163 public int hashCode() {
bbc1c411 164 final int prime = 31;
165 int result = 1;
34480e89
FC
166 result = prime * result + fEndTime.hashCode();
167 result = prime * result + fStartTime.hashCode();
cbd4ad82
FC
168 return result;
169 }
170
bbc1c411 171 @Override
085d898f 172 public boolean equals(final Object obj) {
b9e37ffd 173 if (this == obj) {
bbc1c411 174 return true;
b9e37ffd
FC
175 }
176 if (obj == null) {
bbc1c411 177 return false;
b9e37ffd
FC
178 }
179 if (!(obj instanceof TmfTimeRange)) {
bbc1c411 180 return false;
b9e37ffd 181 }
085d898f 182 final TmfTimeRange other = (TmfTimeRange) obj;
b9e37ffd 183 if (!fEndTime.equals(other.fEndTime)) {
bbc1c411 184 return false;
b9e37ffd
FC
185 }
186 if (!fStartTime.equals(other.fStartTime)) {
bbc1c411 187 return false;
b9e37ffd 188 }
bbc1c411 189 return true;
cbd4ad82
FC
190 }
191
bbc1c411 192 @Override
3b38ea61 193 @SuppressWarnings("nls")
bbc1c411 194 public String toString() {
619d7d7f 195 return "TmfTimeRange [fStartTime=" + fStartTime + ", fEndTime=" + fEndTime + "]";
bbc1c411 196 }
8d2e2848 197
8c8bf09f 198}
This page took 0.052332 seconds and 5 git commands to generate.