#520 - Polished a couple of SonarQube warnings.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013 the original author or authors.
|
||||
* Copyright 2013-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package org.springframework.hateoas;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@@ -26,6 +28,7 @@ import java.util.HashSet;
|
||||
* @see http://www.iana.org/assignments/link-relations/link-relations.xhtml
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@UtilityClass
|
||||
public class IanaRels {
|
||||
|
||||
private static final Collection<String> RELS;
|
||||
@@ -36,13 +39,13 @@ public class IanaRels {
|
||||
|
||||
rels.addAll(Arrays.asList("about", "alternate", "appendix", "archives", "author", "bookmark", "canonical",
|
||||
"chapter", "collection", "contents", "copyright", "create-form", "current", "describedby", "describes",
|
||||
"disclosure", "duplicate", "edit", "edit-form", "edit-media", "enclosure", "first", "glossary", "help",
|
||||
"hosts", "hub", "icon", "index", "item", "last", "latest-version", "license", "lrdd", "memento", "monitor",
|
||||
"monitor-group", "next", "next-archive", "nofollow", "noreferrer", "original", "payment",
|
||||
"predecessor-version", "prefetch", "prev", "preview", "previous", "prev-archive", "privacy-policy", "profile",
|
||||
"related", "replies", "search", "section", "self", "service", "start", "stylesheet", "subsection",
|
||||
"successor-version", "tag", "terms-of-service", "timegate", "timemap", "type", "up", "version-history", "via",
|
||||
"working-copy", "working-copy-of"));
|
||||
"disclosure", "duplicate", "edit", "edit-form", "edit-media", "enclosure", "first", "glossary", "help", "hosts",
|
||||
"hub", "icon", "index", "item", "last", "latest-version", "license", "lrdd", "memento", "monitor",
|
||||
"monitor-group", "next", "next-archive", "nofollow", "noreferrer", "original", "payment", "predecessor-version",
|
||||
"prefetch", "prev", "preview", "previous", "prev-archive", "privacy-policy", "profile", "related", "replies",
|
||||
"search", "section", "self", "service", "start", "stylesheet", "subsection", "successor-version", "tag",
|
||||
"terms-of-service", "timegate", "timemap", "type", "up", "version-history", "via", "working-copy",
|
||||
"working-copy-of"));
|
||||
|
||||
RELS = Collections.unmodifiableCollection(rels);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014 the original author or authors.
|
||||
* Copyright 2014-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,6 +17,9 @@ package org.springframework.hateoas;
|
||||
|
||||
import static org.springframework.hateoas.TemplateVariable.VariableType.*;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Value;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -29,13 +32,15 @@ import org.springframework.util.StringUtils;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@Value
|
||||
@EqualsAndHashCode
|
||||
public final class TemplateVariable implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -2731446749851863774L;
|
||||
|
||||
private final String name;
|
||||
private final TemplateVariable.VariableType type;
|
||||
private final String description;
|
||||
String name;
|
||||
TemplateVariable.VariableType type;
|
||||
String description;
|
||||
|
||||
/**
|
||||
* Creates a new {@link TemplateVariable} with the given name and type.
|
||||
@@ -65,33 +70,6 @@ public final class TemplateVariable implements Serializable {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the variable.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the type of the variable.
|
||||
*
|
||||
* @return the type
|
||||
*/
|
||||
public VariableType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the description of the variable.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the variable has a description.
|
||||
*
|
||||
@@ -142,7 +120,7 @@ public final class TemplateVariable implements Serializable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the variable is a fragement one.
|
||||
* Returns whether the variable is a fragment one.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@@ -161,46 +139,12 @@ public final class TemplateVariable implements Serializable {
|
||||
return StringUtils.hasText(description) ? String.format("%s - %s", base, description) : base;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
|
||||
if (obj == this) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(obj instanceof TemplateVariable)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
TemplateVariable that = (TemplateVariable) obj;
|
||||
return this.name.equals(that.name) && this.type.equals(that.type);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.lang.Object#hashCode()
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
int result = 17;
|
||||
|
||||
result += this.name.hashCode();
|
||||
result += this.type.hashCode();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* An enumeration for all supported variable types.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public static enum VariableType {
|
||||
public enum VariableType {
|
||||
|
||||
PATH_VARIABLE("", false), //
|
||||
REQUEST_PARAM("?", true), //
|
||||
@@ -208,12 +152,13 @@ public final class TemplateVariable implements Serializable {
|
||||
SEGMENT("/", true), //
|
||||
FRAGMENT("#", true);
|
||||
|
||||
private static final List<VariableType> combinableTypes = Arrays.asList(REQUEST_PARAM, REQUEST_PARAM_CONTINUED);
|
||||
private static final List<VariableType> COMBINABLE_TYPES = Arrays.asList(REQUEST_PARAM, REQUEST_PARAM_CONTINUED);
|
||||
|
||||
private final String key;
|
||||
private final boolean optional;
|
||||
|
||||
private VariableType(String key, boolean optional) {
|
||||
|
||||
this.key = key;
|
||||
this.optional = optional;
|
||||
}
|
||||
@@ -228,7 +173,7 @@ public final class TemplateVariable implements Serializable {
|
||||
}
|
||||
|
||||
public boolean canBeCombinedWith(VariableType type) {
|
||||
return this.equals(type) || combinableTypes.contains(this) && combinableTypes.contains(type);
|
||||
return this.equals(type) || COMBINABLE_TYPES.contains(this) && COMBINABLE_TYPES.contains(type);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014 the original author or authors.
|
||||
* Copyright 2014-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,6 +17,8 @@ package org.springframework.hateoas;
|
||||
|
||||
import static org.springframework.hateoas.TemplateVariable.VariableType.*;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -33,9 +35,10 @@ import org.springframework.util.Assert;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@EqualsAndHashCode
|
||||
public final class TemplateVariables implements Iterable<TemplateVariable>, Serializable {
|
||||
|
||||
public static TemplateVariables NONE = new TemplateVariables();
|
||||
public static final TemplateVariables NONE = new TemplateVariables();
|
||||
private static final long serialVersionUID = -7736592281223783079L;
|
||||
|
||||
private final List<TemplateVariable> variables;
|
||||
@@ -172,33 +175,4 @@ public final class TemplateVariables implements Iterable<TemplateVariable>, Seri
|
||||
|
||||
return builder.append("}").toString();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(obj instanceof TemplateVariables)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
TemplateVariables that = (TemplateVariables) obj;
|
||||
|
||||
return this.variables.equals(that.variables);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.lang.Object#hashCode()
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.variables.hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,9 @@
|
||||
*/
|
||||
package org.springframework.hateoas.core;
|
||||
|
||||
import lombok.NonNull;
|
||||
import lombok.Value;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
@@ -79,7 +82,7 @@ public class DummyInvocationUtils {
|
||||
* @param targetType must not be {@literal null}.
|
||||
* @param parameters must not be {@literal null}.
|
||||
*/
|
||||
public InvocationRecordingMethodInterceptor(Class<?> targetType, Object... parameters) {
|
||||
InvocationRecordingMethodInterceptor(Class<?> targetType, Object... parameters) {
|
||||
|
||||
Assert.notNull(targetType, "Target type must not be null!");
|
||||
Assert.notNull(parameters, "Parameters must not be null!");
|
||||
@@ -222,50 +225,11 @@ public class DummyInvocationUtils {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Value
|
||||
static class SimpleMethodInvocation implements MethodInvocation {
|
||||
|
||||
private final Class<?> targetType;
|
||||
private final Method method;
|
||||
private final Object[] arguments;
|
||||
|
||||
/**
|
||||
* Creates a new {@link SimpleMethodInvocation} for the given {@link Method} and arguments.
|
||||
*
|
||||
* @param method
|
||||
* @param arguments
|
||||
*/
|
||||
private SimpleMethodInvocation(Class<?> targetType, Method method, Object[] arguments) {
|
||||
|
||||
this.targetType = targetType;
|
||||
this.arguments = arguments;
|
||||
this.method = method;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.hateoas.core.DummyInvocationUtils.MethodInvocation#getTargetType()
|
||||
*/
|
||||
@Override
|
||||
public Class<?> getTargetType() {
|
||||
return targetType;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.hateoas.core.DummyInvocationUtils.MethodInvocation#getArguments()
|
||||
*/
|
||||
@Override
|
||||
public Object[] getArguments() {
|
||||
return arguments;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.hateoas.core.DummyInvocationUtils.MethodInvocation#getMethod()
|
||||
*/
|
||||
@Override
|
||||
public Method getMethod() {
|
||||
return method;
|
||||
}
|
||||
@NonNull Class<?> targetType;
|
||||
@NonNull Method method;
|
||||
@NonNull Object[] arguments;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user