Skip to content

Commit

Permalink
Modify parse method
Browse files Browse the repository at this point in the history
  • Loading branch information
kelvinqian00 committed Dec 11, 2024
1 parent 9485538 commit 8c41e3c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
21 changes: 10 additions & 11 deletions src/main/java/com/yetanalytics/xapi/model/LangTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ public LangTag(String langTagStr) throws IllformedLocaleException {
languageTagString = langTagStr;
}

/**
* Static method to create a LangTag instance from the langTag string.
* @param langTag - The String language tag.
* @return The new LangTag instance.
* @see java.util.Locale#forLanguageTag(String str)
*/
public static LangTag parse(String langTag) {
return new LangTag(langTag);
}

/**
* Returns the original String version of the LangTag.
* @return LangTag as a String.
Expand Down Expand Up @@ -80,15 +90,4 @@ public boolean equals(Object langTag) {
public int hashCode() {
return languageTagString.hashCode();
}

/**
* Static method to create a LangTag instance from the langTag string.
* See also to URI.create(String uriString)
* @param langTag - The String language tag.
* @return The new LangTag instance.
* @see java.util.URI#create(String str)
*/
public static LangTag create(String langTag) {
return new LangTag(langTag);
}
}
10 changes: 5 additions & 5 deletions src/test/java/com/yetanalytics/XapiDeserializationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void testBasicStatement() throws StreamReadException, DatabindException,

Verb verb = stmt.getVerb();
assertEquals(verb.getId(), URI.create("https://www.yetanalytics.com/profiles/thing/1.0/concepts/verbs/set"));
assertEquals(verb.getDisplay().get(LangTag.create("en-us")), "Set");
assertEquals(verb.getDisplay().get(LangTag.parse("en-us")), "Set");

Activity object = (Activity) stmt.getObject();
assertEquals(object.getId(), URI.create("https://www.yetanalytics.com/profiles/thing/1.0/concepts/activities/act1"));
Expand All @@ -89,8 +89,8 @@ public void testAttachments() throws StreamReadException, DatabindException, IOE
assertEquals(stmt.getAttachments().size(), 1);
Attachment att1 = stmt.getAttachments().get(0);
assertEquals(att1.getUsageType(), URI.create("https://www.yetanalytics.com/usagetypes/1"));
assertEquals(att1.getDisplay().get(LangTag.create("en-us")), "Attachment 1");
assertEquals(att1.getDescription().get(LangTag.create("en-us")), "The First Attachment");
assertEquals(att1.getDisplay().get(LangTag.parse("en-us")), "Attachment 1");
assertEquals(att1.getDescription().get(LangTag.parse("en-us")), "The First Attachment");
assertEquals(att1.getContentType(), "application/json");
assertEquals(att1.getLength(), Integer.valueOf(450));
assertEquals(att1.getSha2(), "426cf3a8b2864dd91201b989ba5728181da52bfff9a0489670e54cd8ec8b3a50");
Expand Down Expand Up @@ -180,12 +180,12 @@ public void testInteractionActivity() throws StreamReadException, DatabindExcept

ActivityDefinition def = act.getDefinition();
assertEquals(def.getType(), URI.create("http://adlnet.gov/expapi/activities/cmi.interaction"));
assertEquals(def.getName().get(LangTag.create("en")), "Multichoice Question");
assertEquals(def.getName().get(LangTag.parse("en")), "Multichoice Question");
assertEquals(def.getCorrectResponsesPattern().get(0), "a");
assertEquals(def.getInteractionType(), InteractionType.CHOICE);
InteractionComponent choice = def.getChoices().iterator().next();
assertEquals(choice.getId(), "a");
assertEquals(choice.getDescription().get(LangTag.create("en")), "A");
assertEquals(choice.getDescription().get(LangTag.parse("en")), "A");
}

public void testGroupActor() throws StreamReadException, DatabindException, IOException {
Expand Down

0 comments on commit 8c41e3c

Please sign in to comment.