poem.boundary.internal.domain.Poem Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of poem-hexagon Show documentation
Show all versions of poem-hexagon Show documentation
A simple example for a hexagonal architecture.
package poem.boundary.internal.domain;
import java.util.Objects;
public class Poem {
private String[] verses;
/**
* Constructs a poem with verses by splitting the specified text using
* newline characters.
*
* @param text the text of the poem
*/
public Poem(String text) {
Objects.requireNonNull(text);
this.verses = text.split("\\r?\\n");
}
/**
* Returns the individual verses of the poem.
*
* @return the verses
*/
public String[] getVerses() {
return verses;
}
@Override
public String toString() {
final String newline = System.getProperty("line.separator");
return String.join(newline, verses);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((verses == null) ? 0 : verses.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Poem other = (Poem) obj;
if (verses == null) {
if (other.verses != null)
return false;
} else if (!verses.equals(other.verses))
return false;
return true;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy