Package at.jku.ssw.fp.sect04_2.fp
Class ResultsList
- java.lang.Object
-
- at.jku.ssw.fp.sect04_2.fp.ResultsList
-
public class ResultsList extends Object
Class for representing and maintaining a list of result records for a set of students.- Author:
- Herbert Praehofer
-
-
Constructor Summary
Constructors Constructor Description ResultsList()
Constructor initializing the list of results with an empty list.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addStudent(String id, String name)
Adds a student to the list.<A,R>
Rcompute(A start, BiFunction<? super A,Results,? extends A> accumulator, Function<? super A,? extends R> finalizer)
Makes a computation on the student result records.<A,R>
Rcompute(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.int
count(Predicate<Results> pred)
Counts the results fulfilling a given predicate.int
countScores(String id, IntPredicate scorePred)
Counts the scores of a student fulfilling a given predicate.Grade
getGrade(String id)
Gets the grade for a student computed from the assignment scores.Results
getResults(String id)
Gets the result object for a student.int[]
getScores(String id)
Gets the scores of a student.void
setGradingFunction(Function<Results,Grade> gradingFn)
Sets the function object to compute the grades.void
setScore(String id, int assignment, int score)
Sets the score for a student for an assignment.void
setScores(String id, int... scores)
Sets the scores for a student.
-
-
-
Method Detail
-
addStudent
public void addStudent(String id, String name)
Adds a student to the list.- Parameters:
id
- the id of the studentname
- 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 studentassignment
- the assignment numberscore
- the score
-
setScores
public void setScores(String id, int... scores)
Sets the scores for a student.- Parameters:
id
- the id of the studentscores
- 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 idscorePred
- 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 valueR
- the type of the result- Parameters:
id
- the student idstart
- the start valueaccumulator
- the accumulator functionfinalizer
- 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 valueR
- the type of the result- Parameters:
start
- the start valueaccumulator
- the accumulator functionfinalizer
- the finalizer function- Returns:
- the computation result
-
-