/** Returns the Cartesian set of the possible cache configurations. */ @SuppressWarnings["unchecked"] private Set combinations[] { Set asyncLoading = ImmutableSet.of[true, false]; Set statistics = filterTypes[options.stats[], cacheSpec.stats[]]; Set keys = filterTypes[options.keys[], cacheSpec.keys[]]; Set values = filterTypes[options.values[], cacheSpec.values[]]; Set computations = filterTypes[options.compute[], cacheSpec.compute[]]; Set implementations = filterTypes[ options.implementation[], cacheSpec.implementation[]]; if [isAsyncOnly] { values = values.contains[ReferenceType.STRONG] ? ImmutableSet.of[ReferenceType.STRONG] : ImmutableSet.of[]; computations = Sets.filter[computations, Compute.ASYNC::equals]; } if [isAsyncOnly || computations.equals[ImmutableSet.of[Compute.ASYNC]]] { implementations = implementations.contains[Implementation.Caffeine] ? ImmutableSet.of[Implementation.Caffeine] : ImmutableSet.of[]; } if [computations.equals[ImmutableSet.of[Compute.SYNC]]] { asyncLoading = ImmutableSet.of[false]; } if [computations.isEmpty[] || implementations.isEmpty[] || keys.isEmpty[] || values.isEmpty[]] { return ImmutableSet.of[]; } return Sets.cartesianProduct[ ImmutableSet.copyOf[cacheSpec.initialCapacity[]], ImmutableSet.copyOf[statistics], ImmutableSet.copyOf[cacheSpec.weigher[]], ImmutableSet.copyOf[cacheSpec.maximumSize[]], ImmutableSet.copyOf[cacheSpec.expiry[]], ImmutableSet.copyOf[cacheSpec.expireAfterAccess[]], ImmutableSet.copyOf[cacheSpec.expireAfterWrite[]], ImmutableSet.copyOf[cacheSpec.refreshAfterWrite[]], ImmutableSet.copyOf[cacheSpec.advanceOnPopulation[]], ImmutableSet.copyOf[keys], ImmutableSet.copyOf[values], ImmutableSet.copyOf[cacheSpec.executor[]], ImmutableSet.copyOf[cacheSpec.scheduler[]], ImmutableSet.copyOf[cacheSpec.removalListener[]], ImmutableSet.copyOf[cacheSpec.population[]], ImmutableSet.of[true, isLoadingOnly], ImmutableSet.copyOf[asyncLoading], ImmutableSet.copyOf[computations], ImmutableSet.copyOf[cacheSpec.loader[]], ImmutableSet.copyOf[cacheSpec.writer[]], ImmutableSet.copyOf[implementations]]; }
In this page you can find the example usage for com.google.common.collect Lists cartesianProduct. public static List cartesianProduct[List prop : properties] { List vals = Lists.newArrayList[]; vals.addAll[prop.getValues[]]; separatedValues.add[vals];//from ww w . j av a 2 s . com } List valueLists = Lists.cartesianProduct[separatedValues]; for [List valueList : valueLists] { Map property = properties.get[i]; Object value = valueList.get[i]; valueMap.put[property, value]; stateMaker.setState[property, value]; } stateMap.put[valueMap, stateMaker]; } } if [stateMap.isEmpty[]] { // No properties. stateMap.put[new LinkedHashMap[], new BlockState[blockType]]; } for [BlockState state : stateMap.values[]] { state.populate[stateMap]; } return stateMap; }
From source file:ItemManagement.GuavaCartesian.java
From source file:ItemManagement.GuavaCartesian.java
public static ArrayList CartesianSetBuilder[ArrayList list1, int limit] throws IOException { List cartesianProduct = Lists.cartesianProduct[list1]; ArrayList uniqueSets = new ArrayList[]; ArrayList uniqueStats = new ArrayList[]; // System.out.println[cartesianProduct.toString[]]; System.out.println[cartesianProduct.size[]]; int index = 0; if [limit == 0] { limit = cartesianProduct.size[]; }/*from w ww .ja va 2 s . c o m*/ while [index != limit] { List mysets = cartesianProduct.get[index]; itemSet myItemSet = new itemSet[mysets]; myItemSet.calcSetStats[]; scoreValues setValues = myItemSet.getSetValues[]; //ListOfSets.add[myItemSet]; if [uniqueStats.contains[setValues]] { System.out.println["stat set already exists"]; } else { uniqueStats.add[setValues]; uniqueSets.add[myItemSet]; System.out.println["UNIQUE SET ADDED - SIZE: " + uniqueSets.size[]]; } // DbConnect con = new DbConnect[]; // con.storeItem[myItemSet]; System.out.println[index + " OF " + limit]; index++; } //myItemSet.calcscore[values]; // Object[] toArray = cartesianProduct.toArray[]; return uniqueSets; }From source file:grakn.core.graql.reasoner.pattern.RelationPattern.java
From source file:tuupertunut.hintahaku.ostoskori.JoukkotilausAlgoritmi.java
private static Map laskeParhaatHinnat[Ostoskori ostoskori] { Map ostoksenHintatiedot = new LinkedHashMap[]; /* Listn ostoksille niiden hintatiedot. */ for [Ostos ostos : ostoskori.getOstokset[]] { /* Listn kaikkien ostoksen tuotevaihtoehtojen hintatiedot yhteen * yhdeksi listaksi. *//*from w w w .j a v a 2 s. co m*/ List yhdistetytHintatiedot = new ArrayList[]; for [Tuote vaihtoehto : ostos.getVaihtoehdot[]] { yhdistetytHintatiedot.addAll[vaihtoehto.getHintatiedot[]]; } /* Poistetaan hintatiedot, joiden suodatettua hintaa ei ole * mritetty [kauppa on suodatettu pois tai postikuluja ei * tiedet]. */ yhdistetytHintatiedot.removeIf[[Hintatieto ht] -> !ht.getSuodatettuHinta[].isPresent[]]; /* Optimointi: Poistetaan ostoksesta ne hintatiedot, joiden * postikuluton hinta on suurempi kuin halvimman hintatiedon * suodatettu [postikulullinen] hinta. */ Optional halvinSuodatettu = ostos.getHalvinSuodatettuHintatieto[] .flatMap[Hintatieto::getSuodatettuHinta]; if [halvinSuodatettu.isPresent[]] { yhdistetytHintatiedot .removeIf[[Hintatieto ht] -> ht.getHinta[].onEnemmanKuin[halvinSuodatettu.get[]]]; } /* Jos hintatietolistassa on hintatietoja jljell, listn ne * mappiin. */ if [!yhdistetytHintatiedot.isEmpty[]] { ostoksenHintatiedot.put[ostos, yhdistetytHintatiedot]; } } Map halvinYhdistelma = null; List ostokset = new ArrayList[ostoksenHintatiedot.keySet[]]; List hintatietoListat = new ArrayList[ostoksenHintatiedot.values[]]; /* Kydn lpi kaikki mahdolliset hintatietoyhdistelmt ja valitaan * niist halvin. Tm prosessi on erittin raskas suurilla tuote- ja * hintatietomrill, joten aiemmassa vaiheessa tehty optimointi on * hyvin trke. Esimerkkin 15 kpl 10:n hintatiedon tuotteita vaatisi * ilman optimointia jopa tuhat biljoonaa kokeilua. */ for [List yhdistelmanHintatiedot : Lists.cartesianProduct[hintatietoListat]] { Map yhdistelma = new HashMap[]; /* Muodostetaan yhdistelm hintatietoja. Tiedetn, ett * yhdistelmanHintatiedot- ja ostokset-listojen indexit vastaavat * toisiaan. */ for [int i = 0; i < ostokset.size[]; i++] { yhdistelma.put[ostokset.get[i], yhdistelmanHintatiedot.get[i]]; } /* Testataan, onko muodostettu yhdistelm halvempi kuin thn asti * halvin yhdistelm. */ if [halvinYhdistelma == null || kokonaisHinta[yhdistelma].onVahemmanKuin[kokonaisHinta[halvinYhdistelma]]] { halvinYhdistelma = yhdistelma; } } return halvinYhdistelma; }From source file:org.sosy_lab.cpachecker.util.templates.TemplatePrecision.java
From source file:org.apache.atlas.gremlin.optimizer.ExpandOrsOptimization.java
/** * This is called when we encounter an expression that is not an "or", for example an "and" expressio. For these * expressions, we process the children and create copies with the cartesian product of the updated * arguments./*ww w . j av a 2 s.c o m*/ * * Example: * * g.V[].and[or[has['x],has['y'], or[has['a'],has['b']]] * * Here, we have an "and" expression with two children: * * 1] or[has['x],has['y'] * 2] or[has['a'],has['b']] * * We first process these children. They each yield 2 expressions: * * 1 -> [ has['x'], has['y'] ] * 2 -> [ has['a'], has['b'] ] * * The cartesian product of these gives this: * * [ has['x'], has['a'] ] * [ has['x'], has['b'] ] * [ has['y'], has['a'] ] * [ has['y'], has['b'] ] * * So the overall result is: * * g.V[].and[has['x'], has['a']] * g.V[].and[has['x'], has['b']] * g.V[].and[has['y'], has['a']] * g.V[].and[has['y'], has['b']] * * * @param source * @param context * @return expressions that should be unioned together to get the query result */ private List processOtherExpression[GroovyExpression source, OptimizationContext context] { UpdatedExpressions updatedChildren = getUpdatedChildren[source, context]; if [!updatedChildren.hasChanges[]] { return Collections.singletonList[source]; } List result = new ArrayList[]; //The updated children list we get back has the possible values for each child //in the expression. We compute a cartesian product to get all possible //combinations of child values. List updateChildLists = Lists .cartesianProduct[updatedChildren.getUpdatedChildren[]]; for [List updatedChildList : updateChildLists] { result.add[source.copy[updatedChildList]]; } return result; }