package org.vaadin.mockapp.samples.backend.mock;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Random;
import java.util.Set;

import org.vaadin.mockapp.samples.backend.data.Availability;
import org.vaadin.mockapp.samples.backend.data.Category;
import org.vaadin.mockapp.samples.backend.data.Product;

public class MockDataGenerator {
    private static int nextCategoryId = 1;
    private static int nextProductId = 1;
    private static final Random random = new Random(1);
    private static final String categoryNames[] = new String[] {
            "Children's books", "Best sellers", "Romance", "Mystery",
            "Thriller", "Sci-fi", "Non-fiction", "Cookbooks" };

    private static String[] word1 = new String[] { "The art of", "Mastering",
            "The secrets of", "Avoiding", "For fun and profit: ",
            "How to fail at", "10 important facts about",
            "The ultimate guide to", "Book of", "Surviving", "Encyclopedia of",
            "Very much", "Learning the basics of", "The cheap way to",
            "Being awesome at", "The life changer:", "The Vaadin way:",
            "Becoming one with", "Beginners guide to",
            "The complete visual guide to", "The mother of all references:" };

    private static String[] word2 = new String[] { "gardening",
            "living a healthy life", "designing tree houses", "home security",
            "intergalaxy travel", "meditation", "ice hockey",
            "children's education", "bromance", "computer programming",
            "Vaadin TreeTable", "winter bathing", "playing the cello",
            "dummies", "rubber bands", "feeling down", "debugging",
            "running barefoot", "speaking to a big audience",
            "creating software", "giant needles", "elephants",
            "keeping your wife happy" };

    static List<Category> createCategories() {
        List<Category> categories = new ArrayList<Category>();
        for (String name : categoryNames) {
            Category c = createCategory(name);
            categories.add(c);
        }
        return categories;

    }

    static List<Product> createProducts(List<Category> categories) {
        List<Product> products = new ArrayList<Product>();
        for (int i = 0; i < 100; i++) {
            Product p = createProduct(categories);
            products.add(p);
        }

        return products;
    }

    private static Category createCategory(String name) {
        Category c = new Category();
        c.setId(nextCategoryId++);
        c.setName(name);
        return c;
    }

    private static Product createProduct(List<Category> categories) {
        Product p = new Product();
        p.setId(nextProductId++);
        p.setProductName(generateName());

        p.setPrice(new BigDecimal((random.nextInt(250) + 50) / 10.0));
        p.setAvailability(Availability.values()[random.nextInt(Availability
                .values().length)]);
        if (p.getAvailability() == Availability.AVAILABLE) {
            p.setStockCount(random.nextInt(523));
        }

        p.setCategory(getCategory(categories, 1, 2));
        return p;
    }

    private static Set<Category> getCategory(List<Category> categories,
            int min, int max) {
        int nr = random.nextInt(max) + min;
        HashSet<Category> productCategories = new HashSet<Category>();
        for (int i = 0; i < nr; i++) {
            productCategories.add(categories.get(random.nextInt(categories
                    .size())));
        }

        return productCategories;
    }

    private static String generateName() {
        return word1[random.nextInt(word1.length)] + " "
                + word2[random.nextInt(word2.length)];
    }

}

@@ -619,20 +619,16 @@
         
-    
 %22Childre
@@ -673,28 +673,24 @@
  %22Mystery%22,%0A
-    
         %22Thr
@@ -820,28 +820,24 @@
 g%22,%0A        
-  
-  
 %22The secrets
@@ -886,20 +886,16 @@
         
-    
 %22How to 
@@ -936,28 +936,24 @@
 t%22,%0A        
-   
- 
 %22The ultimat
@@ -1008,20 +1008,16 @@
 ia of%22,%0A
-    
         
@@ -1083,20 +1083,16 @@
         
-    
 %22Being a
@@ -1151,20 +1151,16 @@
         
- 
-   
 %22Becomin
@@ -1190,28 +1190,24 @@
  guide to%22,%0A
-    
         %22The
@@ -1342,20 +1342,16 @@
         
-  
-  
 %22living 
@@ -1417,20 +1417,16 @@
         
-    
 %22interga
@@ -1463,28 +1463,24 @@
 ce hockey%22,%0A
-    
         %22chi
@@ -1502,20 +1502,8 @@
 on%22,
- %22bromance%22,
  %22co
@@ -1522,28 +1522,16 @@
 amming%22,
-%0A           
  %22Vaadin
@@ -1542,16 +1542,24 @@
 eTable%22,
+%0A       
  %22winter
@@ -1589,28 +1589,16 @@
  cello%22,
-%0A           
  %22dummie
@@ -1616,16 +1616,24 @@
  bands%22,
+%0A       
  %22feelin
@@ -1653,28 +1653,16 @@
 ugging%22,
-%0A           
  %22runnin
@@ -1673,16 +1673,24 @@
 refoot%22,
+%0A       
  %22speaki
@@ -1711,28 +1711,16 @@
 dience%22,
-%0A           
  %22creati
@@ -1749,16 +1749,24 @@
 eedles%22,
+%0A       
  %22elepha
@@ -1770,28 +1770,16 @@
 phants%22,
-%0A           
  %22keepin

Make book titles more neutral