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

com.groupbyinc.api.model.Refinement Maven / Gradle / Ivy

There is a newer version: 198
Show newest version
package com.groupbyinc.api.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeId;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.groupbyinc.api.model.refinement.RefinementRange;
import com.groupbyinc.api.model.refinement.RefinementValue;

/**
 * 
 * Abstract Refinement class holding common methods for RefinementRange and RefinementValue.
 * 
 *
 * @internal
 */
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type", defaultImpl = RefinementValue.class)
@JsonSubTypes({
    @JsonSubTypes.Type(value = RefinementValue.class, name = "Value"), @JsonSubTypes.Type(value = RefinementRange.class, name = "Range")})
public abstract class Refinement> {

  public enum Type {
    Value,
    Range // NOSONAR
  }

  @JsonProperty("_id") private String id;
  @JsonInclude(JsonInclude.Include.NON_DEFAULT) private int count;
  @JsonInclude(JsonInclude.Include.NON_DEFAULT) private Boolean exclude = false;

  /**
   * @return The ID is a MD5 of the name and value of the refinement.
   */
  public String getId() {
    return id;
  }

  /**
   * @param id Set the ID
   * @return
   */
  @SuppressWarnings("unchecked")
  public T setId(String id) {
    this.id = id;
    return (T) this;
  }

  /**
   * @return The number of records that will be left if this refinement is
   * selected.
   */
  public int getCount() {
    return count;
  }

  /**
   * @param count Set the number of matches if this refinement is selected
   * @return
   */
  @SuppressWarnings("unchecked")
  public T setCount(int count) {
    this.count = count;
    return (T) this;
  }

  /**
   * @return True if this is a range refinement.
   */
  @JsonIgnore
  public boolean isRange() {
    return getType() == Type.Range;
  }

  /**
   * 
   * Types are either `Range` or `Value`
   *
   * They represent the objects RefinementRange and RefinementValue
   * 
   *
   * @return The type of this refinement
   */
  @JsonTypeId
  public abstract Type getType();

  /**
   * @return True if the results should exclude this refinement and false to including it. Defaults to false.
   */
  public Boolean getExclude() {
    return exclude;
  }

  /**
   * @param exclude Set to true to get results that exclude this refinement, false to include this refinement.
   * @return
   */
  @SuppressWarnings("unchecked")
  public T setExclude(Boolean exclude) {
    this.exclude = exclude;
    return (T) this;
  }

  /**
   * @return
   * @internal
   */
  public abstract String toTildeString();
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy