package com.acertainbookstore.client.workloads;

import java.util.HashSet;
import java.util.Set;

import com.acertainbookstore.business.ImmutableStockBook;
import com.acertainbookstore.business.StockBook;

/**
 * Helper class to generate stockbooks and isbns modelled similar to Random
 * class
 */
public class BookSetGenerator {
	private int bookNum = 0;
	private int isbn = 1337;

	public BookSetGenerator() {
		// TODO Auto-generated constructor stub
	}

	/**
	 * Returns num randomly selected isbns from the input set
	 * 
	 * @param num
	 * @return
	 */
	public Set<Integer> sampleFromSetOfISBNs(Set<Integer> isbns, int num) {
		if(isbns == null || isbns.size() == 0 || num == 0){
			return null;
		}

		Set<Integer> rand_isbns = new HashSet<Integer>();
		Integer a[] = new Integer[isbns.size()];
		isbns.toArray(a);

		for(int i=0; i<num; i++){
			int idx = (int)(Math.random()*isbns.size());
			rand_isbns.add(a[idx]);
		}
		return rand_isbns;
	}

	/**
	 * Return num stock books. For now return an ImmutableStockBook
	 * 
	 * @param num
	 * @return
	 */
	public Set<StockBook> nextSetOfStockBooks(int num) {
		Set<StockBook> books = new HashSet<StockBook>();
		for(int i=0; i<num; i++){
			int copies = (int)Math.random()*20;
			boolean ep = copies > 10;
			StockBook book = new ImmutableStockBook(isbn + bookNum, "Introduction to Eduroam vol. " + bookNum,
					"Hitlerik Smørhår", (float) 10, copies, 0, 0, 0, ep);
			books.add(book);
		}
		return books;
	}

}

@@ -1210,16 +1210,17 @@
  = (int)
+(
 Math.ran
@@ -1227,16 +1227,17 @@
 dom()*20
+)
 ;%0A%09%09%09boo
@@ -1302,20 +1302,26 @@
 ockBook(
+(
 isbn
+*5851
  + bookN
@@ -1322,16 +1322,22 @@
  bookNum
+*6299)
 , %22Intro
@@ -1416,16 +1416,19 @@
 , copies
++10
 , 0, 0, 
@@ -1455,16 +1455,30 @@
 (book);%0A
+%09%09%09bookNum++;%0A
 %09%09%7D%0A%09%09re

Update BookSetGenerator.java