X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=Robust%2Fsrc%2FBenchmarks%2FWebServerJ%2FInventory.java;fp=Robust%2Fsrc%2FBenchmarks%2FWebServerJ%2FInventory.java;h=0000000000000000000000000000000000000000;hb=refs%2Ftags%2Fbuildscript;hp=570ac6b86818abc6f599ad74ce76412da62c055c;hpb=2f2cbbbc9385b82d891fabf62ab7e0c5cf364658;p=IRC.git diff --git a/Robust/src/Benchmarks/WebServerJ/Inventory.java b/Robust/src/Benchmarks/WebServerJ/Inventory.java deleted file mode 100644 index 570ac6b8..00000000 --- a/Robust/src/Benchmarks/WebServerJ/Inventory.java +++ /dev/null @@ -1,94 +0,0 @@ -import java.util.*; -import java.net.*; -import java.io.*; - -public class Inventory { - // Transaction variables - int numitems; - HashMap map; - int balance; - - // Constructor - public Inventory(){ - map = new HashMap(); - balance=100000; - } - - public Inventory(int howmany) { - numitems = howmany;// howmany keeps track of the number of items - // in the inventory - map = new HashMap(); - } - - // Add item to a list of inventory - public synchronized void additem(String name, int quantity, int price){ - ItemInfo newitem = new ItemInfo(quantity, price); - balance-=quantity*price; - - // Get the item from hash - if (map.containsKey(name) == false) { - map.put(name, newitem); - } else { - ItemInfo i = (ItemInfo) map.get(name); - i.quantity += quantity; - i.price = price; - map.put(name, i); - } - } - - // Buy item from a given list of inventory - public synchronized int buyitem(String name, int quantity){ - if (map.containsKey(name) == false) { - // System.printString("Error - Item does not exist"); - return -1; - } else { - ItemInfo i = (ItemInfo) map.get(name); - if (i.quantity == 0) { - // System.printString("Error - Item unavailable"); - return -1; - } - if ((i.quantity-quantity) < 0 ) { - // System.printString("Error - Available qty is less: Cannot Buy\n"); - return -1; - } else { - i.quantity -= quantity; - map.put(name, i); - balance+=quantity*i.price; - return i.price; - } - } - } - - //Display the inventory list - public synchronized void inventory(Socket s){ - try { - OutputStream sockout=s.getOutputStream(); - Iterator i = map.keySet().iterator();// Gets key from the hashmap= name of item - Iterator j = map.values().iterator();//Gets the value from hashmap - int totalvalue=balance; - while (i.hasNext() == true) { - StringBuffer sb = new StringBuffer(""); - Object o = i.next(); - String name = o.toString(); - ItemInfo oo = (ItemInfo) j.next(); - sb.append(name); - sb.append(" "); - Integer q = new Integer(oo.quantity); - sb.append(q.toString()); - sb.append(" "); - Integer p = new Integer(oo.price); - sb.append(p.toString()); - sb.append("\n"); - totalvalue+=oo.quantity*oo.price; - sockout.write(sb.toString().getBytes()); - } - StringBuffer sb=new StringBuffer(""); - sb.append("Total value: "); - sb.append((new Integer(totalvalue)).toString()); - sb.append("\n"); - sockout.write(sb.toString().getBytes()); - } catch (Exception e) { - e.printStackTrace(); - } - } -}