Updated documentation of DictionaryEntry as requested in Issue #38.

This commit is contained in:
top19 2020-05-01 13:33:21 +01:00
parent 0340fc0038
commit 59cac89fba

View file

@ -18,31 +18,38 @@ import uk.ac.aber.cs221.group20.javafx.Application;
* @author Luke Wybar [law39] * @author Luke Wybar [law39]
* @author Marcin Jakob [maj83] * @author Marcin Jakob [maj83]
* @author Oscar Pocock [osp1] * @author Oscar Pocock [osp1]
* @author Tom Perry [top1] * @author Tom Perry [top19]
* @author Waylen Watts [ncw] * @author Waylen Watts [ncw]
* @version 0.1 Initial development * @version 0.1 Initial development
* @see DictionaryController * @see DictionaryController
*/ */
public class DictionaryEntry { public class DictionaryEntry {
// /////////////////// //
// Instance variables. //
// /////////////////// //
private String english; private String english;
private String welsh; private String welsh;
public enum wordTypeEnum { public enum wordTypeEnum {
nm, nf, verb, other nm, nf, verb, other
} }
private wordTypeEnum wordType; private wordTypeEnum wordType;
// private String wordType;
private Boolean practiceWord; private Boolean practiceWord;
// ///////////// //
// Constructors. //
// ///////////// //
/** /**
* Creates a new instance of a DictionaryEntry * Default constructor for DictionaryEntry.
*/ */
public DictionaryEntry() { public DictionaryEntry() {
practiceWord = false; practiceWord = false;
} }
/** /**
* Creates new instance of a DictionaryEntry * Constructor that creates an instance of DictionaryEntry when given 'english', 'welsh' and 'wordType' parameters.
* *
* @param english english translation of the word * @param english english translation of the word
* @param welsh welsh translation of the word * @param welsh welsh translation of the word
@ -53,54 +60,103 @@ public class DictionaryEntry {
public DictionaryEntry(String english, String welsh, wordTypeEnum wordType) { public DictionaryEntry(String english, String welsh, wordTypeEnum wordType) {
this.english = english; this.english = english;
this.welsh = welsh; this.welsh = welsh;
// this.wordType = wordType;
this.wordType = wordType; this.wordType = wordType;
} }
// ////////////////////// //
// Read/Write properties. //
// ////////////////////// //
/**
* Getter method for the 'english variable'.
*
* @return Current value of 'english'.
*/
public String getEnglish() { public String getEnglish() {
return english; return english;
} }
/**
* Setter for the 'english' variable.
*
* @param english New String value for 'english'.
*/
public void setEnglish(String english) { public void setEnglish(String english) {
this.english = english.trim(); this.english = english.trim();
} }
/**
* Getter for the 'welsh' variable.
*
* @return Current value of 'welsh'.
*/
public String getWelsh() { public String getWelsh() {
return welsh; return welsh;
} }
/**
* Setter for the 'welsh' variable.
*
* @param welsh New String value for 'welsh'.
*/
public void setWelsh(String welsh) { public void setWelsh(String welsh) {
this.welsh = welsh.trim(); this.welsh = welsh.trim();
} }
/**
* Getter for the 'wordType' enum variable.
*
* @return Current value of the 'wordType'.
* @see wordTypeEnum
*/
public wordTypeEnum getWordType() { public wordTypeEnum getWordType() {
return wordType; return wordType;
} }
// public word getWordType() {
// return wordType;
// }
/**
* Setter for the 'wordType' enum variable.
*
* @param wordType New wordTypeEnum value for the 'wordType'.
* @see wordTypeEnum
*/
public void setWordType(wordTypeEnum wordType) { public void setWordType(wordTypeEnum wordType) {
this.wordType = wordType; this.wordType = wordType;
} }
// public void setWordType(String wordType) { /**
// this.wordType = wordType; * Getter for the 'practiceWord' variable.
// } *
* @return Current value of 'practiceWord'
*/
public Boolean isPracticeWord() { public Boolean isPracticeWord() {
return practiceWord; return practiceWord;
} }
/**
* Setter for the 'practiceWord' variable.
*
* @param practiceWord New boolean value for 'practiceWord'.
*/
public void setPracticeWord(Boolean practiceWord) { public void setPracticeWord(Boolean practiceWord) {
this.practiceWord = practiceWord; this.practiceWord = practiceWord;
} }
// //////// //
// Methods. //
// //////// //
/**
* Overidden equals method that checks to see if two Dictionary objects are equal to each other. This work by checking if the objects 'english' or 'welsh' variables are
* equal with the same 'wordType'.
*
* @param entry Object that the DictionaryEntry object is comparing itself to.
* @return Returns true (if equal) or false (not equal).
*/
@Override @Override
public boolean equals(Object entry) { public boolean equals(Object entry) {
DictionaryEntry otherEntry = (DictionaryEntry) entry; DictionaryEntry otherEntry = (DictionaryEntry) entry; // Cast the object to be a DictionaryEntry.
return ((this.getWelsh().equalsIgnoreCase(otherEntry.getWelsh()) || this.getEnglish().equalsIgnoreCase(otherEntry.getWelsh())) && return ((this.getWelsh().equalsIgnoreCase(otherEntry.getWelsh()) || this.getEnglish().equalsIgnoreCase(otherEntry.getWelsh())) &&
this.getWordType().equals(otherEntry.getWordType())); this.getWordType().equals(otherEntry.getWordType())); // Check it they're equal by looking if they have equal 'welsh' or 'english' with the same 'wordType'.
} }
} }