From 86dc85a12e89700db7771e1a5fa7d6b2db1c8777 Mon Sep 17 00:00:00 2001
From: Caideyipi <87789683+Caideyipi@users.noreply.github.com>
Date: Wed, 22 Oct 2025 10:01:08 +0800
Subject: [PATCH 1/8] fix
---
java/pom.xml | 10 -
java/tools/pom.xml | 8 -
.../org/apache/tsfile/tools/TsFileTool.java | 4 +-
java/tsfile/pom.xml | 8 -
.../org/apache/commons/codec/binary/Hex.java | 118 ++
.../codec/binary/MessageDigestAlgorithms.java | 52 +
.../commons/codec/binary/StringUtils.java | 54 +
.../commons/codec/digest/DigestUtils.java | 121 ++
.../commons/collections4/BoundedMap.java | 44 +
.../commons/collections4/CollectionUtils.java | 52 +
.../org/apache/commons/collections4/Get.java | 91 ++
.../commons/collections4/IterableGet.java | 47 +
.../commons/collections4/IterableMap.java | 43 +
.../apache/commons/collections4/KeyValue.java | 44 +
.../commons/collections4/MapIterator.java | 110 ++
.../apache/commons/collections4/MapUtils.java | 39 +
.../commons/collections4/OrderedIterator.java | 46 +
.../commons/collections4/OrderedMap.java | 70 +
.../collections4/OrderedMapIterator.java | 46 +
.../org/apache/commons/collections4/Put.java | 60 +
.../collections4/ResettableIterator.java | 33 +
.../comparators/ComparatorChain.java | 335 ++++
.../iterators/AbstractEmptyIterator.java | 72 +
.../iterators/AbstractEmptyMapIterator.java | 44 +
.../collections4/iterators/EmptyIterator.java | 74 +
.../iterators/EmptyMapIterator.java | 55 +
.../iterators/EmptyOrderedIterator.java | 53 +
.../iterators/EmptyOrderedMapIterator.java | 55 +
.../collections4/map/AbstractHashedMap.java | 1394 +++++++++++++++++
.../collections4/map/AbstractLinkedMap.java | 610 ++++++++
.../commons/collections4/map/LRUMap.java | 572 +++++++
.../java/org/apache/commons/io/Charsets.java | 211 +++
.../commons/io/FileExistsException.java | 53 +
.../java/org/apache/commons/io/FileUtils.java | 884 +++++++++++
.../org/apache/commons/io/FilenameUtils.java | 290 ++++
.../java/org/apache/commons/io/IOCase.java | 247 +++
.../apache/commons/io/IOExceptionList.java | 140 ++
.../apache/commons/io/IOIndexedException.java | 68 +
.../java/org/apache/commons/io/IOUtils.java | 462 ++++++
.../commons/io/RandomAccessFileMode.java | 96 ++
.../apache/commons/io/RandomAccessFiles.java | 46 +
.../commons/io/build/AbstractOrigin.java | 530 +++++++
.../io/build/AbstractOriginSupplier.java | 315 ++++
.../io/build/AbstractStreamBuilder.java | 329 ++++
.../commons/io/build/AbstractSupplier.java | 41 +
.../commons/io/charset/CharsetDecoders.java | 44 +
.../commons/io/charset/CharsetEncoders.java | 58 +
.../org/apache/commons/io/file/Counters.java | 419 +++++
.../commons/io/file/CountingPathVisitor.java | 195 +++
.../apache/commons/io/file/DeleteOption.java | 30 +
.../commons/io/file/DeletingPathVisitor.java | 188 +++
.../apache/commons/io/file/PathFilter.java | 40 +
.../org/apache/commons/io/file/PathUtils.java | 539 +++++++
.../apache/commons/io/file/PathVisitor.java | 30 +
.../commons/io/file/SimplePathVisitor.java | 57 +
.../commons/io/file/StandardDeleteOption.java | 51 +
.../io/filefilter/AbstractFileFilter.java | 177 +++
.../commons/io/filefilter/AndFileFilter.java | 192 +++
.../io/filefilter/ConditionalFileFilter.java | 60 +
.../io/filefilter/FalseFileFilter.java | 114 ++
.../commons/io/filefilter/FileFileFilter.java | 111 ++
.../commons/io/filefilter/IOFileFilter.java | 119 ++
.../commons/io/filefilter/NotFileFilter.java | 104 ++
.../commons/io/filefilter/OrFileFilter.java | 182 +++
.../io/filefilter/SuffixFileFilter.java | 214 +++
.../io/filefilter/SymbolicLinkFileFilter.java | 141 ++
.../commons/io/filefilter/TrueFileFilter.java | 114 ++
.../apache/commons/io/function/Constants.java | 60 +
.../org/apache/commons/io/function/Erase.java | 191 +++
.../commons/io/function/IOBaseStream.java | 153 ++
.../io/function/IOBaseStreamAdapter.java | 50 +
.../commons/io/function/IOBiConsumer.java | 87 +
.../commons/io/function/IOBiFunction.java | 76 +
.../commons/io/function/IOBinaryOperator.java | 75 +
.../commons/io/function/IOComparator.java | 58 +
.../commons/io/function/IOConsumer.java | 145 ++
.../commons/io/function/IOFunction.java | 199 +++
.../commons/io/function/IOIntSupplier.java | 50 +
.../commons/io/function/IOIterator.java | 116 ++
.../io/function/IOIteratorAdapter.java | 55 +
.../commons/io/function/IOLongSupplier.java | 37 +
.../commons/io/function/IOPredicate.java | 134 ++
.../commons/io/function/IOQuadFunction.java | 51 +
.../commons/io/function/IORunnable.java | 36 +
.../commons/io/function/IOSpliterator.java | 146 ++
.../io/function/IOSpliteratorAdapter.java | 44 +
.../apache/commons/io/function/IOStream.java | 633 ++++++++
.../commons/io/function/IOStreamAdapter.java | 44 +
.../apache/commons/io/function/IOStreams.java | 91 ++
.../commons/io/function/IOSupplier.java | 65 +
.../commons/io/function/IOTriConsumer.java | 78 +
.../commons/io/function/IOTriFunction.java | 66 +
.../commons/io/function/IOUnaryOperator.java | 54 +
.../apache/commons/io/function/Uncheck.java | 310 ++++
.../io/function/UncheckedIOBaseStream.java | 88 ++
.../io/function/UncheckedIOIterator.java | 60 +
.../io/function/UncheckedIOSpliterator.java | 82 +
.../commons/io/input/ClosedInputStream.java | 58 +
.../commons/io/input/ReaderInputStream.java | 453 ++++++
.../UnsynchronizedByteArrayInputStream.java | 276 ++++
.../output/AbstractByteArrayOutputStream.java | 394 +++++
.../io/output/ByteArrayOutputStream.java | 162 ++
.../commons/io/output/NullOutputStream.java | 86 +
.../io/output/StringBuilderWriter.java | 160 ++
.../io/output/ThresholdingOutputStream.java | 257 +++
.../UnsynchronizedByteArrayOutputStream.java | 229 +++
.../commons/io/output/WriterOutputStream.java | 479 ++++++
.../org/apache/commons/lang3/ArrayFill.java | 40 +
.../org/apache/commons/lang3/ArrayUtils.java | 355 +++++
.../commons/lang3/CharSequenceUtils.java | 163 ++
.../org/apache/commons/lang3/ClassUtils.java | 34 +
.../lang3/NotImplementedException.java | 143 ++
.../org/apache/commons/lang3/ObjectUtils.java | 148 ++
.../org/apache/commons/lang3/StringUtils.java | 498 ++++++
.../org/apache/commons/lang3/Strings.java | 464 ++++++
.../commons/lang3/SystemProperties.java | 94 ++
.../org/apache/commons/lang3/SystemUtils.java | 144 ++
.../org/apache/commons/lang3/Validate.java | 97 ++
.../lang3/exception/ExceptionUtils.java | 70 +
.../lang3/function/FailableBiConsumer.java | 78 +
.../lang3/function/FailableBiFunction.java | 77 +
.../lang3/function/FailableFunction.java | 114 ++
.../commons/lang3/function/Suppliers.java | 71 +
.../commons/lang3/function/TriFunction.java | 65 +
.../commons/lang3/math/NumberUtils.java | 153 ++
.../commons/lang3/tuple/ImmutablePair.java | 204 +++
.../commons/lang3/tuple/ImmutableTriple.java | 168 ++
.../org/apache/commons/lang3/tuple/Pair.java | 264 ++++
.../apache/commons/lang3/tuple/Triple.java | 205 +++
.../common/block/column/DictionaryColumn.java | 6 +-
.../java/org/apache/tsfile/utils/Pair.java | 1 +
...leGeneratorForSeriesReaderByTimestamp.java | 10 +-
.../tsfile/utils/FilePathUtilsTest.java | 6 +-
.../{FileUtils.java => FileTestUtils.java} | 2 +-
...eUtilsTest.java => FileTestUtilsTest.java} | 26 +-
.../org/apache/tsfile/parser/PathLexer.java | 2 +-
.../org/apache/tsfile/parser/PathParser.java | 2 +-
.../tsfile/parser/PathParserBaseVisitor.java | 2 +-
.../tsfile/parser/PathParserVisitor.java | 2 +-
139 files changed, 20799 insertions(+), 52 deletions(-)
create mode 100644 java/tsfile/src/main/java/org/apache/commons/codec/binary/Hex.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/codec/binary/MessageDigestAlgorithms.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/codec/binary/StringUtils.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/codec/digest/DigestUtils.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/collections4/BoundedMap.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/collections4/CollectionUtils.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/collections4/Get.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/collections4/IterableGet.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/collections4/IterableMap.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/collections4/KeyValue.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/collections4/MapIterator.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/collections4/MapUtils.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/collections4/OrderedIterator.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/collections4/OrderedMap.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/collections4/OrderedMapIterator.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/collections4/Put.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/collections4/ResettableIterator.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/collections4/comparators/ComparatorChain.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/collections4/iterators/AbstractEmptyIterator.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/collections4/iterators/AbstractEmptyMapIterator.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/collections4/iterators/EmptyIterator.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/collections4/iterators/EmptyMapIterator.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/collections4/iterators/EmptyOrderedIterator.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/collections4/iterators/EmptyOrderedMapIterator.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/collections4/map/AbstractHashedMap.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/collections4/map/AbstractLinkedMap.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/collections4/map/LRUMap.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/Charsets.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/FileExistsException.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/FileUtils.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/FilenameUtils.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/IOCase.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/IOExceptionList.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/IOIndexedException.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/IOUtils.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/RandomAccessFileMode.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/RandomAccessFiles.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/build/AbstractOrigin.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/build/AbstractOriginSupplier.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/build/AbstractStreamBuilder.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/build/AbstractSupplier.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/charset/CharsetDecoders.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/charset/CharsetEncoders.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/file/Counters.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/file/CountingPathVisitor.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/file/DeleteOption.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/file/DeletingPathVisitor.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/file/PathFilter.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/file/PathUtils.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/file/PathVisitor.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/file/SimplePathVisitor.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/file/StandardDeleteOption.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/filefilter/AbstractFileFilter.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/filefilter/AndFileFilter.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/filefilter/ConditionalFileFilter.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/filefilter/FalseFileFilter.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/filefilter/FileFileFilter.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/filefilter/IOFileFilter.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/filefilter/NotFileFilter.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/filefilter/OrFileFilter.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/filefilter/SuffixFileFilter.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/filefilter/SymbolicLinkFileFilter.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/filefilter/TrueFileFilter.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/function/Constants.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/function/Erase.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/function/IOBaseStream.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/function/IOBaseStreamAdapter.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/function/IOBiConsumer.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/function/IOBiFunction.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/function/IOBinaryOperator.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/function/IOComparator.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/function/IOConsumer.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/function/IOFunction.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/function/IOIntSupplier.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/function/IOIterator.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/function/IOIteratorAdapter.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/function/IOLongSupplier.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/function/IOPredicate.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/function/IOQuadFunction.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/function/IORunnable.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/function/IOSpliterator.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/function/IOSpliteratorAdapter.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/function/IOStream.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/function/IOStreamAdapter.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/function/IOStreams.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/function/IOSupplier.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/function/IOTriConsumer.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/function/IOTriFunction.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/function/IOUnaryOperator.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/function/Uncheck.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/function/UncheckedIOBaseStream.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/function/UncheckedIOIterator.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/function/UncheckedIOSpliterator.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/input/ClosedInputStream.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/input/ReaderInputStream.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/input/UnsynchronizedByteArrayInputStream.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/output/AbstractByteArrayOutputStream.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/output/ByteArrayOutputStream.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/output/NullOutputStream.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/output/StringBuilderWriter.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/output/ThresholdingOutputStream.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/output/UnsynchronizedByteArrayOutputStream.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/io/output/WriterOutputStream.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/lang3/ArrayFill.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/lang3/ArrayUtils.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/lang3/CharSequenceUtils.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/lang3/ClassUtils.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/lang3/NotImplementedException.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/lang3/ObjectUtils.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/lang3/StringUtils.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/lang3/Strings.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/lang3/SystemProperties.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/lang3/SystemUtils.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/lang3/Validate.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/lang3/exception/ExceptionUtils.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/lang3/function/FailableBiConsumer.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/lang3/function/FailableBiFunction.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/lang3/function/FailableFunction.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/lang3/function/Suppliers.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/lang3/function/TriFunction.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/lang3/math/NumberUtils.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/lang3/tuple/ImmutablePair.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/lang3/tuple/ImmutableTriple.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/lang3/tuple/Pair.java
create mode 100644 java/tsfile/src/main/java/org/apache/commons/lang3/tuple/Triple.java
rename java/tsfile/src/test/java/org/apache/tsfile/utils/{FileUtils.java => FileTestUtils.java} (98%)
rename java/tsfile/src/test/java/org/apache/tsfile/utils/{FileUtilsTest.java => FileTestUtilsTest.java} (58%)
mode change 100755 => 100644
diff --git a/java/pom.xml b/java/pom.xml
index a380d4a4a..b8e5a5517 100644
--- a/java/pom.xml
+++ b/java/pom.xml
@@ -48,16 +48,6 @@
snappy-java1.1.10.5
-
- commons-io
- commons-io
- 2.17.0
-
-
- org.apache.commons
- commons-lang3
- 3.18.0
- org.lz4lz4-java
diff --git a/java/tools/pom.xml b/java/tools/pom.xml
index c8a76f97f..80549e7c2 100644
--- a/java/tools/pom.xml
+++ b/java/tools/pom.xml
@@ -39,14 +39,6 @@
commons-cli1.9.0
-
- commons-io
- commons-io
-
-
- org.apache.commons
- commons-lang3
- org.apache.tsfiletsfile
diff --git a/java/tools/src/main/java/org/apache/tsfile/tools/TsFileTool.java b/java/tools/src/main/java/org/apache/tsfile/tools/TsFileTool.java
index 5dd2afe53..559c8377e 100644
--- a/java/tools/src/main/java/org/apache/tsfile/tools/TsFileTool.java
+++ b/java/tools/src/main/java/org/apache/tsfile/tools/TsFileTool.java
@@ -36,7 +36,6 @@
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.io.FilenameUtils;
-import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -55,6 +54,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
@@ -318,7 +318,7 @@ private static void cpFile(String sourceFilePath, String targetDirectoryPath) {
public static void writeToNewCSV(
String headerLine, String fileAbsolutePath, List data, String newFileName) {
- if (schema.hasHeader && StringUtils.isNotEmpty(headerLine)) {
+ if (schema.hasHeader && Objects.nonNull(headerLine) && !headerLine.isEmpty()) {
data.add(0, headerLine);
}
String inputFileAbsolutePath = new File(inputDirectoryStr).getAbsolutePath();
diff --git a/java/tsfile/pom.xml b/java/tsfile/pom.xml
index 9187b60e8..6d0d41b07 100644
--- a/java/tsfile/pom.xml
+++ b/java/tsfile/pom.xml
@@ -48,14 +48,6 @@
org.xerial.snappysnappy-java
-
- commons-io
- commons-io
-
-
- org.apache.commons
- commons-lang3
- org.lz4lz4-java
diff --git a/java/tsfile/src/main/java/org/apache/commons/codec/binary/Hex.java b/java/tsfile/src/main/java/org/apache/commons/codec/binary/Hex.java
new file mode 100644
index 000000000..01b92eee8
--- /dev/null
+++ b/java/tsfile/src/main/java/org/apache/commons/codec/binary/Hex.java
@@ -0,0 +1,118 @@
+/*
+ * 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.commons.codec.binary;
+
+/////////////////////////////////////////////////////////////////////////////////////////////////
+// IoTDB
+/////////////////////////////////////////////////////////////////////////////////////////////////
+
+public class Hex {
+
+ /** Used to build output as hex. */
+ private static final char[] DIGITS_LOWER = {
+ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
+ };
+
+ /** Used to build output as hex. */
+ private static final char[] DIGITS_UPPER = {
+ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
+ };
+
+ /**
+ * Converts an array of bytes into a String representing the hexadecimal values of each byte in
+ * order. The returned String will be double the length of the passed array, as it takes two
+ * characters to represent any given byte.
+ *
+ * @param data a byte[] to convert to hexadecimal characters
+ * @return A String containing lower-case hexadecimal characters
+ * @since 1.4
+ */
+ public static String encodeHexString(final byte[] data) {
+ return new String(encodeHex(data));
+ }
+
+ /**
+ * Converts an array of bytes into an array of characters representing the hexadecimal values of
+ * each byte in order. The returned array will be double the length of the passed array, as it
+ * takes two characters to represent any given byte.
+ *
+ * @param data a byte[] to convert to hexadecimal characters
+ * @return A char[] containing lower-case hexadecimal characters
+ */
+ public static char[] encodeHex(final byte[] data) {
+ return encodeHex(data, true);
+ }
+
+ /**
+ * Converts an array of bytes into an array of characters representing the hexadecimal values of
+ * each byte in order. The returned array will be double the length of the passed array, as it
+ * takes two characters to represent any given byte.
+ *
+ * @param data a byte[] to convert to Hex characters
+ * @param toLowerCase {@code true} converts to lowercase, {@code false} to uppercase
+ * @return A char[] containing hexadecimal characters in the selected case
+ * @since 1.4
+ */
+ public static char[] encodeHex(final byte[] data, final boolean toLowerCase) {
+ return encodeHex(data, toLowerCase ? DIGITS_LOWER : DIGITS_UPPER);
+ }
+
+ /**
+ * Converts an array of bytes into an array of characters representing the hexadecimal values of
+ * each byte in order. The returned array will be double the length of the passed array, as it
+ * takes two characters to represent any given byte.
+ *
+ * @param data a byte[] to convert to hexadecimal characters
+ * @param toDigits the output alphabet (must contain at least 16 chars)
+ * @return A char[] containing the appropriate characters from the alphabet For best results, this
+ * should be either upper- or lower-case hex.
+ * @since 1.4
+ */
+ protected static char[] encodeHex(final byte[] data, final char[] toDigits) {
+ final int dataLength = data.length;
+ final char[] out = new char[dataLength << 1];
+ encodeHex(data, 0, dataLength, toDigits, out, 0);
+ return out;
+ }
+
+ /**
+ * Converts an array of bytes into an array of characters representing the hexadecimal values of
+ * each byte in order.
+ *
+ * @param data a byte[] to convert to hexadecimal characters
+ * @param dataOffset the position in {@code data} to start encoding from
+ * @param dataLen the number of bytes from {@code dataOffset} to encode
+ * @param toDigits the output alphabet (must contain at least 16 chars)
+ * @param out a char[] which will hold the resultant appropriate characters from the alphabet.
+ * @param outOffset the position within {@code out} at which to start writing the encoded
+ * characters.
+ */
+ private static void encodeHex(
+ final byte[] data,
+ final int dataOffset,
+ final int dataLen,
+ final char[] toDigits,
+ final char[] out,
+ final int outOffset) {
+ // two characters form the hex value.
+ for (int i = dataOffset, j = outOffset; i < dataOffset + dataLen; i++) {
+ out[j++] = toDigits[(0xF0 & data[i]) >>> 4];
+ out[j++] = toDigits[0x0F & data[i]];
+ }
+ }
+}
diff --git a/java/tsfile/src/main/java/org/apache/commons/codec/binary/MessageDigestAlgorithms.java b/java/tsfile/src/main/java/org/apache/commons/codec/binary/MessageDigestAlgorithms.java
new file mode 100644
index 000000000..f27532699
--- /dev/null
+++ b/java/tsfile/src/main/java/org/apache/commons/codec/binary/MessageDigestAlgorithms.java
@@ -0,0 +1,52 @@
+/*
+ * 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.commons.codec.binary;
+
+import java.security.MessageDigest;
+
+/**
+ * Standard {@link MessageDigest} algorithm names from the Java Cryptography Architecture
+ * Standard Algorithm Name Documentation.
+ *
+ *
This class is immutable and thread-safe.
+ *
+ *
+ *
Java 8 and up: SHA-224.
+ *
Java 9 and up: SHA3-224, SHA3-256, SHA3-384, SHA3-512.
+ *
+ *
+ * @see
+ * Java 8 Cryptography Architecture Standard Algorithm Name Documentation
+ * @see
+ * Java 11 Cryptography Architecture Standard Algorithm Name Documentation
+ * @see
+ * Java 17 Cryptography Architecture Standard Algorithm Name Documentation
+ * @see
+ * Java 21 Cryptography Architecture Standard Algorithm Name Documentation
+ * @see FIPS PUB 180-4
+ * @see FIPS PUB 202
+ * @since 1.7
+ */
+public class MessageDigestAlgorithms {
+ /** The MD2 message digest algorithm defined in RFC 1319. */
+ public static final String MD2 = "MD2";
+}
diff --git a/java/tsfile/src/main/java/org/apache/commons/codec/binary/StringUtils.java b/java/tsfile/src/main/java/org/apache/commons/codec/binary/StringUtils.java
new file mode 100644
index 000000000..fe13454fe
--- /dev/null
+++ b/java/tsfile/src/main/java/org/apache/commons/codec/binary/StringUtils.java
@@ -0,0 +1,54 @@
+/*
+ * 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.commons.codec.binary;
+
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+
+/////////////////////////////////////////////////////////////////////////////////////////////////
+// IoTDB
+/////////////////////////////////////////////////////////////////////////////////////////////////
+
+public class StringUtils {
+ /**
+ * Encodes the given string into a sequence of bytes using the UTF-8 charset, storing the result
+ * into a new byte array.
+ *
+ * @param string the String to encode, may be {@code null}
+ * @return encoded bytes, or {@code null} if the input string was {@code null}
+ * @throws NullPointerException Thrown if {@link StandardCharsets#UTF_8} is not initialized, which
+ * should never happen since it is required by the Java platform specification.
+ * @since As of 1.7, throws {@link NullPointerException} instead of UnsupportedEncodingException
+ * @see Charset
+ * @see #getBytesUnchecked(String, String)
+ */
+ public static byte[] getBytesUtf8(final String string) {
+ return getBytes(string, StandardCharsets.UTF_8);
+ }
+
+ /**
+ * Calls {@link String#getBytes(Charset)}
+ *
+ * @param string The string to encode (if null, return null).
+ * @param charset The {@link Charset} to encode the {@code String}
+ * @return the encoded bytes
+ */
+ private static byte[] getBytes(final String string, final Charset charset) {
+ return string == null ? null : string.getBytes(charset);
+ }
+}
diff --git a/java/tsfile/src/main/java/org/apache/commons/codec/digest/DigestUtils.java b/java/tsfile/src/main/java/org/apache/commons/codec/digest/DigestUtils.java
new file mode 100644
index 000000000..5f1b742c0
--- /dev/null
+++ b/java/tsfile/src/main/java/org/apache/commons/codec/digest/DigestUtils.java
@@ -0,0 +1,121 @@
+/*
+ * 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.commons.codec.digest;
+
+import org.apache.commons.codec.binary.Hex;
+import org.apache.commons.codec.binary.MessageDigestAlgorithms;
+import org.apache.commons.codec.binary.StringUtils;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+
+/////////////////////////////////////////////////////////////////////////////////////////////////
+// IoTDB
+/////////////////////////////////////////////////////////////////////////////////////////////////
+
+public class DigestUtils {
+
+ /**
+ * Calculates the MD2 digest and returns the value as a 32 character hexadecimal string.
+ *
+ * @param data Data to digest
+ * @return MD2 digest as a hexadecimal string
+ * @since 1.7
+ */
+ public static String md2Hex(final String data) {
+ return Hex.encodeHexString(md2(data));
+ }
+
+ /**
+ * Calculates the MD2 digest and returns the value as a 16 element {@code byte[]}.
+ *
+ * @param data Data to digest; converted to bytes using {@link StringUtils#getBytesUtf8(String)}
+ * @return MD2 digest
+ * @since 1.7
+ */
+ public static byte[] md2(final String data) {
+ return md2(StringUtils.getBytesUtf8(data));
+ }
+
+ /**
+ * Calculates the MD2 digest and returns the value as a 16 element {@code byte[]}.
+ *
+ * @param data Data to digest
+ * @return MD2 digest
+ * @since 1.7
+ */
+ public static byte[] md2(final byte[] data) {
+ return getMd2Digest().digest(data);
+ }
+
+ /**
+ * Gets an MD2 MessageDigest.
+ *
+ * @return An MD2 digest instance.
+ * @throws IllegalArgumentException when a {@link NoSuchAlgorithmException} is caught, which
+ * should never happen because MD2 is a built-in algorithm
+ * @see MessageDigestAlgorithms#MD2
+ * @since 1.7
+ */
+ public static MessageDigest getMd2Digest() {
+ return getDigest(MessageDigestAlgorithms.MD2);
+ }
+
+ public static String md5Hex(InputStream data) throws IOException {
+ return Hex.encodeHexString(md5(data));
+ }
+
+ public static byte[] md5(InputStream data) throws IOException {
+ return digest(getMd5Digest(), data);
+ }
+
+ public static byte[] digest(MessageDigest messageDigest, InputStream data) throws IOException {
+ return updateDigest(messageDigest, data).digest();
+ }
+
+ public static MessageDigest updateDigest(MessageDigest digest, InputStream inputStream)
+ throws IOException {
+ byte[] buffer = new byte[1024];
+
+ for (int read = inputStream.read(buffer, 0, 1024);
+ read > -1;
+ read = inputStream.read(buffer, 0, 1024)) {
+ digest.update(buffer, 0, read);
+ }
+
+ return digest;
+ }
+
+ public static MessageDigest getMd5Digest() {
+ return getDigest("MD5");
+ }
+
+ public static MessageDigest getDigest(String algorithm) {
+ try {
+ return getMessageDigest(algorithm);
+ } catch (NoSuchAlgorithmException var2) {
+ throw new IllegalArgumentException(var2);
+ }
+ }
+
+ private static MessageDigest getMessageDigest(String algorithm) throws NoSuchAlgorithmException {
+ return MessageDigest.getInstance(algorithm);
+ }
+}
diff --git a/java/tsfile/src/main/java/org/apache/commons/collections4/BoundedMap.java b/java/tsfile/src/main/java/org/apache/commons/collections4/BoundedMap.java
new file mode 100644
index 000000000..8ac6bc769
--- /dev/null
+++ b/java/tsfile/src/main/java/org/apache/commons/collections4/BoundedMap.java
@@ -0,0 +1,44 @@
+/*
+ * 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.commons.collections4;
+
+/**
+ * Defines a map that is bounded in size.
+ *
+ *
The size of the map can vary, but it can never exceed a preset maximum number of elements.
+ * This interface allows the querying of details associated with the maximum number of elements.
+ *
+ * @param the type of the keys in this map
+ * @param the type of the values in this map
+ * @since 3.0
+ */
+public interface BoundedMap extends IterableMap {
+
+ /**
+ * Returns true if this map is full and no new elements can be added.
+ *
+ * @return true if the map is full
+ */
+ boolean isFull();
+
+ /**
+ * Gets the maximum size of the map (the bound).
+ *
+ * @return the maximum number of elements the map can hold
+ */
+ int maxSize();
+}
diff --git a/java/tsfile/src/main/java/org/apache/commons/collections4/CollectionUtils.java b/java/tsfile/src/main/java/org/apache/commons/collections4/CollectionUtils.java
new file mode 100644
index 000000000..37eb6806d
--- /dev/null
+++ b/java/tsfile/src/main/java/org/apache/commons/collections4/CollectionUtils.java
@@ -0,0 +1,52 @@
+/*
+ * 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.commons.collections4;
+
+import java.util.Collection;
+
+/////////////////////////////////////////////////////////////////////////////////////////////////
+// IoTDB
+/////////////////////////////////////////////////////////////////////////////////////////////////
+
+public class CollectionUtils {
+ /**
+ * Null-safe check if the specified collection is empty.
+ *
+ *
Null returns true.
+ *
+ * @param coll the collection to check, may be null
+ * @return true if empty or null
+ * @since 3.2
+ */
+ public static boolean isEmpty(final Collection> coll) {
+ return coll == null || coll.isEmpty();
+ }
+
+ /**
+ * Null-safe check if the specified collection is not empty.
+ *
+ *
Null returns false.
+ *
+ * @param coll the collection to check, may be null
+ * @return true if non-null and non-empty
+ * @since 3.2
+ */
+ public static boolean isNotEmpty(final Collection> coll) {
+ return !isEmpty(coll);
+ }
+}
diff --git a/java/tsfile/src/main/java/org/apache/commons/collections4/Get.java b/java/tsfile/src/main/java/org/apache/commons/collections4/Get.java
new file mode 100644
index 000000000..7f14acb45
--- /dev/null
+++ b/java/tsfile/src/main/java/org/apache/commons/collections4/Get.java
@@ -0,0 +1,91 @@
+/*
+ * 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.commons.collections4;
+
+import java.util.Collection;
+import java.util.Set;
+
+/**
+ * The "read" subset of the {@link java.util.Map} interface.
+ *
+ * @param the type of the keys in this map
+ * @param the type of the values in this map
+ * @since 4.0
+ * @see Put
+ */
+public interface Get {
+
+ /**
+ * @param key key whose presence in this map is to be tested
+ * @return true if this map contains a mapping for the specified key
+ * @see java.util.Map#containsKey(Object)
+ */
+ boolean containsKey(Object key);
+
+ /**
+ * @param value value whose presence in this map is to be tested
+ * @return true if this map maps one or more keys to the specified value
+ * @see java.util.Map#containsValue(Object)
+ */
+ boolean containsValue(Object value);
+
+ /**
+ * @return a set view of the mappings contained in this map
+ * @see java.util.Map#entrySet()
+ */
+ Set> entrySet();
+
+ /**
+ * @param key the key whose associated value is to be returned
+ * @return the value to which the specified key is mapped, or {@code null} if this map contains no
+ * mapping for the key
+ * @see java.util.Map#get(Object)
+ */
+ V get(Object key);
+
+ /**
+ * @param key key whose mapping is to be removed from the map
+ * @return the previous value associated with key, or null if there was
+ * no mapping for key.
+ * @see java.util.Map#remove(Object)
+ */
+ V remove(Object key);
+
+ /**
+ * @return true if this map contains no key-value mappings
+ * @see java.util.Map#isEmpty()
+ */
+ boolean isEmpty();
+
+ /**
+ * @return a set view of the keys contained in this map
+ * @see java.util.Map#keySet()
+ */
+ Set keySet();
+
+ /**
+ * @return the number of key-value mappings in this map
+ * @see java.util.Map#size()
+ */
+ int size();
+
+ /**
+ * @return a collection view of the values contained in this map
+ * @see java.util.Map#values()
+ */
+ Collection values();
+}
diff --git a/java/tsfile/src/main/java/org/apache/commons/collections4/IterableGet.java b/java/tsfile/src/main/java/org/apache/commons/collections4/IterableGet.java
new file mode 100644
index 000000000..485acc7df
--- /dev/null
+++ b/java/tsfile/src/main/java/org/apache/commons/collections4/IterableGet.java
@@ -0,0 +1,47 @@
+/*
+ * 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.commons.collections4;
+
+/**
+ * The "read" subset of the {@link java.util.Map} interface.
+ *
+ * @param the type of the keys in this map
+ * @param the type of the values in this map
+ * @since 4.0
+ * @see Put
+ */
+public interface IterableGet extends Get {
+ /**
+ * Obtains a MapIterator over the map.
+ *
+ *
A map iterator is an efficient way of iterating over maps. There is no need to access the
+ * entry set or use Map Entry objects.
+ *
+ *
+ * IterableMap<String,Integer> map = new HashedMap<String,Integer>();
+ * MapIterator<String,Integer> it = map.mapIterator();
+ * while (it.hasNext()) {
+ * String key = it.next();
+ * Integer value = it.getValue();
+ * it.setValue(value + 1);
+ * }
+ *
+ *
+ * @return a map iterator
+ */
+ MapIterator mapIterator();
+}
diff --git a/java/tsfile/src/main/java/org/apache/commons/collections4/IterableMap.java b/java/tsfile/src/main/java/org/apache/commons/collections4/IterableMap.java
new file mode 100644
index 000000000..c46366ffb
--- /dev/null
+++ b/java/tsfile/src/main/java/org/apache/commons/collections4/IterableMap.java
@@ -0,0 +1,43 @@
+/*
+ * 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.commons.collections4;
+
+import java.util.Map;
+
+/**
+ * Defines a map that can be iterated directly without needing to create an entry set.
+ *
+ *
A map iterator is an efficient way of iterating over maps. There is no need to access the
+ * entry set or use Map Entry objects.
+ *
+ *
+ * IterableMap<String,Integer> map = new HashedMap<String,Integer>();
+ * MapIterator<String,Integer> it = map.mapIterator();
+ * while (it.hasNext()) {
+ * String key = it.next();
+ * Integer value = it.getValue();
+ * it.setValue(value + 1);
+ * }
+ *
+ *
+ * @param the type of the keys in this map
+ * @param the type of the values in this map
+ * @since 3.0
+ */
+public interface IterableMap extends Map, Put, IterableGet {
+ // empty
+}
diff --git a/java/tsfile/src/main/java/org/apache/commons/collections4/KeyValue.java b/java/tsfile/src/main/java/org/apache/commons/collections4/KeyValue.java
new file mode 100644
index 000000000..1956c7a67
--- /dev/null
+++ b/java/tsfile/src/main/java/org/apache/commons/collections4/KeyValue.java
@@ -0,0 +1,44 @@
+/*
+ * 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.commons.collections4;
+
+/**
+ * Defines a simple key value pair.
+ *
+ *
A Map Entry has considerable additional semantics over and above a simple key-value pair. This
+ * interface defines the minimum key value, with just the two get methods.
+ *
+ * @param the type of the key
+ * @param the type of the value
+ * @since 3.0
+ */
+public interface KeyValue {
+
+ /**
+ * Gets the key from the pair.
+ *
+ * @return the key
+ */
+ K getKey();
+
+ /**
+ * Gets the value from the pair.
+ *
+ * @return the value
+ */
+ V getValue();
+}
diff --git a/java/tsfile/src/main/java/org/apache/commons/collections4/MapIterator.java b/java/tsfile/src/main/java/org/apache/commons/collections4/MapIterator.java
new file mode 100644
index 000000000..68198f7d8
--- /dev/null
+++ b/java/tsfile/src/main/java/org/apache/commons/collections4/MapIterator.java
@@ -0,0 +1,110 @@
+/*
+ * 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.commons.collections4;
+
+import java.util.Iterator;
+
+/**
+ * Defines an iterator that operates over a Map.
+ *
+ *
This iterator is a special version designed for maps. It can be more efficient to use this
+ * rather than an entry set iterator where the option is available, and it is certainly more
+ * convenient.
+ *
+ *
A map that provides this interface may not hold the data internally using Map Entry objects,
+ * thus this interface can avoid lots of object creation.
+ *
+ *
In use, this iterator iterates through the keys in the map. After each call to next()
+ * , the getValue() method provides direct access to the value. The value can
+ * also be set using setValue().
+ *
+ *
+ *
+ * @param the type of the keys in the map
+ * @param the type of the values in the map
+ * @since 3.0
+ */
+public interface MapIterator extends Iterator {
+
+ /**
+ * Checks to see if there are more entries still to be iterated.
+ *
+ * @return true if the iterator has more elements
+ */
+ @Override
+ boolean hasNext();
+
+ /**
+ * Gets the next key from the Map.
+ *
+ * @return the next key in the iteration
+ * @throws java.util.NoSuchElementException if the iteration is finished
+ */
+ @Override
+ K next();
+
+ // -----------------------------------------------------------------------
+ /**
+ * Gets the current key, which is the key returned by the last call to next().
+ *
+ * @return the current key
+ * @throws IllegalStateException if next() has not yet been called
+ */
+ K getKey();
+
+ /**
+ * Gets the current value, which is the value associated with the last key returned by
+ * next().
+ *
+ * @return the current value
+ * @throws IllegalStateException if next() has not yet been called
+ */
+ V getValue();
+
+ // -----------------------------------------------------------------------
+ /**
+ * Removes the last returned key from the underlying Map (optional operation).
+ *
+ *
This method can be called once per call to next().
+ *
+ * @throws UnsupportedOperationException if remove is not supported by the map
+ * @throws IllegalStateException if next() has not yet been called
+ * @throws IllegalStateException if remove() has already been called since the last
+ * call to next()
+ */
+ @Override
+ void remove();
+
+ /**
+ * Sets the value associated with the current key (optional operation).
+ *
+ * @param value the new value
+ * @return the previous value
+ * @throws UnsupportedOperationException if setValue is not supported by the map
+ * @throws IllegalStateException if next() has not yet been called
+ * @throws IllegalStateException if remove() has been called since the last call to
+ * next()
+ */
+ V setValue(V value);
+}
diff --git a/java/tsfile/src/main/java/org/apache/commons/collections4/MapUtils.java b/java/tsfile/src/main/java/org/apache/commons/collections4/MapUtils.java
new file mode 100644
index 000000000..d9240870a
--- /dev/null
+++ b/java/tsfile/src/main/java/org/apache/commons/collections4/MapUtils.java
@@ -0,0 +1,39 @@
+/*
+ * 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.commons.collections4;
+
+/////////////////////////////////////////////////////////////////////////////////////////////////
+// IoTDB
+/////////////////////////////////////////////////////////////////////////////////////////////////
+
+import java.util.Map;
+
+public class MapUtils {
+ /**
+ * Null-safe check if the specified map is empty.
+ *
+ *
Null returns true.
+ *
+ * @param map the map to check, may be null
+ * @return true if empty or null
+ * @since 3.2
+ */
+ public static boolean isEmpty(final Map, ?> map) {
+ return map == null || map.isEmpty();
+ }
+}
diff --git a/java/tsfile/src/main/java/org/apache/commons/collections4/OrderedIterator.java b/java/tsfile/src/main/java/org/apache/commons/collections4/OrderedIterator.java
new file mode 100644
index 000000000..44aa020f3
--- /dev/null
+++ b/java/tsfile/src/main/java/org/apache/commons/collections4/OrderedIterator.java
@@ -0,0 +1,46 @@
+/*
+ * 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.commons.collections4;
+
+import java.util.Iterator;
+
+/**
+ * Defines an iterator that operates over an ordered container. Subset of {@link
+ * java.util.ListIterator}.
+ *
+ *
This iterator allows both forward and reverse iteration through the container.
+ *
+ * @param the type of elements returned by this iterator
+ * @since 3.0
+ */
+public interface OrderedIterator extends Iterator {
+
+ /**
+ * Checks to see if there is a previous element that can be iterated to.
+ *
+ * @return true if the iterator has a previous element
+ */
+ boolean hasPrevious();
+
+ /**
+ * Gets the previous element from the container.
+ *
+ * @return the previous element in the iteration
+ * @throws java.util.NoSuchElementException if the iteration is finished
+ */
+ E previous();
+}
diff --git a/java/tsfile/src/main/java/org/apache/commons/collections4/OrderedMap.java b/java/tsfile/src/main/java/org/apache/commons/collections4/OrderedMap.java
new file mode 100644
index 000000000..7239f6deb
--- /dev/null
+++ b/java/tsfile/src/main/java/org/apache/commons/collections4/OrderedMap.java
@@ -0,0 +1,70 @@
+/*
+ * 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.commons.collections4;
+
+/**
+ * Defines a map that maintains order and allows both forward and backward iteration through that
+ * order.
+ *
+ * @param the type of the keys in the map
+ * @param the type of the values in the map
+ * @since 3.0
+ */
+public interface OrderedMap extends IterableMap {
+
+ /**
+ * Obtains an OrderedMapIterator over the map.
+ *
+ *
A ordered map iterator is an efficient way of iterating over maps in both directions.
+ *
+ * @return a map iterator
+ */
+ @Override
+ OrderedMapIterator mapIterator();
+
+ /**
+ * Gets the first key currently in this map.
+ *
+ * @return the first key currently in this map
+ * @throws java.util.NoSuchElementException if this map is empty
+ */
+ K firstKey();
+
+ /**
+ * Gets the last key currently in this map.
+ *
+ * @return the last key currently in this map
+ * @throws java.util.NoSuchElementException if this map is empty
+ */
+ K lastKey();
+
+ /**
+ * Gets the next key after the one specified.
+ *
+ * @param key the key to search for next from
+ * @return the next key, null if no match or at end
+ */
+ K nextKey(K key);
+
+ /**
+ * Gets the previous key before the one specified.
+ *
+ * @param key the key to search for previous from
+ * @return the previous key, null if no match or at start
+ */
+ K previousKey(K key);
+}
diff --git a/java/tsfile/src/main/java/org/apache/commons/collections4/OrderedMapIterator.java b/java/tsfile/src/main/java/org/apache/commons/collections4/OrderedMapIterator.java
new file mode 100644
index 000000000..72a4f7b87
--- /dev/null
+++ b/java/tsfile/src/main/java/org/apache/commons/collections4/OrderedMapIterator.java
@@ -0,0 +1,46 @@
+/*
+ * 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.commons.collections4;
+
+/**
+ * Defines an iterator that operates over an ordered Map.
+ *
+ *
This iterator allows both forward and reverse iteration through the map.
+ *
+ * @param the type of the keys in the map
+ * @param the type of the values in the map
+ * @since 3.0
+ */
+public interface OrderedMapIterator extends MapIterator, OrderedIterator {
+
+ /**
+ * Checks to see if there is a previous entry that can be iterated to.
+ *
+ * @return true if the iterator has a previous element
+ */
+ @Override
+ boolean hasPrevious();
+
+ /**
+ * Gets the previous key from the Map.
+ *
+ * @return the previous key in the iteration
+ * @throws java.util.NoSuchElementException if the iteration is finished
+ */
+ @Override
+ K previous();
+}
diff --git a/java/tsfile/src/main/java/org/apache/commons/collections4/Put.java b/java/tsfile/src/main/java/org/apache/commons/collections4/Put.java
new file mode 100644
index 000000000..2bff27d5e
--- /dev/null
+++ b/java/tsfile/src/main/java/org/apache/commons/collections4/Put.java
@@ -0,0 +1,60 @@
+/*
+ * 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.commons.collections4;
+
+import java.util.Map;
+
+/**
+ * The "write" subset of the {@link Map} interface.
+ *
+ *
NOTE: in the original {@link Map} interface, {@link Map#put(Object, Object)} is known to have
+ * the same return type as {@link Map#get(Object)}, namely {@code V}. {@link Put} makes no
+ * assumptions in this regard (there is no association with, nor even knowledge of, a "reading"
+ * interface) and thus defines {@link #put(Object, Object)} as returning {@link Object}.
+ *
+ * @param the type of the keys in this map
+ * @param the type of the values in this map
+ * @since 4.0
+ * @see Get
+ */
+public interface Put {
+
+ /**
+ * @see Map#clear()
+ */
+ void clear();
+
+ /**
+ * Note that the return type is Object, rather than V as in the Map interface. See the class
+ * Javadoc for further info.
+ *
+ * @param key key with which the specified value is to be associated
+ * @param value value to be associated with the specified key
+ * @return the previous value associated with key, or null if there was
+ * no mapping for key. (A null return can also indicate that the map
+ * previously associated null with key, if the implementation
+ * supports null values.)
+ * @see Map#put(Object, Object)
+ */
+ Object put(K key, V value);
+
+ /**
+ * @param t mappings to be stored in this map
+ * @see Map#putAll(Map)
+ */
+ void putAll(Map extends K, ? extends V> t);
+}
diff --git a/java/tsfile/src/main/java/org/apache/commons/collections4/ResettableIterator.java b/java/tsfile/src/main/java/org/apache/commons/collections4/ResettableIterator.java
new file mode 100644
index 000000000..c798c3b30
--- /dev/null
+++ b/java/tsfile/src/main/java/org/apache/commons/collections4/ResettableIterator.java
@@ -0,0 +1,33 @@
+/*
+ * 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.commons.collections4;
+
+import java.util.Iterator;
+
+/**
+ * Defines an iterator that can be reset back to an initial state.
+ *
+ *
This interface allows an iterator to be repeatedly reused.
+ *
+ * @param the type of elements returned by this iterator
+ * @since 3.0
+ */
+public interface ResettableIterator extends Iterator {
+
+ /** Resets the iterator back to the position at which the iterator was created. */
+ void reset();
+}
diff --git a/java/tsfile/src/main/java/org/apache/commons/collections4/comparators/ComparatorChain.java b/java/tsfile/src/main/java/org/apache/commons/collections4/comparators/ComparatorChain.java
new file mode 100644
index 000000000..69de70464
--- /dev/null
+++ b/java/tsfile/src/main/java/org/apache/commons/collections4/comparators/ComparatorChain.java
@@ -0,0 +1,335 @@
+/*
+ * 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.commons.collections4.comparators;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.BitSet;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * A ComparatorChain is a Comparator that wraps one or more Comparators in sequence. The
+ * ComparatorChain calls each Comparator in sequence until either 1) any single Comparator returns a
+ * non-zero result (and that result is then returned), or 2) the ComparatorChain is exhausted (and
+ * zero is returned). This type of sorting is very similar to multi-column sorting in SQL, and this
+ * class allows Java classes to emulate that kind of behaviour when sorting a List.
+ *
+ *
To further facilitate SQL-like sorting, the order of any single Comparator in the list can be
+ * reversed.
+ *
+ *
Calling a method that adds new Comparators or changes the ascend/descend sort after
+ * compare(Object, Object) has been called will result in an UnsupportedOperationException.
+ * However, take care to not alter the underlying List of Comparators or the BitSet that
+ * defines the sort order.
+ *
+ *
Instances of ComparatorChain are not synchronized. The class is not thread-safe at
+ * construction time, but it is thread-safe to perform multiple comparisons after all the
+ * setup operations are complete.
+ *
+ * @param the type of objects compared by this comparator
+ * @since 2.0
+ */
+public class ComparatorChain implements Comparator, Serializable {
+
+ /** Serialization version from Collections 2.0. */
+ private static final long serialVersionUID = -721644942746081630L;
+
+ /** The list of comparators in the chain. */
+ private final List> comparatorChain;
+
+ /** Order - false (clear) = ascend; true (set) = descend. */
+ private BitSet orderingBits = null;
+
+ /** Whether the chain has been "locked". */
+ private boolean isLocked = false;
+
+ // -----------------------------------------------------------------------
+ /**
+ * Construct a ComparatorChain with no Comparators. You must add at least one Comparator before
+ * calling the compare(Object,Object) method, or an UnsupportedOperationException is thrown
+ */
+ public ComparatorChain() {
+ this(new ArrayList>(), new BitSet());
+ }
+
+ /**
+ * Construct a ComparatorChain with a single Comparator, sorting in the forward order
+ *
+ * @param comparator First comparator in the Comparator chain
+ */
+ public ComparatorChain(final Comparator comparator) {
+ this(comparator, false);
+ }
+
+ /**
+ * Construct a Comparator chain with a single Comparator, sorting in the given order
+ *
+ * @param comparator First Comparator in the ComparatorChain
+ * @param reverse false = forward sort; true = reverse sort
+ */
+ public ComparatorChain(final Comparator comparator, final boolean reverse) {
+ comparatorChain = new ArrayList<>(1);
+ comparatorChain.add(comparator);
+ orderingBits = new BitSet(1);
+ if (reverse == true) {
+ orderingBits.set(0);
+ }
+ }
+
+ /**
+ * Construct a ComparatorChain from the Comparators in the List. All Comparators will default to
+ * the forward sort order.
+ *
+ * @param list List of Comparators
+ * @see #ComparatorChain(List,BitSet)
+ */
+ public ComparatorChain(final List> list) {
+ this(list, new BitSet(list.size()));
+ }
+
+ /**
+ * Construct a ComparatorChain from the Comparators in the given List. The sort order of each
+ * column will be drawn from the given BitSet. When determining the sort order for Comparator at
+ * index i in the List, the ComparatorChain will call BitSet.get(i). If that method
+ * returns false, the forward sort order is used; a return value of true indicates
+ * reverse sort order.
+ *
+ * @param list List of Comparators. NOTE: This constructor does not perform a defensive copy of
+ * the list
+ * @param bits Sort order for each Comparator. Extra bits are ignored, unless extra Comparators
+ * are added by another method.
+ */
+ public ComparatorChain(final List> list, final BitSet bits) {
+ comparatorChain = list;
+ orderingBits = bits;
+ }
+
+ // -----------------------------------------------------------------------
+ /**
+ * Add a Comparator to the end of the chain using the forward sort order
+ *
+ * @param comparator Comparator with the forward sort order
+ */
+ public void addComparator(final Comparator comparator) {
+ addComparator(comparator, false);
+ }
+
+ /**
+ * Add a Comparator to the end of the chain using the given sort order
+ *
+ * @param comparator Comparator to add to the end of the chain
+ * @param reverse false = forward sort order; true = reverse sort order
+ */
+ public void addComparator(final Comparator comparator, final boolean reverse) {
+ checkLocked();
+
+ comparatorChain.add(comparator);
+ if (reverse == true) {
+ orderingBits.set(comparatorChain.size() - 1);
+ }
+ }
+
+ /**
+ * Replace the Comparator at the given index, maintaining the existing sort order.
+ *
+ * @param index index of the Comparator to replace
+ * @param comparator Comparator to place at the given index
+ * @throws IndexOutOfBoundsException if index < 0 or index >= size()
+ */
+ public void setComparator(final int index, final Comparator comparator)
+ throws IndexOutOfBoundsException {
+ setComparator(index, comparator, false);
+ }
+
+ /**
+ * Replace the Comparator at the given index in the ComparatorChain, using the given sort order
+ *
+ * @param index index of the Comparator to replace
+ * @param comparator Comparator to set
+ * @param reverse false = forward sort order; true = reverse sort order
+ */
+ public void setComparator(
+ final int index, final Comparator comparator, final boolean reverse) {
+ checkLocked();
+
+ comparatorChain.set(index, comparator);
+ if (reverse == true) {
+ orderingBits.set(index);
+ } else {
+ orderingBits.clear(index);
+ }
+ }
+
+ /**
+ * Change the sort order at the given index in the ComparatorChain to a forward sort.
+ *
+ * @param index Index of the ComparatorChain
+ */
+ public void setForwardSort(final int index) {
+ checkLocked();
+ orderingBits.clear(index);
+ }
+
+ /**
+ * Change the sort order at the given index in the ComparatorChain to a reverse sort.
+ *
+ * @param index Index of the ComparatorChain
+ */
+ public void setReverseSort(final int index) {
+ checkLocked();
+ orderingBits.set(index);
+ }
+
+ /**
+ * Number of Comparators in the current ComparatorChain.
+ *
+ * @return Comparator count
+ */
+ public int size() {
+ return comparatorChain.size();
+ }
+
+ /**
+ * Determine if modifications can still be made to the ComparatorChain. ComparatorChains cannot be
+ * modified once they have performed a comparison.
+ *
+ * @return true = ComparatorChain cannot be modified; false = ComparatorChain can still be
+ * modified.
+ */
+ public boolean isLocked() {
+ return isLocked;
+ }
+
+ /**
+ * Throws an exception if the {@link ComparatorChain} is locked.
+ *
+ * @throws UnsupportedOperationException if the {@link ComparatorChain} is locked
+ */
+ private void checkLocked() {
+ if (isLocked == true) {
+ throw new UnsupportedOperationException(
+ "Comparator ordering cannot be changed after the first comparison is performed");
+ }
+ }
+
+ /**
+ * Throws an exception if the {@link ComparatorChain} is empty.
+ *
+ * @throws UnsupportedOperationException if the {@link ComparatorChain} is empty
+ */
+ private void checkChainIntegrity() {
+ if (comparatorChain.size() == 0) {
+ throw new UnsupportedOperationException(
+ "ComparatorChains must contain at least one Comparator");
+ }
+ }
+
+ // -----------------------------------------------------------------------
+ /**
+ * Perform comparisons on the Objects as per Comparator.compare(o1,o2).
+ *
+ * @param o1 the first object to compare
+ * @param o2 the second object to compare
+ * @return -1, 0, or 1
+ * @throws UnsupportedOperationException if the ComparatorChain does not contain at least one
+ * Comparator
+ */
+ @Override
+ public int compare(final E o1, final E o2) throws UnsupportedOperationException {
+ if (isLocked == false) {
+ checkChainIntegrity();
+ isLocked = true;
+ }
+
+ // iterate over all comparators in the chain
+ final Iterator> comparators = comparatorChain.iterator();
+ for (int comparatorIndex = 0; comparators.hasNext(); ++comparatorIndex) {
+
+ final Comparator super E> comparator = comparators.next();
+ int retval = comparator.compare(o1, o2);
+ if (retval != 0) {
+ // invert the order if it is a reverse sort
+ if (orderingBits.get(comparatorIndex) == true) {
+ if (retval > 0) {
+ retval = -1;
+ } else {
+ retval = 1;
+ }
+ }
+ return retval;
+ }
+ }
+
+ // if comparators are exhausted, return 0
+ return 0;
+ }
+
+ // -----------------------------------------------------------------------
+ /**
+ * Implement a hash code for this comparator that is consistent with {@link #equals(Object)
+ * equals}.
+ *
+ * @return a suitable hash code
+ * @since 3.0
+ */
+ @Override
+ public int hashCode() {
+ int hash = 0;
+ if (null != comparatorChain) {
+ hash ^= comparatorChain.hashCode();
+ }
+ if (null != orderingBits) {
+ hash ^= orderingBits.hashCode();
+ }
+ return hash;
+ }
+
+ /**
+ * Returns true iff that Object is is a {@link Comparator} whose ordering is
+ * known to be equivalent to mine.
+ *
+ *
This implementation returns true iff
+ * object.{@link Object#getClass() getClass()} equals this.getClass(),
+ * and the underlying comparators and order bits are equal. Subclasses may want to override this
+ * behavior to remain consistent with the {@link Comparator#equals(Object)} contract.
+ *
+ * @param object the object to compare with
+ * @return true if equal
+ * @since 3.0
+ */
+ @Override
+ public boolean equals(final Object object) {
+ if (this == object) {
+ return true;
+ }
+ if (null == object) {
+ return false;
+ }
+ if (object.getClass().equals(this.getClass())) {
+ final ComparatorChain> chain = (ComparatorChain>) object;
+ return (null == orderingBits
+ ? null == chain.orderingBits
+ : orderingBits.equals(chain.orderingBits))
+ && (null == comparatorChain
+ ? null == chain.comparatorChain
+ : comparatorChain.equals(chain.comparatorChain));
+ }
+ return false;
+ }
+}
diff --git a/java/tsfile/src/main/java/org/apache/commons/collections4/iterators/AbstractEmptyIterator.java b/java/tsfile/src/main/java/org/apache/commons/collections4/iterators/AbstractEmptyIterator.java
new file mode 100644
index 000000000..b16d8b4a8
--- /dev/null
+++ b/java/tsfile/src/main/java/org/apache/commons/collections4/iterators/AbstractEmptyIterator.java
@@ -0,0 +1,72 @@
+/*
+ * 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.commons.collections4.iterators;
+
+import java.util.NoSuchElementException;
+
+/**
+ * Provides an implementation of an empty iterator.
+ *
+ * @since 3.1
+ */
+abstract class AbstractEmptyIterator {
+
+ /** Constructor. */
+ protected AbstractEmptyIterator() {
+ super();
+ }
+
+ public boolean hasNext() {
+ return false;
+ }
+
+ public E next() {
+ throw new NoSuchElementException("Iterator contains no elements");
+ }
+
+ public boolean hasPrevious() {
+ return false;
+ }
+
+ public E previous() {
+ throw new NoSuchElementException("Iterator contains no elements");
+ }
+
+ public int nextIndex() {
+ return 0;
+ }
+
+ public int previousIndex() {
+ return -1;
+ }
+
+ public void add(final E obj) {
+ throw new UnsupportedOperationException("add() not supported for empty Iterator");
+ }
+
+ public void set(final E obj) {
+ throw new IllegalStateException("Iterator contains no elements");
+ }
+
+ public void remove() {
+ throw new IllegalStateException("Iterator contains no elements");
+ }
+
+ public void reset() {
+ // do nothing
+ }
+}
diff --git a/java/tsfile/src/main/java/org/apache/commons/collections4/iterators/AbstractEmptyMapIterator.java b/java/tsfile/src/main/java/org/apache/commons/collections4/iterators/AbstractEmptyMapIterator.java
new file mode 100644
index 000000000..cb9b0b604
--- /dev/null
+++ b/java/tsfile/src/main/java/org/apache/commons/collections4/iterators/AbstractEmptyMapIterator.java
@@ -0,0 +1,44 @@
+/*
+ * 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.commons.collections4.iterators;
+
+/**
+ * Provides an implementation of an empty map iterator.
+ *
+ * @param the type of keys
+ * @param the type of mapped values
+ * @since 4.0
+ */
+public abstract class AbstractEmptyMapIterator extends AbstractEmptyIterator {
+
+ /** Create a new AbstractEmptyMapIterator. */
+ public AbstractEmptyMapIterator() {
+ super();
+ }
+
+ public K getKey() {
+ throw new IllegalStateException("Iterator contains no elements");
+ }
+
+ public V getValue() {
+ throw new IllegalStateException("Iterator contains no elements");
+ }
+
+ public V setValue(final V value) {
+ throw new IllegalStateException("Iterator contains no elements");
+ }
+}
diff --git a/java/tsfile/src/main/java/org/apache/commons/collections4/iterators/EmptyIterator.java b/java/tsfile/src/main/java/org/apache/commons/collections4/iterators/EmptyIterator.java
new file mode 100644
index 000000000..1342809e2
--- /dev/null
+++ b/java/tsfile/src/main/java/org/apache/commons/collections4/iterators/EmptyIterator.java
@@ -0,0 +1,74 @@
+/*
+ * 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.commons.collections4.iterators;
+
+import org.apache.commons.collections4.ResettableIterator;
+
+import java.util.Iterator;
+
+/**
+ * Provides an implementation of an empty iterator.
+ *
+ *
This class provides an implementation of an empty iterator. This class provides for binary
+ * compatibility between Commons Collections 2.1.1 and 3.1 due to issues with IteratorUtils
+ * .
+ *
+ * @since 2.1.1 and 3.1
+ */
+public class EmptyIterator extends AbstractEmptyIterator implements ResettableIterator {
+
+ /**
+ * Singleton instance of the iterator.
+ *
+ * @since 3.1
+ */
+ @SuppressWarnings("rawtypes")
+ public static final ResettableIterator RESETTABLE_INSTANCE = new EmptyIterator<>();
+
+ /**
+ * Singleton instance of the iterator.
+ *
+ * @since 2.1.1 and 3.1
+ */
+ @SuppressWarnings("rawtypes")
+ public static final Iterator INSTANCE = RESETTABLE_INSTANCE;
+
+ /**
+ * Get a typed resettable empty iterator instance.
+ *
+ * @param the element type
+ * @return ResettableIterator<E>
+ */
+ public static ResettableIterator resettableEmptyIterator() {
+ return RESETTABLE_INSTANCE;
+ }
+
+ /**
+ * Get a typed empty iterator instance.
+ *
+ * @param the element type
+ * @return Iterator<E>
+ */
+ public static Iterator emptyIterator() {
+ return INSTANCE;
+ }
+
+ /** Constructor. */
+ protected EmptyIterator() {
+ super();
+ }
+}
diff --git a/java/tsfile/src/main/java/org/apache/commons/collections4/iterators/EmptyMapIterator.java b/java/tsfile/src/main/java/org/apache/commons/collections4/iterators/EmptyMapIterator.java
new file mode 100644
index 000000000..18acaace4
--- /dev/null
+++ b/java/tsfile/src/main/java/org/apache/commons/collections4/iterators/EmptyMapIterator.java
@@ -0,0 +1,55 @@
+/*
+ * 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.commons.collections4.iterators;
+
+import org.apache.commons.collections4.MapIterator;
+import org.apache.commons.collections4.ResettableIterator;
+
+/**
+ * Provides an implementation of an empty map iterator.
+ *
+ * @param the type of keys
+ * @param the type of mapped values
+ * @since 3.1
+ */
+public class EmptyMapIterator extends AbstractEmptyMapIterator
+ implements MapIterator, ResettableIterator {
+
+ /**
+ * Singleton instance of the iterator.
+ *
+ * @since 3.1
+ */
+ @SuppressWarnings("rawtypes")
+ public static final MapIterator INSTANCE = new EmptyMapIterator<>();
+
+ /**
+ * Get a typed instance of the iterator.
+ *
+ * @param the key type
+ * @param the value type
+ * @return {@link MapIterator}<K, V>
+ */
+ public static MapIterator emptyMapIterator() {
+ return INSTANCE;
+ }
+
+ /** Constructor. */
+ protected EmptyMapIterator() {
+ super();
+ }
+}
diff --git a/java/tsfile/src/main/java/org/apache/commons/collections4/iterators/EmptyOrderedIterator.java b/java/tsfile/src/main/java/org/apache/commons/collections4/iterators/EmptyOrderedIterator.java
new file mode 100644
index 000000000..90582e208
--- /dev/null
+++ b/java/tsfile/src/main/java/org/apache/commons/collections4/iterators/EmptyOrderedIterator.java
@@ -0,0 +1,53 @@
+/*
+ * 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.commons.collections4.iterators;
+
+import org.apache.commons.collections4.OrderedIterator;
+import org.apache.commons.collections4.ResettableIterator;
+
+/**
+ * Provides an implementation of an empty ordered iterator.
+ *
+ * @param the type to iterate.
+ * @since 3.1
+ */
+public class EmptyOrderedIterator extends AbstractEmptyIterator
+ implements OrderedIterator, ResettableIterator {
+
+ /**
+ * Singleton instance of the iterator.
+ *
+ * @since 3.1
+ */
+ @SuppressWarnings("rawtypes")
+ public static final OrderedIterator INSTANCE = new EmptyOrderedIterator<>();
+
+ /**
+ * Typed instance of the iterator.
+ *
+ * @param the element type
+ * @return OrderedIterator<E>
+ */
+ public static OrderedIterator emptyOrderedIterator() {
+ return INSTANCE;
+ }
+
+ /** Constructor. */
+ protected EmptyOrderedIterator() {
+ super();
+ }
+}
diff --git a/java/tsfile/src/main/java/org/apache/commons/collections4/iterators/EmptyOrderedMapIterator.java b/java/tsfile/src/main/java/org/apache/commons/collections4/iterators/EmptyOrderedMapIterator.java
new file mode 100644
index 000000000..9a3682e18
--- /dev/null
+++ b/java/tsfile/src/main/java/org/apache/commons/collections4/iterators/EmptyOrderedMapIterator.java
@@ -0,0 +1,55 @@
+/*
+ * 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.commons.collections4.iterators;
+
+import org.apache.commons.collections4.OrderedMapIterator;
+import org.apache.commons.collections4.ResettableIterator;
+
+/**
+ * Provides an implementation of an empty ordered map iterator.
+ *
+ * @param the type of keys
+ * @param the type of mapped values
+ * @since 3.1
+ */
+public class EmptyOrderedMapIterator extends AbstractEmptyMapIterator
+ implements OrderedMapIterator, ResettableIterator {
+
+ /**
+ * Singleton instance of the iterator.
+ *
+ * @since 3.1
+ */
+ @SuppressWarnings("rawtypes")
+ public static final OrderedMapIterator INSTANCE = new EmptyOrderedMapIterator<>();
+
+ /**
+ * Get a typed instance of the iterator.
+ *
+ * @param the key type
+ * @param the value type
+ * @return {@link OrderedMapIterator}<K, V>
+ */
+ public static OrderedMapIterator emptyOrderedMapIterator() {
+ return INSTANCE;
+ }
+
+ /** Constructor. */
+ protected EmptyOrderedMapIterator() {
+ super();
+ }
+}
diff --git a/java/tsfile/src/main/java/org/apache/commons/collections4/map/AbstractHashedMap.java b/java/tsfile/src/main/java/org/apache/commons/collections4/map/AbstractHashedMap.java
new file mode 100644
index 000000000..a3e9a1454
--- /dev/null
+++ b/java/tsfile/src/main/java/org/apache/commons/collections4/map/AbstractHashedMap.java
@@ -0,0 +1,1394 @@
+/*
+ * 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.commons.collections4.map;
+
+import org.apache.commons.collections4.IterableMap;
+import org.apache.commons.collections4.KeyValue;
+import org.apache.commons.collections4.MapIterator;
+import org.apache.commons.collections4.iterators.EmptyIterator;
+import org.apache.commons.collections4.iterators.EmptyMapIterator;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.AbstractCollection;
+import java.util.AbstractMap;
+import java.util.AbstractSet;
+import java.util.Collection;
+import java.util.ConcurrentModificationException;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.Set;
+
+/**
+ * An abstract implementation of a hash-based map which provides numerous points for subclasses to
+ * override.
+ *
+ *
This class implements all the features necessary for a subclass hash-based map. Key-value
+ * entries are stored in instances of the HashEntry class, which can be overridden and
+ * replaced. The iterators can similarly be replaced, without the need to replace the KeySet,
+ * EntrySet and Values view classes.
+ *
+ *
Overridable methods are provided to change the default hashing behaviour, and to change how
+ * entries are added to and removed from the map. Hopefully, all you need for unusual subclasses is
+ * here.
+ *
+ *
NOTE: From Commons Collections 3.1 this class extends AbstractMap. This is to provide
+ * backwards compatibility for ReferenceMap between v3.0 and v3.1. This extends clause will be
+ * removed in v5.0.
+ *
+ * @param the type of the keys in this map
+ * @param the type of the values in this map
+ * @since 3.0
+ */
+public class AbstractHashedMap extends AbstractMap implements IterableMap {
+
+ protected static final String NO_NEXT_ENTRY = "No next() entry in the iteration";
+ protected static final String NO_PREVIOUS_ENTRY = "No previous() entry in the iteration";
+ protected static final String REMOVE_INVALID = "remove() can only be called once after next()";
+ protected static final String GETKEY_INVALID =
+ "getKey() can only be called after next() and before remove()";
+ protected static final String GETVALUE_INVALID =
+ "getValue() can only be called after next() and before remove()";
+ protected static final String SETVALUE_INVALID =
+ "setValue() can only be called after next() and before remove()";
+
+ /** The default capacity to use */
+ protected static final int DEFAULT_CAPACITY = 16;
+
+ /** The default threshold to use */
+ protected static final int DEFAULT_THRESHOLD = 12;
+
+ /** The default load factor to use */
+ protected static final float DEFAULT_LOAD_FACTOR = 0.75f;
+
+ /** The maximum capacity allowed */
+ protected static final int MAXIMUM_CAPACITY = 1 << 30;
+
+ /** An object for masking null */
+ protected static final Object NULL = new Object();
+
+ /** Load factor, normally 0.75 */
+ transient float loadFactor;
+
+ /** The size of the map */
+ transient int size;
+
+ /** Map entries */
+ transient HashEntry[] data;
+
+ /** Size at which to rehash */
+ transient int threshold;
+
+ /** Modification count for iterators */
+ transient int modCount;
+
+ /** Entry set */
+ transient EntrySet entrySet;
+
+ /** Key set */
+ transient KeySet keySet;
+
+ /** Values */
+ transient Values values;
+
+ /** Constructor only used in deserialization, do not use otherwise. */
+ protected AbstractHashedMap() {
+ super();
+ }
+
+ /**
+ * Constructor which performs no validation on the passed in parameters.
+ *
+ * @param initialCapacity the initial capacity, must be a power of two
+ * @param loadFactor the load factor, must be > 0.0f and generally < 1.0f
+ * @param threshold the threshold, must be sensible
+ */
+ @SuppressWarnings("unchecked")
+ protected AbstractHashedMap(
+ final int initialCapacity, final float loadFactor, final int threshold) {
+ super();
+ this.loadFactor = loadFactor;
+ this.data = new HashEntry[initialCapacity];
+ this.threshold = threshold;
+ init();
+ }
+
+ /**
+ * Constructs a new, empty map with the specified initial capacity and default load factor.
+ *
+ * @param initialCapacity the initial capacity
+ * @throws IllegalArgumentException if the initial capacity is negative
+ */
+ protected AbstractHashedMap(final int initialCapacity) {
+ this(initialCapacity, DEFAULT_LOAD_FACTOR);
+ }
+
+ /**
+ * Constructs a new, empty map with the specified initial capacity and load factor.
+ *
+ * @param initialCapacity the initial capacity
+ * @param loadFactor the load factor
+ * @throws IllegalArgumentException if the initial capacity is negative
+ * @throws IllegalArgumentException if the load factor is less than or equal to zero
+ */
+ @SuppressWarnings("unchecked")
+ protected AbstractHashedMap(int initialCapacity, final float loadFactor) {
+ super();
+ if (initialCapacity < 0) {
+ throw new IllegalArgumentException("Initial capacity must be a non negative number");
+ }
+ if (loadFactor <= 0.0f || Float.isNaN(loadFactor)) {
+ throw new IllegalArgumentException("Load factor must be greater than 0");
+ }
+ this.loadFactor = loadFactor;
+ initialCapacity = calculateNewCapacity(initialCapacity);
+ this.threshold = calculateThreshold(initialCapacity, loadFactor);
+ this.data = new HashEntry[initialCapacity];
+ init();
+ }
+
+ /**
+ * Constructor copying elements from another map.
+ *
+ * @param map the map to copy
+ * @throws NullPointerException if the map is null
+ */
+ protected AbstractHashedMap(final Map extends K, ? extends V> map) {
+ this(Math.max(2 * map.size(), DEFAULT_CAPACITY), DEFAULT_LOAD_FACTOR);
+ _putAll(map);
+ }
+
+ /** Initialise subclasses during construction, cloning or deserialization. */
+ protected void init() {}
+
+ // -----------------------------------------------------------------------
+ /**
+ * Gets the value mapped to the key specified.
+ *
+ * @param key the key
+ * @return the mapped value, null if no match
+ */
+ @Override
+ public V get(Object key) {
+ key = convertKey(key);
+ final int hashCode = hash(key);
+ HashEntry entry = data[hashIndex(hashCode, data.length)]; // no local for hash index
+ while (entry != null) {
+ if (entry.hashCode == hashCode && isEqualKey(key, entry.key)) {
+ return entry.getValue();
+ }
+ entry = entry.next;
+ }
+ return null;
+ }
+
+ /**
+ * Gets the size of the map.
+ *
+ * @return the size
+ */
+ @Override
+ public int size() {
+ return size;
+ }
+
+ /**
+ * Checks whether the map is currently empty.
+ *
+ * @return true if the map is currently size zero
+ */
+ @Override
+ public boolean isEmpty() {
+ return size == 0;
+ }
+
+ // -----------------------------------------------------------------------
+ /**
+ * Checks whether the map contains the specified key.
+ *
+ * @param key the key to search for
+ * @return true if the map contains the key
+ */
+ @Override
+ public boolean containsKey(Object key) {
+ key = convertKey(key);
+ final int hashCode = hash(key);
+ HashEntry entry = data[hashIndex(hashCode, data.length)]; // no local for hash index
+ while (entry != null) {
+ if (entry.hashCode == hashCode && isEqualKey(key, entry.key)) {
+ return true;
+ }
+ entry = entry.next;
+ }
+ return false;
+ }
+
+ /**
+ * Checks whether the map contains the specified value.
+ *
+ * @param value the value to search for
+ * @return true if the map contains the value
+ */
+ @Override
+ public boolean containsValue(final Object value) {
+ if (value == null) {
+ for (final HashEntry element : data) {
+ HashEntry entry = element;
+ while (entry != null) {
+ if (entry.getValue() == null) {
+ return true;
+ }
+ entry = entry.next;
+ }
+ }
+ } else {
+ for (final HashEntry element : data) {
+ HashEntry entry = element;
+ while (entry != null) {
+ if (isEqualValue(value, entry.getValue())) {
+ return true;
+ }
+ entry = entry.next;
+ }
+ }
+ }
+ return false;
+ }
+
+ // -----------------------------------------------------------------------
+ /**
+ * Puts a key-value mapping into this map.
+ *
+ * @param key the key to add
+ * @param value the value to add
+ * @return the value previously mapped to this key, null if none
+ */
+ @Override
+ public V put(final K key, final V value) {
+ final Object convertedKey = convertKey(key);
+ final int hashCode = hash(convertedKey);
+ final int index = hashIndex(hashCode, data.length);
+ HashEntry entry = data[index];
+ while (entry != null) {
+ if (entry.hashCode == hashCode && isEqualKey(convertedKey, entry.key)) {
+ final V oldValue = entry.getValue();
+ updateEntry(entry, value);
+ return oldValue;
+ }
+ entry = entry.next;
+ }
+
+ addMapping(index, hashCode, key, value);
+ return null;
+ }
+
+ /**
+ * Puts all the values from the specified map into this map.
+ *
+ *
This implementation iterates around the specified map and uses {@link #put(Object, Object)}.
+ *
+ * @param map the map to add
+ * @throws NullPointerException if the map is null
+ */
+ @Override
+ public void putAll(final Map extends K, ? extends V> map) {
+ _putAll(map);
+ }
+
+ /**
+ * Puts all the values from the specified map into this map.
+ *
+ *
This implementation iterates around the specified map and uses {@link #put(Object, Object)}.
+ *
+ *
It is private to allow the constructor to still call it even when putAll is overriden.
+ *
+ * @param map the map to add
+ * @throws NullPointerException if the map is null
+ */
+ private void _putAll(final Map extends K, ? extends V> map) {
+ final int mapSize = map.size();
+ if (mapSize == 0) {
+ return;
+ }
+ final int newSize = (int) ((size + mapSize) / loadFactor + 1);
+ ensureCapacity(calculateNewCapacity(newSize));
+ for (final Map.Entry extends K, ? extends V> entry : map.entrySet()) {
+ put(entry.getKey(), entry.getValue());
+ }
+ }
+
+ /**
+ * Removes the specified mapping from this map.
+ *
+ * @param key the mapping to remove
+ * @return the value mapped to the removed key, null if key not in map
+ */
+ @Override
+ public V remove(Object key) {
+ key = convertKey(key);
+ final int hashCode = hash(key);
+ final int index = hashIndex(hashCode, data.length);
+ HashEntry entry = data[index];
+ HashEntry previous = null;
+ while (entry != null) {
+ if (entry.hashCode == hashCode && isEqualKey(key, entry.key)) {
+ final V oldValue = entry.getValue();
+ removeMapping(entry, index, previous);
+ return oldValue;
+ }
+ previous = entry;
+ entry = entry.next;
+ }
+ return null;
+ }
+
+ /**
+ * Clears the map, resetting the size to zero and nullifying references to avoid garbage
+ * collection issues.
+ */
+ @Override
+ public void clear() {
+ modCount++;
+ final HashEntry[] data = this.data;
+ for (int i = data.length - 1; i >= 0; i--) {
+ data[i] = null;
+ }
+ size = 0;
+ }
+
+ // -----------------------------------------------------------------------
+ /**
+ * Converts input keys to another object for storage in the map. This implementation masks nulls.
+ * Subclasses can override this to perform alternate key conversions.
+ *
+ *
The reverse conversion can be changed, if required, by overriding the getKey() method in the
+ * hash entry.
+ *
+ * @param key the key convert
+ * @return the converted key
+ */
+ protected Object convertKey(final Object key) {
+ return key == null ? NULL : key;
+ }
+
+ /**
+ * Gets the hash code for the key specified. This implementation uses the additional hashing
+ * routine from JDK1.4. Subclasses can override this to return alternate hash codes.
+ *
+ * @param key the key to get a hash code for
+ * @return the hash code
+ */
+ protected int hash(final Object key) {
+ // same as JDK 1.4
+ int h = key.hashCode();
+ h += ~(h << 9);
+ h ^= h >>> 14;
+ h += h << 4;
+ h ^= h >>> 10;
+ return h;
+ }
+
+ /**
+ * Compares two keys, in internal converted form, to see if they are equal. This implementation
+ * uses the equals method and assumes neither key is null. Subclasses can override this to match
+ * differently.
+ *
+ * @param key1 the first key to compare passed in from outside
+ * @param key2 the second key extracted from the entry via entry.key
+ * @return true if equal
+ */
+ protected boolean isEqualKey(final Object key1, final Object key2) {
+ return key1 == key2 || key1.equals(key2);
+ }
+
+ /**
+ * Compares two values, in external form, to see if they are equal. This implementation uses the
+ * equals method and assumes neither value is null. Subclasses can override this to match
+ * differently.
+ *
+ * @param value1 the first value to compare passed in from outside
+ * @param value2 the second value extracted from the entry via getValue()
+ * @return true if equal
+ */
+ protected boolean isEqualValue(final Object value1, final Object value2) {
+ return value1 == value2 || value1.equals(value2);
+ }
+
+ /**
+ * Gets the index into the data storage for the hashCode specified. This implementation uses the
+ * least significant bits of the hashCode. Subclasses can override this to return alternate
+ * bucketing.
+ *
+ * @param hashCode the hash code to use
+ * @param dataSize the size of the data to pick a bucket from
+ * @return the bucket index
+ */
+ protected int hashIndex(final int hashCode, final int dataSize) {
+ return hashCode & dataSize - 1;
+ }
+
+ // -----------------------------------------------------------------------
+ /**
+ * Gets the entry mapped to the key specified.
+ *
+ *
This method exists for subclasses that may need to perform a multi-step process accessing
+ * the entry. The public methods in this class don't use this method to gain a small performance
+ * boost.
+ *
+ * @param key the key
+ * @return the entry, null if no match
+ */
+ protected HashEntry getEntry(Object key) {
+ key = convertKey(key);
+ final int hashCode = hash(key);
+ HashEntry entry = data[hashIndex(hashCode, data.length)]; // no local for hash index
+ while (entry != null) {
+ if (entry.hashCode == hashCode && isEqualKey(key, entry.key)) {
+ return entry;
+ }
+ entry = entry.next;
+ }
+ return null;
+ }
+
+ // -----------------------------------------------------------------------
+ /**
+ * Updates an existing key-value mapping to change the value.
+ *
+ *
This implementation calls setValue() on the entry. Subclasses could override to
+ * handle changes to the map.
+ *
+ * @param entry the entry to update
+ * @param newValue the new value to store
+ */
+ protected void updateEntry(final HashEntry entry, final V newValue) {
+ entry.setValue(newValue);
+ }
+
+ /**
+ * Reuses an existing key-value mapping, storing completely new data.
+ *
+ *
This implementation sets all the data fields on the entry. Subclasses could populate
+ * additional entry fields.
+ *
+ * @param entry the entry to update, not null
+ * @param hashIndex the index in the data array
+ * @param hashCode the hash code of the key to add
+ * @param key the key to add
+ * @param value the value to add
+ */
+ protected void reuseEntry(
+ final HashEntry entry,
+ final int hashIndex,
+ final int hashCode,
+ final K key,
+ final V value) {
+ entry.next = data[hashIndex];
+ entry.hashCode = hashCode;
+ entry.key = key;
+ entry.value = value;
+ }
+
+ // -----------------------------------------------------------------------
+ /**
+ * Adds a new key-value mapping into this map.
+ *
+ *
This implementation calls createEntry(), addEntry() and
+ * checkCapacity(). It also handles changes to modCount and size.
+ * Subclasses could override to fully control adds to the map.
+ *
+ * @param hashIndex the index into the data array to store at
+ * @param hashCode the hash code of the key to add
+ * @param key the key to add
+ * @param value the value to add
+ */
+ protected void addMapping(final int hashIndex, final int hashCode, final K key, final V value) {
+ modCount++;
+ final HashEntry entry = createEntry(data[hashIndex], hashCode, key, value);
+ addEntry(entry, hashIndex);
+ size++;
+ checkCapacity();
+ }
+
+ /**
+ * Creates an entry to store the key-value data.
+ *
+ *
This implementation creates a new HashEntry instance. Subclasses can override this to return
+ * a different storage class, or implement caching.
+ *
+ * @param next the next entry in sequence
+ * @param hashCode the hash code to use
+ * @param key the key to store
+ * @param value the value to store
+ * @return the newly created entry
+ */
+ protected HashEntry createEntry(
+ final HashEntry next, final int hashCode, final K key, final V value) {
+ return new HashEntry<>(next, hashCode, convertKey(key), value);
+ }
+
+ /**
+ * Adds an entry into this map.
+ *
+ *
This implementation adds the entry to the data storage table. Subclasses could override to
+ * handle changes to the map.
+ *
+ * @param entry the entry to add
+ * @param hashIndex the index into the data array to store at
+ */
+ protected void addEntry(final HashEntry entry, final int hashIndex) {
+ data[hashIndex] = entry;
+ }
+
+ // -----------------------------------------------------------------------
+ /**
+ * Removes a mapping from the map.
+ *
+ *
This implementation calls removeEntry() and destroyEntry(). It
+ * also handles changes to modCount and size. Subclasses could override
+ * to fully control removals from the map.
+ *
+ * @param entry the entry to remove
+ * @param hashIndex the index into the data structure
+ * @param previous the previous entry in the chain
+ */
+ protected void removeMapping(
+ final HashEntry entry, final int hashIndex, final HashEntry previous) {
+ modCount++;
+ removeEntry(entry, hashIndex, previous);
+ size--;
+ destroyEntry(entry);
+ }
+
+ /**
+ * Removes an entry from the chain stored in a particular index.
+ *
+ *
This implementation removes the entry from the data storage table. The size is not updated.
+ * Subclasses could override to handle changes to the map.
+ *
+ * @param entry the entry to remove
+ * @param hashIndex the index into the data structure
+ * @param previous the previous entry in the chain
+ */
+ protected void removeEntry(
+ final HashEntry entry, final int hashIndex, final HashEntry previous) {
+ if (previous == null) {
+ data[hashIndex] = entry.next;
+ } else {
+ previous.next = entry.next;
+ }
+ }
+
+ /**
+ * Kills an entry ready for the garbage collector.
+ *
+ *
This implementation prepares the HashEntry for garbage collection. Subclasses can override
+ * this to implement caching (override clear as well).
+ *
+ * @param entry the entry to destroy
+ */
+ protected void destroyEntry(final HashEntry entry) {
+ entry.next = null;
+ entry.key = null;
+ entry.value = null;
+ }
+
+ // -----------------------------------------------------------------------
+ /**
+ * Checks the capacity of the map and enlarges it if necessary.
+ *
+ *
This implementation uses the threshold to check if the map needs enlarging
+ */
+ protected void checkCapacity() {
+ if (size >= threshold) {
+ final int newCapacity = data.length * 2;
+ if (newCapacity <= MAXIMUM_CAPACITY) {
+ ensureCapacity(newCapacity);
+ }
+ }
+ }
+
+ /**
+ * Changes the size of the data structure to the capacity proposed.
+ *
+ * @param newCapacity the new capacity of the array (a power of two, less or equal to max)
+ */
+ @SuppressWarnings("unchecked")
+ protected void ensureCapacity(final int newCapacity) {
+ final int oldCapacity = data.length;
+ if (newCapacity <= oldCapacity) {
+ return;
+ }
+ if (size == 0) {
+ threshold = calculateThreshold(newCapacity, loadFactor);
+ data = new HashEntry[newCapacity];
+ } else {
+ final HashEntry oldEntries[] = data;
+ final HashEntry newEntries[] = new HashEntry[newCapacity];
+
+ modCount++;
+ for (int i = oldCapacity - 1; i >= 0; i--) {
+ HashEntry entry = oldEntries[i];
+ if (entry != null) {
+ oldEntries[i] = null; // gc
+ do {
+ final HashEntry next = entry.next;
+ final int index = hashIndex(entry.hashCode, newCapacity);
+ entry.next = newEntries[index];
+ newEntries[index] = entry;
+ entry = next;
+ } while (entry != null);
+ }
+ }
+ threshold = calculateThreshold(newCapacity, loadFactor);
+ data = newEntries;
+ }
+ }
+
+ /**
+ * Calculates the new capacity of the map. This implementation normalizes the capacity to a power
+ * of two.
+ *
+ * @param proposedCapacity the proposed capacity
+ * @return the normalized new capacity
+ */
+ protected int calculateNewCapacity(final int proposedCapacity) {
+ int newCapacity = 1;
+ if (proposedCapacity > MAXIMUM_CAPACITY) {
+ newCapacity = MAXIMUM_CAPACITY;
+ } else {
+ while (newCapacity < proposedCapacity) {
+ newCapacity <<= 1; // multiply by two
+ }
+ if (newCapacity > MAXIMUM_CAPACITY) {
+ newCapacity = MAXIMUM_CAPACITY;
+ }
+ }
+ return newCapacity;
+ }
+
+ /**
+ * Calculates the new threshold of the map, where it will be resized. This implementation uses the
+ * load factor.
+ *
+ * @param newCapacity the new capacity
+ * @param factor the load factor
+ * @return the new resize threshold
+ */
+ protected int calculateThreshold(final int newCapacity, final float factor) {
+ return (int) (newCapacity * factor);
+ }
+
+ // -----------------------------------------------------------------------
+ /**
+ * Gets the next field from a HashEntry. Used in subclasses that have no
+ * visibility of the field.
+ *
+ * @param entry the entry to query, must not be null
+ * @return the next field of the entry
+ * @throws NullPointerException if the entry is null
+ * @since 3.1
+ */
+ protected HashEntry entryNext(final HashEntry entry) {
+ return entry.next;
+ }
+
+ /**
+ * Gets the hashCode field from a HashEntry. Used in subclasses that
+ * have no visibility of the field.
+ *
+ * @param entry the entry to query, must not be null
+ * @return the hashCode field of the entry
+ * @throws NullPointerException if the entry is null
+ * @since 3.1
+ */
+ protected int entryHashCode(final HashEntry entry) {
+ return entry.hashCode;
+ }
+
+ /**
+ * Gets the key field from a HashEntry. Used in subclasses that have no
+ * visibility of the field.
+ *
+ * @param entry the entry to query, must not be null
+ * @return the key field of the entry
+ * @throws NullPointerException if the entry is null
+ * @since 3.1
+ */
+ protected K entryKey(final HashEntry entry) {
+ return entry.getKey();
+ }
+
+ /**
+ * Gets the value field from a HashEntry. Used in subclasses that have
+ * no visibility of the field.
+ *
+ * @param entry the entry to query, must not be null
+ * @return the value field of the entry
+ * @throws NullPointerException if the entry is null
+ * @since 3.1
+ */
+ protected V entryValue(final HashEntry entry) {
+ return entry.getValue();
+ }
+
+ // -----------------------------------------------------------------------
+ /**
+ * Gets an iterator over the map. Changes made to the iterator affect this map.
+ *
+ *
A MapIterator returns the keys in the map. It also provides convenient methods to get the
+ * key and value, and set the value. It avoids the need to create an entrySet/keySet/values
+ * object. It also avoids creating the Map.Entry object.
+ *
+ * @return the map iterator
+ */
+ @Override
+ public MapIterator mapIterator() {
+ if (size == 0) {
+ return EmptyMapIterator.emptyMapIterator();
+ }
+ return new HashMapIterator<>(this);
+ }
+
+ /** MapIterator implementation. */
+ protected static class HashMapIterator extends HashIterator
+ implements MapIterator {
+
+ protected HashMapIterator(final AbstractHashedMap parent) {
+ super(parent);
+ }
+
+ @Override
+ public K next() {
+ return super.nextEntry().getKey();
+ }
+
+ @Override
+ public K getKey() {
+ final HashEntry current = currentEntry();
+ if (current == null) {
+ throw new IllegalStateException(AbstractHashedMap.GETKEY_INVALID);
+ }
+ return current.getKey();
+ }
+
+ @Override
+ public V getValue() {
+ final HashEntry current = currentEntry();
+ if (current == null) {
+ throw new IllegalStateException(AbstractHashedMap.GETVALUE_INVALID);
+ }
+ return current.getValue();
+ }
+
+ @Override
+ public V setValue(final V value) {
+ final HashEntry current = currentEntry();
+ if (current == null) {
+ throw new IllegalStateException(AbstractHashedMap.SETVALUE_INVALID);
+ }
+ return current.setValue(value);
+ }
+ }
+
+ // -----------------------------------------------------------------------
+ /**
+ * Gets the entrySet view of the map. Changes made to the view affect this map. To simply iterate
+ * through the entries, use {@link #mapIterator()}.
+ *
+ * @return the entrySet view
+ */
+ @Override
+ public Set> entrySet() {
+ if (entrySet == null) {
+ entrySet = new EntrySet<>(this);
+ }
+ return entrySet;
+ }
+
+ /**
+ * Creates an entry set iterator. Subclasses can override this to return iterators with different
+ * properties.
+ *
+ * @return the entrySet iterator
+ */
+ protected Iterator> createEntrySetIterator() {
+ if (size() == 0) {
+ return EmptyIterator.>emptyIterator();
+ }
+ return new EntrySetIterator<>(this);
+ }
+
+ /** EntrySet implementation. */
+ protected static class EntrySet extends AbstractSet> {
+ /** The parent map */
+ private final AbstractHashedMap parent;
+
+ protected EntrySet(final AbstractHashedMap parent) {
+ super();
+ this.parent = parent;
+ }
+
+ @Override
+ public int size() {
+ return parent.size();
+ }
+
+ @Override
+ public void clear() {
+ parent.clear();
+ }
+
+ @Override
+ public boolean contains(final Object entry) {
+ if (entry instanceof Map.Entry) {
+ final Map.Entry, ?> e = (Map.Entry, ?>) entry;
+ final Entry match = parent.getEntry(e.getKey());
+ return match != null && match.equals(e);
+ }
+ return false;
+ }
+
+ @Override
+ public boolean remove(final Object obj) {
+ if (obj instanceof Map.Entry == false) {
+ return false;
+ }
+ if (contains(obj) == false) {
+ return false;
+ }
+ final Map.Entry, ?> entry = (Map.Entry, ?>) obj;
+ parent.remove(entry.getKey());
+ return true;
+ }
+
+ @Override
+ public Iterator> iterator() {
+ return parent.createEntrySetIterator();
+ }
+ }
+
+ /** EntrySet iterator. */
+ protected static class EntrySetIterator extends HashIterator
+ implements Iterator> {
+
+ protected EntrySetIterator(final AbstractHashedMap parent) {
+ super(parent);
+ }
+
+ @Override
+ public Map.Entry next() {
+ return super.nextEntry();
+ }
+ }
+
+ // -----------------------------------------------------------------------
+ /**
+ * Gets the keySet view of the map. Changes made to the view affect this map. To simply iterate
+ * through the keys, use {@link #mapIterator()}.
+ *
+ * @return the keySet view
+ */
+ @Override
+ public Set keySet() {
+ if (keySet == null) {
+ keySet = new KeySet<>(this);
+ }
+ return keySet;
+ }
+
+ /**
+ * Creates a key set iterator. Subclasses can override this to return iterators with different
+ * properties.
+ *
+ * @return the keySet iterator
+ */
+ protected Iterator createKeySetIterator() {
+ if (size() == 0) {
+ return EmptyIterator.emptyIterator();
+ }
+ return new KeySetIterator<>(this);
+ }
+
+ /** KeySet implementation. */
+ protected static class KeySet extends AbstractSet {
+ /** The parent map */
+ private final AbstractHashedMap parent;
+
+ protected KeySet(final AbstractHashedMap parent) {
+ super();
+ this.parent = parent;
+ }
+
+ @Override
+ public int size() {
+ return parent.size();
+ }
+
+ @Override
+ public void clear() {
+ parent.clear();
+ }
+
+ @Override
+ public boolean contains(final Object key) {
+ return parent.containsKey(key);
+ }
+
+ @Override
+ public boolean remove(final Object key) {
+ final boolean result = parent.containsKey(key);
+ parent.remove(key);
+ return result;
+ }
+
+ @Override
+ public Iterator iterator() {
+ return parent.createKeySetIterator();
+ }
+ }
+
+ /** KeySet iterator. */
+ protected static class KeySetIterator extends HashIterator implements Iterator {
+
+ @SuppressWarnings("unchecked")
+ protected KeySetIterator(final AbstractHashedMap parent) {
+ super((AbstractHashedMap) parent);
+ }
+
+ @Override
+ public K next() {
+ return super.nextEntry().getKey();
+ }
+ }
+
+ // -----------------------------------------------------------------------
+ /**
+ * Gets the values view of the map. Changes made to the view affect this map. To simply iterate
+ * through the values, use {@link #mapIterator()}.
+ *
+ * @return the values view
+ */
+ @Override
+ public Collection values() {
+ if (values == null) {
+ values = new Values<>(this);
+ }
+ return values;
+ }
+
+ /**
+ * Creates a values iterator. Subclasses can override this to return iterators with different
+ * properties.
+ *
+ * @return the values iterator
+ */
+ protected Iterator createValuesIterator() {
+ if (size() == 0) {
+ return EmptyIterator.emptyIterator();
+ }
+ return new ValuesIterator<>(this);
+ }
+
+ /** Values implementation. */
+ protected static class Values extends AbstractCollection {
+ /** The parent map */
+ private final AbstractHashedMap, V> parent;
+
+ protected Values(final AbstractHashedMap, V> parent) {
+ super();
+ this.parent = parent;
+ }
+
+ @Override
+ public int size() {
+ return parent.size();
+ }
+
+ @Override
+ public void clear() {
+ parent.clear();
+ }
+
+ @Override
+ public boolean contains(final Object value) {
+ return parent.containsValue(value);
+ }
+
+ @Override
+ public Iterator iterator() {
+ return parent.createValuesIterator();
+ }
+ }
+
+ /** Values iterator. */
+ protected static class ValuesIterator extends HashIterator