Skip to content

Commit

Permalink
Simpify LangTag constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
kelvinqian00 committed Dec 11, 2024
1 parent 489c4e2 commit 9485538
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
15 changes: 5 additions & 10 deletions src/main/java/com/yetanalytics/xapi/model/LangTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,14 @@ public class LangTag {
* This constructor takes a RFC 5646 formatted String and converts it to a
* LangTag object consisting of a java.util.Locale object and the original
* String.
* @param langTag The language tag String from an xAPI Statement language map.
* @param langTagStr The language tag String from an xAPI Statement language map.
* @throws IllformedLocaleException when the String is not a valid language tag.
*/
@JsonCreator
public LangTag(String langTag) throws IllformedLocaleException {
if (langTag == null || langTag.isEmpty()) {
String errMsg = "Cannot parse null or empty language tag String!";
throw new IllformedLocaleException(errMsg);
} else {
Builder builder = new Builder();
languageTagLocale = builder.setLanguageTag(langTag).build();
languageTagString = langTag;
}
public LangTag(String langTagStr) throws IllformedLocaleException {
Builder builder = new Builder();
languageTagLocale = builder.setLanguageTag(langTagStr).build();
languageTagString = langTagStr;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/yetanalytics/model/LangTagTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ public void testInvalidLanguageTag() {

IllformedLocaleException exn2 =
assertThrows(IllformedLocaleException.class, () -> new LangTag(""));
assertEquals("Cannot parse null or empty language tag String!", exn2.getMessage());
assertNotNull(exn2.getMessage());
}
}

0 comments on commit 9485538

Please sign in to comment.