Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static Provider p;
- private static Property property;
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) throws IOException {
- //Initialise dataset, print basic info.
- System.out.print("Initialising provider. ");
- p = new Provider(StreamFactory.create("C:\\path\\to\\51Degrees.dat"));
- System.out.println("Done.");
- System.out.println("***** Data file info *****");
- System.out.println("Data file: "+p.dataSet.getName());
- System.out.println("Published: "+p.dataSet.published);
- System.out.println("Proeprties: "+p.dataSet.getProperties().size());
- System.out.println("**************************");
- System.out.print("Initialising signatures. ");
- //NEW: initialise signatures.
- p.dataSet.initSignatureRanks();
- System.out.print("Done");
- System.out.println();
- //ArrayList stores the distinct browser names.
- ArrayList<String> distinctBrowsers = new ArrayList<>();
- //Loop through all profiles in the Hardware components.
- for (Profile pr : p.dataSet.getHardware().getProfiles()){
- //Get values for the HardwareName property.
- String val = pr.getValues("HardwareName").get(0).getName();
- //Indicates if this particular hardware name is iPhone.
- if(val.equals("iPhone")) {
- //Add distinct related Profiles to the list.
- ArrayList<Profile> relatedProfiles = new ArrayList<>();
- for (Signature s : pr.Signatures()) {
- if (s.getRank() < 1000) {
- /*
- At this point we have found all signatures for the
- Hardware component with 'iPhone' Hardware name and rank
- of a 1000 or less (meaning most popular). This Profile
- is of interest to us, hence add to relatedProfiles list.
- */
- for (Profile p1 : s.getProfiles()) {
- if(!relatedProfiles.contains(p1))
- relatedProfiles.add(p1);
- }
- }
- }
- //Go through each profile in the relatedProfiles list to filter
- //by some variable.
- for (Profile p2 : relatedProfiles) {
- //For each BrowserUA Component of the related Profile:
- if(p2.getComponent().getName().equals("BrowserUA")) {
- //Get browser name
- String osName = p2.getValues("BrowserName").get(0).getName();
- //Get browser version.
- String osVersion = p2.getValues("BrowserVersion").get(0).getName();
- //Add unique browser name to the list to be dispalyed.
- if(!distinctBrowsers.contains(osName)) {
- distinctBrowsers.add(osName);
- }
- }
- }
- }
- }
- //Display the list of unique browser names found during program execution.
- for (String s : distinctBrowsers) {
- System.out.println(s);
- }
- System.exit(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement