From ab86306ee766eb5f39484955cc2f10e41efd2e3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Prante?= Date: Fri, 31 Mar 2023 15:47:56 +0200 Subject: [PATCH] do not use ellipsis in parameter domain arguments --- net/src/main/java/org/xbib/net/Parameter.java | 131 ++++++++---------- .../test/java/org/xbib/net/ParameterTest.java | 6 +- 2 files changed, 61 insertions(+), 76 deletions(-) diff --git a/net/src/main/java/org/xbib/net/Parameter.java b/net/src/main/java/org/xbib/net/Parameter.java index 9e9b172..d8edafd 100644 --- a/net/src/main/java/org/xbib/net/Parameter.java +++ b/net/src/main/java/org/xbib/net/Parameter.java @@ -92,8 +92,8 @@ public class Parameter implements Iterable>, Comparable collection = (Collection) object; Iterator iterator = collection.iterator(); @@ -108,8 +108,8 @@ public class Parameter implements Iterable>, Comparable collection = (Collection) object; Iterator iterator = collection.iterator(); @@ -128,8 +128,8 @@ public class Parameter implements Iterable>, Comparable collection = (Collection) object; Iterator iterator = collection.iterator(); @@ -183,18 +183,15 @@ public class Parameter implements Iterable>, Comparable getAllDomain(Domain... domains) { + public List getAllDomain(Domain domain) { Parameter parameter = null; - for (Domain domain : domains) { - if (builder.parameterMap.containsKey(domain)) { - parameter = builder.parameterMap.get(domain); - } - if (parameter != null) { - List list = parameter.getAllDomain(domains); - if (list != null) { - return list; - } - } + if (builder.parameterMap.containsKey(domain)) { + parameter = builder.parameterMap.get(domain); + } + if (parameter != null) { + return parameter.getAllDomain(domain); + } + if (getDomain().equals(domain)) { return list.stream() .map(Pair::getValue) .collect(Collectors.toList()); @@ -202,44 +199,39 @@ public class Parameter implements Iterable>, Comparable getAll(String key, Domain... domains) { + public List getAll(String key, Domain domain) { Parameter parameter = null; - for (Domain domain : domains) { - if (builder.parameterMap.containsKey(domain)) { - parameter = builder.parameterMap.get(domain); - } - if (parameter != null) { - List list = parameter.getAll(key, domains); - if (list != null) { - return list; - } - } + if (builder.parameterMap.containsKey(domain)) { + parameter = builder.parameterMap.get(domain); + } + if (parameter != null) { + return parameter.getAll(key, domain); + } + if (getDomain().equals(domain)) { return list.stream() .filter(p -> p.getKey().equals(key)) .map(Pair::getValue) @@ -248,43 +240,36 @@ public class Parameter implements Iterable>, Comparable key.equals(p.getKey())); } return false; } - public Object get(String key, Domain... domains) { + public Object get(String key, Domain domain) { Parameter parameter = null; - for (Domain domain : domains) { - if (builder.parameterMap.containsKey(domain)) { - parameter = builder.parameterMap.get(domain); - } - if (parameter != null) { - Object object = parameter.get(key, domains); - if (object != null) { - return object; - } - } else { - Optional optional = list.stream() - .filter(p -> key.equals(p.getKey())) - .map(Pair::getValue) - .findFirst(); - if (optional.isPresent()) { - return optional.get(); - } + if (builder.parameterMap.containsKey(domain)) { + parameter = builder.parameterMap.get(domain); + } + if (parameter != null) { + return parameter.get(key, domain); + } + if (getDomain().equals(domain)) { + Optional optional = list.stream() + .filter(p -> key.equals(p.getKey())) + .map(Pair::getValue) + .findFirst(); + if (optional.isPresent()) { + return optional.get(); } } return null; diff --git a/net/src/test/java/org/xbib/net/ParameterTest.java b/net/src/test/java/org/xbib/net/ParameterTest.java index e6756a0..23821e7 100644 --- a/net/src/test/java/org/xbib/net/ParameterTest.java +++ b/net/src/test/java/org/xbib/net/ParameterTest.java @@ -156,9 +156,9 @@ public class ParameterTest { assertEquals("a", p.get("a", Parameter.Domain.QUERY).toString()); assertEquals("b", p.get("b", Parameter.Domain.FORM).toString()); assertEquals("c", p.get("c", Parameter.Domain.HEADER).toString()); - assertEquals("a", p.get("a", Parameter.Domain.QUERY, Parameter.Domain.FORM, Parameter.Domain.HEADER)); - assertEquals("b", p.get("b", Parameter.Domain.QUERY, Parameter.Domain.FORM, Parameter.Domain.HEADER)); - assertEquals("c", p.get("c", Parameter.Domain.QUERY, Parameter.Domain.FORM, Parameter.Domain.HEADER)); + assertEquals("a", p.get("a", Parameter.Domain.QUERY)); + assertEquals("b", p.get("b", Parameter.Domain.FORM)); + assertEquals("c", p.get("c", Parameter.Domain.HEADER)); assertTrue(p.isPresent(Parameter.Domain.QUERY)); assertTrue(p.isPresent(Parameter.Domain.FORM)); assertTrue(p.isPresent(Parameter.Domain.HEADER));