コード例 #1
0
ファイル: BidService.java プロジェクト: sujjjith/BiddingApp
  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;
  }
コード例 #2
0
ファイル: BidService.java プロジェクト: sujjjith/BiddingApp
 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;
 }