From d6bac7e078e3650bff33c37835cc7619e4931ac4 Mon Sep 17 00:00:00 2001 From: Christine Chen <1369509439@qq.com> Date: Sat, 10 Apr 2021 00:28:15 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E4=B8=8D=E5=9C=A8maven?= =?UTF-8?q?=E4=B8=AD=E7=9A=84=E5=8C=85=EF=BC=8C=E4=BD=BF=E5=BE=97=E7=BC=96?= =?UTF-8?q?=E8=AF=91=E9=80=9A=E8=BF=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 +- chenyuuqun.iml | 38 ++++ src/main/java/Utils/StringUtils.java | 7 + .../builder/ResourcePoolConfig.java | 2 +- .../structural/composite/FileSystemNode.java | 2 - .../flyweight/chess/flyweight/ChessBoard.java | 7 +- .../input_and_output/yearCelebrate.java | 157 ------------- .../java/javabase/map/stream/StreamTest.java | 213 ------------------ .../java/javabase/stringTest/StringTest.java | 1 - 9 files changed, 51 insertions(+), 378 deletions(-) create mode 100644 chenyuuqun.iml create mode 100644 src/main/java/Utils/StringUtils.java delete mode 100644 src/main/java/java_language_basic/input_and_output/yearCelebrate.java delete mode 100644 src/main/java/javabase/map/stream/StreamTest.java diff --git a/.gitignore b/.gitignore index ea76a74..ca3360a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ target/ .idea/ - +chenyuuqun.iml diff --git a/chenyuuqun.iml b/chenyuuqun.iml new file mode 100644 index 0000000..81cac87 --- /dev/null +++ b/chenyuuqun.iml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/Utils/StringUtils.java b/src/main/java/Utils/StringUtils.java new file mode 100644 index 0000000..75c3ca2 --- /dev/null +++ b/src/main/java/Utils/StringUtils.java @@ -0,0 +1,7 @@ +package Utils; + +public class StringUtils { + public static boolean isEmpty(String str) { + return str == null || str.isEmpty(); + } +} diff --git a/src/main/java/design_pattern/creational/builder/ResourcePoolConfig.java b/src/main/java/design_pattern/creational/builder/ResourcePoolConfig.java index a649658..7530fdd 100644 --- a/src/main/java/design_pattern/creational/builder/ResourcePoolConfig.java +++ b/src/main/java/design_pattern/creational/builder/ResourcePoolConfig.java @@ -1,6 +1,6 @@ package design_pattern.creational.builder; -import com.taobao.api.internal.util.StringUtils; +import Utils.StringUtils; /** * @author chenyuqun diff --git a/src/main/java/design_pattern/structural/composite/FileSystemNode.java b/src/main/java/design_pattern/structural/composite/FileSystemNode.java index 53f4198..a2395c4 100644 --- a/src/main/java/design_pattern/structural/composite/FileSystemNode.java +++ b/src/main/java/design_pattern/structural/composite/FileSystemNode.java @@ -1,6 +1,4 @@ package design_pattern.structural.composite; - -import com.dingtalk.api.request.OapiChatSendRequest; import com.google.common.collect.Lists; import java.io.File; diff --git a/src/main/java/design_pattern/structural/flyweight/chess/flyweight/ChessBoard.java b/src/main/java/design_pattern/structural/flyweight/chess/flyweight/ChessBoard.java index 1cf1fc9..7fa5e70 100644 --- a/src/main/java/design_pattern/structural/flyweight/chess/flyweight/ChessBoard.java +++ b/src/main/java/design_pattern/structural/flyweight/chess/flyweight/ChessBoard.java @@ -2,7 +2,6 @@ import com.google.common.collect.Maps; -import javax.jnlp.SingleInstanceListener; import java.util.Map; /** @@ -14,10 +13,12 @@ public class ChessBoard { public ChessBoard() { init(); } + private void init() { - chessPieces.put(1,new ChessPiece(ChessPieceUnitFactory.getChessPiece(1),0,0)); - chessPieces.put(2,new ChessPiece(ChessPieceUnitFactory.getChessPiece(2),1,0)); + chessPieces.put(1, new ChessPiece(ChessPieceUnitFactory.getChessPiece(1), 0, 0)); + chessPieces.put(2, new ChessPiece(ChessPieceUnitFactory.getChessPiece(2), 1, 0)); } + private void move(int chessPieceId, int toPositionX, int toPositionY) { // ...省略... } diff --git a/src/main/java/java_language_basic/input_and_output/yearCelebrate.java b/src/main/java/java_language_basic/input_and_output/yearCelebrate.java deleted file mode 100644 index 87478e4..0000000 --- a/src/main/java/java_language_basic/input_and_output/yearCelebrate.java +++ /dev/null @@ -1,157 +0,0 @@ -package java_language_basic.input_and_output; - -import com.google.common.collect.Maps; -import com.taobao.api.internal.util.StringUtils; -import org.junit.Test; - -import java.io.BufferedReader; -import java.io.FileInputStream; -import java.io.InputStreamReader; -import java.util.Map; - -/** - * @author chenyuqun - * @date 2021/2/11 10:43 下午 - */ -public class yearCelebrate { - public static void main(String[] args) { - String fileName = "/Users/playcrab/Documents/kosworkspace/log/yearCelebrate/fajiangmingdan.ip"; - // key是ip, value是次数。 - Map map = Maps.newHashMap(); - try { - try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(fileName), "UTF-8"))) { - String s; - while ((s = br.readLine()) != null) {//使用readLine方法,一次读一行 - int oldValue = map.getOrDefault(s, 0); - map.put(s, oldValue + 1); - } - } - } catch (Exception e) { - e.printStackTrace(); - } -// 测试 -// System.out.println(map.size()); -// System.out.println(map.get("120.92.126.89")); -// System.out.println(map.get("120.92.127.30")); -// System.out.println(map.get("120.92.126.87")); - // 发了多次邮件奖励的 - Map ip_wit_multi = Maps.newHashMap(); - for (Map.Entry entry : map.entrySet()) { - if (entry.getValue() == 1) { - continue; - } - ip_wit_multi.put(entry.getKey(), entry.getValue()); - } - for (Map.Entry entry : ip_wit_multi.entrySet()) { - System.out.println(entry.getKey() + "," + entry.getValue()); - } - - String ip_sec_file_name = "/Users/playcrab/Documents/kosworkspace/log/yearCelebrate/ip_and_sec.txt"; - Map ipSec = Maps.newHashMap(); - try { - try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(ip_sec_file_name), "UTF-8"))) { - String s; - while ((s = br.readLine()) != null) {//使用readLine方法,一次读一行 - String[] strings = StringUtils.split(s, " "); - ipSec.put(strings[0], strings[1]); - } - } - } catch (Exception e) { - e.printStackTrace(); - } - - String ip_group_file_name = "/Users/playcrab/Documents/kosworkspace/log/yearCelebrate/ip_and_sec.txt"; - Map ipGroup = Maps.newHashMap(); - try { - try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(ip_group_file_name), "UTF-8"))) { - String s; - while ((s = br.readLine()) != null) {//使用readLine方法,一次读一行 - String[] strings = StringUtils.split(s, " "); - ipGroup.put(strings[0], strings[2]); - } - } - } catch (Exception e) { - e.printStackTrace(); - } - String fajiangmingdanFileName = "/Users/playcrab/Documents/kosworkspace/log/yearCelebrate/fajiangmingdan.txt"; - System.out.println(ipSec.size()); - System.out.println(ipGroup.size()); - int totalNum = 0; - // key是sec,value是多发的玩家信息 - Map> count = Maps.newHashMap(); - - for (Map.Entry entry : ip_wit_multi.entrySet()) { - String ip = entry.getKey(); - String sec = ipSec.get(ip); - String group = ipGroup.get(ip); - String rid = getRids(group, fajiangmingdanFileName); - Map rids = findRids(rid, sec); - totalNum += rids.size(); - count.put(sec, rids); - } - - for (Map.Entry entry : ip_wit_multi.entrySet()) { - String sec = ipSec.get(entry.getKey()); - int sendTime = entry.getValue(); - Map playerInfo = count.get(sec); - System.out.println(sec + "服多发了" + (sendTime - 1) + "封邮件,玩家是:"); - playerInfo.forEach((key, value) -> { - System.out.print("[" + key + "," + value + "]"); - }); - System.out.println(); - } - - System.out.println("小结:"); - for (Map.Entry entry : ip_wit_multi.entrySet()) { - int sendTime = entry.getValue(); - String sec = ipSec.get(entry.getKey()); - int np = count.get(sec).size(); - System.out.printf("[%s服有%3d人多发了%3d封邮件]\n", sec, np, sendTime - 1); - } - System.out.println("全服有" + totalNum + "人多发了邮件"); - } - - /** - * @param rids 类似"online#16724351_80350","online#15122552_80349","online#1002056_80349" - * @param sec 类似80350 - * @return online#16724351_80350 - */ - public static Map findRids(String rids, String sec) { - Map re = Maps.newHashMap(); - String[] ridArray = StringUtils.split(rids, ','); - for (int i = 0; i < 300; i++) { - String s = ridArray[i]; - String rid = s.substring(1, s.length() - 1); - String player_code = StringUtils.split(rid, "#")[1]; - String player_sec = player_code.split("_")[1]; - if (sec.equals(player_sec)) { - re.put(i + 1, rid); - } - } - return re; - } - - public static String getRids(String group, String fileName) { - String re = null; - try { - try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(fileName), "UTF-8"))) { - String s; - while ((s = br.readLine()) != null) {//使用readLine方法,一次读一行 - String[] strings = StringUtils.split(s, ":"); - if (strings.length == 2 && strings[0].contains(group)) { - re = strings[1].substring(1, strings[1].length() - 1); - break; - } - } - } - } catch (Exception e) { - e.printStackTrace(); - } - return re; - } - - @Test - public void test1() { - System.out.println(Long.MAX_VALUE); - } -} diff --git a/src/main/java/javabase/map/stream/StreamTest.java b/src/main/java/javabase/map/stream/StreamTest.java deleted file mode 100644 index 4ed25af..0000000 --- a/src/main/java/javabase/map/stream/StreamTest.java +++ /dev/null @@ -1,213 +0,0 @@ -package javabase.map.stream; - -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; -import com.taobao.api.internal.util.StringUtils; -import org.junit.Test; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.TreeMap; -import java.util.stream.Collectors; -import java.util.stream.IntStream; - -import static java.util.Comparator.comparing; - -/** - * @author playcrab_chenyuqun - */ -public class StreamTest { - - private static Map map1 = new HashMap<>(); - private static Map map2 = new HashMap<>(); - - private static String apply(Integer ele) { - return String.valueOf(ele); - } - - @Test - public void testAllMatch() { - Map map = Maps.newHashMap(); - Boolean re = map.values().stream().allMatch(value -> value == 0); - System.out.println(re); - } - - @Test - public void testMapToInt() { - Map items = Maps.newHashMap(); - items.put("item1", 1); - items.put("item2", 2); - items.put("item3", 3); - int sum = items.values().stream().mapToInt(StreamTest::returnInteger).sum(); - System.out.println("sum: " + sum); - } - - @Test - public void testMap() { - Map map = Maps.newHashMap(); - map.put("1", 1); - map.put("2", 2); - map.put("3", 5); - map.put("4", 4); - map.put("5", 3); - List list = map.values().stream().collect(Collectors.toList()); - list.forEach(element -> System.out.println(element)); - } - - @Test - public void testForEach() { - List rewards = Lists.newArrayList(); - rewards.add("1"); - rewards.add("2"); - rewards.add("3"); - rewards.add("5"); - - List newRewards = Lists.newArrayList(); - rewards.forEach(reward -> newRewards.add(reward)); - newRewards.forEach(reward -> System.out.println(reward)); - } - - public static Integer returnInteger(int a) { - return new Integer(a + 1); - } - - @Test - public void testMax() { - Map map = Maps.newHashMap(); - /*Apple apple1 = new Apple("apple1",1); - Apple apple2 = new Apple("apple2",2); - Apple apple3 = new Apple("apple3",3); - Apple apple4 = new Apple("apple4",4); - Apple apple5 = new Apple("apple5",5); - map.put("1", apple1); - map.put("2", apple2); - map.put("3", apple3); - map.put("4", apple4); - map.put("5", apple5);*/ - Apple apple = map.values().stream().max(comparing(Apple::getWeight)).orElse(null); - System.out.println(apple); - } - - @Test - public void testConcat() { - - Map map1 = ImmutableMap.of("One", 1, "Two", 2); - Map map2 = ImmutableMap.of("Three", 3); - - Map expected = ImmutableMap.of("One", 1, "Two", 2, "Three", 3); - Map result = new HashMap<>(); - - map1.merge("One", 3, (oldValue, newValue) -> oldValue + newValue); - result.forEach((k, v) -> System.out.println("key:" + k + " value:" + v)); - } - - @Test - public void testMerge() { - String k = "key"; - HashMap map = new HashMap<>(); - map.merge(k, 2, Integer::sum); - map.forEach((key, v) -> System.out.println("key:" + key + " value:" + v)); - } - - @Test - public void testFilter() { - Map map = Maps.newHashMap(); - map.put("1", 1); - map.put("2", 2); - map.put("3", 3); - List list = map.values().stream().filter(key -> key == 3 || key == 2).collect(Collectors.toList()); - for (Integer integer : list) { - System.out.println(integer); - } - - Integer re = map.values().stream().max(comparing(value -> value)).orElse(null); - System.out.println(re); - } - - /** - * - */ - @Test - public void testPrint() { - System.out.println("hello"); - } - - /** - * - */ - @Test - public void testSendRewardMail() { - TreeMap treeMap = Maps.newTreeMap(); - treeMap.put(1, "1"); - treeMap.put(3, "3"); - treeMap.put(2, "2"); - treeMap.put(4, "4"); - treeMap.put(8, "8"); - treeMap.put(9, "9"); - treeMap.put(10, "10"); - treeMap.put(11, "11"); - treeMap.put(5, "5"); - treeMap.put(6, "6"); - treeMap.put(7, "7"); - - String rewardId = null; - Integer start = null; - int size = 100; - int lastKey = treeMap.lastKey(); - for (Map.Entry entry : treeMap.entrySet()) { - // 遍历第一个entry,初始化rewardId和start. - if (rewardId == null) { - start = entry.getKey(); - rewardId = entry.getValue(); - continue; - } - - sendRewardMail(start, entry.getKey(), rewardId); - start = entry.getKey(); - rewardId = entry.getValue(); - - // 遍历最后一个,如果entry的value不为空,排名从key到最后一名都发奖励。 - if (start == lastKey && !StringUtils.isEmpty(rewardId)) { - sendRewardMail(start, size, rewardId); - } - } - } - - public void sendRewardMail(int begin, int end, String value) { - System.out.println("begin: " + begin + ", end: " + end + ", value: " + value); - } - - @Test - public void testForEach1() { - Map map = Maps.newHashMap(); - map.put("1", 1); - map.put("2", 2); - map.entrySet().forEach(entry -> entry.setValue(0)); - map.forEach((key, value) -> System.out.println(key + value)); - } - - @Test - public void test1() { - for(int i = 0; i < getList().size(); i++) { - System.out.println(i); - } - } - - public List getList() { - List list = Lists.newArrayList(); - list.add("1"); - list.add("2"); - System.out.println("get List"); - return list; - } - - @Test - public void testStreamRange() { - List ret = IntStream.range(0,10).boxed().map(String::valueOf).collect(Collectors.toList()); - for (int i = 0; i < ret.size(); i++) { - System.out.println(ret.get(i)); - } - } -} diff --git a/src/main/java/javabase/stringTest/StringTest.java b/src/main/java/javabase/stringTest/StringTest.java index 4145d58..a12c1dd 100644 --- a/src/main/java/javabase/stringTest/StringTest.java +++ b/src/main/java/javabase/stringTest/StringTest.java @@ -1,7 +1,6 @@ package javabase.stringTest; import com.google.common.base.Strings; -import com.sun.deploy.util.StringUtils; import org.junit.Test; import java.time.Instant;