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

com.adobe.cq.commerce.common.EnumerateAxisFilter Maven / Gradle / Ivy

There is a newer version: 6.5.21
Show newest version
/*************************************************************************
 *
 * ADOBE CONFIDENTIAL
 * __________________
 *
 *  Copyright 2011 Adobe Systems Incorporated
 *  All Rights Reserved.
 *
 * NOTICE:  All information contained herein is, and remains
 * the property of Adobe Systems Incorporated and its suppliers,
 * if any.  The intellectual and technical concepts contained
 * herein are proprietary to Adobe Systems Incorporated and its
 * suppliers and are protected by trade secret or copyright law.
 * Dissemination of this information or reproduction of this material
 * is strictly forbidden unless prior written permission is obtained
 * from Adobe Systems Incorporated.
 **************************************************************************/
package com.adobe.cq.commerce.common;

import com.adobe.cq.commerce.api.Product;
import com.adobe.cq.commerce.api.VariantFilter;

import java.util.HashSet;
import java.util.Set;

/**
 * A {@link VariantFilter} for enumerating variants along a given axis.  A single variation
 * will be returned for each enumeration.
 *
 * 

For example, given the variations: *

    *
  • small-blue
  • *
  • small-black
  • *
  • small-tan
  • *
  • large-green
  • *
  • large-brown
  • *
  • large-red
  • *
* this call:
    product.getVariants(new EnumerateAxisFilter("size"));
* will return two products: small-blue and large-green. * *

NB: the particular variation chosen to represent each enumeration is * not defined. The example above could have also returned small-black and * large-red. */ public class EnumerateAxisFilter implements VariantFilter { private String axis; private Set represented = new HashSet(); public EnumerateAxisFilter(String axis) { this.axis = axis; } public boolean includes(Product product) { String value = product.getProperty(axis, String.class); if (value != null && !represented.contains(value)) { represented.add(value); return true; } return false; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy