From b5fc39183de4e35dfdc81c22f75f7dfcc1da2a1a Mon Sep 17 00:00:00 2001 From: bingor Date: Mon, 17 Oct 2022 10:11:59 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9D=A6=E5=85=8B=E5=A4=A7=E6=88=98=EF=BC=88?= =?UTF-8?q?=E4=B8=80=E6=9C=9F=EF=BC=89-=E8=AE=BE=E8=AE=A1=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F-=E9=9D=99=E6=80=81=E4=BB=A3=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/msb/proxy/v5/Movable.java | 11 +++++++ src/main/java/com/msb/proxy/v5/ProxyTank.java | 30 ++++++++++++++++++ src/main/java/com/msb/proxy/v5/Tank.java | 27 ++++++++++++++++ src/main/java/com/msb/proxy/v6/Main.java | 19 ++++++++++++ src/main/java/com/msb/proxy/v6/Movable.java | 11 +++++++ src/main/java/com/msb/proxy/v6/Tank.java | 27 ++++++++++++++++ .../java/com/msb/proxy/v6/TankLogProxy.java | 30 ++++++++++++++++++ .../java/com/msb/proxy/v6/TankTimeProxy.java | 31 +++++++++++++++++++ 8 files changed, 186 insertions(+) create mode 100644 src/main/java/com/msb/proxy/v5/Movable.java create mode 100644 src/main/java/com/msb/proxy/v5/ProxyTank.java create mode 100644 src/main/java/com/msb/proxy/v5/Tank.java create mode 100644 src/main/java/com/msb/proxy/v6/Main.java create mode 100644 src/main/java/com/msb/proxy/v6/Movable.java create mode 100644 src/main/java/com/msb/proxy/v6/Tank.java create mode 100644 src/main/java/com/msb/proxy/v6/TankLogProxy.java create mode 100644 src/main/java/com/msb/proxy/v6/TankTimeProxy.java diff --git a/src/main/java/com/msb/proxy/v5/Movable.java b/src/main/java/com/msb/proxy/v5/Movable.java new file mode 100644 index 0000000..1b076fd --- /dev/null +++ b/src/main/java/com/msb/proxy/v5/Movable.java @@ -0,0 +1,11 @@ +package com.msb.proxy.v5; + +/** + * @Author bingor + * @Date 2022/10/17 9:40 + * @Description: com.msb.proxy.v5 + * @Version: 1.0 + */ +public interface Movable { + public void move(); +} diff --git a/src/main/java/com/msb/proxy/v5/ProxyTank.java b/src/main/java/com/msb/proxy/v5/ProxyTank.java new file mode 100644 index 0000000..bf7e807 --- /dev/null +++ b/src/main/java/com/msb/proxy/v5/ProxyTank.java @@ -0,0 +1,30 @@ +package com.msb.proxy.v5;/** + * @Author bingor + * @Date 2022/10/17 9:42 + * @Description: com.msb.proxy.v5 + * @Version: 1.0 + */ + +/** + *@ClassName ProxyTank + *@Description TODO + *@Author bingor + *@Date 2022/10/17 9:42 + *@Version 3.0 + */ +public class ProxyTank implements Movable { + + private Tank tank = new Tank(); + + @Override + public void move() { + long startTime = System.currentTimeMillis(); + tank.move(); + long entTime = System.currentTimeMillis(); + System.out.println(entTime - startTime); + } + + public static void main(String[] args) { + new ProxyTank().move(); + } +} diff --git a/src/main/java/com/msb/proxy/v5/Tank.java b/src/main/java/com/msb/proxy/v5/Tank.java new file mode 100644 index 0000000..942dc06 --- /dev/null +++ b/src/main/java/com/msb/proxy/v5/Tank.java @@ -0,0 +1,27 @@ +package com.msb.proxy.v5;/** + * @Author bingor + * @Date 2022/10/17 9:41 + * @Description: com.msb.proxy.v5 + * @Version: 1.0 + */ + +import java.util.Random; + +/** + *@ClassName Tank + *@Description TODO + *@Author bingor + *@Date 2022/10/17 9:41 + *@Version 3.0 + */ +public class Tank implements Movable { + @Override + public void move() { + System.out.println("tank move……"); + try { + Thread.sleep(new Random().nextInt(10000)); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/java/com/msb/proxy/v6/Main.java b/src/main/java/com/msb/proxy/v6/Main.java new file mode 100644 index 0000000..e7d664a --- /dev/null +++ b/src/main/java/com/msb/proxy/v6/Main.java @@ -0,0 +1,19 @@ +package com.msb.proxy.v6;/** + * @Author bingor + * @Date 2022/10/17 9:59 + * @Description: com.msb.proxy.v6 + * @Version: 1.0 + */ + +/** + *@ClassName Main + *@Description TODO + *@Author bingor + *@Date 2022/10/17 9:59 + *@Version 3.0 + */ +public class Main { + public static void main(String[] args) { + new TankLogProxy(new TankTimeProxy(new Tank())).move(); + } +} diff --git a/src/main/java/com/msb/proxy/v6/Movable.java b/src/main/java/com/msb/proxy/v6/Movable.java new file mode 100644 index 0000000..0796ea1 --- /dev/null +++ b/src/main/java/com/msb/proxy/v6/Movable.java @@ -0,0 +1,11 @@ +package com.msb.proxy.v6; + +/** + * @Author bingor + * @Date 2022/10/17 9:40 + * @Description: com.msb.proxy.v5 + * @Version: 1.0 + */ +public interface Movable { + public void move(); +} diff --git a/src/main/java/com/msb/proxy/v6/Tank.java b/src/main/java/com/msb/proxy/v6/Tank.java new file mode 100644 index 0000000..055f797 --- /dev/null +++ b/src/main/java/com/msb/proxy/v6/Tank.java @@ -0,0 +1,27 @@ +package com.msb.proxy.v6;/** + * @Author bingor + * @Date 2022/10/17 9:41 + * @Description: com.msb.proxy.v5 + * @Version: 1.0 + */ + +import java.util.Random; + +/** + *@ClassName Tank + *@Description TODO + *@Author bingor + *@Date 2022/10/17 9:41 + *@Version 3.0 + */ +public class Tank implements Movable { + @Override + public void move() { + System.out.println("tank move……"); + try { + Thread.sleep(new Random().nextInt(10000)); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/java/com/msb/proxy/v6/TankLogProxy.java b/src/main/java/com/msb/proxy/v6/TankLogProxy.java new file mode 100644 index 0000000..20bbc90 --- /dev/null +++ b/src/main/java/com/msb/proxy/v6/TankLogProxy.java @@ -0,0 +1,30 @@ +package com.msb.proxy.v6;/** + * @Author bingor + * @Date 2022/10/17 9:42 + * @Description: com.msb.proxy.v5 + * @Version: 1.0 + */ + +/** + *@ClassName ProxyTank + *@Description TODO + *@Author bingor + *@Date 2022/10/17 9:42 + *@Version 3.0 + */ +public class TankLogProxy implements Movable { + + private Movable movable; + + public TankLogProxy(Movable movable) { + this.movable = movable; + } + + @Override + public void move() { + System.out.println("move start run"); + movable.move(); + System.out.println("move end run"); + } + +} diff --git a/src/main/java/com/msb/proxy/v6/TankTimeProxy.java b/src/main/java/com/msb/proxy/v6/TankTimeProxy.java new file mode 100644 index 0000000..28106ea --- /dev/null +++ b/src/main/java/com/msb/proxy/v6/TankTimeProxy.java @@ -0,0 +1,31 @@ +package com.msb.proxy.v6;/** + * @Author bingor + * @Date 2022/10/17 9:42 + * @Description: com.msb.proxy.v5 + * @Version: 1.0 + */ + +/** + *@ClassName ProxyTank + *@Description TODO + *@Author bingor + *@Date 2022/10/17 9:42 + *@Version 3.0 + */ +public class TankTimeProxy implements Movable { + + private Movable movable; + + public TankTimeProxy(Movable movable) { + this.movable = movable; + } + + @Override + public void move() { + long startTime = System.currentTimeMillis(); + movable.move(); + long entTime = System.currentTimeMillis(); + System.out.println(entTime - startTime); + } + +}