Ejemplo n.º 1
0
  public long createAuction(Item item, String closingTimeString, User owner) {
    long id;
    synchronized (nextId) {
      id = nextId;
      nextId++;
    }
    System.out.println("Creating auction no. " + id);

    Date closingTime;
    try {
      SimpleDateFormat sdf = DatePattern.getSdf();
      closingTime = sdf.parse(closingTimeString);
    } catch (ParseException e) {
      System.out.println(
          "Closing time couldn't be parsed. Did you enter a correctly formatted date?");
      return -1;
    }

    if (closingTime == null) return -1;

    Bid bid = new Bid(item, closingTime, id, owner);
    System.out.println("Auction created: " + bid.getShortDescription());

    bidMap.put(id, bid);

    return id;
  }
Ejemplo n.º 2
0
 public boolean bid(User bidder, long auctionId, double bid) {
   Bid a = bidMap.get(auctionId);
   if (a == null) {
     System.out.println("Wrong auction ID!");
     return false;
   }
   a.bid(bidder, bid);
   return true;
 }