Ignore:
Timestamp:
Jul 23, 2025, 10:18:43 AM (2 months ago)
Author:
ruud
Message:

Modifications for automatic java to python conversion. Overloaded methods now have different names.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • geniuswebcore/geniusweb/actions/ActionWithBid.py

    r100 r111  
    1 from typing import Dict, Any
     1# Generated from java by J2P
     2from __future__ import annotations
    23from geniusweb.actions.AbstractAction import AbstractAction
    34from geniusweb.actions.PartyId import PartyId
    45from geniusweb.issuevalue.Bid import Bid
     6from tudelft.utilities.tools.safehash import safehash
     7from typing import Any
     8from typing import Optional
     9from typing import cast
    510
    611
    7 class ActionWithBid ( AbstractAction ):
    8         '''
    9         An {@link Action} containing a bid. Note that the presense of a bid does not
    10         necessarily mean that an offer was placed for this bid.
     12class ActionWithBid(AbstractAction):
     13 '''
     14 An {@link Action} containing a bid. Note that the presence of a bid does not
     15 necessarily mean that an offer was placed for this bid.
     16 
    1117
    12         '''
     18 '''
     19 
     20 def __init__(self, actor:PartyId, bid:Bid):
     21  self.__bid:Bid = None
     22  super().__init__(actor)
     23  if (bid is None):
     24   raise ValueError("bid is null")
     25  self.__bid=bid
     26 
     27 def getBid(self) -> Bid:
     28  '''
     29 
     30  @return the {@link Bid} that this action is about.
    1331
    14         def __init__(self,  actor:PartyId,      bid:Bid):
    15                 '''
    16                 @param param the actor partyid:
    17                 @param bid the bid. FIXME use Bid object and strong typing
    18                 '''
    19                 super().__init__(actor)
    20                 self._bid = bid
     32  '''
     33  return self.__bid
     34 
     35 #Override
     36 def __hash__(self) -> int:
     37  prime:int = 31
     38  result:int = safehash(super())
     39  result=((prime * result) + (0 if ((self.__bid is None)) else safehash(self.__bid)))
     40  return result
     41 
     42 #Override
     43 def __eq__(self,obj:Optional[Any]) -> bool:
     44  '''
     45  This should work also for derived classes without extra fields.
    2146
    22         def getBid(self) -> Bid:
    23                 '''
    24                 @return the {@link Bid} that this action is about.
    25                 '''
    26                 return self._bid;
    27 
    28         def __eq__(self, other):
    29                 return isinstance(other, self.__class__) and \
    30                         super().__eq__(other) and self._bid==other._bid
    31 
    32         def __hash__(self):
    33                 return hash((self._actor, self._bid))
    34        
     47  '''
     48  if (self is obj):
     49   return True
     50  if not(super().__eq__(obj)):
     51   return False
     52  if (type(self) is not type(obj)):
     53   return False
     54  other:Optional[ActionWithBid] = cast(ActionWithBid,obj)
     55  if (self.__bid is None):
     56   if (other.__bid is not None):
     57    return False
     58  else:
     59   if not(self.__bid == other.__bid):
     60    return False
     61  return True
Note: See TracChangeset for help on using the changeset viewer.