do not use ellipsis in parameter domain arguments
This commit is contained in:
parent
dbe58d2d84
commit
ab86306ee7
2 changed files with 61 additions and 76 deletions
|
@ -92,8 +92,8 @@ public class Parameter implements Iterable<Pair<String, Object>>, Comparable<Par
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public String getAsString(String key, Domain... domains) {
|
public String getAsString(String key, Domain domain) {
|
||||||
Object object = get(key, domains);
|
Object object = get(key, domain);
|
||||||
if (object instanceof Collection) {
|
if (object instanceof Collection) {
|
||||||
Collection<Object> collection = (Collection<Object>) object;
|
Collection<Object> collection = (Collection<Object>) object;
|
||||||
Iterator<Object> iterator = collection.iterator();
|
Iterator<Object> iterator = collection.iterator();
|
||||||
|
@ -108,8 +108,8 @@ public class Parameter implements Iterable<Pair<String, Object>>, Comparable<Par
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public Integer getAsInteger(String key, Domain... domains) {
|
public Integer getAsInteger(String key, Domain domain) {
|
||||||
Object object = get(key, domains);
|
Object object = get(key, domain);
|
||||||
if (object instanceof Collection) {
|
if (object instanceof Collection) {
|
||||||
Collection<Object> collection = (Collection<Object>) object;
|
Collection<Object> collection = (Collection<Object>) object;
|
||||||
Iterator<Object> iterator = collection.iterator();
|
Iterator<Object> iterator = collection.iterator();
|
||||||
|
@ -128,8 +128,8 @@ public class Parameter implements Iterable<Pair<String, Object>>, Comparable<Par
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public Boolean getAsBoolean(String key, Domain... domains) {
|
public Boolean getAsBoolean(String key, Domain domain) {
|
||||||
Object object = get(key, domains);
|
Object object = get(key, domain);
|
||||||
if (object instanceof Collection) {
|
if (object instanceof Collection) {
|
||||||
Collection<Object> collection = (Collection<Object>) object;
|
Collection<Object> collection = (Collection<Object>) object;
|
||||||
Iterator<Object> iterator = collection.iterator();
|
Iterator<Object> iterator = collection.iterator();
|
||||||
|
@ -183,18 +183,15 @@ public class Parameter implements Iterable<Pair<String, Object>>, Comparable<Par
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Object> getAllDomain(Domain... domains) {
|
public List<Object> getAllDomain(Domain domain) {
|
||||||
Parameter parameter = null;
|
Parameter parameter = null;
|
||||||
for (Domain domain : domains) {
|
|
||||||
if (builder.parameterMap.containsKey(domain)) {
|
if (builder.parameterMap.containsKey(domain)) {
|
||||||
parameter = builder.parameterMap.get(domain);
|
parameter = builder.parameterMap.get(domain);
|
||||||
}
|
}
|
||||||
if (parameter != null) {
|
if (parameter != null) {
|
||||||
List<Object> list = parameter.getAllDomain(domains);
|
return parameter.getAllDomain(domain);
|
||||||
if (list != null) {
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if (getDomain().equals(domain)) {
|
||||||
return list.stream()
|
return list.stream()
|
||||||
.map(Pair::getValue)
|
.map(Pair::getValue)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
@ -202,44 +199,39 @@ public class Parameter implements Iterable<Pair<String, Object>>, Comparable<Par
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPresent(Domain... domains) {
|
public boolean isPresent(Domain domain) {
|
||||||
Parameter parameter = null;
|
Parameter parameter = null;
|
||||||
for (Domain domain : domains) {
|
|
||||||
if (builder.parameterMap.containsKey(domain)) {
|
if (builder.parameterMap.containsKey(domain)) {
|
||||||
parameter = builder.parameterMap.get(domain);
|
parameter = builder.parameterMap.get(domain);
|
||||||
}
|
}
|
||||||
if (parameter != null) {
|
if (parameter != null) {
|
||||||
boolean b = parameter.isPresent(domains);
|
return parameter.isPresent(domain);
|
||||||
if (b) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if (getDomain().equals(domain)) {
|
||||||
return list.stream().findAny().isPresent();
|
return list.stream().findAny().isPresent();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Parameter getDomain(Domain... domains) {
|
public Parameter getDomain(Domain domain) {
|
||||||
for (Domain domain : domains) {
|
|
||||||
if (builder.parameterMap.containsKey(domain)) {
|
if (builder.parameterMap.containsKey(domain)) {
|
||||||
return builder.parameterMap.get(domain);
|
return builder.parameterMap.get(domain);
|
||||||
}
|
}
|
||||||
|
if (getDomain().equals(domain)) {
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Object> getAll(String key, Domain... domains) {
|
public List<Object> getAll(String key, Domain domain) {
|
||||||
Parameter parameter = null;
|
Parameter parameter = null;
|
||||||
for (Domain domain : domains) {
|
|
||||||
if (builder.parameterMap.containsKey(domain)) {
|
if (builder.parameterMap.containsKey(domain)) {
|
||||||
parameter = builder.parameterMap.get(domain);
|
parameter = builder.parameterMap.get(domain);
|
||||||
}
|
}
|
||||||
if (parameter != null) {
|
if (parameter != null) {
|
||||||
List<Object> list = parameter.getAll(key, domains);
|
return parameter.getAll(key, domain);
|
||||||
if (list != null) {
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if (getDomain().equals(domain)) {
|
||||||
return list.stream()
|
return list.stream()
|
||||||
.filter(p -> p.getKey().equals(key))
|
.filter(p -> p.getKey().equals(key))
|
||||||
.map(Pair::getValue)
|
.map(Pair::getValue)
|
||||||
|
@ -248,36 +240,30 @@ public class Parameter implements Iterable<Pair<String, Object>>, Comparable<Par
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean containsKey(String key, Domain... domains) {
|
public boolean containsKey(String key, Domain domain) {
|
||||||
Parameter parameter = null;
|
Parameter parameter = null;
|
||||||
for (Domain domain : domains) {
|
|
||||||
if (builder.parameterMap.containsKey(domain)) {
|
if (builder.parameterMap.containsKey(domain)) {
|
||||||
parameter = builder.parameterMap.get(domain);
|
parameter = builder.parameterMap.get(domain);
|
||||||
}
|
}
|
||||||
if (parameter != null) {
|
if (parameter != null) {
|
||||||
boolean b = parameter.containsKey(key, domains);
|
return parameter.containsKey(key, domain);
|
||||||
if (b) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if (getDomain().equals(domain)) {
|
||||||
return list.stream()
|
return list.stream()
|
||||||
.anyMatch(p -> key.equals(p.getKey()));
|
.anyMatch(p -> key.equals(p.getKey()));
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object get(String key, Domain... domains) {
|
public Object get(String key, Domain domain) {
|
||||||
Parameter parameter = null;
|
Parameter parameter = null;
|
||||||
for (Domain domain : domains) {
|
|
||||||
if (builder.parameterMap.containsKey(domain)) {
|
if (builder.parameterMap.containsKey(domain)) {
|
||||||
parameter = builder.parameterMap.get(domain);
|
parameter = builder.parameterMap.get(domain);
|
||||||
}
|
}
|
||||||
if (parameter != null) {
|
if (parameter != null) {
|
||||||
Object object = parameter.get(key, domains);
|
return parameter.get(key, domain);
|
||||||
if (object != null) {
|
|
||||||
return object;
|
|
||||||
}
|
}
|
||||||
} else {
|
if (getDomain().equals(domain)) {
|
||||||
Optional<Object> optional = list.stream()
|
Optional<Object> optional = list.stream()
|
||||||
.filter(p -> key.equals(p.getKey()))
|
.filter(p -> key.equals(p.getKey()))
|
||||||
.map(Pair::getValue)
|
.map(Pair::getValue)
|
||||||
|
@ -286,7 +272,6 @@ public class Parameter implements Iterable<Pair<String, Object>>, Comparable<Par
|
||||||
return optional.get();
|
return optional.get();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -156,9 +156,9 @@ public class ParameterTest {
|
||||||
assertEquals("a", p.get("a", Parameter.Domain.QUERY).toString());
|
assertEquals("a", p.get("a", Parameter.Domain.QUERY).toString());
|
||||||
assertEquals("b", p.get("b", Parameter.Domain.FORM).toString());
|
assertEquals("b", p.get("b", Parameter.Domain.FORM).toString());
|
||||||
assertEquals("c", p.get("c", Parameter.Domain.HEADER).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("a", p.get("a", Parameter.Domain.QUERY));
|
||||||
assertEquals("b", p.get("b", Parameter.Domain.QUERY, Parameter.Domain.FORM, Parameter.Domain.HEADER));
|
assertEquals("b", p.get("b", Parameter.Domain.FORM));
|
||||||
assertEquals("c", p.get("c", Parameter.Domain.QUERY, Parameter.Domain.FORM, Parameter.Domain.HEADER));
|
assertEquals("c", p.get("c", Parameter.Domain.HEADER));
|
||||||
assertTrue(p.isPresent(Parameter.Domain.QUERY));
|
assertTrue(p.isPresent(Parameter.Domain.QUERY));
|
||||||
assertTrue(p.isPresent(Parameter.Domain.FORM));
|
assertTrue(p.isPresent(Parameter.Domain.FORM));
|
||||||
assertTrue(p.isPresent(Parameter.Domain.HEADER));
|
assertTrue(p.isPresent(Parameter.Domain.HEADER));
|
||||||
|
|
Loading…
Reference in a new issue