Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
$Id: Assignment.java 105077 2012-02-24 22:54:29Z ottenhoff@longsight.com $ Copyright (c) 2005, 2006, 2007, 2008 The Sakai Foundation, The MIT Corporation Licensed under the Educational Community License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.opensource.org/licenses/ECL-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. /
 
 
 package org.sakaiproject.tool.gradebook;
 
 import java.util.Date;
 
An Assignment is the basic unit that composes a gradebook. It represents a single unit that, when aggregated in a gradebook, can be used as the denomenator in calculating a CourseGradeRecord.

Author(s):
Josh Holtzman
 
 public class Assignment extends GradableObject {
 
     public static String SORT_BY_DATE = "dueDate";
     public static String SORT_BY_NAME = "name";
     public static String SORT_BY_MEAN = "mean";
     public static String SORT_BY_POINTS = "pointsPossible";
     public static String SORT_BY_RELEASED ="released";
     public static String SORT_BY_COUNTED = "counted";
     public static String SORT_BY_EDITOR = "gradeEditor";
     public static String SORT_BY_SORTING = "sorting";
     public static String DEFAULT_SORT = ;
     
     public static String item_type_points = "Points";
     public static String item_type_percentage = "Percentage";
     public static String item_type_letter = "Letter Grade";
     public static String item_type_nonCalc = "Non-calculating";
     public static String item_type_adjustment = "Adjustment";
 
     public static Comparator dateComparator;
     public static Comparator nameComparator;
     public static Comparator pointsComparator;
     public static Comparator meanComparator;
     public static Comparator releasedComparator;
     public static Comparator countedComparator;
     public static Comparator gradeEditorComparator;
 
     private Double pointsPossible;
     private Date dueDate;
     private boolean notCounted;
     private boolean externallyMaintained;
     private String externalStudentLink;
     private String externalInstructorLink;
     private String externalId;
     private String externalAppName;
     private boolean released;
     private Category category;
     private Double averageTotal;
     private boolean ungraded;
     private Boolean extraCredit = .;
 	private String itemType;
 	private boolean hideInAllGradesTable = false;
 
 	static {
          = new Comparator() {
             public int compare(Object o1Object o2) {
                 if(.isDebugEnabled()) .debug("Comparing assignment + " + o1 + " to " + o2 + " by date");
                 Assignment one = (Assignment)o1;
                 Assignment two = (Assignment)o2;
 
                 // Sort by name if no date on either
                 if(one.getDueDate() == null && two.getDueDate() == null) {
                     return one.getName().toLowerCase().compareTo(two.getName().toLowerCase());
                 }
                 // Null dates are last
                 if(one.getDueDate() == null) {
                     return 1;
                 }
                 if(two.getDueDate() == null) {
                    return -1;
                }
                // Sort by name if both assignments have the same date
                int comp = (one.getDueDate().compareTo(two.getDueDate()));
                if(comp == 0) {
                    return one.getName().toLowerCase().compareTo(two.getName().toLowerCase());
                } else {
                    return comp;
                }
            }
            @Override
            public String toString() {
                return "Assignment.dateComparator";
            }
        };
         = new Comparator() {
			public int compare(Object o1Object o2) {
                Assignment one = (Assignment)o1;
                Assignment two = (Assignment)o2;
                return one.getName().toLowerCase().compareTo(two.getName().toLowerCase());
			}
            @Override
            public String toString() {
                return "Assignment.nameComparator";
            }
        };
         = new Comparator() {
            public int compare(Object o1Object o2) {
                if(.isDebugEnabled()) .debug("Comparing assignment + " + o1 + " to " + o2 + " by points");
                Assignment one = (Assignment)o1;
                Assignment two = (Assignment)o2;
                int comp = one.getPointsPossible().compareTo(two.getPointsPossible());
                if(comp == 0) {
                    return one.getName().toLowerCase().compareTo(two.getName().toLowerCase());
                } else {
                    return comp;
                }
            }
            @Override
            public String toString() {
                return "Assignment.pointsComparator";
            }
        };
         = new Comparator() {
            public int compare(Object o1Object o2) {
                if(.isDebugEnabled()) .debug("Comparing assignment + " + o1 + " to " + o2 + " by mean");
                Assignment one = (Assignment)o1;
                Assignment two = (Assignment)o2;
                Double mean1 = one.getMean();
                Double mean2 = two.getMean();
                if(mean1 == null && mean2 == null) {
                    return one.getName().toLowerCase().compareTo(two.getName().toLowerCase());
                }
                if(mean1 != null && mean2 == null) {
                    return 1;
                }
                if(mean1 == null && mean2 != null) {
                    return -1;
                }
                int comp = mean1.compareTo(mean2);
                if(comp == 0) {
                    return one.getName().toLowerCase().compareTo(two.getName().toLowerCase());
                } else {
                    return comp;
                }
            }
            @Override
            public String toString() {
                return "Assignment.meanComparator";
            }
        };
         = new Comparator() {
            public int compare(Object o1Object o2) {
                if(.isDebugEnabled()) .debug("Comparing assignment + " + o1 + " to " + o2 + " by release");
                Assignment one = (Assignment)o1;
                Assignment two = (Assignment)o2;
                int comp = String.valueOf(one.isReleased()).compareTo(String.valueOf(two.isReleased()));
                if(comp == 0) {
                    return one.getName().compareTo(two.getName());
                } else {
                    return comp;
                }
            }
            @Override
            public String toString() {
                return "Assignment.releasedComparator";
            }
        };
        
         = new Comparator() {
            public int compare(Object o1Object o2) {
                if(.isDebugEnabled()) .debug("Comparing assignment + " + o1 + " to " + o2 + " by counted");
                Assignment one = (Assignment)o1;
                Assignment two = (Assignment)o2;
                int comp = String.valueOf(one.isCounted()).compareTo(String.valueOf(two.isCounted()));
                if(comp == 0) {
                    return one.getName().compareTo(two.getName());
                } else {
                    return comp;
                }
            }
            @Override
            public String toString() {
                return "Assignment.countedComparator";
            }
        };
        
         = new Comparator() {
            public int compare(Object o1Object o2) {
                if(.isDebugEnabled()) .debug("Comparing assignment + " + o1 + " to " + o2 + " by grade editor");
                Assignment one = (Assignment)o1;
                Assignment two = (Assignment)o2;
                int comp = String.valueOf(one.getExternalAppName()).compareTo(String.valueOf(two.getExternalAppName()));
                if(comp == 0) {
                    return one.getName().compareTo(two.getName());
                } else {
                    return comp;
                }
            }
            @Override
            public String toString() {
                return "Assignment.gradeEditorComparator";
            }
        };
    }
    public Assignment(Gradebook gradebookString nameDouble pointsPossibleDate dueDate) {
        this. = gradebook;
        this. = name;
        this. = pointsPossible;
        this. = dueDate;
        this. = true;
        this. = .;
        this. = false;
    }


    
constructor to support selective release

Parameters:
gradebook
name
pointsPossible
dueDate
released
    public Assignment(Gradebook gradebookString nameDouble pointsPossibleDate dueDateboolean released) {
        this. = gradebook;
        this. = name;
        this. = pointsPossible;
        this. = dueDate;
        this. = released;
        this. = .;
        this. = false;
    }
    public Assignment() {
    	super();
    	this. = .;
        this. = false;
    }

    public boolean isCourseGrade() {
        return false;
    }
    
    public boolean isAssignment() {
        return true;
    }
    
    public boolean getIsCategory() {
        return false;
    }

	public Date getDateForDisplay() {
        return ;
	}

Returns:
Returns the dueDate.
	public Date getDueDate() {
		return ;
	}

Parameters:
dueDate The dueDate to set.
	public void setDueDate(Date dueDate) {
		this. = dueDate;
	}
	public boolean isNotCounted() {
		return ;
	}
	public void setNotCounted(boolean notCounted) {
		this. = notCounted;
	}
	public boolean isCounted() {
		return !isNotCounted();
	}
This cover is for the benefit of JSF checkboxes.
	public void setCounted(boolean counted) {
		setNotCounted(!counted);
	}

Returns:
Returns the externalInstructorLink.
	}

