├── .gitignore ├── .editorconfig ├── src ├── test │ └── java │ │ └── com │ │ └── xiaoTools │ │ ├── util │ │ ├── FileUtilTest │ │ │ └── FileUtilTest.java │ │ ├── RandomUtilTest │ │ │ └── RandomUtilTest.java │ │ ├── BooleanUtilTest │ │ │ └── BooleanUtilTest.java │ │ ├── ClassLoaderUtilTest │ │ │ └── ClassLoaderUtilTest.java │ │ ├── HexUtilTest │ │ │ └── HexUtilTest.java │ │ ├── IoUtilTest │ │ │ └── IoUtilTest.java │ │ ├── PageUtilTest │ │ │ └── PageUtilTest.java │ │ ├── ArrayUtilTest │ │ │ └── ArrayUtilTest.java │ │ ├── ClassUtilTest │ │ │ └── ClassUtilTest.java │ │ ├── ObjectUtilTest │ │ │ └── ObjectUtilTest.java │ │ ├── UrlUtilTest │ │ │ └── UrlUtilTest.java │ │ ├── IdUtilTest │ │ │ └── IdUtilTest.java │ │ └── NumUtilTest │ │ │ └── NumUtilTest.java │ │ └── ConvertTest │ │ └── ConvertTest.java └── main │ └── java │ └── com │ └── xiaoTools │ ├── util │ ├── collectionUtil │ │ └── CollectionUtil.java │ ├── spliteratorUtil │ │ └── SpliteratorUtil.java │ ├── regularUtil │ │ └── method │ │ │ └── Func1.java │ ├── dataSizeUtil │ │ └── DataSizeUtil.java │ ├── serializeUtil │ │ └── SerializeUtil.java │ ├── temporalAccessorUtil │ │ └── TemporalUtil.java │ ├── modifierUtil │ │ └── modifierType │ │ │ └── ModifierType.java │ ├── resultutil │ │ └── ResultUtil.java │ ├── desensitizedUtil │ │ └── DesensitizedUtil.java │ ├── unicodeUtil │ │ └── UnicodeUtil.java │ ├── serviceLoaderUtil │ │ └── ServiceLoaderUtil.java │ └── IdUtil │ │ └── IdUtil.java │ ├── core │ ├── exception │ │ ├── IoException │ │ │ └── IoRuntimeException.java │ │ ├── beanException │ │ │ └── BeanException.java │ │ ├── comparatorException │ │ │ └── ComparatorException.java │ │ ├── dateException │ │ │ └── DateException.java │ │ ├── utilException │ │ │ └── UtilException.java │ │ ├── cLoneRuntimeException │ │ │ └── CloneRuntimeException.java │ │ ├── iORuntimeException │ │ │ └── IORuntimeException.java │ │ ├── noResourceException │ │ │ └── NoResourceException.java │ │ └── convertException │ │ │ └── ConvertException.java │ ├── filter │ │ └── Filter.java │ ├── io │ │ ├── lineSeparator │ │ │ └── LineSeparator.java │ │ ├── lineHandler │ │ │ └── LineHandler.java │ │ ├── streamProgress │ │ │ └── StreamProgress.java │ │ ├── nullOutputStream │ │ │ └── NullOutputStream.java │ │ ├── fileWrapper │ │ │ └── FileWrapper.java │ │ ├── dataUnit │ │ │ └── DataUnit.java │ │ ├── fileResource │ │ │ └── FileResource.java │ │ ├── urlResource │ │ │ └── UrlResource.java │ │ ├── validateObjectInputStream │ │ │ └── ValidateObjectInputStream.java │ │ ├── bomInputStream │ │ │ └── BOMInputStream.java │ │ ├── lineIter │ │ │ └── LineIter.java │ │ └── fastByteArrayOutputStream │ │ │ └── FastByteArrayOutputStream.java │ ├── matcher │ │ └── Matcher.java │ ├── convert │ │ ├── uUIDConverter │ │ │ └── UUIDConverter.java │ │ ├── timeZoneConverter │ │ │ └── TimeZoneConverter.java │ │ ├── currencyConverter │ │ │ └── CurrencyConverter.java │ │ ├── optionalConverter │ │ │ └── OptionalConverter.java │ │ ├── charsetConverter │ │ │ └── CharsetConverter.java │ │ ├── booleanConverter │ │ │ └── BooleanConverter.java │ │ ├── atomicLongArrayConverter │ │ │ └── AtomicLongArrayConverter.java │ │ ├── periodConverter │ │ │ └── PeriodConverter.java │ │ ├── atomicIntegerArrayConverter │ │ │ └── AtomicIntegerArrayConverter.java │ │ ├── durationConverter │ │ │ └── DurationConverter.java │ │ ├── classConverter │ │ │ └── ClassConverter.java │ │ ├── uRLConverter │ │ │ └── URLConverter.java │ │ ├── uRIConverter │ │ │ └── URIConverter.java │ │ ├── atomicBooleanConverter │ │ │ └── AtomicBooleanConverter.java │ │ ├── characterConverter │ │ │ └── CharacterConverter.java │ │ ├── converter │ │ │ └── Converter.java │ │ ├── pathConverter │ │ │ └── PathConverter.java │ │ ├── typeReference │ │ │ └── TypeReference.java │ │ ├── atomicReferenceConverter │ │ │ └── AtomicReferenceConverter.java │ │ ├── localeConverte │ │ │ └── LocaleConverter.java │ │ ├── stackTraceElementConverter │ │ │ └── StackTraceElementConverter.java │ │ ├── collectionConverter │ │ │ └── CollectionConverter.java │ │ ├── referenceConverter │ │ │ └── ReferenceConverter.java │ │ ├── calendarConverter │ │ │ └── CalendarConverter.java │ │ ├── beanConverter │ │ │ └── BeanConverter.java │ │ ├── stringConverter │ │ │ └── StringConverter.java │ │ ├── abstractConverter │ │ │ └── inherit │ │ │ │ └── OriginalRegistry.java │ │ └── mapConverter │ │ │ └── MapConverter.java │ ├── match │ │ └── Match.java │ ├── escape │ │ └── filter │ │ │ └── Filter.java │ ├── editor │ │ └── Editor.java │ ├── collection │ │ ├── consumer │ │ │ └── Consumer.java │ │ ├── kVConsumer │ │ │ └── KVConsumer.java │ │ ├── transIter │ │ │ └── TransIter.java │ │ ├── iteratorEnumeration │ │ │ └── IteratorEnumeration.java │ │ ├── copiedIter │ │ │ └── CopiedIter.java │ │ ├── enumerationIter │ │ │ └── EnumerationIter.java │ │ └── transSpliterator │ │ │ └── TransSpliterator.java │ ├── eval │ │ └── operator │ │ │ └── Operator.java │ ├── map │ │ ├── caseInsensitiveMap │ │ │ └── CaseInsensitiveMap.java │ │ ├── biMap │ │ │ └── BiMap.java │ │ ├── customKeyMap │ │ │ └── CustomKeyMap.java │ │ ├── camelCaseMap │ │ │ └── CamelCaseMap.java │ │ └── camelCaseLinkedMap │ │ │ └── CamelCaseLinkedMap.java │ ├── transCollection │ │ └── TransCollection.java │ ├── comparator │ │ └── propertyComparator │ │ │ └── PropertyComparator.java │ ├── versionComparator │ │ └── VersionComparator.java │ └── stringFormatter │ │ └── StrFormatter.java │ ├── lang │ ├── copier │ │ └── Copier.java │ ├── hash │ │ └── hash32 │ │ │ └── Hash32.java │ ├── clone │ │ ├── cLoneable │ │ │ └── Cloneable.java │ │ └── cLoneSupport │ │ │ └── CloneSupport.java │ ├── segment │ │ ├── defaultSegment │ │ │ └── DefaultSegment.java │ │ └── Segment.java │ ├── enumItem │ │ └── EnumItem.java │ ├── pair │ │ └── Pair.java │ └── parameterizedTypeImpl │ │ └── ParameterizedTypeImpl.java │ ├── annotation │ ├── alias │ │ └── Alias.java │ └── propIgnore │ │ └── PropIgnore.java │ ├── entity │ ├── mutable │ │ └── Mutable.java │ ├── valueProvider │ │ └── ValueProvider.java │ ├── dynaBeanValueProvider │ │ └── DynaBeanValueProvider.java │ ├── pinyinComparator │ │ └── PinyinComparator.java │ ├── nullWrapperEntity │ │ └── NullWrapperEntity.java │ ├── holder │ │ └── Holder.java │ ├── mutableObj │ │ └── MutableObj.java │ ├── beanValueProvider │ │ └── BeanValueProvider.java │ └── mapValueProvider │ │ └── MapValueProvider.java │ ├── thread │ └── lock │ │ └── noLock │ │ └── NoLock.java │ ├── date │ ├── quarter │ │ └── Quarter.java │ ├── leven │ │ └── Level.java │ ├── format │ │ ├── basic │ │ │ └── DateBasic.java │ │ ├── abstractDateBasic │ │ │ └── AbstractDateBasic.java │ │ ├── dateParser │ │ │ └── DateParser.java │ │ └── datePrinter │ │ │ └── DatePrinter.java │ ├── dateRange │ │ └── DateRange.java │ └── dateUnit │ │ └── DateUnit.java │ └── cache │ ├── beanDescCache │ └── BeanDescCache.java │ ├── asciiStrCache │ └── AsciiStrCache.java │ ├── simple │ └── method │ │ └── CacheFun.java │ └── beanInfoCache │ └── BeanInfoCache.java ├── .gitattributes ├── .github ├── ISSUE_TEMPLATE │ ├── QUESTION.md │ └── FEATURE_REQUEST.md └── PULL_REQUEST_TEMPLATE.md ├── README.markdown ├── CONTRIBUTING.md └── CODE_OF_CONDUCT.md /.gitignore: -------------------------------------------------------------------------------- 1 | .settings 2 | .vscode 3 | bin 4 | target 5 | .classpath 6 | .project 7 | .idea 8 | xiaoTools.iml 9 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = tab 5 | end_of_line = lf 6 | charset = utf-8 7 | indent_size=4 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | 11 | [*.md] 12 | trim_trailing_whitespace = false -------------------------------------------------------------------------------- /src/test/java/com/xiaoTools/util/FileUtilTest/FileUtilTest.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.util.FileUtilTest; 2 | 3 | import java.io.File; 4 | 5 | import com.xiaoTools.util.fileUtil.fileUtil.FileUtil; 6 | 7 | public class FileUtilTest { 8 | 9 | public void test_demo(){ 10 | File[] files = FileUtil.ls("path"); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/test/java/com/xiaoTools/util/RandomUtilTest/RandomUtilTest.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.util.RandomUtilTest; 2 | 3 | import com.xiaoTools.util.randomUtil.RandomUtil; 4 | 5 | import org.junit.Test; 6 | 7 | public class RandomUtilTest { 8 | 9 | @Test 10 | public void test_randomInt(){ 11 | // 19 12 | System.out.println(RandomUtil.randomInt(10, 100)); 13 | 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/test/java/com/xiaoTools/ConvertTest/ConvertTest.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.ConvertTest; 2 | 3 | import com.xiaoTools.core.convert.Convert; 4 | 5 | import org.junit.Test; 6 | 7 | public class ConvertTest { 8 | 9 | @Test 10 | public void test_demo(){ 11 | int a = 1; 12 | //"1" 13 | String b = Convert.toStr(a); 14 | 15 | long[] c = {1,2,3,4}; 16 | //"{1,2,3,4}" 17 | String d = Convert.toStr(c); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Normalize line endings to LF. 2 | * text eol=lf 3 | 4 | # Ensure that line endings for multipart files in spring-web are not modified. 5 | *.multipart -text 6 | 7 | # Ensure that line endings for DOS batch files are not modified. 8 | *.bat -text 9 | 10 | # Ensure the following are treated as binary. 11 | *.gif binary 12 | *.jar binary 13 | *.jpeg binary 14 | *.jpg binary 15 | *.png binary 16 | *.vsd binary 17 | -------------------------------------------------------------------------------- /src/test/java/com/xiaoTools/util/BooleanUtilTest/BooleanUtilTest.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.util.BooleanUtilTest; 2 | 3 | import com.xiaoTools.util.booleanUtil.BooleanUtil; 4 | 5 | import org.junit.Test; 6 | 7 | public class BooleanUtilTest { 8 | 9 | @Test 10 | public void test_toBoolean(){ 11 | // true 12 | boolean a = BooleanUtil.toBoolean("true"); 13 | //true 14 | boolean b = BooleanUtil.toBoolean("1"); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/QUESTION.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Question 3 | about: Question on how to use or achieve something 4 | 5 | --- 6 | 7 | **Describe what you would like to know or do** 8 | A clear and concise description of what the problem is. 9 | 10 | **Describe the solution you'd considered** 11 | A clear and concise description of any solutions you've considered. 12 | 13 | **Additional context** 14 | Add any other context or links about the question here. -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/util/collectionUtil/CollectionUtil.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.util.collectionUtil; 2 | 3 | import com.xiaoTools.util.collUtil.CollUtil; 4 | 5 | /** 6 | * [集合相关工具类](Collection related tool classes) 7 | * @description zh - 集合相关工具类 8 | * @description en - Collection related tool classes 9 | * @version V1.0 10 | * @author XiaoXunYao 11 | * @since 2021-09-20 08:23:06 12 | */ 13 | public class CollectionUtil extends CollUtil { 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/test/java/com/xiaoTools/util/ClassLoaderUtilTest/ClassLoaderUtilTest.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.util.ClassLoaderUtilTest; 2 | 3 | import com.xiaoTools.util.classLoaderUtil.ClassLoaderUtil; 4 | 5 | import org.junit.Test; 6 | 7 | public class ClassLoaderUtilTest { 8 | 9 | @Test 10 | public void test_getClassLoader(){ 11 | // jdk.internal.loader.ClassLoaders$AppClassLoader@55054057 12 | ClassLoader a = ClassLoaderUtil.getClassLoader(); 13 | System.out.println(a); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/test/java/com/xiaoTools/util/HexUtilTest/HexUtilTest.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.util.HexUtilTest; 2 | 3 | import com.xiaoTools.util.hexUtil.HexUtil; 4 | 5 | import org.junit.Test; 6 | 7 | public class HexUtilTest { 8 | @Test 9 | public void test_encodeHexStr(){ 10 | String a = "this is a xiaoTools"; 11 | 12 | // 746869732069732061207869616f546f6f6c73 13 | System.out.println(HexUtil.encodeHexStr(a)); 14 | // this is a xiaoTools 15 | System.out.println(HexUtil.decodeHexStr(HexUtil.encodeHexStr(a))); 16 | } 17 | 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/exception/IoException/IoRuntimeException.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.exception.IoException; 2 | 3 | import java.io.Serial; 4 | 5 | /** 6 | * [进行IO的异常处理操作](Perform IO exception handling operations) 7 | * @description: zh - 进行IO的异常处理操作 8 | * @description: en - Perform IO exception handling operations 9 | * @version: V1.0 10 | * @author XiaoXunYao 11 | * @since 2021/6/6 10:55 上午 12 | */ 13 | public class IoRuntimeException extends RuntimeException{ 14 | 15 | @Serial 16 | private static final long serialVersionUID = 8247610319171014183L; 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/lang/copier/Copier.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.lang.copier; 2 | 3 | /** 4 | * [拷贝接口](Copy interface) 5 | * @description zh - 拷贝接口 6 | * @description en - Copy interface 7 | * @version V1.0 8 | * @author XiaoXunYao 9 | * @since 2021-10-27 18:14:29 10 | */ 11 | @FunctionalInterface 12 | public interface Copier { 13 | 14 | /** 15 | * [执行拷贝](Execute Copy) 16 | * @description zh - 执行拷贝 17 | * @description en - Execute Copy 18 | * @version V1.0 19 | * @author XiaoXunYao 20 | * @since 2021-10-27 18:14:02 21 | * @return T 22 | */ 23 | T copy(); 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/test/java/com/xiaoTools/util/IoUtilTest/IoUtilTest.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.util.IoUtilTest; 2 | 3 | import java.io.BufferedInputStream; 4 | import java.io.BufferedOutputStream; 5 | 6 | import com.xiaoTools.util.fileUtil.fileUtil.FileUtil; 7 | import com.xiaoTools.util.ioUtil.IoUtil; 8 | 9 | import org.junit.Test; 10 | 11 | public class IoUtilTest { 12 | 13 | @Test 14 | public void test_demo(){ 15 | BufferedInputStream in = FileUtil.getInputStream("d:/test.txt"); 16 | BufferedOutputStream out = FileUtil.getOutputStream("d:/test2.txt"); 17 | long copySize = IoUtil.copy(in, out, IoUtil.DEFAULT_BUFFER_SIZE); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/FEATURE_REQUEST.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | 5 | --- 6 | 7 | **Is your feature request related to a problem? Please describe.** 8 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 9 | 10 | **Describe the solution you'd like** 11 | A clear and concise description of what you want to happen. 12 | 13 | **Describe alternatives you've considered** 14 | A clear and concise description of any alternative solutions or features you've considered. 15 | 16 | **Additional context** 17 | Add any other context or links about the feature request here. -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/filter/Filter.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.filter; 2 | 3 | /** 4 | * [过滤器接口](Filter interface) 5 | * @description: zh - 过滤器接口 6 | * @description: en - Filter interface 7 | * @version: V1.0 8 | * @author XiaoXunYao 9 | * @since 2021/6/12 7:44 下午 10 | */ 11 | @FunctionalInterface 12 | public interface Filter { 13 | 14 | /** 15 | * [是否接受对象](Accept object) 16 | * @description: zh - 是否接受对象 17 | * @description: en - Accept object 18 | * @version: V1.0 19 | * @author XiaoXunYao 20 | * @since 2021/6/12 7:44 下午 21 | * @param t: 检查的对象 22 | * @return boolean 23 | */ 24 | boolean accept(T t); 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/annotation/alias/Alias.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.annotation.alias; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * 7 | * @description: zh - Bean注解 8 | * @version: V1.0 9 | * @author XiaoXunYao 10 | * @since 2021/6/16 3:12 下午 11 | */ 12 | @Documented 13 | @Retention(RetentionPolicy.RUNTIME) 14 | @Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER}) 15 | public @interface Alias { 16 | 17 | /** 18 | * 19 | * @description: zh - 别名值,即使用此注解要替换成的别名名称 20 | * @version: V1.0 21 | * @author XiaoXunYao 22 | * @since 2021/6/16 3:13 下午 23 | * @return java.lang.String 24 | */ 25 | String value(); 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/io/lineSeparator/LineSeparator.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.io.lineSeparator; 2 | 3 | /** 4 | * [换行符枚举](Linefeed enumeration) 5 | * @description zh - 换行符枚举 6 | * @description en - Linefeed enumeration 7 | * @version V1.0 8 | * @author XiaoXunYao 9 | * @since 2021-10-29 22:04:50 10 | */ 11 | public enum LineSeparator { 12 | /** Mac系统换行符:"\r" */ 13 | MAC("\r"), 14 | /** Linux系统换行符:"\n" */ 15 | LINUX("\n"), 16 | /** Windows系统换行符:"\r\n" */ 17 | WINDOWS("\r\n"); 18 | 19 | private final String value; 20 | 21 | LineSeparator(String lineSeparator) { 22 | this.value = lineSeparator; 23 | } 24 | 25 | public String getValue() { 26 | return this.value; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/lang/hash/hash32/Hash32.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.lang.hash.hash32; 2 | 3 | /** 4 | * [Hash计算接口](Hash computing interface) 5 | * @description zh - Hash计算接口 6 | * @description en - Hash computing interface 7 | * @version V1.0 8 | * @author XiaoXunYao 9 | * @since 2021-09-03 21:27:22 10 | */ 11 | @FunctionalInterface 12 | public interface Hash32 { 13 | /** 14 | * [计算Hash值](Calculate hash value) 15 | * @description zh - 计算Hash值 16 | * @description en - Calculate hash value 17 | * @version V1.0 18 | * @author XiaoXunYao 19 | * @since 2021-09-03 21:26:44 20 | * @param t 对象 21 | * @return int 22 | */ 23 | int hash32(T t); 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/matcher/Matcher.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.matcher; 2 | 3 | /** 4 | * [匹配接口](Matching interface) 5 | * @description: zh - 匹配接口 6 | * @description: en - Matching interface 7 | * @version: V1.0 8 | * @author XiaoXunYao 9 | * @since 2021/6/24 7:29 下午 10 | */ 11 | @FunctionalInterface 12 | public interface Matcher { 13 | 14 | /** 15 | * [给定对象是否匹配](Does the given object match) 16 | * @description: zh - 给定对象是否匹配 17 | * @description: en - Does the given object match 18 | * @version: V1.0 19 | * @author XiaoXunYao 20 | * @since 2021/6/24 7:28 下午 21 | * @param t: 对象 22 | * @return boolean 23 | */ 24 | boolean match(T t); 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/convert/uUIDConverter/UUIDConverter.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.convert.uUIDConverter; 2 | 3 | import java.util.UUID; 4 | 5 | import com.xiaoTools.core.convert.abstractConverter.AbstractConverter; 6 | 7 | /** 8 | * [UUID对象转换器转换器](UUID Object Converter) 9 | * @description zh - UUID对象转换器转换器 10 | * @description en - UUID Object Converter 11 | * @version V1.0 12 | * @author XiaoXunYao 13 | * @since 2021-10-20 17:03:55 14 | */ 15 | public class UUIDConverter extends AbstractConverter { 16 | private static final long serialVersionUID = 1L; 17 | 18 | @Override 19 | protected UUID convertInternal(Object value) { 20 | return UUID.fromString(convertToStr(value)); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/lang/clone/cLoneable/Cloneable.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.lang.clone.cLoneable; 2 | 3 | /** 4 | * [克隆支持接口](Clone support interface) 5 | * @description: zh - 克隆支持接口 6 | * @description: en - Clone support interface 7 | * @version: V1.0 8 | * @author XiaoXunYao 9 | * @since 2021/6/19 9:53 上午 10 | */ 11 | public interface Cloneable extends java.lang.Cloneable { 12 | 13 | /** 14 | * [克隆当前对象,浅复制](Clone current object, shallow copy) 15 | * @description: zh - 克隆当前对象,浅复制 16 | * @description: en - Clone current object, shallow copy 17 | * @version: V1.0 18 | * @author XiaoXunYao 19 | * @since 2021/6/19 9:53 上午 20 | * @return T 21 | */ 22 | T clone(); 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/match/Match.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.match; 2 | 3 | /** 4 | * [匹配的对象类型接口](Matching object type interface) 5 | * @description: zh - 匹配的对象类型接口 6 | * @description: en - Matching object type interface 7 | * @version: V1.0 8 | * @author XiaoXunYao 9 | * @since 2021/6/12 2:40 下午 10 | */ 11 | @FunctionalInterface 12 | public interface Match { 13 | /** 14 | * [给定对象是否匹配](Does the given object match) 15 | * @description: zh - 给定对象是否匹配 16 | * @description: en - Does the given object match 17 | * @version: V1.0 18 | * @author XiaoXunYao 19 | * @since 2021/6/12 2:39 下午 20 | * @param t: [对象](object) 21 | * @return boolean 22 | */ 23 | boolean match(T t); 24 | } 25 | -------------------------------------------------------------------------------- /src/test/java/com/xiaoTools/util/PageUtilTest/PageUtilTest.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.util.PageUtilTest; 2 | 3 | import com.xiaoTools.util.pageUtil.PageUtil; 4 | 5 | import org.junit.Test; 6 | 7 | public class PageUtilTest { 8 | 9 | @Test 10 | public void test_transToStartEnd(){ 11 | // 10 20 12 | int[] a = PageUtil.transToStartEnd(1, 10); 13 | for(int i : a){ 14 | System.out.print(i + " "); 15 | } 16 | 17 | System.out.println(); 18 | 19 | // 0 10 20 | int[] b = PageUtil.transToStartEnd(0, 10); 21 | for(int i : b){ 22 | System.out.print(i + " "); 23 | } 24 | } 25 | 26 | @Test 27 | public void test_totalPage(){ 28 | int a = PageUtil.totalPage(10, 3); 29 | // 4 30 | System.out.println(a); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/annotation/propIgnore/PropIgnore.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.annotation.propIgnore; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | /** 10 | * [属性忽略注解](Attribute ignore annotation) 11 | * @description zh - 属性忽略注解 12 | * @description en - Attribute ignore annotation 13 | * @version V1.0 14 | * @author XiaoXunYao 15 | * @since 2021-10-27 08:43:08 16 | */ 17 | @Documented 18 | @Retention(RetentionPolicy.RUNTIME) 19 | @Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER}) 20 | public @interface PropIgnore { 21 | 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/convert/timeZoneConverter/TimeZoneConverter.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.convert.timeZoneConverter; 2 | 3 | import java.util.TimeZone; 4 | 5 | import com.xiaoTools.core.convert.abstractConverter.AbstractConverter; 6 | 7 | /** 8 | * [TimeZone转换器](Timezone converter) 9 | * @description zh - TimeZone转换器 10 | * @description en - Timezone converter 11 | * @version V1.0 12 | * @author XiaoXunYao 13 | * @since 2021-10-20 16:49:24 14 | */ 15 | public class TimeZoneConverter extends AbstractConverter{ 16 | private static final long serialVersionUID = 1L; 17 | 18 | @Override 19 | protected TimeZone convertInternal(Object value) { 20 | return TimeZone.getTimeZone(convertToStr(value)); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/convert/currencyConverter/CurrencyConverter.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.convert.currencyConverter; 2 | 3 | import java.util.Currency; 4 | 5 | import com.xiaoTools.core.convert.abstractConverter.AbstractConverter; 6 | 7 | /** 8 | * [货币Currency转换器](Currency converter) 9 | * @description zh - 货币Currency转换器 10 | * @description en - Currency converter 11 | * @version V1.0 12 | * @author XiaoXunYao 13 | * @since 2021-10-20 17:00:57 14 | */ 15 | public class CurrencyConverter extends AbstractConverter { 16 | private static final long serialVersionUID = 1L; 17 | 18 | @Override 19 | protected Currency convertInternal(Object value) { 20 | return Currency.getInstance(convertToStr(value)); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/convert/optionalConverter/OptionalConverter.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.convert.optionalConverter; 2 | 3 | import java.util.Optional; 4 | 5 | import com.xiaoTools.core.convert.abstractConverter.AbstractConverter; 6 | 7 | /** 8 | * [Optional对象转换器](Optional object converter) 9 | * @description zh - Optional对象转换器 10 | * @description en - Optional object converter 11 | * @version V1.0 12 | * @author XiaoXunYao 13 | * @since 2021-10-20 17:07:02 14 | */ 15 | public class OptionalConverter extends AbstractConverter> { 16 | private static final long serialVersionUID = 1L; 17 | 18 | @Override 19 | protected Optional convertInternal(Object value) { 20 | return Optional.ofNullable(value); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/test/java/com/xiaoTools/util/ArrayUtilTest/ArrayUtilTest.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.util.ArrayUtilTest; 2 | 3 | import com.xiaoTools.util.arrayUtil.ArrayUtil; 4 | 5 | import org.junit.Test; 6 | 7 | public class ArrayUtilTest { 8 | 9 | @Test 10 | public void test_empty(){ 11 | int[] a = {}; 12 | int[] b = null; 13 | // `a` is empty --> true 14 | System.out.println( "`a` is empty --> " + ArrayUtil.isEmpty(a)); 15 | // `b` is empty --> true 16 | System.out.println( "`b` is empty --> " + ArrayUtil.isEmpty(b)); 17 | } 18 | 19 | @Test 20 | public void test_newArray(){ 21 | String[] array = ArrayUtil.newArray(String.class, 10); 22 | // `array` length --> 10 23 | System.out.println( "`array` length --> " + array.length); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/escape/filter/Filter.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.escape.filter; 2 | 3 | /** 4 | * [是否检查该对象的监听器](Do you want to check the listener for this object) 5 | * @description: zh - 是否检查该对象的监听器 6 | * @description: en - Do you want to check the listener for this object 7 | * @version: V1.0 8 | * @author XiaoXunYao 9 | * @since 2021/6/8 2:33 下午 10 | */ 11 | @FunctionalInterface 12 | public interface Filter { 13 | /** 14 | * [是否检查该对象](Check the object) 15 | * @description: zh - 是否检查该对象 16 | * @description: en - Check the object 17 | * @version: V1.0 18 | * @author XiaoXunYao 19 | * @since 2021/6/8 9:55 上午 20 | * @param t: 检查的对象 21 | * @return boolean 22 | */ 23 | boolean accept(T t); 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/io/lineHandler/LineHandler.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.io.lineHandler; 2 | 3 | /** 4 | * [行处理器](Line processor) 5 | * @description zh - 行处理器 6 | * @description en - Line processor 7 | * @version V1.0 8 | * @author XiaoXunYao 9 | * @since 2021-10-23 17:55:40 10 | */ 11 | @FunctionalInterface 12 | public interface LineHandler { 13 | 14 | /** 15 | * [处理一行数据,可以编辑后存入指定地方](Process a row of data, which can be edited and stored in the specified place) 16 | * @description zh - 处理一行数据,可以编辑后存入指定地方 17 | * @description en - Process a row of data, which can be edited and stored in the specified place 18 | * @version V1.0 19 | * @author XiaoXunYao 20 | * @since 2021-10-23 17:55:13 21 | * @param line 行 22 | */ 23 | void handle(String line); 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/convert/charsetConverter/CharsetConverter.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.convert.charsetConverter; 2 | 3 | import java.nio.charset.Charset; 4 | 5 | import com.xiaoTools.core.convert.abstractConverter.AbstractConverter; 6 | import com.xiaoTools.util.charsetUtil.CharsetUtil; 7 | 8 | /** 9 | * [编码对象转换器](Encoding object converter) 10 | * @description zh - 编码对象转换器 11 | * @description en - Encoding object converter 12 | * @version V1.0 13 | * @author XiaoXunYao 14 | * @since 2021-10-20 16:55:27 15 | */ 16 | public class CharsetConverter extends AbstractConverter{ 17 | private static final long serialVersionUID = 1L; 18 | 19 | @Override 20 | protected Charset convertInternal(Object value) { 21 | return CharsetUtil.charset(convertToStr(value)); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/test/java/com/xiaoTools/util/ClassUtilTest/ClassUtilTest.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.util.ClassUtilTest; 2 | 3 | import com.xiaoTools.util.classUtil.ClassUtil; 4 | import com.xiaoTools.util.strUtil.StrUtil; 5 | 6 | import org.junit.Test; 7 | 8 | public class ClassUtilTest { 9 | 10 | @Test 11 | public void test_isAbstract(){ 12 | // false 13 | boolean a = ClassUtil.isAbstract(StrUtil.class); 14 | System.out.println(a); 15 | 16 | // true 17 | boolean b = ClassUtil.isAbstract(int.class); 18 | System.out.println(b); 19 | 20 | } 21 | 22 | @Test 23 | public void test_isBasicType(){ 24 | //true 25 | boolean a = ClassUtil.isBasicType(Integer.class); 26 | System.out.println(a); 27 | 28 | //false 29 | boolean b = ClassUtil.isBasicType(StrUtil.class); 30 | System.out.println(b); 31 | } 32 | 33 | 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/convert/booleanConverter/BooleanConverter.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.convert.booleanConverter; 2 | 3 | import com.xiaoTools.core.convert.abstractConverter.AbstractConverter; 4 | import com.xiaoTools.util.booleanUtil.BooleanUtil; 5 | 6 | /** 7 | * [Boolean转换器](Boolean converter) 8 | * @description zh - Boolean转换器 9 | * @description en - Boolean converter 10 | * @version V1.0 11 | * @author XiaoXunYao 12 | * @since 2021-10-19 07:24:37 13 | */ 14 | public class BooleanConverter extends AbstractConverter { 15 | 16 | private static final long serialVersionUID = 1L; 17 | 18 | @Override 19 | protected Boolean convertInternal(Object value) { 20 | return value instanceof Number ? 21 | 0 != ((Number) value).doubleValue() : 22 | BooleanUtil.toBoolean(convertToStr(value)); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/io/streamProgress/StreamProgress.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.io.streamProgress; 2 | 3 | /** 4 | * [Stream进度条]Z(Stream progress bar) 5 | * @description zh - Stream进度条 6 | * @description en - Stream progress bar 7 | * @version V1.0 8 | * @author XiaoXunYao 9 | * @since 2021-10-22 12:49:15 10 | */ 11 | public interface StreamProgress { 12 | 13 | /** 14 | * [开始](start) 15 | * @description zh - 开始 16 | * @description en - start 17 | * @version V1.0 18 | * @author XiaoXunYao 19 | * @since 2021-10-22 12:48:12 20 | */ 21 | void start(); 22 | 23 | void progress(long progressSize); 24 | 25 | /** 26 | * [结束](end) 27 | * @description zh - 结束 28 | * @description en - end 29 | * @version V1.0 30 | * @author XiaoXunYao 31 | * @since 2021-10-22 12:48:40 32 | */ 33 | void finish(); 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/editor/Editor.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.editor; 2 | 3 | /** 4 | * [编辑器接口,常用于对于集合中的元素做统一编辑](Editor interface, commonly used for unified editing of elements in a collection) 5 | * @description: zh - 编辑器接口,常用于对于集合中的元素做统一编辑 6 | * @description: en - Editor interface, commonly used for unified editing of elements in a collection 7 | * @version: V1.0 8 | * @author XiaoXunYao 9 | * @since 2021/6/12 5:34 下午 10 | */ 11 | @FunctionalInterface 12 | public interface Editor { 13 | /** 14 | * [修改过滤后的结果](Modify the filtered results) 15 | * @description: zh - 修改过滤后的结果 16 | * @description: en - Modify the filtered results 17 | * @version: V1.0 18 | * @author XiaoXunYao 19 | * @since 2021/6/12 5:33 下午 20 | * @param t: 被过滤的对象 21 | * @return T 22 | */ 23 | T edit(T t); 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/collection/consumer/Consumer.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.collection.consumer; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * [针对一个参数做相应的操作](Perform corresponding operations for a parameter) 7 | * @description zh - 针对一个参数做相应的操作 8 | * @description en - Perform corresponding operations for a parameter 9 | * @version V1.0 10 | * @author XiaoXunYao 11 | * @since 2021-09-07 22:07:55 12 | */ 13 | @FunctionalInterface 14 | public interface Consumer extends Serializable { 15 | /** 16 | * [接受并处理一个参数](Accept and process a parameter) 17 | * @description zh - 接受并处理一个参数 18 | * @description en - Accept and process a parameter 19 | * @version V1.0 20 | * @author XiaoXunYao 21 | * @since 2021-09-07 22:11:44 22 | * @param value 参数值 23 | * @param index 参数在集合中的索引 24 | */ 25 | void accept(T value, int index); 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/convert/atomicLongArrayConverter/AtomicLongArrayConverter.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.convert.atomicLongArrayConverter; 2 | 3 | import java.util.concurrent.atomic.AtomicLongArray; 4 | 5 | import com.xiaoTools.core.convert.Convert; 6 | import com.xiaoTools.core.convert.abstractConverter.AbstractConverter; 7 | 8 | /** 9 | * [AtomicLongArray转换器](Atomiclongarray converter) 10 | * @description zh - AtomicLongArray转换器 11 | * @description en - Atomiclongarray converter 12 | * @version V1.0 13 | * @author XiaoXunYao 14 | * @since 2021-10-20 16:46:57 15 | */ 16 | public class AtomicLongArrayConverter extends AbstractConverter { 17 | private static final long serialVersionUID = 1L; 18 | 19 | @Override 20 | protected AtomicLongArray convertInternal(Object value) { 21 | return new AtomicLongArray(Convert.convert(long[].class, value)); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/convert/periodConverter/PeriodConverter.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.convert.periodConverter; 2 | 3 | import java.time.Period; 4 | import java.time.temporal.TemporalAmount; 5 | 6 | import com.xiaoTools.core.convert.abstractConverter.AbstractConverter; 7 | 8 | /** 9 | * [Period对象转换器](Period Object Converter) 10 | * @description zh - Period对象转换器 11 | * @description en - Period Object Converter 12 | * @version V1.0 13 | * @author XiaoXunYao 14 | * @since 2021-10-20 16:28:00 15 | */ 16 | public class PeriodConverter extends AbstractConverter { 17 | private static final long serialVersionUID = 1L; 18 | 19 | @Override 20 | protected Period convertInternal(Object value) { 21 | return value instanceof TemporalAmount ? Period.from((TemporalAmount) value) : 22 | value instanceof Integer ? Period.ofDays((Integer) value) : 23 | Period.parse(convertToStr(value)); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/io/nullOutputStream/NullOutputStream.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.io.nullOutputStream; 2 | 3 | 4 | import java.io.IOException; 5 | import java.io.OutputStream; 6 | 7 | /** 8 | * [此OutputStream写出数据到null](This OutputStream writes out data to null) 9 | * @description zh - 此OutputStream写出数据到null 10 | * @description en - This OutputStream writes out data to null 11 | * @version V1.0 12 | * @author XiaoXunYao 13 | * @since 2021-10-24 10:56:10 14 | */ 15 | public class NullOutputStream extends OutputStream { 16 | public static final NullOutputStream NULL_OUTPUT_STREAM = new NullOutputStream(); 17 | 18 | @Override 19 | public void write(byte[] b, int off, int len) { 20 | // to /dev/null 21 | } 22 | 23 | @Override 24 | public void write(int b) { 25 | // to /dev/null 26 | } 27 | 28 | @Override 29 | public void write(byte[] b) throws IOException { 30 | // to /dev/null 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/convert/atomicIntegerArrayConverter/AtomicIntegerArrayConverter.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.convert.atomicIntegerArrayConverter; 2 | 3 | import java.util.concurrent.atomic.AtomicIntegerArray; 4 | 5 | import com.xiaoTools.core.convert.Convert; 6 | import com.xiaoTools.core.convert.abstractConverter.AbstractConverter; 7 | 8 | /** 9 | * [AtomicIntegerArray转换器](Atomicintegerarray converter) 10 | * @description zh - AtomicIntegerArray转换器 11 | * @description en - Atomicintegerarray converter 12 | * @version V1.0 13 | * @author XiaoXunYao 14 | * @since 2021-10-20 16:45:22 15 | */ 16 | public class AtomicIntegerArrayConverter extends AbstractConverter { 17 | private static final long serialVersionUID = 1L; 18 | 19 | @Override 20 | protected AtomicIntegerArray convertInternal(Object value) { 21 | return new AtomicIntegerArray(Convert.convert(int[].class, value)); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/entity/mutable/Mutable.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.entity.mutable; 2 | 3 | /** 4 | * [提供可变值类型接口](Provide variable value type interface) 5 | * @description: zh - 提供可变值类型接口 6 | * @description: en - Provide variable value type interface 7 | * @version: V1.0 8 | * @author XiaoXunYao 9 | * @since 2021/6/21 8:30 下午 10 | */ 11 | public interface Mutable { 12 | 13 | /** 14 | * [获得原始值](Get the original value) 15 | * @description: zh - 获得原始值 16 | * @description: en - Get the original value 17 | * @version: V1.0 18 | * @author XiaoXunYao 19 | * @since 2021/6/21 8:30 下午 20 | * @return T 21 | */ 22 | T get(); 23 | 24 | /** 25 | * [设置值](Set value) 26 | * @description: zh - 设置值 27 | * @description: en - Set value 28 | * @version: V1.0 29 | * @author XiaoXunYao 30 | * @since 2021/6/21 8:29 下午 31 | * @param value: 值 32 | */ 33 | void set(T value); 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/convert/durationConverter/DurationConverter.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.convert.durationConverter; 2 | 3 | import java.time.Duration; 4 | import java.time.temporal.TemporalAmount; 5 | 6 | import com.xiaoTools.core.convert.abstractConverter.AbstractConverter; 7 | 8 | /** 9 | * [Duration对象转换器](Duration Object Converter) 10 | * @description zh - Duration对象转换器 11 | * @description en - Duration Object Converter 12 | * @version V1.0 13 | * @author XiaoXunYao 14 | * @since 2021-10-20 16:29:10 15 | */ 16 | public class DurationConverter extends AbstractConverter { 17 | private static final long serialVersionUID = 1L; 18 | 19 | @Override 20 | protected Duration convertInternal(Object value) { 21 | return value instanceof TemporalAmount ? Duration.from((TemporalAmount) value) : 22 | value instanceof Long ? Duration.ofMillis((Long) value) : 23 | Duration.parse(convertToStr(value)); 24 | 25 | } 26 | 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/convert/classConverter/ClassConverter.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.convert.classConverter; 2 | 3 | import com.xiaoTools.core.convert.abstractConverter.AbstractConverter; 4 | import com.xiaoTools.util.classLoaderUtil.ClassLoaderUtil; 5 | 6 | /** 7 | * [类转换器](Class converter) 8 | * @description zh - 类转换器 9 | * @description en - Class converter 10 | * @version V1.0 11 | * @author XiaoXunYao 12 | * @since 2021-10-20 16:48:27 13 | */ 14 | public class ClassConverter extends AbstractConverter> { 15 | private static final long serialVersionUID = 1L; 16 | 17 | private final boolean isInitialized; 18 | 19 | public ClassConverter() { 20 | this(true); 21 | } 22 | 23 | public ClassConverter(boolean isInitialized) { 24 | this.isInitialized = isInitialized; 25 | } 26 | 27 | @Override 28 | protected Class convertInternal(Object value) { 29 | return ClassLoaderUtil.loadClass(convertToStr(value), isInitialized); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/test/java/com/xiaoTools/util/ObjectUtilTest/ObjectUtilTest.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.util.ObjectUtilTest; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import com.xiaoTools.util.objectUtil.ObjectUtil; 7 | 8 | import org.junit.Test; 9 | 10 | public class ObjectUtilTest { 11 | 12 | @Test 13 | public void test_equal(){ 14 | Object a = null; 15 | Object b = new Object(); 16 | boolean c = ObjectUtil.equal(a, b); 17 | // `a` equal `b` --> false 18 | System.out.println( "`a` equal `b` --> " + c); 19 | } 20 | 21 | @Test 22 | public void test_length(){ 23 | int[] a = new int[]{0,1,2,3}; 24 | int b = ObjectUtil.length(a); 25 | // `a` array length --> 4 26 | System.out.println( "`a` array length --> " + b); 27 | 28 | Map map = new HashMap<>(); 29 | map.put(1,1); 30 | map.put(2,2); 31 | map.put(3,3); 32 | int c = ObjectUtil.length(map); 33 | // `map` is length --> 3 34 | System.out.println("`map` is length --> " + c); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/convert/uRLConverter/URLConverter.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.convert.uRLConverter; 2 | 3 | import java.io.File; 4 | import java.net.URI; 5 | import java.net.URL; 6 | 7 | import com.xiaoTools.core.convert.abstractConverter.AbstractConverter; 8 | 9 | /** 10 | * [URL对象转换器](URL Object Converter) 11 | * @description zh - URL对象转换器 12 | * @description en - URL Object Converter 13 | * @version V1.0 14 | * @author XiaoXunYao 15 | * @since 2021-10-19 07:40:55 16 | */ 17 | public class URLConverter extends AbstractConverter { 18 | private static final long serialVersionUID = 1L; 19 | 20 | @Override 21 | protected URL convertInternal(Object value) { 22 | try { 23 | if(value instanceof File){ 24 | return ((File)value).toURI().toURL(); 25 | } 26 | 27 | if(value instanceof URI){ 28 | return ((URI)value).toURL(); 29 | } 30 | return new URL(convertToStr(value)); 31 | } catch (Exception e) { 32 | // Ignore Exception 33 | } 34 | return null; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/convert/uRIConverter/URIConverter.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.convert.uRIConverter; 2 | 3 | import java.io.File; 4 | import java.net.URI; 5 | import java.net.URL; 6 | 7 | import com.xiaoTools.core.convert.abstractConverter.AbstractConverter; 8 | 9 | /** 10 | * [URI对象转换器](Uri Object Converter) 11 | * @description zh - URI对象转换器 12 | * @description en - Uri Object Converter 13 | * @version V1.0 14 | * @author XiaoXunYao 15 | * @since 2021-10-19 07:36:34 16 | */ 17 | public class URIConverter extends AbstractConverter { 18 | 19 | private static final long serialVersionUID = 1L; 20 | 21 | @Override 22 | protected URI convertInternal(Object value) { 23 | try { 24 | if(value instanceof File){ 25 | return ((File)value).toURI(); 26 | } 27 | 28 | if(value instanceof URL){ 29 | return ((URL)value).toURI(); 30 | } 31 | return new URI(convertToStr(value)); 32 | } catch (Exception e) { 33 | // Ignore Exception 34 | } 35 | return null; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/convert/atomicBooleanConverter/AtomicBooleanConverter.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.convert.atomicBooleanConverter; 2 | 3 | import java.util.concurrent.atomic.AtomicBoolean; 4 | 5 | import com.xiaoTools.core.convert.abstractConverter.AbstractConverter; 6 | import com.xiaoTools.util.booleanUtil.BooleanUtil; 7 | 8 | /** 9 | * [AtomicBoolean转换器](Atomicboolean converter) 10 | * @description zh - AtomicBoolean转换器 11 | * @description en - Atomicboolean converter 12 | * @version V1.0 13 | * @author XiaoXunYao 14 | * @since 2021-10-19 07:28:17 15 | */ 16 | public class AtomicBooleanConverter extends AbstractConverter { 17 | 18 | private static final long serialVersionUID = 1L; 19 | 20 | @Override 21 | protected AtomicBoolean convertInternal(Object value) { 22 | if (value instanceof Boolean) { 23 | return new AtomicBoolean((Boolean) value); 24 | } 25 | final String valueStr = convertToStr(value); 26 | return new AtomicBoolean(BooleanUtil.toBoolean(valueStr)); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/convert/characterConverter/CharacterConverter.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.convert.characterConverter; 2 | 3 | import com.xiaoTools.core.convert.abstractConverter.AbstractConverter; 4 | import com.xiaoTools.util.booleanUtil.BooleanUtil; 5 | import com.xiaoTools.util.strUtil.StrUtil; 6 | 7 | /** 8 | * [字符转换器](Character converter) 9 | * @description zh - 字符转换器 10 | * @description en - Character converter 11 | * @version V1.0 12 | * @author XiaoXunYao 13 | * @since 2021-10-18 20:14:30 14 | */ 15 | public class CharacterConverter extends AbstractConverter { 16 | 17 | private static final long serialVersionUID = 1L; 18 | 19 | @Override 20 | protected Character convertInternal(Object value) { 21 | if (value instanceof Boolean) { 22 | return BooleanUtil.toCharacter((Boolean) value); 23 | } else { 24 | final String valueStr = convertToStr(value); 25 | if (StrUtil.isNotBlank(valueStr)) { 26 | return valueStr.charAt(0); 27 | } 28 | } 29 | return null; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/test/java/com/xiaoTools/util/UrlUtilTest/UrlUtilTest.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.util.UrlUtilTest; 2 | 3 | import java.net.URL; 4 | 5 | import com.xiaoTools.util.urlUtil.URLUtil; 6 | 7 | import org.junit.Test; 8 | 9 | public class UrlUtilTest { 10 | 11 | @Test 12 | public void test_url() throws Exception{ 13 | String a = "https://github.com/xiao-organization/xiaoTools/wiki/2.-StrUtil"; 14 | URL url = URLUtil.url(a); 15 | // github.com 16 | System.out.println(url.getAuthority()); 17 | } 18 | 19 | @Test 20 | public void test_normalize(){ 21 | String a = "http://github.com//xiao-organization/\\xiaoTools"; 22 | String b = URLUtil.normalize(a); 23 | // http://github.com//xiao-organization//xiaoTools 24 | System.out.println(b); 25 | } 26 | 27 | @Test 28 | public void test_encode_and_decode(){ 29 | String a = "xiaoTools的图标.jpg"; 30 | String b = URLUtil.encode(a); 31 | // xiaoTools%E7%9A%84%E5%9B%BE%E6%A0%87.jpg 32 | System.out.println(b); 33 | 34 | String c = URLUtil.decode(b); 35 | // xiaoTools的图标.jpg 36 | System.out.println(c); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/collection/kVConsumer/KVConsumer.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.collection.kVConsumer; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * [针对两个参数做相应的操作,例如Map中的KEY和VALUE](Perform corresponding operations on two parameters, such as key and value in map) 7 | * @description zh - 针对两个参数做相应的操作,例如Map中的KEY和VALUE 8 | * @description en - Perform corresponding operations on two parameters, such as key and value in map 9 | * @version V1.0 10 | * @author XiaoXunYao 11 | * @since 2021-09-01 19:23:00 12 | */ 13 | @FunctionalInterface 14 | public interface KVConsumer extends Serializable{ 15 | 16 | /** 17 | * [Accept and process a pair of parameters](Accept and process a pair of parameters) 18 | * @description zh - 接受并处理一对参数 19 | * @description en - Accept and process a pair of parameters 20 | * @version V1.0 21 | * @author XiaoXunYao 22 | * @since 2021-09-01 19:22:02 23 | * @param key 键 24 | * @param value 值 25 | * @param index 参数在集合中的索引 26 | */ 27 | void accept(K key, V value, int index); 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/entity/valueProvider/ValueProvider.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.entity.valueProvider; 2 | 3 | import java.lang.reflect.Type; 4 | 5 | /** 6 | * [值提供者](Value provider) 7 | * @description zh - 值提供者 8 | * @description en - Value provider 9 | * @version V1.0 10 | * @author XiaoXunYao 11 | * @since 2021-10-27 18:07:47 12 | */ 13 | public interface ValueProvider { 14 | 15 | /** 16 | * [获取值](Get value) 17 | * @description zh - 获取值 18 | * @description en - Get value 19 | * @version V1.0 20 | * @author XiaoXunYao 21 | * @since 2021-10-27 18:08:13 22 | * @param key Bean对象中参数名 23 | * @param valueType 被注入的值的类型 24 | * @return java.lang.Object 25 | */ 26 | Object value(T key, Type valueType); 27 | 28 | /** 29 | * [是否包含指定KEY](Whether to include the specified key) 30 | * @description zh - 是否包含指定KEY 31 | * @description en - Whether to include the specified key 32 | * @version V1.0 33 | * @author XiaoXunYao 34 | * @since 2021-10-27 18:08:50 35 | * @param key Bean对象中参数名 36 | * @return boolean 37 | */ 38 | boolean containsKey(T key); 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/eval/operator/Operator.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.eval.operator; 2 | 3 | /** 4 | * [封装每一个操作符以及其索引](Encapsulate each operator and its index) 5 | * @description zh - 封装每一个操作符以及其索引 6 | * @description en - Encapsulate each operator and its index 7 | * @version V1.0 8 | * @author XiaoXunYao 9 | * @since 2021-10-19 20:25:15 10 | */ 11 | public class Operator { 12 | 13 | /** 14 | * [操作符](Operator) 15 | * @description zh - 操作符 16 | * @description en - Operator 17 | * @version V1.0 18 | * @author XiaoXunYao 19 | * @since 2021-10-19 20:25:47 20 | */ 21 | char oper; 22 | 23 | /** 24 | * [索引](Indexes) 25 | * @description zh - 索引 26 | * @description en - Indexes 27 | * @version V1.0 28 | * @author XiaoXunYao 29 | * @since 2021-10-19 20:26:18 30 | */ 31 | int index; 32 | 33 | public Operator() { 34 | 35 | } 36 | public Operator(char oper, int index) { 37 | this.oper = oper; 38 | this.index = index; 39 | } 40 | 41 | public int getIndex() { 42 | return index; 43 | } 44 | 45 | public char getOper() { 46 | return oper; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/thread/lock/noLock/NoLock.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.thread.lock.noLock; 2 | 3 | import java.util.concurrent.TimeUnit; 4 | import java.util.concurrent.locks.Condition; 5 | import java.util.concurrent.locks.Lock; 6 | 7 | /** 8 | * [无锁实现](Lock free implementation) 9 | * @description: zh - 无锁实现 10 | * @description: en - Lock free implementation 11 | * @version: V1.0 12 | * @author XiaoXunYao 13 | * @since 2021/6/24 2:19 下午 14 | */ 15 | public class NoLock implements Lock { 16 | 17 | @Override 18 | public void lock() { 19 | } 20 | 21 | @Override 22 | public void lockInterruptibly() { 23 | } 24 | 25 | @Override 26 | public boolean tryLock() { 27 | return true; 28 | } 29 | 30 | @Override 31 | public boolean tryLock(long time, TimeUnit unit) { 32 | return true; 33 | } 34 | 35 | @Override 36 | public void unlock() { 37 | } 38 | 39 | @Override 40 | public Condition newCondition() { 41 | throw new UnsupportedOperationException("NoLock`s newCondition method is unsupported"); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/lang/segment/defaultSegment/DefaultSegment.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.lang.segment.defaultSegment; 2 | 3 | import com.xiaoTools.lang.segment.Segment; 4 | 5 | /** 6 | * [片段默认实现](Fragment default implementation) 7 | * @description zh - 片段默认实现 8 | * @description en - Fragment default implementation 9 | * @version V1.0 10 | * @author XiaoXunYao 11 | * @since 2021-10-18 12:45:49 12 | */ 13 | public class DefaultSegment implements Segment { 14 | 15 | 16 | protected T startIndex; 17 | protected T endIndex; 18 | 19 | /** 20 | * [构造](structure) 21 | * @description zh - 构造 22 | * @description en - structure 23 | * @version V1.0 24 | * @author XiaoXunYao 25 | * @since 2021-10-18 12:46:27 26 | * @param startIndex 起始位置 27 | * @param endIndex 结束位置 28 | */ 29 | public DefaultSegment(T startIndex, T endIndex) { 30 | this.startIndex = startIndex; 31 | this.endIndex = endIndex; 32 | } 33 | 34 | @Override 35 | public T getStartIndex() { 36 | return this.startIndex; 37 | } 38 | 39 | @Override 40 | public T getEndIndex() { 41 | return this.endIndex; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/convert/converter/Converter.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.convert.converter; 2 | 3 | /** 4 | * [转换器接口,实现类型转换](Converter interface to realize type conversion) 5 | * @description: zh - 转换器接口,实现类型转换 6 | * @description: en - Converter interface to realize type conversion 7 | * @version: V1.0 8 | * @author XiaoXunYao 9 | * @since 2021/6/17 8:43 上午 10 | */ 11 | public interface Converter { 12 | /** 13 | * [转换为指定类型 如果类型无法确定,将读取默认值的类型做为目标类型](Convert to the specified type. If the type cannot be determined, the type that reads the default value is used as the target type) 14 | * @description: zh - 转换为指定类型 如果类型无法确定,将读取默认值的类型做为目标类型 15 | * @description: en - Convert to the specified type. If the type cannot be determined, the type that reads the default value is used as the target type 16 | * @version: V1.0 17 | * @author XiaoXunYao 18 | * @since 2021/6/17 8:42 上午 19 | * @param value: 原始值 20 | * @param defaultValue: 默认值 21 | * @throws IllegalArgumentException: 非法参数异常 22 | * @return T 23 | */ 24 | T convert(Object value, T defaultValue) throws IllegalArgumentException; 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/lang/clone/cLoneSupport/CloneSupport.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.lang.clone.cLoneSupport; 2 | 3 | import com.xiaoTools.core.exception.cLoneRuntimeException.CloneRuntimeException; 4 | import com.xiaoTools.lang.clone.cLoneable.Cloneable; 5 | 6 | /** 7 | * [克隆支持类,提供默认的克隆方法](Clone support class, providing the default clone method) 8 | * @description: zh - 克隆支持类,提供默认的克隆方法 9 | * @description: en - Clone support class, providing the default clone method 10 | * @version: V1.0 11 | * @author XiaoXunYao 12 | * @since 2021/6/19 9:50 上午 13 | */ 14 | public class CloneSupport implements Cloneable { 15 | 16 | /** 17 | * [克隆当前对象,浅复制](Clone current object, shallow copy) 18 | * @description: zh - 克隆当前对象,浅复制 19 | * @description: en - Clone current object, shallow copy 20 | * @version: V1.0 21 | * @author XiaoXunYao 22 | * @since 2021/6/19 9:55 上午 23 | * @return T 24 | */ 25 | @Override 26 | public T clone() { 27 | try { 28 | return (T) super.clone(); 29 | } catch (CloneNotSupportedException e) { 30 | throw new CloneRuntimeException(e); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/convert/pathConverter/PathConverter.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.convert.pathConverter; 2 | 3 | import java.io.File; 4 | import java.net.URI; 5 | import java.net.URL; 6 | import java.nio.file.Path; 7 | import java.nio.file.Paths; 8 | 9 | import com.xiaoTools.core.convert.abstractConverter.AbstractConverter; 10 | 11 | /** 12 | * [字符串转换器](String converter) 13 | * @description zh - 字符串转换器 14 | * @description en - String converter 15 | * @version V1.0 16 | * @author XiaoXunYao 17 | * @since 2021-10-20 16:59:40 18 | */ 19 | public class PathConverter extends AbstractConverter{ 20 | 21 | private static final long serialVersionUID = 1L; 22 | 23 | @Override 24 | protected Path convertInternal(Object value) { 25 | try { 26 | if(value instanceof URI){ 27 | return Paths.get((URI)value); 28 | } 29 | 30 | if(value instanceof URL){ 31 | return Paths.get(((URL)value).toURI()); 32 | } 33 | 34 | if(value instanceof File){ 35 | return ((File)value).toPath(); 36 | } 37 | 38 | return Paths.get(convertToStr(value)); 39 | } catch (Exception e) { 40 | // Ignore Exception 41 | } 42 | return null; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/exception/beanException/BeanException.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.exception.beanException; 2 | 3 | import com.xiaoTools.util.exceptionUtil.ExceptionUtil; 4 | import com.xiaoTools.util.strUtil.StrUtil; 5 | 6 | /** 7 | * [Bean异常](Bean exception) 8 | * @description zh - Bean异常 9 | * @description en - Bean exception 10 | * @version V1.0 11 | * @author XiaoXunYao 12 | * @since 2021-10-25 18:31:44 13 | */ 14 | public class BeanException extends RuntimeException { 15 | 16 | private static final long serialVersionUID = -8096998667745023423L; 17 | 18 | public BeanException(Throwable e) { 19 | super(ExceptionUtil.getMessage(e), e); 20 | } 21 | 22 | public BeanException(String message) { 23 | super(message); 24 | } 25 | 26 | public BeanException(String messageTemplate, Object... params) { 27 | super(StrUtil.format(messageTemplate, params)); 28 | } 29 | 30 | public BeanException(String message, Throwable throwable) { 31 | super(message, throwable); 32 | } 33 | 34 | public BeanException(Throwable throwable, String messageTemplate, Object... params) { 35 | super(StrUtil.format(messageTemplate, params), throwable); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/date/quarter/Quarter.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.date.quarter; 2 | 3 | import com.xiaoTools.lang.constant.Constant; 4 | 5 | /** 6 | * [季度枚举](Quarterly enumeration) 7 | * @description: zh - 季度枚举 8 | * @description: en - Quarterly enumeration 9 | * @version: V1.0 10 | * @author XiaoXunYao 11 | * @since 2021/6/18 3:10 下午 12 | */ 13 | public enum Quarter { 14 | 15 | /** 16 | * 第一季度 17 | */ 18 | Quarter1(Constant.ONE), 19 | 20 | /** 21 | * 第二季度 22 | */ 23 | Quarter2(Constant.TWO), 24 | 25 | /** 26 | * 第三季度 27 | */ 28 | Quarter3(Constant.THREE), 29 | 30 | /** 31 | * 第四季度 32 | */ 33 | Quarter4(Constant.FOUR); 34 | 35 | private final int value; 36 | 37 | Quarter(int value) { 38 | this.value = value; 39 | } 40 | 41 | public int getValue() { 42 | return this.value; 43 | } 44 | 45 | public static Quarter of(int intValue) { 46 | return switch (intValue) { 47 | case 1 -> Quarter1; 48 | case 2 -> Quarter2; 49 | case 3 -> Quarter3; 50 | case 4 -> Quarter4; 51 | default -> null; 52 | }; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/collection/transIter/TransIter.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.collection.transIter; 2 | 3 | import java.util.Iterator; 4 | import java.util.function.Function; 5 | 6 | import com.xiaoTools.assertion.Assertion; 7 | 8 | /** 9 | * [使用给定的转换函数](Use the given conversion function) 10 | * @description zh - 使用给定的转换函数 11 | * @description en - Use the given conversion function 12 | * @version V1.0 13 | * @author XiaoXunYao 14 | * @since 2021-09-19 22:01:14 15 | */ 16 | public class TransIter implements Iterator { 17 | 18 | private final Iterator backingIterator; 19 | private final Function func; 20 | 21 | public TransIter(Iterator backingIterator, Function func) { 22 | this.backingIterator = Assertion.notNull(backingIterator); 23 | this.func = Assertion.notNull(func); 24 | } 25 | 26 | @Override 27 | public final boolean hasNext() { 28 | return backingIterator.hasNext(); 29 | } 30 | 31 | @Override 32 | public final T next() { 33 | return func.apply(backingIterator.next()); 34 | } 35 | 36 | @Override 37 | public final void remove() { 38 | backingIterator.remove(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/cache/beanDescCache/BeanDescCache.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.cache.beanDescCache; 2 | 3 | import com.xiaoTools.cache.simple.SimpleCache; 4 | import com.xiaoTools.cache.simple.method.CacheFun; 5 | import com.xiaoTools.entity.beanDesc.BeanDesc; 6 | 7 | /** 8 | * [Bean属性缓存](Bean attribute cache) 9 | * @description zh - Bean属性缓存 10 | * @description en - Bean attribute cache 11 | * @version V1.0 12 | * @author XiaoXunYao 13 | * @since 2021-10-26 09:56:40 14 | */ 15 | public enum BeanDescCache { 16 | 17 | INSTANCE; 18 | 19 | private final SimpleCache, BeanDesc> bdCache = new SimpleCache<>(); 20 | 21 | /** 22 | * [获得属性名和 BeanDesc Map映射](Get the property name and beandesc map mapping) 23 | * @description zh - 获得属性名和 BeanDesc Map映射 24 | * @description en - Get the property name and beandesc map mapping 25 | * @version V1.0 26 | * @author XiaoXunYao 27 | * @since 2021-10-26 09:35:53 28 | * @param beanClass Bean的类 29 | * @param supplier 对象不存在时创建对象的函数 30 | * @return com.xiaoTools.entity.beanDesc.BeanDesc 31 | */ 32 | public BeanDesc getBeanDesc(Class beanClass, CacheFun supplier){ 33 | return bdCache.get(beanClass, supplier); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/entity/dynaBeanValueProvider/DynaBeanValueProvider.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.entity.dynaBeanValueProvider; 2 | 3 | import java.lang.reflect.Type; 4 | 5 | import com.xiaoTools.core.convert.Convert; 6 | import com.xiaoTools.entity.dynaBean.DynaBean; 7 | import com.xiaoTools.entity.valueProvider.ValueProvider; 8 | 9 | /** 10 | * [Bean的值提供者](Value provider for bean) 11 | * @description zh - Bean的值提供者 12 | * @description en - Value provider for bean 13 | * @version V1.0 14 | * @author XiaoXunYao 15 | * @since 2021-10-27 19:04:44 16 | */ 17 | public class DynaBeanValueProvider implements ValueProvider { 18 | 19 | private final DynaBean dynaBean; 20 | private final boolean ignoreError; 21 | 22 | public DynaBeanValueProvider(DynaBean dynaBean, boolean ignoreError) { 23 | this.dynaBean = dynaBean; 24 | this.ignoreError = ignoreError; 25 | } 26 | 27 | @Override 28 | public Object value(String key, Type valueType) { 29 | final Object value = dynaBean.get(key); 30 | return Convert.convertWithCheck(valueType, value, null, this.ignoreError); 31 | } 32 | 33 | @Override 34 | public boolean containsKey(String key) { 35 | return dynaBean.containsProp(key); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/test/java/com/xiaoTools/util/IdUtilTest/IdUtilTest.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.util.IdUtilTest; 2 | 3 | import com.xiaoTools.util.IdUtil.IdUtil; 4 | import com.xiaoTools.util.IdUtil.snowflake.Snowflake; 5 | 6 | import org.junit.Test; 7 | 8 | public class IdUtilTest { 9 | 10 | @Test 11 | public void test_UUID(){ 12 | // simpleUUID --> 2126330ed4bd4e5aa09085cacc27575f 13 | System.out.println( "simpleUUID --> " + IdUtil.simpleUUID()); 14 | // fastUUID --> d52a62c9-2f88-4c1f-8989-115985b00c58 15 | System.out.println( "fastUUID --> " + IdUtil.fastUUID()); 16 | // randomUUID --> 80dee6b8-f0f4-4ed4-adb0-d5692104aefe 17 | System.out.println( "randomUUID --> " + IdUtil.randomUUID()); 18 | // fastSimpleUUID --> accf9816b58a413caf851b58427fcd02 19 | System.out.println( "fastSimpleUUID --> " + IdUtil.fastSimpleUUID()); 20 | 21 | } 22 | 23 | @Test 24 | public void test_objectId(){ 25 | // objectId --> 61861d37-508ef630-2a5f8662 26 | System.out.println( "objectId --> " + IdUtil.objectId()); 27 | } 28 | 29 | @Test 30 | public void test_(){ 31 | Snowflake a = IdUtil.createSnowflakeId(11, 1); 32 | // SnowflakeId --> 654365844147933184 33 | System.out.println( "SnowflakeId --> " + a.nextId()); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/exception/comparatorException/ComparatorException.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.exception.comparatorException; 2 | 3 | import com.xiaoTools.util.exceptionUtil.ExceptionUtil; 4 | import com.xiaoTools.util.strUtil.StrUtil; 5 | 6 | /** 7 | * [比较器异常](Comparator exception) 8 | * @description zh - 比较器异常 9 | * @description en - Comparator exception 10 | * @version V1.0 11 | * @author XiaoXunYao 12 | * @since 2021-10-25 08:40:29 13 | */ 14 | public class ComparatorException extends RuntimeException { 15 | private static final long serialVersionUID = 4475602435485521971L; 16 | 17 | public ComparatorException(Throwable e) { 18 | super(ExceptionUtil.getMessage(e), e); 19 | } 20 | 21 | public ComparatorException(String message) { 22 | super(message); 23 | } 24 | 25 | public ComparatorException(String messageTemplate, Object... params) { 26 | super(StrUtil.format(messageTemplate, params)); 27 | } 28 | 29 | public ComparatorException(String message, Throwable throwable) { 30 | super(message, throwable); 31 | } 32 | 33 | public ComparatorException(Throwable throwable, String messageTemplate, Object... params) { 34 | super(StrUtil.format(messageTemplate, params), throwable); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/entity/pinyinComparator/PinyinComparator.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.entity.pinyinComparator; 2 | 3 | import java.io.Serializable; 4 | import java.text.Collator; 5 | import java.util.Comparator; 6 | import java.util.Locale; 7 | 8 | /** 9 | * [按照GBK拼音顺序对给定的汉字字符串排序](Sort the given Chinese character string according to GBK Pinyin order) 10 | * @description: zh - 按照GBK拼音顺序对给定的汉字字符串排序 11 | * @description: en - Sort the given Chinese character string according to GBK Pinyin order 12 | * @version: V1.0 13 | * @author XiaoXunYao 14 | * @since 2021/6/21 9:27 上午 15 | */ 16 | public class PinyinComparator implements Comparator, Serializable { 17 | private static final long serialVersionUID = 1L; 18 | 19 | final Collator collator; 20 | 21 | /** 22 | * [构造](structure) 23 | * @description: zh - 构造 24 | * @description: en - structure 25 | * @version: V1.0 26 | * @author XiaoXunYao 27 | * @since 2021/6/21 9:27 上午 28 | */ 29 | public PinyinComparator() { 30 | collator = Collator.getInstance(Locale.CHINESE); 31 | } 32 | 33 | @Override 34 | public int compare(String o1, String o2) { 35 | return collator.compare(o1, o2); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/convert/typeReference/TypeReference.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.convert.typeReference; 2 | 3 | import com.xiaoTools.util.typeUtil.TypeUtil; 4 | 5 | import java.lang.reflect.Type; 6 | 7 | /** 8 | * [Type类型参考](Type reference) 9 | * @description: zh - Type类型参考 10 | * @description: en - Type reference 11 | * @version: V1.0 12 | * @author XiaoXunYao 13 | * @since 2021/6/24 7:39 下午 14 | */ 15 | public abstract class TypeReference implements Type { 16 | 17 | 18 | /** 19 | * 泛型参数 20 | */ 21 | private final Type type; 22 | 23 | /** 24 | * 构造 25 | */ 26 | public TypeReference() { 27 | this.type = TypeUtil.getTypeArgument(getClass()); 28 | } 29 | 30 | /** 31 | * [获取用户定义的泛型参数](Gets a user-defined generic parameter) 32 | * @description: zh - 获取用户定义的泛型参数 33 | * @description: en - Gets a user-defined generic parameter 34 | * @version: V1.0 35 | * @author XiaoXunYao 36 | * @since 2021/6/24 7:41 下午 37 | * @return java.lang.reflect.Type 38 | */ 39 | public Type getType() { 40 | return this.type; 41 | } 42 | 43 | @Override 44 | public String toString() { 45 | return this.type.toString(); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/exception/dateException/DateException.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.exception.dateException; 2 | 3 | import com.xiaoTools.util.exceptionUtil.ExceptionUtil; 4 | import com.xiaoTools.util.strUtil.StrUtil; 5 | 6 | import java.io.Serial; 7 | 8 | /** 9 | * [日期异常](Date exception) 10 | * @description: zh - 日期异常 11 | * @description: en - Date exception 12 | * @version: V1.0 13 | * @author XiaoXunYao 14 | * @since 2021/6/18 2:46 下午 15 | */ 16 | public class DateException extends RuntimeException{ 17 | 18 | @Serial 19 | private static final long serialVersionUID = 8247610319171014183L; 20 | 21 | public DateException(Throwable e) { 22 | super(ExceptionUtil.getMessage(e), e); 23 | } 24 | 25 | public DateException(String message) { 26 | super(message); 27 | } 28 | 29 | public DateException(String messageTemplate, Object... params) { 30 | super(StrUtil.format(messageTemplate, params)); 31 | } 32 | 33 | public DateException(String message, Throwable throwable) { 34 | super(message, throwable); 35 | } 36 | 37 | public DateException(Throwable throwable, String messageTemplate, Object... params) { 38 | super(StrUtil.format(messageTemplate, params), throwable); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/exception/utilException/UtilException.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.exception.utilException; 2 | 3 | import com.xiaoTools.util.exceptionUtil.ExceptionUtil; 4 | import com.xiaoTools.util.strUtil.StrUtil; 5 | 6 | import java.io.Serial; 7 | 8 | /** 9 | * [工具类异常](Tool class exception) 10 | * @description: zh - 工具类异常 11 | * @description: en - Tool class exception 12 | * @version: V1.0 13 | * @author XiaoXunYao 14 | * @since 2021/6/16 10:26 上午 15 | */ 16 | public class UtilException extends RuntimeException{ 17 | @Serial 18 | private static final long serialVersionUID = 8247610319171014183L; 19 | 20 | public UtilException(Throwable e) { 21 | super(ExceptionUtil.getMessage(e), e); 22 | } 23 | 24 | public UtilException(String message) { 25 | super(message); 26 | } 27 | 28 | public UtilException(String messageTemplate, Object... params) { 29 | super(StrUtil.format(messageTemplate, params)); 30 | } 31 | 32 | public UtilException(String message, Throwable throwable) { 33 | super(message, throwable); 34 | } 35 | 36 | public UtilException(Throwable throwable, String messageTemplate, Object... params) { 37 | super(StrUtil.format(messageTemplate, params), throwable); 38 | } 39 | 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/collection/iteratorEnumeration/IteratorEnumeration.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.collection.iteratorEnumeration; 2 | 3 | import java.io.Serializable; 4 | import java.util.Enumeration; 5 | import java.util.Iterator; 6 | 7 | /** 8 | * [Iterator 对象转 Enumeration](Iterator object to Enumeration) 9 | * @description zh - Iterator 对象转 Enumeration 10 | * @description en - Iterator object to Enumeration 11 | * @version V1.0 12 | * @author XiaoXunYao 13 | * @since 2021-09-01 16:48:30 14 | */ 15 | public class IteratorEnumeration implements Enumeration, Serializable { 16 | private static final long serialVersionUID = 1L; 17 | 18 | /** 19 | * Iterator 20 | */ 21 | private final Iterator iterator; 22 | 23 | /** 24 | * [构造](structure) 25 | * @description zh - 构造 26 | * @description en - structure 27 | * @version V1.0 28 | * @author XiaoXunYao 29 | * @since 2021-09-01 16:50:26 30 | * @param iterator Iterator 31 | */ 32 | public IteratorEnumeration(Iterator iterator) { 33 | this.iterator = iterator; 34 | } 35 | 36 | @Override 37 | public boolean hasMoreElements() { 38 | return iterator.hasNext(); 39 | } 40 | 41 | @Override 42 | public E nextElement() { 43 | return iterator.next(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/test/java/com/xiaoTools/util/NumUtilTest/NumUtilTest.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.util.NumUtilTest; 2 | 3 | import com.xiaoTools.util.numUtil.NumUtil; 4 | 5 | import org.junit.Test; 6 | 7 | public class NumUtilTest { 8 | 9 | @Test 10 | public void basic_operation(){ 11 | // addition 12 | double a = NumUtil.addition(1.2, 2.3); 13 | // 1.2 + 2.3 = 3.5 14 | System.out.println( "1.2 + 2.3 = " + a); 15 | 16 | // subtraction 17 | double b = NumUtil.subtraction(3.2, 2.1); 18 | // 3.2 - 2.1 = 1.1 19 | System.out.println( "3.2 - 2.1 = " + b); 20 | 21 | // multiple 22 | double c = NumUtil.multiplication(2.3, 4.0); 23 | // 2.3 * 4.0 = 9.2 24 | System.out.println( "2.3 * 4.0 = " + c); 25 | 26 | // division 27 | double d = NumUtil.division(4.2,2.0); 28 | // 4.2 / 2.0 = 2.1 29 | System.out.println( "4.2 / 2.0 = " + d ); 30 | } 31 | 32 | @Test 33 | public void test_retainDecimalPoint(){ 34 | double a = 123456.123456; 35 | double b = NumUtil.retainDecimalPoint(a,2); 36 | // 123456.12 37 | System.out.println(b); 38 | } 39 | 40 | @Test 41 | public void test_roman(){ 42 | // 18 to roman --> XVIII 43 | System.out.println("18 to roman --> " + NumUtil.intToRoman(18)); 44 | // X to int --> 10 45 | System.out.println("X to int --> " + NumUtil.romanToInt("X")); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/cache/asciiStrCache/AsciiStrCache.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.cache.asciiStrCache; 2 | 3 | import com.xiaoTools.lang.constant.Constant; 4 | 5 | /** 6 | * [ASCII字符对应的字符串缓存](String cache for ASCII characters) 7 | * @description: zh - ASCII字符对应的字符串缓存 8 | * @description: en - String cache for ASCII characters 9 | * @version: V1.0 10 | * @author XiaoXunYao 11 | * @since 2021/6/17 3:06 下午 12 | */ 13 | public class AsciiStrCache { 14 | 15 | private static final String[] CACHE = new String[Constant.ONE_TWO_EIGHT]; 16 | 17 | static { 18 | for (char c = 0; c < Constant.ONE_TWO_EIGHT; c++) { 19 | CACHE[c] = String.valueOf(c); 20 | } 21 | } 22 | 23 | /** 24 | * [字符转为字符串,如果为ASCII字符,使用缓存](The character is converted to a string. If it is an ASCII character, the cache is used) 25 | * @description: zh - 字符转为字符串,如果为ASCII字符,使用缓存 26 | * @description: en - The character is converted to a string. If it is an ASCII character, the cache is used 27 | * @version: V1.0 28 | * @author XiaoXunYao 29 | * @since 2021/6/17 3:07 下午 30 | * @param c: 字符 31 | * @return java.lang.String 32 | */ 33 | public static String toString(char c) { 34 | return c < Constant.ONE_TWO_EIGHT ? CACHE[c] : String.valueOf(c); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/date/leven/Level.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.date.leven; 2 | 3 | import com.xiaoTools.lang.constant.Constant; 4 | 5 | public enum Level { 6 | 7 | /** 8 | * 天 9 | */ 10 | DAY(Constant.STRING_DAY), 11 | /** 12 | * 小时 13 | */ 14 | HOUR(Constant.STRING_HOUSE), 15 | /** 16 | * 分钟 17 | */ 18 | MINUTE(Constant.STRING_MINUTE), 19 | /** 20 | * 秒 21 | */ 22 | SECOND(Constant.STRING_SECOND), 23 | /** 24 | * 毫秒 25 | */ 26 | MILLISECOND(Constant.STRING_MILLISECOND); 27 | 28 | /** 29 | * 级别名称 30 | */ 31 | private final String name; 32 | 33 | /** 34 | * [构造](structure) 35 | * @description: zh - 构造 36 | * @description: en - structure 37 | * @version: V1.0 38 | * @author XiaoXunYao 39 | * @since 2021/6/18 6:21 下午 40 | * @param name: 级别名称 41 | */ 42 | Level(String name) { 43 | this.name = name; 44 | } 45 | 46 | /** 47 | * [获取级别名称](Get level name) 48 | * @description: zh - 获取级别名称 49 | * @description: en - Get level name 50 | * @version: V1.0 51 | * @author XiaoXunYao 52 | * @since 2021/6/18 6:21 下午 53 | * @return java.lang.String 54 | */ 55 | public String getName() { 56 | return this.name; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/convert/atomicReferenceConverter/AtomicReferenceConverter.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.convert.atomicReferenceConverter; 2 | 3 | import java.lang.reflect.Type; 4 | import java.util.concurrent.atomic.AtomicReference; 5 | 6 | import com.xiaoTools.core.convert.abstractConverter.AbstractConverter; 7 | import com.xiaoTools.core.convert.converterRegistry.ConverterRegistry; 8 | import com.xiaoTools.util.typeUtil.TypeUtil; 9 | 10 | /** 11 | * [AtomicReference转换器](Atomicreference converter) 12 | * @description zh - AtomicReference转换器 13 | * @description en - Atomicreference converter 14 | * @version V1.0 15 | * @author XiaoXunYao 16 | * @since 2021-10-20 16:39:14 17 | */ 18 | @SuppressWarnings("rawtypes") 19 | public class AtomicReferenceConverter extends AbstractConverter { 20 | private static final long serialVersionUID = 1L; 21 | 22 | @Override 23 | protected AtomicReference convertInternal(Object value) { 24 | 25 | Object targetValue = null; 26 | final Type paramType = TypeUtil.getTypeArgument(AtomicReference.class); 27 | if(false == TypeUtil.isUnknown(paramType)){ 28 | targetValue = ConverterRegistry.getInstance().convert(paramType, value); 29 | } 30 | if(null == targetValue){ 31 | targetValue = value; 32 | } 33 | 34 | return new AtomicReference<>(targetValue); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/exception/cLoneRuntimeException/CloneRuntimeException.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.exception.cLoneRuntimeException; 2 | 3 | import com.xiaoTools.util.exceptionUtil.ExceptionUtil; 4 | import com.xiaoTools.util.strUtil.StrUtil; 5 | 6 | import java.io.Serial; 7 | 8 | /** 9 | * [克隆异常](Clone exception) 10 | * @description: zh - 克隆异常 11 | * @description: en - Clone exception 12 | * @version: V1.0 13 | * @author XiaoXunYao 14 | * @since 2021/6/19 9:56 上午 15 | */ 16 | public class CloneRuntimeException extends RuntimeException{ 17 | @Serial 18 | private static final long serialVersionUID = 6774837422188798989L; 19 | 20 | public CloneRuntimeException(Throwable e) { 21 | super(ExceptionUtil.getMessage(e), e); 22 | } 23 | 24 | public CloneRuntimeException(String message) { 25 | super(message); 26 | } 27 | 28 | public CloneRuntimeException(String messageTemplate, Object... params) { 29 | super(StrUtil.format(messageTemplate, params)); 30 | } 31 | 32 | public CloneRuntimeException(String message, Throwable throwable) { 33 | super(message, throwable); 34 | } 35 | 36 | public CloneRuntimeException(Throwable throwable, String messageTemplate, Object... params) { 37 | super(StrUtil.format(messageTemplate, params), throwable); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/convert/localeConverte/LocaleConverter.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.convert.localeConverte; 2 | 3 | import java.util.Locale; 4 | 5 | import com.xiaoTools.core.convert.abstractConverter.AbstractConverter; 6 | import com.xiaoTools.lang.constant.Constant; 7 | import com.xiaoTools.util.strUtil.StrUtil; 8 | 9 | /** 10 | * [Locale对象转换器](Locale Object Converter) 11 | * @description zh - Locale对象转换器 12 | * @description en - Locale Object Converter 13 | * @version V1.0 14 | * @author XiaoXunYao 15 | * @since 2021-10-20 16:52:11 16 | */ 17 | public class LocaleConverter extends AbstractConverter { 18 | private static final long serialVersionUID = 1L; 19 | 20 | @Override 21 | protected Locale convertInternal(Object value) { 22 | try { 23 | String str = convertToStr(value); 24 | if (StrUtil.isEmpty(str)) { 25 | return null; 26 | } 27 | 28 | final String[] items = str.split("_"); 29 | if (items.length == Constant.ONE) { 30 | return new Locale(items[Constant.ZERO]); 31 | } 32 | if (items.length == Constant.TWO) { 33 | return new Locale(items[Constant.ZERO], items[Constant.ONE]); 34 | } 35 | return new Locale(items[Constant.ZERO], items[Constant.ONE], items[Constant.TWO]); 36 | } catch (Exception e) { 37 | // Ignore Exception 38 | } 39 | return null; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/convert/stackTraceElementConverter/StackTraceElementConverter.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.convert.stackTraceElementConverter; 2 | 3 | import java.util.Map; 4 | 5 | import com.xiaoTools.core.convert.abstractConverter.AbstractConverter; 6 | import com.xiaoTools.util.mapUtil.MapUtil; 7 | import com.xiaoTools.util.objectUtil.ObjectUtil; 8 | 9 | /** 10 | * [StackTraceElement转换器](StackTraceElement converter) 11 | * @description zh - StackTraceElement转换器 12 | * @description en - StackTraceElement converter 13 | * @version V1.0 14 | * @author XiaoXunYao 15 | * @since 2021-10-20 17:05:06 16 | */ 17 | public class StackTraceElementConverter extends AbstractConverter { 18 | private static final long serialVersionUID = 1L; 19 | 20 | @Override 21 | protected StackTraceElement convertInternal(Object value) { 22 | if (value instanceof Map) { 23 | final Map map = (Map) value; 24 | 25 | final String declaringClass = MapUtil.getStr(map, "className"); 26 | final String methodName = MapUtil.getStr(map, "methodName"); 27 | final String fileName = MapUtil.getStr(map, "fileName"); 28 | final Integer lineNumber = MapUtil.getInt(map, "lineNumber"); 29 | 30 | return new StackTraceElement(declaringClass, methodName, fileName, ObjectUtil.defaultIfNull(lineNumber, 0)); 31 | } 32 | return null; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/util/spliteratorUtil/SpliteratorUtil.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.util.spliteratorUtil; 2 | 3 | import java.util.Spliterator; 4 | import java.util.function.Function; 5 | 6 | import com.xiaoTools.core.collection.transSpliterator.TransSpliterator; 7 | 8 | /** 9 | * [Spliterator相关工具类](Splitter related tool classes) 10 | * @description zh - Spliterator相关工具类 11 | * @description en - Splitter related tool classes 12 | * @version V1.0 13 | * @author XiaoXunYao 14 | * @since 2021-10-21 12:45:27 15 | */ 16 | public class SpliteratorUtil { 17 | 18 | /** 19 | * 使用给定的转换函数,转换源{@link Spliterator}为新类型的{@link Spliterator} 20 | * 21 | * @param 源元素类型 22 | * @param 目标元素类型 23 | * @param fromSpliterator 源{@link Spliterator} 24 | * @param function 转换函数 25 | * @return 新类型的{@link Spliterator} 26 | */ 27 | /** 28 | * [使用给定的转换函数](Use the given conversion function) 29 | * @description zh - 使用给定的转换函数 30 | * @description en - Use the given conversion function 31 | * @version V1.0 32 | * @author XiaoXunYao 33 | * @since 2021-10-21 12:44:41 34 | * @param fromSpliterator 源 35 | * @param function 转换函数 36 | * @return java.util.Spliterator 37 | */ 38 | public static Spliterator trans(Spliterator fromSpliterator, Function function) { 39 | return new TransSpliterator<>(fromSpliterator, function); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/cache/simple/method/CacheFun.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.cache.simple.method; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * [无参数的函数对象](Function object without parameters) 7 | * @description: zh - 无参数的函数对象 8 | * @description: en - Function object without parameters 9 | * @version: V1.0 10 | * @author XiaoXunYao 11 | * @since 2021/6/13 7:19 下午 12 | */ 13 | @FunctionalInterface 14 | public interface CacheFun extends Serializable { 15 | /** 16 | * [执行函数](Executive function) 17 | * @description: zh - 执行函数 18 | * @description: en - Executive function 19 | * @version: V1.0 20 | * @author XiaoXunYao 21 | * @since 2021/6/13 7:21 下午 22 | * @throws Exception 异常 23 | * @return R 24 | */ 25 | R call() throws Exception; 26 | 27 | /** 28 | * [执行函数,异常包装为RuntimeException](Execute the function and wrap the exception as RuntimeException) 29 | * @description: zh - 执行函数,异常包装为RuntimeException 30 | * @description: en - Execute the function and wrap the exception as RuntimeException 31 | * @version: V1.0 32 | * @author XiaoXunYao 33 | * @since 2021/6/13 7:22 下午 34 | * @return R 35 | */ 36 | default R callWithRuntimeException(){ 37 | try { 38 | return call(); 39 | } catch (Exception e) { 40 | throw new RuntimeException(e); 41 | } 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/collection/copiedIter/CopiedIter.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.collection.copiedIter; 2 | 3 | import java.io.Serializable; 4 | import java.util.Iterator; 5 | import java.util.List; 6 | 7 | import com.xiaoTools.util.collUtil.CollUtil; 8 | 9 | /** 10 | * [复制Iterator](Copy iterator) 11 | * @description zh - 复制Iterator 12 | * @description en - Copy iterator 13 | * @version V1.0 14 | * @author XiaoXunYao 15 | * @since 2021-10-21 18:07:28 16 | */ 17 | public class CopiedIter implements Iterator, Iterable, Serializable { 18 | private static final long serialVersionUID = 1L; 19 | 20 | private final Iterator listIterator; 21 | 22 | public static CopiedIter copyOf(Iterator iterator){ 23 | return new CopiedIter<>(iterator); 24 | } 25 | 26 | public CopiedIter(Iterator iterator) { 27 | final List eleList = CollUtil.newArrayList(iterator); 28 | this.listIterator = eleList.iterator(); 29 | } 30 | 31 | @Override 32 | public boolean hasNext() { 33 | return this.listIterator.hasNext(); 34 | } 35 | 36 | @Override 37 | public E next() { 38 | return this.listIterator.next(); 39 | } 40 | 41 | @Override 42 | public void remove() throws UnsupportedOperationException{ 43 | throw new UnsupportedOperationException("This is a read-only iterator."); 44 | } 45 | 46 | @Override 47 | public Iterator iterator() { 48 | return this; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/map/caseInsensitiveMap/CaseInsensitiveMap.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.map.caseInsensitiveMap; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import com.xiaoTools.core.map.customKeyMap.CustomKeyMap; 7 | 8 | /** 9 | * [忽略大小写的Map](Ignore uppercase and lowercase maps) 10 | * @description zh - 忽略大小写的Map 11 | * @description en - Ignore uppercase and lowercase maps 12 | * @version V1.0 13 | * @author XiaoXunYao 14 | * @since 2021-10-26 20:13:15 15 | */ 16 | public class CaseInsensitiveMap extends CustomKeyMap { 17 | 18 | private static final long serialVersionUID = 4043263744224569870L; 19 | 20 | public CaseInsensitiveMap() { 21 | this(DEFAULT_INITIAL_CAPACITY); 22 | } 23 | 24 | public CaseInsensitiveMap(int initialCapacity) { 25 | this(initialCapacity, DEFAULT_LOAD_FACTOR); 26 | } 27 | 28 | public CaseInsensitiveMap(Map m) { 29 | this(DEFAULT_LOAD_FACTOR, m); 30 | } 31 | 32 | public CaseInsensitiveMap(float loadFactor, Map m) { 33 | this(m.size(), loadFactor); 34 | this.putAll(m); 35 | } 36 | 37 | public CaseInsensitiveMap(int initialCapacity, float loadFactor) { 38 | super(new HashMap<>(initialCapacity, loadFactor)); 39 | } 40 | 41 | @Override 42 | protected Object customKey(Object key) { 43 | if (key instanceof CharSequence) { 44 | key = key.toString().toLowerCase(); 45 | } 46 | return key; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/date/format/basic/DateBasic.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.date.format.basic; 2 | 3 | import java.util.Locale; 4 | import java.util.TimeZone; 5 | 6 | /** 7 | * [日期基本信息获取接口](Date basic information acquisition interface) 8 | * @description: zh - 日期基本信息获取接口 9 | * @description: en - Date basic information acquisition interface 10 | * @version: V1.0 11 | * @author XiaoXunYao 12 | * @since 2021/6/19 7:58 上午 13 | */ 14 | public interface DateBasic { 15 | 16 | /** 17 | * [获得日期格式化或者转换的格式](Get the format of date formatting or conversion) 18 | * @description: zh - 获得日期格式化或者转换的格式 19 | * @description: en - Get the format of date formatting or conversion 20 | * @version: V1.0 21 | * @author XiaoXunYao 22 | * @since 2021/6/19 7:58 上午 23 | * @return java.lang.String 24 | */ 25 | String getPattern(); 26 | 27 | /** 28 | * [获得时区](Get time zone) 29 | * @description: zh - 获得时区 30 | * @description: en - Get time zone 31 | * @version: V1.0 32 | * @author XiaoXunYao 33 | * @since 2021/6/19 8:05 上午 34 | * @return java.util.TimeZone 35 | */ 36 | TimeZone getTimeZone(); 37 | 38 | /** 39 | * [获得 日期地理位置](Get date location) 40 | * @description: zh - 获得 日期地理位置 41 | * @description: en - Get date location 42 | * @version: V1.0 43 | * @author XiaoXunYao 44 | * @since 2021/6/19 8:05 上午 45 | * @return java.util.Locale 46 | */ 47 | Locale getLocale(); 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/collection/enumerationIter/EnumerationIter.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.collection.enumerationIter; 2 | 3 | import java.io.Serializable; 4 | import java.util.Enumeration; 5 | import java.util.Iterator; 6 | 7 | /** 8 | * [Enumeration 对象转 Iterator 对象](Enumeration object to iterator object) 9 | * @description zh - Enumeration 对象转 Iterator 对象 10 | * @description en - Enumeration object to iterator object 11 | * @version V1.0 12 | * @author XiaoXunYao 13 | * @since 2021-09-01 17:11:39 14 | */ 15 | public class EnumerationIter implements Iterator, Iterable, Serializable { 16 | private static final long serialVersionUID = 1L; 17 | 18 | private final Enumeration enumeration; 19 | 20 | /** 21 | * [构造](structure) 22 | * @description zh - 构造 23 | * @description en - structure 24 | * @version V1.0 25 | * @author XiaoXunYao 26 | * @since 2021-09-01 17:13:07 27 | * @param enumeration Enumeration 28 | */ 29 | public EnumerationIter(Enumeration enumeration) { 30 | this.enumeration = enumeration; 31 | } 32 | 33 | @Override 34 | public boolean hasNext() { 35 | return enumeration.hasMoreElements(); 36 | } 37 | 38 | @Override 39 | public E next() { 40 | return enumeration.nextElement(); 41 | } 42 | 43 | @Override 44 | public void remove() { 45 | throw new UnsupportedOperationException(); 46 | } 47 | 48 | @Override 49 | public Iterator iterator() { 50 | return this; 51 | } 52 | 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/entity/nullWrapperEntity/NullWrapperEntity.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.entity.nullWrapperEntity; 2 | 3 | /** 4 | * [为了解决反射过程中,需要传递null参数,但是会丢失参数类型而设立的包装类](In order to solve the problem of reflection, you need to pass null parameter, but you will lose the wrapper class set by parameter type) 5 | * @description: zh - 为了解决反射过程中,需要传递null参数,但是会丢失参数类型而设立的包装类 6 | * @description: en - In order to solve the problem of reflection, you need to pass null parameter, but you will lose the wrapper class set by parameter type 7 | * @version: V1.0 8 | * @author XiaoXunYao 9 | * @since 2021/6/17 9:06 上午 10 | */ 11 | public class NullWrapperEntity { 12 | 13 | private final Class clazz; 14 | 15 | /** 16 | * [有参函数](Parametric function) 17 | * @description: zh - 有参函数 18 | * @description: en - Parametric function 19 | * @version: V1.0 20 | * @author XiaoXunYao 21 | * @since 2021/6/17 9:07 上午 22 | * @param clazz: 类 23 | */ 24 | public NullWrapperEntity(Class clazz) { 25 | this.clazz = clazz; 26 | } 27 | 28 | /** 29 | * [获取null值对应的类型](Gets the type corresponding to the null value) 30 | * @description: zh - 获取null值对应的类型 31 | * @description: en - Gets the type corresponding to the null value 32 | * @version: V1.0 33 | * @author XiaoXunYao 34 | * @since 2021/6/17 9:07 上午 35 | * @return java.lang.Class 36 | */ 37 | public Class getWrappedClass() { 38 | return clazz; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/util/regularUtil/method/Func1.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.util.regularUtil.method; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * [只有一个参数的函数对象](Function object with only one argument) 7 | * @description: zh - 只有一个参数的函数对象 8 | * @description: en - Function object with only one argument 9 | * @version: V1.0 10 | * @author XiaoXunYao 11 | * @since 2021/6/22 11:03 上午 12 | */ 13 | @FunctionalInterface 14 | public interface Func1 extends Serializable { 15 | 16 | /** 17 | * [执行函数](Executive function) 18 | * @description: zh - 执行函数 19 | * @description: en - Executive function 20 | * @version: V1.0 21 | * @author XiaoXunYao 22 | * @since 2021/6/22 10:55 上午 23 | * @param parameter: 参数 24 | * @throws Exception 25 | * @return R 26 | */ 27 | R call(P parameter) throws Exception; 28 | 29 | /** 30 | * [执行函数,异常包装为RuntimeException](Execute the function and wrap the exception as runtimeException) 31 | * @description: zh - 执行函数,异常包装为RuntimeException 32 | * @description: en - Execute the function and wrap the exception as runtimeException 33 | * @version: V1.0 34 | * @author XiaoXunYao 35 | * @since 2021/6/22 11:02 上午 36 | * @param parameter: 参数 37 | * @return R 38 | */ 39 | default R callWithRuntimeException(P parameter){ 40 | try { 41 | return call(parameter); 42 | } catch (Exception e) { 43 | throw new RuntimeException(e); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/exception/iORuntimeException/IORuntimeException.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.exception.iORuntimeException; 2 | 3 | import com.xiaoTools.util.exceptionUtil.ExceptionUtil; 4 | import com.xiaoTools.util.strUtil.StrUtil; 5 | 6 | /** 7 | * [IO运行时异常,常用于对IOException的包装](IO runtime exception, which is often used to wrap IOException) 8 | * @description zh - IO运行时异常,常用于对IOException的包装 9 | * @description en - IO runtime exception, which is often used to wrap IOException 10 | * @version V1.0 11 | * @author XiaoXunYao 12 | * @since 2021-10-22 12:39:51 13 | */ 14 | public class IORuntimeException extends RuntimeException { 15 | 16 | private static final long serialVersionUID = 8247610319171014183L; 17 | 18 | public IORuntimeException(Throwable e) { 19 | super(ExceptionUtil.getMessage(e), e); 20 | } 21 | 22 | public IORuntimeException(String message) { 23 | super(message); 24 | } 25 | 26 | public IORuntimeException(String messageTemplate, Object... params) { 27 | super(StrUtil.format(messageTemplate, params)); 28 | } 29 | 30 | public IORuntimeException(String message, Throwable throwable) { 31 | super(message, throwable); 32 | } 33 | 34 | public IORuntimeException(Throwable throwable, String messageTemplate, Object... params) { 35 | super(StrUtil.format(messageTemplate, params), throwable); 36 | } 37 | 38 | public boolean causeInstanceOf(Class clazz) { 39 | final Throwable cause = this.getCause(); 40 | return null != clazz && clazz.isInstance(cause); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/util/dataSizeUtil/DataSizeUtil.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.util.dataSizeUtil; 2 | 3 | import java.text.DecimalFormat; 4 | 5 | import com.xiaoTools.core.io.dataSize.DataSize; 6 | import com.xiaoTools.core.io.dataUnit.DataUnit; 7 | 8 | /** 9 | * [数据大小工具类](Data size utility class) 10 | * @description zh - 数据大小工具类 11 | * @description en - Data size utility class 12 | * @version V1.0 13 | * @author XiaoXunYao 14 | * @since 2021-10-29 22:07:02 15 | */ 16 | public class DataSizeUtil { 17 | 18 | /** 19 | * [解析数据大小字符串](Parse data size string) 20 | * @description zh - 解析数据大小字符串 21 | * @description en - Parse data size string 22 | * @version V1.0 23 | * @author XiaoXunYao 24 | * @since 2021-10-29 22:07:25 25 | * @param text 数据大小字符串 26 | * @return long 27 | */ 28 | public static long parse(String text) { 29 | return DataSize.parse(text).toBytes(); 30 | } 31 | 32 | /** 33 | * [可读的文件大小](Readable file size) 34 | * @description zh - 可读的文件大小 35 | * @description en - Readable file size 36 | * @version V1.0 37 | * @author XiaoXunYao 38 | * @since 2021-10-29 22:07:59 39 | * @param size Long类型大小 40 | * @return java.lang.String 41 | */ 42 | public static String format(long size) { 43 | if (size <= 0) { 44 | return "0"; 45 | } 46 | int digitGroups = Math.min(DataUnit.UNIT_NAMES.length-1, (int) (Math.log10(size) / Math.log10(1024))); 47 | return new DecimalFormat("#,##0.##") 48 | .format(size / Math.pow(1024, digitGroups)) + " " + DataUnit.UNIT_NAMES[digitGroups]; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/collection/transSpliterator/TransSpliterator.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.collection.transSpliterator; 2 | 3 | import java.util.Spliterator; 4 | import java.util.function.Consumer; 5 | import java.util.function.Function; 6 | 7 | public class TransSpliterator implements Spliterator { 8 | 9 | private final Spliterator fromSpliterator; 10 | private final Function function; 11 | 12 | public TransSpliterator(Spliterator fromSpliterator, Function function) { 13 | this.fromSpliterator = fromSpliterator; 14 | this.function = function; 15 | } 16 | 17 | @Override 18 | public boolean tryAdvance(Consumer action) { 19 | return fromSpliterator.tryAdvance( 20 | fromElement -> action.accept(function.apply(fromElement))); 21 | } 22 | 23 | @Override 24 | public void forEachRemaining(Consumer action) { 25 | fromSpliterator.forEachRemaining(fromElement -> action.accept(function.apply(fromElement))); 26 | } 27 | 28 | @Override 29 | public Spliterator trySplit() { 30 | Spliterator fromSplit = fromSpliterator.trySplit(); 31 | return (fromSplit != null) ? new TransSpliterator<>(fromSplit, function) : null; 32 | } 33 | 34 | @Override 35 | public long estimateSize() { 36 | return fromSpliterator.estimateSize(); 37 | } 38 | 39 | @Override 40 | public int characteristics() { 41 | return fromSpliterator.characteristics() 42 | & ~(Spliterator.DISTINCT | Spliterator.NONNULL | Spliterator.SORTED); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/exception/noResourceException/NoResourceException.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.exception.noResourceException; 2 | 3 | import com.xiaoTools.core.exception.iORuntimeException.IORuntimeException; 4 | import com.xiaoTools.util.exceptionUtil.ExceptionUtil; 5 | import com.xiaoTools.util.strUtil.StrUtil; 6 | 7 | /** 8 | * [资源文件或资源不存在异常](There is no exception in the resource file or resource) 9 | * @description zh - 资源文件或资源不存在异常 10 | * @description en - There is no exception in the resource file or resource 11 | * @version V1.0 12 | * @author XiaoXunYao 13 | * @since 2021-10-29 09:46:21 14 | */ 15 | public class NoResourceException extends IORuntimeException { 16 | 17 | private static final long serialVersionUID = -623254467603299129L; 18 | 19 | public NoResourceException(Throwable e) { 20 | super(ExceptionUtil.getMessage(e), e); 21 | } 22 | 23 | public NoResourceException(String message) { 24 | super(message); 25 | } 26 | 27 | public NoResourceException(String messageTemplate, Object... params) { 28 | super(StrUtil.format(messageTemplate, params)); 29 | } 30 | 31 | public NoResourceException(String message, Throwable throwable) { 32 | super(message, throwable); 33 | } 34 | 35 | public NoResourceException(Throwable throwable, String messageTemplate, Object... params) { 36 | super(StrUtil.format(messageTemplate, params), throwable); 37 | } 38 | 39 | @Override 40 | public boolean causeInstanceOf(Class clazz) { 41 | final Throwable cause = this.getCause(); 42 | return clazz.isInstance(cause); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/lang/segment/Segment.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.lang.segment; 2 | 3 | import java.lang.reflect.Type; 4 | 5 | import com.xiaoTools.assertion.Assertion; 6 | import com.xiaoTools.core.convert.Convert; 7 | import com.xiaoTools.util.numUtil.NumUtil; 8 | 9 | /** 10 | * [片段表示](Fragment representation) 11 | * @description zh - 片段表示 12 | * @description en - Fragment representation 13 | * @version V1.0 14 | * @author XiaoXunYao 15 | * @since 2021-10-18 12:36:31 16 | */ 17 | public interface Segment { 18 | 19 | /** 20 | * [获取起始位置](Get start position) 21 | * @description zh - 获取起始位置 22 | * @description en - Get start position 23 | * @version V1.0 24 | * @author XiaoXunYao 25 | * @since 2021-10-18 12:38:25 26 | * @return T 27 | */ 28 | T getStartIndex(); 29 | 30 | /** 31 | * [获取结束位置](Get end position) 32 | * @description zh - 获取结束位置 33 | * @description en - Get end position 34 | * @version V1.0 35 | * @author XiaoXunYao 36 | * @since 2021-10-18 12:38:55 37 | * @return T 38 | */ 39 | T getEndIndex(); 40 | 41 | /** 42 | * [片段长度](Fragment length) 43 | * @description zh - 片段长度 44 | * @description en - Fragment length 45 | * @version V1.0 46 | * @author XiaoXunYao 47 | * @since 2021-10-18 12:39:24 48 | * @return T 49 | */ 50 | default T length(){ 51 | final T start = Assertion.notNull(getStartIndex(), "Start index must be not null!"); 52 | final T end = Assertion.notNull(getEndIndex(), "End index must be not null!"); 53 | 54 | return Convert.convert((Type) start.getClass(), NumUtil.subtraction(end, start).abs()); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/io/fileWrapper/FileWrapper.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.io.fileWrapper; 2 | 3 | import java.io.File; 4 | import java.io.Serializable; 5 | import java.nio.charset.Charset; 6 | import java.nio.charset.StandardCharsets; 7 | 8 | import com.xiaoTools.util.fileUtil.fileUtil.FileUtil; 9 | 10 | /** 11 | * [文件包装器](File wrapper) 12 | * @description zh - 文件包装器 13 | * @description en - File wrapper 14 | * @version V1.0 15 | * @author XiaoXunYao 16 | * @since 2021-10-29 21:08:14 17 | */ 18 | public class FileWrapper implements Serializable { 19 | 20 | private static final long serialVersionUID = 1L; 21 | 22 | protected File file; 23 | protected Charset charset; 24 | 25 | /** 26 | * 默认编码:UTF-8 27 | */ 28 | public static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8; 29 | 30 | public FileWrapper(File file, Charset charset) { 31 | this.file = file; 32 | this.charset = charset; 33 | } 34 | 35 | public File getFile() { 36 | return file; 37 | } 38 | 39 | public FileWrapper setFile(File file) { 40 | this.file = file; 41 | return this; 42 | } 43 | 44 | public Charset getCharset() { 45 | return charset; 46 | } 47 | 48 | public FileWrapper setCharset(Charset charset) { 49 | this.charset = charset; 50 | return this; 51 | } 52 | 53 | /** 54 | * [可读的文件大小](Readable file size) 55 | * @description zh - 可读的文件大小 56 | * @description en - Readable file size 57 | * @version V1.0 58 | * @author XiaoXunYao 59 | * @since 2021-10-29 21:11:05 60 | * @return java.lang.String 61 | */ 62 | public String readableFileSize() { 63 | return FileUtil.readableFileSize(file.length()); 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## Description 4 | 5 | 6 | ## Related Issue 7 | 8 | 9 | 10 | 11 | 12 | ## Motivation and Context 13 | 14 | 15 | ## How Has This Been Tested? 16 | 17 | 18 | 19 | 20 | ## Types of changes 21 | 22 | - [ ] Bug fix (non-breaking change which fixes an issue) 23 | - [ ] New feature (non-breaking change which adds functionality) 24 | - [ ] Breaking change (fix or feature that would cause existing functionality to change) 25 | 26 | ## Checklist: 27 | 28 | 29 | - [ ] My code follows the code style of this project. 30 | - [ ] My change requires a change to the documentation. 31 | - [ ] I have updated the documentation accordingly. 32 | - [ ] I have added tests to cover my changes. 33 | - [ ] All new and existing tests passed. -------------------------------------------------------------------------------- /README.markdown: -------------------------------------------------------------------------------- 1 | # xiaoTools 2 | 3 | [![maven-central](https://img.shields.io/maven-central/v/io.github.xiao-organization/xiaoTools.svg)](https://mvnrepository.com/artifact/io.github.xiao-organization/xiaoTools) [![java-doc](https://www.javadoc.io/badge/io.github.xiao-organization/xiaoTools.svg)](https://www.javadoc.io/doc/io.github.xiao-organization/xiaoTools) 4 | 5 | This repository contains simple tools written in 100% Java. 6 | 7 | ## Getting Started 8 | 9 | ### Dependency management tools 10 | 11 | Below is a brief guide to using dependency management tools like Maven or Gradle. 12 | 13 | #### Maven 14 | 15 | To use maven add this dependency to your pom.xml: 16 | 17 | ```xml 18 | 19 | io.github.xiao-organization 20 | xiaoTools 21 | 1.0.1 22 | 23 | ``` 24 | 25 | #### Gradle 26 | 27 | To use Gradle add the Maven central repository to your repositories list: 28 | 29 | ```xml 30 | mavenCentral() 31 | ``` 32 | 33 | Then you can just add the latest version to your build. 34 | 35 | ```xml 36 | implementation 'io.github.xiao-organization:xiaoTools:1.0.1' 37 | ``` 38 | 39 | Standalone jar 40 | If you do not use any dependency management tool, you can find the latest standalone jar [here](https://github.com/xiao-organization/xiaoTools/releases/latest). 41 | 42 | ## Minimum Required JDK 43 | 44 | xiaoTools is known to work with: 45 | 46 | Java 1.8 and higher 47 | 48 | Other JRE implementations may work as well, but haven't been tested. 49 | 50 | ## License 51 | 52 | Everything found in this repo is licensed under an [Apache-2.0 License](https://github.com/xiao-organization/xiaoTools/blob/master/LICENSE). See the `LICENSE` file for specifics. 53 | 54 | 55 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/convert/collectionConverter/CollectionConverter.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.convert.collectionConverter; 2 | 3 | import java.lang.reflect.Type; 4 | import java.util.Collection; 5 | 6 | import com.xiaoTools.core.convert.converter.Converter; 7 | import com.xiaoTools.util.collUtil.CollUtil; 8 | import com.xiaoTools.util.objectUtil.ObjectUtil; 9 | import com.xiaoTools.util.typeUtil.TypeUtil; 10 | 11 | /** 12 | * [各种集合类转换器](Various collection class converters) 13 | * @description zh - 各种集合类转换器 14 | * @description en - Various collection class converters 15 | * @version V1.0 16 | * @author XiaoXunYao 17 | * @since 2021-10-25 08:28:41 18 | */ 19 | public class CollectionConverter implements Converter> { 20 | 21 | /** 22 | * 集合类型 23 | */ 24 | private final Type collectionType; 25 | 26 | /** 27 | * 集合元素类型 28 | */ 29 | private final Type elementType; 30 | 31 | public CollectionConverter(Type collectionType) { 32 | this(collectionType, TypeUtil.getTypeArgument(collectionType)); 33 | } 34 | 35 | public CollectionConverter(Class collectionType) { 36 | this(collectionType, TypeUtil.getTypeArgument(collectionType)); 37 | } 38 | 39 | public CollectionConverter(Type collectionType, Type elementType) { 40 | this.collectionType = collectionType; 41 | this.elementType = elementType; 42 | } 43 | 44 | @Override 45 | public Collection convert(Object value, Collection defaultValue) throws IllegalArgumentException { 46 | final Collection result = convertInternal(value); 47 | return ObjectUtil.defaultIfNull(result, defaultValue); 48 | } 49 | 50 | protected Collection convertInternal(Object value) { 51 | final Collection collection = CollUtil.create(TypeUtil.getClass(this.collectionType)); 52 | return CollUtil.addAll(collection, value, this.elementType); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/convert/referenceConverter/ReferenceConverter.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.convert.referenceConverter; 2 | 3 | import java.lang.ref.Reference; 4 | import java.lang.ref.SoftReference; 5 | import java.lang.ref.WeakReference; 6 | import java.lang.reflect.Type; 7 | 8 | import com.xiaoTools.core.convert.abstractConverter.AbstractConverter; 9 | import com.xiaoTools.core.convert.converterRegistry.ConverterRegistry; 10 | import com.xiaoTools.util.strUtil.StrUtil; 11 | import com.xiaoTools.util.typeUtil.TypeUtil; 12 | 13 | @SuppressWarnings("rawtypes") 14 | public class ReferenceConverter extends AbstractConverter { 15 | private static final long serialVersionUID = 1L; 16 | 17 | private final Class targetType; 18 | 19 | /** 20 | * [构造](structure) 21 | * @description zh - 构造 22 | * @description en - structure 23 | * @version V1.0 24 | * @author XiaoXunYao 25 | * @since 2021-10-20 16:33:31 26 | * @param targetType Reference实现类型 27 | */ 28 | public ReferenceConverter(Class targetType) { 29 | this.targetType = targetType; 30 | } 31 | 32 | @SuppressWarnings("unchecked") 33 | @Override 34 | protected Reference convertInternal(Object value) { 35 | 36 | Object targetValue = null; 37 | final Type paramType = TypeUtil.getTypeArgument(targetType); 38 | if(false == TypeUtil.isUnknown(paramType)){ 39 | targetValue = ConverterRegistry.getInstance().convert(paramType, value); 40 | } 41 | if(null == targetValue){ 42 | targetValue = value; 43 | } 44 | 45 | if(this.targetType == WeakReference.class){ 46 | return new WeakReference(targetValue); 47 | }else if(this.targetType == SoftReference.class){ 48 | return new SoftReference(targetValue); 49 | } 50 | 51 | throw new UnsupportedOperationException(StrUtil.format("Unsupport Reference type: {}", this.targetType.getName())); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/transCollection/TransCollection.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.transCollection; 2 | 3 | import java.util.AbstractCollection; 4 | import java.util.Collection; 5 | import java.util.Iterator; 6 | import java.util.Spliterator; 7 | import java.util.function.Consumer; 8 | import java.util.function.Function; 9 | import java.util.function.Predicate; 10 | 11 | import com.xiaoTools.assertion.Assertion; 12 | import com.xiaoTools.util.iterUtil.IterUtil; 13 | import com.xiaoTools.util.spliteratorUtil.SpliteratorUtil; 14 | 15 | public class TransCollection extends AbstractCollection { 16 | 17 | private final Collection fromCollection; 18 | private final Function function; 19 | 20 | public TransCollection(Collection fromCollection, Function function) { 21 | this.fromCollection = Assertion.notNull(fromCollection); 22 | this.function = Assertion.notNull(function); 23 | } 24 | 25 | @Override 26 | public Iterator iterator() { 27 | return IterUtil.trans(fromCollection.iterator(), function); 28 | } 29 | 30 | @Override 31 | public void clear() { 32 | fromCollection.clear(); 33 | } 34 | 35 | @Override 36 | public boolean isEmpty() { 37 | return fromCollection.isEmpty(); 38 | } 39 | 40 | @Override 41 | public void forEach(Consumer action) { 42 | Assertion.notNull(action); 43 | fromCollection.forEach((f) -> action.accept(function.apply(f))); 44 | } 45 | 46 | @Override 47 | public boolean removeIf(Predicate filter) { 48 | Assertion.notNull(filter); 49 | return fromCollection.removeIf(element -> filter.test(function.apply(element))); 50 | } 51 | 52 | @Override 53 | public Spliterator spliterator() { 54 | return SpliteratorUtil.trans(fromCollection.spliterator(), function); 55 | } 56 | 57 | @Override 58 | public int size() { 59 | return fromCollection.size(); 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/lang/enumItem/EnumItem.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.lang.enumItem; 2 | 3 | import java.io.Serializable; 4 | 5 | public interface EnumItem> extends Serializable { 6 | 7 | String name(); 8 | 9 | default String text() { 10 | return name(); 11 | } 12 | 13 | int intVal(); 14 | 15 | /** 16 | * [获取所有枚举对象](Get all enumerated objects) 17 | * @description zh - 获取所有枚举对象 18 | * @description en - Get all enumerated objects 19 | * @version V1.0 20 | * @author XiaoXunYao 21 | * @since 2021-10-25 08:22:59 22 | * @return E[] 23 | */ 24 | @SuppressWarnings("unchecked") 25 | default E[] items() { 26 | return (E[]) this.getClass().getEnumConstants(); 27 | } 28 | 29 | /** 30 | * [通过int类型值查找其他枚举](Find other enumerations by int type values) 31 | * @description zh - 通过int类型值查找其他枚举 32 | * @description en - Find other enumerations by int type values 33 | * @version V1.0 34 | * @author XiaoXunYao 35 | * @since 2021-10-25 08:22:14 36 | * @param intVal int值 37 | * @return E 38 | */ 39 | default E fromInt(Integer intVal) { 40 | if (intVal == null) { 41 | return null; 42 | } 43 | E[] vs = items(); 44 | for (E enumItem : vs) { 45 | if (enumItem.intVal() == intVal) { 46 | return enumItem; 47 | } 48 | } 49 | return null; 50 | } 51 | 52 | /** 53 | * [通过String类型的值转换](Value conversion through string type) 54 | * @description zh - 通过String类型的值转换 55 | * @description en - Value conversion through string type 56 | * @version V1.0 57 | * @author XiaoXunYao 58 | * @since 2021-10-25 08:21:42 59 | * @param strVal String值 60 | * @return E 61 | */ 62 | default E fromStr(String strVal) { 63 | if (strVal == null) { 64 | return null; 65 | } 66 | E[] vs = items(); 67 | for (E enumItem : vs) { 68 | if (strVal.equalsIgnoreCase(enumItem.name())) { 69 | return enumItem; 70 | } 71 | } 72 | return null; 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/map/biMap/BiMap.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.map.biMap; 2 | 3 | import java.util.Map; 4 | 5 | import com.xiaoTools.core.map.mapWrapper.MapWrapper; 6 | import com.xiaoTools.util.mapUtil.MapUtil; 7 | 8 | /** 9 | * [双向Map](Bidirectional map) 10 | * @description zh - 双向Map 11 | * @description en - Bidirectional map 12 | * @version V1.0 13 | * @author XiaoXunYao 14 | * @since 2021-10-28 19:13:52 15 | */ 16 | public class BiMap extends MapWrapper { 17 | 18 | private static final long serialVersionUID = 1L; 19 | 20 | private Map inverse; 21 | 22 | public BiMap(Map raw) { 23 | super(raw); 24 | } 25 | 26 | @Override 27 | public V put(K key, V value) { 28 | if (null != this.inverse) { 29 | this.inverse.put(value, key); 30 | } 31 | return super.put(key, value); 32 | } 33 | 34 | @Override 35 | public void putAll(Map m) { 36 | super.putAll(m); 37 | if (null != this.inverse) { 38 | m.forEach((key, value) -> this.inverse.put(value, key)); 39 | } 40 | } 41 | 42 | @Override 43 | public void clear() { 44 | super.clear(); 45 | this.inverse = null; 46 | } 47 | 48 | /** 49 | * [获取反向Map](Get reverse map) 50 | * @description zh - 获取反向Map 51 | * @description en - Get reverse map 52 | * @version V1.0 53 | * @author XiaoXunYao 54 | * @since 2021-10-28 19:15:53 55 | * @return java.util.Map 56 | */ 57 | public Map getInverse() { 58 | if (null == this.inverse) { 59 | inverse = MapUtil.inverse(getRaw()); 60 | } 61 | return this.inverse; 62 | } 63 | 64 | /** 65 | * [根据值获得键](Get key from value) 66 | * @description zh - 根据值获得键 67 | * @description en - Get key from value 68 | * @version V1.0 69 | * @author XiaoXunYao 70 | * @since 2021-10-28 19:16:23 71 | * @param value 值 72 | * @return K 73 | */ 74 | public K getKey(V value) { 75 | return getInverse().get(value); 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/io/dataUnit/DataUnit.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.io.dataUnit; 2 | 3 | import com.xiaoTools.core.io.dataSize.DataSize; 4 | import com.xiaoTools.util.strUtil.StrUtil; 5 | 6 | /** 7 | * [数据单位封装](Data unit encapsulation) 8 | * @description zh - 数据单位封装 9 | * @description en - Data unit encapsulation 10 | * @version V1.0 11 | * @author XiaoXunYao 12 | * @since 2021-10-29 22:17:58 13 | */ 14 | public enum DataUnit { 15 | 16 | /** 17 | * Bytes 18 | */ 19 | BYTES("B", DataSize.ofBytes(1)), 20 | 21 | /** 22 | * Kilobytes 23 | */ 24 | KILOBYTES("KB", DataSize.ofKilobytes(1)), 25 | 26 | /** 27 | * Megabytes 28 | */ 29 | MEGABYTES("MB", DataSize.ofMegabytes(1)), 30 | 31 | /** 32 | * Gigabytes 33 | */ 34 | GIGABYTES("GB", DataSize.ofGigabytes(1)), 35 | 36 | /** 37 | * Terabytes 38 | */ 39 | TERABYTES("TB", DataSize.ofTerabytes(1)); 40 | 41 | public static final String[] UNIT_NAMES = new String[]{"B", "KB", "MB", "GB", "TB", "PB", "EB"}; 42 | 43 | private final String suffix; 44 | 45 | private final DataSize size; 46 | 47 | DataUnit(String suffix, DataSize size) { 48 | this.suffix = suffix; 49 | this.size = size; 50 | } 51 | 52 | public DataSize size() { 53 | return this.size; 54 | } 55 | 56 | /** 57 | * [通过后缀返回对应的DataUnit](Return the corresponding dataunit through the suffix) 58 | * @description zh - 通过后缀返回对应的DataUnit 59 | * @description en - Return the corresponding dataunit through the suffix 60 | * @version V1.0 61 | * @author XiaoXunYao 62 | * @since 2021-10-29 22:19:54 63 | * @param suffix 单位后缀 64 | * @return com.xiaoTools.core.io.dataUnit.DataUnit 65 | */ 66 | public static DataUnit fromSuffix(String suffix) { 67 | for (DataUnit candidate : values()) { 68 | if (StrUtil.startWithIgnoreCase(candidate.suffix, suffix)) { 69 | return candidate; 70 | } 71 | } 72 | throw new IllegalArgumentException("Unknown data unit suffix '" + suffix + "'"); 73 | } 74 | 75 | 76 | } 77 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/io/fileResource/FileResource.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.io.fileResource; 2 | import java.net.URL; 3 | import java.io.File; 4 | import java.nio.file.Path; 5 | import java.io.InputStream; 6 | import java.io.Serializable; 7 | 8 | import com.xiaoTools.core.exception.noResourceException.NoResourceException; 9 | import com.xiaoTools.core.io.resource.Resource; 10 | import com.xiaoTools.util.fileUtil.fileUtil.FileUtil; 11 | import com.xiaoTools.util.urlUtil.URLUtil; 12 | 13 | /** 14 | * [文件资源访问对象](File resource access object) 15 | * @description zh - 文件资源访问对象 16 | * @description en - File resource access object 17 | * @version V1.0 18 | * @author XiaoXunYao 19 | * @since 2021-10-29 09:58:59 20 | */ 21 | public class FileResource implements Resource, Serializable { 22 | 23 | private static final long serialVersionUID = 1L; 24 | 25 | private final File file; 26 | 27 | public FileResource(Path path) { 28 | this(path.toFile()); 29 | } 30 | 31 | public FileResource(File file) { 32 | this(file, file.getName()); 33 | } 34 | 35 | public FileResource(File file, String fileName) { 36 | this.file = file; 37 | } 38 | 39 | public FileResource(String path) { 40 | this(FileUtil.file(path)); 41 | } 42 | 43 | @Override 44 | public String getName() { 45 | return this.file.getName(); 46 | } 47 | 48 | @Override 49 | public URL getUrl(){ 50 | return URLUtil.getURL(this.file); 51 | } 52 | 53 | @Override 54 | public InputStream getStream() throws NoResourceException { 55 | return FileUtil.getInputStream(this.file); 56 | } 57 | 58 | @Override 59 | public String toString() { 60 | return (null == this.file) ? "null" : this.file.toString(); 61 | } 62 | 63 | /** 64 | * [获取文件](get files) 65 | * @description zh - 获取文件 66 | * @description en - get files 67 | * @version V1.0 68 | * @author XiaoXunYao 69 | * @since 2021-10-29 10:00:25 70 | * @return java.io.File 71 | */ 72 | public File getFile() { 73 | return this.file; 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/convert/calendarConverter/CalendarConverter.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.convert.calendarConverter; 2 | 3 | import java.util.Calendar; 4 | import java.util.Date; 5 | 6 | import com.xiaoTools.core.convert.abstractConverter.AbstractConverter; 7 | import com.xiaoTools.util.dateUtil.DateUtil; 8 | import com.xiaoTools.util.strUtil.StrUtil; 9 | 10 | /** 11 | * [日期转换器](Date Converter) 12 | * @description zh - 日期转换器 13 | * @description en - Date Converter 14 | * @version V1.0 15 | * @author XiaoXunYao 16 | * @since 2021-10-20 07:38:05 17 | */ 18 | public class CalendarConverter extends AbstractConverter { 19 | private static final long serialVersionUID = 1L; 20 | 21 | /** 22 | * [日期格式化](Date formatting) 23 | * @description zh - 日期格式化 24 | * @description en - Date formatting 25 | * @version V1.0 26 | * @author XiaoXunYao 27 | * @since 2021-10-20 12:20:46 28 | */ 29 | private String format; 30 | 31 | /** 32 | * [获取日期格式](Get date format) 33 | * @description zh - 获取日期格式 34 | * @description en - Get date format 35 | * @version V1.0 36 | * @author XiaoXunYao 37 | * @since 2021-10-20 12:21:15 38 | * @return java.lang.String 39 | */ 40 | public String getFormat() { 41 | return format; 42 | } 43 | 44 | /** 45 | * [设置日期格式](Format date) 46 | * @description zh - 设置日期格式 47 | * @description en - Format date 48 | * @version V1.0 49 | * @author XiaoXunYao 50 | * @since 2021-10-20 12:21:58 51 | * @param format 日期格式 52 | */ 53 | public void setFormat(String format) { 54 | this.format = format; 55 | } 56 | 57 | @Override 58 | protected Calendar convertInternal(Object value) { 59 | if (value instanceof Date) { 60 | return DateUtil.calendar((Date)value); 61 | } 62 | 63 | if (value instanceof Long) { 64 | return DateUtil.calendar((Long)value); 65 | } 66 | 67 | final String valueStr = convertToStr(value); 68 | return DateUtil.calendar(StrUtil.isBlank(format) ? DateUtil.parse(valueStr) : DateUtil.parse(valueStr, format)); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/io/urlResource/UrlResource.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.io.urlResource; 2 | 3 | import java.io.File; 4 | import java.io.InputStream; 5 | import java.io.Serializable; 6 | import java.net.URL; 7 | 8 | import com.xiaoTools.core.exception.noResourceException.NoResourceException; 9 | import com.xiaoTools.core.io.resource.Resource; 10 | import com.xiaoTools.util.fileUtil.fileUtil.FileUtil; 11 | import com.xiaoTools.util.objectUtil.ObjectUtil; 12 | import com.xiaoTools.util.urlUtil.URLUtil; 13 | 14 | /** 15 | * [URL资源访问类](URL resource access class) 16 | * @description zh - URL资源访问类 17 | * @description en - URL resource access class 18 | * @version V1.0 19 | * @author XiaoXunYao 20 | * @since 2021-10-29 10:10:12 21 | */ 22 | public class UrlResource implements Resource, Serializable { 23 | 24 | private static final long serialVersionUID = 1L; 25 | 26 | protected URL url; 27 | protected String name; 28 | 29 | public UrlResource(URL url) { 30 | this(url, null); 31 | } 32 | 33 | public UrlResource(URL url, String name) { 34 | this.url = url; 35 | this.name = ObjectUtil.defaultIfNull(name, (null != url) ? FileUtil.getName(url.getPath()) : null); 36 | } 37 | 38 | @Override 39 | public String getName() { 40 | return this.name; 41 | } 42 | 43 | @Override 44 | public URL getUrl(){ 45 | return this.url; 46 | } 47 | 48 | @Override 49 | public InputStream getStream() throws NoResourceException{ 50 | if(null == this.url){ 51 | throw new NoResourceException("Resource URL is null!"); 52 | } 53 | return URLUtil.getStream(url); 54 | } 55 | 56 | @Override 57 | public String toString() { 58 | return (null == this.url) ? "null" : this.url.toString(); 59 | } 60 | 61 | /** 62 | * [获得File](Get file) 63 | * @description zh - 获得File 64 | * @description en - Get file 65 | * @version V1.0 66 | * @author XiaoXunYao 67 | * @since 2021-10-29 10:11:46 68 | * @return java.io.File 69 | */ 70 | public File getFile(){ 71 | return FileUtil.file(this.url); 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/entity/holder/Holder.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.entity.holder; 2 | 3 | import com.xiaoTools.entity.mutableObj.MutableObj; 4 | 5 | /** 6 | * [为不可变的对象引用提供一个可变的包装,在java中支持引用传递。](It provides a variable wrapper for immutable object references and supports reference passing in Java.) 7 | * @description: zh - 为不可变的对象引用提供一个可变的包装,在java中支持引用传递。 8 | * @description: en - It provides a variable wrapper for immutable object references and supports reference passing in Java. 9 | * @version: V1.0 10 | * @author XiaoXunYao 11 | * @since 2021/6/21 8:21 下午 12 | */ 13 | public final class Holder extends MutableObj { 14 | 15 | /** 16 | * [新建Holder类,持有指定值,当值为空时抛出空指针异常](Create a new holder class, hold the specified value, and throw a null pointer exception when the value is null) 17 | * @description: zh - 新建Holder类,持有指定值,当值为空时抛出空指针异常 18 | * @description: en - Create a new holder class, hold the specified value, and throw a null pointer exception when the value is null 19 | * @version: V1.0 20 | * @author XiaoXunYao 21 | * @since 2021/6/21 8:24 下午 22 | * @param value: 值,不能为空 23 | * @return com.xiaoTools.entity.holder.Holder 24 | */ 25 | public static Holder of(T value) throws NullPointerException{ 26 | if(null == value){ 27 | throw new NullPointerException("Holder can not hold a null value!"); 28 | } 29 | return new Holder<>(value); 30 | } 31 | 32 | /** 33 | * [构造](structure) 34 | * @description: zh - 构造 35 | * @description: en - structure 36 | * @version: V1.0 37 | * @author XiaoXunYao 38 | * @since 2021/6/21 8:25 下午 39 | */ 40 | public Holder() { 41 | } 42 | 43 | /** 44 | * [构造](structure) 45 | * @description: zh - 构造 46 | * @description: en - structure 47 | * @version: V1.0 48 | * @author XiaoXunYao 49 | * @since 2021/6/21 8:24 下午 50 | * @param value: 被包装的对象 51 | */ 52 | public Holder(T value) { 53 | super(value); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/util/serializeUtil/SerializeUtil.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.util.serializeUtil; 2 | 3 | import java.io.ByteArrayInputStream; 4 | import java.io.Serializable; 5 | 6 | import com.xiaoTools.core.io.fastByteArrayOutputStream.FastByteArrayOutputStream; 7 | import com.xiaoTools.lang.constant.Constant; 8 | import com.xiaoTools.util.ioUtil.IoUtil; 9 | 10 | /** 11 | * [序列化工具类](Serialization tool class) 12 | * @description zh - 序列化工具类 13 | * @description en - Serialization tool class 14 | * @version V1.0 15 | * @author XiaoXunYao 16 | * @since 2021-10-22 12:28:33 17 | */ 18 | public class SerializeUtil { 19 | 20 | /** 21 | * [序列化后拷贝流的方式克隆](Clone by copying stream after serialization) 22 | * @description zh - 序列化后拷贝流的方式克隆 23 | * @description en - Clone by copying stream after serialization 24 | * @version V1.0 25 | * @author XiaoXunYao 26 | * @since 2021-10-22 12:28:59 27 | * @param obj 对象 28 | * @return T 29 | */ 30 | public static T clone(T obj) { 31 | return Constant.FALSE == (obj instanceof Serializable) ? null : 32 | deserialize(serialize(obj)); 33 | } 34 | 35 | /** 36 | * [反序列化](Deserialization) 37 | * @description zh - 反序列化 38 | * @description en - Deserialization 39 | * @version V1.0 40 | * @author XiaoXunYao 41 | * @since 2021-10-22 12:29:37 42 | * @param bytes 反序列化的字节码 43 | * @return T 44 | */ 45 | public static T deserialize(byte[] bytes) { 46 | return IoUtil.readObj(new ByteArrayInputStream(bytes)); 47 | } 48 | 49 | /** 50 | * [序列化](serialize) 51 | * @description zh - 序列化 52 | * @description en - serialize 53 | * @version V1.0 54 | * @author XiaoXunYao 55 | * @since 2021-10-22 12:31:22 56 | * @parram obj 对象 57 | * @return byte[] 58 | */ 59 | public static byte[] serialize(T obj) { 60 | if (false == (obj instanceof Serializable)) { 61 | return null; 62 | } 63 | final FastByteArrayOutputStream byteOut = new FastByteArrayOutputStream(); 64 | IoUtil.writeObjects(byteOut, false, (Serializable) obj); 65 | return byteOut.toByteArray(); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/util/temporalAccessorUtil/TemporalUtil.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.util.temporalAccessorUtil; 2 | 3 | import java.time.Duration; 4 | import java.time.temporal.ChronoUnit; 5 | import java.time.temporal.Temporal; 6 | 7 | /** 8 | * [Temporal 工具类封装](Encapsulation of temporary tool class) 9 | * @description: zh - Temporal 工具类封装 10 | * @description: en - Encapsulation of temporary tool class 11 | * @version: V1.0 12 | * @author XiaoXunYao 13 | * @since 2021/6/21 11:02 上午 14 | */ 15 | public class TemporalUtil { 16 | 17 | /** 18 | * [获取两个日期的差,如果结束时间早于开始时间,获取结果为负。](Gets the difference between two dates. If the end time is earlier than the start time, the result is negative.) 19 | * @description: zh - 获取两个日期的差,如果结束时间早于开始时间,获取结果为负。 20 | * @description: en - Gets the difference between two dates. If the end time is earlier than the start time, the result is negative. 21 | * @version: V1.0 22 | * @author XiaoXunYao 23 | * @since 2021/6/21 11:03 上午 24 | * @param startTimeInclude: 开始时间(包含) 25 | * @param endTimeExclude: 结束时间(不包含) 26 | * @return java.time.Duration 27 | */ 28 | public static Duration between(Temporal startTimeInclude, Temporal endTimeExclude) { 29 | return Duration.between(startTimeInclude, endTimeExclude); 30 | } 31 | 32 | /** 33 | * [获取两个日期的差,如果结束时间早于开始时间,获取结果为负。](Gets the difference between two dates. If the end time is earlier than the start time, the result is negative.) 34 | * @description: zh - 获取两个日期的差,如果结束时间早于开始时间,获取结果为负。 35 | * @description: en - Gets the difference between two dates. If the end time is earlier than the start time, the result is negative. 36 | * @version: V1.0 37 | * @author XiaoXunYao 38 | * @since 2021/6/21 11:02 上午 39 | * @param startTimeInclude: 开始时间(包括) 40 | * @param endTimeExclude: 结束时间(不包括) 41 | * @param unit: 时间差单位 42 | * @return long 43 | */ 44 | public static long between(Temporal startTimeInclude, Temporal endTimeExclude, ChronoUnit unit) { 45 | return unit.between(startTimeInclude, endTimeExclude); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/util/modifierUtil/modifierType/ModifierType.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.util.modifierUtil.modifierType; 2 | 3 | import java.lang.reflect.Modifier; 4 | 5 | /** 6 | * [修饰符枚举](Modifier enumeration) 7 | * @description zh - 修饰符枚举 8 | * @description en - Modifier enumeration 9 | * @version V1.0 10 | * @author XiaoXunYao 11 | * @since 2021-10-28 09:28:27 12 | */ 13 | public enum ModifierType { 14 | 15 | /** 16 | * public修饰符,所有类都能访问 17 | */ 18 | PUBLIC(Modifier.PUBLIC), 19 | 20 | /** 21 | * private修饰符,只能被自己访问和修改 22 | */ 23 | PRIVATE(Modifier.PRIVATE), 24 | 25 | /** 26 | * protected修饰符,自身、子类及同一个包中类可以访问 27 | */ 28 | PROTECTED(Modifier.PROTECTED), 29 | 30 | /** 31 | * static修饰符,(静态修饰符)指定变量被所有对象共享,即所有实例都可以使用该变量。变量属于这个类 32 | */ 33 | STATIC(Modifier.STATIC), 34 | 35 | /** 36 | * final修饰符,最终修饰符,指定此变量的值不能变,使用在方法上表示不能被重载 37 | */ 38 | FINAL(Modifier.FINAL), 39 | 40 | /** 41 | * synchronized,同步修饰符,在多个线程中,该修饰符用于在运行前,对他所属的方法加锁,以防止其他线程的访问,运行结束后解锁。 42 | */ 43 | SYNCHRONIZED(Modifier.SYNCHRONIZED), 44 | 45 | /** 46 | * (易失修饰符)指定该变量可以同时被几个线程控制和修改 47 | */ 48 | VOLATILE(Modifier.VOLATILE), 49 | 50 | /** 51 | * (过度修饰符)指定该变量是系统保留,暂无特别作用的临时性变量,序列化时忽略 52 | */ 53 | TRANSIENT(Modifier.TRANSIENT), 54 | 55 | /** 56 | * native,本地修饰符。指定此方法的方法体是用其他语言在程序外部编写的。 57 | */ 58 | NATIVE(Modifier.NATIVE), 59 | 60 | /** 61 | * abstract,将一个类声明为抽象类,没有实现的方法,需要子类提供方法实现。 62 | */ 63 | ABSTRACT(Modifier.ABSTRACT), 64 | 65 | /** 66 | * strictfp,一旦使用了关键字strictfp来声明某个类、接口或者方法时,那么在这个关键字所声明的范围内所有浮点运算都是精确的,符合IEEE-754规范的。 67 | */ 68 | STRICT(Modifier.STRICT); 69 | 70 | /** 71 | * 修饰符枚举对应的int修饰符值 72 | */ 73 | private final int value; 74 | 75 | ModifierType(int modifier) { 76 | this.value = modifier; 77 | } 78 | 79 | /** 80 | * [获取修饰符枚举对应的int修饰符值](Gets the int modifier value corresponding to the modifier enumeration) 81 | * @description zh - 获取修饰符枚举对应的int修饰符值 82 | * @description en - Gets the int modifier value corresponding to the modifier enumeration 83 | * @version V1.0 84 | * @author XiaoXunYao 85 | * @since 2021-10-28 09:30:51 86 | * @return int 87 | */ 88 | public int getValue() { 89 | return this.value; 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/map/customKeyMap/CustomKeyMap.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.map.customKeyMap; 2 | 3 | import java.util.Map; 4 | 5 | import com.xiaoTools.core.map.mapWrapper.MapWrapper; 6 | 7 | /** 8 | * [自定义键的Map](Custom key map) 9 | * @description zh - 自定义键的Map 10 | * @description en - Custom key map 11 | * @version V1.0 12 | * @author XiaoXunYao 13 | * @since 2021-10-02 10:08:42 14 | */ 15 | public abstract class CustomKeyMap extends MapWrapper { 16 | private static final long serialVersionUID = 4043263744224569870L; 17 | 18 | /** 19 | * [构造](structure) 20 | * @description zh - 构造 21 | * @description en - structure 22 | * @version V1.0 23 | * @author XiaoXunYao 24 | * @since 2021-10-02 10:06:20 25 | * @param map 集合 26 | */ 27 | public CustomKeyMap(Map map) { 28 | super(map); 29 | } 30 | 31 | @Override 32 | public V get(Object key) { 33 | return super.get(customKey(key)); 34 | } 35 | 36 | @SuppressWarnings("unchecked") 37 | @Override 38 | public V put(K key, V value) { 39 | return super.put((K) customKey(key), value); 40 | } 41 | 42 | @Override 43 | public void putAll(Map m) { 44 | m.forEach(this::put); 45 | } 46 | 47 | @Override 48 | public boolean containsKey(Object key) { 49 | return super.containsKey(customKey(key)); 50 | } 51 | 52 | @Override 53 | public V remove(Object key) { 54 | return super.remove(customKey(key)); 55 | } 56 | 57 | @Override 58 | public boolean remove(Object key, Object value) { 59 | return super.remove(customKey(key), value); 60 | } 61 | 62 | @Override 63 | public boolean replace(K key, V oldValue, V newValue) { 64 | return super.replace((K) customKey(key), oldValue, newValue); 65 | } 66 | 67 | @Override 68 | public V replace(K key, V value) { 69 | return super.replace((K) customKey(key), value); 70 | } 71 | 72 | /** 73 | * [自定义键](Custom key) 74 | * @description zh - 自定义键 75 | * @description en - Custom key 76 | * @version V1.0 77 | * @author XiaoXunYao 78 | * @since 2021-10-02 10:07:54 79 | * @param key 键 80 | * @return java.lang.Object 81 | */ 82 | protected abstract Object customKey(Object key); 83 | } 84 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## Contributing to Xiao-Tools 2 | Xiao-Tools is released under the Apache 2.0 license. If you would like to contribute something, or want to hack on the code this document should help you get started. 3 | 4 | ## Code of Conduct 5 | This project adheres to the Contributor Covenant code of conduct. By participating, you are expected to uphold this code. Please report unacceptable behavior to [huchengyea@163.com](huchengyea@163.com) 6 | 7 | ## Using GitHub Issues 8 | We use GitHub issues to track bugs and enhancements. 9 | 10 | If you are reporting a bug, please help to speed up problem diagnosis by providing as much information as possible. Ideally, that would include a small sample project that reproduces the problem. 11 | 12 | ## Reporting Security Vulnerabilities 13 | Please report security vulnerabilities using GitHub issues. 14 | 15 | ## Sign the Contributor License Agreement 16 | Before we accept a non-trivial patch or pull request we will need you to sign the Contributor License Agreement. Signing the contributor’s agreement does not grant anyone commit rights to the main repository, but it does mean that we can accept your contributions, and you will get an author credit if we do. Active contributors might be asked to join the core team, and given the ability to merge pull requests. 17 | 18 | ## Code Conventions and Housekeeping 19 | - None of these is essential for a pull request, but they will all help. They can also be added after the original pull request but before a merge. 20 | 21 | - Make sure all new .java files have a Javadoc class comment with at least an @author tag identifying you, and preferably at least a paragraph on what the class is for. 22 | 23 | - Add yourself as an @author to the .java files that you modify substantially (more than cosmetic changes). 24 | 25 | - Add some Javadocs. 26 | 27 | - A few unit tests would help a lot as well — someone has to do it. 28 | 29 | - If no-one else is using your branch, please rebase it against the current main branch (or other target branch in the project). 30 | 31 | - When writing a commit message please follow these conventions. 32 | 33 | ## Working with the Code 34 | For information on editing, building, and testing the code, see the Working with the Code page on the project wiki. -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/comparator/propertyComparator/PropertyComparator.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.comparator.propertyComparator; 2 | 3 | import java.io.Serializable; 4 | import java.util.Comparator; 5 | 6 | import com.xiaoTools.core.exception.comparatorException.ComparatorException; 7 | import com.xiaoTools.lang.constant.Constant; 8 | import com.xiaoTools.util.beanUtil.BeanUtil; 9 | import com.xiaoTools.util.compareUtil.CompareUtil; 10 | import com.xiaoTools.util.objectUtil.ObjectUtil; 11 | 12 | /** 13 | * [Bean属性排序器](Bean property sorter) 14 | * @description zh - Bean属性排序器 15 | * @description en - Bean property sorter 16 | * @version V1.0 17 | * @author XiaoXunYao 18 | * @since 2021-09-01 19:00:25 19 | */ 20 | public class PropertyComparator implements Comparator, Serializable { 21 | private static final long serialVersionUID = 9157326766723846313L; 22 | 23 | /** 24 | * 属性名 25 | */ 26 | private final String property; 27 | 28 | /** 29 | * null值是否排在后(从小到大排序) 30 | */ 31 | private final boolean isNullGreater; 32 | 33 | public PropertyComparator(String property) { 34 | this(property, true); 35 | } 36 | 37 | public PropertyComparator(String property, boolean isNullGreater) { 38 | this.property = property; 39 | this.isNullGreater = isNullGreater; 40 | } 41 | 42 | @Override 43 | public int compare(T o1, T o2) { 44 | if (o1 == o2) { 45 | return Constant.ZERO; 46 | } else if (Constant.NULL == o1) { 47 | return isNullGreater ? Constant.ONE : Constant.NEGATIVE_ONE; 48 | } else if (Constant.NULL == o2) { 49 | return isNullGreater ? Constant.NEGATIVE_ONE : Constant.ONE; 50 | } 51 | 52 | Comparable v1; 53 | Comparable v2; 54 | try { 55 | v1 = BeanUtil.getProperty(o1, property); 56 | v2 = BeanUtil.getProperty(o2, property); 57 | } catch (Exception e) { 58 | throw new ComparatorException(e); 59 | } 60 | 61 | return compare(o1, o2, v1, v2); 62 | } 63 | 64 | @SuppressWarnings({"rawtypes", "unchecked"}) 65 | private int compare(T o1, T o2, Comparable fieldValue1, Comparable fieldValue2) { 66 | int result = ObjectUtil.compare(fieldValue1, fieldValue2, isNullGreater); 67 | if(Constant.ZERO == result) { 68 | result = CompareUtil.compare(o1, o2, this.isNullGreater); 69 | } 70 | return result; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/entity/mutableObj/MutableObj.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.entity.mutableObj; 2 | 3 | import com.xiaoTools.entity.mutable.Mutable; 4 | import com.xiaoTools.lang.constant.Constant; 5 | 6 | import java.io.Serial; 7 | import java.io.Serializable; 8 | 9 | /** 10 | * [可变Object](Variable object) 11 | * @description: zh - 可变Object 12 | * @description: en - Variable object 13 | * @version: V1.0 14 | * @author XiaoXunYao 15 | * @since 2021/6/21 8:37 下午 16 | */ 17 | public class MutableObj implements Mutable, Serializable { 18 | 19 | @Serial 20 | private static final long serialVersionUID = 1L; 21 | 22 | private T value; 23 | 24 | /** 25 | * [构造,空值](Construction, null) 26 | * @description: zh - 构造,空值 27 | * @description: en - Construction, null 28 | * @version: V1.0 29 | * @author XiaoXunYao 30 | * @since 2021/6/21 8:32 下午 31 | */ 32 | public MutableObj() { } 33 | 34 | /** 35 | * [有参构造](Parametric structure) 36 | * @description: zh - 有参构造 37 | * @description: en - Parametric structure 38 | * @version: V1.0 39 | * @author XiaoXunYao 40 | * @since 2021/6/21 8:32 下午 41 | * @param value: 值 42 | */ 43 | public MutableObj(final T value) { 44 | this.value = value; 45 | } 46 | 47 | /*重写-----------------------------------------------------------Override*/ 48 | 49 | @Override 50 | public T get() { 51 | return this.value; 52 | } 53 | 54 | @Override 55 | public void set(T value) { 56 | this.value = value; 57 | } 58 | 59 | @Override 60 | public boolean equals(final Object obj) { 61 | if (obj == Constant.NULL) { 62 | return Constant.FALSE; 63 | } 64 | if (this == obj) { 65 | return Constant.TRUE; 66 | } 67 | if (this.getClass() == obj.getClass()) { 68 | final MutableObj that = (MutableObj) obj; 69 | return this.value.equals(that.value); 70 | } 71 | return Constant.FALSE; 72 | } 73 | 74 | @Override 75 | public int hashCode() { 76 | return value == Constant.NULL ? Constant.ZERO : value.hashCode(); 77 | } 78 | 79 | @Override 80 | public String toString() { 81 | return value == Constant.NULL ? Constant.STRING_NULL_OUT : value.toString(); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/io/validateObjectInputStream/ValidateObjectInputStream.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.io.validateObjectInputStream; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | import java.io.InvalidClassException; 6 | import java.io.ObjectInputStream; 7 | import java.io.ObjectStreamClass; 8 | import java.util.HashSet; 9 | import java.util.Set; 10 | 11 | import com.xiaoTools.util.collUtil.CollUtil; 12 | 13 | /** 14 | * [带有类验证的对象流](Object flow with class validation) 15 | * @description zh - 带有类验证的对象流 16 | * @description en - Object flow with class validation 17 | * @version V1.0 18 | * @author XiaoXunYao 19 | * @since 2021-10-23 17:32:26 20 | */ 21 | public class ValidateObjectInputStream extends ObjectInputStream { 22 | 23 | private Set whiteClassSet; 24 | private Set blackClassSet; 25 | 26 | public ValidateObjectInputStream(InputStream inputStream, Class... acceptClasses) throws IOException { 27 | super(inputStream); 28 | accept(acceptClasses); 29 | } 30 | 31 | public void refuse(Class... refuseClasses) { 32 | if(null == this.blackClassSet){ 33 | this.blackClassSet = new HashSet<>(); 34 | } 35 | for (Class acceptClass : refuseClasses) { 36 | this.blackClassSet.add(acceptClass.getName()); 37 | } 38 | } 39 | 40 | public void accept(Class... acceptClasses) { 41 | if(null == this.whiteClassSet){ 42 | this.whiteClassSet = new HashSet<>(); 43 | } 44 | for (Class acceptClass : acceptClasses) { 45 | this.whiteClassSet.add(acceptClass.getName()); 46 | } 47 | } 48 | 49 | @Override 50 | protected Class resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException { 51 | validateClassName(desc.getName()); 52 | return super.resolveClass(desc); 53 | } 54 | 55 | private void validateClassName(String className) throws InvalidClassException { 56 | if(CollUtil.isNotEmpty(this.blackClassSet)){ 57 | if(this.blackClassSet.contains(className)){ 58 | throw new InvalidClassException("Unauthorized deserialization attempt by black list", className); 59 | } 60 | } 61 | 62 | if(CollUtil.isEmpty(this.whiteClassSet)){ 63 | return; 64 | } 65 | if(className.startsWith("java.")){ 66 | return; 67 | } 68 | if(this.whiteClassSet.contains(className)){ 69 | return; 70 | } 71 | 72 | throw new InvalidClassException("Unauthorized deserialization attempt", className); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/util/resultutil/ResultUtil.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.util.resultutil; 2 | 3 | import com.xiaoTools.core.result.Result; 4 | 5 | /** 6 | * [返回值工具类](return value tools) 7 | * @description: zh - 返回值工具类 8 | * @description: en - return value tools 9 | * @version: V1.0 10 | * @author XiaoXunYao 11 | * @since 2021/7/24 8:33 下午 12 | */ 13 | public class ResultUtil { 14 | 15 | /** 16 | * [成功的 return value](Successful return value) 17 | * @description: zh - 成功的 return value 18 | * @description: en - Successful return value 19 | * @version: V1.0 20 | * @author XiaoXunYao 21 | * @since 2021/7/24 8:35 下午 22 | * @param value: message Value 23 | * @param path: URL path 24 | * @return com.xiaoTools.core.result.Result 25 | */ 26 | public Result success(Object value,String path){ 27 | return new Result().result200(value,path); 28 | } 29 | 30 | /** 31 | * [请求的地方为多处](Multiple places requested) 32 | * @description: zh - 请求的地方为多处 33 | * @description: en - Multiple places requested 34 | * @version: V1.0 35 | * @author XiaoXunYao 36 | * @since 2021/7/24 8:38 下午 37 | * @param value: message Value 38 | * @param path: URL path 39 | * @return com.xiaoTools.core.result.Result 40 | */ 41 | public Result complete(Object value,String path){ 42 | return new Result().result300(value,path); 43 | } 44 | 45 | /** 46 | * [客户端请求有语法错误。](The client request has a syntax error.) 47 | * @description: 客户端请求有语法错误。 48 | * @description: The client request has a syntax error. 49 | * @version: V1.0 50 | * @author XiaoXunYao 51 | * @since 2021/7/24 8:43 下午 52 | * @param value: message Value 53 | * @param path: URL path 54 | * @return com.xiaoTools.core.result.Result 55 | */ 56 | public Result syntax(Object value,String path){ 57 | return new Result().result400(value,path); 58 | } 59 | 60 | /** 61 | * [服务器错误。](Server error.) 62 | * @description: zh - 服务器错误。 63 | * @description: en -Server error. 64 | * @version: V1.0 65 | * @author XiaoXunYao 66 | * @since 2021/7/24 8:44 下午 67 | * @param value: message Value 68 | * @param path: URL path 69 | * @return com.xiaoTools.core.result.Result 70 | */ 71 | public Result error(Object value,String path){ 72 | return new Result().result500(value,path); 73 | } 74 | 75 | 76 | } 77 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Code of Conduct 2 | 3 | As contributors and maintainers of this project, and in the interest of fostering an open and welcoming community, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities. 4 | 5 | We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, or nationality. 6 | 7 | Examples of unacceptable behavior by participants include: 8 | 9 | - The use of sexualized language or imagery 10 | 11 | - Personal attacks 12 | 13 | - Trolling or insulting/derogatory comments 14 | 15 | - Public or private harassment 16 | 17 | - Publishing other’s private information, such as physical or electronic addresses, without explicit permission 18 | 19 | - Other unethical or unprofessional conduct 20 | 21 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 22 | 23 | By adopting this Code of Conduct, project maintainers commit themselves to fairly and consistently applying these principles to every aspect of managing this project. Project maintainers who do not follow or enforce the Code of Conduct may be permanently removed from the project team. 24 | 25 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its -community. 26 | 27 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting a project maintainer at [huchengyea@163.com](huchengyea@163.com) . All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. Maintainers are obligated to maintain confidentiality with regard to the reporter of an incident. 28 | 29 | This Code of Conduct is adapted from the [Contributor Covenant](https://www.contributor-covenant.org/), version 1.3.0, available at [contributor-covenant.org/version/1/3/0/](https://www.contributor-covenant.org/version/1/3/0/code-of-conduct/) -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/convert/beanConverter/BeanConverter.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.convert.beanConverter; 2 | 3 | import java.util.Map; 4 | import java.lang.reflect.Type; 5 | 6 | import com.xiaoTools.core.convert.abstractConverter.AbstractConverter; 7 | import com.xiaoTools.core.exception.convertException.ConvertException; 8 | import com.xiaoTools.core.map.mapProxy.MapProxy; 9 | import com.xiaoTools.entity.beanCopier.BeanCopier; 10 | import com.xiaoTools.entity.copyOptions.CopyOptions; 11 | import com.xiaoTools.entity.valueProvider.ValueProvider; 12 | import com.xiaoTools.util.beanUtil.BeanUtil; 13 | import com.xiaoTools.util.objectUtil.ObjectUtil; 14 | import com.xiaoTools.util.reflectUtil.ReflectUtil; 15 | import com.xiaoTools.util.typeUtil.TypeUtil; 16 | 17 | /** 18 | * [Bean转换器](Bean converter) 19 | * @description zh - Bean转换器 20 | * @description en - Bean converter 21 | * @version V1.0 22 | * @author XiaoXunYao 23 | * @since 2021-10-28 10:05:23 24 | */ 25 | public class BeanConverter extends AbstractConverter { 26 | 27 | private static final long serialVersionUID = 1L; 28 | 29 | private final Type beanType; 30 | private final Class beanClass; 31 | private final CopyOptions copyOptions; 32 | 33 | @SuppressWarnings("unchecked") 34 | public BeanConverter(Type beanType, CopyOptions copyOptions) { 35 | this.beanType = beanType; 36 | this.beanClass = (Class) TypeUtil.getClass(beanType); 37 | this.copyOptions = copyOptions; 38 | } 39 | 40 | public BeanConverter(Class beanClass) { 41 | this(beanClass, CopyOptions.create().setIgnoreError(true)); 42 | } 43 | 44 | public BeanConverter(Type beanType) { 45 | this(beanType, CopyOptions.create().setIgnoreError(true)); 46 | } 47 | 48 | @Override 49 | protected T convertInternal(Object value) { 50 | if(value instanceof Map || 51 | value instanceof ValueProvider || 52 | BeanUtil.isBean(value.getClass())) { 53 | if(value instanceof Map && this.beanClass.isInterface()) { 54 | return MapProxy.create((Map)value).toProxyBean(this.beanClass); 55 | } 56 | 57 | return BeanCopier.create(value, ReflectUtil.newInstanceIfPossible(this.beanClass), this.beanType, this.copyOptions).copy(); 58 | } else if(value instanceof byte[]){ 59 | return ObjectUtil.deserialize((byte[])value); 60 | } 61 | 62 | throw new ConvertException("Unsupported source type: {}", value.getClass()); 63 | } 64 | 65 | @Override 66 | public Class getTargetType() { 67 | return this.beanClass; 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/entity/beanValueProvider/BeanValueProvider.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.entity.beanValueProvider; 2 | 3 | import java.util.Map; 4 | import java.lang.reflect.Type; 5 | 6 | import com.xiaoTools.entity.propDesc.PropDesc; 7 | import com.xiaoTools.entity.valueProvider.ValueProvider; 8 | import com.xiaoTools.util.beanUtil.BeanUtil; 9 | import com.xiaoTools.util.strUtil.StrUtil; 10 | 11 | /** 12 | * [Bean的值提供者](Value provider for bean) 13 | * @description zh - Bean的值提供者 14 | * @description en - Value provider for bean 15 | * @version V1.0 16 | * @author XiaoXunYao 17 | * @since 2021-10-27 18:58:06 18 | */ 19 | public class BeanValueProvider implements ValueProvider { 20 | 21 | private final Object source; 22 | private final boolean ignoreError; 23 | final Map sourcePdMap; 24 | 25 | /** 26 | * [构造](structure) 27 | * @description zh - 构造 28 | * @description en - structure 29 | * @version V1.0 30 | * @author XiaoXunYao 31 | * @since 2021-10-27 18:59:36 32 | * @param bean Bean 33 | * @param ignoreCase 是否忽略字段大小写 34 | * @param ignoreError 是否忽略字段值读取错误 35 | */ 36 | public BeanValueProvider(Object bean, boolean ignoreCase, boolean ignoreError) { 37 | this.source = bean; 38 | this.ignoreError = ignoreError; 39 | sourcePdMap = BeanUtil.getBeanDesc(source.getClass()).getPropMap(ignoreCase); 40 | } 41 | 42 | @Override 43 | public Object value(String key, Type valueType) { 44 | final PropDesc sourcePd = getPropDesc(key, valueType); 45 | 46 | Object result = null; 47 | if (null != sourcePd) { 48 | result = sourcePd.getValue(this.source, valueType, this.ignoreError); 49 | } 50 | return result; 51 | } 52 | 53 | @Override 54 | public boolean containsKey(String key) { 55 | final PropDesc sourcePd = getPropDesc(key, null); 56 | return null != sourcePd && sourcePd.isReadable(false); 57 | } 58 | 59 | /** 60 | * [获得属性描述](Get attribute description) 61 | * @description zh - 获得属性描述 62 | * @description en - Get attribute description 63 | * @version V1.0 64 | * @author XiaoXunYao 65 | * @since 2021-10-27 19:01:32 66 | * @param key 字段名 67 | * @param valueType 值类型 68 | * @return com.xiaoTools.entity.propDesc.PropDesc 69 | */ 70 | private PropDesc getPropDesc(String key, Type valueType) { 71 | PropDesc sourcePd = sourcePdMap.get(key); 72 | if (null == sourcePd && (null == valueType || Boolean.class == valueType || boolean.class == valueType)) { 73 | sourcePd = sourcePdMap.get(StrUtil.upperFirstAndAddPre(key, "is")); 74 | } 75 | 76 | return sourcePd; 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/date/format/abstractDateBasic/AbstractDateBasic.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.date.format.abstractDateBasic; 2 | 3 | import com.xiaoTools.date.format.basic.DateBasic; 4 | import com.xiaoTools.date.format.fastDatePrinter.FastDatePrinter; 5 | import com.xiaoTools.lang.constant.Constant; 6 | 7 | import java.io.Serial; 8 | import java.io.Serializable; 9 | import java.util.Locale; 10 | import java.util.TimeZone; 11 | 12 | /** 13 | * [摘要日期基本](Summary date basic) 14 | * @description: zh - 摘要日期基本 15 | * @description: en - Summary date basic 16 | * @version: V1.0 17 | * @author XiaoXunYao 18 | * @since 2021/6/19 11:21 上午 19 | */ 20 | public class AbstractDateBasic implements DateBasic, Serializable { 21 | 22 | @Serial 23 | private static final long serialVersionUID = 6333136319870641818L; 24 | 25 | /** 26 | * 模式 27 | */ 28 | protected final String pattern; 29 | 30 | /** 31 | * 时区 32 | */ 33 | protected final TimeZone timeZone; 34 | 35 | /** 36 | * 区域设置 37 | */ 38 | protected final Locale locale; 39 | 40 | /*构造函数--------------------------------------------------------------------Constructors*/ 41 | 42 | protected AbstractDateBasic(final String pattern, final TimeZone timeZone, final Locale locale) { 43 | this.pattern = pattern; 44 | this.timeZone = timeZone; 45 | this.locale = locale; 46 | } 47 | 48 | /*访问器--------------------------------------------------------------------Accessors*/ 49 | 50 | @Override 51 | public String getPattern() { 52 | return pattern; 53 | } 54 | 55 | @Override 56 | public TimeZone getTimeZone() { 57 | return timeZone; 58 | } 59 | 60 | @Override 61 | public Locale getLocale() { 62 | return locale; 63 | } 64 | 65 | /*基础--------------------------------------------------------------------Basic*/ 66 | 67 | @Override 68 | public boolean equals(final Object obj) { 69 | if (!(obj instanceof FastDatePrinter)) { 70 | return false; 71 | } 72 | final AbstractDateBasic other = (AbstractDateBasic) obj; 73 | return pattern.equals(other.pattern) && timeZone.equals(other.timeZone) && locale.equals(other.locale); 74 | } 75 | 76 | @Override 77 | public int hashCode() { 78 | return pattern.hashCode() + Constant.THIRTEEN * (timeZone.hashCode() + Constant.THIRTEEN * locale.hashCode()); 79 | } 80 | 81 | @Override 82 | public String toString() { 83 | return "FastDatePrinter[" + pattern + "," + locale + "," + timeZone.getID() + "]"; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/convert/stringConverter/StringConverter.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.convert.stringConverter; 2 | 3 | import java.io.InputStream; 4 | import java.io.Reader; 5 | import java.sql.Blob; 6 | import java.sql.Clob; 7 | import java.sql.SQLException; 8 | import java.util.TimeZone; 9 | 10 | import com.xiaoTools.core.convert.abstractConverter.AbstractConverter; 11 | import com.xiaoTools.core.exception.convertException.ConvertException; 12 | import com.xiaoTools.util.charsetUtil.CharsetUtil; 13 | import com.xiaoTools.util.ioUtil.IoUtil; 14 | import com.xiaoTools.util.xmlUtil.XmlUtil; 15 | 16 | /** 17 | * [字符串转换器](String converter) 18 | * @description zh - 字符串转换器 19 | * @description en - String converter 20 | * @version V1.0 21 | * @author XiaoXunYao 22 | * @since 2021-10-19 07:30:31 23 | */ 24 | public class StringConverter extends AbstractConverter { 25 | 26 | private static final long serialVersionUID = 1L; 27 | 28 | @Override 29 | protected String convertInternal(Object value) { 30 | if (value instanceof TimeZone) { 31 | return ((TimeZone) value).getID(); 32 | } else if (value instanceof org.w3c.dom.Node) { 33 | return XmlUtil.toStr((org.w3c.dom.Node) value); 34 | } else if (value instanceof Clob) { 35 | return clobToStr((Clob) value); 36 | } else if (value instanceof Blob) { 37 | return blobToStr((Blob) value); 38 | } 39 | 40 | // 其它情况 41 | return convertToStr(value); 42 | } 43 | 44 | /** 45 | * [Clob字段值转字符串](Clob field value to string) 46 | * @description zh - Clob字段值转字符串 47 | * @description en - Clob field value to string 48 | * @version V1.0 49 | * @author XiaoXunYao 50 | * @since 2021-10-19 07:32:07 51 | * @param clob Clob 52 | * @return java.lang.String 53 | */ 54 | private static String clobToStr(Clob clob) { 55 | Reader reader = null; 56 | try { 57 | reader = clob.getCharacterStream(); 58 | return IoUtil.read(reader); 59 | } catch (SQLException e) { 60 | throw new ConvertException(e); 61 | } finally { 62 | IoUtil.close(reader); 63 | } 64 | } 65 | 66 | /** 67 | * [Clob字段值转字符串](Clob field value to string) 68 | * @description zh - Clob字段值转字符串 69 | * @description en - Clob field value to string 70 | * @version V1.0 71 | * @author XiaoXunYao 72 | * @since 2021-10-19 07:33:07 73 | * @param blob Blob 74 | * @return java.lang.String 75 | */ 76 | private static String blobToStr(Blob blob) { 77 | InputStream in = null; 78 | try { 79 | in = blob.getBinaryStream(); 80 | return IoUtil.read(in, CharsetUtil.CHARSET_UTF_8); 81 | } catch (SQLException e) { 82 | throw new ConvertException(e); 83 | } finally { 84 | IoUtil.close(in); 85 | } 86 | } 87 | 88 | } 89 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/entity/mapValueProvider/MapValueProvider.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.entity.mapValueProvider; 2 | 3 | import java.util.Map; 4 | import java.lang.reflect.Type; 5 | 6 | import com.xiaoTools.core.convert.Convert; 7 | import com.xiaoTools.core.map.caseInsensitiveMap.CaseInsensitiveMap; 8 | import com.xiaoTools.entity.valueProvider.ValueProvider; 9 | import com.xiaoTools.lang.constant.Constant; 10 | import com.xiaoTools.util.strUtil.StrUtil; 11 | 12 | /** 13 | * [Map值提供者](Map value provider) 14 | * @description zh - Map值提供者 15 | * @description en - Map value provider 16 | * @version V1.0 17 | * @author XiaoXunYao 18 | * @since 2021-10-27 18:43:31 19 | */ 20 | public class MapValueProvider implements ValueProvider { 21 | 22 | private final Map map; 23 | 24 | private final boolean ignoreError; 25 | 26 | public MapValueProvider(Map map, boolean ignoreCase) { 27 | this(map, ignoreCase, Constant.FALSE); 28 | } 29 | 30 | public MapValueProvider(Map map, boolean ignoreCase, boolean ignoreError) { 31 | if (Constant.FALSE == ignoreCase || map instanceof CaseInsensitiveMap) { 32 | this.map = map; 33 | } else { 34 | this.map = new CaseInsensitiveMap<>(map); 35 | } 36 | this.ignoreError = ignoreError; 37 | } 38 | 39 | @Override 40 | public Object value(String key, Type valueType) { 41 | final String key1 = getKey(key, valueType); 42 | if (null == key1) { 43 | return null; 44 | } 45 | 46 | final Object value = map.get(key1); 47 | return Convert.convertWithCheck(valueType, value, null, this.ignoreError); 48 | } 49 | 50 | @Override 51 | public boolean containsKey(String key) { 52 | return null != getKey(key, null); 53 | } 54 | 55 | /** 56 | * [获得map中可能包含的key](Get the key that may be contained in the map) 57 | * @description zh - 获得map中可能包含的key 58 | * @description en - Get the key that may be contained in the map 59 | * @version V1.0 60 | * @author XiaoXunYao 61 | * @since 2021-10-27 18:44:47 62 | * @param key map中可能包含的key 63 | * @param valueType 值类型 64 | * @return java.lang.String 65 | */ 66 | private String getKey(String key, Type valueType) { 67 | if (map.containsKey(key)) { 68 | return key; 69 | } 70 | 71 | String customKey = StrUtil.toUnderlineCase(key); 72 | if (map.containsKey(customKey)) { 73 | return customKey; 74 | } 75 | 76 | if (null == valueType || Boolean.class == valueType || boolean.class == valueType) { 77 | customKey = StrUtil.upperFirstAndAddPre(key, "is"); 78 | if (map.containsKey(customKey)) { 79 | return customKey; 80 | } 81 | 82 | customKey = StrUtil.toUnderlineCase(customKey); 83 | if (map.containsKey(customKey)) { 84 | return customKey; 85 | } 86 | } 87 | return null; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/lang/pair/Pair.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.lang.pair; 2 | 3 | import com.xiaoTools.lang.clone.cLoneSupport.CloneSupport; 4 | 5 | import java.io.Serializable; 6 | import java.util.Objects; 7 | 8 | /** 9 | * [键值对对象](Key value pair object) 10 | * @description zh - 键值对对象 11 | * @description en - Key value pair object 12 | * @version V1.0 13 | * @author XiaoXunYao 14 | * @since 2021-09-25 19:54:42 15 | */ 16 | public class Pair extends CloneSupport> implements Serializable { 17 | 18 | private static final long serialVersionUID = 1L; 19 | 20 | private final K key; 21 | private final V value; 22 | 23 | /** 24 | * [构建 Pair 对象](Building pair objects) 25 | * @description zh - 构建 Pair 对象 26 | * @description en - Building pair objects 27 | * @version V1.0 28 | * @author XiaoXunYao 29 | * @since 2021-09-25 19:56:19 30 | * @param key 键 31 | * @param value 值 32 | * @return com.xiaoTools.lang.pair.Pair 33 | */ 34 | public static Pair of(K key, V value) { 35 | return new Pair<>(key, value); 36 | } 37 | 38 | /** 39 | * [构造](structure) 40 | * @description zh - 构造 41 | * @description en - structure 42 | * @version V1.0 43 | * @author XiaoXunYao 44 | * @since 2021-09-25 19:58:53 45 | * @param key 键 46 | * @param value 值 47 | */ 48 | public Pair(K key, V value) { 49 | this.key = key; 50 | this.value = value; 51 | } 52 | 53 | /** 54 | * [获取值](get value) 55 | * @description zh - 获取值 56 | * @description en - get Value 57 | * @version V1.0 58 | * @author XiaoXunYao 59 | * @since 2021-09-25 20:01:10 60 | * @return V 61 | */ 62 | public V getValue() { 63 | return this.value; 64 | } 65 | 66 | /** 67 | * [获取键](get key) 68 | * @description zh - 获取键 69 | * @description en - get key 70 | * @version V1.0 71 | * @author XiaoXunYao 72 | * @since 2021-09-25 20:08:57 73 | */ 74 | public K getKey() { 75 | return this.key; 76 | } 77 | 78 | 79 | @Override 80 | public String toString() { 81 | return "Pair [key=" + key + ", value=" + value + "]"; 82 | } 83 | 84 | @Override 85 | public boolean equals(Object o) { 86 | if (this == o) 87 | return true; 88 | if (o instanceof Pair) { 89 | Pair pair = (Pair) o; 90 | return Objects.equals(getKey(), pair.getKey()) && 91 | Objects.equals(getValue(), pair.getValue()); 92 | } 93 | return false; 94 | } 95 | 96 | @Override 97 | public int hashCode() { 98 | return Objects.hashCode(key) ^ Objects.hashCode(value); 99 | } 100 | 101 | 102 | } 103 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/exception/convertException/ConvertException.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.exception.convertException; 2 | 3 | import com.xiaoTools.util.exceptionUtil.ExceptionUtil; 4 | import com.xiaoTools.util.strUtil.StrUtil; 5 | 6 | import java.io.Serial; 7 | 8 | /** 9 | * [转换异常](Conversion exception) 10 | * @description: zh - 转换异常 11 | * @description: en - Conversion exception 12 | * @version: V1.0 13 | * @author XiaoXunYao 14 | * @since 2021/6/17 3:45 下午 15 | */ 16 | public class ConvertException extends RuntimeException{ 17 | 18 | @Serial 19 | private static final long serialVersionUID = 4730597402855274362L; 20 | 21 | 22 | /** 23 | * [转换异常](Conversion exception) 24 | * @description: zh - 转换异常 25 | * @description: en - Conversion exception 26 | * @version: V1.0 27 | * @author XiaoXunYao 28 | * @since 2021/6/17 3:46 下午 29 | * @param e: 异常 30 | */ 31 | public ConvertException(Throwable e) { 32 | super(ExceptionUtil.getMessage(e), e); 33 | } 34 | 35 | /** 36 | * [转换异常](Conversion exception) 37 | * @description: zh - 转换异常 38 | * @description: en - Conversion exception 39 | * @version: V1.0 40 | * @author XiaoXunYao 41 | * @since 2021/6/17 3:47 下午 42 | * @param message: 异常信息 43 | */ 44 | public ConvertException(String message) { 45 | super(message); 46 | } 47 | 48 | /** 49 | * [转换异常](Conversion exception) 50 | * @description: zh - 转换异常 51 | * @description: en - Conversion exception 52 | * @version: V1.0 53 | * @author XiaoXunYao 54 | * @since 2021/6/17 3:52 下午 55 | * @param messageTemplate: 错误信息 56 | * @param params: 57 | */ 58 | public ConvertException(String messageTemplate, Object... params) { 59 | super(StrUtil.format(messageTemplate, params)); 60 | } 61 | 62 | /** 63 | * [转换异常](Conversion exception) 64 | * @description: zh - 转换异常 65 | * @description: en - Conversion exception 66 | * @version: V1.0 67 | * @author XiaoXunYao 68 | * @since 2021/6/17 3:53 下午 69 | * @param message: 错误信息 70 | * @param throwable: 异常问题 71 | */ 72 | public ConvertException(String message, Throwable throwable) { 73 | super(message, throwable); 74 | } 75 | 76 | /** 77 | * [转换异常](Conversion exception) 78 | * @description: zh - 转换异常 79 | * @description: en - Conversion exception 80 | * @version: V1.0 81 | * @author XiaoXunYao 82 | * @since 2021/6/17 3:55 下午 83 | * @param throwable: 异常问题 84 | * @param messageTemplate: 异常信息模板 85 | * @param params: 异常参数 86 | */ 87 | public ConvertException(Throwable throwable, String messageTemplate, Object... params) { 88 | super(StrUtil.format(messageTemplate, params), throwable); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/io/bomInputStream/BOMInputStream.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.io.bomInputStream; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | import java.io.PushbackInputStream; 6 | 7 | import com.xiaoTools.core.exception.iORuntimeException.IORuntimeException; 8 | import com.xiaoTools.util.charsetUtil.CharsetUtil; 9 | 10 | /** 11 | * [读取带BOM头的流内容](Read stream content with BOM header) 12 | * @description zh - 读取带BOM头的流内容 13 | * @description en - Read stream content with BOM header 14 | * @version V1.0 15 | * @author XiaoXunYao 16 | * @since 2021-10-22 22:49:08 17 | */ 18 | public class BOMInputStream extends InputStream { 19 | 20 | private final PushbackInputStream in; 21 | private boolean isInited = false; 22 | private final String defaultCharset; 23 | private String charset; 24 | 25 | private static final int BOM_SIZE = 4; 26 | 27 | public BOMInputStream(InputStream in) { 28 | this(in, CharsetUtil.UTF_8); 29 | } 30 | 31 | public BOMInputStream(InputStream in, String defaultCharset) { 32 | this.in = new PushbackInputStream(in, BOM_SIZE); 33 | this.defaultCharset = defaultCharset; 34 | } 35 | 36 | public String getDefaultCharset() { 37 | return defaultCharset; 38 | } 39 | 40 | public String getCharset() { 41 | if (!isInited) { 42 | try { 43 | init(); 44 | } catch (IOException ex) { 45 | throw new IORuntimeException(ex); 46 | } 47 | } 48 | return charset; 49 | } 50 | 51 | @Override 52 | public void close() throws IOException { 53 | isInited = true; 54 | in.close(); 55 | } 56 | 57 | @Override 58 | public int read() throws IOException { 59 | isInited = true; 60 | return in.read(); 61 | } 62 | 63 | protected void init() throws IOException { 64 | if (isInited) { 65 | return; 66 | } 67 | 68 | byte[] bom = new byte[BOM_SIZE]; 69 | int n, unread; 70 | n = in.read(bom, 0, bom.length); 71 | 72 | if ((bom[0] == (byte) 0x00) && (bom[1] == (byte) 0x00) && (bom[2] == (byte) 0xFE) && (bom[3] == (byte) 0xFF)) { 73 | charset = "UTF-32BE"; 74 | unread = n - 4; 75 | } else if ((bom[0] == (byte) 0xFF) && (bom[1] == (byte) 0xFE) && (bom[2] == (byte) 0x00) && (bom[3] == (byte) 0x00)) { 76 | charset = "UTF-32LE"; 77 | unread = n - 4; 78 | } else if ((bom[0] == (byte) 0xEF) && (bom[1] == (byte) 0xBB) && (bom[2] == (byte) 0xBF)) { 79 | charset = "UTF-8"; 80 | unread = n - 3; 81 | } else if ((bom[0] == (byte) 0xFE) && (bom[1] == (byte) 0xFF)) { 82 | charset = "UTF-16BE"; 83 | unread = n - 2; 84 | } else if ((bom[0] == (byte) 0xFF) && (bom[1] == (byte) 0xFE)) { 85 | charset = "UTF-16LE"; 86 | unread = n - 2; 87 | } else { 88 | charset = defaultCharset; 89 | unread = n; 90 | } 91 | 92 | if (unread > 0) { 93 | in.unread(bom, (n - unread), unread); 94 | } 95 | 96 | isInited = true; 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/date/dateRange/DateRange.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.date.dateRange; 2 | 3 | import com.xiaoTools.date.dateField.DateField; 4 | import com.xiaoTools.date.dateTime.DateTime; 5 | import com.xiaoTools.lang.constant.Constant; 6 | import com.xiaoTools.lang.range.Range; 7 | import com.xiaoTools.util.dateUtil.DateUtil; 8 | 9 | import java.io.Serial; 10 | import java.util.Date; 11 | 12 | /** 13 | * [日期范围](Date range) 14 | * @description: zh - 日期范围 15 | * @description: en - Date range 16 | * @version: V1.0 17 | * @author XiaoXunYao 18 | * @since 2021/6/24 1:27 下午 19 | */ 20 | public class DateRange extends Range { 21 | 22 | @Serial 23 | private static final long serialVersionUID = 1L; 24 | 25 | /** 26 | * [构造,包含开始和结束日期时间](Construct, including start and end dates and times) 27 | * @description: zh - 构造,包含开始和结束日期时间 28 | * @description: en - Construct, including start and end dates and times 29 | * @version: V1.0 30 | * @author XiaoXunYao 31 | * @since 2021/6/24 2:37 下午 32 | * @param start: 起始日期时间 33 | * @param end: 结束日期时间 34 | * @param unit: 步进单位 35 | */ 36 | public DateRange(Date start, Date end, final DateField unit) { 37 | this(start, end, unit, Constant.ONE); 38 | } 39 | 40 | /** 41 | * [构造,包含开始和结束日期时间](Construct, including start and end dates and times) 42 | * @description: zh - 构造,包含开始和结束日期时间 43 | * @description: en - Construct, including start and end dates and times 44 | * @version: V1.0 45 | * @author XiaoXunYao 46 | * @since 2021/6/24 2:38 下午 47 | * @param start: 起始日期时间 48 | * @param end: 结束日期时间 49 | * @param unit: 步进单位 50 | * @param step: 步进数 51 | */ 52 | public DateRange(Date start, Date end, final DateField unit, final int step) { 53 | this(start, end, unit, step, true, true); 54 | } 55 | 56 | /** 57 | * [构造,包含开始和结束日期时间](Construct, including start and end dates and times) 58 | * @description: zh - 构造,包含开始和结束日期时间 59 | * @description: en - Construct, including start and end dates and times 60 | * @version: V1.0 61 | * @author XiaoXunYao 62 | * @since 2021/6/24 2:46 下午 63 | * @param start: 起始日期时间 64 | * @param end: 结束日期时间 65 | * @param unit: 步进单位 66 | * @param step: 步进数 67 | * @param isIncludeStart: 是否包含开始的时间 68 | * @param isIncludeEnd: 是否包含结束的时间 69 | */ 70 | public DateRange(Date start, Date end, final DateField unit, final int step, boolean isIncludeStart, boolean isIncludeEnd) { 71 | super(DateUtil.date(start), DateUtil.date(end), (current, end1, index) -> { 72 | DateTime dt = current.offsetNew(unit, step); 73 | if (dt.isAfter(end1)) { 74 | return null; 75 | } 76 | return current.offsetNew(unit, step); 77 | }, isIncludeStart, isIncludeEnd); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/versionComparator/VersionComparator.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.versionComparator; 2 | 3 | import com.xiaoTools.lang.constant.Constant; 4 | import com.xiaoTools.util.objectUtil.ObjectUtil; 5 | import com.xiaoTools.util.strUtil.StrUtil; 6 | 7 | import java.io.Serial; 8 | import java.io.Serializable; 9 | import java.util.Comparator; 10 | import java.util.List; 11 | 12 | public class VersionComparator implements Comparator, Serializable { 13 | 14 | @Serial 15 | private static final long serialVersionUID = 8083701245147495562L; 16 | 17 | /** 18 | * [单例模式](Singleton mode) 19 | * @description: zh - 单例模式 20 | * @description: en - Singleton mode 21 | * @version: V1.0 22 | * @author XiaoXunYao 23 | * @since 2021/7/13 8:23 下午 24 | */ 25 | public static final VersionComparator INSTANCE = new VersionComparator(); 26 | 27 | /** 28 | * [默认构造](Default construction) 29 | * @description: zh - 默认构造 30 | * @description: en - Default construction 31 | * @version: V1.0 32 | * @author XiaoXunYao 33 | * @since 2021/7/13 8:23 下午 34 | */ 35 | public VersionComparator() { } 36 | 37 | /** 38 | * [比较两个版本](Compare the two versions) 39 | * @description: zh - 比较两个版本 40 | * @description: en - Compare the two versions 41 | * @version: V1.0 42 | * @author XiaoXunYao 43 | * @since 2021/7/13 8:29 下午 44 | * @param version1: 版本1 45 | * @param version2: 版本2 46 | * @return int 47 | */ 48 | @Override 49 | public int compare(String version1, String version2) { 50 | if(ObjectUtil.equal(version1, version2)) { 51 | return Constant.ZERO; 52 | } 53 | if (version1 == Constant.NULL && version2 == Constant.NULL) { 54 | return Constant.ZERO; 55 | } else if (version1 == Constant.NULL) { 56 | // null视为最小版本,排在前 57 | return Constant.NEGATIVE_ONE; 58 | } else if (version2 == Constant.NULL) { 59 | return Constant.ONE; 60 | } 61 | 62 | final List v1s = StrUtil.split(version1, Constant.CHAR_SPOT); 63 | final List v2s = StrUtil.split(version2, Constant.CHAR_SPOT); 64 | 65 | int diff = Constant.ZERO; 66 | // 取最小长度值 67 | int minLength = Math.min(v1s.size(), v2s.size()); 68 | String v1; 69 | String v2; 70 | for (int i = Constant.ZERO; i < minLength; i++) { 71 | v1 = v1s.get(i); 72 | v2 = v2s.get(i); 73 | // 先比较长度 74 | diff = v1.length() - v2.length(); 75 | if (Constant.ZERO == diff) { diff = v1.compareTo(v2); } 76 | if(diff != Constant.ZERO) { 77 | //已有结果,结束 78 | break; 79 | } 80 | } 81 | // 如果已经分出大小,则直接返回,如果未分出大小,则再比较位数,有子版本的为大; 82 | return (diff != Constant.ZERO) ? diff : v1s.size() - v2s.size(); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/io/lineIter/LineIter.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.io.lineIter; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.Closeable; 5 | import java.io.IOException; 6 | import java.io.InputStream; 7 | import java.io.Reader; 8 | import java.io.Serializable; 9 | import java.nio.charset.Charset; 10 | import java.util.Iterator; 11 | import java.util.NoSuchElementException; 12 | 13 | import com.xiaoTools.assertion.Assertion; 14 | import com.xiaoTools.core.exception.iORuntimeException.IORuntimeException; 15 | import com.xiaoTools.util.ioUtil.IoUtil; 16 | 17 | /** 18 | * [将Reader包装为一个按照行读取的Iterator](将Reader包装为一个按照行读取的Iterator) 19 | * @description zh - 将Reader包装为一个按照行读取的Iterator 20 | * @description en - 将Reader包装为一个按照行读取的Iterator 21 | * @version V1.0 22 | * @author XiaoXunYao 23 | * @since 2021-10-24 10:55:30 24 | */ 25 | public class LineIter implements Iterator, Iterable, Closeable, Serializable { 26 | 27 | private static final long serialVersionUID = 1L; 28 | 29 | 30 | private final BufferedReader bufferedReader; 31 | 32 | private String cachedLine; 33 | 34 | private boolean finished = false; 35 | 36 | public LineIter(InputStream in, Charset charset) throws IllegalArgumentException { 37 | this(IoUtil.getReader(in, charset)); 38 | } 39 | 40 | public LineIter(Reader reader) throws IllegalArgumentException { 41 | Assertion.notNull(reader, "Reader must not be null"); 42 | this.bufferedReader = IoUtil.getReader(reader); 43 | } 44 | 45 | @Override 46 | public boolean hasNext() throws IORuntimeException { 47 | if (cachedLine != null) { 48 | return true; 49 | } else if (finished) { 50 | return false; 51 | } else { 52 | try { 53 | while (true) { 54 | String line = bufferedReader.readLine(); 55 | if (line == null) { 56 | finished = true; 57 | return false; 58 | } else if (isValidLine(line)) { 59 | cachedLine = line; 60 | return true; 61 | } 62 | } 63 | } catch (IOException ioe) { 64 | close(); 65 | throw new IORuntimeException(ioe); 66 | } 67 | } 68 | } 69 | 70 | @Override 71 | public String next() throws NoSuchElementException { 72 | return nextLine(); 73 | } 74 | 75 | public String nextLine() throws NoSuchElementException { 76 | if (false == hasNext()) { 77 | throw new NoSuchElementException("No more lines"); 78 | } 79 | String currentLine = this.cachedLine; 80 | this.cachedLine = null; 81 | return currentLine; 82 | } 83 | 84 | @Override 85 | public void close() { 86 | finished = true; 87 | IoUtil.close(bufferedReader); 88 | cachedLine = null; 89 | } 90 | 91 | @Override 92 | public void remove() { 93 | throw new UnsupportedOperationException("Remove unsupported on LineIterator"); 94 | } 95 | 96 | protected boolean isValidLine(String line) { 97 | return true; 98 | } 99 | 100 | @Override 101 | public Iterator iterator() { 102 | return this; 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/lang/parameterizedTypeImpl/ParameterizedTypeImpl.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.lang.parameterizedTypeImpl; 2 | 3 | import java.io.Serializable; 4 | import java.lang.reflect.ParameterizedType; 5 | import java.lang.reflect.Type; 6 | 7 | import com.xiaoTools.util.arrayUtil.ArrayUtil; 8 | import com.xiaoTools.util.strUtil.StrUtil; 9 | 10 | public class ParameterizedTypeImpl implements ParameterizedType, Serializable { 11 | 12 | private static final long serialVersionUID = 1L; 13 | 14 | private final Type[] actualTypeArguments; 15 | private final Type ownerType; 16 | private final Type rawType; 17 | 18 | /** 19 | * [构造](structure) 20 | * @description zh - 构造 21 | * @description en - structure 22 | * @version V1.0 23 | * @author XiaoXunYao 24 | * @since 2021-10-21 12:36:48 25 | * @param actualTypeArguments 实际的泛型参数类型 26 | * @param ownerType 拥有者类型 27 | * @param rawType 原始类型 28 | */ 29 | public ParameterizedTypeImpl(Type[] actualTypeArguments, Type ownerType, Type rawType) { 30 | this.actualTypeArguments = actualTypeArguments; 31 | this.ownerType = ownerType; 32 | this.rawType = rawType; 33 | } 34 | 35 | @Override 36 | public Type[] getActualTypeArguments() { 37 | return actualTypeArguments; 38 | } 39 | 40 | @Override 41 | public Type getOwnerType() { 42 | return ownerType; 43 | } 44 | 45 | @Override 46 | public Type getRawType() { 47 | return rawType; 48 | } 49 | 50 | @Override 51 | public String toString() { 52 | final StringBuilder buf = new StringBuilder(); 53 | 54 | final Type useOwner = this.ownerType; 55 | final Class raw = (Class) this.rawType; 56 | if (useOwner == null) { 57 | buf.append(raw.getName()); 58 | } else { 59 | if (useOwner instanceof Class) { 60 | buf.append(((Class) useOwner).getName()); 61 | } else { 62 | buf.append(useOwner.toString()); 63 | } 64 | buf.append('.').append(raw.getSimpleName()); 65 | } 66 | 67 | appendAllTo(buf.append('<'), ", ", this.actualTypeArguments).append('>'); 68 | return buf.toString(); 69 | } 70 | 71 | /** 72 | * [追加](Add) 73 | * @description zh - 追加 74 | * @description en - Add 75 | * @version V1.0 76 | * @author XiaoXunYao 77 | * @since 2021-10-21 12:38:44 78 | * @param buf 目标 79 | * @param sep 分隔符 80 | * @param types 加入的类型 81 | * @return java.lang.StringBuilder 82 | */ 83 | private static StringBuilder appendAllTo(final StringBuilder buf, final String sep, final Type... types) { 84 | if (ArrayUtil.isNotEmpty(types)) { 85 | boolean isFirst = true; 86 | for (Type type : types) { 87 | if (isFirst) { 88 | isFirst = false; 89 | } else { 90 | buf.append(sep); 91 | } 92 | 93 | String typeStr; 94 | if(type instanceof Class) { 95 | typeStr = ((Class)type).getName(); 96 | }else { 97 | typeStr = StrUtil.toString(type); 98 | } 99 | 100 | buf.append(typeStr); 101 | } 102 | } 103 | return buf; 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/date/format/dateParser/DateParser.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.date.format.dateParser; 2 | 3 | import com.xiaoTools.date.format.basic.DateBasic; 4 | 5 | import java.text.ParseException; 6 | import java.text.ParsePosition; 7 | import java.util.Calendar; 8 | import java.util.Date; 9 | 10 | /** 11 | * [日期解析接口](Date resolution interface) 12 | * @description: zh - 日期解析接口 13 | * @description: en - Date resolution interface 14 | * @version: V1.0 15 | * @author XiaoXunYao 16 | * @since 2021/6/19 7:57 上午 17 | */ 18 | public interface DateParser extends DateBasic { 19 | 20 | /** 21 | * [将日期字符串解析并转换为 Date 对象](Parses and converts a date string to a date object) 22 | * @description: zh - 将日期字符串解析并转换为 Date 对象 23 | * @description: en - Parses and converts a date string to a date object 24 | * @version: V1.0 25 | * @author XiaoXunYao 26 | * @since 2021/6/19 9:07 上午 27 | * @param source: 日期字符串 28 | * @return java.util.Date 29 | */ 30 | Date parse(String source) throws ParseException; 31 | 32 | /** 33 | * [将日期字符串解析并转换为 Date 对象](Parses and converts a date string to a date object) 34 | * @description: zh - 将日期字符串解析并转换为 Date 对象 35 | * @description: en - Parses and converts a date string to a date object 36 | * @version: V1.0 37 | * @author XiaoXunYao 38 | * @since 2021/6/19 9:06 上午 39 | * @param source: 日期字符串 40 | * @param pos: ParsePosition 41 | * @return java.util.Date 42 | */ 43 | Date parse(String source, ParsePosition pos); 44 | 45 | /** 46 | * [根据给定格式转换日期字符串](Converts the date string according to the given format) 47 | * @description: zh - 根据给定格式转换日期字符串 48 | * @description: en - Converts the date string according to the given format 49 | * @version: V1.0 50 | * @author XiaoXunYao 51 | * @since 2021/6/19 9:05 上午 52 | * @param source: 被转换的日期字符串 53 | * @param pos: 定义开始转换的位置 54 | * @param calendar: 要在其中设置已解析字段的日历。 55 | * @return boolean 56 | */ 57 | boolean parse(String source, ParsePosition pos, Calendar calendar); 58 | 59 | /** 60 | * [将日期字符串解析并转换为 Date 对象](Parses and converts a date string to a date object) 61 | * @description: zh - 将日期字符串解析并转换为 Date 对象 62 | * @description: en - Parses and converts a date string to a date object 63 | * @version: V1.0 64 | * @author XiaoXunYao 65 | * @since 2021/6/19 9:02 上午 66 | * @param source: 解析其开头。 67 | * @return java.lang.Object 68 | */ 69 | Object parseObject(String source) throws ParseException; 70 | 71 | /** 72 | * [根据 ParsePosition 给定将日期字符串解析并转换为 Date 对象](Parse and convert date string to Date object according to ParsePosition) 73 | * @description: zh - 根据 ParsePosition 给定将日期字符串解析并转换为 Date 对象 74 | * @description: en - Parse and convert date string to Date object according to ParsePosition 75 | * @version: V1.0 76 | * @author XiaoXunYao 77 | * @since 2021/6/19 8:08 上午 78 | * @param source: 解析其开头。 79 | * @param pos: 解析位置 80 | * @return java.lang.Object 81 | */ 82 | Object parseObject(String source, ParsePosition pos); 83 | } 84 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/stringFormatter/StrFormatter.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.stringFormatter; 2 | 3 | import com.xiaoTools.lang.constant.Constant; 4 | import com.xiaoTools.util.arrayUtil.ArrayUtil; 5 | import com.xiaoTools.util.strUtil.StrUtil; 6 | 7 | import java.nio.charset.StandardCharsets; 8 | 9 | /** 10 | * [格式化字符串](format string ) 11 | * @description: zh - 格式化字符串 12 | * @description: en - format string 13 | * @version: V1.0 14 | * @author XiaoXunYao 15 | * @since 2021/6/15 6:46 下午 16 | */ 17 | public class StrFormatter { 18 | public static String format(final String strPattern, final Object... argArray) { 19 | if (StrUtil.isBlank(strPattern) || ArrayUtil.isEmpty(argArray)) { 20 | return strPattern; 21 | } 22 | final int strPatternLength = strPattern.length(); 23 | // 初始化定义好的长度以获得更好的性能 24 | StringBuilder sbuf = new StringBuilder(strPatternLength + Constant.FIFTY); 25 | // 记录已经处理到的位置 26 | int handledPosition = Constant.ZERO; 27 | int delimIndex;// 占位符所在位置 28 | for (int argIndex = Constant.ZERO; argIndex < argArray.length; argIndex++) { 29 | delimIndex = strPattern.indexOf(Constant.BRACKETS, handledPosition); 30 | // 剩余部分无占位符 31 | if (delimIndex == Constant.NEGATIVE_ONE) { 32 | // 不带占位符的模板直接返回 33 | if (handledPosition == Constant.ZERO) { 34 | return strPattern; 35 | } 36 | // 字符串模板剩余部分不再包含占位符,加入剩余部分后返回结果 37 | sbuf.append(strPattern, handledPosition, strPatternLength); 38 | return sbuf.toString(); 39 | } 40 | 41 | // 转义符 42 | if (delimIndex > Constant.ZERO && strPattern.charAt(delimIndex - Constant.ONE) == Constant.DOUBLE_CHAR_SLASH) { 43 | // 双转义符 44 | if (delimIndex > Constant.ONE && strPattern.charAt(delimIndex - Constant.TWO) == Constant.DOUBLE_CHAR_SLASH) { 45 | // 转义符之前还有一个转义符,占位符依旧有效 46 | sbuf.append(strPattern, handledPosition, delimIndex - Constant.ONE); 47 | sbuf.append(utf8Str(argArray[argIndex])); 48 | handledPosition = delimIndex + Constant.TWO; 49 | } else { 50 | // 占位符被转义 51 | argIndex--; 52 | sbuf.append(strPattern, handledPosition, delimIndex - Constant.ONE); 53 | sbuf.append(Constant.LEFT_BRACKETS); 54 | handledPosition = delimIndex + Constant.ONE; 55 | } 56 | } else { 57 | // 正常占位符 58 | sbuf.append(strPattern, handledPosition, delimIndex); 59 | sbuf.append(utf8Str(argArray[argIndex])); 60 | handledPosition = delimIndex + Constant.TWO; 61 | } 62 | } 63 | // 加入最后一个占位符后所有的字符 64 | sbuf.append(strPattern, handledPosition, strPattern.length()); 65 | 66 | return sbuf.toString(); 67 | } 68 | 69 | public static String utf8Str(Object o) { 70 | return StrUtil.string(o, StandardCharsets.UTF_8); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/map/camelCaseMap/CamelCaseMap.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.map.camelCaseMap; 2 | 3 | import java.util.LinkedHashMap; 4 | import java.util.Map; 5 | 6 | import com.xiaoTools.core.map.customKeyMap.CustomKeyMap; 7 | import com.xiaoTools.util.strUtil.StrUtil; 8 | 9 | /** 10 | * [驼峰Key风格的map](Hump key style map) 11 | * @description zh - 驼峰Key风格的map 12 | * @description en - Hump key style map 13 | * @version V1.0 14 | * @author XiaoXunYao 15 | * @since 2021-10-04 08:40:41 16 | */ 17 | public class CamelCaseMap extends CustomKeyMap { 18 | 19 | private static final long serialVersionUID = 4043263744224569870L; 20 | 21 | /** 22 | * [构造](structure) 23 | * @description zh - 构造 24 | * @description en - structure 25 | * @version V1.0 26 | * @author XiaoXunYao 27 | * @since 2021-10-04 08:30:43 28 | */ 29 | public CamelCaseMap() { 30 | this(DEFAULT_INITIAL_CAPACITY); 31 | } 32 | 33 | /** 34 | * [构造](structure) 35 | * @description zh - 构造 36 | * @description en - structure 37 | * @version V1.0 38 | * @author XiaoXunYao 39 | * @since 2021-10-04 08:36:14 40 | * @param map 集合 41 | */ 42 | public CamelCaseMap(Map map) { 43 | this(DEFAULT_LOAD_FACTOR, map); 44 | } 45 | 46 | /** 47 | * [构造](structure) 48 | * @description zh - 构造 49 | * @description en - structure 50 | * @version V1.0 51 | * @author XiaoXunYao 52 | * @since 2021-10-04 08:31:24 53 | * @param initialCapacity 初始大小 54 | */ 55 | public CamelCaseMap(int initialCapacity) { 56 | this(initialCapacity, DEFAULT_LOAD_FACTOR); 57 | } 58 | 59 | /** 60 | * [构造](structure) 61 | * @description zh - 构造 62 | * @description en - structure 63 | * @version V1.0 64 | * @author XiaoXunYao 65 | * @since 2021-10-04 08:32:01 66 | * @param loadFactor 加载因子 67 | * @param map 集合 68 | */ 69 | public CamelCaseMap(float loadFactor, Map map) { 70 | this(map.size(), loadFactor); 71 | this.putAll(map); 72 | } 73 | 74 | /** 75 | * [构造](structure) 76 | * @description zh - 构造 77 | * @description en - structure 78 | * @version V1.0 79 | * @author XiaoXunYao 80 | * @since 2021-10-04 08:33:05 81 | * @param initialCapacity 初始大小 82 | * @param loadFactor 加载因子 83 | */ 84 | public CamelCaseMap(int initialCapacity, float loadFactor) { 85 | super(new LinkedHashMap<>(initialCapacity, loadFactor)); 86 | } 87 | 88 | /** 89 | * [将Key转为驼峰风格](Change key to hump style) 90 | * @description zh - 将Key转为驼峰风格 91 | * @description en - Change key to hump style 92 | * @version V1.0 93 | * @author XiaoXunYao 94 | * @since 2021-10-04 08:34:14 95 | * @param key 键 96 | * @return java.lang.Object 97 | */ 98 | @Override 99 | protected Object customKey(Object key) { 100 | if (key instanceof CharSequence) { 101 | key = StrUtil.toCamelCase(key.toString()); 102 | } 103 | return key; 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/util/desensitizedUtil/DesensitizedUtil.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.util.desensitizedUtil; 2 | 3 | import com.xiaoTools.lang.constant.Constant; 4 | import com.xiaoTools.util.strUtil.StrUtil; 5 | 6 | /** 7 | * [脱敏工具类](Desensitization tools) 8 | * @description zh - 脱敏工具类 9 | * @description en - Desensitization tools 10 | * @version V1.0 11 | * @author XiaoXunYao 12 | * @since 2021-09-20 17:50:55 13 | */ 14 | public class DesensitizedUtil { 15 | /** 16 | * [脱敏类型枚举](Desensitization type enumeration) 17 | * @description zh - 脱敏类型枚举 18 | * @description en - Desensitization type enumeration 19 | * @version V1.0 20 | * @author XiaoXunYao 21 | * @since 2021-09-20 17:52:09 22 | */ 23 | public enum DesensitizedType { 24 | //用户id 25 | USER_ID, 26 | //电子邮件 27 | EMAIL, 28 | //密码 29 | PASSWORD 30 | } 31 | 32 | /** 33 | * [脱敏](Desensitization) 34 | * @description zh - 脱敏 35 | * @description en - Desensitization 36 | * @version V1.0 37 | * @author XiaoXunYao 38 | * @since 2021-09-20 17:56:14 39 | */ 40 | public static String desensitized(CharSequence str, DesensitizedUtil.DesensitizedType desensitizedType) { 41 | if (StrUtil.isBlank(str)) { 42 | return Constant.EMPTY; 43 | } 44 | String newStr = String.valueOf(str); 45 | switch (desensitizedType) { 46 | case USER_ID: 47 | newStr = String.valueOf(DesensitizedUtil.userId()); 48 | break; 49 | case EMAIL: 50 | newStr = DesensitizedUtil.email(String.valueOf(str)); 51 | break; 52 | case PASSWORD: 53 | newStr = DesensitizedUtil.password(String.valueOf(str)); 54 | break; 55 | default: 56 | } 57 | return newStr; 58 | } 59 | 60 | /** 61 | * [不对外提供userId](Do not provide userid externally) 62 | * @description zh - 不对外提供userId 63 | * @description en - Do not provide userid externally 64 | * @version V1.0 65 | * @author XiaoXunYao 66 | * @since 2021-09-20 17:58:37 67 | * @return java.lang.Long 68 | */ 69 | public static Long userId() { 70 | return 0L; 71 | } 72 | 73 | /** 74 | * [电子邮箱](E-mail) 75 | * @description zh - 电子邮箱 76 | * @description en - E-mail 77 | * @version V1.0 78 | * @author XiaoXunYao 79 | * @since 2021-09-20 18:01:22 80 | * @param email 邮箱 81 | * @return java.lang.String 82 | */ 83 | public static String email(String email) { 84 | if (StrUtil.isBlank(email)) { 85 | return Constant.EMPTY; 86 | } 87 | int index = StrUtil.indexOf(email, '@'); 88 | return index <= Constant.ONE ? email : StrUtil.hide(email, Constant.ONE, index); 89 | } 90 | 91 | /** 92 | * [密码](password) 93 | * @description zh - 密码 94 | * @description en - password 95 | * @version V1.0 96 | * @author XiaoXunYao 97 | * @since 2021-09-21 08:05:06 98 | * @param password 密码 99 | * @return java.lang.String 100 | */ 101 | public static String password(String password) { 102 | return StrUtil.isBlank(password) ? Constant.EMPTY : StrUtil.repeat('*', password.length()); 103 | } 104 | 105 | 106 | } 107 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/map/camelCaseLinkedMap/CamelCaseLinkedMap.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.map.camelCaseLinkedMap; 2 | 3 | import java.util.LinkedHashMap; 4 | import java.util.Map; 5 | 6 | import com.xiaoTools.core.map.customKeyMap.CustomKeyMap; 7 | import com.xiaoTools.util.strUtil.StrUtil; 8 | 9 | /** 10 | * [驼峰Key风格的LinkedHashMap](Hump key style LinkedHashMap) 11 | * @description zh - 驼峰Key风格的LinkedHashMap 12 | * @description en - Hump key style LinkedHashMap 13 | * @version V1.0 14 | * @author XiaoXunYao 15 | * @since 2021-10-04 08:28:03 16 | */ 17 | public class CamelCaseLinkedMap extends CustomKeyMap { 18 | 19 | private static final long serialVersionUID = 4043263744224569870L; 20 | 21 | /** 22 | * [构造](structure) 23 | * @description zh - 构造 24 | * @description en - structure 25 | * @version V1.0 26 | * @author XiaoXunYao 27 | * @since 2021-10-04 08:30:43 28 | */ 29 | public CamelCaseLinkedMap() { 30 | this(DEFAULT_INITIAL_CAPACITY); 31 | } 32 | 33 | /** 34 | * [构造](structure) 35 | * @description zh - 构造 36 | * @description en - structure 37 | * @version V1.0 38 | * @author XiaoXunYao 39 | * @since 2021-10-04 08:36:14 40 | * @param map 集合 41 | */ 42 | public CamelCaseLinkedMap(Map map) { 43 | this(DEFAULT_LOAD_FACTOR, map); 44 | } 45 | 46 | /** 47 | * [构造](structure) 48 | * @description zh - 构造 49 | * @description en - structure 50 | * @version V1.0 51 | * @author XiaoXunYao 52 | * @since 2021-10-04 08:31:24 53 | * @param initialCapacity 初始大小 54 | */ 55 | public CamelCaseLinkedMap(int initialCapacity) { 56 | this(initialCapacity, DEFAULT_LOAD_FACTOR); 57 | } 58 | 59 | /** 60 | * [构造](structure) 61 | * @description zh - 构造 62 | * @description en - structure 63 | * @version V1.0 64 | * @author XiaoXunYao 65 | * @since 2021-10-04 08:32:01 66 | * @param loadFactor 加载因子 67 | * @param map 集合 68 | */ 69 | public CamelCaseLinkedMap(float loadFactor, Map map) { 70 | this(map.size(), loadFactor); 71 | this.putAll(map); 72 | } 73 | 74 | /** 75 | * [构造](structure) 76 | * @description zh - 构造 77 | * @description en - structure 78 | * @version V1.0 79 | * @author XiaoXunYao 80 | * @since 2021-10-04 08:33:05 81 | * @param initialCapacity 初始大小 82 | * @param loadFactor 加载因子 83 | */ 84 | public CamelCaseLinkedMap(int initialCapacity, float loadFactor) { 85 | super(new LinkedHashMap<>(initialCapacity, loadFactor)); 86 | } 87 | 88 | /** 89 | * [将Key转为驼峰风格](Change key to hump style) 90 | * @description zh - 将Key转为驼峰风格 91 | * @description en - Change key to hump style 92 | * @version V1.0 93 | * @author XiaoXunYao 94 | * @since 2021-10-04 08:34:14 95 | * @param key 键 96 | * @return java.lang.Object 97 | */ 98 | @Override 99 | protected Object customKey(Object key) { 100 | if (key instanceof CharSequence) { 101 | key = StrUtil.toCamelCase(key.toString()); 102 | } 103 | return key; 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/date/format/datePrinter/DatePrinter.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.date.format.datePrinter; 2 | 3 | import com.xiaoTools.date.format.basic.DateBasic; 4 | 5 | import java.util.Calendar; 6 | import java.util.Date; 7 | 8 | /** 9 | * [日期格式化输出接口](Date format output interface) 10 | * @description: zh - 日期格式化输出接口 11 | * @description: en - Date format output interface 12 | * @version: V1.0 13 | * @author XiaoXunYao 14 | * @since 2021/6/19 9:11 上午 15 | */ 16 | public interface DatePrinter extends DateBasic { 17 | 18 | /** 19 | * [格式化日期表示的毫秒数](The number of milliseconds represented by the formatted date) 20 | * @description: zh - 格式化日期表示的毫秒数 21 | * @description: en - The number of milliseconds represented by the formatted date 22 | * @version: V1.0 23 | * @author XiaoXunYao 24 | * @since 2021/6/19 9:19 上午 25 | * @param millis: 日期毫秒数 26 | * @return java.lang.String 27 | */ 28 | String format(long millis); 29 | 30 | /** 31 | * [使用 GregorianCalendar 格式化 Date](Format date with Gregorian calendar) 32 | * @description: zh - 使用 GregorianCalendar 格式化 Date 33 | * @description: en - Format date with Gregorian calendar 34 | * @version: V1.0 35 | * @author XiaoXunYao 36 | * @since 2021/6/19 9:19 上午 37 | * @param date: 日期 38 | * @return java.lang.String 39 | */ 40 | String format(Date date); 41 | 42 | /** 43 | * [格式化 Calendar](Formats a Calendar object) 44 | * @description: zh - 格式化 Calendar 45 | * @description: en - Formats a Calendar object 46 | * @version: V1.0 47 | * @author XiaoXunYao 48 | * @since 2021/6/19 9:17 上午 49 | * @param calendar: Calendar 50 | * @return java.lang.String 51 | */ 52 | String format(Calendar calendar); 53 | 54 | /** 55 | * 56 | * @description: zh - 将毫秒长的值格式化为提供的可追加项。 57 | * @description: en - Formats a millisecond long value into the supplied Appendable. 58 | * @version: V1.0 59 | * @author XiaoXunYao 60 | * @since 2021/6/19 9:16 上午 61 | * @param millis: 要格式化的毫秒值 62 | * @param buf: 要格式化为的缓冲区 63 | * @return B 64 | */ 65 | B format(long millis, B buf); 66 | 67 | /** 68 | * [使用GregorianCalendar将aDate对象格式化为提供的Appendable。](Formats aDate object into the supplied Appendable using a GregorianCalendar.) 69 | * @description: zh - 使用GregorianCalendar将aDate对象格式化为提供的Appendable。 70 | * @description: en - Formats aDate object into the supplied Appendable using a GregorianCalendar. 71 | * @version: V1.0 72 | * @author XiaoXunYao 73 | * @since 2021/6/19 9:13 上午 74 | * @param date: 要格式化的日期 75 | * @param buf: 要格式化为的缓冲区 76 | * @return B 77 | */ 78 | B format(Date date, B buf); 79 | 80 | /** 81 | * [将日历对象格式化为所提供的可追加项。](Formats a Calendar object into the supplied Appendable.) 82 | * @description: zh - 将日历对象格式化为所提供的可追加项。 83 | * @description: en - Formats a Calendar object into the supplied Appendable. 84 | * @version: V1.0 85 | * @author XiaoXunYao 86 | * @since 2021/6/19 9:12 上午 87 | * @param calendar: 要格式化的日历 88 | * @param buf: 要格式化为的缓冲区 89 | * @return B 90 | */ 91 | B format(Calendar calendar, B buf); 92 | } 93 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/util/unicodeUtil/UnicodeUtil.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.util.unicodeUtil; 2 | 3 | import com.xiaoTools.core.text.stringBuilder.StrBuilder; 4 | import com.xiaoTools.lang.constant.Constant; 5 | import com.xiaoTools.util.charUtil.CharUtil; 6 | import com.xiaoTools.util.hexUtil.HexUtil; 7 | import com.xiaoTools.util.strUtil.StrUtil; 8 | 9 | /** 10 | * [提供Unicode字符串和普通字符串之间的转换](Provides conversion between Unicode strings and normal strings) 11 | * @description zh - 提供Unicode字符串和普通字符串之间的转换 12 | * @description en - Provides conversion between Unicode strings and normal strings 13 | * @version V1.0 14 | * @author XiaoXunYao 15 | * @since 2021-10-28 20:41:56 16 | */ 17 | public class UnicodeUtil { 18 | 19 | /** 20 | * [Unicode字符串转为普通字符串](Convert Unicode string to normal string) 21 | * @description zh - Unicode字符串转为普通字符串 22 | * @description en - Convert Unicode string to normal string 23 | * @version V1.0 24 | * @author XiaoXunYao 25 | * @since 2021-10-28 20:43:58 26 | * @param unicode Unicode字符串 27 | * @return java.lang.String 28 | */ 29 | public static String toString(String unicode) { 30 | if (StrUtil.isBlank(unicode)) { 31 | return unicode; 32 | } 33 | 34 | final int len = unicode.length(); 35 | StrBuilder sb = StrBuilder.create(len); 36 | int i; 37 | int pos = Constant.ZERO; 38 | while ((i = StrUtil.indexOfIgnoreCase(unicode, "\\u", pos)) != Constant.NEGATIVE_ONE) { 39 | sb.append(unicode, pos, i);//写入Unicode符之前的部分 40 | pos = i; 41 | if (i + Constant.FIVE < len) { 42 | char c; 43 | try { 44 | c = (char) Integer.parseInt(unicode.substring(i + Constant.TWO, i + Constant.SIX), Constant.SIXTEEN); 45 | sb.append(c); 46 | pos = i + Constant.SIX; 47 | } catch (NumberFormatException e) { 48 | sb.append(unicode, pos, i + Constant.TWO); 49 | pos = i + Constant.TWO; 50 | } 51 | } else { 52 | break; 53 | } 54 | } 55 | 56 | if (pos < len) { 57 | sb.append(unicode, pos, len); 58 | } 59 | return sb.toString(); 60 | } 61 | 62 | 63 | public static String toUnicode(char c) { 64 | return HexUtil.toUnicodeHex(c); 65 | } 66 | 67 | public static String toUnicode(int c) { 68 | return HexUtil.toUnicodeHex(c); 69 | } 70 | 71 | public static String toUnicode(String str) { 72 | return toUnicode(str, Constant.TRUE); 73 | } 74 | 75 | /** 76 | * [字符串编码为Unicode形式](The string is encoded in Unicode) 77 | * @description zh - 字符串编码为Unicode形式 78 | * @description en - The string is encoded in Unicode 79 | * @version V1.0 80 | * @author XiaoXunYao 81 | * @since 2021-10-28 20:46:23 82 | * @param str 被编码的字符串 83 | * @param isSkipAscii 是否跳过ASCII字符(只跳过可见字符) 84 | * @return java.lang.String 85 | */ 86 | public static String toUnicode(String str, boolean isSkipAscii) { 87 | if (StrUtil.isEmpty(str)) { 88 | return str; 89 | } 90 | 91 | final int len = str.length(); 92 | final StrBuilder unicode = StrBuilder.create(str.length() * Constant.SIX); 93 | char c; 94 | for (int i = Constant.ZERO; i < len; i++) { 95 | c = str.charAt(i); 96 | unicode.append(isSkipAscii && CharUtil.isAsciiPrintable(c) ? c : HexUtil.toUnicodeHex(c)); 97 | } 98 | return unicode.toString(); 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/convert/abstractConverter/inherit/OriginalRegistry.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.convert.abstractConverter.inherit; 2 | 3 | import com.xiaoTools.core.convert.Convert; 4 | import com.xiaoTools.core.convert.abstractConverter.AbstractConverter; 5 | import com.xiaoTools.core.convert.numberConverter.NumberConverter; 6 | import com.xiaoTools.core.exception.convertException.ConvertException; 7 | import com.xiaoTools.lang.constant.Constant; 8 | import com.xiaoTools.util.objectUtil.ObjectUtil; 9 | 10 | import java.io.Serial; 11 | import java.util.function.Function; 12 | 13 | /** 14 | * [原始类型的转换器](Converter of primitive type) 15 | * @description: zh - 原始类型的转换器 16 | * @description: en - Converter of primitive type 17 | * @version: V1.0 18 | * @author XiaoXunYao 19 | * @since 2021/6/17 3:27 下午 20 | */ 21 | public class OriginalRegistry extends AbstractConverter { 22 | 23 | @Serial 24 | private static final long serialVersionUID = 1L; 25 | 26 | private final Class targetType; 27 | 28 | /** 29 | * [构造](structure) 30 | * @description: zh - 构造 31 | * @description: en - structure 32 | * @version: V1.0 33 | * @author XiaoXunYao 34 | * @since 2021/6/17 3:31 下午 35 | * @param clazz: 需要转换的原始 36 | */ 37 | public OriginalRegistry(Class clazz) { 38 | if (Constant.NULL == clazz) { 39 | throw new NullPointerException("PrimitiveConverter not allow null target type!"); 40 | } else if (!clazz.isPrimitive()) { 41 | throw new IllegalArgumentException("[" + clazz + "] is not a primitive class!"); 42 | } 43 | this.targetType = clazz; 44 | } 45 | 46 | @Override 47 | protected Object convertInternal(Object value) { 48 | return null; 49 | } 50 | 51 | protected static Object convert(Object value, Class primitiveClass, Function toStringFunc) { 52 | if (byte.class == primitiveClass) { 53 | return ObjectUtil.defaultIfNull(NumberConverter.convert(value, Byte.class, toStringFunc), Constant.ZERO); 54 | } else if (short.class == primitiveClass) { 55 | return ObjectUtil.defaultIfNull(NumberConverter.convert(value, Short.class, toStringFunc), Constant.ZERO); 56 | } else if (int.class == primitiveClass) { 57 | return ObjectUtil.defaultIfNull(NumberConverter.convert(value, Integer.class, toStringFunc), Constant.ZERO); 58 | } else if (long.class == primitiveClass) { 59 | return ObjectUtil.defaultIfNull(NumberConverter.convert(value, Long.class, toStringFunc), Constant.ZERO); 60 | } else if (float.class == primitiveClass) { 61 | return ObjectUtil.defaultIfNull(NumberConverter.convert(value, Float.class, toStringFunc), Constant.ZERO); 62 | } else if (double.class == primitiveClass) { 63 | return ObjectUtil.defaultIfNull(NumberConverter.convert(value, Double.class, toStringFunc), Constant.ZERO); 64 | } else if (char.class == primitiveClass) { 65 | return Convert.convert(Character.class, value); 66 | } else if (boolean.class == primitiveClass) { 67 | return Convert.convert(Boolean.class, value); 68 | } 69 | 70 | throw new ConvertException("Unsupported target type: {}", primitiveClass); 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/convert/mapConverter/MapConverter.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.convert.mapConverter; 2 | 3 | import java.lang.reflect.Type; 4 | import java.util.Map; 5 | import java.util.Map.Entry; 6 | import java.util.Objects; 7 | 8 | import com.xiaoTools.core.convert.abstractConverter.AbstractConverter; 9 | import com.xiaoTools.core.convert.converterRegistry.ConverterRegistry; 10 | import com.xiaoTools.lang.constant.Constant; 11 | import com.xiaoTools.util.beanUtil.BeanUtil; 12 | import com.xiaoTools.util.mapUtil.MapUtil; 13 | import com.xiaoTools.util.strUtil.StrUtil; 14 | import com.xiaoTools.util.typeUtil.TypeUtil; 15 | 16 | /** 17 | * [Map 转换器](Map converter) 18 | * @description zh - Map 转换器 19 | * @description en - Map converter 20 | * @version V1.0 21 | * @author XiaoXunYao 22 | * @since 2021-10-25 08:33:29 23 | */ 24 | public class MapConverter extends AbstractConverter> { 25 | private static final long serialVersionUID = 1L; 26 | 27 | /** 28 | * Map类型 29 | */ 30 | private final Type mapType; 31 | 32 | /** 33 | * 键类型 34 | */ 35 | private final Type keyType; 36 | 37 | /** 38 | * 值类型 39 | */ 40 | private final Type valueType; 41 | 42 | public MapConverter(Type mapType) { 43 | this(mapType, TypeUtil.getTypeArgument(mapType, Constant.ZERO), TypeUtil.getTypeArgument(mapType, 1)); 44 | } 45 | 46 | public MapConverter(Type mapType, Type keyType, Type valueType) { 47 | this.mapType = mapType; 48 | this.keyType = keyType; 49 | this.valueType = valueType; 50 | } 51 | 52 | @Override 53 | @SuppressWarnings({ "rawtypes", "unchecked" }) 54 | protected Map convertInternal(Object value) { 55 | Map map; 56 | if (value instanceof Map) { 57 | final Type[] typeArguments = TypeUtil.getTypeArguments(value.getClass()); 58 | if (null != typeArguments // 59 | && 2 == typeArguments.length// 60 | && Objects.equals(this.keyType, typeArguments[0]) // 61 | && Objects.equals(this.valueType, typeArguments[1])) { 62 | return (Map) value; 63 | } 64 | map = MapUtil.createMap(TypeUtil.getClass(this.mapType)); 65 | convertMapToMap((Map) value, map); 66 | } else if (BeanUtil.isBean(value.getClass())) { 67 | map = BeanUtil.beanToMap(value); 68 | map = convertInternal(map); 69 | } else { 70 | throw new UnsupportedOperationException(StrUtil.format("Unsupport toMap value type: {}", value.getClass().getName())); 71 | } 72 | return map; 73 | } 74 | 75 | /** 76 | * [Map转Map](Map to Map) 77 | * @description zh - Map转Map 78 | * @description en - Map to Map 79 | * @version V1.0 80 | * @author XiaoXunYao 81 | * @since 2021-10-25 08:32:51 82 | * @param srcMap 源Map 83 | * @param targetMap 目标Map 84 | */ 85 | private void convertMapToMap(Map srcMap, Map targetMap) { 86 | final ConverterRegistry convert = ConverterRegistry.getInstance(); 87 | Object key; 88 | Object value; 89 | for (Entry entry : srcMap.entrySet()) { 90 | key = TypeUtil.isUnknown(this.keyType) ? entry.getKey() : convert.convert(this.keyType, entry.getKey()); 91 | value = TypeUtil.isUnknown(this.valueType) ? entry.getValue() : convert.convert(this.valueType, entry.getValue()); 92 | targetMap.put(key, value); 93 | } 94 | } 95 | 96 | @Override 97 | @SuppressWarnings("unchecked") 98 | public Class> getTargetType() { 99 | return (Class>) TypeUtil.getClass(this.mapType); 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/util/serviceLoaderUtil/ServiceLoaderUtil.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.util.serviceLoaderUtil; 2 | 3 | import com.xiaoTools.lang.constant.Constant; 4 | import com.xiaoTools.util.classLoaderUtil.ClassLoaderUtil; 5 | import com.xiaoTools.util.objectUtil.ObjectUtil; 6 | 7 | import java.util.Iterator; 8 | import java.util.ServiceConfigurationError; 9 | import java.util.ServiceLoader; 10 | 11 | /** 12 | * [SPI机制中的服务加载工具类](Service loading tool class in SPI mechanism) 13 | * @description: zh - SPI机制中的服务加载工具类 14 | * @description: en - Service loading tool class in SPI mechanism 15 | * @version: V1.0 16 | * @author XiaoXunYao 17 | * @since 2021/6/17 9:22 上午 18 | */ 19 | public class ServiceLoaderUtil { 20 | 21 | /** 22 | * [加载第一个可用服务,如果用户定义了多个接口实现类,只获取第一个不报错的服务。](Load the first available service. If the user defines multiple interface implementation classes, only the first non error service will be obtained.) 23 | * @description: zh - 加载第一个可用服务,如果用户定义了多个接口实现类,只获取第一个不报错的服务。 24 | * @description: en - Load the first available service. If the user defines multiple interface implementation classes, only the first non error service will be obtained. 25 | * @version: V1.0 26 | * @author XiaoXunYao 27 | * @since 2021/6/17 9:23 上午 28 | * @param clazz: 服务接口 29 | * @return T 30 | */ 31 | public static T loadFirstAvailable(Class clazz) { 32 | final Iterator iterator = load(clazz).iterator(); 33 | while (iterator.hasNext()) { 34 | try { 35 | return iterator.next(); 36 | } catch (ServiceConfigurationError ignore) { 37 | // ignore 38 | } 39 | } 40 | return (T) Constant.NULL; 41 | } 42 | 43 | /** 44 | * [加载第一个服务,如果用户定义了多个接口实现类,只获取第一个。](Load the first service. If the user has defined multiple interface implementation classes, only the first one will be obtained.) 45 | * @description: zh - 加载第一个服务,如果用户定义了多个接口实现类,只获取第一个。 46 | * @description: en - Load the first service. If the user has defined multiple interface implementation classes, only the first one will be obtained. 47 | * @version: V1.0 48 | * @author XiaoXunYao 49 | * @since 2021/6/17 9:25 上午 50 | * @param clazz: 服务接口 51 | * @return T 52 | */ 53 | public static T loadFirst(Class clazz) { 54 | final Iterator iterator = load(clazz).iterator(); 55 | if (iterator.hasNext()) { 56 | return iterator.next(); 57 | } 58 | return (T) Constant.NULL; 59 | } 60 | 61 | /** 62 | * [加载服务](Load service) 63 | * @description: zh - 加载服务 64 | * @description: en - Load service 65 | * @version: V1.0 66 | * @author XiaoXunYao 67 | * @since 2021/6/17 9:25 上午 68 | * @param clazz: 服务接口 69 | * @return java.util.ServiceLoader 70 | */ 71 | public static ServiceLoader load(Class clazz) { 72 | return load(clazz, null); 73 | } 74 | 75 | /** 76 | * [加载服务](Load service) 77 | * @description: zh - 加载服务 78 | * @description: en - Load service 79 | * @version: V1.0 80 | * @author XiaoXunYao 81 | * @since 2021/6/17 9:32 上午 82 | * @param clazz:服务接口 83 | * @param loader: ClassLoader 84 | * @return java.util.ServiceLoader 85 | */ 86 | public static ServiceLoader load(Class clazz, ClassLoader loader) { 87 | return ServiceLoader.load(clazz, ObjectUtil.defaultIfNull(loader, ClassLoaderUtil.getClassLoader())); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/util/IdUtil/IdUtil.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.util.IdUtil; 2 | 3 | import com.xiaoTools.lang.constant.Constant; 4 | import com.xiaoTools.util.IdUtil.objectId.ObjectId; 5 | import com.xiaoTools.util.IdUtil.snowflake.Snowflake; 6 | import com.xiaoTools.util.IdUtil.uuid.UUID; 7 | 8 | /** 9 | * [产生的随机ID工具类](Generated random ID tool class) 10 | * @description: zh - 产生的随机ID工具类 11 | * @description: en - Generated random ID tool class 12 | * @version: V1.0 13 | * @author XiaoXunYao 14 | * @since 2021/6/3 1:28 下午 15 | */ 16 | public class IdUtil { 17 | 18 | /** 19 | * [产生UUID,是基础的UUID,携带`-`的随机字符串](Generate UUID, is the basis of UUID, carry '-'random string) 20 | * @description: zh - 产生UUID,是基础的UUID,携带`-`的随机字符串 21 | * @description: en - Generate UUID, is the basis of UUID, carry '-'random string 22 | * @version: V1.0 23 | * @author XiaoXunYao 24 | * @since 2021/6/6 3:17 下午 25 | * @return java.lang.String 26 | */ 27 | public static String randomUUID(){ 28 | return UUID.randomUUID().toString(); 29 | } 30 | 31 | /** 32 | * [产生了简化的UUID,去除了`-`的随机字符串](A simplified UUID is generated and the random string of '-' is removed) 33 | * @description: zh - 产生了简化的UUID,去除了`-`的随机字符串 34 | * @description: en - A simplified UUID is generated and the random string of '-' is removed 35 | * @version: V1.0 36 | * @author XiaoXunYao 37 | * @since 2021/6/6 3:21 下午 38 | * @return java.lang.String 39 | */ 40 | public static String simpleUUID(){ 41 | return UUID.randomUUID().toString(Constant.TRUE); 42 | } 43 | 44 | /** 45 | * [产生一个性能更快更稳定的UUID](Generate a faster and more stable UUID) 46 | * @description: zh - 产生一个性能更快更稳定的UUID 47 | * @description: en - Generate a faster and more stable UUID 48 | * @version: V1.0 49 | * @author XiaoXunYao 50 | * @since 2021/6/6 3:26 下午 51 | * @return java.lang.String 52 | */ 53 | public static String fastUUID(){ 54 | return UUID.fastUUID().toString(); 55 | } 56 | 57 | /** 58 | * [产生性能更快并且没有`-`的UUID](Produce faster performance UUID without '-') 59 | * @description: zh - 产生性能更快并且没有`-`的UUID 60 | * @description: en - Produce faster performance UUID without '-' 61 | * @version: V1.0 62 | * @author XiaoXunYao 63 | * @since 2021/6/6 3:28 下午 64 | * @return java.lang.String 65 | */ 66 | public static String fastSimpleUUID(){ 67 | return UUID.fastUUID().toString(Constant.TRUE); 68 | } 69 | 70 | /** 71 | * [创建一个简单的ObjectID](Create a simple ObjectID) 72 | * @description: zh - 创建一个简单的ObjectID 73 | * @description: en - Create a simple ObjectID 74 | * @version: V1.0 75 | * @author XiaoXunYao 76 | * @since 2021/6/7 9:40 上午 77 | * @return java.lang.String 78 | */ 79 | public static String objectId() { 80 | return ObjectId.nextId(); 81 | } 82 | 83 | /** 84 | * [创建Twitter的Snowflake 算法生成器。](Create Twitter's snowflake algorithm generator.) 85 | * @description: zh - 创建Twitter的Snowflake 算法生成器。 86 | * @description: en - Create Twitter's snowflake algorithm generator. 87 | * @version: V1.0 88 | * @author XiaoXunYao 89 | * @since 2021/6/7 9:03 上午 90 | * @param workId: [终端ID](Terminal ID) 91 | * @param datacenterId: [数据中心ID](Data center ID) 92 | * @return com.xiaoTools.util.IdUtil.snowflake.Snowflake 93 | */ 94 | public static Snowflake createSnowflakeId(long workId,long datacenterId){ 95 | return new Snowflake(workId,datacenterId); 96 | } 97 | 98 | } 99 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/date/dateUnit/DateUnit.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.date.dateUnit; 2 | 3 | import com.xiaoTools.lang.constant.Constant; 4 | 5 | import java.time.temporal.ChronoUnit; 6 | 7 | /** 8 | * [日期时间单位,每个单位都是以毫秒为基数](Date time units, each in milliseconds) 9 | * @description: zh - 日期时间单位,每个单位都是以毫秒为基数 10 | * @description: en - Date time units, each in milliseconds 11 | * @version: V1.0 12 | * @author XiaoXunYao 13 | * @since 2021/6/18 5:01 下午 14 | */ 15 | public enum DateUnit { 16 | /** 17 | * 一毫秒 18 | */ 19 | MS(Constant.ONE), 20 | /** 21 | * 一秒的毫秒数 22 | */ 23 | SECOND(Constant.ONE_THOUSAND), 24 | /** 25 | * 一分钟的毫秒数 26 | */ 27 | MINUTE(SECOND.getMillis() * Constant.SIXTY), 28 | /** 29 | * 一小时的毫秒数 30 | */ 31 | HOUR(MINUTE.getMillis() * Constant.SIXTY), 32 | /** 33 | * 一天的毫秒数 34 | */ 35 | DAY(HOUR.getMillis() * Constant.TWENTY_FOUR), 36 | /** 37 | * 一周的毫秒数 38 | */ 39 | WEEK(DAY.getMillis() * Constant.SEVEN); 40 | 41 | private final long millis; 42 | 43 | DateUnit(long millis) { 44 | this.millis = millis; 45 | } 46 | 47 | /** 48 | * [单位对应的毫秒数](The number of milliseconds corresponding to the unit) 49 | * @description: zh - 单位对应的毫秒数 50 | * @description: en - The number of milliseconds corresponding to the unit 51 | * @version: V1.0 52 | * @author XiaoXunYao 53 | * @since 2021/6/18 5:41 下午 54 | * @return long 55 | */ 56 | public long getMillis() { return this.millis; } 57 | 58 | public ChronoUnit toChronoUnit() { 59 | return DateUnit.toChronoUnit(this); 60 | } 61 | 62 | /** 63 | * [单位兼容转换,将ChronoUnit转换为对应的DateUnit](Unit compatible conversion: convert ChronoUnit to corresponding DateUnit) 64 | * @description: zh - 单位兼容转换,将ChronoUnit转换为对应的DateUnit 65 | * @description: en - Unit compatible conversion: convert ChronoUnit to corresponding DateUnit 66 | * @version: V1.0 67 | * @author XiaoXunYao 68 | * @since 2021/6/18 5:46 下午 69 | * @param unit: ChronoUnit 70 | * @return com.xiaoTools.date.dateUnit.DateUnit 71 | */ 72 | public static DateUnit of(ChronoUnit unit) { 73 | return switch (unit) { 74 | case MICROS -> DateUnit.MS; 75 | case SECONDS -> DateUnit.SECOND; 76 | case MINUTES -> DateUnit.MINUTE; 77 | case HOURS -> DateUnit.HOUR; 78 | case DAYS -> DateUnit.DAY; 79 | case WEEKS -> DateUnit.WEEK; 80 | default -> null; 81 | }; 82 | } 83 | 84 | /** 85 | * [单位兼容转换,将DateUnit转换为对应的ChronoUnit](Unit compatible conversion, converting DateUnit to corresponding ChronoUnit) 86 | * @description: zh - 单位兼容转换,将DateUnit转换为对应的ChronoUnit 87 | * @description: en - Unit compatible conversion, converting DateUnit to corresponding ChronoUnit 88 | * @version: V1.0 89 | * @author XiaoXunYao 90 | * @since 2021/6/18 5:47 下午 91 | * @param unit: DateUnit 92 | * @return java.time.temporal.ChronoUnit 93 | */ 94 | public static ChronoUnit toChronoUnit(DateUnit unit) { 95 | return switch (unit) { 96 | case MS -> ChronoUnit.MICROS; 97 | case SECOND -> ChronoUnit.SECONDS; 98 | case MINUTE -> ChronoUnit.MINUTES; 99 | case HOUR -> ChronoUnit.HOURS; 100 | case DAY -> ChronoUnit.DAYS; 101 | case WEEK -> ChronoUnit.WEEKS; 102 | default -> null; 103 | }; 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/core/io/fastByteArrayOutputStream/FastByteArrayOutputStream.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.core.io.fastByteArrayOutputStream; 2 | 3 | import java.io.IOException; 4 | import java.io.OutputStream; 5 | import java.nio.charset.Charset; 6 | 7 | import com.xiaoTools.core.exception.iORuntimeException.IORuntimeException; 8 | import com.xiaoTools.core.io.fastByteBuffer.FastByteBuffer; 9 | import com.xiaoTools.util.charsetUtil.CharsetUtil; 10 | import com.xiaoTools.util.objectUtil.ObjectUtil; 11 | 12 | /** 13 | * [基于快速缓冲FastByteBuffer的OutputStream](OutputStream based on fastbytebuffer) 14 | * @description zh - 基于快速缓冲FastByteBuffer的OutputStream 15 | * @description en - OutputStream based on fastbytebuffer 16 | * @version V1.0 17 | * @author XiaoXunYao 18 | * @since 2021-10-22 12:35:17 19 | */ 20 | public class FastByteArrayOutputStream extends OutputStream { 21 | 22 | private final FastByteBuffer buffer; 23 | 24 | public FastByteArrayOutputStream() { 25 | this(1024); 26 | } 27 | 28 | public FastByteArrayOutputStream(int size) { 29 | buffer = new FastByteBuffer(size); 30 | } 31 | 32 | @Override 33 | public void write(byte[] b, int off, int len) { 34 | buffer.append(b, off, len); 35 | } 36 | 37 | @Override 38 | public void write(int b) { 39 | buffer.append((byte) b); 40 | } 41 | 42 | public int size() { 43 | return buffer.size(); 44 | } 45 | 46 | @Override 47 | public void close() { 48 | // nop 49 | } 50 | 51 | public void reset() { 52 | buffer.reset(); 53 | } 54 | 55 | /** 56 | * [写出](Write) 57 | * @description zh - 写出 58 | * @description en - Write 59 | * @version V1.0 60 | * @author XiaoXunYao 61 | * @since 2021-10-22 12:32:17 62 | * @param out 输出流 63 | * @throws com.xiaoTools.core.exception.iORuntimeException.IORuntimeException 64 | */ 65 | public void writeTo(OutputStream out) throws IORuntimeException { 66 | final int index = buffer.index(); 67 | byte[] buf; 68 | try { 69 | for (int i = 0; i < index; i++) { 70 | buf = buffer.array(i); 71 | out.write(buf); 72 | } 73 | out.write(buffer.array(index), 0, buffer.offset()); 74 | } catch (IOException e) { 75 | throw new IORuntimeException(e); 76 | } 77 | } 78 | 79 | /** 80 | * [转为Byte数组](Convert to byte array) 81 | * @description zh - 转为Byte数组 82 | * @description en - Convert to byte array 83 | * @version V1.0 84 | * @author XiaoXunYao 85 | * @since 2021-10-22 12:33:03 86 | * @return byte[] 87 | */ 88 | public byte[] toByteArray() { 89 | return buffer.toArray(); 90 | } 91 | 92 | @Override 93 | public String toString() { 94 | return toString(CharsetUtil.defaultCharset()); 95 | } 96 | 97 | /** 98 | * [转为字符串](Convert to string) 99 | * @description zh - 转为字符串 100 | * @description en - Convert to string 101 | * @version V1.0 102 | * @author XiaoXunYao 103 | * @since 2021-10-22 12:33:29 104 | * @param charsetName 编码 105 | * @return java.lang.String 106 | */ 107 | public String toString(String charsetName) { 108 | return toString(CharsetUtil.charset(charsetName)); 109 | } 110 | 111 | /** 112 | * [转为字符串](Convert to string) 113 | * @description zh - 转为字符串 114 | * @description en - Convert to string 115 | * @version V1.0 116 | * @author XiaoXunYao 117 | * @since 2021-10-22 12:34:14 118 | * @param charset 编码 119 | * @return java.lang.String 120 | */ 121 | public String toString(Charset charset) { 122 | return new String(toByteArray(), 123 | ObjectUtil.defaultIfNull(charset, CharsetUtil.defaultCharset())); 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /src/main/java/com/xiaoTools/cache/beanInfoCache/BeanInfoCache.java: -------------------------------------------------------------------------------- 1 | package com.xiaoTools.cache.beanInfoCache; 2 | 3 | import java.beans.PropertyDescriptor; 4 | import java.util.Map; 5 | 6 | import com.xiaoTools.cache.simple.SimpleCache; 7 | import com.xiaoTools.cache.simple.method.CacheFun; 8 | 9 | /** 10 | * [Bean属性缓存](Bean attribute cache) 11 | * @description zh - Bean属性缓存 12 | * @description en - Bean attribute cache 13 | * @version V1.0 14 | * @author XiaoXunYao 15 | * @since 2021-10-26 10:00:46 16 | */ 17 | public enum BeanInfoCache { 18 | INSTANCE; 19 | 20 | private final SimpleCache, Map> pdCache = new SimpleCache<>(); 21 | private final SimpleCache, Map> ignoreCasePdCache = new SimpleCache<>(); 22 | 23 | /** 24 | * [获得属性名和 PropertyDescriptor Map 映射](Get property name and PropertyDescriptor Map mapping) 25 | * @description zh - 获得属性名和 PropertyDescriptor Map 映射 26 | * @description en - Get property name and PropertyDescriptor Map mapping 27 | * @version V1.0 28 | * @author XiaoXunYao 29 | * @since 2021-10-26 10:04:04 30 | * @param beanClass 31 | * @param ignoreCase 32 | * @return java.util.Map 33 | */ 34 | public Map getPropertyDescriptorMap(Class beanClass, boolean ignoreCase) { 35 | return getCache(ignoreCase).get(beanClass); 36 | } 37 | 38 | /** 39 | * [获得属性名和 PropertyDescriptor Map 映射](Get property name and PropertyDescriptor Map mapping) 40 | * @description zh - 获得属性名和 PropertyDescriptor Map 映射 41 | * @description en - Get property name and PropertyDescriptor Map mapping 42 | * @version V1.0 43 | * @author XiaoXunYao 44 | * @since 2021-10-26 10:05:31 45 | * @param beanClass Bean的类 46 | * @param ignoreCase 是否忽略大小写 47 | * @param supplier 缓存对象产生函数 48 | * @return java.util.Map 49 | */ 50 | public Map getPropertyDescriptorMap( 51 | Class beanClass, 52 | boolean ignoreCase, 53 | CacheFun> supplier) { 54 | return getCache(ignoreCase).get(beanClass, supplier); 55 | } 56 | 57 | /** 58 | * 加入缓存 59 | * 60 | * @param beanClass Bean的类 61 | * @param fieldNamePropertyDescriptorMap 属性名和{@link PropertyDescriptor}Map映射 62 | * @param ignoreCase 是否忽略大小写 63 | */ 64 | /** 65 | * [加入缓存](Add cache) 66 | * @description zh - 加入缓存 67 | * @description en - Add cache 68 | * @version V1.0 69 | * @author XiaoXunYao 70 | * @since 2021-10-26 10:06:39 71 | * @param beanClass Bean的类 72 | * @param fieldNamePropertyDescriptorMap 属性名和 PropertyDescriptor Map 映射 73 | * @param ignoreCase 是否忽略大小写 74 | */ 75 | public void putPropertyDescriptorMap(Class beanClass, Map fieldNamePropertyDescriptorMap, boolean ignoreCase) { 76 | getCache(ignoreCase).put(beanClass, fieldNamePropertyDescriptorMap); 77 | } 78 | 79 | /** 80 | * [根据是否忽略字段名的大小写](Depending on whether the case of the field name is ignored) 81 | * @description zh - 根据是否忽略字段名的大小写 82 | * @description en - Depending on whether the case of the field name is ignored 83 | * @version V1.0 84 | * @author XiaoXunYao 85 | * @since 2021-10-26 10:07:19 86 | * @param ignoreCase 是否忽略大小写 87 | * @return com.xiaoTools.cache.simple.SimpleCache, java.util.Map> 88 | */ 89 | private SimpleCache, Map> getCache(boolean ignoreCase) { 90 | return ignoreCase ? ignoreCasePdCache : pdCache; 91 | } 92 | 93 | } 94 | --------------------------------------------------------------------------------