From commits-return-14248-archive-asf-public=cust-asf.ponee.io@hudi.apache.org Thu Mar 26 05:29:38 2020 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 67622180670 for ; Thu, 26 Mar 2020 06:29:37 +0100 (CET) Received: (qmail 60738 invoked by uid 500); 26 Mar 2020 05:29:36 -0000 Mailing-List: contact commits-help@hudi.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hudi.apache.org Delivered-To: mailing list commits@hudi.apache.org Received: (qmail 60654 invoked by uid 99); 26 Mar 2020 05:29:36 -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; Thu, 26 Mar 2020 05:29:36 +0000 From: GitBox To: commits@hudi.apache.org Subject: [GitHub] [incubator-hudi] vinothchandar commented on a change in pull request #1159: [HUDI-479] Eliminate or Minimize use of Guava if possible Message-ID: <158520057650.17924.6118028820829921583.gitbox@gitbox.apache.org> References: In-Reply-To: Date: Thu, 26 Mar 2020 05:29:36 -0000 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit vinothchandar commented on a change in pull request #1159: [HUDI-479] Eliminate or Minimize use of Guava if possible URL: https://github.com/apache/incubator-hudi/pull/1159#discussion_r398321995 ########## File path: hudi-common/src/main/java/org/apache/hudi/common/util/CollectionUtils.java ########## @@ -0,0 +1,132 @@ +/* + * 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.hudi.common.util; + +import java.util.Collections; +import java.util.Iterator; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class CollectionUtils { + /** + * Determines whether two iterators contain equal elements in the same order. More specifically, + * this method returns {@code true} if {@code iterator1} and {@code iterator2} contain the same + * number of elements and every element of {@code iterator1} is equal to the corresponding element + * of {@code iterator2}. + * + *

Note that this will modify the supplied iterators, since they will have been advanced some + * number of elements forward. + */ + public static boolean elementsEqual(Iterator iterator1, Iterator iterator2) { + while (iterator1.hasNext()) { + if (!iterator2.hasNext()) { + return false; + } + Object o1 = iterator1.next(); + Object o2 = iterator2.next(); + if (!Objects.equals(o1, o2)) { + return false; + } + } + return !iterator2.hasNext(); + } + + @SafeVarargs + public static Set createSetFromElements(final T... elements) { + return Stream.of(elements).collect(Collectors.toSet()); + } + + public static Map createImmutableMap(final K key, final V value) { + return Collections.unmodifiableMap(Collections.singletonMap(key, value)); + } + + @SafeVarargs + public static List createImmutableList(final T... elements) { + return Collections.unmodifiableList(Stream.of(elements).collect(Collectors.toList())); + } + + public static Map createImmutableMap(final Map map) { + return Collections.unmodifiableMap(map); + } + + @SafeVarargs + public static Set createImmutableSet(final T... elements) { + return Collections.unmodifiableSet(Stream.of(elements).collect(Collectors.toSet())); + } + + public static Set createImmutableSet(final Set set) { + return Collections.unmodifiableSet(set); + } + + public static List createImmutableList(final List list) { + return Collections.unmodifiableList(list); + } + + private static Object[] checkElementsNotNull(Object... array) { + return checkElementsNotNull(array, array.length); + } + + private static Object[] checkElementsNotNull(Object[] array, int length) { + for (int i = 0; i < length; i++) { + checkElementNotNull(array[i], i); + } + return array; + } + + private static Object checkElementNotNull(Object element, int index) { + if (element == null) { Review comment: just call Objects.requireNonNull(obj, string) ? ---------------------------------------------------------------- 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