Class TempTag

java.lang.Object
com.ubs.backend.classes.TempTag

public class TempTag extends Object
Tag used for temporary saving a tag and building JSON objects.
Since:
17.07.2021
Author:
Tim Irmler
  • Field Details

    • tag

      private Tag tag
      The tag
      Since:
      17.07.2021
      See Also:
      Tag
    • upvotes

      private int upvotes
      Amount of upvotes this tag in this context has received
      Since:
      17.07.2021
    • downvotes

      private int downvotes
      Amount of downvotes this tag in this context has received
      Since:
      17.07.2021
    • tagUsages

      private int tagUsages
      how often the tag has been used
      Since:
      17.07.2021
    • amountAnswers

      private int amountAnswers
      amount of answers using this tag
      Since:
      17.07.2021
    • singleAnswerID

      private long singleAnswerID
      the answer this specific tag belongs to in a result set
      Since:
      17.07.2021
      See Also:
      TempAnswer
    • allAnswers

      private ArrayList<TempAnswer> allAnswers
      All Answers that use this tag
      Since:
      17.07.2021
      See Also:
      TempAnswer
  • Constructor Details

    • TempTag

      public TempTag()
      default constructor
    • TempTag

      public TempTag(Tag tag, long singleAnswerID, int upvotes, int downvotes, int tagUsages)
      used when we need to figure out to what specific result and answer this tag belongs to
      Parameters:
      tag - the default tag we want to save
      singleAnswerID - the id of the answer in the db to which this tag belongs to
      upvotes - the amount of upvotes this tag has in the db in this result set
      downvotes - the amount of downvotes this tag has in the db in this result set
      tagUsages - how often this tag has been used with this answer
      Since:
      17.07.2021
    • TempTag

      public TempTag(Tag tag)
      save tag but only with its id and its name.
      Parameters:
      tag - the tag we want to save
      Since:
      17.07.2021
  • Method Details

    • increaseAllValues

      public void increaseAllValues(TempTag tag)
      Parameters:
      tag - the TempTag from where we take its values and increase ours by
      Since:
      17.07.2021
    • getTag

      public Tag getTag()
      Returns:
      the tag of this instance
      Since:
      17.07.2021
    • setTag

      public void setTag(Tag tag)
      Parameters:
      tag - the tag to set
      Since:
      17.07.2021
    • getSingleAnswerID

      public long getSingleAnswerID()
      Returns:
      the ID of the Answer
      Since:
      17.07.2021
    • setSingleAnswerID

      public void setSingleAnswerID(long singleAnswerID)
      Parameters:
      singleAnswerID - the ID of the new Answer
      Since:
      17.07.2021
    • getAllAnswers

      public ArrayList<TempAnswer> getAllAnswers()
      Returns:
      a List of all Answers
      Since:
      17.07.2021
    • setAllAnswers

      public void setAllAnswers(ArrayList<TempAnswer> allAnswers)
      Parameters:
      allAnswers - the new List of Answers
      Since:
      17.07.2021
    • setAllAnswers

      public void setAllAnswers(List<Answer> answers)
      Parameters:
      answers - all
      Since:
      28.07.2021
    • addAnswers

      public void addAnswers(ArrayList<TempAnswer> answers)
      adds the given TempAnswers to this instance
      Parameters:
      answers - a list of all the TempAnswers
      Since:
      28.07.2021
    • addAnswersWithUsefulness

      public void addAnswersWithUsefulness(ArrayList<TempAnswer> tempAnswers, AnswerDAO answerDAO, javax.persistence.EntityManager em)
      calculates the average usefulness of every given answer and adds it to this instance
      Parameters:
      tempAnswers - every TempAnswer that we want to add and calculate the usefulness from
      answerDAO - the answerDAO to access the DB
      em - the entity manager
      Since:
      28.07.2021
    • getTempAnswersFromAnswers

      public ArrayList<TempAnswer> getTempAnswersFromAnswers(List<Answer> answers)
      Parameters:
      answers - the Answers of which TempAnswers should be created from
      Returns:
      a list of the newly created TempAnswers
      Since:
      28.07.2021
    • getUsefulness

      public float getUsefulness(TempAnswer tempAnswer, AnswerDAO answerDAO, javax.persistence.EntityManager em)
      method to calculate the average usefulness of an answer by accessing the DB
      Parameters:
      tempAnswer - the tempAnswer to get the usefulness from
      answerDAO - the DB access object to get the information from the DB
      em - the entity manager
      Returns:
      the average usefulness of the answer as a floating point number
      Since:
      28.07.2021
      See Also:
      AnswerDAO.getAverageUsefulness(long, EntityManager)
    • getUpvotes

      public int getUpvotes()
      Returns:
      the amount of Upvotes
      Since:
      17.07.2021
    • setUpvotes

      public void setUpvotes(int upvotes)
      Parameters:
      upvotes - the new Amount of upvotes
      Since:
      17.07.2021
    • increaseUpvotes

      public void increaseUpvotes(int value)
      Parameters:
      value - the value by which the upvotes should be increased
      Since:
      17.07.2021
    • getDownvotes

      public int getDownvotes()
      Returns:
      the amount of Downvotes
      Since:
      17.07.2021
    • setDownvotes

      public void setDownvotes(int downvotes)
      Parameters:
      downvotes - the new amount of Downvotes
      Since:
      17.07.2021
    • increaseDownvotes

      public void increaseDownvotes(int value)
      Parameters:
      value - the value by which the amount of Downvotes should be increased
      Since:
      17.07.2021
    • getTagUsages

      public int getTagUsages()
      Returns:
      the amount of TagUsages
      Since:
      17.07.2021
    • setTagUsages

      public void setTagUsages(int tagUsages)
      Parameters:
      tagUsages - how often this tag has been used
      Since:
      17.07.2021
    • increaseTagUsages

      public void increaseTagUsages(int value)
      Parameters:
      value - the value the Tag Usages should be increased by
      Since:
      17.07.2021
    • getAmountAnswers

      public int getAmountAnswers()
      Returns:
      the amount of Answers this TempTag has
      Since:
      17.07.2021
    • setAmountAnswers

      public void setAmountAnswers(int amountAnswers)
      Parameters:
      amountAnswers - the amount of answers
      Since:
      17.07.2021
    • increaseAmountAnswers

      public void increaseAmountAnswers(int value)
      Parameters:
      value - the value the AmountAnswers should be increased by
      Since:
      17.07.2021
    • toString

      public String toString()
      Overrides:
      toString in class Object