78 lines
2.1 KiB
Java
78 lines
2.1 KiB
Java
package model;
|
|
|
|
import java.time.LocalDateTime;
|
|
import java.util.Objects;
|
|
|
|
public abstract class StoryElement {
|
|
protected String description;
|
|
|
|
protected StoryMetadata metadata;
|
|
|
|
protected StoryLogger logger = new StoryLogger();
|
|
|
|
public StoryElement(String description) {
|
|
this.description = description;
|
|
this.metadata = new StoryMetadata();
|
|
logger.logCreation();
|
|
}
|
|
|
|
public String getDescription() {
|
|
return description;
|
|
}
|
|
|
|
@Override
|
|
public String toString() {
|
|
return this.getClass().getSimpleName() + "{" +
|
|
"description='" + description + '\'' +
|
|
'}';
|
|
}
|
|
|
|
@Override
|
|
public boolean equals(Object obj) {
|
|
if (this == obj) return true;
|
|
if (obj == null || getClass() != obj.getClass()) return false;
|
|
StoryElement that = (StoryElement) obj;
|
|
return Objects.equals(description, that.description);
|
|
}
|
|
|
|
@Override
|
|
public int hashCode() {
|
|
return description != null ? description.hashCode() : 0;
|
|
}
|
|
|
|
public class StoryLogger {
|
|
public void logCreation() {
|
|
System.out.println("[DEBUG] Story Element Created: " + description);
|
|
}
|
|
|
|
public void logInteraction(String interaction) {
|
|
System.out.println("[DEBUG] Interaction with '" + description + "': " + interaction);
|
|
}
|
|
}
|
|
|
|
public static class StoryMetadata {
|
|
private final LocalDateTime creationDate;
|
|
private LocalDateTime lastUpdatedDate;
|
|
|
|
public StoryMetadata() {
|
|
this.creationDate = LocalDateTime.now();
|
|
this.lastUpdatedDate = creationDate;
|
|
}
|
|
|
|
// Getter and setters
|
|
public LocalDateTime getCreationDate() {
|
|
return creationDate;
|
|
}
|
|
|
|
public void setLastUpdatedDate(LocalDateTime lastUpdatedDate) {
|
|
this.lastUpdatedDate = lastUpdatedDate;
|
|
}
|
|
|
|
public String toString() {
|
|
return "StoryMetadata{" +
|
|
"creationDate=" + creationDate +
|
|
", lastUpdatedDate=" + lastUpdatedDate +
|
|
'}';
|
|
}
|
|
}
|
|
} |