package Ġrx . quiz . combin ing Ċ Ċ import Ġio . reactivex . Observable Ċ import Ġio . reactivex . subjects . Behavior Subject Ċ import Ġorg . assertj . core . api . Java 6 Assertions . assertThat Ċ import Ġorg . junit . Test Ċ import Ġrx . quiz . combin ing . Intermediate Combine Latest Ko an . Par king Api Ċ import Ġrx . quiz . combin ing . Intermediate Combine Latest Ko an . Sound Ċ Ċ /** Ċ Ġ* Ġ# ĠTask Ċ Ġ* ĠCreate Ġan Ġ[ Observable ] Ġwhich Ġhelps Ġthe Ġuser Ġby Ġproviding Ġaud ible Ġfeedback Ġabout Ġthe Ġdistance Ġwhen Ġpar king Ċ Ġ* Ċ Ġ* Ġ## ĠD eta iled Ġdescription Ċ Ġ* ĠUsing Ġ[ Par king Api ] Ġevaluate Ġreal - time Ġinformation Ġfrom Ġmultiple Ġsensors Ġusing Ġthe Ġfollowing Ġalgorithm : Ċ Ġ* Ġ* ĠIf Ġpar king Ġis Ġoff Ġ([ Par king Api . is Sw itched On ]), Ġemit Ġ[ Sound . NONE ] Ċ Ġ* Ġ* ĠOtherwise , Ġdepending Ġon Ġthe Ġ[ Par king Api . is Re ar Speed On ], Ġevaluate Ġdistances Ġto Ġfront Ġor Ġrear Ġsensors Ċ Ġ* Ġ* Ġif Ġdistance Ġis Ġmore Ġthan Ġ 3 Ġmeters Ġemit Ġ[ Sound . NONE ] Ċ Ġ* Ġ* Ġif Ġdistance Ġis Ġ 3 Ġmeters Ġemit Ġ[ Sound . B EE EP _ B EE EP ] Ċ Ġ* Ġ* Ġif Ġdistance Ġis Ġ 2 Ġmeters Ġemit Ġ[ Sound . B EE P _ B EE P _ B EE P ] Ċ Ġ* Ġ* Ġif Ġdistance Ġis Ġ 1 Ġmeter Ġemit Ġ[ Sound . B IP _ B IP _ B IP _ B IP ] Ċ Ġ* Ġ* Ġif Ġdistance Ġis Ġ 0 Ġmeters Ġemit Ġ[ Sound . B EEEE EEEE EEEE ] Ċ Ġ* Ċ Ġ* Ġ## ĠRequires Ċ Ġ* Ċ Ġ* Ġ* ĠAdvanced Ġknowledge Ġabout Ġcombining Ġoperators Ċ Ġ*/ Ċ abstract Ġclass ĠInter mediate Combine Latest Ko an Ġ{ ĊĠĠĠ Ġenum Ġclass ĠSound Ġ{ ĊĠĠĠĠĠĠĠ ĠNONE , ĠB EE EP _ B EE EP , ĠB EE P _ B EE P _ B EE P , ĠB IP _ B IP _ B IP _ B IP , ĠB EEEE EEEE EEEE ; ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġinterface ĠPark ing Api Ġ{ ĊĠĠĠĠĠĠĠ Ġfun Ġis Sw itched On (): ĠObservable < Boolean > ĊĠĠĠĠĠĠĠ Ġfun Ġfront Left (): ĠObservable < Int > ĊĠĠĠĠĠĠĠ Ġfun Ġfront Right (): ĠObservable < Int > ĊĠĠĠĠĠĠĠ Ġfun Ġrear Left (): ĠObservable < Int > ĊĠĠĠĠĠĠĠ Ġfun Ġrear Right (): ĠObservable < Int > ĊĠĠĠĠĠĠĠ Ġfun Ġis Re ar Speed On (): ĠObservable < Boolean > ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġabstract Ġfun Ġpar king Assistant ( park ing Api : ĠPark ing Api ): ĠObservable < Sound > ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` use Ġdata Ġfrom Ġmultiple Ġsensors Ġto Ġcreate Ġa Ġpar king Ġassistant `() Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġis Sw itched On Ġ= ĠBehavior Subject . create Default ( false ) ĊĠĠĠĠĠĠĠ Ġval Ġfront Left Ġ= ĠBehavior Subject . create Default ( 1 0 ) ĊĠĠĠĠĠĠĠ Ġval Ġfront Right Ġ= ĠBehavior Subject . create Default ( 1 0 ) ĊĠĠĠĠĠĠĠ Ġval Ġrear Left Ġ= ĠBehavior Subject . create Default ( 1 0 ) ĊĠĠĠĠĠĠĠ Ġval Ġrear Right Ġ= ĠBehavior Subject . create Default ( 1 0 ) ĊĠĠĠĠĠĠĠ Ġval Ġis Re ar Speed On Ġ= ĠBehavior Subject . create Default ( false ) ĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġpar king Assistant ( object Ġ: ĠPark ing Api Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġoverride Ġfun Ġis Sw itched On () Ġ= Ġis Sw itched On ĊĠĠĠĠĠĠĠĠĠĠĠ Ġoverride Ġfun Ġfront Left () Ġ= Ġfront Left ĊĠĠĠĠĠĠĠĠĠĠĠ Ġoverride Ġfun Ġfront Right () Ġ= Ġfront Right ĊĠĠĠĠĠĠĠĠĠĠĠ Ġoverride Ġfun Ġrear Left () Ġ= Ġrear Left ĊĠĠĠĠĠĠĠĠĠĠĠ Ġoverride Ġfun Ġrear Right () Ġ= Ġrear Right ĊĠĠĠĠĠĠĠĠĠĠĠ Ġoverride Ġfun Ġis Re ar Speed On () Ġ= Ġis Re ar Speed On ĊĠĠĠĠĠĠĠ Ġ}). test () ĊĊĠĠĠĠĠĠĠ Ġis Re ar Speed On . onNext ( true ) ĊĠĠĠĠĠĠĠ Ġis Re ar Speed On . onNext ( false ) ĊĠĠĠĠĠĠĠ Ġfront Left . onNext ( 6 ) ĊĠĠĠĠĠĠĠ Ġfront Left . onNext ( 1 ) ĊĠĠĠĠĠĠĠ Ġfront Left . onNext ( 4 ) ĊĠĠĠĠĠĠĠ Ġis Sw itched On . onNext ( true ) ĊĠĠĠĠĠĠĠ Ġfront Right . onNext ( 3 ) ĊĠĠĠĠĠĠĠ Ġfront Right . onNext ( 2 ) ĊĠĠĠĠĠĠĠ Ġfront Left . onNext ( 1 ) ĊĠĠĠĠĠĠĠ Ġfront Left . onNext ( 0 ) ĊĠĠĠĠĠĠĠ Ġis Re ar Speed On . onNext ( true ) ĊĠĠĠĠĠĠĠ Ġrear Right . onNext ( 3 ) ĊĠĠĠĠĠĠĠ Ġrear Left . onNext ( 2 ) ĊĠĠĠĠĠĠĠ Ġrear Left . onNext ( 1 ) ĊĠĠĠĠĠĠĠ Ġfront Left . onNext ( 0 ) ĊĠĠĠĠĠĠĠ Ġfront Left . onNext ( 3 ) ĊĠĠĠĠĠĠĠ Ġis Re ar Speed On . onNext ( false ) ĊĠĠĠĠĠĠĠ Ġfront Right . onNext ( 2 ) ĊĠĠĠĠĠĠĠ Ġfront Left . onNext ( 1 ) ĊĠĠĠĠĠĠĠ Ġrear Right . onNext ( 0 ) ĊĠĠĠĠĠĠĠ Ġfront Left . onNext ( 0 ) ĊĠĠĠĠĠĠĠ Ġfront Right . onNext ( 0 ) ĊĊĠĠĠĠĠĠĠ Ġval Ġvalues Ġ= Ġresult . values (). iterator () ĊĠĠĠĠĠĠĠ ĠassertThat ( values . next ()). described As (" is Ġoff "). isEqualTo ( Sound . NONE ) ĊĠĠĠĠĠĠĠ ĠassertThat ( values . next ()). described As (" is Ġoff "). isEqualTo ( Sound . NONE ) ĊĠĠĠĠĠĠĠ ĠassertThat ( values . next ()). described As (" is Ġoff "). isEqualTo ( Sound . NONE ) ĊĠĠĠĠĠĠĠ ĠassertThat ( values . next ()). described As (" is Ġoff "). isEqualTo ( Sound . NONE ) ĊĠĠĠĠĠĠĠ ĠassertThat ( values . next ()). described As (" is Ġoff "). isEqualTo ( Sound . NONE ) ĊĠĠĠĠĠĠĠ ĠassertThat ( values . next ()). described As (" is Ġoff "). isEqualTo ( Sound . NONE ) ĊĠĠĠĠĠĠĠ ĠassertThat ( values . next ()). described As (" too Ġfar "). isEqualTo ( Sound . NONE ) ĊĠĠĠĠĠĠĠ ĠassertThat ( values . next ()). described As (" clo ser "). isEqualTo ( Sound . B EE EP _ B EE EP ) ĊĠĠĠĠĠĠĠ ĠassertThat ( values . next ()). described As (" clo ser "). isEqualTo ( Sound . B EE P _ B EE P _ B EE P ) ĊĠĠĠĠĠĠĠ ĠassertThat ( values . next ()). described As (" very Ġclose "). isEqualTo ( Sound . B IP _ B IP _ B IP _ B IP ) ĊĠĠĠĠĠĠĠ ĠassertThat ( values . next ()). described As (" almost Ġhit Ġthe Ġwall "). isEqualTo ( Sound . B EEEE EEEE EEEE ) ĊĠĠĠĠĠĠĠ ĠassertThat ( values . next ()). described As (" sw itched Ġge ars "). isEqualTo ( Sound . NONE ) ĊĠĠĠĠĠĠĠ ĠassertThat ( values . next ()). described As (" something Ġcoming Ġfrom Ġbehind "). isEqualTo ( Sound . B EE EP _ B EE EP ) ĊĠĠĠĠĠĠĠ ĠassertThat ( values . next ()). described As (" something Ġcoming Ġfrom Ġbehind "). isEqualTo ( Sound . B EE P _ B EE P _ B EE P ) ĊĠĠĠĠĠĠĠ ĠassertThat ( values . next ()). described As (" something Ġcoming Ġfrom Ġbehind "). isEqualTo ( Sound . B IP _ B IP _ B IP _ B IP ) ĊĠĠĠĠĠĠĠ ĠassertThat ( values . next ()). described As (" something Ġcoming Ġfrom Ġbehind "). isEqualTo ( Sound . B IP _ B IP _ B IP _ B IP ) ĊĠĠĠĠĠĠĠ ĠassertThat ( values . next ()). described As (" something Ġcoming Ġfrom Ġbehind "). isEqualTo ( Sound . B IP _ B IP _ B IP _ B IP ) ĊĠĠĠĠĠĠĠ ĠassertThat ( values . next ()). described As (" sw itched Ġge ar Ġagain "). isEqualTo ( Sound . B EE P _ B EE P _ B EE P ) ĊĠĠĠĠĠĠĠ ĠassertThat ( values . next ()). described As (" going Ġforwards "). isEqualTo ( Sound . B EE P _ B EE P _ B EE P ) ĊĠĠĠĠĠĠĠ ĠassertThat ( values . next ()). described As (" going Ġforwards "). isEqualTo ( Sound . B IP _ B IP _ B IP _ B IP ) ĊĠĠĠĠĠĠĠ ĠassertThat ( values . next ()). described As (" going Ġforwards "). isEqualTo ( Sound . B IP _ B IP _ B IP _ B IP ) ĊĠĠĠĠĠĠĠ ĠassertThat ( values . next ()). described As (" going Ġforwards "). isEqualTo ( Sound . B EEEE EEEE EEEE ) ĊĠĠĠĠĠĠĠ ĠassertThat ( values . next ()). described As (" done "). isEqualTo ( Sound . B EEEE EEEE EEEE ) ĊĠĠĠ Ġ} Ċ }