Package app

Class MediaCommunicator

java.lang.Object
app.MediaCommunicator

public class MediaCommunicator extends Object
Main facade class.

Users of this class can submit the creation/modification/deletion of Media entities as well as request that changes be saved to whatever MediaStorage implementation is used.

The MediaCommunicator provides a central API for modifying Media and allows listening for changes made using its API via the MediaObserver interface.

  • Constructor Details

    • MediaCommunicator

      public MediaCommunicator(MediaStorage storage)
      Instantiate a MediaCommunicator with the given storage backend.
  • Method Details

    • addObserver

      public void addObserver(MediaObserver o)
      Add a MediaObserver to this MediaCommunicator. The added MediaObserver will be notified whenever Media is added/modified/removed via this MediaCommunicator.
    • removeObserver

      public void removeObserver(MediaObserver o)
      Remove a MediaObserver from this MediaCommunicator. The removed MediaObserver will no longer be notified of any changes to Media made via this MediaCommunicator.
    • updateMedia

      public void updateMedia(Media media, Consumer<Long> idCallback) throws Exception
      Update (or add, if it doesn't already exist) the given Media object.

      If the given Media does not yet have an assigned ID, an ID will be generated and the method passed as `idCallback` will be called with the generated ID as its argument before any MediaObservers are notified of the new Media.

      Throws:
      Exception
    • updateMedia

      public void updateMedia(Media media) throws Exception
      Update (or add, if it doesn't already exist) the given Media object.
      Throws:
      Exception
    • deleteMedia

      public void deleteMedia(long id)
      Remove the Media object with the given name.
    • getIDsWithin

      public Set<Long> getIDsWithin(double x, double y, double w, double h) throws Exception
      Return a set containing at least the IDs of all the Media objects within the rectangular region with top left corner at (`x`, `y`) and with width `w` and height `h`.
      Throws:
      Exception
    • getMedia

      public Media getMedia(long id) throws Exception
      Return the Media object with the given ID.
      Throws:
      Exception
    • save

      public void save() throws Exception
      Save changes to storage.
      Throws:
      Exception