예제 #1
0
 @Override
 public boolean registerBid(double value, int uniqueUserId, int auctionId) throws RemoteException {
   RMIClientIntf clientIntf = registeredUsers.get(uniqueUserId);
   Bid bid = new Bid(value, uniqueUserId);
   if (!liveAuctionItems.containsKey(auctionId)) {
     clientIntf.callBack("Auction item id does not exist\n");
     return false;
   }
   if (uniqueUserId == liveAuctionItems.get(auctionId).getCreator_id()) {
     clientIntf.callBack("Not able to register bid - bidder is the creator of this auction\n");
     return false;
   } else {
     if (liveAuctionItems.get(auctionId).addBidder(bid)) {
       clientIntf.callBack(
           "Bid registered to auction with id "
               + auctionId
               + " and amount "
               + bid.getBid()
               + "\n");
       return true;
     } else {
       clientIntf.callBack(
           "Bid rejected, user has already placed a bid for this auction, can only place higher bids\n");
       return false;
     }
   }
 }
예제 #2
0
  /**
   * build BidWin from scratch
   *
   * @param bid value of the winning bid
   * @param fine fine in case of transaction failure
   * @return
   */
  @Override
  public Packet buildBidWin(Bid bid, int fine) {

    int transactionID = bid.getTransactionID();
    Inet4Address winnerIP = bid.getSourceIP();
    int winningBid = bid.getBid();
    BidWin bidWin = new BidWin(transactionID, winnerIP, winningBid, fine);
    bidWin.setSourceIP(this.deviceIP);
    bidWin.setDestinationIP(this.broadcastAddr);
    return bidWin;
  }
예제 #3
0
 @Override
 public boolean equals(Object obj) {
   if (obj instanceof Bid) {
     Bid b = (Bid) obj;
     return (this.name.equals(b.getBidder()) && this.value == b.getBid());
   } else if (obj instanceof String) {
     String str = (String) obj;
     return str.equals(name + value);
   } else {
     return false;
   }
 }