Class identity comparisons wherever possible (and further polishing)

Issue: SPR-12926
This commit is contained in:
Juergen Hoeller
2015-12-09 12:28:09 +01:00
parent 4261f34b63
commit 11806b9215
29 changed files with 127 additions and 109 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2015 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.
@@ -41,36 +41,39 @@ abstract class AbstractMediaTypeExpression implements Comparable<AbstractMediaTy
private final boolean isNegated;
AbstractMediaTypeExpression(String expression) {
if (expression.startsWith("!")) {
isNegated = true;
this.isNegated = true;
expression = expression.substring(1);
}
else {
isNegated = false;
this.isNegated = false;
}
this.mediaType = MediaType.parseMediaType(expression);
}
AbstractMediaTypeExpression(MediaType mediaType, boolean negated) {
this.mediaType = mediaType;
isNegated = negated;
this.isNegated = negated;
}
@Override
public MediaType getMediaType() {
return mediaType;
return this.mediaType;
}
@Override
public boolean isNegated() {
return isNegated;
return this.isNegated;
}
public final boolean match(HttpServletRequest request) {
try {
boolean match = matchMediaType(request);
return !isNegated ? match : !match;
return (!this.isNegated ? match : !match);
}
catch (HttpMediaTypeException ex) {
return false;
@@ -79,6 +82,7 @@ abstract class AbstractMediaTypeExpression implements Comparable<AbstractMediaTy
protected abstract boolean matchMediaType(HttpServletRequest request) throws HttpMediaTypeException;
@Override
public int compareTo(AbstractMediaTypeExpression other) {
return MediaType.SPECIFICITY_COMPARATOR.compare(this.getMediaType(), other.getMediaType());
@@ -89,25 +93,25 @@ abstract class AbstractMediaTypeExpression implements Comparable<AbstractMediaTy
if (this == obj) {
return true;
}
if (obj != null && getClass().equals(obj.getClass())) {
if (obj != null && getClass() == obj.getClass()) {
AbstractMediaTypeExpression other = (AbstractMediaTypeExpression) obj;
return (this.mediaType.equals(other.mediaType)) && (this.isNegated == other.isNegated);
return (this.mediaType.equals(other.mediaType) && this.isNegated == other.isNegated);
}
return false;
}
@Override
public int hashCode() {
return mediaType.hashCode();
return this.mediaType.hashCode();
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
if (isNegated) {
if (this.isNegated) {
builder.append('!');
}
builder.append(mediaType.toString());
builder.append(this.mediaType.toString());
return builder.toString();
}

View File

@@ -33,7 +33,7 @@ public abstract class AbstractRequestCondition<T extends AbstractRequestConditio
if (this == obj) {
return true;
}
if (obj != null && getClass().equals(obj.getClass())) {
if (obj != null && getClass() == obj.getClass()) {
AbstractRequestCondition<?> other = (AbstractRequestCondition<?>) obj;
return getContent().equals(other.getContent());
}

View File

@@ -158,7 +158,7 @@ public class PathResourceResolver extends AbstractResourceResolver {
}
private boolean isResourceUnderLocation(Resource resource, Resource location) throws IOException {
if (!resource.getClass().equals(location.getClass())) {
if (resource.getClass() != location.getClass()) {
return false;
}