public static void addAutoStyleParameterFilter(
     final LayerInfo layer, GeoServerTileLayerInfo layerInfo) {
   StyleParameterFilter filter = new StyleParameterFilter();
   filter.setLayer(layer);
   layerInfo.removeParameterFilter("STYLES");
   layerInfo.getParameterFilters().add(filter);
 }
  /**
   * Set the styles which should be cached on a layer
   *
   * @param info
   * @param defaultStyle
   * @param cachedStyles
   */
  public static void setCachedStyles(
      GeoServerTileLayerInfo info, String defaultStyle, Set<String> cachedStyles) {
    StyleParameterFilter filter = (StyleParameterFilter) info.getParameterFilter("STYLES");
    if (filter == null) filter = new StyleParameterFilter();

    filter.setDefaultValue(defaultStyle);
    filter.setStyles(cachedStyles);
    info.addParameterFilter(filter);
  }
  /**
   * If the layer is configured for automatic style updates of its Style parameter filter, do so.
   *
   * @param layer The GeoServer layer
   * @param layerInfo The GeoWebCache layer
   */
  public static void checkAutomaticStyles(final LayerInfo layer, GeoServerTileLayerInfo layerInfo) {

    ParameterFilter filter = layerInfo.getParameterFilter("STYLES");

    // Update the filter with the latest available styles if it's a style filter
    if (filter != null && filter instanceof StyleParameterFilter) {
      ((StyleParameterFilter) filter).setLayer(layer);
    }
  }