Class AudioDatabase

java.lang.Object
yearreview.app.data.sources.audio.database.AudioDatabase
All Implemented Interfaces:
Iterable<ListeningEvent>

public class AudioDatabase extends Object implements Iterable<ListeningEvent>
Database that stores the events of the listening history and the data associated to these events.
Author:
ColdStone37
  • Field Details

    • events

      private final SortedSet<ListeningEvent> events
      Set of all events sorted by time.
    • dataMap

      private final Map<String,AudioData> dataMap
      Map that stores the data with an associated key for fast access. Data of different Types is stored alongside each other and is differentiated by putting the name of the type in front.
  • Constructor Details

    • AudioDatabase

      public AudioDatabase()
      Constructs a Database by initializing the internal Datastructures.
  • Method Details

    • getDataById

      public AudioData getDataById(AudioData.Type type, String name)
      Gets AudioData inside the Database by type and name.
      Parameters:
      type - type of data to get
      name - name of data to get
      Returns:
      AudioData if the value exists otherwise null
    • getFilteredData

      public List<AudioData> getFilteredData(AudioData.Type type)
      Gets a List of AudioData that is filtered by the AudioData.Type of data.
      Parameters:
      type - type to filter by
      Returns:
      filtered data
    • hasData

      public boolean hasData(AudioData.Type type, String name)
      Tests whether certain data is stored in the database.
      Parameters:
      type - type of data to test for
      name - name of data to test for
      Returns:
      true if the database contains the data, false otherwise
    • insertEvent

      public void insertEvent(ListeningEvent event)
      Inserts an event into the database.
      Parameters:
      event - event to insert
    • getData

      public AudioData getData(String name, AudioData.Type type)
      Gets AudioData from the database. If the data does not exist it will be created and inserted.
      Parameters:
      name - name of data to get
      type - type of data to get
      Returns:
      requested data
    • getPiece

      public AudioPiece getPiece(String name, List<AudioData> data, AudioData.Type type)
      Gets AudioPiece from the database. If the piece does not exist it will be created and inserted
      Parameters:
      name - name of piece to get
      data - associated data of the piece
      type - type of data to get (must be a piece)
      Returns:
      requested piece
    • getEventCount

      public int getEventCount()
      Gets the amount of events stored in the database.
      Returns:
      amount of events
    • getDataCount

      public int getDataCount()
      Gets the amount of AudioData-elements stored in this database.
      Returns:
      amount of AudioData-elements
    • iterator

      public Iterator<ListeningEvent> iterator()
      Needed to implement the Iterable-interface.
      Specified by:
      iterator in interface Iterable<ListeningEvent>
      Returns:
      iterator for the events stored in the database