You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Oct 29, 2023. It is now read-only.
/** *Returns the color for {@code tagName}'s label */privateStringgetTagColorFor(StringtagName) {
//Uses the hash code of the tag name to generate a color, such that each run of the program//produce the same color for that tag namereturnTAG_COLORS[Math.abs(tagName.hashCode()) % TAG_COLORS.length];
}
/** *Creates tag labels for {@code person}. */privatevoidinitTags(Personperson) {
person.getTags().forEach(tag -> {
LabeltagLabel = newLabel(tag.tagName);
tagLabel.getStyleClass().add(getTagColorFor(tag.tagName));
tags.getChildren().add(tagLabel);
});
}
//@author@Overridepublicbooleanequals(Objectother) {
// short circuit if same objectif (other == this) {
returntrue;
}
// instanceof handles nullsif (!(otherinstanceofPersonCard)) {
returnfalse;
}
// state checkPersonCardcard = (PersonCard) other;
returnid.getText().equals(card.id.getText())
&& person.equals(card.person);
}
}
/** * Returns the color for {@code tagName}. The tag's color is determined by looking up the color * in {@code PersonCard#TAG_COLORS}, using an index generated by the hash code of the tag's name. * * @see PersonCard#getTagColorFor(String) */privatestaticStringgetTagColorFor(StringtagName) {
switch (tagName) {
case"classmates":
case"owesMoney":
return"blue";
case"colleagues":
case"neighbours":
return"green";
case"family":
case"friend":
return"orange";
case"friends":
return"pink";
case"husband":
return"brown";
default:
fail(tagName + " does not have a color assigned.");
return"";
}
}
/** * Asserts that the tags in {@code actualCard} matches all the tags in {@code expectedPerson} with the correct * color. */privatestaticvoidassertTagsEqual(PersonexpectedPerson, PersonCardHandleactualCard) {
List<String> expectedTags = expectedPerson.getTags().stream()
.map(tag -> tag.tagName).collect(Collectors.toList());
assertEquals(expectedTags, actualCard.getTags());
expectedTags.forEach(tag ->
assertEquals(Arrays.asList(LABEL_DEFAULT_COLOR, getTagColorFor(tag)),
actualCard.getTagColorClasses(tag)));
}