diff --git a/hibernate-types-52/src/test/java/com/vladmihalcea/hibernate/type/json/polymorphic/PostgreSQLJsonPolymorphicListCustomTypeTest.java b/hibernate-types-52/src/test/java/com/vladmihalcea/hibernate/type/json/polymorphic/PostgreSQLJsonPolymorphicListCustomTypeTest.java index 91faab86d..c03aaf165 100644 --- a/hibernate-types-52/src/test/java/com/vladmihalcea/hibernate/type/json/polymorphic/PostgreSQLJsonPolymorphicListCustomTypeTest.java +++ b/hibernate-types-52/src/test/java/com/vladmihalcea/hibernate/type/json/polymorphic/PostgreSQLJsonPolymorphicListCustomTypeTest.java @@ -12,9 +12,10 @@ import javax.persistence.*; import java.io.Serializable; -import java.sql.Timestamp; -import java.time.LocalDateTime; +import java.math.BigDecimal; import java.util.*; +import java.util.function.Function; +import java.util.stream.Collectors; import static org.junit.Assert.assertEquals; @@ -41,11 +42,15 @@ protected void additionalProperties(Properties properties) { objectMapper.activateDefaultTypingAsProperty( objectMapper.getPolymorphicTypeValidator(), ObjectMapper.DefaultTyping.OBJECT_AND_NON_CONCRETE, - "className" + "type" ), ArrayList.class - ), - "json-polymorphic-list" + ) { + @Override + public String getName() { + return "json-polymorphic-list"; + } + } ) ) ); @@ -54,17 +59,15 @@ protected void additionalProperties(Properties properties) { @Test public void test() { - Timestamp validUntil = Timestamp.valueOf(LocalDateTime.now().plusDays(10)); - doInJPA(entityManager -> { entityManager.persist( new Book() .setIsbn("978-9730228236") - .addTopic(new Post("High-Performance Java Persistence") - .setContent("It rocks!") + .addCoupon(new AmountDiscountCoupon("PPP") + .setAmount(new BigDecimal("4.99")) ) - .addTopic(new Announcement("Black Friday - 50% discount") - .setValidUntil(validUntil) + .addCoupon(new PercentageDiscountCoupon("Black Friday") + .setPercentage(BigDecimal.valueOf(0.02)) ) ); }); @@ -74,14 +77,28 @@ public void test() { .bySimpleNaturalId(Book.class) .load("978-9730228236"); - List topics = book.getTopics(); + Map topics = book.getCoupons() + .stream() + .collect( + Collectors.toMap( + DiscountCoupon::getName, + Function.identity() + ) + ); + assertEquals(2, topics.size()); - Post post = (Post) topics.get(0); - assertEquals("It rocks!", post.getContent()); - Announcement announcement = (Announcement) topics.get(1); + AmountDiscountCoupon amountDiscountCoupon = (AmountDiscountCoupon) + topics.get("PPP"); + assertEquals( + new BigDecimal("4.99"), + amountDiscountCoupon.getAmount() + ); + + PercentageDiscountCoupon percentageDiscountCoupon = (PercentageDiscountCoupon) + topics.get("Black Friday"); assertEquals( - validUntil.getTime(), - announcement.getValidUntil().getTime() + BigDecimal.valueOf(0.02), + percentageDiscountCoupon.getPercentage() ); }); } @@ -100,7 +117,7 @@ public static class Book { @Type(type = "json-polymorphic-list") @Column(columnDefinition = "jsonb") - private List topics = new ArrayList<>(); + private List coupons = new ArrayList<>(); public String getIsbn() { return isbn; @@ -111,83 +128,92 @@ public Book setIsbn(String isbn) { return this; } - public List getTopics() { - return topics; + public List getCoupons() { + return coupons; } - public Book setTopics(List topics) { - this.topics = topics; + public Book setCoupons(List coupons) { + this.coupons = coupons; return this; } - public Book addTopic(Topic topic) { - topics.add(topic); + public Book addCoupon(DiscountCoupon topic) { + coupons.add(topic); return this; } } - public static abstract class Topic implements Serializable { + public abstract static class DiscountCoupon implements Serializable { - private String title; + private String name; + + public DiscountCoupon() { + } - public Topic() { + public DiscountCoupon(String name) { + this.name = name; } - public Topic(String title) { - this.title = title; + public String getName() { + return name; } - public String getTitle() { - return title; + public void setName(String name) { + this.name = name; } - public void setTitle(String title) { - this.title = title; + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof DiscountCoupon)) return false; + DiscountCoupon that = (DiscountCoupon) o; + return Objects.equals(getName(), that.getName()); } - String getType() { - return getClass().getSimpleName(); + @Override + public int hashCode() { + return Objects.hash(getName()); } } - public static class Post extends Topic { + public static class AmountDiscountCoupon extends DiscountCoupon { - private String content; + private BigDecimal amount; - public Post() { + public AmountDiscountCoupon() { } - public Post(String title) { - super(title); + public AmountDiscountCoupon(String name) { + super(name); } - public String getContent() { - return content; + public BigDecimal getAmount() { + return amount; } - public Post setContent(String content) { - this.content = content; + public AmountDiscountCoupon setAmount(BigDecimal amount) { + this.amount = amount; return this; } } - public static class Announcement extends Topic { + public static class PercentageDiscountCoupon extends DiscountCoupon { - private Date validUntil; + private BigDecimal percentage; - public Announcement() { + public PercentageDiscountCoupon() { } - public Announcement(String title) { - super(title); + public PercentageDiscountCoupon(String name) { + super(name); } - public Date getValidUntil() { - return validUntil; + public BigDecimal getPercentage() { + return percentage; } - public Announcement setValidUntil(Date validUntil) { - this.validUntil = validUntil; + public PercentageDiscountCoupon setPercentage(BigDecimal amount) { + this.percentage = amount; return this; } } diff --git a/hibernate-types-52/src/test/java/com/vladmihalcea/hibernate/type/json/polymorphic/PostgreSQLJsonPolymorphicListJacksonTypeTest.java b/hibernate-types-52/src/test/java/com/vladmihalcea/hibernate/type/json/polymorphic/PostgreSQLJsonPolymorphicListJacksonTypeTest.java index 38431f33a..b8cde0530 100644 --- a/hibernate-types-52/src/test/java/com/vladmihalcea/hibernate/type/json/polymorphic/PostgreSQLJsonPolymorphicListJacksonTypeTest.java +++ b/hibernate-types-52/src/test/java/com/vladmihalcea/hibernate/type/json/polymorphic/PostgreSQLJsonPolymorphicListJacksonTypeTest.java @@ -2,7 +2,6 @@ import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.annotation.JsonTypeInfo; -import com.fasterxml.jackson.annotation.JsonTypeName; import com.vladmihalcea.hibernate.type.json.JsonBinaryType; import com.vladmihalcea.hibernate.util.AbstractPostgreSQLIntegrationTest; import org.hibernate.Session; @@ -13,11 +12,13 @@ import javax.persistence.*; import java.io.Serializable; -import java.sql.Timestamp; -import java.time.LocalDateTime; +import java.math.BigDecimal; import java.util.ArrayList; -import java.util.Date; import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.function.Function; +import java.util.stream.Collectors; import static org.junit.Assert.assertEquals; @@ -36,17 +37,15 @@ protected Class[] entities() { @Test public void test() { - Timestamp validUntil = Timestamp.valueOf(LocalDateTime.now().plusDays(10)); - doInJPA(entityManager -> { entityManager.persist( new Book() .setIsbn("978-9730228236") - .addTopic(new Post("High-Performance Java Persistence") - .setContent("It rocks!") + .addCoupon(new AmountDiscountCoupon("PPP") + .setAmount(new BigDecimal("4.99")) ) - .addTopic(new Announcement("Black Friday - 50% discount") - .setValidUntil(validUntil) + .addCoupon(new PercentageDiscountCoupon("Black Friday") + .setPercentage(BigDecimal.valueOf(0.02)) ) ); }); @@ -56,14 +55,26 @@ public void test() { .bySimpleNaturalId(Book.class) .load("978-9730228236"); - List topics = book.getTopics(); + Map topics = book.getCoupons() + .stream() + .collect( + Collectors.toMap( + DiscountCoupon::getName, + Function.identity() + ) + ); + assertEquals(2, topics.size()); - Post post = (Post) topics.get(0); - assertEquals("It rocks!", post.getContent()); - Announcement announcement = (Announcement) topics.get(1); + AmountDiscountCoupon amountDiscountCoupon = (AmountDiscountCoupon) topics.get("PPP"); + assertEquals( + new BigDecimal("4.99"), + amountDiscountCoupon.getAmount() + ); + + PercentageDiscountCoupon percentageDiscountCoupon = (PercentageDiscountCoupon) topics.get("Black Friday"); assertEquals( - validUntil.getTime(), - announcement.getValidUntil().getTime() + BigDecimal.valueOf(0.02), + percentageDiscountCoupon.getPercentage() ); }); } @@ -83,7 +94,7 @@ public static class Book { @Type(type = "jsonb") @Column(columnDefinition = "jsonb") - private List topics = new ArrayList<>(); + private List coupons = new ArrayList<>(); public String getIsbn() { return isbn; @@ -94,17 +105,17 @@ public Book setIsbn(String isbn) { return this; } - public List getTopics() { - return topics; + public List getCoupons() { + return coupons; } - public Book setTopics(List topics) { - this.topics = topics; + public Book setCoupons(List coupons) { + this.coupons = coupons; return this; } - public Book addTopic(Topic topic) { - topics.add(topic); + public Book addCoupon(DiscountCoupon topic) { + coupons.add(topic); return this; } } @@ -116,92 +127,103 @@ public Book addTopic(Topic topic) { ) @JsonSubTypes({ @JsonSubTypes.Type( - name = "topic.post", - value = Post.class + name = "discount.coupon.amount", + value = AmountDiscountCoupon.class ), @JsonSubTypes.Type( - name = "topic.announcement", - value = Announcement.class + name = "discount.coupon.percentage", + value = PercentageDiscountCoupon.class ), }) - public abstract static class Topic implements Serializable { + public abstract static class DiscountCoupon implements Serializable { - private String title; + private String name; - public Topic() { + public DiscountCoupon() { } - public Topic(String title) { - this.title = title; + public DiscountCoupon(String name) { + this.name = name; } - public String getTitle() { - return title; + public String getName() { + return name; } - public void setTitle(String title) { - this.title = title; + public void setName(String name) { + this.name = name; } @JsonTypeInfo(use = JsonTypeInfo.Id.NAME) public abstract String getType(); + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof DiscountCoupon)) return false; + DiscountCoupon that = (DiscountCoupon) o; + return Objects.equals(getName(), that.getName()); + } + + @Override + public int hashCode() { + return Objects.hash(getName()); + } } - @JsonTypeName(Post.QUALIFIER) - public static class Post extends Topic { + public static class AmountDiscountCoupon extends DiscountCoupon { - public static final String QUALIFIER = "topic.post"; + public static final String DISCRIMINATOR = "discount.coupon.amount"; - private String content; + private BigDecimal amount; - public Post() { + public AmountDiscountCoupon() { } - public Post(String title) { - super(title); + public AmountDiscountCoupon(String name) { + super(name); } - public String getContent() { - return content; + public BigDecimal getAmount() { + return amount; } - public Post setContent(String content) { - this.content = content; + public AmountDiscountCoupon setAmount(BigDecimal amount) { + this.amount = amount; return this; } @Override public String getType() { - return Post.QUALIFIER; + return DISCRIMINATOR; } } - @JsonTypeName("topic.announcement") - public static class Announcement extends Topic { + public static class PercentageDiscountCoupon extends DiscountCoupon { - public static final String QUALIFIER = "topic.announcement"; + public static final String DISCRIMINATOR = "discount.coupon.percentage"; - private Date validUntil; + private BigDecimal percentage; - public Announcement() { + public PercentageDiscountCoupon() { } - public Announcement(String title) { - super(title); + public PercentageDiscountCoupon(String name) { + super(name); } - public Date getValidUntil() { - return validUntil; + public BigDecimal getPercentage() { + return percentage; } - public Announcement setValidUntil(Date validUntil) { - this.validUntil = validUntil; + public PercentageDiscountCoupon setPercentage(BigDecimal amount) { + this.percentage = amount; return this; } @Override public String getType() { - return QUALIFIER; + return DISCRIMINATOR; } } } \ No newline at end of file diff --git a/hibernate-types-55/src/test/java/com/vladmihalcea/hibernate/type/json/polymorphic/PostgreSQLJsonPolymorphicListCustomTypeTest.java b/hibernate-types-55/src/test/java/com/vladmihalcea/hibernate/type/json/polymorphic/PostgreSQLJsonPolymorphicListCustomTypeTest.java index 7aad816e0..e1a3978e9 100644 --- a/hibernate-types-55/src/test/java/com/vladmihalcea/hibernate/type/json/polymorphic/PostgreSQLJsonPolymorphicListCustomTypeTest.java +++ b/hibernate-types-55/src/test/java/com/vladmihalcea/hibernate/type/json/polymorphic/PostgreSQLJsonPolymorphicListCustomTypeTest.java @@ -1,26 +1,21 @@ package com.vladmihalcea.hibernate.type.json.polymorphic; -import com.fasterxml.jackson.annotation.JsonSubTypes; -import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.fasterxml.jackson.databind.ObjectMapper; import com.vladmihalcea.hibernate.type.json.JsonBinaryType; -import com.vladmihalcea.hibernate.type.json.configuration.CustomObjectMapperSupplier; -import com.vladmihalcea.hibernate.type.json.configuration.PostgreSQLJsonBinaryTypeProgrammaticConfigurationTest; import com.vladmihalcea.hibernate.type.util.ObjectMapperWrapper; import com.vladmihalcea.hibernate.util.AbstractPostgreSQLIntegrationTest; import org.hibernate.Session; import org.hibernate.annotations.NaturalId; import org.hibernate.annotations.Type; -import org.hibernate.annotations.TypeDef; import org.hibernate.jpa.boot.spi.TypeContributorList; import org.junit.Test; import javax.persistence.*; import java.io.Serializable; -import java.sql.*; -import java.time.LocalDateTime; +import java.math.BigDecimal; import java.util.*; -import java.util.Date; +import java.util.function.Function; +import java.util.stream.Collectors; import static org.junit.Assert.assertEquals; @@ -47,11 +42,15 @@ protected void additionalProperties(Properties properties) { objectMapper.activateDefaultTypingAsProperty( objectMapper.getPolymorphicTypeValidator(), ObjectMapper.DefaultTyping.OBJECT_AND_NON_CONCRETE, - "className" + "type" ), ArrayList.class - ), - "json-polymorphic-list" + ) { + @Override + public String getName() { + return "json-polymorphic-list"; + } + } ) ) ); @@ -60,17 +59,15 @@ protected void additionalProperties(Properties properties) { @Test public void test() { - Timestamp validUntil = java.sql.Timestamp.valueOf(LocalDateTime.now().plusDays(10)); - doInJPA(entityManager -> { entityManager.persist( new Book() .setIsbn("978-9730228236") - .addTopic(new Post("High-Performance Java Persistence") - .setContent("It rocks!") + .addCoupon(new AmountDiscountCoupon("PPP") + .setAmount(new BigDecimal("4.99")) ) - .addTopic(new Announcement("Black Friday - 50% discount") - .setValidUntil(validUntil) + .addCoupon(new PercentageDiscountCoupon("Black Friday") + .setPercentage(BigDecimal.valueOf(0.02)) ) ); }); @@ -80,14 +77,26 @@ public void test() { .bySimpleNaturalId(Book.class) .load("978-9730228236"); - List topics = book.getTopics(); + Map topics = book.getCoupons() + .stream() + .collect( + Collectors.toMap( + DiscountCoupon::getName, + Function.identity() + ) + ); + assertEquals(2, topics.size()); - Post post = (Post) topics.get(0); - assertEquals("It rocks!", post.getContent()); - Announcement announcement = (Announcement) topics.get(1); + AmountDiscountCoupon amountDiscountCoupon = (AmountDiscountCoupon) topics.get("PPP"); + assertEquals( + new BigDecimal("4.99"), + amountDiscountCoupon.getAmount() + ); + + PercentageDiscountCoupon percentageDiscountCoupon = (PercentageDiscountCoupon) topics.get("Black Friday"); assertEquals( - validUntil.getTime(), - announcement.getValidUntil().getTime() + BigDecimal.valueOf(0.02), + percentageDiscountCoupon.getPercentage() ); }); } @@ -106,7 +115,7 @@ public static class Book { @Type(type = "json-polymorphic-list") @Column(columnDefinition = "jsonb") - private List topics = new ArrayList<>(); + private List coupons = new ArrayList<>(); public String getIsbn() { return isbn; @@ -117,83 +126,92 @@ public Book setIsbn(String isbn) { return this; } - public List getTopics() { - return topics; + public List getCoupons() { + return coupons; } - public Book setTopics(List topics) { - this.topics = topics; + public Book setCoupons(List coupons) { + this.coupons = coupons; return this; } - public Book addTopic(Topic topic) { - topics.add(topic); + public Book addCoupon(DiscountCoupon topic) { + coupons.add(topic); return this; } } - public static abstract class Topic implements Serializable { + public abstract static class DiscountCoupon implements Serializable { - private String title; + private String name; + + public DiscountCoupon() { + } - public Topic() { + public DiscountCoupon(String name) { + this.name = name; } - public Topic(String title) { - this.title = title; + public String getName() { + return name; } - public String getTitle() { - return title; + public void setName(String name) { + this.name = name; } - public void setTitle(String title) { - this.title = title; + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof DiscountCoupon)) return false; + DiscountCoupon that = (DiscountCoupon) o; + return Objects.equals(getName(), that.getName()); } - String getType() { - return getClass().getSimpleName(); + @Override + public int hashCode() { + return Objects.hash(getName()); } } - public static class Post extends Topic { + public static class AmountDiscountCoupon extends DiscountCoupon { - private String content; + private BigDecimal amount; - public Post() { + public AmountDiscountCoupon() { } - public Post(String title) { - super(title); + public AmountDiscountCoupon(String name) { + super(name); } - public String getContent() { - return content; + public BigDecimal getAmount() { + return amount; } - public Post setContent(String content) { - this.content = content; + public AmountDiscountCoupon setAmount(BigDecimal amount) { + this.amount = amount; return this; } } - public static class Announcement extends Topic { + public static class PercentageDiscountCoupon extends DiscountCoupon { - private Date validUntil; + private BigDecimal percentage; - public Announcement() { + public PercentageDiscountCoupon() { } - public Announcement(String title) { - super(title); + public PercentageDiscountCoupon(String name) { + super(name); } - public Date getValidUntil() { - return validUntil; + public BigDecimal getPercentage() { + return percentage; } - public Announcement setValidUntil(Date validUntil) { - this.validUntil = validUntil; + public PercentageDiscountCoupon setPercentage(BigDecimal amount) { + this.percentage = amount; return this; } } diff --git a/hibernate-types-55/src/test/java/com/vladmihalcea/hibernate/type/json/polymorphic/PostgreSQLJsonPolymorphicListJacksonTypeTest.java b/hibernate-types-55/src/test/java/com/vladmihalcea/hibernate/type/json/polymorphic/PostgreSQLJsonPolymorphicListJacksonTypeTest.java index 38431f33a..cda0ecf02 100644 --- a/hibernate-types-55/src/test/java/com/vladmihalcea/hibernate/type/json/polymorphic/PostgreSQLJsonPolymorphicListJacksonTypeTest.java +++ b/hibernate-types-55/src/test/java/com/vladmihalcea/hibernate/type/json/polymorphic/PostgreSQLJsonPolymorphicListJacksonTypeTest.java @@ -13,11 +13,12 @@ import javax.persistence.*; import java.io.Serializable; +import java.math.BigDecimal; import java.sql.Timestamp; import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; +import java.util.*; +import java.util.function.Function; +import java.util.stream.Collectors; import static org.junit.Assert.assertEquals; @@ -36,17 +37,15 @@ protected Class[] entities() { @Test public void test() { - Timestamp validUntil = Timestamp.valueOf(LocalDateTime.now().plusDays(10)); - doInJPA(entityManager -> { entityManager.persist( new Book() .setIsbn("978-9730228236") - .addTopic(new Post("High-Performance Java Persistence") - .setContent("It rocks!") + .addCoupon(new AmountDiscountCoupon("PPP") + .setAmount(new BigDecimal("4.99")) ) - .addTopic(new Announcement("Black Friday - 50% discount") - .setValidUntil(validUntil) + .addCoupon(new PercentageDiscountCoupon("Black Friday") + .setPercentage(BigDecimal.valueOf(0.02)) ) ); }); @@ -56,14 +55,26 @@ public void test() { .bySimpleNaturalId(Book.class) .load("978-9730228236"); - List topics = book.getTopics(); + Map topics = book.getCoupons() + .stream() + .collect( + Collectors.toMap( + DiscountCoupon::getName, + Function.identity() + ) + ); + assertEquals(2, topics.size()); - Post post = (Post) topics.get(0); - assertEquals("It rocks!", post.getContent()); - Announcement announcement = (Announcement) topics.get(1); + AmountDiscountCoupon amountDiscountCoupon = (AmountDiscountCoupon) topics.get("PPP"); + assertEquals( + new BigDecimal("4.99"), + amountDiscountCoupon.getAmount() + ); + + PercentageDiscountCoupon percentageDiscountCoupon = (PercentageDiscountCoupon) topics.get("Black Friday"); assertEquals( - validUntil.getTime(), - announcement.getValidUntil().getTime() + BigDecimal.valueOf(0.02), + percentageDiscountCoupon.getPercentage() ); }); } @@ -83,7 +94,7 @@ public static class Book { @Type(type = "jsonb") @Column(columnDefinition = "jsonb") - private List topics = new ArrayList<>(); + private List coupons = new ArrayList<>(); public String getIsbn() { return isbn; @@ -94,17 +105,17 @@ public Book setIsbn(String isbn) { return this; } - public List getTopics() { - return topics; + public List getCoupons() { + return coupons; } - public Book setTopics(List topics) { - this.topics = topics; + public Book setCoupons(List coupons) { + this.coupons = coupons; return this; } - public Book addTopic(Topic topic) { - topics.add(topic); + public Book addCoupon(DiscountCoupon topic) { + coupons.add(topic); return this; } } @@ -116,92 +127,103 @@ public Book addTopic(Topic topic) { ) @JsonSubTypes({ @JsonSubTypes.Type( - name = "topic.post", - value = Post.class + name = "discount.coupon.amount", + value = AmountDiscountCoupon.class ), @JsonSubTypes.Type( - name = "topic.announcement", - value = Announcement.class + name = "discount.coupon.percentage", + value = PercentageDiscountCoupon.class ), }) - public abstract static class Topic implements Serializable { + public abstract static class DiscountCoupon implements Serializable { - private String title; + private String name; - public Topic() { + public DiscountCoupon() { } - public Topic(String title) { - this.title = title; + public DiscountCoupon(String name) { + this.name = name; } - public String getTitle() { - return title; + public String getName() { + return name; } - public void setTitle(String title) { - this.title = title; + public void setName(String name) { + this.name = name; } @JsonTypeInfo(use = JsonTypeInfo.Id.NAME) public abstract String getType(); + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof DiscountCoupon)) return false; + DiscountCoupon that = (DiscountCoupon) o; + return Objects.equals(getName(), that.getName()); + } + + @Override + public int hashCode() { + return Objects.hash(getName()); + } } - @JsonTypeName(Post.QUALIFIER) - public static class Post extends Topic { + public static class AmountDiscountCoupon extends DiscountCoupon { - public static final String QUALIFIER = "topic.post"; + public static final String DISCRIMINATOR = "discount.coupon.amount"; - private String content; + private BigDecimal amount; - public Post() { + public AmountDiscountCoupon() { } - public Post(String title) { - super(title); + public AmountDiscountCoupon(String name) { + super(name); } - public String getContent() { - return content; + public BigDecimal getAmount() { + return amount; } - public Post setContent(String content) { - this.content = content; + public AmountDiscountCoupon setAmount(BigDecimal amount) { + this.amount = amount; return this; } @Override public String getType() { - return Post.QUALIFIER; + return DISCRIMINATOR; } } - @JsonTypeName("topic.announcement") - public static class Announcement extends Topic { + public static class PercentageDiscountCoupon extends DiscountCoupon { - public static final String QUALIFIER = "topic.announcement"; + public static final String DISCRIMINATOR = "discount.coupon.percentage"; - private Date validUntil; + private BigDecimal percentage; - public Announcement() { + public PercentageDiscountCoupon() { } - public Announcement(String title) { - super(title); + public PercentageDiscountCoupon(String name) { + super(name); } - public Date getValidUntil() { - return validUntil; + public BigDecimal getPercentage() { + return percentage; } - public Announcement setValidUntil(Date validUntil) { - this.validUntil = validUntil; + public PercentageDiscountCoupon setPercentage(BigDecimal amount) { + this.percentage = amount; return this; } @Override public String getType() { - return QUALIFIER; + return DISCRIMINATOR; } } } \ No newline at end of file