<commit_before>/*
 * Copyright 2012, Red Hat, Inc. and individual contributors
 * as indicated by the @author tags. See the copyright.txt file in the
 * distribution for a full listing of individual contributors.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package org.zanata.search;

//TODO May want to add document(someDocument) to these constraints
//so that only one search method is needed on the interface.

import lombok.Getter;

import com.google.common.base.Objects;

/**
 * Specifies a set of constraints to be applied by a filter.
 * 
 * @author <NAME>, <EMAIL>
 */
@Getter
public class FilterConstraints
{
   private String searchString;
   private boolean isCaseSensitive;
   private boolean searchInSource;
   private boolean searchInTarget;
   private ActiveStates includedStates;

   private FilterConstraints(String searchString, boolean caseSensitive,
                             boolean searchInSource, boolean searchInTarget,
                             ActiveStates includedStates)
   {
      this.searchString = searchString;
      this.isCaseSensitive = caseSensitive;
      this.searchInSource = searchInSource;
      this.searchInTarget = searchInTarget;
      this.includedStates = includedStates;
   }

   public static Builder builder()
   {
      return new Builder();
   }

   @Override
   public String toString()
   {
      // @formatter:off
      return Objects.toStringHelper(this).
            add("searchString", searchString).
            add("isCaseSensitive", isCaseSensitive).
            add("searchInSource", searchInSource).
            add("searchInTarget", searchInTarget).
            add("includedStates", includedStates).
            toString();
      // @formatter:on
   }

   public static class Builder
   {
      private String searchString;
      private boolean caseSensitive;
      private boolean searchInSource;
      private boolean searchInTarget;
      private ActiveStates.Builder states;

      public Builder()
      {
         states = ActiveStates.builder();
         setKeepAll();
      }

      public FilterConstraints build()
      {
         return new FilterConstraints(searchString, caseSensitive,
               searchInSource, searchInTarget, states.build());
      }

      public Builder keepAll()
      {
         setKeepAll();
         return this;
      }

      private void setKeepAll()
      {
         searchString = "";
         caseSensitive = false;
         searchInSource = true;
         searchInTarget = true;
         states.allOn();
      }

      public Builder keepNone()
      {
         searchString = "";
         caseSensitive = false;
         searchInSource = false;
         searchInTarget = false;
         states.allOff();
         return this;
      }

      public Builder filterBy(String searchString)
      {
         this.searchString = searchString;
         return this;
      }

      public Builder caseSensitive(boolean caseSensitive)
      {
         this.caseSensitive = caseSensitive;
         return this;
      }

      public Builder checkInSource(boolean check)
      {
         searchInSource = check;
         return this;
      }

      public Builder checkInTarget(boolean check)
      {
         searchInTarget = check;
         return this;
      }

      public Builder includeStates(ActiveStates states)
      {
         this.states.fromStates(states);
         return this;
      }

      public Builder includeNew()
      {<commit_msg>Revert FilterConstraints includeStates(ActiveStates) to old behaviour<commit_after>/*
 * Copyright 2012, Red Hat, Inc. and individual contributors
 * as indicated by the @author tags. See the copyright.txt file in the
 * distribution for a full listing of individual contributors.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package org.zanata.search;

//TODO May want to add document(someDocument) to these constraints
//so that only one search method is needed on the interface.

import lombok.Getter;

import com.google.common.base.Objects;

/**
 * Specifies a set of constraints to be applied by a filter.
 * 
 * @author <NAME>, <EMAIL>
 */
@Getter
public class FilterConstraints
{
   private String searchString;
   private boolean isCaseSensitive;
   private boolean searchInSource;
   private boolean searchInTarget;
   private ActiveStates includedStates;

   private FilterConstraints(String searchString, boolean caseSensitive,
                             boolean searchInSource, boolean searchInTarget,
                             ActiveStates includedStates)
   {
      this.searchString = searchString;
      this.isCaseSensitive = caseSensitive;
      this.searchInSource = searchInSource;
      this.searchInTarget = searchInTarget;
      this.includedStates = includedStates;
   }

   public static Builder builder()
   {
      return new Builder();
   }

   @Override
   public String toString()
   {
      // @formatter:off
      return Objects.toStringHelper(this).
            add("searchString", searchString).
            add("isCaseSensitive", isCaseSensitive).
            add("searchInSource", searchInSource).
            add("searchInTarget", searchInTarget).
            add("includedStates", includedStates).
            toString();
      // @formatter:on
   }

   public static class Builder
   {
      private String searchString;
      private boolean caseSensitive;
      private boolean searchInSource;
      private boolean searchInTarget;
      private ActiveStates.Builder states;

      public Builder()
      {
         states = ActiveStates.builder();
         setKeepAll();
      }

      public FilterConstraints build()
      {
         return new FilterConstraints(searchString, caseSensitive,
               searchInSource, searchInTarget, states.build());
      }

      public Builder keepAll()
      {
         setKeepAll();
         return this;
      }

      private void setKeepAll()
      {
         searchString = "";
         caseSensitive = false;
         searchInSource = true;
         searchInTarget = true;
         states.allOn();
      }

      public Builder keepNone()
      {
         searchString = "";
         caseSensitive = false;
         searchInSource = false;
         searchInTarget = false;
         states.allOff();
         return this;
      }

      public Builder filterBy(String searchString)
      {
         this.searchString = searchString;
         return this;
      }

      public Builder caseSensitive(boolean caseSensitive)
      {
         this.caseSensitive = caseSensitive;
         return this;
      }

      public Builder checkInSource(boolean check)
      {
         searchInSource = check;
         return this;
      }

      public Builder checkInTarget(boolean check)
      {
         searchInTarget = check;
         return this;
      }

      public Builder includeStates(ActiveStates states)
      {
         //FIXME this behaviour is too surprising.
         // It exists because the editor UI should show all states when either
         // all or none of the states are checked. This logic should just happen
         // in the editor backend *before* sending a request to the server.
         if (states.hasNoStates())
         {
            this.states.allOn();
         }
         else
         {
            this.states.fromStates(states);
         }
         return this;
      }

      public Builder includeNew()
      {
{'fraction_non_alphanumeric': 0.07107456634377111, 'fraction_numerical': 0.003829691371930615, 'mean_word_length': 2.332957957957958, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6541084', 'n_tokens_mistral': 2222, 'n_tokens_neox': 2155, 'n_words': 775}