diff --git a/net/src/main/java/com/zfoo/net/packet/PacketService.java b/net/src/main/java/com/zfoo/net/packet/PacketService.java index 92425091..4d575416 100644 --- a/net/src/main/java/com/zfoo/net/packet/PacketService.java +++ b/net/src/main/java/com/zfoo/net/packet/PacketService.java @@ -27,7 +27,7 @@ import com.zfoo.protocol.serializer.CodeLanguage; import com.zfoo.protocol.util.DomUtils; import com.zfoo.protocol.util.StringUtils; import com.zfoo.protocol.xml.XmlProtocols; -import com.zfoo.util.math.NumberUtils; +import com.zfoo.protocol.util.NumberUtils; import io.netty.buffer.ByteBuf; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/protocol/src/main/java/com/zfoo/protocol/collection/CollectionUtils.java b/protocol/src/main/java/com/zfoo/protocol/collection/CollectionUtils.java index 99e1272d..8719f478 100644 --- a/protocol/src/main/java/com/zfoo/protocol/collection/CollectionUtils.java +++ b/protocol/src/main/java/com/zfoo/protocol/collection/CollectionUtils.java @@ -13,7 +13,6 @@ package com.zfoo.protocol.collection; -import com.zfoo.protocol.collection.model.NaturalComparator; import com.zfoo.protocol.model.Pair; import com.zfoo.protocol.util.AssertionUtils; import com.zfoo.protocol.util.IOUtils; @@ -131,11 +130,11 @@ public abstract class CollectionUtils { * @return a new sorted List, containing the elements of Collection a and b */ public static > List collate(List aList, List bList) { - return collate(aList, bList, NaturalComparator.getInstance(), true); + return collate(aList, bList, Comparator.naturalOrder(), true); } public static > List collate(List aList, List bList, boolean includeDuplicates) { - return collate(aList, bList, NaturalComparator.getInstance(), includeDuplicates); + return collate(aList, bList, Comparator.naturalOrder(), includeDuplicates); } public static List collate(List aList, List bList, Comparator comparator) { diff --git a/protocol/src/main/java/com/zfoo/protocol/collection/model/NaturalComparator.java b/protocol/src/main/java/com/zfoo/protocol/collection/model/NaturalComparator.java deleted file mode 100644 index 7a00100a..00000000 --- a/protocol/src/main/java/com/zfoo/protocol/collection/model/NaturalComparator.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (C) 2020 The zfoo Authors - * Licensed 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 com.zfoo.protocol.collection.model; - -import java.util.Comparator; - -public class NaturalComparator> implements Comparator { - - - /** - * The singleton instance. - */ - private static final NaturalComparator INSTANCE = new NaturalComparator<>(); - - //----------------------------------------------------------------------- - - /** - * Constructor whose use should be avoided. - *

- * Please use the {@link #getInstance()} method whenever possible. - */ - public NaturalComparator() { - super(); - } - - //----------------------------------------------------------------------- - - /** - * Gets the singleton instance of a ComparableComparator. - *

- * Developers are encouraged to use the comparator returned from this method - * instead of constructing a new instance to reduce allocation and GC overhead - * when multiple comparable comparators may be used in the same VM. - * - * @param the element type - * @return the singleton ComparableComparator - */ - public static > NaturalComparator getInstance() { - return (NaturalComparator) INSTANCE; - } - - //----------------------------------------------------------------------- - - /** - * Compare the two {@link Comparable Comparable} arguments. - * This method is equivalent to: - *

((Comparable)obj1).compareTo(obj2)
- * - * @param a the first object to compare - * @param b the second object to compare - * @return negative if obj1 is less, positive if greater, zero if equal - * @throws NullPointerException if obj1 is null, - * or when ((Comparable)obj1).compareTo(obj2) does - * @throws ClassCastException if obj1 is not a Comparable, - * or when ((Comparable)obj1).compareTo(obj2) does - */ - @Override - public int compare(final E a, final E b) { - return a.compareTo(b); - } - -} diff --git a/util/src/main/java/com/zfoo/util/math/NumberUtils.java b/protocol/src/main/java/com/zfoo/protocol/util/NumberUtils.java similarity index 99% rename from util/src/main/java/com/zfoo/util/math/NumberUtils.java rename to protocol/src/main/java/com/zfoo/protocol/util/NumberUtils.java index 0c052e23..de495fac 100644 --- a/util/src/main/java/com/zfoo/util/math/NumberUtils.java +++ b/protocol/src/main/java/com/zfoo/protocol/util/NumberUtils.java @@ -1,6 +1,5 @@ /* * Copyright (C) 2020 The zfoo Authors - * * Licensed 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 * @@ -11,11 +10,9 @@ * See the License for the specific language governing permissions and limitations under the License. */ -package com.zfoo.util.math; +package com.zfoo.protocol.util; import com.zfoo.protocol.collection.ArrayUtils; -import com.zfoo.protocol.util.AssertionUtils; -import com.zfoo.protocol.util.StringUtils; import java.math.BigDecimal; import java.math.RoundingMode; diff --git a/util/src/main/java/com/zfoo/util/math/RandomUtils.java b/util/src/main/java/com/zfoo/util/math/RandomUtils.java index 994b7e27..ceb0d8b4 100644 --- a/util/src/main/java/com/zfoo/util/math/RandomUtils.java +++ b/util/src/main/java/com/zfoo/util/math/RandomUtils.java @@ -13,6 +13,7 @@ package com.zfoo.util.math; +import com.zfoo.protocol.util.NumberUtils; import com.zfoo.protocol.util.StringUtils; import java.math.BigDecimal;