<commit_before>/*
 *                      Nividic development code
 *
 * This code may be freely distributed and modified under the
 * terms of the GNU Lesser General Public Licence.  This should
 * be distributed with the code.  If you do not have a copy,
 * see:
 *
 *      http://www.gnu.org/copyleft/lesser.html
 *
 * Copyright for this code is held jointly by the microarray platform
 * of the cole Normale Suprieure and the individual authors.
 * These should be listed in @author doc comments.
 *
 * For more information on the Nividic project and its aims,
 * or to join the Nividic mailing list, visit the home page
 * at:
 *
 *      http://www.transcriptome.ens.fr/nividic
 *
 */

package fr.ens.transcriptome.nividic.om.filters;

import fr.ens.transcriptome.nividic.om.BioAssay;

/**
 * This class define a filter for double with a threshold and a comparator.
 * @author <NAME>
 */
public class BioAssayDoubleThresholdFilter extends
    BioAssayGenericDoubleFieldFilter {

  private String field = BioAssay.FIELD_NAME_M;
  private static final Comparator defaultComparator = Comparator.UPPER;
  private double threshold;
  private boolean absolute;

  private Comparator comparator = Comparator.UPPER;

  private enum Comparator {
    LOWER, LOWEREQUALS, EQUALS, NOTEQUALS, UPPEREQUALS, UPPER;

    public String toString() {

      switch (this) {
      case LOWER:
        return "<";
      case LOWEREQUALS:
        return "<=";
      case EQUALS:
        return "=";
      case NOTEQUALS:
        return "!=";
      case UPPEREQUALS:
        return ">=";
      case UPPER:
        return ">";

      default:
        return "";
      }

    }

    public static Comparator getComparator(final String comparatorString) {

      if (comparatorString == null)
        return defaultComparator;

      String s = comparatorString.trim();

      if (s.equals("<"))
        return LOWER;
      if (s.equals("<="))
        return LOWEREQUALS;
      if (s.equals("=") || s.equals("=="))
        return EQUALS;
      if (s.equals("!="))
        return NOTEQUALS;
      if (s.equals(">="))
        return UPPEREQUALS;
      if (s.equals(">"))
        return UPPER;

      return defaultComparator;
    }

  };

  //
  // Getter
  //

  /**
   * Define the field to filter.
   * @return the field to filter
   */
  public String getFieldToFilter() {

    return field;
  }

  /**
   * Get the comparator.
   * @return The comparator
   */
  public String getComparator() {

    return comparator.toString();
  }

  /**
   * Get the threshold.
   * @return The threshold
   */
  public double getThreshold() {

    return this.threshold;
  }

  /**
   * test if the value to test is absolute.
   * @return true if the value to test is absolute
   */
  public boolean isAbsolute() {

    return this.absolute;
  }

  //
  // Setter
  //

  /**
   * Set the field to filter.
   * @param field Field to filter
   */
  public void setFieldToFilter(final String field) {

    this.field = field;
  }

  /**
   * Set the comparator.
   * @param comparator Comparator to set
   */
  public void setComparator(final String comparator) {

    this.comparator = Comparator.getComparator(comparator);
  }

  /**
   * Set the threshold.
   * @param threshold Threshold to set
   */
  public void setThreshold(final double threshold) {

    this.threshold = threshold;
  }

  /**
   * Set if the value to test is absolute.
   * @param absolute true to enable absolute values
   */
  public void setAbsolute(final boolean absolute) {

    this.absolute = absolute;
  }

  //
  // Other methods
  //

  /**
   * Test the value.
   * @param value Value to test
   * @return true if the test if positive
   */
  @Override
  public boolean test(final double value) {

    final double threshold = this.threshold;

    final double v = this.absolute ? Math.abs(value) : value;

    if (this.absolute)

      if (Double.isNaN(threshold))
        return false;

    switch (this.comparator) {
    case LOWER:
      return v < threshold;
    case LOWEREQUALS:
      return v <= threshold;
    case EQUALS:
      return v == threshold;
    case NOTEQUALS:<commit_msg>Fix bug<commit_after>/*
 *                      Nividic development code
 *
 * This code may be freely distributed and modified under the
 * terms of the GNU Lesser General Public Licence.  This should
 * be distributed with the code.  If you do not have a copy,
 * see:
 *
 *      http://www.gnu.org/copyleft/lesser.html
 *
 * Copyright for this code is held jointly by the microarray platform
 * of the �cole Normale Sup�rieure and the individual authors.
 * These should be listed in @author doc comments.
 *
 * For more information on the Nividic project and its aims,
 * or to join the Nividic mailing list, visit the home page
 * at:
 *
 *      http://www.transcriptome.ens.fr/nividic
 *
 */

package fr.ens.transcriptome.nividic.om.filters;

import fr.ens.transcriptome.nividic.om.BioAssay;

/**
 * This class define a filter for double with a threshold and a comparator.
 * @author <NAME>
 */
public class BioAssayDoubleThresholdFilter extends
    BioAssayGenericDoubleFieldFilter {

  private String field = BioAssay.FIELD_NAME_M;
  private static final Comparator defaultComparator = Comparator.UPPER;
  private double threshold;
  private boolean absolute;

  private Comparator comparator = Comparator.UPPER;

  private enum Comparator {
    LOWER, LOWEREQUALS, EQUALS, NOTEQUALS, UPPEREQUALS, UPPER;

    public String toString() {

      switch (this) {
      case LOWER:
        return "<";
      case LOWEREQUALS:
        return "<=";
      case EQUALS:
        return "=";
      case NOTEQUALS:
        return "!=";
      case UPPEREQUALS:
        return ">=";
      case UPPER:
        return ">";

      default:
        return "";
      }

    }

    public static Comparator getComparator(final String comparatorString) {

      if (comparatorString == null)
        return defaultComparator;

      String s = comparatorString.trim();

      if (s.equals("<"))
        return LOWER;
      if (s.equals("<="))
        return LOWEREQUALS;
      if (s.equals("=") || s.equals("=="))
        return EQUALS;
      if (s.equals("!="))
        return NOTEQUALS;
      if (s.equals(">="))
        return UPPEREQUALS;
      if (s.equals(">"))
        return UPPER;

      return defaultComparator;
    }

  };

  //
  // Getter
  //

  /**
   * Define the field to filter.
   * @return the field to filter
   */
  public String getFieldToFilter() {

    return field;
  }

  /**
   * Get the comparator.
   * @return The comparator
   */
  public String getComparator() {

    return comparator.toString();
  }

  /**
   * Get the threshold.
   * @return The threshold
   */
  public double getThreshold() {

    return this.threshold;
  }

  /**
   * test if the value to test is absolute.
   * @return true if the value to test is absolute
   */
  public boolean isAbsolute() {

    return this.absolute;
  }

  //
  // Setter
  //

  /**
   * Set the field to filter.
   * @param field Field to filter
   */
  public void setFieldToFilter(final String field) {

    this.field = field;
  }

  /**
   * Set the comparator.
   * @param comparator Comparator to set
   */
  public void setComparator(final String comparator) {

    this.comparator = Comparator.getComparator(comparator);
  }

  /**
   * Set the threshold.
   * @param threshold Threshold to set
   */
  public void setThreshold(final double threshold) {

    this.threshold = threshold;
  }

  /**
   * Set if the value to test is absolute.
   * @param absolute true to enable absolute values
   */
  public void setAbsolute(final boolean absolute) {

    this.absolute = absolute;
  }

  //
  // Other methods
  //

  /**
   * Test the value.
   * @param value Value to test
   * @return true if the test if positive
   */
  @Override
  public boolean test(final double value) {

    final double threshold = this.threshold;

    final double v = this.absolute ? Math.abs(value) : value;

    if (Double.isNaN(threshold))
      return false;

    switch (this.comparator) {
    case LOWER:
      return v < threshold;
    case LOWEREQUALS:
      return v <= threshold;
    case EQUALS:
      return v == threshold;
    case NOTEQUALS:
{'fraction_non_alphanumeric': 0.10106511740498669, 'fraction_numerical': 0.0, 'mean_word_length': 2.3864754098360654, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '538345', 'n_tokens_mistral': 2509, 'n_tokens_neox': 2434, 'n_words': 790}