From 12abae6da924cb33858fbc9948fdf7a181e2038c Mon Sep 17 00:00:00 2001 From: Fibinger Ádám <adam.fibinger@wup.hu> Date: Tue, 12 Mar 2019 19:31:27 +0100 Subject: [PATCH] Decoupling final version --- src/main/java/hu/unr/fiber/cardapi/rest/RestCard.java | 96 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 96 insertions(+), 0 deletions(-) diff --git a/src/main/java/hu/unr/fiber/cardapi/rest/RestCard.java b/src/main/java/hu/unr/fiber/cardapi/rest/RestCard.java new file mode 100644 index 0000000..8cd4b1a --- /dev/null +++ b/src/main/java/hu/unr/fiber/cardapi/rest/RestCard.java @@ -0,0 +1,96 @@ +package hu.unr.fiber.cardapi.rest; + +import com.fasterxml.jackson.annotation.JsonCreator; +import hu.unr.fiber.cardapi.interfaces.CardInterface; + +import java.util.Objects; + + +public class RestCard implements CardInterface { + public static final long INVALID_ID = 0; + private long id = INVALID_ID; + + private String name; + //FIXME: @Pattern([0-9]+) + private String number; + private String cardHolder; + + public RestCard(long id) { + this.id = id; + } + + public RestCard(long id, String name, String number) { + this.setId(id) + .setName(name) + .setNumber(number); + } + + @JsonCreator + public RestCard(long id, String name, String number, String cardHolder) { + this.setId(id) + .setName(name) + .setNumber(number) + .setCardHolder(cardHolder); + } + + public long getId() { + return id; + } + + public boolean validId() { + return (this.getId() != RestCard.INVALID_ID); + } + + public RestCard setId(long id) { + this.id = id; + return this; + } + + public String getName() { + return name; + } + + public RestCard setName(String name) { + this.name = name; + return this; + } + + public String getNumber() { + return number; + } + + public RestCard setNumber(String number) { + this.number = number; + return this; + } + + public String getCardHolder() { + return cardHolder; + } + + public RestCard setCardHolder(String cardHolder) { + this.cardHolder = cardHolder; + return this; + } + + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + RestCard card = (RestCard) o; + return id == card.id && + name.equals(card.name) && + number.equals(card.number) && + Objects.equals(cardHolder, card.cardHolder); + } + + public RestCard update(CardInterface otherCard) { + this.setName(otherCard.getName()); + this.setNumber(otherCard.getNumber()); + this.setCardHolder(otherCard.getCardHolder()); + return this; + } + + public String toString() { + return "#" + this.number + " - " + this.name + " @ " + this.cardHolder; + } +} -- Gitblit v1.8.0