protected Item findItem(String itemName) { for (Item item : Server.getInstance().getItemList()) { if (item.getName().equals(itemName)) { return item; } } return null; }
@Override public void placeItemForBid( String ownerName, String itemName, String itemDesc, double startBid, int auctionTime, String auctionType) throws RemoteException { List<Item> items = Server.getInstance().getItemList(); BiddingStrategyValidator validator; if (auctionType.equals("English")) { validator = new EnglishAuctionBiddingStrategyValidator(); } else { validator = new DutchAuctionBiddingStrategyValidator(); } Item newItem = new Item( ownerName, itemName, itemDesc, startBid, null, auctionTime, validator, Calendar.getInstance()); if (items.contains(newItem)) { throw new RemoteException("Item with that name already exists!"); } else { items.add(newItem); System.out.println( "Wystawiono przedmiot " + newItem + " na aukcje typu " + newItem.getValidator().getClass().getName() + "."); } }
@Override public Item[] getItems() throws RemoteException { return (Item[]) Server.getInstance().getItemList().toArray(); }
public void closeAuction(String itemName) throws RemoteException { Item item = findItem(itemName); notifyObservers(item, "close"); Server.getInstance().getItemList().remove(item); listeners.remove(itemName); }