{@inheritDoc}

@param VariantInterface[] $variants Variants to choose from
7109
public function chooseVariant($variants)
    {
        if (array_key_exists($this->choice, $variants)) {
            return $variants[$this->choice];
        }

        return null;
    }
794138
public static List<String> getAllVariantKeysFromFixedVariants(Map<String, VariantSet> variants,
			Map<String, String> fixedVariants) {

		Map<String, VariantSet> tempVariants = new HashMap<>(variants);

		if (fixedVariants != null) {

			for (Entry<String, String> entry : fixedVariants.entrySet()) {
				VariantSet variantSet = tempVariants.get(entry.getKey());
				if (variantSet != null) {
					String variantValue = variantSet.getDefaultVariant();
					if (variantSet.contains(entry.getValue())) {
						variantValue = entry.getValue();
					}

					VariantSet newVariantSet = new VariantSet(variantSet.getType(), variantValue,
							Arrays.asList(variantValue));
					tempVariants.put(variantSet.getType(), newVariantSet);
				}
			}
		}

		return getAllVariantKeys(tempVariants);
	}
215873
public function setVariant($variant)
    {
        if ($this->isFromServer) {
            $this->validateVariant($variant);
        }

        $clone = clone $this;
        $clone->variant = $this->normalizeVariant($variant);

        return $clone;
    }
1038999
public function deleteVariant(TargetInterface $target, $variant)
    {
        if ($variant == static::ORIGINAL) {
            $path = $target->original();
        } else {
            $path = $target->variant($variant);
        }

        // If the file does not exist, consider 'deletion' a success
        if ( ! $this->storage->exists($path)) {
            return true;
        }

        return $this->storage->delete($path);
    }
488641
public function getVariationFromId($experimentKey, $variationId)
    {
        if (isset($this->_variationIdMap[$experimentKey])
            && isset($this->_variationIdMap[$experimentKey][$variationId])
        ) {
            return $this->_variationIdMap[$experimentKey][$variationId];
        }

        $this->_logger->log(
            Logger::ERROR,
            sprintf(
                'No variation ID "%s" defined in datafile for experiment "%s".',
                $variationId,
                $experimentKey
            )
        );
        $this->_errorHandler->handleError(new InvalidVariationException('Provided variation is not in datafile.'));
        return new Variation();
    }
1083821
public void setClientVariant(String context, String variant, CmsClientVariantInfo info) {

        if (!m_clientVariantInfo.containsKey(context)) {
            Map<String, CmsClientVariantInfo> variants = new LinkedHashMap<String, CmsClientVariantInfo>();
            m_clientVariantInfo.put(context, variants);
        }
        m_clientVariantInfo.get(context).put(variant, info);
    }
526636
private function getVariantValueList(TdbShopVariantType $variantType)
    {
        $dbConnection = $this->getDatabaseConnection();

        /**
         * @var array $selectedVariantTypeValues
         */
        $selectedVariantTypeValues = $this->getInputFilterUtil()->getFilteredInput('variantTypeValues');

        if (false === is_array($selectedVariantTypeValues) || false === array_key_exists($variantType->id, $selectedVariantTypeValues)) {
            return $variantType->GetFieldShopVariantTypeValueList();
        }

        $selectedVariantValues = $selectedVariantTypeValues[$variantType->id];

        $query = 'SELECT * 
                            FROM `shop_variant_type_value`
                           WHERE `shop_variant_type_value`.`id` IN (%s) 
                        ORDER BY %s ASC 
                            ';

        $escapedSelectedVariantValues = implode(',', array_map(array($dbConnection, 'quote'), $selectedVariantValues));
        $escapedFieldName = $dbConnection->quoteIdentifier($variantType->fieldShopVariantTypeValueCmsfieldname);
        $query = sprintf($query, $escapedSelectedVariantValues, $escapedFieldName);

        return TdbShopVariantTypeValueList::GetList($query);
    }
494369
@Override
	public void setVariants(Map<String, VariantSet> variantSets) {

		if (variantSets != null) {
			this.variants = new TreeMap<>(variantSets);
			variantKeys = VariantUtils.getAllVariantKeys(this.variants);
		}
	}
1252651
private List<BundlePath> getItemPathList(List<BundlePath> itemList, Map<String, String> variants) {
		if (variants == null || variants.isEmpty()) {
			return itemList;
		}

		List<BundlePath> rets = new ArrayList<>();

		for (BundlePath bundlePath : itemList) {
			String path = bundlePath.getPath();
			if (generatorRegistry.isPathGenerated(path)) {
				Set<String> variantTypes = generatorRegistry.getGeneratedResourceVariantTypes(path);
				String variantKey = VariantUtils.getVariantKey(variants, variantTypes);
				if (StringUtils.isNotEmpty(variantKey)) {
					rets.add(new BundlePath(bundlePath.getBundlePrefix(),
							VariantUtils.getVariantBundleName(path, variantKey, true)));
				} else {
					rets.add(bundlePath);
				}
			} else {
				rets.add(bundlePath);
			}
		}
		return rets;
	}
993903
public function initialise_for_slot($slot, $question, $variant = null) {
        $newqstat = new calculated($question, $slot, $variant);
        if ($variant === null) {
            $this->questionstats[$slot] = $newqstat;
        } else {
            $this->questionstats[$slot]->variantstats[$variant] = $newqstat;
        }
    }
