diff --git a/src/main/java/cn/whaifree/leetCode/Array/LeetCode215.java b/src/main/java/cn/whaifree/leetCode/Array/LeetCode215.java index 0fba4dd..74a2a43 100644 --- a/src/main/java/cn/whaifree/leetCode/Array/LeetCode215.java +++ b/src/main/java/cn/whaifree/leetCode/Array/LeetCode215.java @@ -2,15 +2,49 @@ package cn.whaifree.leetCode.Array; import org.junit.Test; -import java.util.Arrays; -import java.util.Comparator; -import java.util.PriorityQueue; -import java.util.Random; +import java.io.*; +import java.util.*; +import java.util.function.BiConsumer; import static org.junit.Assert.assertArrayEquals; public class LeetCode215 { + public static void main(String[] args) throws FileNotFoundException { + String name = "/Users/kyriewhluo/IdeaProjects/tsf/tsf-dispatch/src/main/resources/tsf-dispatch.yml"; + // 读取每一行 + HashMap> map = new HashMap<>(); + try (BufferedReader reader = new BufferedReader(new FileReader(name))) { + String line; + while ((line = reader.readLine()) != null) { + if (line.contains("tsf-resource")) { + String[] split = line.split("/"); + String key = "/" + split[1] + "/" + split[2]; + List orDefault = map.getOrDefault(key, new ArrayList<>()); + orDefault.add(line); + map.put(key, orDefault); + } + } + } catch (IOException e) { + throw new RuntimeException(e); + } + + map.forEach(new BiConsumer>() { + @Override + public void accept(String s, List strings) { + System.out.println("# key:" + s); + System.out.println("# size:" + strings.size()); + for (String string : strings) { + System.out.println(string); + } + + for (int i = 0; i < 3; i++) { + System.out.println(); + } + } + }); + } + @Test public void sort_EmptyArray_ShouldHandleGracefull3y() { diff --git a/src/main/java/cn/whaifree/tech/dataStructure/listSeries.java b/src/main/java/cn/whaifree/tech/dataStructure/listSeries.java new file mode 100644 index 0000000..40a9c61 --- /dev/null +++ b/src/main/java/cn/whaifree/tech/dataStructure/listSeries.java @@ -0,0 +1,55 @@ +package cn.whaifree.tech.dataStructure; + +import org.junit.Test; + +import java.io.*; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.locks.ReentrantLock; + +public class listSeries { + + @Test + public void test() throws IOException, ClassNotFoundException { + + ReentrantLock reentrantLock = new ReentrantLock(); + + } + public static void main(String[] args) throws IOException, ClassNotFoundException { + List o = new ArrayList<>(); + o.add(new User(1, "110")); + + try(FileOutputStream fileOutputStream = new FileOutputStream("./user.ser")) { + ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream); + objectOutputStream.writeObject(o); + } + + + // 恢复对象 + try(FileInputStream fileInputStream = new FileInputStream("./user.ser")) { + ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream); + Object o1 = objectInputStream.readObject(); + List users = (List) o1; + System.out.println(users); + } + + } + static class User implements Serializable{ + int age; + String name; + + public User(int age, String name) { + this.age = age; + this.name = name; + } + + @Override + public String toString() { + return "User{" + + "age=" + age + + ", name='" + name + '\'' + + '}'; + } + } + +} diff --git a/user.ser b/user.ser new file mode 100644 index 0000000..3dba2c6 Binary files /dev/null and b/user.ser differ