11/*
22 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
33 *
4- * Copyright (c) 2010-2012 Oracle and/or its affiliates. All rights reserved.
4+ * Copyright (c) 2010-2013 Oracle and/or its affiliates. All rights reserved.
55 *
66 * The contents of this file are subject to the terms of either the GNU
77 * General Public License Version 2 only ("GPL") or the Common Development
5050 * A pattern for matching a string against a regular expression
5151 * and returning capturing group values for any capturing groups present in
5252 * the expression.
53- *
53+ * <p/>
5454 * #renamed com.sun.jersey.api.uri.UriPattern
5555 *
5656 * @author Paul Sandoz
@@ -76,7 +76,7 @@ public class PatternWithGroups {
7676 private final int [] groupIndexes ;
7777
7878 /**
79- * Construct an empty pattern.
79+ * Construct an empty pattern.
8080 */
8181 protected PatternWithGroups () {
8282 this .regex = "" ;
@@ -87,11 +87,9 @@ protected PatternWithGroups() {
8787 /**
8888 * Construct a new pattern.
8989 *
90- * @param regex the regular expression. If the expression is null or an
91- * empty string then the pattern will only match a null or empty
92- * string.
93- * @throws java.util.regex.PatternSyntaxException if the
94- * regular expression could not be compiled
90+ * @param regex the regular expression. If the expression is {@code null} or an empty string then the pattern will only match
91+ * a {@code null} or empty string.
92+ * @throws java.util.regex.PatternSyntaxException if the regular expression could not be compiled.
9593 */
9694 public PatternWithGroups (final String regex ) throws PatternSyntaxException {
9795 this (regex , EMPTY_INT_ARRAY );
@@ -100,12 +98,10 @@ public PatternWithGroups(final String regex) throws PatternSyntaxException {
10098 /**
10199 * Construct a new pattern.
102100 *
103- * @param regex the regular expression. If the expression is null or an
104- * empty string then the pattern will only match a null or empty
105- * string.
101+ * @param regex the regular expression. If the expression is {@code null} or an empty string then the pattern will only match
102+ * a {@code null} or empty string.
106103 * @param groupIndexes the array of group indexes to capturing groups.
107- * @throws java.util.regex.PatternSyntaxException if the
108- * regular expression could not be compiled
104+ * @throws java.util.regex.PatternSyntaxException if the regular expression could not be compiled.
109105 */
110106 public PatternWithGroups (final String regex , final int [] groupIndexes ) throws PatternSyntaxException {
111107 this (compile (regex ), groupIndexes );
@@ -118,8 +114,8 @@ private static Pattern compile(final String regex) throws PatternSyntaxException
118114 /**
119115 * Construct a new pattern.
120116 *
121- * @param regexPattern the regular expression pattern
122- * @throws IllegalArgumentException if the regexPattern is null.
117+ * @param regexPattern the regular expression pattern.
118+ * @throws IllegalArgumentException if the regexPattern is {@code null} .
123119 */
124120 public PatternWithGroups (final Pattern regexPattern ) throws IllegalArgumentException {
125121 this (regexPattern , EMPTY_INT_ARRAY );
@@ -128,9 +124,9 @@ public PatternWithGroups(final Pattern regexPattern) throws IllegalArgumentExcep
128124 /**
129125 * Construct a new pattern.
130126 *
131- * @param regexPattern the regular expression pattern
127+ * @param regexPattern the regular expression pattern.
132128 * @param groupIndexes the array of group indexes to capturing groups.
133- * @throws IllegalArgumentException if the regexPattern is null.
129+ * @throws IllegalArgumentException if the regexPattern is {@code null} .
134130 */
135131 public PatternWithGroups (final Pattern regexPattern , final int [] groupIndexes ) throws IllegalArgumentException {
136132 if (regexPattern == null ) {
@@ -139,7 +135,7 @@ public PatternWithGroups(final Pattern regexPattern, final int[] groupIndexes) t
139135
140136 this .regex = regexPattern .toString ();
141137 this .regexPattern = regexPattern ;
142- this .groupIndexes = groupIndexes ;
138+ this .groupIndexes = groupIndexes . clone () ;
143139 }
144140
145141 /**
@@ -157,7 +153,7 @@ public final String getRegex() {
157153 * @return the group indexes.
158154 */
159155 public final int [] getGroupIndexes () {
160- return groupIndexes ;
156+ return groupIndexes . clone () ;
161157 }
162158
163159 private static final class EmptyStringMatchResult implements MatchResult {
@@ -206,6 +202,7 @@ public int groupCount() {
206202 return 0 ;
207203 }
208204 }
205+
209206 private static final EmptyStringMatchResult EMPTY_STRING_MATCH_RESULT = new EmptyStringMatchResult ();
210207
211208 private final class GroupIndexMatchResult implements MatchResult {
@@ -293,17 +290,14 @@ public final MatchResult match(final CharSequence cs) {
293290
294291 /**
295292 * Match against the pattern.
296- * <p>
297- * If a matched then the capturing group values
298- * (if any) will be added to a list passed in as parameter.
293+ * <p/>
294+ * If a matched then the capturing group values (if any) will be added to a list passed in as parameter.
299295 *
300296 * @param cs the char sequence to match against the template.
301- * @param groupValues the list to add the values of a pattern's
302- * capturing groups if matching is successful. The values are added
303- * in the same order as the pattern's capturing groups. The list
304- * is cleared before values are added.
305- * @return true if the char sequence matches the pattern, otherwise false.
306- * @throws IllegalArgumentException if the group values is null.
297+ * @param groupValues the list to add the values of a pattern's capturing groups if matching is successful. The values are
298+ * added in the same order as the pattern's capturing groups. The list is cleared before values are added.
299+ * @return {@code true} if the char sequence matches the pattern, otherwise {@code false}.
300+ * @throws IllegalArgumentException if the group values is {@code null}.
307301 */
308302 public final boolean match (final CharSequence cs , final List <String > groupValues ) throws IllegalArgumentException {
309303 if (groupValues == null ) {
@@ -312,7 +306,7 @@ public final boolean match(final CharSequence cs, final List<String> groupValues
312306
313307 // Check for match against the empty pattern
314308 if (cs == null || cs .length () == 0 ) {
315- return ( regexPattern == null ) ? true : false ;
309+ return regexPattern == null ;
316310 } else if (regexPattern == null ) {
317311 return false ;
318312 }
@@ -342,33 +336,26 @@ public final boolean match(final CharSequence cs, final List<String> groupValues
342336
343337 /**
344338 * Match against the pattern.
345- * <p>
346- * If a matched then the capturing group values
347- * (if any) will be added to a list passed in as parameter.
339+ * <p/>
340+ * If a matched then the capturing group values (if any) will be added to a list passed in as parameter.
348341 *
349342 * @param cs the char sequence to match against the template.
350- * @param groupNames the list names associated with a pattern's
351- * capturing groups. The names MUST be in the same order as the
352- * pattern's capturing groups and the size MUST be equal to or
353- * less than the number of capturing groups.
354- * @param groupValues the map to add the values of a pattern's
355- * capturing groups if matching is successful. A values is put
356- * into the map using the group name associated with the
357- * capturing group. The map is cleared before values are added.
358- * @return true if the matches the pattern, otherwise false.
359- * @throws IllegalArgumentException if group values is null.
343+ * @param groupNames the list names associated with a pattern's capturing groups. The names MUST be in the same order as the
344+ * pattern's capturing groups and the size MUST be equal to or less than the number of capturing groups.
345+ * @param groupValues the map to add the values of a pattern's capturing groups if matching is successful. A values is put
346+ * into the map using the group name associated with the capturing group. The map is cleared before values are added.
347+ * @return {@code true} if the matches the pattern, otherwise {@code false}.
348+ * @throws IllegalArgumentException if group values is {@code null}.
360349 */
361- public final boolean match (
362- final CharSequence cs ,
363- final List <String > groupNames ,
364- final Map <String , String > groupValues ) throws IllegalArgumentException {
350+ public final boolean match (final CharSequence cs , final List <String > groupNames , final Map <String ,
351+ String > groupValues ) throws IllegalArgumentException {
365352 if (groupValues == null ) {
366353 throw new IllegalArgumentException ();
367354 }
368355
369356 // Check for match against the empty pattern
370357 if (cs == null || cs .length () == 0 ) {
371- return ( regexPattern == null ) ? true : false ;
358+ return regexPattern == null ;
372359 } else if (regexPattern == null ) {
373360 return false ;
374361 }
@@ -385,7 +372,7 @@ public final boolean match(
385372 String name = groupNames .get (i );
386373 String currentValue = m .group ((groupIndexes .length > 0 ) ? groupIndexes [i ] : i + 1 );
387374
388- // Group names can have the same name occuring more than once,
375+ // Group names can have the same name occurring more than once,
389376 // check that groups values are same.
390377 String previousValue = groupValues .get (name );
391378 if (previousValue != null && !previousValue .equals (currentValue )) {
0 commit comments