Class Facet<T>

java.lang.Object
com.appiancorp.common.query.Facet<T>
Type Parameters:
T - the type of values in the facet option filters
All Implemented Interfaces:
com.appiancorp.common.query.ReadOnlyFacet<T>
Direct Known Subclasses:
GenericFacet, TypedValueFacet

@GwtCompatible public abstract class Facet<T> extends Object implements com.appiancorp.common.query.ReadOnlyFacet<T>

This class holds the metadata for a facet and its options. For example, a Car record could have a Color facet with the options Black, White, Silver.

  • Field Details

  • Constructor Details

    • Facet

      protected Facet()
      Default constructor, provided only for JAXB serialization. Sub-classes should not expose a public default constructor.
    • Facet

      protected Facet(String name, boolean isVisible, String defaultOption, List<FacetOption<T>> options, int numOmittedOptions, int omittedOptionsDataCount, boolean isExclusiveOptions, String facetType, String sourceRef)
      Constructs a new facet.
      Parameters:
      name - The name of the facet.
      options - The list of options for this facet.
      isVisible - Whether or not the facet will appear to the user.
      defaultOption - The defaultOption to be applied.
      numOmittedOptions - The number of additional options that are available, but are not included in the provided list of options.
      omittedOptionsDataCount - The number of objects that contain data matched by the omitted options. This allows the UI to present the generic option "Other" along with a count.
      isExclusiveOptions - Whether this facet's options are exclusive or not. See isExclusiveOptions().
      facetType - Type of the facet (whether it is List or DateRange)
      sourceRef - Name of the field (of the record), on which the filter is applied.
    • Facet

      protected Facet(String name, boolean isVisible, String defaultOption, List<String> defaultOptions, List<FacetOption<T>> options, int numOmittedOptions, int omittedOptionsDataCount, boolean isExclusiveOptions, String facetType, String sourceRef)
  • Method Details

    • getName

      public String getName()
      Specified by:
      getName in interface com.appiancorp.common.query.ReadOnlyFacet<T>
      Returns:
      The name of this facet.
    • isVisible

      public boolean isVisible()
      Specified by:
      isVisible in interface com.appiancorp.common.query.ReadOnlyFacet<T>
      Returns:
      whether or not this facet should be displayed to the user.
    • getDefaultOption

      public String getDefaultOption()
      Specified by:
      getDefaultOption in interface com.appiancorp.common.query.ReadOnlyFacet<T>
      Returns:
      the default applied option for the facet.
    • getDefaultOptions

      public List<String> getDefaultOptions()
      Specified by:
      getDefaultOptions in interface com.appiancorp.common.query.ReadOnlyFacet<T>
    • getNumOmittedOptions

      public int getNumOmittedOptions()
      Specified by:
      getNumOmittedOptions in interface com.appiancorp.common.query.ReadOnlyFacet<T>
      Returns:
      The number of options that exist, but are not included in the list of options. If this number is not available, returns FacetOption.COUNT_NOT_AVAILABLE.
    • getTotalNumOptions

      public int getTotalNumOptions()
      Returns:
      The number of options plus the number of omitted options. If the number of omitted options is not available, returns FacetOption.COUNT_NOT_AVAILABLE.
    • getOmittedOptionsDataCount

      public int getOmittedOptionsDataCount()
      Specified by:
      getOmittedOptionsDataCount in interface com.appiancorp.common.query.ReadOnlyFacet<T>
      Returns:
      The number of objects that have a value for this facet that matches one of the omitted options. If this number is not available, returns FacetOption.COUNT_NOT_AVAILABLE.
    • isExclusiveOptions

      public boolean isExclusiveOptions()
      Specified by:
      isExclusiveOptions in interface com.appiancorp.common.query.ReadOnlyFacet<T>
      Returns:
      true if the options are exclusive, and false otherwise. If the options are exclusive, only one of the options can be applied for a given query. If the options are not exclusive, multiple options can be selected and applied in a given query. This is analogous to radio buttons vs checkboxes.
    • getFacetType

      public String getFacetType()
      Specified by:
      getFacetType in interface com.appiancorp.common.query.ReadOnlyFacet<T>
    • getSourceRef

      public String getSourceRef()
      Specified by:
      getSourceRef in interface com.appiancorp.common.query.ReadOnlyFacet<T>
    • getOptions

      public abstract List<FacetOption<T>> getOptions()
      Returns:
      The options of this facet.
    • setOptions

      protected abstract void setOptions(List<FacetOption<T>> options)
      Sets the options for this facet.
      Parameters:
      options - the list of options
    • getOptionsReadOnly

      public com.google.common.collect.ImmutableList<com.appiancorp.common.query.ReadOnlyFacetOption<T>> getOptionsReadOnly()
      Specified by:
      getOptionsReadOnly in interface com.appiancorp.common.query.ReadOnlyFacet<T>
    • getAppliedOptions

      public List<FacetOption<T>> getAppliedOptions()
      Returns:
      The subset of this facet's options that are applied (ie, options whose isApplied property is set to true).
    • setAppliedOptions

      public void setAppliedOptions(Criteria appliedCriteria)
      Sets the isApplied property on the options of this facet, based on the given query criteria.

      An option's isApplied property will be set to true, if that option's filters are contained in the given criteria. Otherwise, the isApplied property will be set to false.

      Parameters:
      appliedCriteria - the criteria to use in order to determine which facet options are enabled
    • setAppliedOptions

      public static <T> void setAppliedOptions(Iterable<Facet<T>> facets, Criteria appliedCriteria)
      Sets the isApplied property on the appropriate options of the given facets, using setAppliedOptions(Criteria).
      Parameters:
      facets - the facets to configure
      appliedCriteria - the criteria to use in order to determine which facet options are enabled
    • findOptionById

      public FacetOption<T> findOptionById(String facetOptionId)
      Finds an option by id.
      Parameters:
      facetOptionId - the target option id
      Returns:
      If this facet's list of options contains an option with the given id, returns that option. Otherwise, returns null.
    • findOptionByIdReadOnly

      public com.appiancorp.common.query.ReadOnlyFacetOption<T> findOptionByIdReadOnly(String facetOptionId)
      Specified by:
      findOptionByIdReadOnly in interface com.appiancorp.common.query.ReadOnlyFacet<T>
    • findOptionById

      public static <T> FacetOption<T> findOptionById(List<Facet<T>> facets, String facetOptionId)
      Finds the first matching option by id, within the options of the given facets.
      Parameters:
      facets - the facets whose options should be searched
      facetOptionId - the target option id
      Returns:
      If the given list of facets contains a facet with an option with the given id, returns that option. Otherwise, returns null.
    • findOptionByIdReadOnly

      public static <T> com.appiancorp.common.query.ReadOnlyFacetOption<T> findOptionByIdReadOnly(List<com.appiancorp.common.query.ReadOnlyFacet<T>> facets, String facetOptionId)
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • multilineToString

      public static com.appian.core.base.ToStringFunction<Facet<?>> multilineToString(int indent)
      Returns a function that generates a multi-line String representation of a facet.
      Parameters:
      indent - the indent to be used by the returned function
      Returns:
      the "toString" function
    • hashCode

      public int hashCode()
      Returns a hash code that uses the name property only.

      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Compares the given object by checking that it's an instance of Facet and has the same name as this facet.

      Overrides:
      equals in class Object
    • equalDataCheck

      public static com.google.common.base.Equivalence<Facet<?>> equalDataCheck()
      Returns:
      An equivalence that checks all properties of Facet.