package Ġcn . lab zen . cells . network . http . meta Ċ Ċ import Ġcom . google . common . cache . Cache Builder Ċ import Ġcn . lab zen . cells . network . http . meta . Operating System . Type .* Ċ import Ġjava . util . concurrent . TimeUnit Ċ Ċ const Ġval ĠUNKNOWN Ġ= Ġ" Unknown " Ċ Ċ val ĠUNKNOWN _ DEVICE Ġ= ĠDevice ( UNKNOWN ) Ċ val ĠUNKNOWN _ OPER ATING _ SYSTEM Ġ= ĠOperating System ( UNKNOWN ) Ċ val ĠUNKNOWN _ LAYOUT _ ENGINE Ġ= ĠLayout Engine ( UNKNOWN ) Ċ val ĠUNKNOWN _ AGENT Ġ= ĠAgent ( UNKNOWN ) ĊĊ Ċ data Ġclass ĠDevice Ġ@ Jvm Over loads Ġconstructor ( ĊĠ Ġval Ġtype : ĠString , Ġval Ġname : ĠString Ġ= ĠUNKNOWN Ċ ) Ġ{ ĊĠ Ġvar Ġbrand : ĠString Ġ= ĠUNKNOWN ĊĠ Ġvar Ġcpu : ĠString Ġ= ĠUNKNOWN ĊĠ Ġvar Ġbits : ĠInt Ġ= Ġ 0 Ċ } Ċ Ċ data Ġclass ĠOperating System Ġ@ Jvm Over loads Ġconstructor ( ĊĠ Ġval Ġtype : ĠString , ĊĠ Ġval Ġname : ĠString Ġ= ĠUNKNOWN , ĊĠ Ġval Ġversion : ĠString Ġ= ĠUNKNOWN Ċ ) Ġ{ ĊĠ Ġvar Ġnamed Version : ĠString Ġ= ĠUNKNOWN ĊĊĠ Ġenum Ġclass ĠType Ġ{ ĊĠĠĠ ĠDES K TOP , ĠPH ONE , ĠTABLE T , ĠW ATCH , ĠG AMES , ĠR OB OT , ĠPRO GRAM ĊĠ Ġ} Ċ } Ċ Ċ data Ġclass ĠLayout Engine Ġ@ Jvm Over loads Ġconstructor ( ĊĠ Ġval Ġtype : ĠString , ĊĠ Ġval Ġname : ĠString Ġ= ĠUNKNOWN , ĊĠ Ġval Ġversion : ĠString Ġ= ĠUNKNOWN Ċ ) Ġ{ ĊĠ Ġvar Ġnamed Version : ĠString Ġ= ĠUNKNOWN ĊĠ Ġvar Ġbuild : ĠString Ġ= ĠUNKNOWN ĊĊĠ Ġenum Ġclass ĠType Ġ{ ĊĠĠĠ ĠB ROW SER , ĠPRO GRAM ĊĠ Ġ} Ċ } Ċ Ċ data Ġclass ĠAgent Ġ@ Jvm Over loads Ġconstructor ( ĊĠ Ġval Ġtype : ĠString , ĊĠ Ġval Ġname : ĠString Ġ= ĠUNKNOWN , ĊĠ Ġval Ġversion : ĠString Ġ= ĠUNKNOWN Ċ ) Ġ{ ĊĠ Ġvar Ġnamed Version : ĠString Ġ= ĠUNKNOWN ĊĊĠ Ġenum Ġclass ĠType Ġ{ ĊĠĠĠ ĠB ROW SER , ĠWEB VIEW , ĠAPP , ĠE MAIL , ĠPRO GRAM , ĠSYSTEM ĊĠ Ġ} Ċ } Ċ Ċ data Ġclass ĠUser Agent Ġinternal Ġconstructor ( ĊĠ Ġval Ġoriginal : ĠString , ĊĠ Ġval Ġdevice : ĠDevice , ĊĠ Ġval Ġoperating System : ĠOperating System , ĊĠ Ġval Ġlayout Engine : ĠLayout Engine , ĊĠ Ġval Ġagent : ĠAgent Ċ ) Ġ{ ĊĊĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠ Ġ/* ĊĠĠĠĠ Ġ* Ġ ç¼ĵåŃĺ çŃĸçķ¥ éľĢè¦ģ ä¼ĺåĮĸ ĊĠĠĠĠ Ġ*/ ĊĠĠĠ Ġprivate Ġval Ġcache Ġ= ĠCache Builder . newBuilder () ĊĠĠĠĠĠ Ġ. expire After Access ( 3 0 , ĠTimeUnit . SECONDS ) ĊĠĠĠĠĠ Ġ. maximum Size ( 5 1 2 ) ĊĠĠĠĠĠ Ġ. build < Int , ĠUser Agent >() ĊĊĠĠĠ Ġ@ Jvm Static ĊĠĠĠ Ġfun Ġparse ( value : ĠString ): ĠUser Agent Ġ{ ĊĠĠĠĠĠ Ġval Ġkey Ġ= Ġvalue . hashCode () ĊĠĠĠĠĠ Ġreturn Ġcache . get ( key ) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġdevice Ġ= ĠDevice Analyzer . analyze ( value ) ĊĠĠĠĠĠĠĠ Ġval Ġoperating System Ġ= ĠOperating System Analyzer . analyze ( value ) ĊĠĠĠĠĠĠĠ Ġval Ġlayout Engine Ġ= ĠLayout Engine Analyzer . analyze ( value ) ĊĠĠĠĠĠĠĠ Ġval Ġagent Ġ= ĠAgent Analyzer . analyze ( value ) ĊĊĠĠĠĠĠĠĠ ĠUser Agent ( value , Ġdevice , Ġoperating System , Ġlayout Engine , Ġagent ) ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĠ Ġ} Ċ } Ċ Ċ internal Ġopen Ġclass ĠMatcher ( val Ġname : ĠString , Ġpattern : ĠString ) Ġ{ ĊĊĠ Ġprivate Ġval Ġregex Ġ= ĠRegex ( pattern , ĠRegex Option . IGNORE _ CASE ) ĊĊĠ Ġfun Ġmatch ( value : ĠString ): ĠBoolean Ġ= ĊĠĠĠ Ġregex . contains Match In ( value ) Ċ } Ċ Ċ internal Ġobject ĠDevice Analyzer Ġ{ ĊĊĠ Ġprivate Ġval Ġmatch ers Ġ= ĠlistOf < Matcher >() ĊĊĠ Ġ// Ġtodo ĊĠ Ġfun Ġanalyze ( value : ĠString ): ĠDevice Ġ= ĊĠĠĠ ĠUNKNOWN _ DEVICE Ċ } Ċ Ċ internal Ġobject ĠOperating System Analyzer Ġ{ ĊĊĠ Ġinternal Ġclass ĠOperating System Matcher ( ĊĠĠĠ Ġname : ĠString , ĊĠĠĠ Ġpattern : ĠString , ĊĠĠĠ Ġval Ġtype : ĠOperating System . Type ĊĠ Ġ) Ġ: ĠMatcher ( name , Ġpattern ) ĊĊĠ Ġprivate Ġval Ġmatch ers Ġ= ĠlistOf ( ĊĠĠĠ ĠOperating System Matcher (" Windows Ġ 1 0 Ġor ĠWindows ĠServer Ġ 2 0 1 6 ", Ġ" windows Ġnt Ġ 1 0 \\. 0 ", ĠDES K TOP ), ĊĠĠĠ ĠOperating System Matcher (" Windows Ġ 8 . 1 Ġor ĠW ins ows ĠServer Ġ 2 0 1 2 R 2 ", Ġ" windows Ġnt Ġ 6 \\. 3 ", ĠDES K TOP ), ĊĠĠĠ ĠOperating System Matcher (" Windows Ġ 8 Ġor ĠW ins ows ĠServer Ġ 2 0 1 2 ", Ġ" windows Ġnt Ġ 6 \\. 2 ", ĠDES K TOP ), ĊĠĠĠ ĠOperating System Matcher (" Windows ĠVista ", Ġ" windows Ġnt Ġ 6 \\. 0 ", ĠDES K TOP ), ĊĠĠĠ ĠOperating System Matcher (" Windows Ġ 7 Ġor ĠWindows ĠServer Ġ 2 0 0 8 R 2 ", Ġ" windows Ġnt Ġ 6 \\. 1 ", ĠDES K TOP ), ĊĠĠĠ ĠOperating System Matcher (" Windows Ġ 2 0 0 3 ", Ġ" windows Ġnt Ġ 5 \\. 2 ", ĠDES K TOP ), ĊĠĠĠ ĠOperating System Matcher (" Windows ĠXP ", Ġ" windows Ġnt Ġ 5 \\. 1 ", ĠDES K TOP ), ĊĠĠĠ ĠOperating System Matcher (" Windows Ġ 2 0 0 0 ", Ġ" windows Ġnt Ġ 5 \\. 0 ", ĠDES K TOP ), ĊĠĠĠ ĠOperating System Matcher (" Windows ĠPhone ", Ġ" windows Ġ( ce | phone | mobile )( Ġos )? ", ĠPH ONE ), ĊĠĠĠ ĠOperating System Matcher (" Windows ", Ġ" windows ", ĠDES K TOP ), ĊĠĠĠ ĠOperating System Matcher (" OSX ", Ġ" os Ġx Ġ( \\ d + )[ ._ ]( \\ d + )", ĠDES K TOP ), ĊĠĠĠ ĠOperating System Matcher (" Android ", Ġ" Android ", ĠPH ONE ), ĊĠĠĠ ĠOperating System Matcher (" Linux ", Ġ" linux ", ĠDES K TOP ), ĊĠĠĠ ĠOperating System Matcher (" W ii ", Ġ" w ii ", ĠG AMES ), ĊĠĠĠ ĠOperating System Matcher (" PS 3 ", Ġ" play station Ġ 3 ", ĠG AMES ), ĊĠĠĠ ĠOperating System Matcher (" P SP ", Ġ" play station Ġportable ", ĠG AMES ), ĊĠĠĠ ĠOperating System Matcher (" i Pad ", Ġ"\\ ( i Pad .* os Ġ( \\ d + )[ ._ ]( \\ d + )", ĠTABLE T ), ĊĠĠĠ ĠOperating System Matcher (" iPhone ", Ġ"\\ ( iPhone .* os Ġ( \\ d + )[ ._ ]( \\ d + )", ĠPH ONE ), ĊĠĠĠ ĠOperating System Matcher (" Y Pod ", Ġ" i Pod Ġtouch [ \\ s \\ ; ]+ iPhone .* os Ġ( \\ d + )[ ._ ]( \\ d + )", ĠTABLE T ), ĊĠĠĠ ĠOperating System Matcher (" Y Pad ", Ġ" i Pad [ \\ s \\ ; ]+ iPhone .* os Ġ( \\ d + )[ ._ ]( \\ d + )", ĠTABLE T ), ĊĠĠĠ ĠOperating System Matcher (" Y Phone ", Ġ" iPhone [ \\ s \\ ; ]+ iPhone .* os Ġ( \\ d + )[ ._ ]( \\ d + )", ĠPH ONE ), ĊĠĠĠ ĠOperating System Matcher (" S ymb ian ", Ġ" s ymb ian ( os )? ", ĠDES K TOP ), ĊĠĠĠ ĠOperating System Matcher (" Dar win ", Ġ" Dar win \\/ ([ \\ d \\ w \\. \\ - ]+ )", ĠDES K TOP ), ĊĠĠĠ ĠOperating System Matcher (" A dobe ĠAir ", Ġ" A dobe Air \\/ ([ \\ d \\ w \\. \\ - ]+ )", ĠDES K TOP ), ĊĠĠĠ ĠOperating System Matcher (" Java ", Ġ" Java [ \\ s ]+ ([ \\ d \\ w \\. \\ - ]+ )", ĠPRO GRAM ) ĊĠ Ġ) ĊĊĠ Ġfun Ġanalyze ( value : ĠString ): ĠOperating System Ġ= ĊĠĠĠ Ġmatch ers . first OrNull Ġ{ Ġit . match ( value ) Ġ} ?. let Ġ{ ĊĠĠĠĠĠ ĠOperating System ( it . type . toString (), Ġname Ġ= Ġit . name ) ĊĠĠĠ Ġ} Ġ?: ĠUNKNOWN _ OPER ATING _ SYSTEM Ċ } Ċ Ċ internal Ġobject ĠLayout Engine Analyzer Ġ{ ĊĊĠ Ġinternal Ġclass ĠLayout Engine Matcher ( ĊĠĠĠ Ġname : ĠString , ĊĠĠĠ Ġpattern : ĠString , ĊĠĠĠ Ġval Ġtype : ĠLayout Engine . Type ĊĠ Ġ) Ġ: ĠMatcher ( name , Ġpattern ) ĊĊĠ Ġprivate Ġval Ġmatch ers Ġ= ĠlistOf ( ĊĠĠĠ ĠLayout Engine Matcher (" Tr ident ", Ġ" tr ident ", ĠLayout Engine . Type . BROWSER ), ĊĠĠĠ ĠLayout Engine Matcher (" Web kit ", Ġ" webkit ", ĠLayout Engine . Type . BROWSER ), ĊĠĠĠ ĠLayout Engine Matcher (" Chrome ", Ġ" chrome ", ĠLayout Engine . Type . BROWSER ), ĊĠĠĠ ĠLayout Engine Matcher (" Oper a ", Ġ" oper a ", ĠLayout Engine . Type . BROWSER ), ĊĠĠĠ ĠLayout Engine Matcher (" Pre sto ", Ġ" pre sto ", ĠLayout Engine . Type . BROWSER ), ĊĠĠĠ ĠLayout Engine Matcher (" Ge cko ", Ġ" ge cko ", ĠLayout Engine . Type . BROWSER ), ĊĠĠĠ ĠLayout Engine Matcher (" KHTML ", Ġ" k html ", ĠLayout Engine . Type . BROWSER ), ĊĠĠĠ ĠLayout Engine Matcher (" Kon q er or ", Ġ" kon quer or ", ĠLayout Engine . Type . BROWSER ), ĊĠĠĠ ĠLayout Engine Matcher (" MID P ", Ġ" MID P ", ĠLayout Engine . Type . BROWSER ) ĊĠ Ġ) ĊĊĠ Ġfun Ġanalyze ( value : ĠString ): ĠLayout Engine Ġ= ĊĠĠĠ Ġmatch ers . first OrNull Ġ{ Ġit . match ( value ) Ġ} ?. let Ġ{ ĊĠĠĠĠĠ ĠLayout Engine ( it . type . toString (), Ġit . name ) ĊĠĠĠ Ġ} Ġ?: ĠUNKNOWN _ LAYOUT _ ENGINE Ċ } Ċ Ċ internal Ġobject ĠAgent Analyzer Ġ{ ĊĊĠ Ġinternal Ġclass ĠAgent Matcher ( ĊĠĠĠ Ġname : ĠString , ĊĠĠĠ Ġpattern : ĠString , ĊĠĠĠ Ġval Ġtype : ĠAgent . Type ĊĠ Ġ) Ġ: ĠMatcher ( name , Ġpattern ) ĊĊĠ Ġprivate Ġval Ġmatch ers Ġ= ĠlistOf ( ĊĠĠĠ ĠAgent Matcher (" M SE d ge ", Ġ" Edge ", ĠAgent . Type . BROWSER ), ĊĠĠĠ ĠAgent Matcher (" Chrome ", Ġ" chrome ", ĠAgent . Type . BROWSER ), ĊĠĠĠ ĠAgent Matcher (" Firefox ", Ġ" firefox ", ĠAgent . Type . BROWSER ), ĊĠĠĠ ĠAgent Matcher (" IE Mobile ", Ġ" iem obile ", ĠAgent . Type . BROWSER ), ĊĠĠĠ ĠAgent Matcher (" S afari ", Ġ" s afari ", ĠAgent . Type . BROWSER ), ĊĠĠĠ ĠAgent Matcher (" Oper a ", Ġ" oper a ", ĠAgent . Type . BROWSER ), ĊĠĠĠ ĠAgent Matcher (" Kon quer or ", Ġ" kon quer or ", ĠAgent . Type . BROWSER ), ĊĠĠĠ ĠAgent Matcher (" PS 3 ", Ġ" play station Ġ 3 ", ĠAgent . Type . SYSTEM ), ĊĠĠĠ ĠAgent Matcher (" P SP ", Ġ" play station Ġportable ", ĠAgent . Type . SYSTEM ), ĊĠĠĠ ĠAgent Matcher (" Lot us ", Ġ" lot us . notes ", ĠAgent . Type . EMAIL ), ĊĠĠĠ ĠAgent Matcher (" Th under bird ", Ġ" th under bird ", ĠAgent . Type . EMAIL ), ĊĠĠĠ ĠAgent Matcher (" Net scape ", Ġ" net scape ", ĠAgent . Type . BROWSER ), ĊĠĠĠ ĠAgent Matcher (" Se amon key ", Ġ" se amon key ", ĠAgent . Type . BROWSER ), ĊĠĠĠ ĠAgent Matcher (" Outlook ", Ġ" microsoft . outlook ", ĠAgent . Type . EMAIL ), ĊĠĠĠ ĠAgent Matcher (" MSI E ", Ġ" ms ie ", ĠAgent . Type . BROWSER ), ĊĠĠĠ ĠAgent Matcher (" MSI E 1 1 ", Ġ" rv : 1 1 ", ĠAgent . Type . BROWSER ), ĊĠĠĠ ĠAgent Matcher (" Y ammer ĠDesktop ", Ġ" A dobe Air ", ĠAgent . Type . APP ), ĊĠĠĠ ĠAgent Matcher (" Y ammer ĠMobile ", Ġ" Y ammer [ \\ s ]+ ([ \\ d \\ w \\. \\ - ]+ )", ĠAgent . Type . APP ), ĊĠĠĠ ĠAgent Matcher (" Apache ĠHTTP ĠClient ", Ġ" Apache \\\\ - HttpClient ", ĠAgent . Type . PROGRAM ), ĊĠĠĠ ĠAgent Matcher (" Black B erry ", Ġ" Black B erry ", ĠAgent . Type . SYSTEM ), ĊĠ Ġ) ĊĊĠ Ġfun Ġanalyze ( value : ĠString ): ĠAgent Ġ= ĊĠĠĠ Ġmatch ers . first OrNull Ġ{ Ġit . match ( value ) Ġ} ?. let Ġ{ ĊĠĠĠĠĠ ĠAgent ( it . type . toString (), Ġit . name ) ĊĠĠĠ Ġ} Ġ?: ĠUNKNOWN _ AGENT Ċ } Ċ