iotdb-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [incubator-iotdb] liuruiyiyang commented on a change in pull request #108: [IOTDB-64] TsFile-Spark-Connector update
Date Mon, 06 May 2019 10:30:02 GMT
liuruiyiyang commented on a change in pull request #108: [IOTDB-64] TsFile-Spark-Connector
update
URL: https://github.com/apache/incubator-iotdb/pull/108#discussion_r281131472
 
 

 ##########
 File path: tsfile/src/main/java/org/apache/iotdb/tsfile/read/common/TimeRange.java
 ##########
 @@ -0,0 +1,279 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iotdb.tsfile.read.common;
+
+import java.util.ArrayList;
+import org.apache.iotdb.tsfile.read.expression.IExpression;
+import org.apache.iotdb.tsfile.read.expression.impl.BinaryExpression;
+import org.apache.iotdb.tsfile.read.expression.impl.GlobalTimeExpression;
+import org.apache.iotdb.tsfile.read.filter.TimeFilter;
+
+/**
+ * interval [min,max] of long data type
+ *
+ * Reference: http://www.java2s.com/Code/Java/Collections-Data-Structure/Anumericalinterval.htm
+ *
+ * @author ryanm
+ */
+public class TimeRange implements Comparable<TimeRange> {
+
+  /**
+   * The lower value
+   */
+  private long min = 0;
+
+  /**
+   * The upper value
+   */
+  private long max = 0;
+
+  /**
+   * @param min
+   * @param max
+   */
+  public TimeRange(long min, long max) {
+    set(min, max);
+  }
+
+  public int compareTo(TimeRange r) {
+    long res1 = this.min - r.min;
+    if (res1 > 0) {
+      return 1;
+    } else if (res1 < 0) {
+      return -1;
+    } else {
+      long res2 = this.max - r.max;
+      if (res2 > 0) {
+        return 1;
+      } else if (res2 < 0) {
+        return -1;
+      } else {
+        return 0;
+      }
+    }
+  }
+
+  /**
+   * @return true if the value lies between the min and max values, inclusively
+   */
+  public boolean contains(long value) {
+    return min <= value && max >= value;
+  }
+
+  /**
+   * @return true if the given range lies in this range, inclusively
+   */
+  public boolean contains(TimeRange r) {
+    return min <= r.min && max >= r.max;
+  }
+
+  /**
+   * @param min
+   * @param max
+   */
+  public void set(long min, long max) {
+    this.min = min;
+    this.max = max;
+
+    sort();
+  }
+
+  /**
+   * @param r
+   */
+  public void set(TimeRange r) {
+    set(r.getMin(), r.getMax());
+  }
+
+  /**
+   * @return The lower range boundary
+   */
+  public long getMin() {
+    return min;
+  }
+
+  /**
+   * @param min
+   */
+  public void setMin(long min) {
+    this.min = min;
+
+    sort();
+  }
+
+  /**
+   * @return The upper range boundary
+   */
+  public long getMax() {
+    return max;
+  }
+
+  /**
+   * @param max
+   */
+  public void setMax(long max) {
+    this.max = max;
+
+    sort();
+  }
+
+  private void sort() {
+    if (min > max) {
+      long t = min;
+      min = max;
+      max = t;
+    }
+  }
+
+  /**
+   * @return <code>true</code> if the intersection exists
+   */
+  public boolean intersection(TimeRange r, TimeRange dest) {
+    if (intersects(r)) {
+      dest.set(Math.max(min, r.min), Math.min(max, r.max));
+      return true;
+    }
+
+    return false;
+  }
+
+  /**
+   * @return <code>true</code> if the ranges have values in common
+   */
+  public boolean intersects(TimeRange r) {
+    return overlaps(min, max, r.min, r.max);
+  }
+
+  /**
+   * @return <code>true</code> if the ranges overlap
+   */
+  public static boolean overlaps(long minA, long maxA, long minB, long maxB) {
+    assert minA <= maxA;
 
 Review comment:
   it is recommended to throw specific exceptions instead of using ```assert```, because assertions
can be disabled at runtime in the JVM and they throw AssertionErrors, which is usually not
expected in normal programs.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message