Light, fluffy, and always free - The AWS Local Emulator alternative
refactor(s3): dedupe XmlElement child-count helper (#3844)
Priamo Germosen86f3084ff061
diff --git a/src/main/java/io/github/hectorvent/floci/core/common/XmlParser.java b/src/main/java/io/github/hectorvent/floci/core/common/XmlParser.javaindex 3bdc586d8c..1453138374 100644--- a/src/main/java/io/github/hectorvent/floci/core/common/XmlParser.java+++ b/src/main/java/io/github/hectorvent/floci/core/common/XmlParser.java@@ -468,6 +468,10 @@ public final class XmlParser {.findFirst().orElse(null);}++ public long count(String childName) {+ return children.stream().filter(child -> childName.equals(child.name())).count();+ }}/**diff --git a/src/main/java/io/github/hectorvent/floci/services/s3/S3AnalyticsConfiguration.java b/src/main/java/io/github/hectorvent/floci/services/s3/S3AnalyticsConfiguration.javaindex d48cdc1729..54005fe070 100644--- a/src/main/java/io/github/hectorvent/floci/services/s3/S3AnalyticsConfiguration.java+++ b/src/main/java/io/github/hectorvent/floci/services/s3/S3AnalyticsConfiguration.java@@ -40,9 +40,9 @@ record S3AnalyticsConfiguration(String id, String innerXml) {// The configuration is one Id, at most one Filter and one StorageClassAnalysis, so// anything else under the root is a body AWS would not have accepted.- long ids = count(root, "Id");- long filters = count(root, "Filter");- long analyses = count(root, "StorageClassAnalysis");+ long ids = root.count("Id");+ long filters = root.count("Filter");+ long analyses = root.count("StorageClassAnalysis");if (ids != 1 || filters > 1 || analyses != 1|| root.children().size() != ids + filters + analyses) {throw malformed();@@ -78,8 +78,8 @@ record S3AnalyticsConfiguration(String id, String innerXml) {case "Tag" -> tagXml(predicate);case "And" -> {List<XmlElement> conjuncts = predicate.children();- long prefixes = count(predicate, "Prefix");- long tags = count(predicate, "Tag");+ long prefixes = predicate.count("Prefix");+ long tags = predicate.count("Tag");// Every conjunct has to be one floci understands, or the filter it stores would// not be the filter that was sent.if (conjuncts.size() < 2 || prefixes > 1 || conjuncts.size() != prefixes + tags) {@@ -112,7 +112,7 @@ record S3AnalyticsConfiguration(String id, String innerXml) {* the output schema version and a destination bucket, with the account id and prefix optional.*/private static String storageClassAnalysisXml(XmlElement analysis) {- long exports = count(analysis, "DataExport");+ long exports = analysis.count("DataExport");if (exports > 1 || analysis.children().size() != exports) {throw malformed();}@@ -156,8 +156,4 @@ record S3AnalyticsConfiguration(String id, String innerXml) {}return out.end("S3BucketDestination").end("Destination").end("DataExport").build();}-- private static long count(XmlElement parent, String childName) {- return parent.children().stream().filter(child -> childName.equals(child.name())).count();- }}diff --git a/src/main/java/io/github/hectorvent/floci/services/s3/S3InventoryConfiguration.java b/src/main/java/io/github/hectorvent/floci/services/s3/S3InventoryConfiguration.javaindex fba9c40919..bf41b53d84 100644--- a/src/main/java/io/github/hectorvent/floci/services/s3/S3InventoryConfiguration.java+++ b/src/main/java/io/github/hectorvent/floci/services/s3/S3InventoryConfiguration.java@@ -48,11 +48,11 @@ record S3InventoryConfiguration(String id, String innerXml) {// The configuration is one each of Id, IsEnabled, IncludedObjectVersions, Schedule and// Destination, with Filter and OptionalFields at most once, so anything else under the// root is a body AWS would not have accepted.- long filters = count(root, "Filter");- long optionalFields = count(root, "OptionalFields");- if (count(root, "Id") != 1 || count(root, "IsEnabled") != 1- || count(root, "IncludedObjectVersions") != 1 || count(root, "Schedule") != 1- || count(root, "Destination") != 1 || filters > 1 || optionalFields > 1+ long filters = root.count("Filter");+ long optionalFields = root.count("OptionalFields");+ if (root.count("Id") != 1 || root.count("IsEnabled") != 1+ || root.count("IncludedObjectVersions") != 1 || root.count("Schedule") != 1+ || root.count("Destination") != 1 || filters > 1 || optionalFields > 1|| root.children().size() != 5 + filters + optionalFields) {throw malformed();}@@ -169,8 +169,4 @@ record S3InventoryConfiguration(String id, String innerXml) {}return out.build();}-- private static long count(XmlElement parent, String childName) {- return parent.children().stream().filter(child -> childName.equals(child.name())).count();- }}