From reviews-return-1554-archive-asf-public=cust-asf.ponee.io@iotdb.apache.org Mon May 6 10:30:03 2019 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by mx-eu-01.ponee.io (Postfix) with SMTP id 0F0A4180763 for ; Mon, 6 May 2019 12:30:02 +0200 (CEST) Received: (qmail 49621 invoked by uid 500); 6 May 2019 10:30:02 -0000 Mailing-List: contact reviews-help@iotdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: reviews@iotdb.apache.org Delivered-To: mailing list reviews@iotdb.apache.org Received: (qmail 49609 invoked by uid 99); 6 May 2019 10:30:02 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 06 May 2019 10:30:02 +0000 From: GitBox To: reviews@iotdb.apache.org Subject: [GitHub] [incubator-iotdb] liuruiyiyang commented on a change in pull request #108: [IOTDB-64] TsFile-Spark-Connector update Message-ID: <155713860207.31862.1436735757949031959.gitbox@gitbox.apache.org> Date: Mon, 06 May 2019 10:30:02 -0000 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit 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_r281131932 ########## 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 { + + /** + * 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 true 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 true if the ranges have values in common + */ + public boolean intersects(TimeRange r) { + return overlaps(min, max, r.min, r.max); + } + + /** + * @return true if the ranges overlap + */ + public static boolean overlaps(long minA, long maxA, long minB, long maxB) { + assert minA <= maxA; + assert minB <= maxB; + + // Because timestamp is long data type, x and x+1 are considered continuous. + return !(minA >= maxB + 2 || maxA <= minB - 2); + } + + @Override + public String toString() { + return "[ " + min + " : " + max + " ]"; + } + + // NOTE the primitive timeRange is always a closed interval [min,max] and + // only in getRemains functions are leftClose and rightClose considered. + private boolean leftClose = true; // default true + private boolean rightClose = true; // default true + + public void setLeftClose(boolean leftClose) { + this.leftClose = leftClose; + } + + public void setRightClose(boolean rightClose) { + this.rightClose = rightClose; + } + + public boolean getLeftClose() { + return leftClose; + } + + public boolean getRightClose() { + return rightClose; + } + + /** + * Get the remaining time ranges in the current ranges but not in timeRangesPrev. + * + * NOTE the primitive timeRange is always a closed interval [min,max] and only in this function + * are leftClose and rightClose changed. + * + * @param timeRangesPrev time ranges union in ascending order + * @return the remaining time ranges + */ + public ArrayList getRemains(ArrayList timeRangesPrev) { Review comment: return type of method usually use interface such as ``` List``` rather than implementation ```ArrayList``` ---------------------------------------------------------------- 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