001// SPDX-License-Identifier: GPL-3.0-or-later 002 003package es.uvigo.esei.sing.textproc.entity; 004 005import javax.persistence.Column; 006import javax.persistence.MappedSuperclass; 007 008import lombok.Getter; 009import lombok.NonNull; 010import lombok.Setter; 011 012/** 013 * Represents a processed text document which has a title. 014 * 015 * @author Alejandro González García 016 * @implNote The implementation of this class is not thread-safe. 017 */ 018@MappedSuperclass 019public abstract class ProcessedDocumentWithTitle extends ProcessedDocument { 020 @Getter @Setter @NonNull @Column(nullable = false) 021 private String title; 022 023 /** 024 * Creates a new processed text document which has a title with the given 025 * parameters. 026 * 027 * @param id The ID of the processed text document with title, that must 028 * match the ID of a text document which has a title. 029 * @param text The processed text of the document, with tokens separated by 030 * spaces. 031 * @param title The processed title of the text document. 032 * @throws IllegalArgumentException If any parameter is {@code null}. 033 */ 034 protected ProcessedDocumentWithTitle(final int id, final String text, @NonNull final String title) { 035 super(id, text); 036 this.title = title; 037 } 038 039 /** 040 * Dummy constructor that only assigns a primary key. Intended for usage when 041 * the rest of the entity attributes are to be be assigned later. 042 * 043 * @param id The primary key of the entity. 044 * @throws IllegalArgumentException If {@code id} is {@code null}. 045 */ 046 protected ProcessedDocumentWithTitle(@NonNull final Integer id) { 047 super(id, ""); 048 this.title = ""; 049 } 050 051 /** 052 * Dummy default constructor, to be used by JPA only. 053 */ 054 protected ProcessedDocumentWithTitle() { 055 this.title = ""; 056 } 057 058 @Override 059 public String toString() { 060 final StringBuilder stringBuilder = new StringBuilder(super.toString()); 061 062 stringBuilder 063 .append('\n').append("Title: ").append(title); 064 065 return stringBuilder.toString(); 066 } 067}