Skip to content

Commit

Permalink
Use methods to receive holiday and country description from Resource …
Browse files Browse the repository at this point in the history
…Util
  • Loading branch information
derTobsch committed Jan 4, 2025
1 parent b4fe326 commit 23dad25
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package de.focus_shift.jollyday.core;

import de.focus_shift.jollyday.core.util.ResourceUtil;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

import static de.focus_shift.jollyday.core.util.ResourceUtil.UNDEFINED;
import static de.focus_shift.jollyday.core.util.ResourceUtil.getCountryDescription;

/**
* Bean class for describing the configuration hierarchy.
*/
Expand Down Expand Up @@ -45,21 +46,17 @@ public String getId() {
* @return the description
*/
public String getDescription() {
return getDescription(Locale.getDefault());
return receiveFallbackDescription(getCountryDescription(getPropertiesKey()));
}

/**
* Returns the hierarchies description text from the resource bundle.
*
* @param l Locale to return the description text for.
* @param locale Locale to return the description text for.
* @return Description text
*/
public String getDescription(Locale l) {
String descr = ResourceUtil.getCountryDescription(l, getPropertiesKey());
if (ResourceUtil.UNDEFINED.equals(descr) && fallbackDescription != null) {
descr = fallbackDescription;
}
return descr;
public String getDescription(Locale locale) {
return receiveFallbackDescription(getCountryDescription(locale, getPropertiesKey()));
}

/**
Expand All @@ -81,7 +78,7 @@ private String getPropertiesKey() {
* Compares Hierarchies by id.
*/
@Override
public boolean equals(Object obj) {
public boolean equals(final Object obj) {
if (obj instanceof CalendarHierarchy) {
return ((CalendarHierarchy) obj).getId().equals(this.getId());
}
Expand Down Expand Up @@ -118,8 +115,14 @@ public Map<String, CalendarHierarchy> getChildren() {
/**
* @param description the fallback description
*/
public void setFallbackDescription(String description) {
public void setFallbackDescription(final String description) {
this.fallbackDescription = description;
}

private String receiveFallbackDescription(final String description) {
if (UNDEFINED.equals(description) && fallbackDescription != null) {
return fallbackDescription;
}
return description;
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package de.focus_shift.jollyday.core;

import de.focus_shift.jollyday.core.util.ResourceUtil;

import java.time.LocalDate;
import java.util.Locale;
import java.util.Objects;
import java.util.Optional;

import static de.focus_shift.jollyday.core.util.ResourceUtil.getHolidayDescription;

/**
* Represents the holiday and contains the actual date and an localized
* description.
Expand Down Expand Up @@ -118,7 +118,7 @@ public String getPropertiesKey() {
* @return Description for this holiday
*/
public String getDescription() {
return ResourceUtil.getHolidayDescription(Locale.getDefault(), getPropertiesKey());
return getHolidayDescription(getPropertiesKey());
}

/**
Expand All @@ -128,7 +128,7 @@ public String getDescription() {
* @return Description for this holiday
*/
public String getDescription(Locale locale) {
return ResourceUtil.getHolidayDescription(locale, getPropertiesKey());
return getHolidayDescription(locale, getPropertiesKey());
}

@Override
Expand Down

0 comments on commit 23dad25

Please sign in to comment.