| 1111 | |
| 1112 | @functools.total_ordering |
| 1113 | class Balance(object): |
| 1114 | __slots__ = "currency", "amount", |
| 1115 | |
| 1116 | def __init__(self, currency="", amount=float(0.0)): |
| 1117 | self.currency = currency |
| 1118 | self.amount = amount |
| 1119 | |
| 1120 | # Struct shallow copy |
| 1121 | def copy(self, other): |
| 1122 | self.currency = other.currency |
| 1123 | self.amount = other.amount |
| 1124 | return self |
| 1125 | |
| 1126 | # Struct deep clone |
| 1127 | def clone(self): |
| 1128 | # Serialize the struct to the FBE stream |
| 1129 | writer = BalanceModel(fbe.WriteBuffer()) |
| 1130 | writer.serialize(self) |
| 1131 | |
| 1132 | # Deserialize the struct from the FBE stream |
| 1133 | reader = BalanceModel(fbe.ReadBuffer()) |
| 1134 | reader.attach_buffer(writer.buffer) |
| 1135 | return reader.deserialize()[0] |
| 1136 | |
| 1137 | def __eq__(self, other): |
| 1138 | if not isinstance(self, other.__class__): |
| 1139 | return NotImplemented |
| 1140 | if not self.currency == other.currency: |
| 1141 | return False |
| 1142 | return True |
| 1143 | |
| 1144 | def __lt__(self, other): |
| 1145 | if not isinstance(self, other.__class__): |
| 1146 | return NotImplemented |
| 1147 | if self.currency < other.currency: |
| 1148 | return True |
| 1149 | if self.currency == other.currency: |
| 1150 | return False |
| 1151 | return False |
| 1152 | |
| 1153 | @property |
| 1154 | def __key__(self): |
| 1155 | return self.currency, |
| 1156 | |
| 1157 | def __hash__(self): |
| 1158 | return hash(self.__key__) |
| 1159 | |
| 1160 | def __format__(self, format_spec): |
| 1161 | return self.__str__() |
| 1162 | |
| 1163 | def __str__(self): |
| 1164 | sb = list() |
| 1165 | sb.append("Balance(") |
| 1166 | sb.append("currency=") |
| 1167 | if self.currency is not None: |
| 1168 | sb.append("\"" + str(self.currency) + "\"") |
| 1169 | else: |
| 1170 | sb.append("null") |
no outgoing calls
no test coverage detected