Skip to content

Commit

Permalink
增加新代码
Browse files Browse the repository at this point in the history
  • Loading branch information
lijun695 committed May 27, 2024
1 parent 1c4f4a9 commit dad0be2
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/main/java/com/diguage/truman/concurrent/ConcurrentMapTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.diguage.truman.concurrent;

import org.junit.jupiter.api.Test;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicInteger;

public class ConcurrentMapTest {
@Test
public void test() {
ConcurrentMap<String, AtomicInteger> map = new ConcurrentHashMap<>();
// AtomicInteger cnt = map.putIfAbsent("abc", new AtomicInteger(10));
AtomicInteger cnt = map.computeIfAbsent("abc", (k) -> new AtomicInteger(10));
System.out.println(cnt);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.diguage.truman.concurrent;

import org.junit.jupiter.api.Test;

import java.time.LocalDateTime;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.LockSupport;

public class ScheduledThreadPoolExecutorTest {
@Test
public void test() {
ScheduledExecutorService executor = new ScheduledThreadPoolExecutor(0);
executor.scheduleAtFixedRate(() -> System.out.println("OKKK"), 0, 10, TimeUnit.MINUTES);
LockSupport.parkNanos(TimeUnit.MINUTES.toNanos(1));
System.out.println(executor);
}

@Test
public void testSchedule() {
ScheduledExecutorService executor = new ScheduledThreadPoolExecutor(0);
for (int i = 0; i < 100; i++) {
executor.schedule(() -> System.out.println(LocalDateTime.now() + " OKKK"), 0, TimeUnit.MINUTES);
}
LockSupport.parkNanos(TimeUnit.SECONDS.toNanos(10));
System.out.println(executor);
}
}
48 changes: 48 additions & 0 deletions src/main/java/com/diguage/truman/io/FileTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.diguage.truman.io;

import org.junit.jupiter.api.Test;

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Date;

import static java.nio.file.StandardOpenOption.TRUNCATE_EXISTING;

public class FileTest {

private static DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS");

@Test
public void test() {
File file = new File("/Users/lijun695/vm.log");
long mod = file.lastModified();
System.out.println(new Date(mod).toInstant().atZone(ZoneId.systemDefault()));
System.out.println(file.getName());
}

public static void main(String[] args) throws IOException {
for (int i = 0; i < 10; i++) {
Files.write(Paths.get("/tmp/abc123/456/20230609183256983"),
("" + i + " -- D瓜哥 · https://www.diguage.com").getBytes(StandardCharsets.UTF_8), TRUNCATE_EXISTING);
}
}

public static void createDirectory(String path) {
File file = new File(path);
if (file.exists() && !file.isDirectory()) {
file.delete();
}
if (!file.exists()) {
try {
Files.createDirectories(Paths.get(path));
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
13 changes: 13 additions & 0 deletions src/main/java/com/diguage/truman/math/BigDecimalTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.diguage.truman.math;

import org.junit.jupiter.api.Test;

import java.math.BigDecimal;

public class BigDecimalTest {
@Test
public void test() {
BigDecimal decimal = new BigDecimal("10.");
System.out.println(decimal);
}
}
22 changes: 22 additions & 0 deletions src/main/java/com/diguage/truman/time/FormatTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.diguage.truman.time;

import org.junit.jupiter.api.Test;

import java.time.Duration;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;

public class FormatTest {

@Test
public void test() {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS");
// ZonedDateTime time = ZonedDateTime.parse("20230815114735092", formatter);
LocalDateTime t3 = LocalDateTime.parse("20230609143033001", formatter);
LocalDateTime t1 = LocalDateTime.parse("20230815114735092", formatter);
LocalDateTime t2 = LocalDateTime.parse("20230815114735099", formatter);
System.out.println();
}
}
17 changes: 17 additions & 0 deletions src/main/java/com/diguage/truman/time/ZoneTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.diguage.truman.time;

import org.junit.jupiter.api.Test;

import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;

public class ZoneTest {
@Test
public void test() {
ZonedDateTime now = ZonedDateTime.now(ZoneId.of("Asia/Shanghai"));
ZonedDateTime tomorrow = now.plusDays(1L).truncatedTo(ChronoUnit.DAYS).plusHours(5L);
System.out.println(now);
System.out.println(tomorrow);
}
}

0 comments on commit dad0be2

Please sign in to comment.