All Downloads are FREE. Search and download functionalities are using the official Maven repository.

poem.boundary.internal.domain.Poem Maven / Gradle / Ivy

The newest version!
package poem.boundary.internal.domain;

import java.util.Arrays;
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 + Arrays.hashCode(verses);
    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 (!Arrays.equals(verses, other.verses))
      return false;
    return true;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy