Class CsvAnalysisUtility
java.lang.Object
de.bcxp.challenge.common.analysis.csv.CsvAnalysisUtility
Utility class providing common analytical operations for
Document
objects.
This class contains static helper methods that perform reusable data analysis tasks, such as identifying the best-matching document entries based on numeric column comparisons.
The utility class is declared final
and has a private constructor to prevent instantiation.
All functionality is provided via static methods.
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
Private constructor to prevent instantiation of this utility class. -
Method Summary
Modifier and TypeMethodDescriptionprivate static Set<DocumentEntry>
getAllDocumentEntriesWithBestScore
(Set<IEntryWithComparableNumericTuple> comparableEntries, double bestScore) Retrieves all entries from the given set that have the determined score.static Set<DocumentEntry>
getBestMatchesForNumericColumnComparison
(Document document, NumericComparisonType type) Finds all entries in the givenDocument
that share the "best" numeric score, according to the specifiedComparator
.private static Set<IEntryWithComparableNumericTuple>
-
Field Details
-
logger
private static final org.apache.logging.log4j.Logger logger
-
-
Constructor Details
-
CsvAnalysisUtility
private CsvAnalysisUtility()Private constructor to prevent instantiation of this utility class.
-
-
Method Details
-
getBestMatchesForNumericColumnComparison
public static Set<DocumentEntry> getBestMatchesForNumericColumnComparison(Document document, NumericComparisonType type) throws NoSuchElementException Finds all entries in the givenDocument
that share the "best" numeric score, according to the specifiedComparator
.The method performs the following steps:
- Validates that the document and its entries are not
null
and meet the required type constraints. - Validates that all entries implement
IEntryWithComparableNumericTuple
. - Calculates a numeric score for each entry via
IEntryWithComparableNumericTuple.getBestMatchScore()
. - Determines the best score according to
type.comparator
. - Collects and returns all entries that have this best score.
- Parameters:
document
- theDocument
containing entries to analyzetype
- theNumericComparisonType
providing the Comparator for best score determination- Returns:
- a
Set
of entries with the best score according to the given comparator; nevernull
but may be empty - Throws:
NoSuchElementException
- if the document contains no valid entries or no score could be computedIllegalArgumentException
- if the document entries are not of typeIEntryWithComparableNumericTuple
IllegalStateException
- if the document contains anull
entry- See Also:
- Validates that the document and its entries are not
-
getEntriesWithComparableNumericTuples
private static Set<IEntryWithComparableNumericTuple> getEntriesWithComparableNumericTuples(Document document) throws IllegalArgumentException - Parameters:
document
- Document with numeric tuples- Returns:
- a
Set
ofIEntryWithComparableNumericTuple
objects representing the entries from the given document - Throws:
IllegalArgumentException
- if the entries are empty, null, or not all the same concrete type implementingIEntryWithComparableNumericTuple
-
getAllDocumentEntriesWithBestScore
private static Set<DocumentEntry> getAllDocumentEntriesWithBestScore(Set<IEntryWithComparableNumericTuple> comparableEntries, double bestScore) Retrieves all entries from the given set that have the determined score.- Parameters:
comparableEntries
- Set containing all entries from the document.bestScore
- Score to filter for- Returns:
- Set of all
DocumentEntry
objects with the best score.
-