Class ResultsList


  • public class ResultsList
    extends Object
    Class for representing and maintaining a list of result records for a set of students.
    Author:
    Herbert Praehofer
    • Field Detail

      • resultsList

        private FList<Results> resultsList
        The list of results for a set of students
    • Constructor Detail

      • ResultsList

        public ResultsList()
        Constructor initializing the list of results with an empty list.
    • Method Detail

      • addStudent

        public void addStudent​(String id,
                               String name)
        Adds a student to the list.
        Parameters:
        id - the id of the student
        name - the name of the student
      • setScore

        public void setScore​(String id,
                             int assignment,
                             int score)
        Sets the score for a student for an assignment.
        Parameters:
        id - the id of the student
        assignment - the assignment number
        score - the score
      • setScores

        public void setScores​(String id,
                              int... scores)
        Sets the scores for a student.
        Parameters:
        id - the id of the student
        scores - the scores for the assignments
      • getScores

        public int[] getScores​(String id)
        Gets the scores of a student.
        Parameters:
        id - the id of the student
        Returns:
        the array with the scores
      • getResults

        public Results getResults​(String id)
        Gets the result object for a student.
        Parameters:
        id - the id of the student
        Returns:
        the result object
      • setGradingFunction

        public void setGradingFunction​(Function<Results,​Grade> gradingFn)
        Sets the function object to compute the grades.
        Parameters:
        gradingFn - the function object to compute the grades
      • getGrade

        public Grade getGrade​(String id)
        Gets the grade for a student computed from the assignment scores.
        Parameters:
        id - the student id
        Returns:
        the grade for the student.
      • countScores

        public int countScores​(String id,
                               IntPredicate scorePred)
        Counts the scores of a student fulfilling a given predicate.
        Parameters:
        id - the student id
        scorePred - the predicate
        Returns:
        the number of scores fulfilling the predicate
      • compute

        public <A,​R> R compute​(String id,
                                     A start,
                                     BiFunction<? super A,​Integer,​? extends A> accumulator,
                                     Function<? super A,​? extends R> finalizer)
        Computes a result from the scores for a student. Uses an accumulator and a finalizer function.
        Type Parameters:
        A - the type of the start and accumulated value
        R - the type of the result
        Parameters:
        id - the student id
        start - the start value
        accumulator - the accumulator function
        finalizer - the finalizer function
        Returns:
        the computation result
      • count

        public int count​(Predicate<Results> pred)
        Counts the results fulfilling a given predicate.
        Parameters:
        pred - the predicate to test
        Returns:
        the number of student results fulfilling the predicate
      • compute

        public <A,​R> R compute​(A start,
                                     BiFunction<? super A,​Results,​? extends A> accumulator,
                                     Function<? super A,​? extends R> finalizer)
        Makes a computation on the student result records. Uses a accumulator and a finalizer function.
        Type Parameters:
        A - the type of the start and accumulated value
        R - the type of the result
        Parameters:
        start - the start value
        accumulator - the accumulator function
        finalizer - the finalizer function
        Returns:
        the computation result