<commit_before>package eu.dzhw.fdz.metadatamanagement.domain.validation;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

import eu.dzhw.fdz.metadatamanagement.domain.I18nString;
import eu.dzhw.fdz.metadatamanagement.domain.ScaleLevels;

/**
 * Validator of the scale level. Only values from the class {@link ScaleLevels} are allowed.
 * 
 * @author <NAME>
 *
 */
public class ValidScaleLevelValidator implements ConstraintValidator<ValidScaleLevel, I18nString> {

  /*
   * (non-Javadoc)
   * 
   * @see javax.validation.ConstraintValidator#initialize(java.lang.annotation.Annotation)
   */
  @Override
  public void initialize(ValidScaleLevel constraintAnnotation) {}

  /*
   * (non-Javadoc)
   * 
   * @see javax.validation.ConstraintValidator#isValid(java.lang.Object,
   * javax.validation.ConstraintValidatorContext)
   */
  @Override
  public boolean isValid(I18nString scaleLevel, ConstraintValidatorContext context) {

 // Check for emptyness
    if (scaleLevel == null) {
      return true;
    }

    //english and german have correct values, but are they consistent?
    // nominal
    if (scaleLevel.getDe()
        .equals(ScaleLevels.NOMINAL.getDe())
        && scaleLevel.getEn()
          .equals(ScaleLevels.NOMINAL.getEn())) {
      return true;
    }
    
    // ordinal
    if (scaleLevel.getDe()
        .equals(ScaleLevels.ORDINAL.getDe())
        && scaleLevel.getEn()
          .equals(ScaleLevels.ORDINAL.getEn())) {
      return true;
    }<commit_msg>#272 fixed nullpointer within validscalelevelvalidator<commit_after>package eu.dzhw.fdz.metadatamanagement.domain.validation;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

import eu.dzhw.fdz.metadatamanagement.domain.I18nString;
import eu.dzhw.fdz.metadatamanagement.domain.ScaleLevels;

/**
 * Validator of the scale level. Only values from the class {@link ScaleLevels} are allowed.
 * 
 * @author <NAME>
 *
 */
public class ValidScaleLevelValidator implements ConstraintValidator<ValidScaleLevel, I18nString> {

  /*
   * (non-Javadoc)
   * 
   * @see javax.validation.ConstraintValidator#initialize(java.lang.annotation.Annotation)
   */
  @Override
  public void initialize(ValidScaleLevel constraintAnnotation) {}

  /*
   * (non-Javadoc)
   * 
   * @see javax.validation.ConstraintValidator#isValid(java.lang.Object,
   * javax.validation.ConstraintValidatorContext)
   */
  @Override
  public boolean isValid(I18nString scaleLevel, ConstraintValidatorContext context) {

    // Check for emptyness
    if (scaleLevel == null) {
      return false;
    }

    // check for part objects
    if (scaleLevel.getDe() == null || scaleLevel.getEn() == null) {
      return false;
    }

    //english and german have correct values, but are they consistent?
    // nominal
    if (scaleLevel.getDe()
        .equals(ScaleLevels.NOMINAL.getDe())
        && scaleLevel.getEn()
          .equals(ScaleLevels.NOMINAL.getEn())) {
      return true;
    }
    
    // ordinal
    if (scaleLevel.getDe()
        .equals(ScaleLevels.ORDINAL.getDe())
        && scaleLevel.getEn()
          .equals(ScaleLevels.ORDINAL.getEn())) {
      return true;
    }
{'fraction_non_alphanumeric': 0.11145510835913312, 'fraction_numerical': 0.0046439628482972135, 'mean_word_length': 3.366216216216216, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4268939', 'n_tokens_mistral': 1012, 'n_tokens_neox': 970, 'n_words': 185}