Skip to content

Commit

Permalink
Require StripeJsonModel subclasseses to implement hashCode() and equa…
Browse files Browse the repository at this point in the history
…ls() (#1079)
  • Loading branch information
mshafrir-stripe authored Jun 10, 2019
1 parent e4c029b commit 1a55ad4
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ public abstract class StripeJsonModel {
@NonNull
public abstract JSONObject toJson();

@Override
public abstract int hashCode();

@Override
public abstract boolean equals(@Nullable Object obj);

static void putStripeJsonModelMapIfNotNull(
@NonNull Map<String, Object> upperLevelMap,
@NonNull @Size(min = 1) String key,
Expand Down Expand Up @@ -63,7 +69,6 @@ static void putStripeJsonModelListIfNotNull(
upperLevelMap.put(key, mapList);
}


static void putStripeJsonModelListIfNotNull(
@NonNull JSONObject jsonObject,
@NonNull @Size(min = 1) String key,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ private MasterpassWallet(@NonNull Parcel in) {
}

@Override
public void writeToParcel(Parcel dest, int flags) {
public void writeToParcel(@NonNull Parcel dest, int flags) {
super.writeToParcel(dest, flags);
dest.writeParcelable(billingAddress, flags);
dest.writeString(email);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ private VisaCheckoutWallet(@NonNull Parcel in) {
}

@Override
public void writeToParcel(Parcel dest, int flags) {
public void writeToParcel(@NonNull Parcel dest, int flags) {
super.writeToParcel(dest, flags);
dest.writeParcelable(billingAddress, flags);
dest.writeString(email);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.AbstractMap;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

import static com.stripe.android.model.StripeJsonUtils.optString;

Expand All @@ -31,7 +32,7 @@ public abstract class Wallet extends StripeJsonModel implements Parcelable {

Wallet(@NonNull Parcel in) {
dynamicLast4 = in.readString();
walletType = Type.fromCode(in.readString());
walletType = Objects.requireNonNull(Type.fromCode(in.readString()));
}

@Override
Expand All @@ -40,7 +41,7 @@ public int describeContents() {
}

@Override
public void writeToParcel(Parcel dest, int flags) {
public void writeToParcel(@NonNull Parcel dest, int flags) {
dest.writeString(dynamicLast4);
dest.writeString(walletType.code);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ public JSONObject toJson() {
return jsonObject;
}

@Override
public int hashCode() {
return 0;
}

@Override
public boolean equals(Object obj) {
if (!(obj instanceof ExampleJsonModel)) {
Expand Down

0 comments on commit 1a55ad4

Please sign in to comment.