提交 2b887783 编写于 作者: C chenjianqiang

init

Signed-off-by: Nchenjianqiang <wushanxi@gmail.com>
上级 286ebb86
<html>Simple <b>Java</b> application that includes a class with <code>main()</code> method</html>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="PROJECT" charset="UTF-8" />
</component>
</project>
\ No newline at end of file
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="JavaDoc" enabled="true" level="WARNING" enabled_by_default="true">
<option name="TOP_LEVEL_CLASS_OPTIONS">
<value>
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
<option name="REQUIRED_TAGS" value="" />
</value>
</option>
<option name="INNER_CLASS_OPTIONS">
<value>
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
<option name="REQUIRED_TAGS" value="" />
</value>
</option>
<option name="METHOD_OPTIONS">
<value>
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
<option name="REQUIRED_TAGS" value="@return@param@throws or @exception" />
</value>
</option>
<option name="FIELD_OPTIONS">
<value>
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
<option name="REQUIRED_TAGS" value="" />
</value>
</option>
<option name="IGNORE_DEPRECATED" value="false" />
<option name="IGNORE_JAVADOC_PERIOD" value="true" />
<option name="IGNORE_DUPLICATED_THROWS" value="false" />
<option name="IGNORE_POINT_TO_ITSELF" value="false" />
<option name="myAdditionalJavadocTags" value="date" />
</inspection_tool>
</profile>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="EntryPointsManager">
<entry_points version="2.0" />
</component>
<component name="ProjectKey">
<option name="state" value="project://e2804f05-5315-4fc6-a121-c522a6c26470" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/patterns.iml" filepath="$PROJECT_DIR$/patterns.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<template>
<input-field default="com.company">IJ_BASE_PACKAGE</input-field>
</template>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="e43e9168-5945-4f45-b4c2-1b6410d1eef8" name="Changes" comment="" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
<option value="package-info" />
<option value="Class" />
</list>
</option>
</component>
<component name="ProjectId" id="1zOe73GcNcKVHdZbMKVNmxcnwqc" />
<component name="ProjectView">
<navigator currentView="ProjectPane" proportions="" version="1" splitterProportion="0.5">
<flattenPackages />
<showMembers />
<showModules />
<showLibraryContents />
<hideEmptyPackages />
<abbreviatePackageNames />
<autoscrollToSource />
<autoscrollFromSource />
<sortByType />
</navigator>
<panes>
<pane id="Scope" />
<pane id="PackagesPane" />
<pane id="ProjectPane">
<subPane>
<PATH>
<PATH_ELEMENT>
<option name="myItemId" value="untitled104" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.ProjectViewProjectNode" />
</PATH_ELEMENT>
</PATH>
<PATH>
<PATH_ELEMENT>
<option name="myItemId" value="untitled104" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.ProjectViewProjectNode" />
</PATH_ELEMENT>
<PATH_ELEMENT>
<option name="myItemId" value="untitled104" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
</PATH_ELEMENT>
</PATH>
<PATH>
<PATH_ELEMENT>
<option name="myItemId" value="untitled104" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.ProjectViewProjectNode" />
</PATH_ELEMENT>
<PATH_ELEMENT>
<option name="myItemId" value="untitled104" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
</PATH_ELEMENT>
<PATH_ELEMENT>
<option name="myItemId" value="src" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
</PATH_ELEMENT>
<PATH_ELEMENT>
<option name="myItemId" value="company" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
</PATH_ELEMENT>
</PATH>
</subPane>
</pane>
</panes>
</component>
<component name="ProjectViewState">
<option name="autoscrollFromSource" value="true" />
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent">
<property name="WebServerToolWindowFactoryState" value="false" />
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
<property name="vue.rearranger.settings.migration" value="true" />
</component>
<component name="RecentsManager">
<key name="CopyClassDialog.RECENTS_KEY">
<recent name="com.company.InterpreterPattern" />
</key>
</component>
<component name="RunManager">
<configuration name="Main" type="Application" factoryName="Application" temporary="true">
<option name="MAIN_CLASS_NAME" value="com.chen.Main" />
<module name="patterns" />
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$" />
<RunnerSettings RunnerId="Run" />
<ConfigurationWrapper RunnerId="Run" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<recent_temporary>
<list>
<item itemvalue="Application.Main" />
</list>
</recent_temporary>
</component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="e43e9168-5945-4f45-b4c2-1b6410d1eef8" name="Changes" comment="" />
<created>1634023392076</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1634023392076</updated>
<workItem from="1634023393246" duration="1045000" />
<workItem from="1634026286938" duration="1220000" />
<workItem from="1634085227295" duration="1967000" />
<workItem from="1634087918450" duration="3646000" />
<workItem from="1634091679401" duration="1323000" />
</task>
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="3" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
package com.chen.InterpreterPattern;
import com.chen.InterpreterPattern.po.AndExpression;
import com.chen.InterpreterPattern.po.Expression;
import com.chen.InterpreterPattern.po.OrExpression;
import com.chen.InterpreterPattern.po.TerminalExpression;
/**
* 解释器模式触发器
*
* @author lx
* @date 2021/10/13 9:23
**/
public class InterpreterMain {
String[] cityAndFree = new String[]{"杭州", "攀枝花"};
String[] cardAndFree = new String[]{"市民卡", "社保卡"};
String[] workAndFree = new String[]{"税务够年", "已退休"};
String[] allOrFree = new String[]{"孕妇", "退伍军人", "儿童"};
String freeNotice = "滴,免费卡!";
String spendNotice = "滴,扣费一万元!余额不足,请下去!";
String[] customers = new String[]{"已退休的杭州的市民卡", "税务够年的上海的市民卡", "杭州的社保卡的已退休", "成都的退伍军人", "北京的市民卡"};
Expression e;
TerminalExpression allOrFreeT;
TerminalExpression cityAndFreeT;
TerminalExpression cardAndFreeT;
TerminalExpression workAndFreeT;
public void main() {
allOrFreeT = new TerminalExpression(allOrFree);
cityAndFreeT = new TerminalExpression(cityAndFree);
cardAndFreeT = new TerminalExpression(cardAndFree);
workAndFreeT = new TerminalExpression(workAndFree);
for (String customer : customers) {
System.out.println("欢迎“".concat(customer).concat("”乘车,正在检查你的卡:"));
System.out.println(">>>>>>>>>>>>>>>>>>>>>>>".concat(exec(customer)));
}
}
private String exec(String customer) {
e = new OrExpression(allOrFreeT, new AndExpression(cityAndFreeT, new AndExpression(cardAndFreeT, workAndFreeT)));
return !e.interpret(customer) ? spendNotice : freeNotice;
}
}
/**
* 解释器模式
*/
package com.chen.InterpreterPattern;
package com.chen.InterpreterPattern.po;
/**
* 与
* @author lx
* @date 2021/10/13 9:33
**/
public class AndExpression implements Expression{
private final Expression e1;
private final Expression e2;
public AndExpression(Expression e1, Expression e2) {
this.e1 = e1;
this.e2 = e2;
}
/**
* 解释
*
* @param context 正文
* @return true、false
*/
@Override
public boolean interpret(String context) {
return e1.interpret(context) && e2.interpret(context);
}
}
package com.chen.InterpreterPattern.po;
/**
* 表达
*
* @author lx
* @date 2021/10/13 9:20
**/
public interface Expression {
/**
* 解释
*
* @param context 正文
* @return true、false
*/
boolean interpret(String context);
}
package com.chen.InterpreterPattern.po;
/**
* 或
* @author lx
* @date 2021/10/13 9:33
**/
public class OrExpression implements Expression{
private final Expression e1;
private final Expression e2;
public OrExpression(Expression e1, Expression e2) {
this.e1 = e1;
this.e2 = e2;
}
/**
* 解释
*
* @param context 正文
* @return true、false
*/
@Override
public boolean interpret(String context) {
return e1.interpret(context) || e2.interpret(context);
}
}
package com.chen.InterpreterPattern.po;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
/**
* 终端计算
*
* @author lx
* @date 2021/10/13 9:33
**/
public class TerminalExpression implements Expression {
private final Set<String> data;
public TerminalExpression(String[] data) {
this.data = new HashSet<>(Arrays.asList(data));
}
/**
* 解释
*
* @param context 被验证元素
* @return true、false
*/
@Override
public boolean interpret(String context) {
System.out.println(data);
String splitFux = "的";
if(!context.contains(splitFux)){
return data.contains(context);
}
String[] contexts = context.split(splitFux);
boolean result = false;
for (String s : contexts) {
if (data.contains(s)) {
result = true;
}
}
System.out.println("结果:" + result);
return result;
}
}
package com.chen;
import com.chen.InterpreterPattern.InterpreterMain;
/**
* @author lx
*/
public class PatternMain {
public static void main(String[] args) {
//解释器模式
new InterpreterMain().main();
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册