From 2b887783c26129324db847b87f1653d2ad61a9ff Mon Sep 17 00:00:00 2001 From: chenjianqiang Date: Wed, 13 Oct 2021 10:51:26 +0800 Subject: [PATCH] init Signed-off-by: chenjianqiang --- .idea/.gitignore | 0 .idea/description.html | 1 + .idea/encodings.xml | 6 + .idea/inspectionProfiles/Project_Default.xml | 36 +++++ .idea/misc.xml | 12 ++ .idea/modules.xml | 8 ++ .idea/project-template.xml | 3 + .idea/workspace.xml | 125 ++++++++++++++++++ .../InterpreterPattern/InterpreterMain.class | Bin 0 -> 2419 bytes .../InterpreterPattern/po/AndExpression.class | Bin 0 -> 803 bytes .../InterpreterPattern/po/Expression.class | Bin 0 -> 176 bytes .../InterpreterPattern/po/OrExpression.class | Bin 0 -> 1086 bytes .../po/TerminalExpression.class | Bin 0 -> 1716 bytes out/production/patterns/com/chen/Main.class | Bin 0 -> 451 bytes .../InterpreterPattern/AndExpression.class | Bin 0 -> 901 bytes .../InterpreterPattern/Expression.class | Bin 0 -> 176 bytes .../InterpreterPattern/InterpreterMain.class | Bin 0 -> 2558 bytes .../InterpreterPattern/OrExpression.class | Bin 0 -> 1086 bytes .../TerminalExpression.class | Bin 0 -> 1716 bytes .../untitled/com/company/Main.class | Bin 0 -> 460 bytes patterns.iml | 11 ++ .../InterpreterPattern/InterpreterMain.java | 55 ++++++++ .../chen/InterpreterPattern/package-info.java | 4 + .../InterpreterPattern/po/AndExpression.java | 28 ++++ .../InterpreterPattern/po/Expression.java | 18 +++ .../InterpreterPattern/po/OrExpression.java | 28 ++++ .../po/TerminalExpression.java | 46 +++++++ src/com/chen/PatternMain.java | 19 +++ 28 files changed, 400 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/description.html create mode 100644 .idea/encodings.xml create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/project-template.xml create mode 100644 .idea/workspace.xml create mode 100644 out/production/patterns/com/chen/InterpreterPattern/InterpreterMain.class create mode 100644 out/production/patterns/com/chen/InterpreterPattern/po/AndExpression.class create mode 100644 out/production/patterns/com/chen/InterpreterPattern/po/Expression.class create mode 100644 out/production/patterns/com/chen/InterpreterPattern/po/OrExpression.class create mode 100644 out/production/patterns/com/chen/InterpreterPattern/po/TerminalExpression.class create mode 100644 out/production/patterns/com/chen/Main.class create mode 100644 out/production/untitled/com/company/InterpreterPattern/AndExpression.class create mode 100644 out/production/untitled/com/company/InterpreterPattern/Expression.class create mode 100644 out/production/untitled/com/company/InterpreterPattern/InterpreterMain.class create mode 100644 out/production/untitled/com/company/InterpreterPattern/OrExpression.class create mode 100644 out/production/untitled/com/company/InterpreterPattern/TerminalExpression.class create mode 100644 out/production/untitled/com/company/Main.class create mode 100644 patterns.iml create mode 100644 src/com/chen/InterpreterPattern/InterpreterMain.java create mode 100644 src/com/chen/InterpreterPattern/package-info.java create mode 100644 src/com/chen/InterpreterPattern/po/AndExpression.java create mode 100644 src/com/chen/InterpreterPattern/po/Expression.java create mode 100644 src/com/chen/InterpreterPattern/po/OrExpression.java create mode 100644 src/com/chen/InterpreterPattern/po/TerminalExpression.java create mode 100644 src/com/chen/PatternMain.java diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/.idea/description.html b/.idea/description.html new file mode 100644 index 0000000..db5f129 --- /dev/null +++ b/.idea/description.html @@ -0,0 +1 @@ +Simple Java application that includes a class with main() method \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..97626ba --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..6560a98 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,36 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..2fc6c34 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..d97338e --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/project-template.xml b/.idea/project-template.xml new file mode 100644 index 0000000..1f08b88 --- /dev/null +++ b/.idea/project-template.xml @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..8e2f1cf --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,125 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1634023392076 + + + + + + \ No newline at end of file diff --git a/out/production/patterns/com/chen/InterpreterPattern/InterpreterMain.class b/out/production/patterns/com/chen/InterpreterPattern/InterpreterMain.class new file mode 100644 index 0000000000000000000000000000000000000000..a461ab0ba6cbe8437d1850d3a0a1c3de48cd760b GIT binary patch literal 2419 zcmb7G>vI!T6#s3Kb~oulA*JOZEpKR3AoB3RqeVcfXraYaFd*u7yR-|*ZryBo_@Y3e zijtvfGEx=BVbEP%j1(@^uKVjY5BxgKcVMrnvg=JW2QOho^#K+_xHQ^oSXjf zaPTgG)#wgjDYl8&E}=m}qaW4SA>j=P5gs;4cvHeo9`2IxmV~H;-E8fV@HXqc65e6` zu7vj_C=!|_s1jP(r-|4Xz$~<~(Z)h&v7f~OKVpbWFal(l0eH|J!27U7Bt+N&EJjBF zi_pQb2a9kBheaF_@qvIMRkx39G+OE`O%qVEr+&Y3PzlErqct3{E!}8c$1#f4l8Y%i zWLgJumS2g*8mvrqU>_~A-L!R;mI{u$QlecmTCyR2wIgAham`8y5GbX(UNz%kwM{d^ zTMb*Y+AWP_qhgaZ!tG{w%VBaQ61r&+sz7e%CIPD^N^R1txNa!1F-ypKwNrp^v)MwJi|chm+ujjx)~qI_Ipz{KRVB7lv2?aaoj$uwCzi{e z3Nw%NHbrNSzBp+CQud$(Op4fwdSIKPZ*XCY@cx?66d= zPG`W=9@}?0mw=2K5Z5V>mjj(cy7#J+ydc1z{<1TDp?Bo;bs5VTh~F7Fp1yX@>A6Vb z;mdbZ_j+k8Bg~WX@K0x*(-)n~-#NGXI5v6XerIRu_Bk2P@_eCl^(*JcZVGhWJ)tp+9!!mrnE5nWkd1U70W2dRq!0B{< za%@aRE-}ZP1F|dyl%_xZ;{J&{AZ|y@FFJg_1 zwJg@LSdTR#K9cbpNXjv2JTcwI+3Mk}A%>SG_X{}IY;swOz-N2g4E zMmRGs>3?9|jd}E=u#|qiWcpGclLWV{tEn|zP0ihJwL|g5beR zB>|%z%)my9kTbBc37g3h@N$mQpOjlbzP8X1W<^7N zC{E&;e$39A1+H11H6_=q$eKm2Ifv3_)>q%H@z$2lzJxi|h>$ObkM)Vl5RVw70EQ;QQ?psbYh=DorU&)^0xFZg A`~Uy| literal 0 HcmV?d00001 diff --git a/out/production/patterns/com/chen/InterpreterPattern/po/AndExpression.class b/out/production/patterns/com/chen/InterpreterPattern/po/AndExpression.class new file mode 100644 index 0000000000000000000000000000000000000000..c03865dd615f609211e3e2da64a1e0823d5e42b5 GIT binary patch literal 803 zcmb7C%Ss$U6g^elPCGBhjIYEbX57s~Y$DkyAwd!dOdc>{z-&TITWFcFdgy6`zv36T zaT8EP7k)rKD&$ldjCzUQ8Esrvor`Ub!&tQL^NlRT!d?BHn;0iFeT9$+QF z3jwKL3bfi$d>BUi+J+x&s*^#YiC$6gA$C2uHRbm_;75#MI3nWoC(v?-M!|WX_zqEK4ZG;jI*mg wO(?XxNquE2_kR}qlM0b*W$WZnAk2q>lS2j4?5qm{cLDX@a}yIDx@-rkPF+?z(WP zuC>wlin?K=5ex=&@6RAu+3^pI=T57Xh-uiIJLlYUzVF=g&H4W8%U1vsxDY}&27?IU zC^thv9K-PdPK0n0rvexb;WQH6P>__7l984%!XTI#hIH0&N}4fe+S+y7Gu^UllAYE) zvbI)sw5tmgs#Gk;p5!It3|$v3+wv|k%p~?uyoc0eok5 z6j8H|p%?SIYjM97l)O2s!Z6y2WXj#~oS^mR$qeyCc3!`yYen6j)pDL|*|U?$+YGYd zP|||Ong2;(2k;soT_V>*DT&^PdncjuT~JlsDdye3ZjU}7*n9(3`4N7 z_-E-PY>E#+zE>#oLXwmp|(demr`$wOW@kq2L_O zD>#6Iq+|yn+k0V%ZNFuzFmD?4zGMf0?a?ua2`*9_NbY{cGfQ;gR0%5H9F^s0(=$koWn{+C3rlS2HCG)fqd`TEBfdG{&K%1j- z5$F^s9zzdVmAo19MLMIY&tR$a5`@&q62uRFVlP=064@}>2!cLD4ErfE)GR|BedG~< zPs98#PQ+P70*#rY7j^j-7?m6#y-{<{$&iVPzA0Gg?imez% zFs)%GhAX%lLm!@tVi<)ep2rI@yolKdiZRULr8Ahv%WCzChHEkCn2umUeHWE@Rf+4$ zVM)Vl8g6K~DG=P2o)j1?-I04T-|$Q;UpBm=K(uV`*wSmbhQP(sr*o~XCGDMj*>g>M zr#MfK@SJIz-n_tQ=61J5cAdc%oo&JmmQ34NX;ilicTH|t)Wl0pMOy39HPybY40^j} zUEoTo;#BjMUBk}bv^~SExd!E`^eF9o&B?DBZq>Al^}6ZUOlG)83M|SzMi5A3 zdL+3iAQ&^=eI%e&9D4720+D*nGQFk7K9_AJox+UXuy`zp(qHyu<>O^p^NZ2&y5IAZ zK&`Hskq#CkD6BFs*IFWoI59efsMcpa1sLfsXg^z7ikk z_z)i{P!eSNe-A<6Y$w{Stvg1At;zleOlO9t+*>STX&FVM7Ov0LYpyHrs@}_b$*eO# z`V{wCVT;+;IDHRgMt&sQ)Ax0Yj%6`D#hea)t4nw5o>66Br$O*U3&(Wwt7N^$tPELI zWb+F>ttMY;%E+?+LAB$YScp#^Y1%B{{7E)0?n<|8e9|!Nic!oeHg$+V68sAw?Ls~= z1umaNYhTf9&l?ezwVGjX3rzNM>AD7OzOd#Cnay@vyXnN^i02#+Z6woeNQ<8LZyhPV zZ6n|@|8YfdejnpQ*oP$lg1kRZd4ZZ$1gQZ=#t$LJkI=V~`yPQq1iwS*Yv1Du$^ir@ zhiDro@-Uv{ZnWixr!dAH5vWNKRp4n{Y@v%R{h~bE`v&3hZxL!ji$|7o6HP=9FrYNK z9}w%qeWg0H5-0>GXG6)*gF-k^&=OiA{3TM!P(quTjVR+}#JBzo;b0+nPZM7~`h~zp z&^HdzA0KF9FcECxY!gFG#1p~$j2wWNiO~0l+Z9G1oQeGAvP>e<32q57ow!5ssI20 literal 0 HcmV?d00001 diff --git a/out/production/patterns/com/chen/Main.class b/out/production/patterns/com/chen/Main.class new file mode 100644 index 0000000000000000000000000000000000000000..7e9403a55142821afe45e18faf03366875057e5b GIT binary patch literal 451 zcmZuu%Sr<=6g`qFpG0@PwqJ!Xg2i!C1xIt*PG+b(tl>ZjW1;!L2@+aC&4&+|tm z(2TWF*RyG&?43*|#B9cSDkno}HTO%hT8#8FPpA1bN=M2>S5lik*-WVlbbAl+SiZ<; zB25+z3ad@lU&Kh8k+A*Gv4B6wXEs$AnsYsNJYtg&F4hDNS6P>)Q1;0x!dqDon&=P3 zx)AFuX{;nn3be{Q-6Ug`7T80LUWk_i!8wE;brDrTwRSLvcwHR(g!Nw%0qw)(K172$ pj}n{2u=r$Q1_U2)?&qkyp;}t-CxCK%8ZB)Cw6H-uy*HtQ_766`SsMTV literal 0 HcmV?d00001 diff --git a/out/production/untitled/com/company/InterpreterPattern/AndExpression.class b/out/production/untitled/com/company/InterpreterPattern/AndExpression.class new file mode 100644 index 0000000000000000000000000000000000000000..6096ffa1d7025af6f71bcbfe5963a78b31d12f3e GIT binary patch literal 901 zcmcIi%Wl&^6g}5=YLX^Rnx^Gd9sw4K)70XzD?%Uy5>j|bL0PbyxK^2xjw8oKWzSFW z1#H+L5g}Oc0elqVjAT42^Zm!yZvbxLS_wYR7qNs*3l}V0T*fI} z@^RTm)5jHo6JHl}dQox^@*6AjCVXVFI31@k@tMkqCVX&2KAGsm?AVqY7H$fbZfm2n zJA${Ze^B^8rR{;hyPxdFf@)8j_{rhHFixMV;fO2sUJ|L%K&9I9<3%rfsV9Q%MS1R- z-MRA@_3VNK>#g3tdac5dGJ9b^OSReCX}=KoQNp65%v%3dAgJ^+6}@__#>Y`g{p2u> z;)gm9J7>6U+smlnY8ge8%2>8gw$Q-3U~9pzn-de%PSQLb?#B@mwihUz9A4nI+5 zdIMM^7Z3syLT+qe-+B&&#qv?5cMY u3hk~kqE+@O_y0QfClz9~l|z6q9|n$>nsvwsgd~0fC?$-L_6p<339=tl2`{Yx literal 0 HcmV?d00001 diff --git a/out/production/untitled/com/company/InterpreterPattern/InterpreterMain.class b/out/production/untitled/com/company/InterpreterPattern/InterpreterMain.class new file mode 100644 index 0000000000000000000000000000000000000000..dbe68156ec9d66a917fd4d853ac15a942d2f9f19 GIT binary patch literal 2558 zcmcIm+jA3T6#s3Kb~ovkLQ0E8+Hw(W(@MCBNC8EpiWXW-1p}gP)1_TVHg&Uw)*F?! z+@y@m=s4mO2Sjm3839{TS}sq%=zrm4)AGctPv|+DCQWIbJkidc^PThk&dKk5`<;{g z`DpYWfOR%Xxcz?qo<%r@BD|(whU>cgv5{Xw6^> zjz*2c8OyDN!;MBN+H;VS?24LNh*EiH%@pfU_0}{*AXrU9C>rt8)1m0y{vEoh8Xbm8 zvPm&X>i+FrWXED!R3|2$%%?RASeq-fSv4Y>u7szhkh2P=Byv`5Y-SZlraRObGoumJ zhzZEwr0JTuMS!!adXE6twrDHyFKWRJD+#1_sUZO?s%9Q~^-LFCPdds#w9^Qw z^%`@Y|JdiQd28Sj zt;et2OWYr%wG2OR%Huzuv(8+yu6%FZ9%5|#=7XM|#GUgpR`Gtmb?s~Gr;`M<-2>K% z?-HYzUtRx`?*92)eiJ^jc@XNsRuQolV9jE_QW}?wEPS`K^5-;{|Mx z@gj?jEb6d9#HTVo!!ZF1w#@z~<8|zi(Ssc#=uD5Jm-;gYfktDhy9CtcK-1Wmf-}=T z7X31w$9fSbWSqn)0V{K4dF--IyP}OPht!ZMptNe1QO13neVw~wrW&D!j&@Q+Nvct_ zsK1Hko=MYBRU*`Y`Jt#DQV39NH^TIN0b&QE!#X9Ht^4Q``>Jwv{nVM%JsBt$9(+PH zICpi9H#SuuwLKkIYRLc3k?q40`kJbx?^Br`8Y?8h6U5duDQr!%z}D3Hwx%|=HQgjz zQv=wVdcfAy2DYY7ur;+8X(t4pawK0O>ks773OMGAL-6I@g(K+nIs-wM*A*B>UfPq- z9+5m!+T&)Ahdc$o{8W_8p29#d&pU_QMLzG`Va)S+y~8N>Nh!#DhLkX*G!V@9E(iog z?^6UWyFnBjc$wr|Nq3bH%ar7M9(@Gks3s>c4+8cV`y&aulJ0{wwK4E~c5b6irwLg>)PJAYtyMRBIE} zvYlR_iaxQGq7*?<@r>BCR$~c~l zqiPt{WK`GOhR=Zu@Q_h_6(Xs5*C{;3m47h-)x@eM!--N)GT{}o6TqBAIM#0y@dlZ1 IlIcLhe}dchKmY&$ literal 0 HcmV?d00001 diff --git a/out/production/untitled/com/company/InterpreterPattern/OrExpression.class b/out/production/untitled/com/company/InterpreterPattern/OrExpression.class new file mode 100644 index 0000000000000000000000000000000000000000..b169cff01565dd8fcd2c0f8739a17b30d5b27f1c GIT binary patch literal 1086 zcmb7DO-~b16g_XIGVL(^V6dp5h+o(bU@W38Fvi4aVp4^qrU~w*;{*rWnPxgQuYC~^WOJgU%mpEzy%rI7z{zi zQ67duIELdvoRD!6r-B%kaT!M{_-X(^a#2$+GkebXh1g-Qo(d@>4hS# zs9DF*i+SC(IBqQlyt`I~VYHLTl)Ga)A?we68RCiToPJ-|in=|kWCw!n(J_b#Zc-abZlU6tCHmo1i7MV4mE~yDG)Rxe zY3e09KkWtni0L%Zd<~syhIcbyw~_byt?%R}pUPaRX#dB_JlzO>Nf=!M0V;QZZjQ=L zptnHlG4xPW3C$1|=^agd21})vAf!f?Ab#)@dnu|2Pz+OyAmmfTu%A|jnq`Qij}Q^~ zGR*(tLR^NtYROb7TcCfLj|iyy(#z;lB?`+3ranPPuOK9#ju-*437$dq#_Z# l5!ol`r_Klb2Kt(We;df)5c)}OfO5NtM!d`j9VR5;$Zy%~7R>+v literal 0 HcmV?d00001 diff --git a/out/production/untitled/com/company/InterpreterPattern/TerminalExpression.class b/out/production/untitled/com/company/InterpreterPattern/TerminalExpression.class new file mode 100644 index 0000000000000000000000000000000000000000..1de125d5328d5d1b8763d9b36f8ef431910b0a4b GIT binary patch literal 1716 zcmb7ET~ixX7=BK^Hc1yKflyKJFC6Q0Ho<_2<2bYX?%DUe@AG~==luHT&-Vdb#by-4 zn9?vE#T8tQ!iN_k7(zaR7x7XQFJmT*LKL%j)60;#`6GA3~s(*T3d$0&OA8!{P(ZEeE7?Ojt}sm5+CXK z7@sIm5@hOs4?*B;C)%yeJ4TtU$@~XQXNITTTP$N~X+@(JuE*7DjwAO~?`6Gc))^pm zihHfFg-mOlo`*6cKN9Wfd%A_HWidU)oDP1gOZ#=#s4#G~LGXAB$E@a7$aJWh>_!mIh1wCR4 zTt11`KBAePCn6+kHN)N#nCRuwbqv~kVa*rP8|}7s(}~+*w|YFZ;dHklEqb26H6(er z4TIZ!V~XJXKEaF7hXh|i-k+zuK+OsQ)BwX{hY({&@U3Tmg#QqM9}xW3^LUD~AAZU~ z+Qx`Hgs1s8((=PI808-ks7Vr4;8|R3p^FUtBHY{k4xzE{5o|(>g_pA9O+*gRuQb`8 z5cT1nQk_}$=K~Wn!9?(WKIG49aV;MD8p%X3u1(K`m2o2MS$~00ARoA^iEkeNM&Kjp z>xbxz^*1pP4>WPMiNPjf@xVPs_Cw`A&08DHI?7!8m}Q(fj^a67LJAqmd0b{E(kOAg zjx6dJ_iCI&hdm)tuxWp~#rmU&p&+=kH!5`p{ z65oqLb1;y3`{wP;gqN@H_fG&v*bC4=*TZ%I2VI7qhaC^Q0*w=Gba5(B>mQ5-+_U^a z3AAEu)YW1(QTA3&GGeykJdxR0TFw0*=@yUriDyYZi|Cz8^AcT3ZHDADqbktr-^Ww= zETc@CG#V9Fn{-$vNt=?k^Uqiy808C_sB_KHK06NBB!q`Gfk8Fy!W7ERts=aU1)+&5 z6iY*Fu&P~EF;CR$%dRI=l@!=VomRz<1Hoy8K6MdQLA8Fkgm^8-0b!#g+i21`{JlVR rojRXFTg0&VxHJQrA8_uLsJ+2mS@7QgItb9M*fi0`Ch@dfLI<56BZFN~ literal 0 HcmV?d00001 diff --git a/patterns.iml b/patterns.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/patterns.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/com/chen/InterpreterPattern/InterpreterMain.java b/src/com/chen/InterpreterPattern/InterpreterMain.java new file mode 100644 index 0000000..97d933d --- /dev/null +++ b/src/com/chen/InterpreterPattern/InterpreterMain.java @@ -0,0 +1,55 @@ +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; + } +} diff --git a/src/com/chen/InterpreterPattern/package-info.java b/src/com/chen/InterpreterPattern/package-info.java new file mode 100644 index 0000000..d625f2a --- /dev/null +++ b/src/com/chen/InterpreterPattern/package-info.java @@ -0,0 +1,4 @@ +/** + * 解释器模式 + */ +package com.chen.InterpreterPattern; diff --git a/src/com/chen/InterpreterPattern/po/AndExpression.java b/src/com/chen/InterpreterPattern/po/AndExpression.java new file mode 100644 index 0000000..31cad07 --- /dev/null +++ b/src/com/chen/InterpreterPattern/po/AndExpression.java @@ -0,0 +1,28 @@ +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); + } +} diff --git a/src/com/chen/InterpreterPattern/po/Expression.java b/src/com/chen/InterpreterPattern/po/Expression.java new file mode 100644 index 0000000..c5675f5 --- /dev/null +++ b/src/com/chen/InterpreterPattern/po/Expression.java @@ -0,0 +1,18 @@ +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); +} diff --git a/src/com/chen/InterpreterPattern/po/OrExpression.java b/src/com/chen/InterpreterPattern/po/OrExpression.java new file mode 100644 index 0000000..fc25670 --- /dev/null +++ b/src/com/chen/InterpreterPattern/po/OrExpression.java @@ -0,0 +1,28 @@ +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); + } +} diff --git a/src/com/chen/InterpreterPattern/po/TerminalExpression.java b/src/com/chen/InterpreterPattern/po/TerminalExpression.java new file mode 100644 index 0000000..072b8e4 --- /dev/null +++ b/src/com/chen/InterpreterPattern/po/TerminalExpression.java @@ -0,0 +1,46 @@ +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 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; + } +} diff --git a/src/com/chen/PatternMain.java b/src/com/chen/PatternMain.java new file mode 100644 index 0000000..9b948a5 --- /dev/null +++ b/src/com/chen/PatternMain.java @@ -0,0 +1,19 @@ +package com.chen; + +import com.chen.InterpreterPattern.InterpreterMain; + +/** + * @author lx + */ +public class PatternMain { + + public static void main(String[] args) { + + //解释器模式 + new InterpreterMain().main(); + + + + } + +} -- GitLab