Skip to content

Commit

Permalink
[core] Code cleanup with lombok
Browse files Browse the repository at this point in the history
  • Loading branch information
bigscoop authored Aug 13, 2023
1 parent e63562d commit 84cd9bc
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 114 deletions.
3 changes: 1 addition & 2 deletions xchange-bibox/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,5 @@
<artifactId>xchange-core</artifactId>
<version>${project.version}</version>
</dependency>

</dependencies>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ public AccountInfo getAccountInfo() throws IOException {
public String withdrawFunds(WithdrawFundsParams params) throws IOException {
if (params instanceof DefaultWithdrawFundsParams) {
DefaultWithdrawFundsParams defaultWithdrawFundsParams = (DefaultWithdrawFundsParams) params;
String address = defaultWithdrawFundsParams.address;
String address = defaultWithdrawFundsParams.getAddress();
if (params instanceof RippleWithdrawFundsParams) {
address = address + "?dt=" + ((RippleWithdrawFundsParams) params).tag;
address = address + "?dt=" + ((RippleWithdrawFundsParams) params).getTag();
}
return withdrawCrypto(
address,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ public String withdrawFunds(WithdrawFundsParams p)
DefaultWithdrawFundsParams params = (DefaultWithdrawFundsParams) p;
CoingiWithdrawalRequest request =
new CoingiWithdrawalRequest()
.setAddress(params.address)
.setAmount(params.amount)
.setCurrency(params.currency.getCurrencyCode().toUpperCase());
.setAddress(params.getAddress())
.setAmount(params.getAmount())
.setCurrency(params.getCurrency().getCurrencyCode().toUpperCase());

return withdraw(request).toString();
}
Expand Down
1 change: 1 addition & 0 deletions xchange-core/lombok.config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lombok.equalsAndHashCode.callSuper = call
Original file line number Diff line number Diff line change
@@ -1,48 +1,16 @@
package org.knowm.xchange.dto.account;

import java.io.Serializable;
import java.util.Objects;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Value;

public final class AddressWithTag implements Serializable {
@Value
@Builder
@AllArgsConstructor
public class AddressWithTag {

private final String address;
private final String addressTag;
String address;

public AddressWithTag(String address, String addressTag) {
this.address = address;
this.addressTag = addressTag;
}
String addressTag;

public String getAddress() {
return address;
}

public String getAddressTag() {
return addressTag;
}

@Override
public String toString() {
return "AddressWithTag{"
+ "address='"
+ address
+ '\''
+ ", addressTag='"
+ addressTag
+ '\''
+ '}';
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
AddressWithTag that = (AddressWithTag) o;
return Objects.equals(address, that.address) && Objects.equals(addressTag, that.addressTag);
}

@Override
public int hashCode() {
return Objects.hash(address, addressTag);
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
package org.knowm.xchange.service.trade.params;

import java.math.BigDecimal;
import javax.annotation.Nullable;
import lombok.Value;
import lombok.experimental.NonFinal;
import org.knowm.xchange.currency.Currency;
import org.knowm.xchange.dto.account.AddressWithTag;

@Value
@NonFinal
public class DefaultWithdrawFundsParams implements WithdrawFundsParams {
public final String address;

private final String addressTag;
String address;

public final Currency currency;
String addressTag;

public final BigDecimal amount;
Currency currency;

@Nullable public final BigDecimal commission;
BigDecimal amount;

BigDecimal commission;

public DefaultWithdrawFundsParams(String address, Currency currency, BigDecimal amount) {
this(address, currency, amount, null);
Expand All @@ -24,72 +28,31 @@ public DefaultWithdrawFundsParams(AddressWithTag address, Currency currency, Big
this(address, currency, amount, null);
}

public DefaultWithdrawFundsParams(
String address, Currency currency, BigDecimal amount, BigDecimal commission) {
public DefaultWithdrawFundsParams(String address, Currency currency, BigDecimal amount,
BigDecimal commission) {
this.address = address;
this.addressTag = null;
this.currency = currency;
this.amount = amount;
this.commission = commission;
}

public DefaultWithdrawFundsParams(
AddressWithTag address, Currency currency, BigDecimal amount, BigDecimal commission) {
public DefaultWithdrawFundsParams(AddressWithTag address, Currency currency, BigDecimal amount,
BigDecimal commission) {
this.address = address.getAddress();
this.addressTag = address.getAddressTag();
this.currency = currency;
this.amount = amount;
this.commission = commission;
}

public DefaultWithdrawFundsParams(
String address,
String addressTag,
Currency currency,
BigDecimal amount,
BigDecimal commission) {
public DefaultWithdrawFundsParams(String address, String addressTag, Currency currency,
BigDecimal amount, BigDecimal commission) {
this.address = address;
this.addressTag = addressTag;
this.currency = currency;
this.amount = amount;
this.commission = commission;
}

public String getAddress() {
return address;
}

public String getAddressTag() {
return addressTag;
}

public Currency getCurrency() {
return currency;
}

public BigDecimal getAmount() {
return amount;
}

@Nullable
public BigDecimal getCommission() {
return commission;
}

@Override
public String toString() {
return "DefaultWithdrawFundsParams{"
+ "address='"
+ getAddress()
+ ", addressTag="
+ getAddressTag()
+ '\''
+ ", currency="
+ getCurrency()
+ ", amount="
+ getAmount()
+ ", commission="
+ getCommission()
+ '}';
}
}
1 change: 1 addition & 0 deletions xchange-kucoin/lombok.config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lombok.equalsAndHashCode.callSuper = call
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,42 @@
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import java.math.BigDecimal;
import lombok.Builder;
import lombok.Getter;
import lombok.ToString;
import lombok.Value;

@Getter
@ToString
@Value
@Builder
@JsonInclude(value = Include.NON_EMPTY, content = Include.NON_NULL)
public class ApplyWithdrawApiRequest {

/** Currency */
private final String currency;
String currency;

/** Withdrawal address */
private final String address;
String address;

/**
* Withdrawal amount, a positive number which is a multiple of the amount precision (fees
* excluded)
*/
private final BigDecimal amount;
BigDecimal amount;

/**
* [optional] The note that is left on the withdrawal address. When you withdraw from KuCoin to
* other platforms, you need to fill in memo(tag). If you don't fill in memo(tag), your withdrawal
* may not be available.
*/
private final String memo;
String memo;

/** [optional] Internal withdrawal or not. Default setup: false */
@Builder.Default private final boolean isInner = false;
boolean isInner;

/** [optional] Remark */
private final String remark;
String remark;

/**
* [optional] The chain name of currency, e.g. The available value for USDT are OMNI, ERC20,
* TRC20, default is OMNI. This only apply for multi-chain currency, and there is no need for
* single chain currency.
*/
private final String chain;
String chain;
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public String withdrawFunds(Currency currency, BigDecimal amount, String address
public String withdrawFunds(WithdrawFundsParams params) throws IOException {
if (params instanceof DefaultWithdrawFundsParams) {
DefaultWithdrawFundsParams defaultParams = (DefaultWithdrawFundsParams) params;
return withdrawFunds(defaultParams.currency, defaultParams.amount, defaultParams.address);
return withdrawFunds(defaultParams.getCurrency(), defaultParams.getAmount(), defaultParams.getAddress());
}
throw new IllegalStateException("Don't know how to withdraw: " + params);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public AccountInfo getAccountInfo() throws IOException {
public String withdrawFunds(WithdrawFundsParams params) throws IOException {
if (params instanceof DefaultWithdrawFundsParams) {
DefaultWithdrawFundsParams p = (DefaultWithdrawFundsParams) params;
return withdrawFunds0(p.currency, p.amount, p.address, p.commission);
return withdrawFunds0(p.getCurrency(), p.getAmount(), p.getAddress(), p.getCommission());
}
throw new IllegalStateException("Don't know how to withdraw: " + params);
}
Expand Down

0 comments on commit 84cd9bc

Please sign in to comment.