001package model.entity; 002 003import lombok.Getter; 004import lombok.Setter; 005import org.hibernate.annotations.LazyCollection; 006import org.hibernate.annotations.LazyCollectionOption; 007import org.hibernate.annotations.NaturalId; 008 009import javax.persistence.*; 010import java.io.Serializable; 011import java.util.Map; 012 013@Entity 014public class Section implements Serializable { 015 016 @Getter @Setter 017 @Id @GeneratedValue(strategy = GenerationType.IDENTITY) 018 protected Integer id; 019 020 @Getter @Setter 021 @Column(length = 255) 022 protected String description; 023 024 025 @Getter @Setter 026 @Column(length = 50, nullable = false, unique = true) 027 @NaturalId(mutable = true) 028 protected String name; 029 030 @Getter @Setter 031 @Column(length = 4096) 032 protected String picture; 033 034 @Getter @Setter 035 @Column(length = 4096) 036 protected String banner; 037 038 @OneToMany(mappedBy="section") 039 @MapKeyJoinColumn(name="user_id", updatable = false, insertable = false) 040 @LazyCollection(LazyCollectionOption.EXTRA) 041 protected Map<User, Follow> follows; 042 043 /** 044 * Ottieni un'istanza di <pre>Follow</pre> tra la sezione in questione e l'utente specificato (o <pre>null</pre> se tale istanza non รจ presente) 045 * @param user Riferimento all'utente 046 * @return Un oggetto {@link Follow} 047 */ 048 public Follow getFollow(User user){ 049 return follows.get(user); 050 } 051 052 /** 053 * Ottieni il numero di seguaci 054 * @return Il numero di seguaci alla sezione in questione 055 */ 056 public int getFollowCount(){ 057 return follows.size(); 058 } 059 060 public Section(){} 061 062 @Override 063 public boolean equals(Object o) { 064 if (this == o) return true; 065 if (!(o instanceof Section)) return false; 066 Section section = (Section) o; 067 return id.equals(section.id); 068 } 069 070 @Override 071 public int hashCode() { 072 return getClass().hashCode(); 073 } 074}