Advertisement
nerru86

List all browsers on iPhones using 51Degrees data file

Mar 20th, 2015
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.42 KB | None | 0 0
  1.     private static Provider p;
  2.     private static Property property;
  3.    
  4.     /**
  5.      * @param args the command line arguments
  6.      */
  7.     public static void main(String[] args) throws IOException {
  8.         //Initialise dataset, print basic info.
  9.         System.out.print("Initialising provider. ");
  10.         p = new Provider(StreamFactory.create("C:\\path\\to\\51Degrees.dat"));
  11.         System.out.println("Done.");
  12.         System.out.println("***** Data file info *****");
  13.         System.out.println("Data file: "+p.dataSet.getName());
  14.         System.out.println("Published: "+p.dataSet.published);
  15.         System.out.println("Proeprties: "+p.dataSet.getProperties().size());
  16.         System.out.println("**************************");
  17.         System.out.print("Initialising signatures. ");
  18.         //NEW: initialise signatures.
  19.         p.dataSet.initSignatureRanks();
  20.         System.out.print("Done");
  21.         System.out.println();
  22.        
  23.         //ArrayList stores the distinct browser names.
  24.         ArrayList<String> distinctBrowsers = new ArrayList<>();
  25.        
  26.         //Loop through all profiles in the Hardware components.
  27.         for (Profile pr : p.dataSet.getHardware().getProfiles()){
  28.             //Get values for the HardwareName property.
  29.             String val = pr.getValues("HardwareName").get(0).getName();
  30.            
  31.             //Indicates if this particular hardware name is iPhone.
  32.             if(val.equals("iPhone")) {
  33.                 //Add distinct related Profiles to the list.
  34.                 ArrayList<Profile> relatedProfiles = new ArrayList<>();
  35.                 for (Signature s : pr.Signatures()) {
  36.                     if (s.getRank() < 1000) {
  37.                         /*
  38.                         At this point we have found all signatures for the
  39.                         Hardware component with 'iPhone' Hardware name and rank
  40.                         of a 1000 or less (meaning most popular). This Profile
  41.                         is of interest to us, hence add to relatedProfiles list.
  42.                         */
  43.                         for (Profile p1 : s.getProfiles()) {
  44.                             if(!relatedProfiles.contains(p1))
  45.                                 relatedProfiles.add(p1);
  46.                         }
  47.                     }
  48.                 }
  49.                
  50.                 //Go through each profile in the relatedProfiles list to filter
  51.                 //by some variable.
  52.                 for (Profile p2 : relatedProfiles) {
  53.                     //For each BrowserUA Component of the related Profile:
  54.                     if(p2.getComponent().getName().equals("BrowserUA")) {
  55.                         //Get browser name
  56.                         String osName = p2.getValues("BrowserName").get(0).getName();
  57.                         //Get browser version.
  58.                         String osVersion = p2.getValues("BrowserVersion").get(0).getName();
  59.                        
  60.                         //Add unique browser name to the list to be dispalyed.
  61.                         if(!distinctBrowsers.contains(osName)) {
  62.                             distinctBrowsers.add(osName);
  63.                         }
  64.                     }
  65.                 }
  66.             }
  67.  
  68.         }
  69.         //Display the list of unique browser names found during program execution.
  70.         for (String s : distinctBrowsers) {
  71.              System.out.println(s);  
  72.         }
  73.         System.exit(0);
  74.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement