]> git.proxmox.com Git - ceph.git/blame - ceph/src/arrow/java/vector/src/main/java/org/apache/arrow/vector/compare/VectorEqualsVisitor.java
import quincy 17.2.0
[ceph.git] / ceph / src / arrow / java / vector / src / main / java / org / apache / arrow / vector / compare / VectorEqualsVisitor.java
CommitLineData
1d09f67e
TL
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18package org.apache.arrow.vector.compare;
19
20import static org.apache.arrow.vector.compare.RangeEqualsVisitor.DEFAULT_TYPE_COMPARATOR;
21
22import java.util.function.BiFunction;
23
24import org.apache.arrow.vector.ValueVector;
25
26/**
27 * Visitor to compare vectors equal.
28 */
29public class VectorEqualsVisitor {
30
31 /**
32 * Checks if two vectors are equals with default type comparator.
33 * @param left the left vector to compare.
34 * @param right the right vector to compare.
35 * @return true if the vectors are equal, and false otherwise.
36 */
37 public static boolean vectorEquals(ValueVector left, ValueVector right) {
38 return vectorEquals(left, right, DEFAULT_TYPE_COMPARATOR);
39 }
40
41 /**
42 * Checks if two vectors are equals.
43 * @param left the left vector to compare.
44 * @param right the right vector to compare.
45 * @param typeComparator type comparator to compare vector type.
46 * @return true if the vectors are equal, and false otherwise.
47 */
48 public static boolean vectorEquals(
49 ValueVector left,
50 ValueVector right,
51 BiFunction<ValueVector, ValueVector, Boolean> typeComparator) {
52
53 if (left.getValueCount() != right.getValueCount()) {
54 return false;
55 }
56
57 RangeEqualsVisitor visitor = new RangeEqualsVisitor(left, right, typeComparator);
58 return visitor.rangeEquals(new Range(0, 0, left.getValueCount()));
59 }
60}