Class Dynasty


  • public class Dynasty
    extends java.lang.Object
    Class used to get and represent roman emperors' dynasties data.
    Author:
    Matteo Collica, Radu Ionut Barbalata
    See Also:
    DynastySerializer, DynastyTree
    • Constructor Summary

      Constructors 
      Constructor Description
      Dynasty​(java.lang.String dynastyPageUrl, java.lang.String dynastyName, org.openqa.selenium.WebDriver webDriver, boolean makeDynastyTree)
      Given a Web Driver and a dynasty's Wikipedia page URL, scrape its data and/to construct a Dynasty object
      Dynasty​(java.lang.String wikipediaPageUrl, org.json.simple.JSONObject serializedDynasty)
      Restore (and construct) a Dynasty from a JSONObject (its serialized form)
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void createDynastyTree​(org.openqa.selenium.WebDriver webDriver)
      Given a Web Driver, create (and set as field) the dynasty's DynastyTree object
      static boolean dynastyPageUrlEquals​(java.lang.String dynastyPageUrl, java.lang.String urlToBeChecked)
      Check if a given URL points to the same dynasty's Wikipedia page whose URL is given - this is preferable over a simple .equalsIgnoreCase() between the two strings because there are different URLs for the same dynasties
      java.lang.String getDepositionDate()  
      static java.util.HashMap<java.lang.String,​java.lang.String> getDynasties​(org.openqa.selenium.WebDriver webDriver)
      Scrape dynasty names and URLs from the roman emperors page (https://it.wikipedia.org/wiki/Imperatori_romani), translate names from Italian to English language and return them in form of an HashMap using the dynasties' Wikipedia page URL as key
      static java.lang.String getDynastyNameTranslation​(java.lang.String dynastyItalianName)
      Given a Dynasty's (scraped) italian name, translate and return it in English language
      DynastyTree getDynastyTree()  
      java.lang.String getFoundationDate()  
      PersonPageData getFounderPageData()  
      java.lang.String getName()  
      java.lang.String getPageTitle()  
      static java.util.HashMap<java.lang.String,​Dynasty> getStoredDynasties()  
      static java.lang.StringBuilder getStoredDynastiesNames()  
      static Dynasty getStoredDynastyByUrl​(java.lang.String dynastyPageUrl)
      Given a dynasty's Wikipedia page URL, return the corresponding Dynasty object
      java.lang.String getWikipediaPageUrl()  
      static java.util.ArrayList<java.lang.String> retrieveEmperorsNamesAndReignPeriods​(org.openqa.selenium.WebDriver webDriver)
      Given a driver loaded with a dynasty's Wikipedia page, get all the emperors' names and reign periods from the eligible h3 HTML elements
      static PersonNameUrl retrieveFounderNameUrl​(org.openqa.selenium.WebDriver webDriver)
      Given a driver loaded with a dynasty's Wikipedia page, retrieve the dynasty founder's name and Wikipedia page URL by iterating through elements of class 'vedi-anche' and picking the first link whose page is an emperor's one
      static void setStoredDynasties​(java.util.HashMap<java.lang.String,​Dynasty> storedDynasties)  
      static void storeDynasty​(java.lang.String dynastyPageUrl, Dynasty dynasty)
      Put a new Dynasty in the stored dynasties HashMap by its Wikipedia page URL
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • wikipediaPageUrl

        private final java.lang.String wikipediaPageUrl
      • pageTitle

        private final java.lang.String pageTitle
      • name

        private final java.lang.String name
      • foundationDate

        private final java.lang.String foundationDate
      • depositionDate

        private final java.lang.String depositionDate
      • storedDynasties

        private static java.util.HashMap<java.lang.String,​Dynasty> storedDynasties
      • dynastyNameTranslations

        private static java.util.HashMap<java.lang.String,​java.lang.String> dynastyNameTranslations
    • Constructor Detail

      • Dynasty

        public Dynasty​(java.lang.String dynastyPageUrl,
                       java.lang.String dynastyName,
                       org.openqa.selenium.WebDriver webDriver,
                       boolean makeDynastyTree)
        Given a Web Driver and a dynasty's Wikipedia page URL, scrape its data and/to construct a Dynasty object
        Parameters:
        dynastyPageUrl - the dynasty's Wikipedia page URL
        dynastyName - the dynasty's name
        webDriver - the Web Driver instance to be used to scrape data
        makeDynastyTree - whether the dynasty tree should be created or not
      • Dynasty

        public Dynasty​(java.lang.String wikipediaPageUrl,
                       org.json.simple.JSONObject serializedDynasty)
        Restore (and construct) a Dynasty from a JSONObject (its serialized form)
        Parameters:
        wikipediaPageUrl - the Wikipedia page URL of the dynasty
        serializedDynasty - the dynasty's serialized object
    • Method Detail

      • createDynastyTree

        public void createDynastyTree​(org.openqa.selenium.WebDriver webDriver)
        Given a Web Driver, create (and set as field) the dynasty's DynastyTree object
        Parameters:
        webDriver - the Web Driver instance to be used to scrape data
      • getDynasties

        public static java.util.HashMap<java.lang.String,​java.lang.String> getDynasties​(org.openqa.selenium.WebDriver webDriver)
        Scrape dynasty names and URLs from the roman emperors page (https://it.wikipedia.org/wiki/Imperatori_romani), translate names from Italian to English language and return them in form of an HashMap using the dynasties' Wikipedia page URL as key
        Parameters:
        webDriver - the WebDriver to be used to get the roman emperors page content and then search for dynasty names and URLs
        Returns:
        an HashMap of (dynasty Wikipedia page URL : dynasty english name) entries
      • getStoredDynastiesNames

        public static java.lang.StringBuilder getStoredDynastiesNames()
        Returns:
        All the stored dynasties' names in a dashed list form, e.g.:
        - Dinastia costantiniana
        - Dinastia giulio-claudia
        [...]
      • setStoredDynasties

        public static void setStoredDynasties​(java.util.HashMap<java.lang.String,​Dynasty> storedDynasties)
        Parameters:
        storedDynasties - the HashMap containing the dynasties to be stored by their Wikipedia page url
      • getStoredDynasties

        public static java.util.HashMap<java.lang.String,​Dynasty> getStoredDynasties()
        Returns:
        the HashMap containing the stored dynasties by their Wikipedia page URL
      • storeDynasty

        public static void storeDynasty​(java.lang.String dynastyPageUrl,
                                        Dynasty dynasty)
        Put a new Dynasty in the stored dynasties HashMap by its Wikipedia page URL
        Parameters:
        dynastyPageUrl - the dynasty's Wikipedia page URL
        dynasty - the dynasty's Dynasty object
      • getStoredDynastyByUrl

        public static Dynasty getStoredDynastyByUrl​(java.lang.String dynastyPageUrl)
        Given a dynasty's Wikipedia page URL, return the corresponding Dynasty object
        Parameters:
        dynastyPageUrl - the dynasty's Wikipedia page URL
        Returns:
        the dynasty's Dynasty object
      • dynastyPageUrlEquals

        public static boolean dynastyPageUrlEquals​(java.lang.String dynastyPageUrl,
                                                   java.lang.String urlToBeChecked)
        Check if a given URL points to the same dynasty's Wikipedia page whose URL is given - this is preferable over a simple .equalsIgnoreCase() between the two strings because there are different URLs for the same dynasties
        Parameters:
        dynastyPageUrl - the known dynasty's Wikipedia page URL
        urlToBeChecked - the URL to compare dynastyPageUrl against
        Returns:
        true if they point to the same dynasty's Wikipedia page, false otherwise
      • retrieveFounderNameUrl

        public static PersonNameUrl retrieveFounderNameUrl​(org.openqa.selenium.WebDriver webDriver)
        Given a driver loaded with a dynasty's Wikipedia page, retrieve the dynasty founder's name and Wikipedia page URL by iterating through elements of class 'vedi-anche' and picking the first link whose page is an emperor's one
        Parameters:
        webDriver - the Web Driver instance to be used to scrape data
        Returns:
        the dynasty founder's PersonNameUrl object
      • retrieveEmperorsNamesAndReignPeriods

        public static java.util.ArrayList<java.lang.String> retrieveEmperorsNamesAndReignPeriods​(org.openqa.selenium.WebDriver webDriver)
        Given a driver loaded with a dynasty's Wikipedia page, get all the emperors' names and reign periods from the eligible h3 HTML elements
        Parameters:
        webDriver - the Web Driver instance to be used to scrape data
        Returns:
        an array containing strings in 'Name (Reign Period)' format
      • getDynastyNameTranslation

        public static java.lang.String getDynastyNameTranslation​(java.lang.String dynastyItalianName)
        Given a Dynasty's (scraped) italian name, translate and return it in English language
        Parameters:
        dynastyItalianName - the italian dynasty name
        Returns:
        the given italian dynasty name's english translation
      • getWikipediaPageUrl

        public java.lang.String getWikipediaPageUrl()
        Returns:
        the dynasty's Wikipedia page URL
      • getPageTitle

        public java.lang.String getPageTitle()
        Returns:
        the dynasty's Wikipedia page title
      • getDynastyTree

        public DynastyTree getDynastyTree()
        Returns:
        the dynasty's DynastyTree object
      • getFoundationDate

        public java.lang.String getFoundationDate()
        Returns:
        the dynasty's foundation date in String format (e.g. '27 a.C.')
      • getDepositionDate

        public java.lang.String getDepositionDate()
        Returns:
        the dynasty's deposition date in String format (e.g. '68 d.C.')
      • getFounderPageData

        public PersonPageData getFounderPageData()
        Returns:
        the dynasty founder's PersonPageData object
      • getName

        public java.lang.String getName()
        Returns:
        the dynasty's name (already translated in English language)