Hi all, thanks in advance for any advice...My problem is that I am not sure that my code here is sufficient and/or the best possible design for what I am trying to do. The scenario is that I have a database storing project information, which I am pulling projects from and then calculating the amount of likes and views said project has received. So, at the end of each day I would like to be able to call a method that will decrement the "score" of these projects, as well as return the sorted list to be displayed. The purpose of the decay is so that over time if a project loses popularity its score will slowly decrease, instead of allowing it to hold its high score forever even though it hasn't been liked or viewed in the recent past. Here is my code, let me know what you think!
The controller class:
public class Project implements Comparable
{
private int likes;
private int views;
private double score;
public double calcCurrentScore(){
score = this.views + (this.likes * 10);
return score;
}
public double decrementScore(){
score = calcCurrentScore()*.9;
return score;
}
public int compareTo(Object o){
calcCurrentScore();
decrementScore();
double temp1 = this.score;
double temp2 = ((Project) o).score;
if(temp1>temp2){
return 1;
} else if(temp2>temp1){
return -1;
} else {
return 0;
}
}
The controller class:
public class ProjectController {
// Would be the class that holds methods for querying database
//@Inject
// ProjectService projectService;
/* A script in the database will call this method every day at the end
* of the day in order to return the list after its decayed
*/
public List<Project> getSortedProjectList(){
// Would be from the class that holds methods for querying database
List<Project> list = projectService.getProjects();
Collections.sort(list);
return list;
}
}