Parameters:
externalInstructorLink The externalInstructorLink to set.
	public void setExternalInstructorLink(String externalInstructorLink) {
		this. = externalInstructorLink;
	}

Returns:
Returns the externallyMaintained.
	public boolean isExternallyMaintained() {
	}

Parameters:
externallyMaintained The externallyMaintained to set.
	public void setExternallyMaintained(boolean externallyMaintained) {
		this. = externallyMaintained;
	}

Returns:
Returns the externalStudentLink.
	}

Parameters:
externalStudentLink The externalStudentLink to set.
	public void setExternalStudentLink(String externalStudentLink) {
		this. = externalStudentLink;
	}

Returns:
Returns the pointsPossible.
	}

Parameters:
pointsPossible The pointsPossible to set.
	public void setPointsPossible(Double pointsPossible) {
		this. = pointsPossible;
	}

Returns:
Returns the externalId.
	public String getExternalId() {
		return ;
	}

Parameters:
externalId The externalId to set.
	public void setExternalId(String externalId) {
		this. = externalId;
	}

Returns:
Returns the externalAppName.
	}

Parameters:
externalAppName The externalAppName to set.
	public void setExternalAppName(String externalAppName) {
		this. = externalAppName;
	}


    

Returns:
selective release true or false
    public boolean isReleased() {
        return ;
    }

    

