-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MET-5132: Update code after answers from rnd
- Loading branch information
Showing
17 changed files
with
146 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 40 additions & 18 deletions
58
...-normalization/src/main/java/eu/europeana/normalization/dates/edtf/DateQualification.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,61 @@ | ||
package eu.europeana.normalization.dates.edtf; | ||
|
||
import java.util.Arrays; | ||
import java.util.EnumSet; | ||
import java.util.Set; | ||
import java.util.regex.Pattern; | ||
|
||
/** | ||
* Date qualification characters according to <a href="https://www.loc.gov/standards/datetime/">Extended Date/Time Format (EDTF) | ||
* Specification</a> | ||
*/ | ||
public enum DateQualification { | ||
UNCERTAIN, APPROXIMATE; | ||
|
||
NO_QUALIFICATION(""), | ||
UNCERTAIN("?"), | ||
APPROXIMATE("~"), | ||
UNCERTAIN_APPROXIMATE("%"); | ||
|
||
public static final Pattern CHECK_QUALIFICATION_PATTERN = Pattern.compile("^[^?~%]*([?~%])$"); | ||
private final String character; | ||
|
||
DateQualification(String character) { | ||
this.character = character; | ||
} | ||
private static final String CHARACTER_UNCERTAIN = "?"; | ||
private static final String CHARACTER_APPROXIMATE = "~"; | ||
private static final String CHARACTER_UNCERTAIN_APPROXIMATE = "%"; | ||
private static final String QUALIFICATION_CHARACTER_REGEX = | ||
CHARACTER_UNCERTAIN + CHARACTER_APPROXIMATE + CHARACTER_UNCERTAIN_APPROXIMATE; | ||
public static final Pattern CHECK_QUALIFICATION_PATTERN = Pattern.compile( | ||
"^[^" + QUALIFICATION_CHARACTER_REGEX + "]*([" + QUALIFICATION_CHARACTER_REGEX + "])$"); | ||
|
||
/** | ||
* Get the enum value based on the character provided. | ||
* <p>It will return a matched enum value or {@link #NO_QUALIFICATION}.</p> | ||
* Get the enum values based on the character provided. | ||
* <p>It will return an empty set or the set with the applicable qualifications.</p> | ||
* | ||
* @param character the provided character | ||
* @return the enum value | ||
*/ | ||
public static DateQualification fromCharacter(String character) { | ||
return Arrays.stream(DateQualification.values()).filter(value -> value.character.equals(character)).findFirst().orElse( | ||
NO_QUALIFICATION); | ||
public static Set<DateQualification> fromCharacter(String character) { | ||
final Set<DateQualification> dateQualifications = EnumSet.noneOf(DateQualification.class); | ||
if (CHARACTER_UNCERTAIN_APPROXIMATE.equals(character)) { | ||
dateQualifications.add(DateQualification.UNCERTAIN); | ||
dateQualifications.add(DateQualification.APPROXIMATE); | ||
} else if (CHARACTER_UNCERTAIN.equals(character)) { | ||
dateQualifications.add(DateQualification.UNCERTAIN); | ||
} else if (CHARACTER_APPROXIMATE.equals(character)) { | ||
dateQualifications.add(DateQualification.APPROXIMATE); | ||
} | ||
return dateQualifications; | ||
} | ||
|
||
public String getCharacter() { | ||
/** | ||
* Get the string representation based on the provided date qualifications. | ||
* | ||
* @param dateQualifications the date qualifications | ||
* @return the string representation | ||
*/ | ||
public static String getCharacterFromQualifications(Set<DateQualification> dateQualifications) { | ||
final String character; | ||
if (dateQualifications.contains(UNCERTAIN) && dateQualifications.contains(APPROXIMATE)) { | ||
character = CHARACTER_UNCERTAIN_APPROXIMATE; | ||
} else if (dateQualifications.contains(UNCERTAIN)) { | ||
character = CHARACTER_UNCERTAIN; | ||
} else if (dateQualifications.contains(APPROXIMATE)) { | ||
character = CHARACTER_APPROXIMATE; | ||
} else { | ||
character = ""; | ||
} | ||
return character; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.