Browse Source

demo

pull/1/head
马府强 2 years ago
parent
commit
fc727ea8e9
  1. 8
      demodump/.idea/.gitignore
  2. 14
      demodump/.idea/compiler.xml
  3. 20
      demodump/.idea/jarRepositories.xml
  4. 14
      demodump/.idea/misc.xml
  5. 8
      demodump/.idea/setting.xml
  6. 124
      demodump/.idea/uiDesigner.xml
  7. 2
      demodump/demodump.iml
  8. 29
      demodump/pom.xml
  9. 19
      demodump/src/main/java/org/example/function/BranchHandle.java
  10. 25
      demodump/src/main/java/org/example/function/PresentOrElseHandler.java
  11. 17
      demodump/src/main/java/org/example/function/ThrowExceptionFunction.java
  12. 63
      demodump/src/main/java/org/example/function/VUtils.java
  13. 19
      demodump/src/main/java/org/example/strategy/Eclipse.java
  14. 17
      demodump/src/main/java/org/example/strategy/IDEA.java
  15. 16
      demodump/src/main/java/org/example/strategy/Program.java
  16. 57
      demodump/src/main/java/org/example/strategy/Programmer.java
  17. 53
      demodump/src/test/java/org/example/Test.java
  18. BIN
      demodump/target/classes/org/example/function/BranchHandle.class
  19. BIN
      demodump/target/classes/org/example/function/PresentOrElseHandler.class
  20. BIN
      demodump/target/classes/org/example/function/ThrowExceptionFunction.class
  21. BIN
      demodump/target/classes/org/example/function/VUtils.class
  22. BIN
      demodump/target/classes/org/example/strategy/Eclipse.class
  23. BIN
      demodump/target/classes/org/example/strategy/IDEA.class
  24. BIN
      demodump/target/classes/org/example/strategy/Program.class
  25. BIN
      demodump/target/classes/org/example/strategy/Programmer.class
  26. BIN
      demodump/target/test-classes/org/example/Test.class

8
demodump/.idea/.gitignore

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Datasource local storage ignored files
/../../../:\demodump\.idea/dataSources/
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/

14
demodump/.idea/compiler.xml

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile name="Maven default annotation processors profile" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="demodump" />
</profile>
</annotationProcessing>
<bytecodeTargetLevel target="8" />
</component>
</project>

20
demodump/.idea/jarRepositories.xml

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Central Repository" />
<option name="url" value="https://repo.maven.apache.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="jboss.community" />
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
</component>
</project>

14
demodump/.idea/misc.xml

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

8
demodump/.idea/setting.xml

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="arthas.idea.plugin">
<option name="redisAddress" value="" />
<option name="redisAuth" value="" />
<option name="redisCacheKey" value="" />
</component>
</project>

124
demodump/.idea/uiDesigner.xml

@ -0,0 +1,124 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>

2
demodump/demodump.iml

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4" />

29
demodump/pom.xml

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>demodump</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-context -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.3.23</version>
</dependency>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

19
demodump/src/main/java/org/example/function/BranchHandle.java

@ -0,0 +1,19 @@
package org.example.function;
/**
* @className: BranchHandle
* @author: xiaomage
* @date: 2022/12/17
**/
public interface BranchHandle {
/**
* 分支操作
*
* @param trueHandle 为true时要进行的操作
* @param falseHandle 为false时要进行的操作
* @return void
**/
void trueOrFalseHandle(Runnable trueHandle, Runnable falseHandle);
}

25
demodump/src/main/java/org/example/function/PresentOrElseHandler.java

@ -0,0 +1,25 @@
package org.example.function;
/**
* @className: PresentOrElseHandler
* @author: xiaomage
* @date: 2022/12/17
**/
import java.util.function.Consumer;
/**
* 空值与非空值分支处理
*/
public interface PresentOrElseHandler<T extends Object> {
/**
* 值不为空时执行消费操作
* 值为空时执行其他的操作
*
* @param action 值不为空时执行的消费操作
* @param emptyAction 值为空时执行的操作
**/
void presentOrElseHandle(Consumer<? super T> action, Runnable emptyAction);
}

17
demodump/src/main/java/org/example/function/ThrowExceptionFunction.java

@ -0,0 +1,17 @@
package org.example.function;
/**
* @className: ThrowExceptionFunction
* @author: xiaomage
* @date: 2022/12/17
**/
public interface ThrowExceptionFunction {
/**
* 抛出异常信息
*
* @param message 异常信息
* @return void
**/
void throwMessage(String message);
}

63
demodump/src/main/java/org/example/function/VUtils.java

