Remove CollectionUtils
Motivation: CollectionUtils has only one method and it is used only in DefaultHeaders. Modification: Move CollectionUtils.equals() to DefaultHeaders and make it private Result: One less class to expose in our public API
This commit is contained in:
parent
ceb06dc1b1
commit
8235337d4e
@ -14,7 +14,6 @@
|
||||
*/
|
||||
package io.netty.handler.codec;
|
||||
|
||||
import io.netty.util.collection.CollectionUtils;
|
||||
import io.netty.util.collection.IntObjectHashMap;
|
||||
import io.netty.util.collection.IntObjectMap;
|
||||
import io.netty.util.concurrent.FastThreadLocal;
|
||||
@ -1147,7 +1146,7 @@ public class DefaultHeaders<T> implements Headers<T> {
|
||||
// because we want to force the keyComparator to be used for all comparisons
|
||||
List<T> namesList = namesList();
|
||||
List<T> otherNamesList = h2.namesList();
|
||||
if (!CollectionUtils.equals(namesList, otherNamesList, keyComparator)) {
|
||||
if (!equals(namesList, otherNamesList, keyComparator)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1156,7 +1155,7 @@ public class DefaultHeaders<T> implements Headers<T> {
|
||||
Set<T> names = new TreeSet<T>(keyComparator);
|
||||
names.addAll(namesList);
|
||||
for (T name : names) {
|
||||
if (!CollectionUtils.equals(getAll(name), h2.getAll(name), valueComparator)) {
|
||||
if (!equals(getAll(name), h2.getAll(name), valueComparator)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -1164,6 +1163,31 @@ public class DefaultHeaders<T> implements Headers<T> {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare two lists using the {@code comparator} for all comparisons (not using the equals() operator)
|
||||
* @param lhs Left hand side
|
||||
* @param rhs Right hand side
|
||||
* @param comparator Comparator which will be used for all comparisons (equals() on objects will not be used)
|
||||
* @return True if {@code lhs} == {@code rhs} according to {@code comparator}. False otherwise.
|
||||
*/
|
||||
private static <T> boolean equals(List<T> lhs, List<T> rhs, Comparator<? super T> comparator) {
|
||||
final int lhsSize = lhs.size();
|
||||
if (lhsSize != rhs.size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Don't use a TreeSet to do the comparison. We want to force the comparator
|
||||
// to be used instead of the object's equals()
|
||||
Collections.sort(lhs, comparator);
|
||||
Collections.sort(rhs, comparator);
|
||||
for (int i = 0; i < lhsSize; ++i) {
|
||||
if (comparator.compare(lhs.get(i), rhs.get(i)) != 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = 1;
|
||||
|
@ -1,52 +0,0 @@
|
||||
/*
|
||||
* Copyright 2014 The Netty Project
|
||||
*
|
||||
* The Netty Project 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 io.netty.util.collection;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Provides utilities for the primitive collection types that are not supplied by the JDK
|
||||
*/
|
||||
public final class CollectionUtils {
|
||||
|
||||
private CollectionUtils() { }
|
||||
|
||||
/**
|
||||
* Compare two lists using the {@code comparator} for all comparisons (not using the equals() operator)
|
||||
* @param lhs Left hand side
|
||||
* @param rhs Right hand side
|
||||
* @param comparator Comparator which will be used for all comparisons (equals() on objects will not be used)
|
||||
* @return True if {@code lhs} == {@code rhs} according to {@code comparator}. False otherwise.
|
||||
*/
|
||||
public static <T> boolean equals(List<T> lhs, List<T> rhs, Comparator<? super T> comparator) {
|
||||
final int lhsSize = lhs.size();
|
||||
if (lhsSize != rhs.size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Don't use a TreeSet to do the comparison. We want to force the comparator
|
||||
// to be used instead of the object's equals()
|
||||
Collections.sort(lhs, comparator);
|
||||
Collections.sort(rhs, comparator);
|
||||
for (int i = 0; i < lhsSize; ++i) {
|
||||
if (comparator.compare(lhs.get(i), rhs.get(i)) != 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user