VersionParser { static VersionNumber identifyWebOSVersion(final String userAgent) { VersionNumber version = VersionNumber.UNKNOWN; final List<Pattern> patterns = new ArrayList<Pattern>(); patterns.add(Pattern.compile("hpwOS/((\\d+)((\\.\\d+)+)?);")); patterns.add(Pattern.compile("webOS/((\\d+)((\\.\\d+)+)?);")); for (final Pattern pattern : patterns) { final Matcher m = pattern.matcher(userAgent); if (m.find()) { version = parseFirstVersionNumber(m.group(MAJOR_INDEX)); break; } } return version; } private  VersionParser(); static VersionNumber parseLastVersionNumber(@Nonnull final String text); static VersionNumber parseOperatingSystemVersion(@Nonnull final OperatingSystemFamily family, @Nonnull final String userAgent); static VersionNumber parseVersion(@Nonnull final String version);  }
@Test public void identifyWebOSVersion() { final String hpwos305 = "Mozilla/5.0 (hp-tablet; Linux; hpwOS/3.0.5; U; en-US) AppleWebKit/534.6 (KHTML, like Gecko) wOSBrowser/234.83 Safari/534.6 TouchPad/1.0"; assertThat(VersionParser.identifyWebOSVersion(hpwos305).toVersionString()).isEqualTo("3.0.5"); final String webos10 = "Mozilla/5.0 (webOS/1.0; U; en-US) AppleWebKit/525.27.1 (KHTML, like Gecko) Version/1.0 Safari/525.27.1 Pre/1.0"; assertThat(VersionParser.identifyWebOSVersion(webos10).toVersionString()).isEqualTo("1.0"); final String webos201 = "Mozilla/5.0 (webOS/2.0.1; U; en-GB)(iPhone; U; en) AppleWebKit/532.2 Version/1.0 Safari/532.2 Pre/1.2 -CET"; assertThat(VersionParser.identifyWebOSVersion(webos201).toVersionString()).isEqualTo("2.0.1"); }