Parameters:
released returns wther the assignment has been released to users
    public void setReleased(boolean released) {
        this. = released;
    }

    
Calculate the mean score for students with entered grades.
    public void calculateStatistics(Collection<AssignmentGradeRecordgradeRecords) {
        int numScored = 0;
        BigDecimal total = new BigDecimal("0");
        BigDecimal pointsTotal = new BigDecimal("0");
        for (AssignmentGradeRecord record : gradeRecords) {
            // Skip grade records that don't apply to this gradable object
            if(!record.getGradableObject().equals(this)) {
                continue;
            }
            if(record.getDroppedFromGrade() == null) {
                throw new RuntimeException("record.droppedFromGrade cannot be null");
            }
            Double score = null;
            if(! &&  > 0)
            	score = record.getGradeAsPercentage();
            Double points = record.getPointsEarned();
            if (score == null && points == null || record.getDroppedFromGrade()) {
            	continue;
            }
            else if (score == null)
            {
            	pointsTotal = pointsTotal.add(new BigDecimal(points.toString()));
            	numScored++;
            }
            else 
            {
            	total = total.add(new BigDecimal(score.toString()));
            	pointsTotal = pointsTotal.add(new BigDecimal(points.toString()));
            	numScored++;
            }
        }
        if (numScored == 0) {
        	 = null;
        	 = null;
        } else {
        	BigDecimal bdNumScored = new BigDecimal(numScored);
        	if(! &&  > 0)
        	{
        		 = Double.valueOf(total.divide(bdNumScored.).doubleValue());
        	}
        	else
        	{
        		 = null;
        	}
        	 = Double.valueOf(pointsTotal.divide(bdNumScored.).doubleValue());
        }
    }
		{
			return ;
		}
		public void setCategory(Category category)
		{
			this. = category;
		}
		{
			return ;
		}
		public void setAverageTotal(Double averageTotal)
		{
			this. = averageTotal;
		}
		public boolean getUngraded()
		{
			return ;
		}
		public void setUngraded(boolean ungraded)
		{
			this. = ungraded;
		}
		//these two functions are needed to keep the old API and help JSF and RSF play nicely together.  Since isExtraCredit already exists and we can't remove it
		//and JSF expects Boolean values to be "getExtraCredit", this had to be added for JSF.  Also, since the external GB create item page is in
		//RSF, you can't name it getExtraCredit and keep isExtraCredit b/c of SAK-14589
			return isExtraCredit();
		}
		public void setIsExtraCredit(Boolean isExtraCredit){
			this.setExtraCredit(isExtraCredit);
		}
		public Boolean isExtraCredit() {
			if( == null){
				return .;
			}
			return ;
		}
		public void setExtraCredit(Boolean isExtraCredit) {
			this. = isExtraCredit;
		}
		}
		public void setAssignmentWeighting(Double assignmentWeighting) {
			this. = assignmentWeighting;
		}
		public String getItemType() {
			if (gb!=null)
			{
				if (isExtraCredit()!=null)
				{
					{
						// if we made it in here, go ahead and return since adjustment item takes priority over the rest
						return ;
					}
				}
				{
					// if we made it in here, go ahead and return since non-calc item takes priority over the rest
					return ;
				}
				{
				}
				{
				}
				{
				}
			}
			return ;
		}
		public void setItemType(String itemType) {
			this. = itemType;
		}
		}
		public void setCountNullsAsZeros(Boolean countNullsAsZeros) {
			this. = countNullsAsZeros;
		}
		}
		public void setSelectedGradeEntryValue(String selectedGradeEntryValue) {
			this. = selectedGradeEntryValue;
		}

Convenience method for checking if the grade for the assignment should be included in calculations. This is different from just the isCounted() method for an assignment. This method does a more thorough check using other values, such as if removed, isExtraCredit, ungraded, etc in addition to the assignment's notCounted property.

Returns:
true if grades for this assignment should be included in various calculations.
		public boolean isIncludedInCalculations() {
			boolean isIncludedInCalculations = false;
			boolean extraCredit = isExtraCredit()!=null && isExtraCredit();
    		if (! && ! && ! && (extraCredit || ( != null && >0)))
    		{
    			isIncludedInCalculations = true;
    		}
			return isIncludedInCalculations;
		}
	public boolean isHideInAllGradesTable() {
	}
	public void setHideInAllGradesTable(boolean hideInAllGradesTable) {
		this. = hideInAllGradesTable;
	}
New to GrepCode? Check out our FAQ X