SKUCombinationsIterator implements Iterator<CPDefinitionOptionValueRel[]> { public SKUCombinationsIterator( Map<CPDefinitionOptionRel, CPDefinitionOptionValueRel[]> cpDefinitionOptionRelMap) { _combinationLength = cpDefinitionOptionRelMap.size(); _cpDefinitionOptionValueRels = new CPDefinitionOptionValueRel[_combinationLength][]; _currentIndexes = new int[_combinationLength]; _maxIndexes = new int[_combinationLength]; if (_combinationLength == 0) { _hasNext = false; return; } _hasNext = true; int valuesIndex = 0; List<CPDefinitionOptionRel> cpDefinitionOptionRels = new ArrayList<>( cpDefinitionOptionRelMap.keySet()); for (CPDefinitionOptionRel cpDefinitionOptionRel : cpDefinitionOptionRels) { _cpDefinitionOptionValueRels[valuesIndex++] = cpDefinitionOptionRelMap.get(cpDefinitionOptionRel); } for (int i = 0; i < _combinationLength; i++) { if (_cpDefinitionOptionValueRels[i].length == 0) { _hasNext = false; return; } _currentIndexes[i] = 0; _maxIndexes[i] = _cpDefinitionOptionValueRels[i].length - 1; } } SKUCombinationsIterator(
		Map<CPDefinitionOptionRel, CPDefinitionOptionValueRel[]>
			cpDefinitionOptionRelMap); @Override boolean hasNext(); @Override CPDefinitionOptionValueRel[] next(); @Override void remove();  }
@Test public void testSKUCombinationsIterator() throws Exception { int optionsAndValuesCount = 2; CPDefinition cpDefinition = _createCPDefinition(); Map<CPDefinitionOptionRel, CPDefinitionOptionValueRel[]> combinationGeneratorMap = _createCombinationGeneratorMap( optionsAndValuesCount, cpDefinition); Assert.assertEquals( combinationGeneratorMap.toString(), optionsAndValuesCount, combinationGeneratorMap.size()); Iterator<CPDefinitionOptionValueRel[]> iterator = new SKUCombinationsIterator(combinationGeneratorMap); int count = 0; while (iterator.hasNext()) { CPDefinitionOptionValueRel[] cpDefinitionOptionValueRels = iterator.next(); count += cpDefinitionOptionValueRels.length; } Assert.assertEquals( (int)Math.pow(optionsAndValuesCount, optionsAndValuesCount + 1), count); }