From 56e3f319b1b8a18c55335427507bd23512ba5ed4 Mon Sep 17 00:00:00 2001 From: Alexandre Montplaisir Date: Fri, 1 Nov 2013 18:54:12 -0400 Subject: [PATCH] tmf: Optimize the ETERNITY time range TmfTimeRange.ETERNITY is often used in requests and the like, when you do not want to filter on timestamps at all. Implement it as a subclass which does not even bother checking the range borders, since any other timestamp or time range is definitely included. Change-Id: I45c80523b054c33bd96f859355b795be38f7e760 Signed-off-by: Alexandre Montplaisir Reviewed-on: https://git.eclipse.org/r/17981 Tested-by: Hudson CI Reviewed-by: Patrick Tasse IP-Clean: Patrick Tasse --- .../tmf/core/timestamp/TmfTimeRange.java | 34 +++++++++++++++++-- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/timestamp/TmfTimeRange.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/timestamp/TmfTimeRange.java index ed29889e27..dae79c1ffa 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/timestamp/TmfTimeRange.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/timestamp/TmfTimeRange.java @@ -22,7 +22,7 @@ package org.eclipse.linuxtools.tmf.core.timestamp; * * @see ITmfTimestamp */ -public final class TmfTimeRange { +public class TmfTimeRange { // ------------------------------------------------------------------------ // Constants @@ -31,8 +31,7 @@ public final class TmfTimeRange { /** * The full possible time range */ - public static final TmfTimeRange ETERNITY = - new TmfTimeRange(TmfTimestamp.BIG_BANG, TmfTimestamp.BIG_CRUNCH); + public static final TmfTimeRange ETERNITY = new EternityTimeRange(); /** * The null time range @@ -193,4 +192,33 @@ public final class TmfTimeRange { return "TmfTimeRange [fStartTime=" + fStartTime + ", fEndTime=" + fEndTime + "]"; } + // ------------------------------------------------------------------------ + // Inner classes + // ------------------------------------------------------------------------ + + /** + * "Eternity" time range, representing the largest time range possible, + * which includes any other time range or timestamp. + */ + private static final class EternityTimeRange extends TmfTimeRange { + + public EternityTimeRange() { + super(TmfTimestamp.BIG_BANG, TmfTimestamp.BIG_CRUNCH); + } + + @Override + public boolean contains(ITmfTimestamp ts) { + return true; + } + + @Override + public boolean contains(TmfTimeRange range) { + return true; + } + + @Override + public TmfTimeRange getIntersection(TmfTimeRange range) { + return range; + } + } } -- 2.34.1