From 01f0bd3ed8428b946a394dcbcf94c61207341d5d Mon Sep 17 00:00:00 2001 From: Jim Myers Date: Fri, 27 Sep 2024 16:14:25 -0400 Subject: [PATCH] abstract cleaning to separate method --- .../pidproviders/doi/AbstractDOIProvider.java | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/src/main/java/edu/harvard/iq/dataverse/pidproviders/doi/AbstractDOIProvider.java b/src/main/java/edu/harvard/iq/dataverse/pidproviders/doi/AbstractDOIProvider.java index fae40ddb77e..70ce1ec4c14 100644 --- a/src/main/java/edu/harvard/iq/dataverse/pidproviders/doi/AbstractDOIProvider.java +++ b/src/main/java/edu/harvard/iq/dataverse/pidproviders/doi/AbstractDOIProvider.java @@ -28,27 +28,23 @@ public abstract class AbstractDOIProvider extends AbstractPidProvider { public AbstractDOIProvider(String id, String label, String providerAuthority, String providerShoulder, String identifierGenerationStyle, String datafilePidFormat, String managedList, String excludedList) { super(id, label, DOI_PROTOCOL, providerAuthority, providerShoulder, identifierGenerationStyle, datafilePidFormat, managedList, excludedList); //Create case insensitive (converted toUpperCase) managedSet and excludedSet - HashSet cleanManagedSet = new HashSet(); - for(String entry: managedSet) { - if(entry.startsWith(DOI_PROTOCOL)) { - cleanManagedSet.add(DOI_PROTOCOL + entry.substring(DOI_PROTOCOL.length()).toUpperCase()); - } else { - logger.warning("Non-DOI found in managedSet of pidProvider id: " + getId() + ": " + entry + ". Entry is being dropped."); - } - } - managedSet = cleanManagedSet; - HashSet cleanExcludedSet = new HashSet(); - for(String entry: excludedSet) { + managedSet = clean(managedSet, "managed"); + excludedSet = clean(excludedSet, "excluded"); + } + + private HashSet clean(HashSet originalSet, String setName) { + HashSet cleanSet = new HashSet(); + for(String entry: originalSet) { if(entry.startsWith(DOI_PROTOCOL)) { - cleanExcludedSet.add(DOI_PROTOCOL + entry.substring(DOI_PROTOCOL.length()).toUpperCase()); + cleanSet.add(DOI_PROTOCOL + entry.substring(DOI_PROTOCOL.length()).toUpperCase()); } else { - logger.warning("Non-DOI found in excludedSet of pidProvider id: " + getId() + ": " + entry + ". Entry is being dropped."); + logger.warning("Non-DOI found in " + setName + " set of pidProvider id: " + getId() + ": " + entry + ". Entry is being dropped."); } } - excludedSet = cleanExcludedSet; + return cleanSet; } - //For Unmanged provider + //For Unmanaged provider public AbstractDOIProvider(String name, String label) { super(name, label, DOI_PROTOCOL); }