implementation 'io.github.zhangliangbo:level0:1.0.0'
<dependency>
<groupId>io.github.zhangliangbo</groupId>
<artifactId>level0</artifactId>
<version>1.0.0</version>
</dependency>
void testAppend() {
println(Append.append(["a", "b", "c", "d"], "tail"))
}
[a, b, c, d, tail]
void testPrepend() {
println(Prepend.prepend(["a", "b", "c", "d"], "head"))
}
[head, a, b, c, d]
void testInsert() {
println(Insert.insert(["a", "b", "c", "d"], "x", 1))
}
[a, x, b, c, d]
void testDelete() {
println(Delete.delete(["a", "b", "c", "d"], [1, 3]))
}
[a, c]
void testRange() {
println(Range.range(1, 10, 2))
println(Range.range('a' as char, 'z' as char))
}
[1, 3, 5, 7, 9]
[a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y]
void testSubdivide() {
println(Subdivide.subdivide(0D, 10D, 3))
}
[0.0, 3.3333333333333335, 6.666666666666667, 10.0]
void testTake() {
def list = [1, 2, 3, 4, 5, 6, 7, 8, 9]
println(Take.take(list, 1, 7, 2))
println(Take.take(list, 0, list.size()))
}
[2, 4, 6]
[1, 2, 3, 4, 5, 6, 7, 8, 9]
void testDrop() {
def list = [1, 2, 3, 4, 5, 6, 7, 8, 9]
println(Drop.drop(list, 3))
println(Drop.drop(list, 1, 7, 2))
println(Drop.drop(list, 0, list.size()))
}
[4, 5, 6, 7, 8, 9]
[1, 3, 5, 7, 8, 9]
[]
void testFirstPosition() throws Exception {
println(FirstPosition.firstPosition([1, 2, 3, 4, 5], { integer -> integer > 0 }))
println(FirstPosition.firstPosition([1, 2, 3, 4, 5], { integer -> integer > 6 }, -1))
println(FirstPosition.firstPosition([1, 2, 3, 4, 5], { integer -> integer > 6 }))
}
0
-1
java.util.NoSuchElementException: No value present
def list = ["a", "b", "c", "d"]
println(Position.position(list, "a"))
println(Position.position(list, "b"))
println(Position.position(list, new Predicate<String>() {
@Override
boolean test(String t) {
return t.equals("c")
}
}))
[0]
[1]
[2]
void testExtract() {
println(Extract.extract(["a", "b", "c", "d"], [0, 1]))
}
[a, b]
void testCount() {
println(Count.count([1, 2, 3, 4, 5, 6, 7, 8, 9, 8], 8))
println(Count.count([1, 2, 3, 4, 5, 6, 7, 8, 9, 8], 2))
}
2
1
void testSelect() {
println(Select.select([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0], new Predicate<Integer>() {
@Override
boolean test(Integer t) {
return t > 5
}
}))
println(Select.select([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0], new Predicate<Integer>() {
@Override
boolean test(Integer t) {
return t <= 5
}
}))
}
[6, 7, 8, 9, 8, 7, 6]
[0, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1, 0]
void testSelectFirst() {
println(SelectFirst.selectFirst([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], new Predicate<Integer>() {
@Override
boolean test(Integer t) {
return t > 5;
}
}))
println(SelectFirst.selectFirst([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], new Predicate<Integer>() {
@Override
boolean test(Integer t) {
return t <= 5;
}
}))
}
6
0
void testTakeWhile() {
println(TakeWhile.takeWhile([0, 1, 2, 3, 4, 5, 4, 3, 2, 1, 0], new Predicate<Integer>() {
@Override
boolean test(Integer t) {
return t > 3
}
}))
println(TakeWhile.takeWhile([0, 1, 2, 3, 4, 5, 4, 3, 2, 1, 0], new Predicate<Integer>() {
@Override
boolean test(Integer t) {
return t <= 3
}
}))
}
[]
[0, 1, 2, 3]
void testArray() {
println(Array.array(new Function<Integer, Character>() {
@Override
Character apply(Integer integer) {
return integer as char
}
}, 26, 97))
}
[a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z]
void testTable() {
println(Table.table(new Function<Integer, String>() {
@Override
String apply(Integer t) {
return "index" + t
}
}, Range.range(10)))
println(Table.table(new BiFunction<Integer, Integer, String>() {
@Override
String apply(Integer f, Integer s) {
return "(" + f + "," + s + ")"
}
}, Range.range(10), Range.range(10)))
}
[index0, index1, index2, index3, index4, index5, index6, index7, index8, index9]
[[(0,0), (0,1), (0,2)], [(1,0), (1,1), (1,2)], [(2,0), (2,1), (2,2)]]
void testReverse() {
println(Reverse.reverse(["a", "b", "c", "d"]))
}
[d, c, b, a]
void testJoin() {
println(Join.join([1, 2, 3], [4, 5, 6]))
}
[1, 2, 3, 4, 5, 6]
void testIntersection() {
println(Intersection.intersection([1, 1, 2, 3], [3, 1, 4]))
}
[1, 3]
void testUnion() {
println(Union.union(["a", "b", "a", "c"], ["d", "a", "e", "b"]))
}
[a, b, c, d, e]
void testComplement() {
println(Complement.complement([1, 2, 3, 4, 5], [1, 2]))
}
[3, 4, 5]
void testSort() {
def list = [6, 4, 7, 3, 9, 4, 6, 8, 1, 2, 3]
println(Sort.sort(list))
}
[1, 2, 3, 3, 4, 4, 6, 6, 7, 8, 9]
void testOrdering() {
println(Ordering.ordering(["c", "a", "b"]))
}
[1, 2, 0]
public class Hello {
private String name;
private int age;
private String info;
private int number;
}
public class Interest {
private String name;
private int age;
}
void testAssociation() {
def map = Association.association(Rule.valueOf("a", 1), Rule.valueOf("b", 2), Rule.valueOf("c", 3))
println(map)
}
[a:1, b:2, c:3]
void testAssociation3() {
Hello hello = new Hello()
hello.setName("xxl")
hello.setAge(18)
hello.setInfo("info")
hello.setNumber(2)
def map = Association.association(hello, ["name", "age"])
println(map)
}
[name:xxl, age:18]
void testAssociation1() {
Hello hello = new Hello()
hello.setName("xxl")
hello.setAge(18)
hello.setInfo("info")
hello.setNumber(2)
def map = Association.association(hello)
println(map)
}
[number:2, name:xxl, age:18, info:info]
void testAssociation2() {
Hello hello = new Hello()
hello.setName("xxl")
hello.setAge(18)
hello.setInfo("info")
hello.setNumber(2)
def map = Association.association(hello, Interest.class)
println(map)
}
[name:xxl, age:18]
void testAssociationMap() {
def map = AssociationMap.associationMap({ t -> Math.sqrt(t) }, [1, 2, 3, 4])
println(map)
}
[1:1.0, 2:1.4142135623730951, 3:1.7320508075688772, 4:2.0]
void testAssociationMap1() {
def now = AssociationMap.associationMap({ t -> Rule.valueOf(t.getValue(), t.getKey()) }, ["a": 1, "b": 2, "c": 3, "d": 4])
println(now)
}
[1:a, 2:b, 3:c, 4:d]
void testKeyMap() {
println(KeyMap.keyMap(new Function<Integer, String>() {
@Override
String apply(Integer k1) {
return Math.pow(k1, 2)
}
}, [1: "a", 2: "b", 3: "c", 4: "d"]))
}
[16.0:d, 1.0:a, 4.0:b, 9.0:c]
void testKeys() {
println(Keys.keys(["a": 1, "b": 2, "c": 3, "d": 4, "e": 5]))
}
[a, b, c, d, e]
void testKeys1() {
Hello hello = new Hello()
hello.setName("xxl")
hello.setAge(111)
hello.setNumber(1)
hello.setInfo("hello world")
println(Keys.keys(hello))
}
[name, age, info, number]
void testKeys2() {
println(Keys.keys(Hello.class))
}
[name, age, info, number]
void testKeySelect() {
println(KeySelect.keySelect([1: "a", 2: "b", 3: "c", 4: "d", 5: "e"], new Predicate<Integer>() {
@Override
boolean test(Integer integer) {
return integer > 3
}
}))
}
[4:d, 5:e]
void testKeySort() {
println(KeySort.keySort(["b": 1, "c": 2, "a": 3]))
}
[a:3, b:1, c:2]
void testKeySortBy() {
println(KeySortBy.keySortBy([1: "a", 2: "b", 3: "c", 4: "d"], new Function<Integer, Integer>() {
@Override
Integer apply(Integer k) {
return -k
}
}))
}
[4:d, 3:c, 2:b, 1:a]
void testKeyValueMap() {
println(KeyValueMap.keyValueMap(new BiFunction<Integer, String, String>() {
@Override
String apply(Integer k, String v) {
return k + v
}
}, [1: "a", 2: "b", 3: "c", 4: "b"]))
}
[1a, 2b, 3c, 4b]
void testValues() {
println(Values.values([1: "a", 2: "b", 3: "c", 4: "d", 5: "c"]))
}
[a, b, c, d, c]
void testTestValues() {
Hello hello = new Hello()
hello.setName("xxl")
hello.setAge(111)
hello.setNumber(1)
hello.setInfo("hello world")
println(Values.values(hello))
}
[1, xxl, 111, hello world]
void testTestValues1() {
Hello hello = new Hello()
hello.setName("xxl")
hello.setAge(111)
hello.setNumber(1)
hello.setInfo("hello world")
println(Values.values(hello, ["name", "age"]))
}
[xxl, 111]
void testPopulateObject() {
def map = [name: "aaa", age: 1, info: "lllll", number: 5]
println(PopulateObject.populateObject(map, Hello.class))
}
Hello{name='aaa', age=1, info='lllll', number=5}
void testPopulateObject1() {
def map = [name: "aaa", age: 1, info: "lllll", number: 5]
Hello hello = new Hello()
println(PopulateObject.populateObject(map, hello))
}
Hello{name='aaa', age=1, info='lllll', number=5}
void testPopulateObject2() {
Hello src = new Hello()
src.setName("xxl")
src.setAge(111)
src.setNumber(1)
src.setInfo("hello world")
println(PopulateObject.populateObject(src, Hello.class))
}
Hello{name='xxl', age=111, info='hello world', number=1}
void testPopulateObject3() {
Hello src = new Hello()
src.setName("xxl")
src.setAge(111)
src.setNumber(1)
src.setInfo("hello world")
Hello dst = new Hello()
println(PopulateObject.populateObject(src, dst))
}
Hello{name='xxl', age=111, info='hello world', number=1}
void testGroupBy() {
println(GroupBy.groupBy([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0], new Function<Integer, String>() {
@Override
String apply(Integer v) {
return String.valueOf(v)
}
}))
}
[0:[0, 0], 1:[1, 1], 2:[2, 2], 3:[3, 3], 4:[4, 4], 5:[5, 5], 6:[6, 6], 7:[7, 7], 8:[8, 8], 9:[9]]
void testStringCases() {
println(StringCases.stringCases("the cat in the hat", "a.*e")) //默认第0个组
println(StringCases.stringCases("the cat in the hat", "a(.*)e", 1)) //选择第1个组
println(StringCases.stringCases("abcdabcdcd", "abc|cd"))
}
[at in the]
[t in th]
[abc, abc, cd]
void testStringRiffle() {
System.out.println(StringRiffle.stringRiffle(Arrays.asList("zlb", "hwj", "dsx"), "|"))
}
zlb|hwj|dsx
void testStringSplit() {
println(StringSplit.stringSplit("a-b:c-d:e-f-g", ":", "-"))
}
[a, b, c, d, e, f, g]
void testStringContainQ() {
println(StringContainsQ.stringContainsQ("abcdefghijk", "abc"))
println(StringContainsQ.stringContainsQ("abcdefghijk", "abcc"))
}
true
false
void testStringCount() {
println(StringCount.stringCount("abc11abc22abc33abc44abc55", "abc"))
}
5
void testStringJoin() {
println(StringJoin.stringJoin(["a", "b", "c", "d", "e", "f", "g", "h"]))
}
abcdefgh
void testStringRepeat() {
System.out.println(StringRepeat.stringRepeat("<a>", 10))
}
<a><a><a><a><a><a><a><a><a><a>
void testAllTrue() {
def list = [1, 2, 3, 4, 5, 6, 7, 8, 9]
println(AllTrue.allTrue(list, new Predicate<Integer>() {
@Override
boolean test(Integer t) {
return t < 10
}
}))
println(AllTrue.allTrue(list, new Predicate<Integer>() {
@Override
boolean test(Integer t) {
return t < 9
}
}))
}
true
false
void testAnyTrue() {
def list = [1, 2, 3, 4, 5, 6, 7, 8, 9]
println(AnyTrue.anyTrue(list, new Predicate<Integer>() {
@Override
boolean test(Integer t) {
return t > 1
}
}))
println(AnyTrue.anyTrue(list, new Predicate<Integer>() {
@Override
boolean test(Integer t) {
return t > 8
}
}))
println(AllTrue.allTrue(list, new Predicate<Integer>() {
@Override
boolean test(Integer t) {
return t > 9
}
}))
}
true
true
false
void testNoneTrue() {
def list = [1, 2, 3, 4, 5, 6, 7, 8, 9]
println(NoneTrue.noneTrue(list, new Predicate<Integer>() {
@Override
boolean test(Integer t) {
return t > 1
}
}))
println(NoneTrue.noneTrue(list, new Predicate<Integer>() {
@Override
boolean test(Integer t) {
return t > 8
}
}))
println(NoneTrue.noneTrue(list, new Predicate<Integer>() {
@Override
boolean test(Integer t) {
return t > 9
}
}))
}
false
false
true
void testAnd() {
println(And.and(1 > 0, 2 < 3, 5 < 6, true))
println(And.and(1 > 0, 2 > 3, 5 < 6, true))
}
true
false
void testOr() {
println(or(1 > 0, 0 > 1, 1 + 1 == 2))
println(or(1 + 1 == 2, 2 + 2 == 4))
println(or(1 + 1 == 3, 2 + 2 == 3))
}
true
true
false
void testNot() throws Exception {
println(Not.not(1 + 1 == 2))
println(Not.not(Not.not(1 + 1 == 2)))//双重否定等于肯定
}
false
true
void testMemberQ() {
println(MemberQ.memberQ([1, 2, 3, 4, 5], 5))
println(MemberQ.memberQ([1, 2, 3, 4, 5], 6))
}
true
false
void testFreeQ(){
println(FreeQ.freeQ([1, 2, 3, 4, 5], 5))
println(FreeQ.freeQ([1, 2, 3, 4, 5], 6))
}
false
true
void testEvenQ() {
println(EvenQ.evenQ(2))
println(EvenQ.evenQ(3))
println(EvenQ.evenQ(4))
}
true
false
true
void testOddQ() {
println(OddQ.oddQ(2))
println(OddQ.oddQ(3))
println(OddQ.oddQ(4))
}
false
true
false
void testPrimerQ() {
println(PrimerQ.primerQ(2))
println(PrimerQ.primerQ(3))
println(PrimerQ.primerQ(4))
}
true
true
false
void testDateList() {
println(DateList.dateList("2020-06-01 12:00:00", "yyyy-MM-dd HH:mm:ss"))
}
Mon Jun 01 12:00:00 CST 2020
void testDateString() {
println(DateString.dateString(new Date(),"yyyy-MM-dd HH:mm:ss"))
}
2020-06-11 09:08:16
void testRandomSample() {
println(RandomSample.randomSample(Range.range(10), 4))
}
[7, 0, 4, 8]
void testRandomSample() {
println(RandomSample.randomSample(Range.range(10), 11))
}
[1, 2, 9, 3, 5, 4, 0, 8, 6, 7]
void testRandomInteger() throws Exception {
println(RandomInteger.randomInteger(0, 10, 10))
}
[6, 3, 1, 9, 3, 5, 7, 8, 4, 3]
void testRandomChoice() {
println(RandomChoice.randomChoice(["A", "B", "C", "D"], 10))
}
[A, A, C, C, A, B, C, A, C, D]
void testUrlDownload() {
println(URLDownload.urlDownload(
"https://repo1.maven.org/maven2/io/netty/netty-all/4.1.50.Final/netty-all-4.1.50.Final.jar",
"D:\\",
new Consumer<Float>() {
@Override
void accept(Float aFloat) {
System.err.println(aFloat)
}
}
))
}
99.94338
99.96768
99.97693
100.0
D:\netty-all-4.1.50.Final.jar
void testJarDownload() {
println(JarDownload.jarDownload("io.netty:netty-all:4.1.50.Final", "C:\\Users\\Admin\\Desktop\\a", new BiConsumer<String, Float>() {
@Override
void accept(String s, Float aFloat) {
System.out.println(s + "\t" + aFloat)
}
}))
}
C:\Users\Admin\Desktop\a\io\netty\netty-all\4.1.50.Final(默认返回目录,下挂三个sha1文件夹)
void testNIntegrate() {
Function<Double, Double> f = new Function<Double, Double>() {
@Override
Double apply(Double aDouble) {
return Math.sin(Math.sin(aDouble))
}
};
println(NIntegrate.nIntegrate(f, 0, 2, IntegrationMethod.IterativeLegendreGauss))
println(NIntegrate.nIntegrate(f, 0, 2, IntegrationMethod.MidPoint))
println(NIntegrate.nIntegrate(f, 0, 2, IntegrationMethod.Romberg))
println(NIntegrate.nIntegrate(f, 0, 2, IntegrationMethod.Simpson))
println(NIntegrate.nIntegrate(f, 0, 2, IntegrationMethod.Trapezoid))
}
1.2470560538570927
1.2470567278907687
1.2470560580690107
1.2470560656862713
1.2470556590870487
public class Pojo {
@ExcelColumnName(value = "名称", order = 2) //用于选择要导出的字段
private String name;
@ExcelColumnName(value = "年龄", order = 1)
private int age;
@ExcelColumnName(value = "性别", order = 3)
private String sex;
}
void testExportXlsx() {
println(Export.exportExcel(IExcel.JXL, "D:\\helloworld.xlsx", false, [[new Pojo("zlb", 18, "男")]]))
}
(文件内容)
年龄 名称 性别
18 zlb 男
void testExportWord() {
List<Object> content = new ArrayList<>()
content.add("table 1")
content.add([["c1", "c2", "c3"], ["aaa", "aa", "a"], ["aaa", "bbb", "ccc"]] as String[][])
content.add("table2")
content.add([["c1", "c2", "c3"], ["aaa", "bbb", "ccc"], ["aaa", "bbb", "ccc"]] as String[][])
content.add("table3")
content.add([["c1", "c2", "c3"], ["fff", "fff", "ff"], ["ggg", "ggg", "eee"]] as String[][])
println(Export.exportWord("D:\\helloworld.doc", content))
}
(文件内容)
table 1
c1 c2 c3
aaa aa a
aaa bbb ccc
table2
c1 c2 c3
aaa bbb ccc
aaa bbb ccc
table3
c1 c2 c3
fff fff ff
ggg ggg eee
void testExportText(){
println(Export.exportText("D:\\a.txt","abcdefgh",false))
println(Export.exportText("D:\\a.txt","123456789",true))
}
(文件内容)
abcdefgh123456789
void testImportStringXml() {
Map map = ImportString.importXml("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" +
"<xmlBean>\n" +
" <name>xxl</name>\n" +
" <age>18</age>\n" +
" <goods>\n" +
" <name>child1</name>\n" +
" <weight>5</weight>\n" +
" </goods>\n" +
" <goods>\n" +
" <name>child2</name>\n" +
" <weight>10</weight>\n" +
" </goods>\n" +
"</xmlBean>")
println(map)
}
[name:xxl, goods:[[name:child1, weight:5], [name:child2, weight:10]], age:18]
void testImportString() {
XmlBean xmlBean = ImportString.importXml("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" +
"<xmlBean>\n" +
" <name>xxl</name>\n" +
" <age>18</age>\n" +
" <goods>\n" +
" <name>child1</name>\n" +
" <weight>5</weight>\n" +
" </goods>\n" +
" <goods>\n" +
" <name>child2</name>\n" +
" <weight>10</weight>\n" +
" </goods>\n" +
"</xmlBean>", XmlBean.class)
println(xmlBean)
}
XmlBean{name='xxl', age=18, state=12, goods=[XmlBeanChild{name='child1', weight=5}, XmlBeanChild{name='child2', weight=10}]}
void testImportStringObject() {
Hello hello = ImportString.importJsonObject("{\"name\":\"zlb\",\"age\":111,\"info\":\"some info\",\"number\":1}", Hello.class)
println(hello)
}
Hello{name='zlb', age=111, info='some info', number=1}
void testImportStringJson() {
def map = ImportString.importJsonMapObject("{\n" +
" \"status\": \"0000\",\n" +
" \"message\": \"success\",\n" +
" \"data\": {\n" +
" \"title\": {\n" +
" \"id\": \"001\",\n" +
" \"name\" : \"白菜\"\n" +
" },\n" +
" \"content\": [\n" +
" {\n" +
" \"id\": \"001\",\n" +
" \"value\":\"你好 白菜\"\n" +
" },\n" +
" {\n" +
" \"id\": \"002\",\n" +
" \"value\":\"你好 萝卜\" \n" +
" }\n" +
" ]\n" +
" }\n" +
"}\n")
println(map)
}
[status:0000, message:success, data:[title:[id:001, name:白菜], content:[[id:001, value:你好 白菜], [id:002, value:你好 萝卜]]]]
void testImportStringMapString(){
def map = ImportString.importJsonMapString("{\n" +
" \"status\": \"0000\",\n" +
" \"message\": \"success\",\n" +
" \"data\": {\n" +
" \"title\": {\n" +
" \"id\": \"001\",\n" +
" \"name\" : \"白菜\"\n" +
" },\n" +
" \"content\": [\n" +
" {\n" +
" \"id\": \"001\",\n" +
" \"value\":\"你好 白菜\"\n" +
" },\n" +
" {\n" +
" \"id\": \"002\",\n" +
" \"value\":\"你好 萝卜\" \n" +
" }\n" +
" ]\n" +
" }\n" +
"}\n")
println(map)
}
[message:success, status:0000]
void testExportStringJson() {
Hello hello = new Hello()
hello.setName("zlb")
hello.setAge(111)
hello.setInfo("some info")
hello.setNumber(1)
println(ExportString.exportStringJson(hello))
}
{"name":"zlb","age":111,"info":"some info","number":1}
@XmlRootElement
@XmlType
@XmlAccessorType(XmlAccessType.FIELD)
public class XmlBean {
@XmlElement
public int age;
@XmlElement
public List<XmlBeanChild> goods;
@XmlElement
public String name;
@Override
public String toString() {
return "XmlBean{" +
"name='" + name + '\'' +
", age=" + age +
", goods=" + goods +
'}';
}
}
@XmlType
public class XmlBeanChild {
@XmlElement
public String name;
@XmlElement
public int weight;
@Override
public String toString() {
return "XmlBeanChild{" +
"name='" + name + '\'' +
", weight=" + weight +
'}';
}
}
void testExportStringXml() {
XmlBean xmlBean = new XmlBean()
xmlBean.name = "xxl"
xmlBean.age = 18
XmlBeanChild c1 = new XmlBeanChild();
c1.name = "child1"
c1.weight = 5
XmlBeanChild c2 = new XmlBeanChild();
c2.name = "child2"
c2.weight = 10
xmlBean.goods = [c1, c2]
println(ExportString.exportStringXml(xmlBean))
}
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xmlBean>
<age>18</age>
<goods>
<name>child1</name>
<weight>5</weight>
</goods>
<goods>
<name>child2</name>
<weight>10</weight>
</goods>
<name>xxl</name>
</xmlBean>
void testDeleteFile() {
println(DeleteFile.deleteFile("C:\\Users\\Admin\\Desktop\\a\\org\\apache\\commons\\commons-lang3\\3.10\\commons-lang3-3.10.jar"))
}
true
void testCopyFile() {
println(CopyFile.copyFile("C:\\a.jar","D:\\b.jar"))
}
D:\b.jar
void testFileExistsQ() {
println(FileExistsQ.fileExistsQ("C:\\a\\b\\c\\d"))
}
false
void testFileBaseName() throws Exception {
println(FileBaseName.fileBaseName("first"))
println(FileBaseName.fileBaseName("second.tar.gz"))
println(FileBaseName.fileBaseName("three."))
println(FileBaseName.fileBaseName("four.txt"))
println(FileBaseName.fileBaseName("C:\\Users\\zhang\\Rdrnss\\Code\\Flavors\\app\\release\\five.txt"))
}
first
second.tar
three
four
five
void testFileExtension() throws Exception {
println(FileExtension.fileExtension("file.txt"))
println(FileExtension.fileExtension("file.tar.gz"))
println(FileExtension.fileExtension("C:\\file\\file\\file.tar.gz"))
println(FileExtension.fileExtension("C:\\file\\file\\file.txt"))
}
txt
gz
gz
txt
void testFileNameTake() {
println(FileNameTake.fileNameTake("D:\\a\\b\\c\\d\\e\\f\\g\\h", -1))//后1个
println(FileNameTake.fileNameTake("D:\\a\\b\\c\\d\\e\\f\\g\\h", 1))//前1个
println(FileNameTake.fileNameTake("D:\\a\\b\\c\\d\\e\\f\\g\\h", 1, 4))//从0开始的索引
}
h
D:
a\b\c
void testDirectoryName() throws Exception {
println("dir:" + DirectoryName.directoryName("C:\\a\\b\\c\\d.txt", 0))
println("dir:" + DirectoryName.directoryName("C:\\a\\b\\c\\d.txt", 1))
println("dir:" + DirectoryName.directoryName("C:\\a\\b\\c\\d.txt", 2))
println("dir:" + DirectoryName.directoryName("C:\\a\\b\\c\\d.txt", 3))
println("dir:" + DirectoryName.directoryName("C:\\a\\b\\c\\d.txt", 4))
println("dir:" + DirectoryName.directoryName("C:\\a\\b\\c\\d.txt", 5))
println("dir:" + DirectoryName.directoryName("C:\\a\\b\\c\\d.txt", 6))
}
dir:C:\a\b\c\d.txt
dir:C:\a\b\c
dir:C:\a\b
dir:C:\a
dir:C:\
dir:null
dir:null
void testParentDirectory() throws Exception {
System.out.println(ParentDirectory.parentDirectory("C:\\Program Files\\abc.txt"))
System.out.println(ParentDirectory.parentDirectory("C:\\Program Files"))
}
C:\Program Files
C:\
void testFileNames() {
println(FileNames.fileNames(".*doc", "C:\\Users\\Admin\\Downloads"))
}
[C:\Users\Admin\Downloads\6614839830876524544 (1).apk, C:\Users\Admin\Downloads\6614839830876524544 (2).apk, C:\Users\Admin\Downloads\6614839830876524544 (3).apk, C:\Users\Admin\Downloads\6614839830876524544 (4).apk, C:\Users\Admin\Downloads\6614839830876524544.apk, C:\Users\Admin\Downloads\6678970299108560896.apk, C:\Users\Admin\Downloads\app-rice-debug.apk]
void testHostLookup() {
println(HostLookup.hostLookup("www.baidu.com"))
}
14.215.177.38
void testPingTime() {
System.err.println(PingTime.pingTime("www.baidu.com"))
}
24.0
void testTelnet() {
println(Telnet.telnet("www.baidu.com",80))
println(Telnet.telnet("www.baidu.com",8000))
}
true
false
void testRunProcess() {
def rule = External.runProcess("git help")
println(rule.key + "\n" + new String(rule.value))
}
0
usage: git [--version] [--help] [-C <path>] [-c <name>=<value>]
[--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
[-p | --paginate | -P | --no-pager] [--no-replace-objects] [--bare]
[--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
<command> [<args>]
void testRun() {
println(External.run('git --help'))
}
0
void testSendMail() {
println(External.sendMail("forbidden@aliyun.com", "附件", "<img src=\"https://himg2.huanqiucdn.cn/attachment2010/2019/1101/20191101072831653.jpg\"/>", [new File("C:\\Users\\zhang\\Desktop\\shu.jpg")], "someone@qq.com", "smtp.aliyun.com", "forbidden@aliyun.com", "forbidden"))
}
(邮件id)
void testBaseEncode() {
byte[] bytes = BaseEncode.baseEncode("hello world".getBytes())
println(new String(bytes))
}
aGVsbG8gd29ybGQ=
void testBaseDecode() {
def bytes = BaseDecode.baseDecode("aGVsbG8gd29ybGQ=".getBytes())
println(new String(bytes))
}
hello world
支持的方法
MD2("MD2"), MD5("MD5"), SHA1("SHA-1"), SHA224("SHA-224"), SHA256("SHA-256"), SHA384("SHA-384"), SHA512("SHA-512"), SHA3224("SHA3-224"), SHA3256("SHA3-256"), SHA3384("SHA3-384"), SHA3512("SHA3-512");
void testByteArray() {
println(Hash.encodeHexString(Hash.hashByteArray("hello world".getBytes(), Hash.Algorithm.MD5)))
}
5eb63bbbe01eeed093cb22bb8f5acdc3
void testByteBuffer() {
println(Hash.encodeHexString(Hash.hashByteBuffer(ByteBuffer.wrap("hello world".getBytes()), Hash.Algorithm.MD5)))
}
5eb63bbbe01eeed093cb22bb8f5acdc3
void testHashString() {
println(Hash.encodeHexString(Hash.hashString("hello world", Hash.Algorithm.MD5)))
}
5eb63bbbe01eeed093cb22bb8f5acdc3
void testHashFile() {
println(Hash.encodeHexString(Hash.hashFile("D:\\hhh.txt", Hash.Algorithm.MD5))) //文件里面的内容是'hello world'
}
5eb63bbbe01eeed093cb22bb8f5acdc3
void testHashStream() {
def stream = new FileInputStream("D:\\hhh.txt")
println(Hash.encodeHexString(Hash.hashStream(stream, Hash.Algorithm.MD5)))
stream.close()
}
5eb63bbbe01eeed093cb22bb8f5acdc3
void testMap() {
long s = System.currentTimeMillis()
println(
Map.map(t -> {
sleep(5000)
return t * t
}, [1, 2, 3, 4, 5, 6, 7, 8])
)
println("duration:" + (System.currentTimeMillis() - s))
}
[1, 4, 9, 16, 25, 36, 49, 64]
duration:40365
时间是:(n/maxCore+1)*oneItemTime
void testParallelMap() {
long s = System.currentTimeMillis()
println(
ParallelMap.parallelMap(t -> {
sleep(5000)
return t * t
}, [1, 2, 3, 4, 5, 6, 7, 8])
)
println("duration:" + (System.currentTimeMillis() - s))
}
[1, 4, 9, 16, 25, 36, 49, 64]
duration:5242