polishing

This commit is contained in:
Juergen Hoeller 2009-02-24 12:20:41 +00:00
parent 760cab8fea
commit c46b0ae271
3 changed files with 43 additions and 22 deletions

View File

@ -1,11 +1,29 @@
/*
* Copyright 2002-2009 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.util; package org.springframework.util;
import java.util.Map; import java.util.Map;
/** /**
* Package-protected helper class for {@link AntPathMatcher}. Tests whether or not a string matches against a pattern. * Package-protected helper class for {@link AntPathMatcher}.
* The pattern may contain special characters:<br> '*' means zero or more characters<br> '?' means one and only one * Tests whether or not a string matches against a pattern.
* character, '{' and '}' indicate a uri template pattern *
* <p>The pattern may contain special characters: '*' means zero or more characters;
* '?' means one and only one character; '{' and '}' indicate a URI template pattern.
* *
* @author Arjen Poutsma * @author Arjen Poutsma
* @since 3.0 * @since 3.0
@ -28,29 +46,24 @@ class AntPatchStringMatcher {
private final Map<String, String> uriTemplateVariables; private final Map<String, String> uriTemplateVariables;
/** Constructs a new instance of the <code>AntPatchStringMatcher</code>. */
AntPatchStringMatcher(String pattern, String str, Map<String, String> uriTemplateVariables) { /**
patArr = pattern.toCharArray(); * Construct a new instance of the <code>AntPatchStringMatcher</code>.
strArr = str.toCharArray(); */
public AntPatchStringMatcher(String pattern, String str, Map<String, String> uriTemplateVariables) {
this.patArr = pattern.toCharArray();
this.strArr = str.toCharArray();
this.patIdxEnd = this.patArr.length - 1;
this.strIdxEnd = this.strArr.length - 1;
this.uriTemplateVariables = uriTemplateVariables; this.uriTemplateVariables = uriTemplateVariables;
patIdxEnd = patArr.length - 1;
strIdxEnd = strArr.length - 1;
} }
private void addTemplateVariable(int curlyIdxStart, int curlyIdxEnd, int valIdxStart, int valIdxEnd) {
if (uriTemplateVariables != null) {
String varName = new String(patArr, curlyIdxStart + 1, curlyIdxEnd - curlyIdxStart - 1);
String varValue = new String(strArr, valIdxStart, valIdxEnd - valIdxStart + 1);
uriTemplateVariables.put(varName, varValue);
}
}
/** /**
* Main entry point. * Main entry point.
*
* @return <code>true</code> if the string matches against the pattern, or <code>false</code> otherwise. * @return <code>true</code> if the string matches against the pattern, or <code>false</code> otherwise.
*/ */
boolean matchStrings() { public boolean matchStrings() {
if (shortcutPossible()) { if (shortcutPossible()) {
return doShortcut(); return doShortcut();
} }
@ -119,6 +132,14 @@ class AntPatchStringMatcher {
return onlyStarsLeft(); return onlyStarsLeft();
} }
private void addTemplateVariable(int curlyIdxStart, int curlyIdxEnd, int valIdxStart, int valIdxEnd) {
if (uriTemplateVariables != null) {
String varName = new String(patArr, curlyIdxStart + 1, curlyIdxEnd - curlyIdxStart - 1);
String varValue = new String(strArr, valIdxStart, valIdxEnd - valIdxStart + 1);
uriTemplateVariables.put(varName, varValue);
}
}
private boolean consecutiveStars(int patIdxTmp) { private boolean consecutiveStars(int patIdxTmp) {
if (patIdxTmp == patIdxStart + 1 && patArr[patIdxStart] == '*' && patArr[patIdxTmp] == '*') { if (patIdxTmp == patIdxStart + 1 && patArr[patIdxStart] == '*' && patArr[patIdxTmp] == '*') {
// Two stars next to each other, skip the first one. // Two stars next to each other, skip the first one.

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2008 the original author or authors. * Copyright 2002-2009 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -106,7 +106,7 @@ public class CachingMapDecorator<K, V> implements Map<K, V>, Serializable {
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public CachingMapDecorator(Map<K, V> targetMap, boolean synchronize, boolean weak) { public CachingMapDecorator(Map<K, V> targetMap, boolean synchronize, boolean weak) {
Assert.notNull(targetMap, "Target Map is required"); Assert.notNull(targetMap, "'targetMap' must not be null");
this.targetMap = (Map<K, Object>) (synchronize ? Collections.synchronizedMap(targetMap) : targetMap); this.targetMap = (Map<K, Object>) (synchronize ? Collections.synchronizedMap(targetMap) : targetMap);
this.synchronize = synchronize; this.synchronize = synchronize;
this.weak = weak; this.weak = weak;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2008 the original author or authors. * Copyright 2002-2009 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -36,6 +36,6 @@ package org.springframework.web.bind.annotation;
*/ */
public enum RequestMethod { public enum RequestMethod {
GET, HEAD, POST, PUT, DELETE, OPTIONS, TRACE; GET, HEAD, POST, PUT, DELETE, OPTIONS, TRACE
} }