All Downloads are FREE. Search and download functionalities are using the official Maven repository.

hr.fer.junit.grading.GradingMatrixModel Maven / Gradle / Ivy

The newest version!
package hr.fer.junit.grading;

import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;

public class GradingMatrixModel {
  //test_group    description minusPercent
  private Set testGroupNames;
  private Map groupToDescription;
  private Map groupToMinusPercent;

  public GradingMatrixModel() {
    testGroupNames = new LinkedHashSet<>();
    groupToDescription = new HashMap<>();
    groupToMinusPercent = new HashMap<>();
  }

  public String getDescription(String testGroup) {
    return groupToDescription.get(testGroup);
  }

  public Integer getMinusPercent(String testGroup) {
    return groupToMinusPercent.get(testGroup);
  }

  public void setPercent(String testGroup, int minusPercent) {
    if(!testGroupNames.contains(testGroup))
      throw new GradingMatrixException("Can not set percent for test group '" + testGroup + "' that is not in the model.");
    if(minusPercent < 0)
      throw new GradingMatrixException(String.format("MinusPercent for group '%s' can not be %d. It should be >= 0.", testGroup, minusPercent));
    if(minusPercent > 100)
      throw new GradingMatrixException(String.format("MinusPercent for group '%s' can not be %d. It should be <= 100.", testGroup, minusPercent));

    groupToMinusPercent.put(testGroup, minusPercent);
  }

  private void addTestGroup(String testGroup) {
    if(testGroupNames.contains(testGroup))
      throw new GradingMatrixException("Duplicate test group '" + testGroup + "'.");
    testGroupNames.add(testGroup);
  }

  public void setDescription(String testGroup, String description) {
    if(!testGroupNames.contains(testGroup))
      throw new GradingMatrixException("Can not set description for test group '" + testGroup + "' that is not in the model.");

    groupToDescription.put(testGroup, description);
  }

  public String getTestGroupDisplayText(String testGroup) {
    if(groupToDescription.containsKey(testGroup) && !groupToDescription.get(testGroup).isEmpty())
      return groupToDescription.get(testGroup);

    return testGroup;
  }

  public Set testGroups() {
    return testGroupNames;
  }

  public void addTestGroup(String testGroup, int minusPercent) {
    addTestGroup(testGroup);
    setPercent(testGroup, minusPercent);
  }

  public void addTestGroup(String testGroup, int minusPercent, String description) {
    addTestGroup(testGroup);
    setPercent(testGroup, minusPercent);
    setDescription(testGroup, description);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy