diff options
Diffstat (limited to 'bigtop-bigpetstore')
33 files changed, 1086 insertions, 684 deletions
diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/Constants.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/Constants.java index 90b363ee..f43cf924 100644 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/Constants.java +++ b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/Constants.java @@ -42,7 +42,7 @@ public class Constants public static final File NAMEDB_FILE = new File("namedb/data/data.dat"); - public static final File PRODUCTS_FILE = new File("product_categories.json"); + public static final String PRODUCTS_COLLECTION = "small"; public static final double INCOME_SCALING_FACTOR = 100.0; @@ -89,8 +89,10 @@ public class Constants public static final double STATIC_FIELD_VALUE_WEIGHT_EXPONENTIAL = 2.0; - public static final String PRODUCT_QUANTITY = "size"; + public static final String PRODUCT_QUANTITY = "quantity"; public static final String PRODUCT_CATEGORY = "category"; + public static final String PRODUCT_UNIT_PRICE = "unitPrice"; + public static final String PRODUCT_PRICE = "price"; public static final double STOP_CATEGORY_WEIGHT = 0.01; } diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/DataLoader.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/DataLoader.java index fbd158d6..a67acd73 100644 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/DataLoader.java +++ b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/DataLoader.java @@ -18,15 +18,12 @@ package org.apache.bigtop.bigpetstore.datagenerator; import java.io.BufferedInputStream; import java.io.File; import java.io.InputStream; -import java.util.Collection; import java.util.List; import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.InputData; import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.Names; -import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ProductCategory; import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ZipcodeRecord; import org.apache.bigtop.bigpetstore.datagenerator.datareaders.NameReader; -import org.apache.bigtop.bigpetstore.datagenerator.datareaders.ProductsReader; import org.apache.bigtop.bigpetstore.datagenerator.datareaders.ZipcodeReader; public class DataLoader @@ -53,12 +50,7 @@ public class DataLoader Names names = nameReader.readData(); System.out.println("Read " + names.getFirstNames().size() + " first names and " + names.getLastNames().size() + " last names"); - System.out.println("Reading product data"); - ProductsReader reader = new ProductsReader(getResource(Constants.PRODUCTS_FILE)); - Collection<ProductCategory> productCategories = reader.readData(); - System.out.println("Read " + productCategories.size() + " product categories"); - - InputData inputData = new InputData(zipcodeTable, names, productCategories); + InputData inputData = new InputData(zipcodeTable, names); return inputData; } diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/ProductGenerator.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/ProductGenerator.java new file mode 100644 index 00000000..fb3e068c --- /dev/null +++ b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/ProductGenerator.java @@ -0,0 +1,39 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.bigtop.bigpetstore.datagenerator; + +import java.util.List; + +import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ProductCategory; +import org.apache.bigtop.bigpetstore.datagenerator.generators.products.collections.SmallProductCollection; + +public class ProductGenerator +{ + String collection; + + public ProductGenerator(String collection) + { + this.collection = collection; + } + + public List<ProductCategory> generate() + { + SmallProductCollection collection = new SmallProductCollection(); + List<ProductCategory> categories = collection.generateProductCategory(); + + return categories; + } +} diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/cli/Simulation.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/cli/Simulation.java index b3e07afe..f8bf18f1 100644 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/cli/Simulation.java +++ b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/cli/Simulation.java @@ -20,7 +20,9 @@ import java.util.Collections; import java.util.List; import java.util.Vector; +import org.apache.bigtop.bigpetstore.datagenerator.Constants; import org.apache.bigtop.bigpetstore.datagenerator.CustomerGenerator; +import org.apache.bigtop.bigpetstore.datagenerator.ProductGenerator; import org.apache.bigtop.bigpetstore.datagenerator.PurchasingModelGenerator; import org.apache.bigtop.bigpetstore.datagenerator.StoreGenerator; import org.apache.bigtop.bigpetstore.datagenerator.TransactionGenerator; @@ -28,6 +30,7 @@ import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Customer; import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Store; import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Transaction; import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.InputData; +import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ProductCategory; import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory; import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.RouletteWheelSampler; import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.Sampler; @@ -48,6 +51,7 @@ public class Simulation List<Customer> customers; Sampler<PurchasingModel> purchasingModelSampler; List<Transaction> transactions; + List<ProductCategory> productCategories; public Simulation(InputData inputData, int nStores, int nCustomers, int nPurchasingModels, double simulationTime, long seed) { @@ -93,10 +97,17 @@ public class Simulation System.out.println("Generated " + customers.size() + " customers"); } + public void generateProducts() + { + System.out.println("Generating products"); + ProductGenerator generator = new ProductGenerator(Constants.PRODUCTS_COLLECTION); + productCategories = generator.generate(); + } + public void generatePurchasingProfiles() throws Exception { System.out.println("Generating purchasing profiles"); - PurchasingModelGenerator generator = new PurchasingModelGenerator(inputData.getProductCategories(), seedFactory); + PurchasingModelGenerator generator = new PurchasingModelGenerator(productCategories, seedFactory); Collection<PurchasingModel> purchasingProfiles = new Vector<PurchasingModel>(); for(int i = 0; i < nPurchasingModels; i++) @@ -121,7 +132,7 @@ public class Simulation PurchasingModel profile = purchasingModelSampler.sample(); TransactionGenerator generator = new TransactionGenerator(customer, - profile, inputData.getProductCategories(), seedFactory); + profile, productCategories, seedFactory); while(true) { @@ -140,6 +151,7 @@ public class Simulation { generateStores(); generateCustomers(); + generateProducts(); generatePurchasingProfiles(); generateTransactions(); } diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datamodels/inputs/InputData.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datamodels/inputs/InputData.java index def554cc..4fad2196 100644 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datamodels/inputs/InputData.java +++ b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datamodels/inputs/InputData.java @@ -16,7 +16,6 @@ package org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs; import java.io.Serializable; -import java.util.Collection; import java.util.Collections; import java.util.List; @@ -26,15 +25,12 @@ public class InputData implements Serializable List<ZipcodeRecord> zipcodeTable; Names names; - Collection<ProductCategory> productCategories; public InputData(List<ZipcodeRecord> zipcodeTable, - Names names, - Collection<ProductCategory> productCategories) + Names names) { this.zipcodeTable = Collections.unmodifiableList(zipcodeTable); this.names = names; - this.productCategories = Collections.unmodifiableCollection(productCategories); } public List<ZipcodeRecord> getZipcodeTable() @@ -46,11 +42,4 @@ public class InputData implements Serializable { return names; } - - public Collection<ProductCategory> getProductCategories() - { - return productCategories; - } - - } diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datamodels/inputs/ProductCategory.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datamodels/inputs/ProductCategory.java index db40288a..6fb0572c 100644 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datamodels/inputs/ProductCategory.java +++ b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datamodels/inputs/ProductCategory.java @@ -105,8 +105,4 @@ public class ProductCategory implements Serializable { return products; } - - - - } diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datareaders/ProductsReader.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datareaders/ProductsReader.java deleted file mode 100644 index 91db010d..00000000 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datareaders/ProductsReader.java +++ /dev/null @@ -1,152 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.bigtop.bigpetstore.datagenerator.datareaders; - -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; -import java.util.List; -import java.util.Map; - -import org.apache.bigtop.bigpetstore.datagenerator.datamodels.PetSpecies; -import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Product; -import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ProductCategory; -import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ProductCategoryBuilder; - -import com.google.common.collect.Lists; -import com.google.gson.Gson; - -public class ProductsReader -{ - InputStream path; - - public ProductsReader(InputStream path) - { - this.path = path; - } - - protected Product parseProduct(Object productJson) - { - Map<String, Object> fields = (Map<String, Object>) productJson; - Product product = new Product(fields); - return product; - } - - protected ProductCategory parseProductCategory(Object productCategoryObject) throws Exception - { - Map<String, Object> jsonProductCategory = (Map<String, Object>) productCategoryObject; - - ProductCategoryBuilder builder = new ProductCategoryBuilder(); - - for(Map.Entry<String, Object> entry : jsonProductCategory.entrySet()) - { - Object key = entry.getKey(); - Object value = entry.getValue(); - - if(key.equals("category")) - { - builder.setCategory( (String) entry.getValue()); - } - else if(key.equals("species")) - { - for(String species : (List<String>) value) - { - if(species.equals("dog")) - { - builder.addApplicableSpecies(PetSpecies.DOG); - } - else if(species.equals("cat")) - { - builder.addApplicableSpecies(PetSpecies.CAT); - } - else - { - throw new Exception("Invalid species " + species + " encountered when parsing product categories JSON."); - } - } - } - else if(key.equals("trigger_transaction")) - { - builder.setTriggerTransaction((Boolean) entry.getValue()); - } - else if(key.equals("fields")) - { - for(String fieldName : (List<String>) value) - { - builder.addFieldName(fieldName); - } - } - else if(key.equals("daily_usage_rate")) - { - builder.setDailyUsageRate((Double) value); - } - else if(key.equals("base_amount_used_average")) - { - builder.setAmountUsedPetPetAverage((Double) value); - } - else if(key.equals("base_amount_used_variance")) - { - builder.setAmountUsedPetPetVariance((Double) value); - } - else if(key.equals("transaction_trigger_rate")) - { - builder.setTriggerTransactionRate((Double) value); - } - else if(key.equals("transaction_purchase_rate")) - { - builder.setTriggerPurchaseRate((Double) value); - } - else if(key.equals("items")) - { - for(Object productJson : (List<Object>) value) - { - Product product = parseProduct(productJson); - builder.addProduct(product); - } - } - else - { - throw new Exception("Invalid field " + key + " encountered when parsing product categories JSON."); - } - - } - - return builder.build(); - } - - public List<ProductCategory> readData() throws Exception - { - Gson gson = new Gson(); - - Reader reader = new InputStreamReader(path); - Object json = gson.fromJson(reader, Object.class); - - List<Object> productCategoryObjects = (List<Object>) json; - - List<ProductCategory> productCategories = Lists.newArrayList(); - - for(Object obj : productCategoryObjects) - { - ProductCategory productCategory = parseProductCategory(obj); - productCategories.add(productCategory); - } - - reader.close(); - - return productCategories; - - } -} diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/ProductBuilderIterator.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/ProductBuilderIterator.java new file mode 100644 index 00000000..c7dd0ab7 --- /dev/null +++ b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/ProductBuilderIterator.java @@ -0,0 +1,80 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.bigtop.bigpetstore.datagenerator.generators.products; + +import java.util.Iterator; +import java.util.Map; + +import org.apache.bigtop.bigpetstore.datagenerator.Constants; +import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Product; + +import com.google.common.collect.Maps; + +public class ProductBuilderIterator implements Iterator<Product> +{ + Iterator<Map<String, ProductFieldValue>> productIterator; + double basePrice; + String productCategory; + + public ProductBuilderIterator(double basePrice, String productCategory, + Iterator<Map<String, ProductFieldValue>> productIterator) + { + this.productIterator = productIterator; + this.basePrice = basePrice; + this.productCategory = productCategory; + } + + @Override + public boolean hasNext() + { + return productIterator != null && productIterator.hasNext(); + } + + @Override + public Product next() + { + Map<String, ProductFieldValue> productComponents = productIterator.next(); + + double sum = 0.0; + double product = 1.0; + + Map<String, Object> productFields = Maps.newHashMap(); + + for(Map.Entry<String, ProductFieldValue> entry : productComponents.entrySet()) + { + productFields.put(entry.getKey(), entry.getValue().getValue()); + sum += entry.getValue().getAdd(); + product *= entry.getValue().getMultiply(); + } + + double quantity = (Double) productFields.get(Constants.PRODUCT_QUANTITY); + double price = product * (sum + basePrice); + double unitPrice = price / quantity; + + productFields.put(Constants.PRODUCT_UNIT_PRICE, unitPrice); + productFields.put(Constants.PRODUCT_PRICE, price); + productFields.put(Constants.PRODUCT_CATEGORY, productCategory); + + return new Product(productFields); + } + + @Override + public void remove() + { + throw new UnsupportedOperationException("ProductBuilder does not support remove()"); + } + +} diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datamodels/inputs/ProductCategoryBuilder.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/ProductCategoryBuilder.java index ee5fd62c..df8ae125 100644 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datamodels/inputs/ProductCategoryBuilder.java +++ b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/ProductCategoryBuilder.java @@ -13,36 +13,48 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs; +package org.apache.bigtop.bigpetstore.datagenerator.generators.products; +import java.util.Arrays; +import java.util.Collection; +import java.util.Iterator; import java.util.List; +import java.util.Map; import java.util.Set; +import java.util.Vector; +import org.apache.bigtop.bigpetstore.datagenerator.Constants; import org.apache.bigtop.bigpetstore.datagenerator.datamodels.PetSpecies; import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Product; +import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ProductCategory; +import org.apache.bigtop.bigpetstore.datagenerator.generators.products.rules.AlwaysTrueRule; +import org.apache.bigtop.bigpetstore.datagenerator.generators.products.rules.NotRule; +import org.apache.bigtop.bigpetstore.datagenerator.generators.products.rules.OrRule; +import org.apache.bigtop.bigpetstore.datagenerator.generators.products.rules.Rule; import com.google.common.collect.Lists; +import com.google.common.collect.Maps; import com.google.common.collect.Sets; public class ProductCategoryBuilder { String categoryLabel; Set<PetSpecies> applicableSpecies; - Set<String> fieldNames; Boolean triggerTransaction; Double dailyUsageRate; Double amountUsedPerPetAverage; Double amountUsedPerPetVariance; Double triggerTransactionRate; Double triggerPurchaseRate; + List<Rule> exclusionRules; + Map<String, Collection<ProductFieldValue>> productFieldValues; + Double basePrice; List<Product> products; - + public ProductCategoryBuilder() { applicableSpecies = Sets.newHashSet(); - fieldNames = Sets.newHashSet(); - products = Lists.newArrayList(); - + dailyUsageRate = 0.0; amountUsedPerPetAverage = 0.0; amountUsedPerPetVariance = 0.0; @@ -50,82 +62,132 @@ public class ProductCategoryBuilder triggerPurchaseRate = 0.0; triggerTransaction = false; categoryLabel = null; + exclusionRules = new Vector<Rule>(); + productFieldValues = Maps.newHashMap(); + basePrice = 1.0; + products = Lists.newArrayList(); } - + public void setCategory(String category) { this.categoryLabel = category; } - + public void setTriggerTransaction(Boolean triggerTransaction) { this.triggerTransaction = triggerTransaction; } - + public void setDailyUsageRate(Double dailyUsageRate) { this.dailyUsageRate = dailyUsageRate; } - + public void setAmountUsedPetPetAverage(Double baseAmountUsedAverage) { this.amountUsedPerPetAverage = baseAmountUsedAverage; } - + public void setAmountUsedPetPetVariance(Double baseAmountUsedVariance) { this.amountUsedPerPetVariance = baseAmountUsedVariance; } - + public void setTriggerTransactionRate(Double triggerTransactionRate) { this.triggerTransactionRate = triggerTransactionRate; } - + public void setTriggerPurchaseRate(Double triggerPurchaseRate) { this.triggerPurchaseRate = triggerPurchaseRate; } - + public void addApplicableSpecies(PetSpecies species) { this.applicableSpecies.add(species); } - - public void addFieldName(String fieldName) + + public void addProduct(Product product) { - this.fieldNames.add(fieldName); + products.add(product); } - - public void addProduct(Product product) + + public void addExclusionRule(Rule rule) + { + this.exclusionRules.add(rule); + } + + public void addPropertyValues(String fieldName, ProductFieldValue ... values) { - this.products.add(product); + this.productFieldValues.put(fieldName, Arrays.asList(values)); } - - protected boolean validateProducts() + + public void setBasePrice(double basePrice) + { + this.basePrice = basePrice; + } + + + protected List<Product> generateProducts() + { + Rule combinedRules = new NotRule(new AlwaysTrueRule()); + if(exclusionRules.size() == 1) + { + combinedRules = exclusionRules.get(0); + } + else if(exclusionRules.size() > 1) + { + combinedRules = new OrRule(exclusionRules.toArray(new Rule[] {})); + } + + Iterator<Product> productIterator = new ProductIterator(productFieldValues, combinedRules, + basePrice, categoryLabel); + + while(productIterator.hasNext()) + { + products.add(productIterator.next()); + } + + return products; + } + + public void validateProducts() { for(Product product : products) { - for(String fieldName : product.getFieldNames()) + if(!product.getFieldNames().contains(Constants.PRODUCT_CATEGORY)) + { + throw new IllegalStateException("Product must have field " + Constants.PRODUCT_CATEGORY); + } + + if(!product.getFieldNames().contains(Constants.PRODUCT_QUANTITY)) + { + throw new IllegalStateException("Product must have field " + Constants.PRODUCT_QUANTITY); + } + + if(!product.getFieldNames().contains(Constants.PRODUCT_PRICE)) { - if(!fieldNames.contains(fieldName)) - return false; + throw new IllegalStateException("Product must have field " + Constants.PRODUCT_PRICE); } - - for(String fieldName : fieldNames) + + if(!product.getFieldNames().contains(Constants.PRODUCT_UNIT_PRICE)) { - if(!product.getFieldNames().contains(fieldName)) - return false; + throw new IllegalStateException("Product must have field " + Constants.PRODUCT_UNIT_PRICE); } } - - return true; } - + public ProductCategory build() { - validateProducts(); - + List<Product> products = generateProducts(); + + Set<String> fieldNames = Sets.newHashSet(); + for(Product product : products) + { + fieldNames.addAll(product.getFieldNames()); + } + return new ProductCategory(categoryLabel, applicableSpecies, fieldNames, triggerTransaction, dailyUsageRate, amountUsedPerPetAverage, amountUsedPerPetVariance, triggerTransactionRate, triggerPurchaseRate, products); diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/ProductFieldValue.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/ProductFieldValue.java new file mode 100644 index 00000000..fe4d7fa1 --- /dev/null +++ b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/ProductFieldValue.java @@ -0,0 +1,45 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.bigtop.bigpetstore.datagenerator.generators.products; + +public class ProductFieldValue +{ + Object value; + double add; + double multiply; + + public ProductFieldValue(Object value, double add, double multiply) + { + this.value = value; + this.add = add; + this.multiply = multiply; + } + + public Object getValue() + { + return value; + } + + public double getAdd() + { + return add; + } + + public double getMultiply() + { + return multiply; + } +} diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/ProductFilterIterator.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/ProductFilterIterator.java new file mode 100644 index 00000000..c0e285da --- /dev/null +++ b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/ProductFilterIterator.java @@ -0,0 +1,72 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.bigtop.bigpetstore.datagenerator.generators.products; + +import java.util.Iterator; + +import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Product; +import org.apache.bigtop.bigpetstore.datagenerator.generators.products.rules.Rule; + +public class ProductFilterIterator implements Iterator<Product> +{ + Rule rule; + Iterator<Product> products; + Product buffer; + + public ProductFilterIterator(Rule rule, Iterator<Product> products) + { + this.rule = rule; + this.products = products; + this.buffer = getNext(); + } + + private Product getNext() + { + while(products.hasNext()) + { + Product product = products.next(); + + if(!rule.ruleMatches(product)) + { + return product; + } + } + + return null; + } + + @Override + public boolean hasNext() + { + return buffer != null; + } + + @Override + public Product next() + { + Product previous = buffer; + buffer = getNext(); + + return previous; + } + + @Override + public void remove() + { + throw new UnsupportedOperationException("ProductFilter does not support remove()"); + } + +} diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/ProductIterator.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/ProductIterator.java new file mode 100644 index 00000000..ccfef56f --- /dev/null +++ b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/ProductIterator.java @@ -0,0 +1,78 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.bigtop.bigpetstore.datagenerator.generators.products; + +import java.util.Collection; +import java.util.Iterator; +import java.util.Map; + +import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Product; +import org.apache.bigtop.bigpetstore.datagenerator.generators.products.cartesian.CartesianProduct; +import org.apache.bigtop.bigpetstore.datagenerator.generators.products.cartesian.CartesianProductBase; +import org.apache.bigtop.bigpetstore.datagenerator.generators.products.cartesian.CartesianProductField; +import org.apache.bigtop.bigpetstore.datagenerator.generators.products.rules.Rule; + +public class ProductIterator implements Iterator<Product> +{ + + Iterator<Product> productIterator; + + public ProductIterator(Map<String, Collection<ProductFieldValue>> fieldValues, Rule matcher, + double basePrice, String productCategory) + { + productIterator = new ProductFilterIterator(matcher, + new ProductBuilderIterator(basePrice, productCategory, + buildCartesianProductIterator(fieldValues))); + } + + public Iterator<Map<String, ProductFieldValue>> + buildCartesianProductIterator(Map<String, Collection<ProductFieldValue>> fieldValues) + { + CartesianProduct<ProductFieldValue> product = null; + for(Map.Entry<String, Collection<ProductFieldValue>> pair : fieldValues.entrySet()) + { + if(product == null) + { + product = new CartesianProductBase<ProductFieldValue>(pair.getKey(), pair.getValue()); + } else + { + product = new CartesianProductField<ProductFieldValue>(pair.getKey(), pair.getValue(), product); + } + + } + + return product; + } + + @Override + public boolean hasNext() + { + return productIterator.hasNext(); + } + + @Override + public Product next() + { + return productIterator.next(); + } + + @Override + public void remove() + { + throw new UnsupportedOperationException("ProductIterator does not support remove()"); + } + +} diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/cartesian/CartesianProduct.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/cartesian/CartesianProduct.java new file mode 100644 index 00000000..f6889808 --- /dev/null +++ b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/cartesian/CartesianProduct.java @@ -0,0 +1,24 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.bigtop.bigpetstore.datagenerator.generators.products.cartesian; + +import java.util.Iterator; +import java.util.Map; + +public interface CartesianProduct<T> extends Iterator<Map<String, T>> +{ + +} diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/cartesian/CartesianProductBase.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/cartesian/CartesianProductBase.java new file mode 100644 index 00000000..7b0934c6 --- /dev/null +++ b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/cartesian/CartesianProductBase.java @@ -0,0 +1,56 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.bigtop.bigpetstore.datagenerator.generators.products.cartesian; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + + +public class CartesianProductBase<T> implements CartesianProduct<T> +{ + String fieldName; + Iterator<T> fieldValues; + + public CartesianProductBase(String fieldName, Collection<T> fieldValues) + { + this.fieldName = fieldName; + this.fieldValues = fieldValues.iterator(); + } + + + @Override + public boolean hasNext() + { + return fieldValues.hasNext(); + } + + @Override + public Map<String, T> next() + { + Map<String, T> map = new HashMap<String, T>(); + map.put(fieldName, fieldValues.next()); + + return map; + } + + @Override + public void remove() + { + throw new UnsupportedOperationException("CartesianProductBase does not support remove()"); + } +} diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/cartesian/CartesianProductField.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/cartesian/CartesianProductField.java new file mode 100644 index 00000000..166efc8b --- /dev/null +++ b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/cartesian/CartesianProductField.java @@ -0,0 +1,79 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.bigtop.bigpetstore.datagenerator.generators.products.cartesian; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.NoSuchElementException; + +public class CartesianProductField<T> implements CartesianProduct<T> +{ + String fieldName; + Iterator<T> fieldValuesIterator; + Collection<T> fieldValues; + CartesianProduct<T> previous; + Map<String, T> baseValue; + + public CartesianProductField(String fieldName, Collection<T> fieldValues, CartesianProduct<T> previous) + { + this.fieldValues = fieldValues; + this.fieldName = fieldName; + this.previous = previous; + } + + @Override + public boolean hasNext() + { + return previous.hasNext() || (fieldValuesIterator != null && fieldValuesIterator.hasNext()); + } + + @Override + public Map<String, T> next() + { + if(fieldValuesIterator != null) + { + Map<String, T> map = new HashMap<String, T>(baseValue); + map.put(fieldName, fieldValuesIterator.next()); + + if(!fieldValuesIterator.hasNext()) + { + fieldValuesIterator = null; + } + + return map; + } else if(previous.hasNext()) + { + baseValue = previous.next(); + fieldValuesIterator = fieldValues.iterator(); + + Map<String, T> map = new HashMap<String, T>(baseValue); + map.put(fieldName, fieldValuesIterator.next()); + + return map; + } + + throw new NoSuchElementException(); + } + + @Override + public void remove() + { + throw new UnsupportedOperationException("CartesianProductBase does not support remove()"); + } + +} diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/collections/SmallProductCollection.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/collections/SmallProductCollection.java new file mode 100644 index 00000000..8ca71ef7 --- /dev/null +++ b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/collections/SmallProductCollection.java @@ -0,0 +1,162 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.bigtop.bigpetstore.datagenerator.generators.products.collections; + +import java.util.List; + +import org.apache.bigtop.bigpetstore.datagenerator.datamodels.PetSpecies; +import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ProductCategory; +import org.apache.bigtop.bigpetstore.datagenerator.generators.products.ProductCategoryBuilder; +import org.apache.bigtop.bigpetstore.datagenerator.generators.products.ProductFieldValue; + +import com.google.common.collect.Lists; + +public class SmallProductCollection +{ + private ProductCategory createDogFood() + { + ProductCategoryBuilder builder = new ProductCategoryBuilder(); + + builder.addApplicableSpecies(PetSpecies.DOG); + builder.setCategory("dry dog food"); + builder.setTriggerTransaction(true); + builder.setDailyUsageRate(2.0); + builder.setAmountUsedPetPetAverage(0.25); + builder.setAmountUsedPetPetVariance(0.1); + builder.setTriggerTransactionRate(2.0); + builder.setTriggerPurchaseRate(7.0); + builder.setBasePrice(2.0); + + builder.addPropertyValues("brand", + new ProductFieldValue("Wellfed", 0.0, 1.0), + new ProductFieldValue("Happy Pup", 0.67, 1.0), + new ProductFieldValue("Dog Days", 1.0, 1.0)); + + builder.addPropertyValues("flavor", + new ProductFieldValue("Chicken", 0.0, 1.0), + new ProductFieldValue("Pork", 0.0, 1.0), + new ProductFieldValue("Lamb & Rice", 0.0, 1.0), + new ProductFieldValue("Fish & Potato", 0.0, 1.0)); + + builder.addPropertyValues("quantity", + new ProductFieldValue(4.5, 0.0, 4.5), + new ProductFieldValue(15.0, 0.0, 15.0), + new ProductFieldValue(30.0, 0.0, 30.0)); + + return builder.build(); + } + + private ProductCategory createCatFood() + { + ProductCategoryBuilder builder = new ProductCategoryBuilder(); + + builder.addApplicableSpecies(PetSpecies.CAT); + builder.setCategory("dry cat food"); + builder.setTriggerTransaction(true); + builder.setDailyUsageRate(2.0); + builder.setAmountUsedPetPetAverage(0.1); + builder.setAmountUsedPetPetVariance(0.05); + builder.setTriggerTransactionRate(2.0); + builder.setTriggerPurchaseRate(7.0); + builder.setBasePrice(2.14); + + builder.addPropertyValues("brand", + new ProductFieldValue("Wellfed", 0.0, 1.0), + new ProductFieldValue("Pretty Cat", 0.72, 1.0), + new ProductFieldValue("Feisty Feline", 0.0, 1.0)); + + builder.addPropertyValues("flavor", + new ProductFieldValue("Tuna", 0.0, 1.0), + new ProductFieldValue("Chicken & Rice", 0.0, 1.0)); + + builder.addPropertyValues("quantity", + new ProductFieldValue(7.0, 0.0, 7.0), + new ProductFieldValue(15.0, 0.0, 15.0)); + + builder.addPropertyValues("hairball management", + new ProductFieldValue("true", 0.0, 1.0), + new ProductFieldValue("false", 0.0, 1.0)); + + return builder.build(); + } + + private ProductCategory createKittyLitter() + { + ProductCategoryBuilder builder = new ProductCategoryBuilder(); + + builder.addApplicableSpecies(PetSpecies.CAT); + builder.setCategory("kitty litter"); + builder.setTriggerTransaction(true); + builder.setDailyUsageRate(1.0); + builder.setAmountUsedPetPetAverage(0.1); + builder.setAmountUsedPetPetVariance(0.05); + builder.setTriggerTransactionRate(2.0); + builder.setTriggerPurchaseRate(7.0); + builder.setBasePrice(1.43); + + builder.addPropertyValues("brand", + new ProductFieldValue("Pretty Cat", 0.0, 1.0), + new ProductFieldValue("Feisty Feline", 0.07, 1.0)); + + builder.addPropertyValues("quantity", + new ProductFieldValue(7.0, 0.0, 7.0), + new ProductFieldValue(14.0, 0.0, 14.0), + new ProductFieldValue(28.0, 0.0, 28.0)); + + return builder.build(); + } + + private ProductCategory createPoopBags() + { + ProductCategoryBuilder builder = new ProductCategoryBuilder(); + + builder.addApplicableSpecies(PetSpecies.DOG); + builder.setCategory("poop bags"); + builder.setTriggerTransaction(true); + builder.setDailyUsageRate(2.0); + builder.setAmountUsedPetPetAverage(1.0); + builder.setAmountUsedPetPetVariance(0.5); + builder.setTriggerTransactionRate(2.0); + builder.setTriggerPurchaseRate(7.0); + builder.setBasePrice(0.17); + + builder.addPropertyValues("brand", + new ProductFieldValue("Happy Pup", 0.0, 1.0), + new ProductFieldValue("Dog Days", 0.04, 1.0)); + + builder.addPropertyValues("color", + new ProductFieldValue("blue", 0.0, 1.0), + new ProductFieldValue("multicolor", 0.0, 1.0)); + + builder.addPropertyValues("quantity", + new ProductFieldValue(60.0, 0.0, 60.0), + new ProductFieldValue(120.0, 0.0, 120.0)); + + return builder.build(); + } + + public List<ProductCategory> generateProductCategory() + { + List<ProductCategory> productCategories = Lists.newArrayList(); + + productCategories.add(this.createDogFood()); + productCategories.add(this.createCatFood()); + productCategories.add(this.createKittyLitter()); + productCategories.add(this.createPoopBags()); + + return productCategories; + } +} diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/AlwaysTrueRule.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/AlwaysTrueRule.java new file mode 100644 index 00000000..d9733461 --- /dev/null +++ b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/AlwaysTrueRule.java @@ -0,0 +1,29 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.bigtop.bigpetstore.datagenerator.generators.products.rules; + +import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Product; + +public class AlwaysTrueRule implements Rule +{ + + @Override + public boolean ruleMatches(Product product) throws IllegalArgumentException + { + return true; + } + +} diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/AndRule.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/AndRule.java new file mode 100644 index 00000000..4be89be1 --- /dev/null +++ b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/AndRule.java @@ -0,0 +1,50 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.bigtop.bigpetstore.datagenerator.generators.products.rules; + +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; + +import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Product; + +public class AndRule implements Rule +{ + List<Rule> rules; + + public AndRule(Rule rule1, Rule rule2, Rule ... rules) + { + this.rules = new LinkedList<Rule>(Arrays.asList(rules)); + this.rules.add(rule1); + this.rules.add(rule2); + } + + @Override + public boolean ruleMatches(Product product) throws IllegalArgumentException + { + boolean matches = true; + for(Rule rule : rules) + { + if(! rule.ruleMatches(product)) + { + matches = false; + } + } + + return matches; + } + +} diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/FieldPredicate.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/FieldPredicate.java new file mode 100644 index 00000000..37e7c12a --- /dev/null +++ b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/FieldPredicate.java @@ -0,0 +1,48 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.bigtop.bigpetstore.datagenerator.generators.products.rules; + +import java.util.Arrays; +import java.util.Collection; + +import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Product; + +public class FieldPredicate implements Rule +{ + String fieldName; + Collection<String> allowedValues; + + public FieldPredicate(String fieldName, String ... allowedValues) + { + this.fieldName = fieldName; + this.allowedValues = Arrays.asList(allowedValues); + } + + @Override + public boolean ruleMatches(Product product) + { + if(! product.getFieldNames().contains(fieldName)) + { + throw new IllegalArgumentException("Product (" + product.toString() + + ") does not contain field name (" + fieldName + ")"); + } + + Object seenValue = product.getFieldValue(fieldName); + + return allowedValues.contains(seenValue); + } + +} diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/NotRule.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/NotRule.java new file mode 100644 index 00000000..ffac751e --- /dev/null +++ b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/NotRule.java @@ -0,0 +1,36 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.bigtop.bigpetstore.datagenerator.generators.products.rules; + +import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Product; + +public class NotRule implements Rule +{ + Rule rule; + + public NotRule(Rule rule) + { + this.rule = rule; + } + + + @Override + public boolean ruleMatches(Product product) throws IllegalArgumentException + { + return ! rule.ruleMatches(product); + } + +} diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/OrRule.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/OrRule.java new file mode 100644 index 00000000..c3ed549f --- /dev/null +++ b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/OrRule.java @@ -0,0 +1,43 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.bigtop.bigpetstore.datagenerator.generators.products.rules; + +import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Product; + +public class OrRule implements Rule +{ + Rule[] rules; + + public OrRule(Rule ... rules) + { + this.rules = rules; + } + + @Override + public boolean ruleMatches(Product product) throws IllegalArgumentException + { + for(Rule rule : rules) + { + if(rule.ruleMatches(product)) + { + return true; + } + } + + return false; + } + +} diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/Rule.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/Rule.java new file mode 100644 index 00000000..4aa7945f --- /dev/null +++ b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/rules/Rule.java @@ -0,0 +1,23 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.bigtop.bigpetstore.datagenerator.generators.products.rules; + +import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Product; + +public interface Rule +{ + public boolean ruleMatches(Product product) throws IllegalArgumentException; +} diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/resources/input_data/product_categories.json b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/resources/input_data/product_categories.json deleted file mode 100644 index 4c880bd3..00000000 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/resources/input_data/product_categories.json +++ /dev/null @@ -1,440 +0,0 @@ -[ - { - "category" : "dry dog food", - "species" : ["dog"], - "trigger_transaction" : true, - "fields" : ["brand", "flavor", "size"], - "daily_usage_rate" : 2.0, - "base_amount_used_average" : 0.25, - "base_amount_used_variance" : 0.1, - "transaction_trigger_rate" : 2.0, - "transaction_purchase_rate" : 7.0, - "items" : - [ - { - "category" : "dry dog food", - "brand" : "Wellfed", - "flavor" : "Chicken", - "size" : 15.0, - "per_unit_cost" : 2.00 - }, - { - "category" : "dry dog food", - "brand" : "Wellfed", - "flavor" : "Pork", - "size" : 15.0, - "per_unit_cost" : 2.00 - }, - { - "category" : "dry dog food", - "brand" : "Wellfed", - "flavor" : "Lamb & Rice", - "size" : 15.0, - "per_unit_cost" : 2.00 - }, - { - "category" : "dry dog food", - "brand" : "Wellfed", - "flavor" : "Fish & Potato", - "size" : 15.0, - "per_unit_cost" : 2.00 - }, - { - "category" : "dry dog food", - "brand" : "Wellfed", - "flavor" : "Chicken", - "size" : 30.0, - "per_unit_cost" : 2.00 - }, - { - "category" : "dry dog food", - "brand" : "Wellfed", - "flavor" : "Pork", - "size" : 30.0, - "per_unit_cost" : 2.00 - }, - { - "category" : "dry dog food", - "brand" : "Wellfed", - "flavor" : "Lamb & Rice", - "size" : 30.0, - "per_unit_cost" : 2.00 - }, - { - "category" : "dry dog food", - "brand" : "Wellfed", - "flavor" : "Fish & Potato", - "size" : 30.0, - "per_unit_cost" : 2.00 - }, - { - "category" : "dry dog food", - "brand" : "Happy Pup", - "flavor" : "Chicken", - "size" : 15.0, - "per_unit_cost" : 2.67 - }, - { - "category" : "dry dog food", - "brand" : "Happy Pup", - "flavor" : "Pork", - "size" : 15.0, - "per_unit_cost" : 2.67 - }, - { - "category" : "dry dog food", - "brand" : "Happy Pup", - "flavor" : "Lamb & Rice", - "size" : 15.0, - "per_unit_cost" : 2.67 - }, - { - "category" : "dry dog food", - "brand" : "Happy Pup", - "flavor" : "Fish & Potato", - "size" : 15.0, - "per_unit_cost" : 2.67 - }, - { - "category" : "dry dog food", - "brand" : "Happy Pup", - "flavor" : "Chicken", - "size" : 30.0, - "per_unit_cost" : 2.67 - }, - { - "category" : "dry dog food", - "brand" : "Happy Pup", - "flavor" : "Pork", - "size" : 30.0, - "per_unit_cost" : 2.67 - }, - { - "category" : "dry dog food", - "brand" : "Happy Pup", - "flavor" : "Lamb & Rice", - "size" : 30.0, - "per_unit_cost" : 2.67 - }, - { - "category" : "dry dog food", - "brand" : "Happy Pup", - "flavor" : "Fish & Potato", - "size" : 30.0, - "per_unit_cost" : 2.67 - }, - { - "category" : "dry dog food", - "brand" : "Dog Days", - "flavor" : "Chicken", - "size" : 15.0, - "per_unit_cost" : 3.00 - }, - { - "category" : "dry dog food", - "brand" : "Dog Days", - "flavor" : "Pork", - "size" : 15.0, - "per_unit_cost" : 3.00 - }, - { - "category" : "dry dog food", - "brand" : "Dog Days", - "flavor" : "Lamb & Rice", - "size" : 15.0, - "per_unit_cost" : 3.00 - }, - { - "category" : "dry dog food", - "brand" : "Dog Days", - "flavor" : "Fish & Potato", - "size" : 15.0, - "per_unit_cost" : 3.00 - }, - { - "category" : "dry dog food", - "brand" : "Dog Days", - "flavor" : "Chicken", - "size" : 30.0, - "per_unit_cost" : 3.00 - }, - { - "category" : "dry dog food", - "brand" : "Dog Days", - "flavor" : "Pork", - "size" : 30.0, - "per_unit_cost" : 3.00 - }, - { - "category" : "dry dog food", - "brand" : "Dog Days", - "flavor" : "Lamb & Rice", - "size" : 30.0, - "per_unit_cost" : 3.00 - }, - { - "category" : "dry dog food", - "brand" : "Dog Days", - "flavor" : "Fish & Potato", - "size" : 30.0, - "per_unit_cost" : 3.00 - } - ] - }, - { - "category" : "dry cat food", - "species" : ["cat"], - "trigger_transaction" : true, - "fields" : ["brand", "flavor", "size"], - "daily_usage_rate" : 2.0, - "base_amount_used_average" : 0.1, - "base_amount_used_variance" : 0.05, - "transaction_trigger_rate" : 2.0, - "transaction_purchase_rate" : 7.0, - "items" : - [ - { - "category" : "dry cat food", - "brand" : "Pretty Cat", - "flavor" : "Chicken & Rice (Hairball Management)", - "size" : 7.0, - "per_unit_cost" : 2.86 - }, - { - "category" : "dry cat food", - "brand" : "Pretty Cat", - "flavor" : "Tuna", - "size" : 7.0, - "per_unit_cost" : 2.86 - }, - { - "category" : "dry cat food", - "brand" : "Pretty Cat", - "flavor" : "Chicken & Rice", - "size" : 15.0, - "per_unit_cost" : 2.86 - }, - { - "category" : "dry cat food", - "brand" : "Pretty Cat", - "flavor" : "Chicken & Rice (Hairball Management)", - "size" : 15.0, - "per_unit_cost" : 2.86 - }, - { - "category" : "dry cat food", - "brand" : "Pretty Cat", - "flavor" : "Tuna", - "size" : 15.0, - "per_unit_cost" : 2.86 - }, - { - "category" : "dry cat food", - "brand" : "Wellfed", - "flavor" : "Chicken & Rice", - "size" : 7.0, - "per_unit_cost" : 2.14 - }, - { - "category" : "dry cat food", - "brand" : "Wellfed", - "flavor" : "Chicken & Rice (Hairball Management)", - "size" : 7.0, - "per_unit_cost" : 2.14 - }, - { - "category" : "dry cat food", - "brand" : "Wellfed", - "flavor" : "Tuna", - "size" : 7.0, - "per_unit_cost" : 2.14 - }, - { - "category" : "dry cat food", - "brand" : "Wellfed", - "flavor" : "Chicken & Rice", - "size" : 14.0, - "per_unit_cost" : 2.14 - }, - { - "category" : "dry cat food", - "brand" : "Wellfed", - "flavor" : "Chicken & Rice (Hairball Management)", - "size" : 14.0, - "per_unit_cost" : 2.14 - }, - { - "category" : "dry cat food", - "brand" : "Wellfed", - "flavor" : "Tuna", - "size" : 14.0, - "per_unit_cost" : 2.14 - }, - { - "category" : "dry cat food", - "brand" : "Feisty Feline", - "flavor" : "Chicken & Rice", - "size" : 7.0, - "per_unit_cost" : 2.14 - }, - { - "category" : "dry cat food", - "brand" : "Feisty Feline", - "flavor" : "Chicken & Rice (Hairball Management)", - "size" : 7.0, - "per_unit_cost" : 2.14 - }, - { - "category" : "dry cat food", - "brand" : "Feisty Feline", - "flavor" : "Tuna", - "size" : 7.0, - "per_unit_cost" : 2.14 - }, - { - "category" : "dry cat food", - "brand" : "Feisty Feline", - "flavor" : "Chicken & Rice", - "size" : 14.0, - "per_unit_cost" : 2.14 - }, - { - "category" : "dry cat food", - "brand" : "Feisty Feline", - "flavor" : "Chicken & Rice (Hairball Management)", - "size" : 14.0, - "per_unit_cost" : 2.14 - }, - { - "category" : "dry cat food", - "brand" : "Feisty Feline", - "flavor" : "Tuna", - "size" : 14.0, - "per_unit_cost" : 2.14 - } - ] - }, - { - "category" : "kitty litter", - "species" : ["cat"], - "trigger_transaction" : true, - "fields" : ["brand", "size"], - "daily_usage_rate" : 1.0, - "base_amount_used_average" : 0.1, - "base_amount_used_variance" : 0.05, - "transaction_trigger_rate" : 2.0, - "transaction_purchase_rate" : 7.0, - "items" : - [ - { - "category" : "kitty litter", - "brand" : "Pretty Cat", - "size" : 7, - "per_unit_cost" : 1.43 - } - , - { - "category" : "kitty litter", - "brand" : "Pretty Cat", - "size" : 14, - "per_unit_cost" : 1.43 - }, - { - "category" : "kitty litter", - "brand" : "Pretty Cat", - "size" : 28, - "per_unit_cost" : 1.43 - }, - { - "category" : "kitty litter", - "brand" : "Fiesty Feline", - "size" : 7, - "per_unit_cost" : 1.50 - } - , - { - "category" : "kitty litter", - "brand" : "Fiesty Feline", - "size" : 14, - "per_unit_cost" : 1.50 - }, - { - "category" : "kitty litter", - "brand" : "Feisty Feline", - "size" : 28, - "per_unit_cost" : 1.50 - } - ] - - }, - { - "category" : "poop bags", - "species" : ["dog"], - "trigger_transaction" : true, - "fields" : ["brand", "color", "size"], - "daily_usage_rate" : 2.0, - "base_amount_used_average" : 1.0, - "base_amount_used_variance" : 0.5, - "transaction_trigger_rate" : 2.0, - "transaction_purchase_rate" : 7.0, - "items" : - [ - { - "category" : "poop bags", - "brand" : "Happy Pup", - "color" : "Blue", - "size" : 60, - "per_unit_cost" : 0.17 - }, - { - "category" : "poop bags", - "brand" : "Happy Pup", - "color" : "Blue", - "size" : 120, - "per_unit_cost" : 0.17 - }, - { - "category" : "poop bags", - "brand" : "Happy Pup", - "color" : "multicolor", - "size" : 60, - "per_unit_cost" : 0.17 - }, - { - "category" : "poop bags", - "brand" : "Happy Pup", - "color" : "multicolor", - "size" : 120, - "per_unit_cost" : 0.17 - }, - { - "category" : "poop bags", - "brand" : "Dog Days", - "color" : "Blue", - "size" : 60, - "per_unit_cost" : 0.21 - }, - { - "category" : "poop bags", - "brand" : "Dog Days", - "color" : "Blue", - "size" : 120, - "per_unit_cost" : 0.21 - }, - { - "category" : "poop bags", - "brand" : "Dog Days", - "color" : "multicolor", - "size" : 60, - "per_unit_cost" : 0.21 - }, - { - "category" : "poop bags", - "brand" : "Dog Days", - "color" : "multicolor", - "size" : 120, - "per_unit_cost" : 0.21 - } - ] - } -] diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/customer/TestCustomerSamplerBuilder.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/customer/TestCustomerSamplerBuilder.java index cd920522..fdff8267 100644 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/customer/TestCustomerSamplerBuilder.java +++ b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/customer/TestCustomerSamplerBuilder.java @@ -18,7 +18,6 @@ package org.apache.bigtop.bigpetstore.datagenerator.generators.customer; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Map; @@ -28,11 +27,9 @@ import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Pair; import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Store; import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.InputData; import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.Names; -import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ProductCategory; import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ZipcodeRecord; import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory; import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.Sampler; -import org.apache.bigtop.bigpetstore.datagenerator.generators.customer.CustomerSamplerBuilder; import org.junit.Test; import com.google.common.collect.ImmutableMap; @@ -53,7 +50,7 @@ public class TestCustomerSamplerBuilder Names names = new Names(nameList, nameList); // don't need product categories for building customers - InputData inputData = new InputData(zipcodes, names, new ArrayList<ProductCategory>()); + InputData inputData = new InputData(zipcodes, names); List<Store> stores = Arrays.asList(new Store(0, "Store_0", zipcodes.get(0)), new Store(1, "Store_1", zipcodes.get(1)), diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/cartesian/TestCartesianProductBase.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/cartesian/TestCartesianProductBase.java new file mode 100644 index 00000000..f171980e --- /dev/null +++ b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/cartesian/TestCartesianProductBase.java @@ -0,0 +1,41 @@ +package org.apache.bigtop.bigpetstore.datagenerator.generators.products.cartesian; + +import java.util.Arrays; +import java.util.Iterator; +import java.util.Map; + +import org.junit.Assert; +import org.junit.Test; + +public class TestCartesianProductBase +{ + @Test + public void testNext() + { + Iterator<Map<String, Double>> iter = new CartesianProductBase<Double>("count", + Arrays.asList(1.0, 2.0, 3.0)); + + Assert.assertTrue(iter.hasNext()); + + Map<String, Double> map = iter.next(); + Assert.assertEquals(1, map.size()); + Assert.assertTrue(map.containsKey("count")); + Assert.assertEquals( (double) map.get("count"), (double) 1.0, 0.0001); + + Assert.assertTrue(iter.hasNext()); + + map = iter.next(); + Assert.assertEquals(1, map.size()); + Assert.assertTrue(map.containsKey("count")); + Assert.assertEquals( (double) map.get("count"), (double) 2.0, 0.0001); + + Assert.assertTrue(iter.hasNext()); + + map = iter.next(); + Assert.assertEquals(1, map.size()); + Assert.assertTrue(map.containsKey("count")); + Assert.assertEquals( (double) map.get("count"), (double) 3.0, 0.0001); + + Assert.assertFalse(iter.hasNext()); + } +} diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/cartesian/TestCartesianProductField.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/cartesian/TestCartesianProductField.java new file mode 100644 index 00000000..42d62c7e --- /dev/null +++ b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/cartesian/TestCartesianProductField.java @@ -0,0 +1,57 @@ +package org.apache.bigtop.bigpetstore.datagenerator.generators.products.cartesian; + +import java.util.Arrays; +import java.util.Iterator; +import java.util.Map; + +import org.junit.Assert; +import org.junit.Test; + +public class TestCartesianProductField +{ + + @Test + public void testTwoLevels() + { + Iterator<Map<String, String>> iter = new CartesianProductField<String>( + "children", Arrays.asList("1", "2"), + new CartesianProductBase<String>( + "animal", Arrays.asList("cat", "dog"))); + + Assert.assertEquals(iter.hasNext(), true); + Map<String, String> map = iter.next(); + Assert.assertEquals(map.size(), 2); + Assert.assertTrue(map.containsKey("animal")); + Assert.assertTrue(map.containsKey("children")); + Assert.assertEquals(map.get("animal"), "cat"); + Assert.assertEquals(map.get("children"), "1"); + + Assert.assertEquals(iter.hasNext(), true); + map = iter.next(); + Assert.assertEquals(map.size(), 2); + Assert.assertTrue(map.containsKey("animal")); + Assert.assertTrue(map.containsKey("children")); + Assert.assertEquals(map.get("animal"), "cat"); + Assert.assertEquals(map.get("children"), "2"); + + Assert.assertEquals(iter.hasNext(), true); + map = iter.next(); + Assert.assertEquals(map.size(), 2); + Assert.assertTrue(map.containsKey("animal")); + Assert.assertTrue(map.containsKey("children")); + Assert.assertEquals(map.get("animal"), "dog"); + Assert.assertEquals(map.get("children"), "1"); + + Assert.assertEquals(iter.hasNext(), true); + map = iter.next(); + Assert.assertEquals(map.size(), 2); + Assert.assertTrue(map.containsKey("animal")); + Assert.assertTrue(map.containsKey("children")); + Assert.assertEquals(map.get("animal"), "dog"); + Assert.assertEquals(map.get("children"), "2"); + + Assert.assertFalse(iter.hasNext()); + Assert.assertFalse(iter.hasNext()); + Assert.assertFalse(iter.hasNext()); + } +} diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/TestProductCategoryMarkovModelSampler.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/TestProductCategoryMarkovModelSampler.java index e32994b0..89303f67 100644 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/TestProductCategoryMarkovModelSampler.java +++ b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/TestProductCategoryMarkovModelSampler.java @@ -25,11 +25,11 @@ import org.apache.bigtop.bigpetstore.datagenerator.Constants; import org.apache.bigtop.bigpetstore.datagenerator.datamodels.PetSpecies; import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Product; import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ProductCategory; -import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ProductCategoryBuilder; import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory; import org.apache.bigtop.bigpetstore.datagenerator.framework.markovmodels.MarkovModel; import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.Sampler; import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.UniformSampler; +import org.apache.bigtop.bigpetstore.datagenerator.generators.products.ProductCategoryBuilder; import org.apache.bigtop.bigpetstore.datagenerator.generators.purchase.ProductCategoryMarkovModelSampler; import org.junit.Test; @@ -49,9 +49,6 @@ public class TestProductCategoryMarkovModelSampler foodBuilder.setAmountUsedPetPetAverage(1.0); foodBuilder.setAmountUsedPetPetVariance(1.0); foodBuilder.setDailyUsageRate(2.0); - foodBuilder.addFieldName(Constants.PRODUCT_CATEGORY); - foodBuilder.addFieldName(Constants.PRODUCT_QUANTITY); - foodBuilder.addFieldName("Flavor"); foodBuilder.setCategory("dogFood"); foodBuilder.addProduct(new Product(ImmutableMap.of(Constants.PRODUCT_CATEGORY, (Object) "dogFood", Constants.PRODUCT_QUANTITY, (Object) 60.0, "Flavor", "Fish & Potato"))); @@ -66,9 +63,6 @@ public class TestProductCategoryMarkovModelSampler bagBuilder.setAmountUsedPetPetAverage(1.0); bagBuilder.setAmountUsedPetPetVariance(1.0); bagBuilder.setDailyUsageRate(2.0); - bagBuilder.addFieldName(Constants.PRODUCT_CATEGORY); - bagBuilder.addFieldName(Constants.PRODUCT_QUANTITY); - bagBuilder.addFieldName("Color"); bagBuilder.setCategory("Poop Bags"); bagBuilder.addProduct(new Product(ImmutableMap.of(Constants.PRODUCT_CATEGORY, (Object) "Poop Bags", Constants.PRODUCT_QUANTITY, (Object) 60.0, "Color", "Blue"))); diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/TestPurchasingModelSampler.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/TestPurchasingModelSampler.java index 04a20f0c..12efe13d 100644 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/TestPurchasingModelSampler.java +++ b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/TestPurchasingModelSampler.java @@ -24,9 +24,9 @@ import org.apache.bigtop.bigpetstore.datagenerator.Constants; import org.apache.bigtop.bigpetstore.datagenerator.datamodels.PetSpecies; import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Product; import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ProductCategory; -import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ProductCategoryBuilder; import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory; import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.Sampler; +import org.apache.bigtop.bigpetstore.datagenerator.generators.products.ProductCategoryBuilder; import org.apache.bigtop.bigpetstore.datagenerator.generators.purchase.MarkovPurchasingModel; import org.apache.bigtop.bigpetstore.datagenerator.generators.purchase.PurchasingModelSamplerBuilder; import org.junit.Test; @@ -46,9 +46,6 @@ public class TestPurchasingModelSampler foodBuilder.setAmountUsedPetPetAverage(1.0); foodBuilder.setAmountUsedPetPetVariance(1.0); foodBuilder.setDailyUsageRate(2.0); - foodBuilder.addFieldName(Constants.PRODUCT_CATEGORY); - foodBuilder.addFieldName(Constants.PRODUCT_QUANTITY); - foodBuilder.addFieldName("Flavor"); foodBuilder.setCategory("dogFood"); foodBuilder.addProduct(new Product(ImmutableMap.of(Constants.PRODUCT_CATEGORY, (Object) "dogFood", Constants.PRODUCT_QUANTITY, (Object) 60.0, "Flavor", "Fish & Potato"))); @@ -63,9 +60,6 @@ public class TestPurchasingModelSampler bagBuilder.setAmountUsedPetPetAverage(1.0); bagBuilder.setAmountUsedPetPetVariance(1.0); bagBuilder.setDailyUsageRate(2.0); - bagBuilder.addFieldName(Constants.PRODUCT_CATEGORY); - bagBuilder.addFieldName(Constants.PRODUCT_QUANTITY); - bagBuilder.addFieldName("Color"); bagBuilder.setCategory("Poop Bags"); bagBuilder.addProduct(new Product(ImmutableMap.of(Constants.PRODUCT_CATEGORY, (Object) "Poop Bags", Constants.PRODUCT_QUANTITY, (Object) 60.0, "Color", "Blue"))); diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/TestPurchasingModelSamplerBuilder.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/TestPurchasingModelSamplerBuilder.java index 2255fc36..2d526ed9 100644 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/TestPurchasingModelSamplerBuilder.java +++ b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/purchase/TestPurchasingModelSamplerBuilder.java @@ -24,9 +24,9 @@ import org.apache.bigtop.bigpetstore.datagenerator.Constants; import org.apache.bigtop.bigpetstore.datagenerator.datamodels.PetSpecies; import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Product; import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ProductCategory; -import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ProductCategoryBuilder; import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory; import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.Sampler; +import org.apache.bigtop.bigpetstore.datagenerator.generators.products.ProductCategoryBuilder; import org.apache.bigtop.bigpetstore.datagenerator.generators.purchase.MarkovPurchasingModel; import org.apache.bigtop.bigpetstore.datagenerator.generators.purchase.PurchasingModelSamplerBuilder; import org.junit.Test; @@ -46,9 +46,6 @@ public class TestPurchasingModelSamplerBuilder foodBuilder.setAmountUsedPetPetAverage(1.0); foodBuilder.setAmountUsedPetPetVariance(1.0); foodBuilder.setDailyUsageRate(2.0); - foodBuilder.addFieldName(Constants.PRODUCT_CATEGORY); - foodBuilder.addFieldName(Constants.PRODUCT_QUANTITY); - foodBuilder.addFieldName("Flavor"); foodBuilder.setCategory("dogFood"); foodBuilder.addProduct(new Product(ImmutableMap.of(Constants.PRODUCT_CATEGORY, (Object) "dogFood", Constants.PRODUCT_QUANTITY, (Object) 60.0, "Flavor", "Fish & Potato"))); @@ -63,9 +60,6 @@ public class TestPurchasingModelSamplerBuilder bagBuilder.setAmountUsedPetPetAverage(1.0); bagBuilder.setAmountUsedPetPetVariance(1.0); bagBuilder.setDailyUsageRate(2.0); - bagBuilder.addFieldName(Constants.PRODUCT_CATEGORY); - bagBuilder.addFieldName(Constants.PRODUCT_QUANTITY); - bagBuilder.addFieldName("Color"); bagBuilder.setCategory("Poop Bags"); bagBuilder.addProduct(new Product(ImmutableMap.of(Constants.PRODUCT_CATEGORY, (Object) "Poop Bags", Constants.PRODUCT_QUANTITY, (Object) 60.0, "Color", "Blue"))); diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestCustomerInventory.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestCustomerInventory.java index 6edb03da..322bb5e5 100644 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestCustomerInventory.java +++ b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestCustomerInventory.java @@ -24,9 +24,9 @@ import org.apache.bigtop.bigpetstore.datagenerator.Constants; import org.apache.bigtop.bigpetstore.datagenerator.datamodels.PetSpecies; import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Product; import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ProductCategory; -import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ProductCategoryBuilder; import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory; import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.Sampler; +import org.apache.bigtop.bigpetstore.datagenerator.generators.products.ProductCategoryBuilder; import org.apache.bigtop.bigpetstore.datagenerator.generators.transaction.CustomerInventory; import org.apache.bigtop.bigpetstore.datagenerator.generators.transaction.CustomerTransactionParameters; import org.apache.bigtop.bigpetstore.datagenerator.generators.transaction.CustomerTransactionParametersSamplerBuilder; diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestCustomerInventoryBuilder.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestCustomerInventoryBuilder.java index fb147de0..d8d6d70a 100644 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestCustomerInventoryBuilder.java +++ b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestCustomerInventoryBuilder.java @@ -24,9 +24,9 @@ import org.apache.bigtop.bigpetstore.datagenerator.Constants; import org.apache.bigtop.bigpetstore.datagenerator.datamodels.PetSpecies; import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Product; import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ProductCategory; -import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ProductCategoryBuilder; import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory; import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.Sampler; +import org.apache.bigtop.bigpetstore.datagenerator.generators.products.ProductCategoryBuilder; import org.apache.bigtop.bigpetstore.datagenerator.generators.transaction.CustomerInventory; import org.apache.bigtop.bigpetstore.datagenerator.generators.transaction.CustomerInventoryBuilder; import org.apache.bigtop.bigpetstore.datagenerator.generators.transaction.CustomerTransactionParameters; diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestProductCategoryInventory.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestProductCategoryInventory.java index 121f08cf..dc08979c 100644 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestProductCategoryInventory.java +++ b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestProductCategoryInventory.java @@ -24,9 +24,9 @@ import org.apache.bigtop.bigpetstore.datagenerator.Constants; import org.apache.bigtop.bigpetstore.datagenerator.datamodels.PetSpecies; import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Product; import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ProductCategory; -import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ProductCategoryBuilder; import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory; import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.Sampler; +import org.apache.bigtop.bigpetstore.datagenerator.generators.products.ProductCategoryBuilder; import org.apache.bigtop.bigpetstore.datagenerator.generators.transaction.CustomerTransactionParameters; import org.apache.bigtop.bigpetstore.datagenerator.generators.transaction.CustomerTransactionParametersSamplerBuilder; import org.apache.bigtop.bigpetstore.datagenerator.generators.transaction.ProductCategoryInventory; diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestTransactionPurchasesHiddenMarkovModel.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestTransactionPurchasesHiddenMarkovModel.java index 9d89410e..6383c2e9 100644 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestTransactionPurchasesHiddenMarkovModel.java +++ b/bigtop-bigpetstore/bigpetstore-data-generator/src/test/java/org/apache/bigtop/bigpetstore/datagenerator/generators/transaction/TestTransactionPurchasesHiddenMarkovModel.java @@ -25,12 +25,12 @@ import org.apache.bigtop.bigpetstore.datagenerator.Constants; import org.apache.bigtop.bigpetstore.datagenerator.datamodels.PetSpecies; import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Product; import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ProductCategory; -import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ProductCategoryBuilder; import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory; import org.apache.bigtop.bigpetstore.datagenerator.framework.markovmodels.MarkovModel; import org.apache.bigtop.bigpetstore.datagenerator.framework.markovmodels.MarkovModelBuilder; import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.Sampler; import org.apache.bigtop.bigpetstore.datagenerator.framework.wfs.ConditionalWeightFunction; +import org.apache.bigtop.bigpetstore.datagenerator.generators.products.ProductCategoryBuilder; import org.apache.bigtop.bigpetstore.datagenerator.generators.purchase.MarkovPurchasingModel; import org.apache.bigtop.bigpetstore.datagenerator.generators.purchase.PurchasingProcesses; import org.apache.bigtop.bigpetstore.datagenerator.generators.transaction.CategoryWeightFunction; |