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){
			return null;
		}

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

		for(int i=0; i<num; i++){
			int idx = (int)Math.random()*isbns.size();
			rand_isbns.add(isbnsArr[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;
			StockBook book = new ImmutableStockBook(isbn + bookNum, "Introduction to Eduroam vol. " + bookNum,
					"Hitlerik Smørhår", (float) 10, copies, 0, 0, 0, false);
			books.add(book);
		}
		return books;
	}

}

@@ -663,16 +663,28 @@
 ize() ==
+ 0 %7C%7C num ==
  0)%7B%0A%09%09%09
@@ -766,34 +766,44 @@
 eger
+ a
 %5B%5D 
-isbnsArr = (Integer%5B%5D) 
+= new Integer%5Bisbns.size()%5D;%0A%09%09
 isbn
@@ -812,16 +812,17 @@
 toArray(
+a
 );%0A%0A%09%09fo
@@ -855,32 +855,33 @@
 %09int idx = (int)
+(
 Math.random()*is
@@ -890,16 +890,17 @@
 s.size()
+)
 ;%0A%09%09%09ran
@@ -915,16 +915,9 @@
 add(
-isbnsArr
+a
 %5Bidx
@@ -1228,16 +1228,45 @@
 m()*20;%0A
+%09%09%09boolean ep = copies %3E 10;%0A
 %09%09%09Stock
@@ -1417,13 +1417,10 @@
  0, 
-fals
 e
+p
 );%0A%09

Update BookSetGenerator.java