From 8d697e1ea712df05bdb258f22dff8b8573c3d05e Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Sun, 10 Mar 2024 07:13:12 +0100 Subject: [PATCH] introduce singleton() --- .../rbac/rbacdef/InsertTriggerGenerator.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/net/hostsharing/hsadminng/rbac/rbacdef/InsertTriggerGenerator.java b/src/main/java/net/hostsharing/hsadminng/rbac/rbacdef/InsertTriggerGenerator.java index 7afd1941..5303c27e 100644 --- a/src/main/java/net/hostsharing/hsadminng/rbac/rbacdef/InsertTriggerGenerator.java +++ b/src/main/java/net/hostsharing/hsadminng/rbac/rbacdef/InsertTriggerGenerator.java @@ -1,6 +1,7 @@ package net.hostsharing.hsadminng.rbac.rbacdef; import java.util.Optional; +import java.util.function.BinaryOperator; import java.util.stream.Stream; import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Permission.INSERT; @@ -142,19 +143,20 @@ public class InsertTriggerGenerator { private Optional getOptionalInsertGrant() { return getInsertGrants() - .reduce((x, y) -> { - throw new IllegalStateException("only a single INSERT permission grant allowed"); - }); + .reduce(singleton()); } private Optional getOptionalInsertSuperRole() { return getInsertGrants() .map(RbacView.RbacGrantDefinition::getSuperRoleDef) - .reduce((x, y) -> { - throw new IllegalStateException("only a single INSERT permission grant allowed"); - }); + .reduce(singleton()); } + private static BinaryOperator singleton() { + return (x, y) -> { + throw new IllegalStateException("only a single INSERT permission grant allowed"); + }; + } private static String toVar(final RbacView.RbacRoleDefinition roleDef) { return uncapitalize(roleDef.getEntityAlias().simpleName()) + capitalize(roleDef.getRole().roleName());