-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
1,149 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# InfectStatistic-221701223 | ||
疫情统计 | ||
|
||
### 项目概述 | ||
|
||
1.读取指定路径下所有格式为yyyy-MM-dd.log.txt的日志文件,统计日志文件的信息并输出到指定的文件 | ||
|
||
2.支持处理命令行参数. | ||
|
||
``` | ||
日志文件可能出现的几种情况 | ||
1、<省> 新增 感染患者 n人 | ||
2、<省> 新增 疑似患者 n人 | ||
3、<省1> 感染患者 流入 <省2> n人 | ||
4、<省1> 疑似患者 流入 <省2> n人 | ||
5、<省> 死亡 n人 | ||
6、<省> 治愈 n人 | ||
7、<省> 疑似患者 确诊感染 n人 | ||
8、<省> 排除 疑似患者 n人 | ||
PS:日志中各种情况的出现顺序不定,省出现的顺序不定,出现哪些省不定,省出现几次不定。 | ||
``` | ||
|
||
``` | ||
输出文件样例 | ||
全国 感染患者22人 疑似患者25人 治愈10人 死亡2人 | ||
福建 感染患者2人 疑似患者5人 治愈0人 死亡0人 | ||
浙江 感染患者3人 疑似患者5人 治愈2人 死亡1人 | ||
// 该文档并非真实数据,仅供测试使用 | ||
PS : 每一行记录的输出顺序规则如下 | ||
1.先输出全国,其他省份按汉字拼音排序,且只输出日志文件中出现过的省份 | ||
2.如果命令行指定了-province,则应该输出所有指定的项没有指定就不必输出,顺序同规则1 | ||
``` | ||
### 如何运行 | ||
|
||
1.源文件在/src目录下,通过javac命令编译。Windows下在编译时还要加上-encoding utf-8来避免编码问题。 | ||
|
||
2.通过IDEA导入项目,点击Run->Edit Configurations,在Program arguments栏中正确输入下面列出的参数的组合,然后编译运行。 | ||
|
||
### 功能简介 | ||
list命令支持以下命令行参数 : | ||
|
||
- ```-log```指定日志文件目录的位置,该项**必会附带**。 | ||
- ```-out```指定输出文件的路径和文件名,该项**必会附带**。 | ||
- ```-date```指定日期,可选 (日期格式必须为yyyy-MM-dd)。 | ||
- ```-type```指定患者类型,可选,会按指定的顺序输出,默认输出全部。(使用缩写,ip:感染患者, sp:疑似患者, cure:治愈, dead:死亡)。 | ||
- ```-province```指定列出的省,可选,会按拼音顺序输出指定的省。 | ||
|
||
作业链接:https://edu.cnblogs.com/campus/fzu/2020SpringW/homework/10281 | ||
|
||
博客链接:https://www.cnblogs.com/ybn-juan/p/12319108.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
## 代码风格 | ||
参考自 [阿里巴巴JAVA开发手册](https://github.com/chjw8016/alibaba-java-style-guide) | ||
|
||
- 缩进 | ||
* 缩进采用4个空格,禁止使用tab字符。 | ||
* 如果使用tab键来缩进,在IDEA中要取消勾选Use tab character。 | ||
- 变量命名 | ||
* 成员变量、局部变量都统一使用lowerCamelCase风格,必须遵从驼峰形式。 | ||
* 代码中的命名严禁使用拼音与英文混合的方式,更不允许直接使用中文的方式。 | ||
- 每行最多字符数 | ||
|
||
每行最多120个字符,超出需要换行,换行规则如下: | ||
* 第二行相对第一行缩进 4个空格,从第三行开始,不再继续缩进,参考示例。 | ||
* 运算符与下文一起换行。 | ||
* 方法调用的点符号与下文一起换行。 | ||
* 在多个参数超长,逗号后进行换行。 | ||
* 在括号前不要换行,见反例。 | ||
> 正例: | ||
``` | ||
StringBuffer sb = new StringBuffer(); | ||
//超过120个字符的情况下,换行缩进4个空格,并且方法前的点符号一起换行 | ||
sb.append("zi").append("xin")... | ||
.append("huang")... | ||
.append("huang")... | ||
.append("huang"); | ||
``` | ||
> 反例: | ||
``` | ||
StringBuffer sb = new StringBuffer(); | ||
//超过120个字符的情况下,不要在括号前换行 | ||
sb.append("zi").append("xin")...append | ||
("huang"); | ||
//参数很多的方法调用可能超过120个字符,不要在逗号前换行 | ||
method(args1, args2, args3, ... | ||
, argsX); | ||
``` | ||
|
||
- 函数、类命名 | ||
* 函数和类命名的文本使用要求与变量的命名要求一致。 | ||
* 类名使用UpperCamelCase风格,必须遵从驼峰形式,但以下情形例外:(领域模型的相关命名)DO / BO / DTO / VO等。 | ||
* 方法名、参数名都统一使用lowerCamelCase风格,必须遵从驼峰形式。 | ||
* 抽象类命名使用Abstract或Base开头;异常类命名使用Exception结尾;测试类命名以它要测试的类的名称开始,以Test结尾。 | ||
* 类名如果有复数含义,可以使用复数形式。 | ||
* 杜绝完全不规范的缩写,避免望文不知义。 | ||
* 接口类中的方法和属性不要加任何修饰符号(public也不要加),保持代码的简洁性,并加上有效的Javadoc注释。尽量不要在接口里定义变量,如果一定要定义变量,肯定是与接口方法相关,并且是整个应用的基础常量。 | ||
* 枚举类名建议带上Enum后缀,枚举成员名称需要全大写,单词间用下划线隔开。 | ||
- 常量 | ||
* 常量命名全部大写,单词间用下划线隔开,力求语义表达完整清楚,不要嫌名字长。 | ||
* 常量名前要用static final修饰。 | ||
- 空行规则 | ||
* 方法体内的执行语句组、变量的定义语句组、不同的业务逻辑之间或者不同的语义之间插入一个空行。相同业务逻辑和语义之间不需要插入空行。但没有必要插入多个空行进行分隔。 | ||
* 类与类、类的方法与方法、变量与方法之间插入一个空行,类名与第一个方法名、最后一个方法与类的大括号间不空行。 | ||
* 换行符统一为LF(Unix/macOS)风格,即"\n"。 | ||
- 注释规则 | ||
|
||
1.类、类属性、类方法的注释必须使用Javadoc规范,使用/**内容*/格式,不得使用//xxx方式。 | ||
> 说明:在IDE编辑窗口中,Javadoc方式会提示相关注释,生成Javadoc可以正确输出相应注释;在IDE中,工程调用方法时,不进入方法即可悬浮提示方法、参数、返回值的意义,提高阅读效率。 | ||
2.所有的抽象方法(包括接口中的方法)必须要用Javadoc注释、除了返回值、参数、异常说明外,还必须指出该方法做什么事情,实现什么功能。 | ||
|
||
> 说明:对子类的实现要求,或者调用注意事项,请一并说明。 | ||
3.所有的类都必须添加创建者信息。 | ||
|
||
4.方法内部单行注释,在被注释语句上方另起一行,使用//注释。方法内部多行注释使用/* */注释,注意与代码对齐。 | ||
|
||
5.所有的枚举类型字段必须要有注释,说明每个数据项的用途。 | ||
|
||
- 操作符前后空格 | ||
* 方法参数在定义和传入时,多个参数逗号后边必须加空格。 | ||
* 任何运算符左右必须加一个空格。 | ||
* if/for/while/switch/do等保留字与左右括号之间都必须加空格。 | ||
* 左括号和后一个字符之间不出现空格;同样,右括号和前一个字符之间也不出现空格。 | ||
- 大括号使用规则 | ||
|
||
如果是大括号内为空,则简洁地写成{}即可,不需要换行;如果是非空代码块则: | ||
* 左大括号前不换行。 | ||
* 左大括号后换行。 | ||
* 右大括号前换行。 | ||
* 右大括号后还有else等代码则不换行;表示终止右大括号后必须换行。 | ||
> 使用匿名内部类的时候,两个左大括号都不换行,两个右大括号都换行。如: | ||
``` | ||
ArrayList<String> list = new ArrayList<>(4) {{ | ||
add(Lib.INFECTED); | ||
add(Lib.SUSPECTED); | ||
add(Lib.CURED); | ||
add(Lib.DEAD); | ||
}}; | ||
``` | ||
- 其他规则 | ||
|
||
一般情况下,IDEA的代码格式化就已经能满足大部分对格式的控制要求。对于一些代码块/业务逻辑之间的空行,则需要自己把握。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/** | ||
* InfectStatistic | ||
* | ||
* @author ybn | ||
*/ | ||
public class InfectStatistic { | ||
/** | ||
* Main | ||
* 程序主入口 | ||
* | ||
* @param args args | ||
*/ | ||
public static void main(String[] args) { | ||
try { | ||
ArgumentContainer argumentContainer = ArgumentHandler.getArgumentContainer(args); | ||
RecordContainer recordContainer = new RecordContainer(argumentContainer) {{ | ||
init(); | ||
}}; | ||
FileTools fileTools = new FileTools(argumentContainer); | ||
fileTools.readFile(recordContainer); | ||
fileTools.createOutputFile(recordContainer.newOutputDataSet()); | ||
} catch (ArgumentException ae) { | ||
ae.printStackTrace(); | ||
} | ||
} | ||
|
||
/** | ||
* Test main | ||
*/ | ||
// @Test | ||
// public void testMain() { | ||
// ArrayList<String[]> argList = new ArrayList<>() {{ | ||
// //指定日期 | ||
// add(new String[]{"list", "-date", "2020-01-27", "-log", "/Users/ybn/IdeaProjects/InfectStatistic-main" + | ||
// "/221701223/log/", "-out", "/Users/ybn/Downloads/out1.txt"}); | ||
// //指定省份 | ||
// add(new String[]{"list", "-log", "/Users/ybn/IdeaProjects/InfectStatistic-main/221701223/log/", "-province", | ||
// "福建", "湖北", "江西", "-out", "/Users/ybn/Downloads/out2.txt"}); | ||
// //指定类型 | ||
// add(new String[]{"list", "-log", "/Users/ybn/IdeaProjects/InfectStatistic-main/221701223/log/", "-type", | ||
// "ip", "dead", "-out", "/Users/ybn/Downloads/out3.txt"}); | ||
// //指定省份和类型 | ||
// add(new String[]{"list", "-log", "/Users/ybn/IdeaProjects/InfectStatistic-main/221701223/log/", "-type", | ||
// "ip", "dead", "-province", "湖北", "-out", "/Users/ybn/Downloads/out4.txt"}); | ||
// //指定日期、省份和类型 | ||
// add(new String[]{"list", "-log", "/Users/ybn/IdeaProjects/InfectStatistic-main/221701223/log/", "-date", | ||
// "2020-01-27", "-province", "福建", "-type", "sp", "-out", "/Users/ybn/Downloads/out5.txt"}); | ||
// //缺少list | ||
// add(new String[]{"-log", "~/IdeaProjects/InfectStatistic-main/221701223/log/", "out", | ||
// "/Users/ybn/Downloads/out6.txt"}); | ||
// //日期超出范围 | ||
// add(new String[]{"list", "-log", "/Users/ybn/IdeaProjects/InfectStatistic-main/221701223/log/", "-date", | ||
// "2020-01-28", "-out", "/Users/ybn/Downloads/out7.txt"}); | ||
// //带-type却未指定type | ||
// add(new String[]{"list", "-log", "/Users/ybn/IdeaProjects/InfectStatistic-main/221701223/log/", "-type", | ||
// "-out", "/Users/ybn/Downloads/out8.txt"}); | ||
// //带-province却未指定province | ||
// add(new String[]{"list", "-log", "/Users/ybn/IdeaProjects/InfectStatistic-main/221701223/log/", | ||
// "-province", "-out", "/Users/ybn/Downloads/out8.txt"}); | ||
// //log文件格式有误 | ||
// add(new String[]{"list", "-log", "/Users/ybn/Downloads/log/", "-out", "/Users/ybn/Downloads/out9.txt"}); | ||
// //缺少-log | ||
// add(new String[]{"list", "-province", "福建", "湖北", "江西", "-out", "/Users/ybn/Downloads/out2.txt"}); | ||
// //缺少-out | ||
// add(new String[]{"list", "-log", "/Users/ybn/IdeaProjects/InfectStatistic-main/221701223/log/", "-province", | ||
// "福建", "湖北"}); | ||
// }}; | ||
// for (String[] args : argList) { | ||
// InfectStatistic.main(args); | ||
// } | ||
// } | ||
} |
Oops, something went wrong.