From 5bdfb999bc660a76a36c85ac85e27c6d2e9e704c Mon Sep 17 00:00:00 2001 From: Vincent Potucek Date: Thu, 16 Jan 2025 08:54:52 +0100 Subject: [PATCH] Make `io.quarkus.builder.Consume` a `record` --- .../io/quarkus/builder/BuildChainBuilder.java | 2 +- .../io/quarkus/builder/BuildStepBuilder.java | 2 +- .../main/java/io/quarkus/builder/Consume.java | 48 +++++-------------- 3 files changed, 15 insertions(+), 37 deletions(-) diff --git a/core/builder/src/main/java/io/quarkus/builder/BuildChainBuilder.java b/core/builder/src/main/java/io/quarkus/builder/BuildChainBuilder.java index 8bc07c3da372d5..aa242d96475533 100644 --- a/core/builder/src/main/java/io/quarkus/builder/BuildChainBuilder.java +++ b/core/builder/src/main/java/io/quarkus/builder/BuildChainBuilder.java @@ -178,7 +178,7 @@ private Map> wireDependencies(Set entry : stepBuilder.getConsumes().entrySet()) { final Consume consume = entry.getValue(); final ItemId id = entry.getKey(); - if (!consume.getFlags().contains(ConsumeFlag.OPTIONAL) && !id.isMulti()) { + if (!consume.flags().contains(ConsumeFlag.OPTIONAL) && !id.isMulti()) { if (!initialIds.contains(id) && !allProduces.containsKey(id)) { throw new ChainBuildException("No producers for required item " + id); } diff --git a/core/builder/src/main/java/io/quarkus/builder/BuildStepBuilder.java b/core/builder/src/main/java/io/quarkus/builder/BuildStepBuilder.java index 1d46c0aac0931f..75431f9b6e6944 100644 --- a/core/builder/src/main/java/io/quarkus/builder/BuildStepBuilder.java +++ b/core/builder/src/main/java/io/quarkus/builder/BuildStepBuilder.java @@ -235,7 +235,7 @@ Map getProduces() { Set getRealConsumes() { final HashMap map = new HashMap<>(consumes); - map.entrySet().removeIf(e -> e.getValue().getConstraint() == Constraint.ORDER_ONLY); + map.entrySet().removeIf(e -> e.getValue().constraint() == Constraint.ORDER_ONLY); return map.keySet(); } diff --git a/core/builder/src/main/java/io/quarkus/builder/Consume.java b/core/builder/src/main/java/io/quarkus/builder/Consume.java index d64980fa102de6..806bf8bdcb18a7 100644 --- a/core/builder/src/main/java/io/quarkus/builder/Consume.java +++ b/core/builder/src/main/java/io/quarkus/builder/Consume.java @@ -1,42 +1,20 @@ package io.quarkus.builder; -final class Consume { - private final BuildStepBuilder buildStepBuilder; - private final ItemId itemId; - private final Constraint constraint; - private final ConsumeFlags flags; +import static io.quarkus.builder.Constraint.ORDER_ONLY; +import static io.quarkus.builder.Constraint.REAL; +import static io.quarkus.builder.ConsumeFlag.OPTIONAL; - Consume(final BuildStepBuilder buildStepBuilder, final ItemId itemId, final Constraint constraint, - final ConsumeFlags flags) { - this.buildStepBuilder = buildStepBuilder; - this.itemId = itemId; - this.constraint = constraint; - this.flags = flags; - } - - BuildStepBuilder getBuildStepBuilder() { - return buildStepBuilder; - } - - ItemId getItemId() { - return itemId; - } - - ConsumeFlags getFlags() { - return flags; - } +record Consume(BuildStepBuilder buildStepBuilder, ItemId itemId, Constraint constraint, ConsumeFlags flags) { Consume combine(final Constraint constraint, final ConsumeFlags flags) { - final Constraint outputConstraint = constraint == Constraint.REAL || this.constraint == Constraint.REAL - ? Constraint.REAL - : Constraint.ORDER_ONLY; - final ConsumeFlags outputFlags = !flags.contains(ConsumeFlag.OPTIONAL) || !this.flags.contains(ConsumeFlag.OPTIONAL) - ? flags.with(this.flags).without(ConsumeFlag.OPTIONAL) - : flags.with(this.flags); - return new Consume(buildStepBuilder, itemId, outputConstraint, outputFlags); - } - - Constraint getConstraint() { - return constraint; + return new Consume( + buildStepBuilder, + itemId, + constraint == REAL || this.constraint == REAL + ? REAL + : ORDER_ONLY, + !flags.contains(OPTIONAL) || !this.flags.contains(OPTIONAL) + ? flags.with(this.flags).without(OPTIONAL) + : flags.with(this.flags)); } }