Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.factual;
 
 import java.util.List;
 
Represents a group of Filters as one Filter.

Author(s):
aaron
public class FilterGroup implements Filter {
  private final List<Filterfilters;
  private String op = "$and";


  
Constructor. Defaults logic to AND.
  public FilterGroup(List<Filterfilters) {
    this. = filters;
  }

  
Constructor. Defaults logic to AND.
  public FilterGroup(Filter... filters) {
    this. = Lists.newArrayList();
    for(Filter f : filters) {
      this..add(f);
    }
  }

  
Sets this FilterGroup's logic, e.g., "$or".
  public FilterGroup op(String op) {
    this. = op;
    return this;
  }

  
Sets this FilterGroup's logic to be OR.
  public FilterGroup asOR() {
    return op("$or");
  }
  public void add(Filter filter) {
    .add(filter);
  }

  
Produces JSON representation for this FilterGroup

For example:

 {"$and":[{"first_name":{"$eq":"Bradley"}},{"region":{"$eq":"CA"}},{"locality":{"$eq":"Los Angeles"}}]}
 
  public String toJsonStr() {
    return "{\"" +  + "\":[" + logicJsonStr() + "]}";
  }
  private String logicJsonStr() {
    List<Stringlogics = Lists.newArrayList();
    for(Filter f : ) {
      logics.add(f.toJsonStr());
    }
    return Joiner.on(",").join(logics);
  }
New to GrepCode? Check out our FAQ X