package ua.nure.jfn.task4;

import java.util.Objects;

public class Word implements Comparable<Word> {
	private String content;
	private int frequency;

	public Word(String content) {
		this.content = content;
		this.frequency = 1;
	}

	public String getContent() {
		return content;
	}

	public int getFrequency() {
		return frequency;
	}

	public void incrementFrequency() {
		this.frequency++;
	}

	@Override
	public boolean equals(Object o) {
		if (o == null) {
			return false;
		}

		if (this == o) {
			return true;
		}

		Word word = (Word) o;

		return content.equals(word.content);
	}

	@Override
	public int hashCode() {
		return Objects.hash(content);
	}

	@Override
	public String toString() {
		return content + " : " + frequency;
	}

	@Override
	public int compareTo(Word other) {
		int frequencyComparison = Integer.compare(this.frequency, other.frequency);

		if (frequencyComparison != 0) {
			return frequencyComparison;
		}

		return this.content.compareTo(other.content);
	}
}
