Skip to content

Commit

Permalink
#616 equals and hashcode for Wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
amihaiemil committed Oct 16, 2020
1 parent 9e7510e commit 50d5550
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
23 changes: 23 additions & 0 deletions self-api/src/main/java/com/selfxdsd/api/Wallet.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Iterator;
import java.util.Objects;

/**
* A project's wallet.
Expand Down Expand Up @@ -239,6 +240,28 @@ public Iterator<PaymentMethod> iterator() {
}
};
}

@Override
public boolean equals(final Object other) {
boolean equals;
if (this == other) {
equals = true;
} else {
if (other == null || getClass() != other.getClass()) {
equals = false;
} else {
final Missing missing = (Missing) other;
equals = this.project.equals(missing.project)
&& this.type.equals(missing.type);
}
}
return equals;
}

@Override
public int hashCode() {
return Objects.hash(this.project, this.type);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,13 @@
import java.math.RoundingMode;
import java.time.LocalDateTime;
import java.time.OffsetDateTime;
import java.util.Objects;

/**
* A Project's Stripe wallet.
* @author Mihai Andronache (amihaiemil@gmail.com)
* @version $Id$
* @since 0.0.27
* @todo #609:15min Implement equals() and hashCode() for StripeWallet since
* StoredPaymentMethod is using Wallet for its equals and hashCode methods.
*/
public final class StripeWallet implements Wallet {

Expand Down Expand Up @@ -252,4 +251,25 @@ public Wallet updateCash(final BigDecimal cash) {
public PaymentMethods paymentMethods() {
return this.storage.paymentMethods().ofWallet(this);
}

@Override
public boolean equals(final Object other) {
boolean equals;
if (this == other) {
equals = true;
} else {
if (other == null || getClass() != other.getClass()) {
equals = false;
} else {
final StripeWallet stripeWallet = (StripeWallet) other;
equals = this.project.equals(stripeWallet.project);
}
}
return equals;
}

@Override
public int hashCode() {
return Objects.hash(this.project);
}
}

0 comments on commit 50d5550

Please sign in to comment.