title: Filtering Java ConcurrentHashMap
body: <p>I am working on ecom application. My product is defined below:</p>
  <pre><code>import java.math.BigDecimal;
  import java.util.Objects;
  
  public class Product {
      private String productId;
      private String brand;
      private String description;
      private BigDecimal price;
  
      public String getProductId() {
          return productId;
      }
  
      public void setProductId(String productId) {
          this.productId = productId;
      }
  
      public String getBrand() {
          return brand;
      }
  
      public void setBrand(String brand) {
          this.brand = brand;
      }
  
      public String getDescription() {
          return description;
      }
  
      public void setDescription(String description) {
          this.description = description;
      }
  
      public BigDecimal getPrice() { return price; }
  
      public void setPrice(BigDecimal price) { this.price = price; }
  
      @Override
      public boolean equals(Object o) {
          if (this == o) return true;
          if (o == null || getClass() != o.getClass()) return false;
          Product product = (Product) o;
          return productId.equals(product.productId);
      }
  
      @Override
      public int hashCode() {
          return Objects.hash(productId);
      }
  }
  </code></pre>
  <p>I have a Cache object defined as below to persist my product objects as:</p>
  <pre><code>import java.util.Map;
  import java.util.concurrent.ConcurrentHashMap;
  
  public class Cache&lt;K, V&gt; extends ConcurrentHashMap&lt;K, V&gt; {
  
      private static final int MAX_SIZE = 2;
  
      @Override
      public V put(K key, V value) {
          return super.size() &lt; MAX_SIZE ? super.put(key, value) : null;
      }
  
      @Override
      public void putAll(Map&lt;? extends K, ? extends V&gt; m) {
          if(MAX_SIZE &gt; (super.size() + m.size())){
              super.putAll(m);
          }
      }
  
      public Cache&lt;K, V&gt; getByBrand(String brand) {
          return super.entrySet().stream()
          .filter(e -&gt; e.getValue().getBrand().equals(brand));
      }
  }
  </code></pre>
  <p>And, I persist my product in the above cache as:</p>
  <pre><code>@Repository
  public class ProductRepository {
  
      private Map&lt;String, Product&gt; products = new Cache&lt;&gt;();
  
      public void addProduct(Product product) {
          products.put(product.getProductId(), product);
      }
  
      public Product getProduct(String productId) {
          return products.get(productId);
      }
  
      public List&lt;Product&gt; getProductByBrand(String brand) {
          return products.getByBrand(brand);
      }
  
      public Collection&lt;Product&gt; getAll() {
          return products.values();
      }
  }
  </code></pre>
  <p>However, when I am trying to run this code, it does not even compile. It is failing on <code>return products.getByBrand(brand);</code> with the following error:</p>
  <pre><code>cannot find symbol
  [ERROR]   symbol:   method getByBrand(java.lang.String)
  </code></pre>
  <p>How would I code this correctly?</p>