文档地址见:https://aaa-aa.github.io/basic-tools/
- 常用工具集合 basic-tool
public static void main(String[] args) {
AtomicLong counter = new AtomicLong(0);
String bigFilePath = "/Users/renhongqiang/Downloads/work-doc/2000W/test.csv";
BigFileReader.Builder builder = new BigFileReader.Builder(bigFilePath, line -> System.out.println(String.format("total record: %s,line is: %s", counter.incrementAndGet(), line)));
BigFileReader bigFileReader = builder
.threadPoolSize(100)
.charset(StandardCharsets.UTF_8)
.bufferSize(1024 * 1024).build();
bigFileReader.start();
}
支持集合、字符串、对象判空,注解类判定,以及各类综合操作
Date today = Dates.today();
Date date = Dates.addDays(custDate, 32);
String format = Dates.format(date);
Date custDate = Dates.parse("2020-04-23 25", Dates.DATE_FORMAT);
Date date = Dates.addDays(custDate, 32);
Date addM = Dates.addMinutes(date,5);
Order order = new Order("Carli","12112");
Order order2 = new Order("Michale","11223");
Order order3 = new Order("Marry","642321");
List<Order> list = new ArrayList<>();
list.add(order);
list.add(order2);
list.add(order3);
Map<String, Order> kvFieldBean = ExtCollections.kvFieldBean(Order::getOwner, list);
Order order = new Order("Carli","12112");
Order order2 = new Order("Carli","11223");
Order order3 = new Order("Marry","642321");
List<Order> list = new ArrayList<>();
list.add(order);
list.add(order2);
list.add(order3);
Map<String, List<Order>> kvFieldBeans = ExtCollections.kvFieldBeans(Order::getOwner, list);
System.out.println(kvFieldBeans);
Order order = new Order("Carli","12112");
Order order2 = new Order("Carli","11223");
Order order3 = new Order("Marry","642321");
List<Order> list = new ArrayList<>();
list.add(order);
list.add(order2);
list.add(order3);
Map<String, String> map = ExtCollections.kv(Order::getId, Order::getOwner, list);
@Test
public void testGenerate() {
System.out.println(IdCards.generate());
System.out.println(IdCards.generateByAreaName("东城区"));
}
IdCards.parseAge("420102199401015244")
IdCards.parseBirthday("420102199401015244")
boolean checkCardId = IdCards.checkCardId("420102199401015244");
String idCard = IdCards.trans15To18("420102199401015")
在需要的字段上加 @HideImg
@Test
public void testHide() {
Person person = new Person();
System.out.println(LogFormats.formatLog(person));
}
@Data
public static class Person {
@HideImg
private String img = "/9jhfsdhajfksjdfhuhiuwbjbdfoasuhrttttttthhhhhhhhhhhhhhhhhhdfuf";
@HideAnn
private String password = "128397287827802hhfashfkjhasfh";
@HideCollection
private List<String> cellphones = new ArrayList<>();
}
直接在字段上加@HideAnn注解
直接在集合字段上加@HideCollection注解
@Test
public void testHit() {
int count = 1;
for (int i = 0; i < 1000000; i++) {
boolean hit = Randoms.isScoreAHit(1, 1000);
if (hit) {
System.out.println(count++);
}
}
}
@Test
public void testRandomNumOrA() {
for (int i = 0; i < 10; i++) {
//指定5-8位长度字符串
System.out.println(Randoms.randomOfA(5, 8));
//指定4-7位长度数字
System.out.println(Randoms.randomOfD(4,7));
//指定4个长度的数字和字母混合字符串
System.out.println(Randoms.randomOfDA(4));
}
}
@Test
public void testRandomRegStr() {
System.out.println(Randoms.checkAndGetResultString());
}
@Test
public void testLineToHump() {
String authUser = "auth_user";
System.out.println(Strings.lineToHump(authUser));
}
@Test
public void testHumpToLine() {
String authUser = "authUser";
System.out.println(Strings.humpToLine(authUser));
}
@Test
public void testSubString() {
String demoString = "demo_string_123";
System.out.println(Strings.substring(demoString,1,3));
}
ProgressListener downProgress = new ProgressListener("下载计数器", datas.size())
picProgress.addCount("下载成功数");
picProgress.addCount("下载失败数");
picProgress.startLog();
1.默认10秒钟打印一次日志(可以指定,避免大量日志过多) 2.可以统计平均速率,和当前的速率
ExpireMap<String, String> map = new ExpireMap<>(1, 10);
map.put("aaa", "test", 3, TimeUnit.SECONDS);