HBASE-19487 Remove IterablesUtil Class

Signed-off-by: Chia-Ping Tsai <chia7712@gmail.com>
This commit is contained in:
BELUGA BEHR 2017-12-25 16:11:37 +08:00 committed by Chia-Ping Tsai
parent 27c56860da
commit 38472e1c07
4 changed files with 17 additions and 58 deletions

View File

@ -22,11 +22,10 @@ import java.nio.ByteBuffer;
import java.util.Collection;
import java.util.List;
import org.apache.commons.collections4.IterableUtils;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.IterableUtils;
import org.apache.hadoop.hbase.util.Strings;
import org.apache.yetus.audience.InterfaceAudience;
import org.apache.hadoop.hbase.shaded.com.google.common.collect.Lists;
@InterfaceAudience.Private
@ -64,7 +63,7 @@ public class KeyValueTestUtil {
boolean includeMemstoreTS) {
int totalBytes = KeyValueUtil.totalLengthWithMvccVersion(kvs, includeMemstoreTS);
ByteBuffer bb = ByteBuffer.allocate(totalBytes);
for (KeyValue kv : IterableUtils.nullSafe(kvs)) {
for (KeyValue kv : IterableUtils.emptyIfNull(kvs)) {
KeyValueUtil.appendToByteBuffer(bb, kv, includeMemstoreTS);
}
bb.rewind();

View File

@ -28,11 +28,11 @@ import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.collections4.IterableUtils;
import org.apache.hadoop.hbase.KeyValue.Type;
import org.apache.hadoop.hbase.io.util.StreamUtils;
import org.apache.hadoop.hbase.util.ByteBufferUtils;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.IterableUtils;
import org.apache.hadoop.io.IOUtils;
import org.apache.hadoop.io.WritableUtils;
import org.apache.yetus.audience.InterfaceAudience;
@ -90,7 +90,7 @@ public class KeyValueUtil {
public static int totalLengthWithMvccVersion(final Iterable<? extends KeyValue> kvs,
final boolean includeMvccVersion) {
int length = 0;
for (KeyValue kv : IterableUtils.nullSafe(kvs)) {
for (KeyValue kv : IterableUtils.emptyIfNull(kvs)) {
length += lengthWithMvccVersion(kv, includeMvccVersion);
}
return length;

View File

@ -30,8 +30,10 @@ import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
@ -47,7 +49,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.hadoop.hbase.shaded.com.google.common.annotations.VisibleForTesting;
import org.apache.hadoop.hbase.shaded.com.google.common.collect.Lists;
import com.google.protobuf.ByteString;
@ -2339,21 +2340,24 @@ public class Bytes implements Comparable<Bytes> {
}
public static boolean isSorted(Collection<byte[]> arrays) {
if (!CollectionUtils.isEmpty(arrays)) {
byte[] previous = new byte[0];
for (byte[] array : IterableUtils.nullSafe(arrays)) {
for (byte[] array : arrays) {
if (Bytes.compareTo(previous, array) > 0) {
return false;
}
previous = array;
}
}
return true;
}
public static List<byte[]> getUtf8ByteArrays(List<String> strings) {
List<byte[]> byteArrays = Lists.newArrayListWithCapacity(CollectionUtils.nullSafeSize(strings));
for (String s : IterableUtils.nullSafe(strings)) {
byteArrays.add(Bytes.toBytes(s));
if (CollectionUtils.isEmpty(strings)) {
return Collections.emptyList();
}
List<byte[]> byteArrays = new ArrayList<>(strings.size());
strings.forEach(s -> byteArrays.add(Bytes.toBytes(s)));
return byteArrays;
}

View File

@ -1,44 +0,0 @@
/*
* 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.hadoop.hbase.util;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.apache.yetus.audience.InterfaceAudience;
/**
* Utility methods for Iterable including null-safe handlers.
*/
@InterfaceAudience.Private
public class IterableUtils {
private static final List<Object> EMPTY_LIST = Collections
.unmodifiableList(new ArrayList<>(0));
@SuppressWarnings("unchecked")
public static <T> Iterable<T> nullSafe(Iterable<T> in) {
if (in == null) {
return (List<T>) EMPTY_LIST;
}
return in;
}
}