private static void examineDeviceCategory ( final UserAgent . Builder builder , final Data data ) { // a robot will be classified as 'Other' if ( UserAgentType . ROBOT == builder . getType ( ) ) { final DeviceCategory category = findDeviceCategoryByValue ( Category . OTHER , data ) ; builder . setDeviceCategory ( category ) ; return ; } // classification depends on matching order for ( final Entry < DevicePattern , Device > entry : data . getPatternToDeviceMap ( ) . entrySet ( ) ) { final Matcher matcher = entry . getKey ( ) . getPattern ( ) . matcher ( builder . getUserAgentString ( ) ) ; if ( matcher . find ( ) ) { final Category category = Category . evaluate ( entry . getValue ( ) . getName ( ) ) ; final DeviceCategory deviceCategory = findDeviceCategoryByValue ( category , data ) ; builder . setDeviceCategory ( deviceCategory ) ; return ; } } // an unknown user agent type should lead to an unknown device if ( UserAgentType . UNKNOWN == builder . getType ( ) ) { builder . setDeviceCategory ( DeviceCategory . EMPTY ) ; return ; } // if no pattern is available but the type is Other, Library, Validator or UA Anonymizer // than classify it as 'Other' if ( UserAgentType . OTHER == builder . getType ( ) || UserAgentType . LIBRARY == builder . getType ( ) || UserAgentType . VALIDATOR == builder . getType ( ) || UserAgentType . USERAGENT_ANONYMIZER == builder . getType ( ) ) { final DeviceCategory category = findDeviceCategoryByValue ( Category . OTHER , data ) ; builder . setDeviceCategory ( category ) ; return ; } // if no pattern is available but the type is a mobile or WAP browser than classify it as 'Smartphone' if ( UserAgentType . MOBILE_BROWSER == builder . getType ( ) || UserAgentType . WAP_BROWSER == builder . getType ( ) ) { final DeviceCategory category = findDeviceCategoryByValue ( Category . SMARTPHONE , data ) ; builder . setDeviceCategory ( category ) ; return ; } final DeviceCategory category = findDeviceCategoryByValue ( Category . PERSONAL_COMPUTER , data ) ; builder . setDeviceCategory ( category ) ; }
Examines the user agent string whether has a specific device category .