Generify Bond raw types & rename BondRepository type params

Replace all raw uses of 'Bond<T extends BondedAsset>', mostly with
wildcards (that is, 'Bond<?>'), to prevent compiler/IDE warnings.

Also rename the 'T extends Bond<R>' & 'R extend BondedAsset' type params
of 'BondRepository<..>' to 'B' & 'T' respectively, as this is a little
less confusing.
This commit is contained in:
Steven Barclay 2024-03-08 21:11:31 +08:00
parent 314e976bbc
commit e1a8424f12
No known key found for this signature in database
GPG Key ID: 9FED6BF1176D500B
7 changed files with 28 additions and 32 deletions

View File

@ -598,14 +598,14 @@ public class DaoFacade implements DaoSetupService {
}
public List<Bond> getAllBonds() {
List<Bond> bonds = new ArrayList<>(bondedReputationRepository.getBonds());
public List<Bond<?>> getAllBonds() {
List<Bond<?>> bonds = new ArrayList<>(bondedReputationRepository.getBonds());
bonds.addAll(bondedRolesRepository.getBonds());
return bonds;
}
public List<Bond> getAllActiveBonds() {
List<Bond> bonds = new ArrayList<>(bondedReputationRepository.getActiveBonds());
public List<Bond<?>> getAllActiveBonds() {
List<Bond<?>> bonds = new ArrayList<>(bondedReputationRepository.getActiveBonds());
bonds.addAll(bondedRolesRepository.getActiveBonds());
return bonds;
}
@ -739,7 +739,7 @@ public class DaoFacade implements DaoSetupService {
return bondedRolesRepository.isMyRole(role);
}
public Optional<Bond> getBondByLockupTxId(String lockupTxId) {
public Optional<Bond<?>> getBondByLockupTxId(String lockupTxId) {
return getAllBonds().stream().filter(e -> lockupTxId.equals(e.getLockupTxId())).findAny();
}

View File

@ -56,7 +56,7 @@ import lombok.extern.slf4j.Slf4j;
* unconfirmed txs.
*/
@Slf4j
public abstract class BondRepository<T extends Bond, R extends BondedAsset> implements DaoSetupService,
public abstract class BondRepository<B extends Bond<T>, T extends BondedAsset> implements DaoSetupService,
BsqWalletService.WalletTransactionsChangeListener {
///////////////////////////////////////////////////////////////////////////////////////////
@ -64,7 +64,7 @@ public abstract class BondRepository<T extends Bond, R extends BondedAsset> impl
///////////////////////////////////////////////////////////////////////////////////////////
public static void applyBondState(DaoStateService daoStateService,
Bond bond,
Bond<?> bond,
Tx lockupTx,
TxOutput lockupTxOutput) {
if (bond.getBondState() != BondState.LOCKUP_TX_PENDING || bond.getBondState() != BondState.UNLOCK_TX_PENDING)
@ -132,7 +132,7 @@ public abstract class BondRepository<T extends Bond, R extends BondedAsset> impl
.anyMatch(data -> Arrays.equals(BondConsensus.getHashFromOpReturnData(data), bondedAsset.getHash()));
}
public static boolean isConfiscated(Bond bond, DaoStateService daoStateService) {
public static boolean isConfiscated(Bond<?> bond, DaoStateService daoStateService) {
return (bond.getLockupTxId() != null && daoStateService.isConfiscatedLockupTxOutput(bond.getLockupTxId())) ||
(bond.getUnlockTxId() != null && daoStateService.isConfiscatedUnlockTxOutput(bond.getUnlockTxId()));
}
@ -142,9 +142,9 @@ public abstract class BondRepository<T extends Bond, R extends BondedAsset> impl
protected final BsqWalletService bsqWalletService;
// This map is just for convenience. The data which are used to fill the map are stored in the DaoState (role, txs).
protected final Map<String, T> bondByUidMap = new HashMap<>();
protected final Map<String, B> bondByUidMap = new HashMap<>();
@Getter
protected final ObservableList<T> bonds = FXCollections.observableArrayList();
protected final ObservableList<B> bonds = FXCollections.observableArrayList();
///////////////////////////////////////////////////////////////////////////////////////////
@ -192,12 +192,12 @@ public abstract class BondRepository<T extends Bond, R extends BondedAsset> impl
// API
///////////////////////////////////////////////////////////////////////////////////////////
public boolean isBondedAssetAlreadyInBond(R bondedAsset) {
public boolean isBondedAssetAlreadyInBond(T bondedAsset) {
boolean contains = bondByUidMap.containsKey(bondedAsset.getUid());
return contains && bondByUidMap.get(bondedAsset.getUid()).getLockupTxId() != null;
}
public List<Bond> getActiveBonds() {
public List<B> getActiveBonds() {
return bonds.stream().filter(Bond::isActive).collect(Collectors.toList());
}
@ -206,17 +206,17 @@ public abstract class BondRepository<T extends Bond, R extends BondedAsset> impl
// Protected
///////////////////////////////////////////////////////////////////////////////////////////
protected abstract T createBond(R bondedAsset);
protected abstract B createBond(T bondedAsset);
protected abstract void updateBond(T bond, R bondedAsset, TxOutput lockupTxOutput);
protected abstract void updateBond(B bond, T bondedAsset, TxOutput lockupTxOutput);
protected abstract Stream<R> getBondedAssetStream();
protected abstract Stream<T> getBondedAssetStream();
protected void update() {
log.debug("update");
getBondedAssetStream().forEach(bondedAsset -> {
String uid = bondedAsset.getUid();
T bond = bondByUidMap.computeIfAbsent(uid, u -> createBond(bondedAsset));
B bond = bondByUidMap.computeIfAbsent(uid, u -> createBond(bondedAsset));
daoStateService.getLockupTxOutputs().forEach(lockupTxOutput ->
updateBond(bond, bondedAsset, lockupTxOutput));

View File

@ -50,7 +50,6 @@ import javax.annotation.Nullable;
@FxmlView
public class BondingView extends ActivatableView<AnchorPane, Void> {
private final ViewLoader viewLoader;
private final Navigation navigation;
@ -138,8 +137,7 @@ public class BondingView extends ActivatableView<AnchorPane, Void> {
else if (view instanceof BondsView) {
toggleGroup.selectToggle(bonds);
if (data instanceof Bond)
((BondsView) view).setSelectedBond((Bond) data);
((BondsView) view).setSelectedBond((Bond<?>) data);
}
}
}

View File

@ -37,7 +37,7 @@ import lombok.extern.slf4j.Slf4j;
@Value
@Slf4j
class BondListItem {
private final Bond bond;
private final Bond<?> bond;
private final String bondType;
private final String lockupTxId;
private final String amount;
@ -47,7 +47,7 @@ class BondListItem {
private final BondState bondState;
private final String bondStateString;
BondListItem(Bond bond, BsqFormatter bsqFormatter) {
BondListItem(Bond<?> bond, BsqFormatter bsqFormatter) {
this.bond = bond;
amount = bsqFormatter.formatCoin(Coin.valueOf(bond.getAmount()));

View File

@ -76,7 +76,7 @@ public class BondsView extends ActivatableView<GridPane, Void> {
private ListChangeListener<BondedRole> bondedRolesListener;
private ListChangeListener<BondedReputation> bondedReputationListener;
private Bond selectedBond;
private Bond<?> selectedBond;
///////////////////////////////////////////////////////////////////////////////////////////
// Constructor, lifecycle
@ -124,7 +124,7 @@ public class BondsView extends ActivatableView<GridPane, Void> {
// API
///////////////////////////////////////////////////////////////////////////////////////////
public void setSelectedBond(Bond bond) {
public void setSelectedBond(Bond<?> bond) {
// Set the selected bond if it's found in the tableView, which listens to sortedList.
// If this is called before the sortedList has been populated the selected bond is stored and
// we try to apply again after the next update.
@ -141,7 +141,7 @@ public class BondsView extends ActivatableView<GridPane, Void> {
///////////////////////////////////////////////////////////////////////////////////////////
private void updateList() {
List<Bond> combined = new ArrayList<>(bondedReputationRepository.getBonds());
List<Bond<?>> combined = new ArrayList<>(bondedReputationRepository.getBonds());
combined.addAll(bondedRolesRepository.getBonds());
observableList.setAll(combined.stream()
.map(bond -> new BondListItem(bond, bsqFormatter))
@ -149,7 +149,7 @@ public class BondsView extends ActivatableView<GridPane, Void> {
.collect(Collectors.toList()));
GUIUtil.setFitToRowsForTableView(tableView, 37, 28, 2, 30);
if (selectedBond != null) {
Bond bond = selectedBond;
Bond<?> bond = selectedBond;
selectedBond = null;
setSelectedBond(bond);
}
@ -259,8 +259,6 @@ public class BondsView extends ActivatableView<GridPane, Void> {
@Override
public TableCell<BondListItem, BondListItem> call(TableColumn<BondListItem, BondListItem> column) {
return new TableCell<>() {
private InfoAutoTooltipLabel infoTextField;
@Override
public void updateItem(final BondListItem item, boolean empty) {
super.updateItem(item, empty);
@ -271,7 +269,7 @@ public class BondsView extends ActivatableView<GridPane, Void> {
info = item.getBondDetails() + "\n" + info;
}
infoTextField = new InfoAutoTooltipLabel(item.getBondDetails(),
InfoAutoTooltipLabel infoTextField = new InfoAutoTooltipLabel(item.getBondDetails(),
AwesomeIcon.INFO_SIGN,
ContentDisplay.LEFT,
info,

View File

@ -120,7 +120,7 @@ public class ProposalDisplay {
@Nullable
public ComboBox<Param> paramComboBox;
@Nullable
public ComboBox<Bond> confiscateBondComboBox;
public ComboBox<Bond<?>> confiscateBondComboBox;
@Nullable
public ComboBox<BondedRoleType> bondedRoleTypeComboBox;
@Nullable
@ -371,7 +371,7 @@ public class ProposalDisplay {
confiscateBondComboBox.setItems(FXCollections.observableArrayList(daoFacade.getAllActiveBonds()));
confiscateBondComboBox.setConverter(new StringConverter<>() {
@Override
public String toString(Bond bond) {
public String toString(Bond<?> bond) {
String details = " (" + Res.get("dao.bond.table.column.lockupTxId") + ": " + bond.getLockupTxId() + ")";
if (bond instanceof BondedRole) {
return bond.getBondedAsset().getDisplayString() + details;
@ -381,7 +381,7 @@ public class ProposalDisplay {
}
@Override
public Bond fromString(String string) {
public Bond<?> fromString(String string) {
return null;
}
});

View File

@ -453,7 +453,7 @@ public class MakeProposalView extends ActivatableView<GridPane, Void> implements
case CONFISCATE_BOND:
checkNotNull(proposalDisplay.confiscateBondComboBox,
"proposalDisplay.confiscateBondComboBox must not be null");
Bond bond = proposalDisplay.confiscateBondComboBox.getSelectionModel().getSelectedItem();
Bond<?> bond = proposalDisplay.confiscateBondComboBox.getSelectionModel().getSelectedItem();
if (!bond.isActive())
throw new VoteResultException.ValidationException("Bond is not locked and can't be confiscated");