@ -0,0 +1,63 @@
package org.example.function;
/**
* vutils
*
* @author Admin
* @date 2022/12/17
*/
public class VUtils {
/**
* 如果参数为true抛出异常
*
* @param b
* @return com.example.demo.func.ThrowExceptionFunction
**/
public static ThrowExceptionFunction isTure(boolean b) {
return (errorMessage) -> {
if (b) {
throw new RuntimeException(errorMessage);
}
};
}
/**
* 参数为true或false时分别进行不同的操作
*
* @param b
* @return com.example.demo.func.BranchHandle
**/
public static BranchHandle isTureOrFalse(boolean b){
return (trueHandle, falseHandle) -> {
if (b){
trueHandle.run();
} else {
falseHandle.run();
}
};
}
/**
* 参数为true或false时分别进行不同的操作
*
* @param b
* @return com.example.demo.func.BranchHandle
**/
public static PresentOrElseHandler<?> isBlankOrNoBlank(String str){
return (consumer, runnable) -> {
if (str == null || str.length() == 0){
runnable.run();
} else {
consumer.accept(str);
}
};
}
}

19
demodump/src/main/java/org/example/strategy/Eclipse.java

@ -0,0 +1,19 @@
package org.example.strategy;
/**
* Eclipse
*
* @author xiaomage
* @date 2022/12/18
*/
public class Eclipse implements Program {
/**
* 编码
*/
@Override
public void coding() {
System.out.println("用Eclipse 进行编码");
}
}

17
demodump/src/main/java/org/example/strategy/IDEA.java

@ -0,0 +1,17 @@
package org.example.strategy;
/**
* IDEA
*
* @author xiaomage
* @date 2022/12/18
*/
public class IDEA implements Program {
@Override
public void coding() {
System.out.println("用IDEA 编码");
}
}

16
demodump/src/main/java/org/example/strategy/Program.java

@ -0,0 +1,16 @@
package org.example.strategy;
/**
* 编程
*
* @author xiaomage
* @date 2022/12/18
*/
public interface Program {
/**
* 编码
*/
void coding();
}

57
demodump/src/main/java/org/example/strategy/Programmer.java

@ -0,0 +1,57 @@
package org.example.strategy;
import java.util.Objects;
/**
* 程序员
* 分享用策略模式去消除代码中的if else
* @author xiaomage
* @date 2022/12/18
*/
public class Programmer {
private Program program;
public Programmer(Program program) {
this.program = program;
}
public Program getProgram() {
return program;
}
public void setProgram(Program program) {
this.program = program;
}
// /**
// * 编码
// *
// * @param codeType 类型
// */
// public void coding(String codeType) {
// if (Objects.equals("IDEA",codeType)) {
// System.out.println("用IDEA编码");
// }else if(Objects.equals("Eclipse",codeType)){
// System.out.println("用Eclipse编码");
// }
//// ......
// }
/**
* 用策略模式编码
*/
public void codingStrategy( ) {
program.coding();
}
public static void main(String[] args) {
Programmer programmerI = new Programmer(new IDEA());
programmerI.codingStrategy();
Programmer programmerE = new Programmer(new Eclipse());
programmerE.codingStrategy();
}
}

53
demodump/src/test/java/org/example/Test.java

@ -0,0 +1,53 @@
package org.example;
import org.example.function.VUtils;
/**
* 用Java 8中的 Function接口消灭代码中if...else
*
* Supplier供给型函数
* Consumer消费型函数
* Runnable无参无返回型函数
* Function函数的表现形式为接收一个参数并返回一个值
* SupplierConsumer和Runnable可以看作Function的一种特殊表现形式
*
* 处理抛出异常的if
* 处理if分支操作
* 如果存在值执行消费操作否则执行基于空的操作
*/
public class Test {
public static void main(String[] args) {
// if (...){
// throw new RuntimeException("出现异常了");
// }
//
// if (...){
// doSomething();
// } else {
// doOther();
// }
// VUtils.isTure(true).throwMessage("hahaha");
// VUtils.isTureOrFalse(false)
// .trueOrFalseHandle(
// () -> {
// System.out.println("我是true ,现在我要这样做");
// },
// () -> {
// System.out.println("我是false ,天下无敌");
// }
// );
VUtils.isBlankOrNoBlank("hello")
.presentOrElseHandle(System.out::println,
() -> {
System.out.println("空字符串");
});
}
}

BIN
demodump/target/classes/org/example/function/BranchHandle.class

Binary file not shown.

BIN
demodump/target/classes/org/example/function/PresentOrElseHandler.class

Binary file not shown.

BIN
demodump/target/classes/org/example/function/ThrowExceptionFunction.class

Binary file not shown.

BIN
demodump/target/classes/org/example/function/VUtils.class

Binary file not shown.

BIN
demodump/target/classes/org/example/strategy/Eclipse.class

Binary file not shown.

BIN
demodump/target/classes/org/example/strategy/IDEA.class

Binary file not shown.

BIN
demodump/target/classes/org/example/strategy/Program.class

Binary file not shown.

BIN
demodump/target/classes/org/example/strategy/Programmer.class

Binary file not shown.

BIN
demodump/target/test-classes/org/example/Test.class

Binary file not shown.
Loading…
Cancel
Save