88635
private function processAttributes(ProductInterface $variant, array $variantData, $locale)
    {
        $parent = $variant->getParent();

        // Number of attributes in variantData and parents variant-attributes need to match and must not be 0.
        $sizeOfVariantAttributes = count($this->getProperty($variantData, 'attributes'));
        $sizeOfParentAttributes = $parent->getVariantAttributes()->count();
        if (!$sizeOfVariantAttributes
            || !$sizeOfParentAttributes
            || $sizeOfVariantAttributes != $sizeOfParentAttributes
        ) {
            throw new ProductException('Invalid number of attributes for variant provided.');
        }

        $attributesDataCopy = $variantData['attributes'];

        // For all variants of parent, find corresponding attribute in variant-data.
        foreach ($parent->getVariantAttributes() as $variantAttribute) {
            foreach ($attributesDataCopy as $index => $attributeData) {
                if ($variantAttribute->getId() === $attributeData['attributeId']) {
                    // Update or create ProductAttribute for variant.
                    $this->productAttributeManager->updateOrCreateProductAttributeForProduct(
                        $variant,
                        $variantAttribute,
                        $attributeData,
                        $locale
                    );

                    unset($attributesDataCopy[$index]);
                }
            }
        }

        // Not all necessary variant attributes were defined in data array.
        if (count($attributesDataCopy)) {
            throw new ProductException('Invalid attributes for variant provided.');
        }
    }
117709
public function participates($test, $variant = null)
    {
        $test = $test instanceof TestInterface ? $test->getIdentifier() : $test;
        $variant = $variant instanceof VariantInterface ? $variant->getIdentifier() : $variant;

        if (!$this->storage->has($test)) {
            return false;
        }

        $storedValue = $this->storage->get($test);

        // It was asked explicitly for the variant and it matches
        if (null !== $variant) {
            return $storedValue === $variant;
        }

        return true;
    }
713797
protected static function deleteVariantByIdAsyncWithHttpInfo($variant_id) 
    {
        $returnType = '';  
        $request = self::deleteVariantByIdRequest($variant_id); 

        return self::getHttpClient()
            ->sendAsync($request, self::createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    return [null, $response->getStatusCode(), $response->getHeaders()];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();
                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        $response->getBody()
                    );
                }
            );
    }
1280433
public static Map<String, VariantSet> concatVariants(Map<String, VariantSet> variantSet1,
			Map<String, VariantSet> variantSet2) {

		Map<String, VariantSet> result = new HashMap<>();
		if (!isEmpty(variantSet1) && isEmpty(variantSet2)) {
			result.putAll(variantSet1);
		} else if (isEmpty(variantSet1) && !isEmpty(variantSet2)) {
			result.putAll(variantSet2);
		} else if (!isEmpty(variantSet1) && !isEmpty(variantSet2)) {

			Set<String> keySet = new HashSet<>();
			keySet.addAll(variantSet1.keySet());
			keySet.addAll(variantSet2.keySet());
			for (String variantType : keySet) {
				VariantSet variants1 = variantSet1.get(variantType);
				VariantSet variants2 = variantSet2.get(variantType);
				Set<String> variants = new HashSet<>();
				String defaultVariant = null;

				if (variants1 != null && variants2 != null && !variants1.hasSameDefaultVariant(variants2)) {
					throw new BundlingProcessException("For the variant type '" + variantType
							+ "', the variant sets defined in your bundles don't have the same default value.");
				}

				if (variants1 != null) {
					variants.addAll(variants1);
					defaultVariant = variants1.getDefaultVariant();
				}
				if (variants2 != null) {
					variants.addAll(variants2);
					defaultVariant = variants2.getDefaultVariant();
				}

				VariantSet variantSet = new VariantSet(variantType, defaultVariant, variants);
				result.put(variantType, variantSet);
			}
		}

		return result;
	}
329640
def insertVariantSet(self, variantSet):
        
        # We cheat a little here with the VariantSetMetadata, and encode these
        # within the table as a JSON dump. These should really be stored in
        # their own table
        metadataJson = json.dumps(
            [protocol.toJsonDict(metadata) for metadata in
             variantSet.getMetadata()])
        urlMapJson = json.dumps(variantSet.getReferenceToDataUrlIndexMap())
        try:
            models.Variantset.create(
                id=variantSet.getId(),
                datasetid=variantSet.getParentContainer().getId(),
                referencesetid=variantSet.getReferenceSet().getId(),
                name=variantSet.getLocalId(),
                created=datetime.datetime.now(),
                updated=datetime.datetime.now(),
                metadata=metadataJson,
                dataurlindexmap=urlMapJson,
                attributes=json.dumps(variantSet.getAttributes()))
        except Exception as e:
            raise exceptions.RepoManagerException(e)
        for callSet in variantSet.getCallSets():
            self.insertCallSet(callSet)
1340485
protected function extractPaperclipVariantInfo(PaperclipAttachmentInstance $paperclip, $variant)
    {
        $config = $paperclip->getNormalizedConfig();

        $variantSteps = array_get($config, "variants.{$variant}", []);

        $dimensions = array_get($variantSteps, 'resize.dimensions');
        $extension  = array_get($variantSteps, "extensions.{$variant}");
        $mimeType   = array_get($variantSteps, "types.{$variant}");

        return compact('dimensions', 'extension', 'mimeType');
    }
1055887
public void addPostProcessVariant(Map<String, VariantSet> variants) {

		if (!searchingPostProcessorVariants) {
			throw new BundlingProcessException(
					"You are not allowed to define post process variants if we are not searching for post processor variants.");
		}
		postProcessVariants = VariantUtils.concatVariants(postProcessVariants, variants);
	}