dcdd89e44c6ed20ed73b32fd2f7d7faef4900ba1
1 /*******************************************************************************
2 * Copyright (c) 2017 École Polytechnique de Montréal
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
8 ******************************************************************************/
10 package org
.eclipse
.tracecompass
.internal
.datastore
.core
.condition
;
12 import org
.eclipse
.jdt
.annotation
.NonNull
;
13 import org
.eclipse
.tracecompass
.internal
.provisional
.datastore
.core
.condition
.RangeCondition
;
16 * Generic Range Condition. This condition will verify that a value are within a
17 * range limited by a lower and upper bound.
19 * @author Loïc Prieur-Drevon
21 * Comparable type, for instance Long for timestamps
23 public class ContinuousRangeCondition
<E
extends Comparable
<E
>> implements RangeCondition
<E
> {
29 * Build a continuous range condition from two bounds.
32 * The range's lower bound
34 * The range's higher bound
36 public ContinuousRangeCondition(@NonNull E low
, @NonNull E high
) {
37 if (low
.compareTo(high
) > 0) {
38 throw new IllegalArgumentException(low
.toString() + " is greater than " + high
.toString()); //$NON-NLS-1$
55 public boolean test(E element
) {
56 return fMin
.compareTo(element
) <= 0 && element
.compareTo(fMax
) <= 0;
60 public boolean intersects(E low
, E high
) {
61 return fMin
.compareTo(high
) <= 0 && fMax
.compareTo(low
) >= 0;
64 private static <E
extends Comparable
<E
>> E
min(E n1
, E n2
) {
65 if (n1
.compareTo(n2
) <= 0) {
71 private static <E
extends Comparable
<E
>> E
max(E n1
, E n2
) {
72 if (n1
.compareTo(n2
) >= 0) {
79 public @NonNull RangeCondition
<E
> subCondition(E from
, E to
) {
80 return new ContinuousRangeCondition
<>(max(from
, fMin
), min(fMax
, to
));
84 public String
toString() {
85 return "Continuous condition: " + fMin
.toString() + '-' + fMax
.toString(); //$NON-NLS-1$
This page took 0.033631 seconds and 4 git commands to generate.