11/*
22 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
33 *
4- * Copyright (c) 2010-2013 Oracle and/or its affiliates. All rights reserved.
4+ * Copyright (c) 2010-2014 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
@@ -64,11 +64,11 @@ public final class PathPattern extends PatternWithGroups {
6464 * Path pattern matching the end of a URI path. Can be either empty {@code ""}
6565 * or contain a trailing slash {@code "/"}.
6666 */
67- public static final PathPattern END_OF_PATH_PATTERN = new PathPattern ("" , PathPattern .RightHandPath .capturingZeroSegments );
67+ public static final PathPattern END_OF_PATH_PATTERN = new PathPattern ("" , PathPattern .RightHandPath .capturingZeroSegments );
6868 /**
6969 * Path pattern matching the any URI path.
7070 */
71- public static final PathPattern OPEN_ROOT_PATH_PATTERN = new PathPattern ("" , RightHandPath .capturingZeroOrMoreSegments );
71+ public static final PathPattern OPEN_ROOT_PATH_PATTERN = new PathPattern ("" , RightHandPath .capturingZeroOrMoreSegments );
7272 /**
7373 * Path pattern comparator that defers to {@link UriTemplate#COMPARATOR comparing
7474 * the templates} associated with the patterns.
@@ -119,6 +119,7 @@ private String getRegex() {
119119 public static PathPattern asClosed (PathPattern pattern ) {
120120 return new PathPattern (pattern .getTemplate ().getTemplate (), RightHandPath .capturingZeroSegments );
121121 }
122+
122123 //
123124 private final UriTemplate template ;
124125
@@ -132,7 +133,6 @@ private PathPattern() {
132133 * {@link RightHandPath#capturingZeroOrMoreSegments}.
133134 *
134135 * @param template the path template.
135- *
136136 * @see #PathPattern(String, PathPattern.RightHandPath)
137137 */
138138 public PathPattern (String template ) {
@@ -144,12 +144,11 @@ public PathPattern(String template) {
144144 * {@link RightHandPath#capturingZeroOrMoreSegments}.
145145 *
146146 * @param template the path template
147- *
148147 * @see #PathPattern(PathTemplate, PathPattern.RightHandPath)
149148 */
150149 public PathPattern (PathTemplate template ) {
151150 super (postfixWithCapturingGroup (template .getPattern ().getRegex ()),
152- addIndexForRightHandPathCapturingGroup (template .getPattern ().getGroupIndexes ()));
151+ addIndexForRightHandPathCapturingGroup (template .getNumberOfRegexGroups (), template . getPattern ().getGroupIndexes ()));
153152
154153 this .template = template ;
155154 }
@@ -158,7 +157,7 @@ public PathPattern(PathTemplate template) {
158157 * Create a path pattern and post fix with a right hand path pattern.
159158 *
160159 * @param template the path template.
161- * @param rhpp the right hand path pattern postfix.
160+ * @param rhpp the right hand path pattern postfix.
162161 */
163162 public PathPattern (String template , RightHandPath rhpp ) {
164163 this (new PathTemplate (template ), rhpp );
@@ -168,11 +167,11 @@ public PathPattern(String template, RightHandPath rhpp) {
168167 * Create a path pattern and post fix with a right hand path pattern.
169168 *
170169 * @param template the path template.
171- * @param rhpp the right hand path pattern postfix.
170+ * @param rhpp the right hand path pattern postfix.
172171 */
173172 public PathPattern (PathTemplate template , RightHandPath rhpp ) {
174173 super (postfixWithCapturingGroup (template .getPattern ().getRegex (), rhpp ),
175- addIndexForRightHandPathCapturingGroup (template .getPattern ().getGroupIndexes ()));
174+ addIndexForRightHandPathCapturingGroup (template .getNumberOfRegexGroups (), template . getPattern ().getGroupIndexes ()));
176175
177176 this .template = template ;
178177 }
@@ -193,15 +192,15 @@ private static String postfixWithCapturingGroup(String regex, RightHandPath rhpp
193192 return regex + rhpp .getRegex ();
194193 }
195194
196- private static int [] addIndexForRightHandPathCapturingGroup (int [] indexes ) {
195+ private static int [] addIndexForRightHandPathCapturingGroup (int numberOfGroups , int [] indexes ) {
197196 if (indexes .length == 0 ) {
198197 return indexes ;
199198 }
200199
201200 int [] cgIndexes = new int [indexes .length + 1 ];
202201 System .arraycopy (indexes , 0 , cgIndexes , 0 , indexes .length );
203202
204- cgIndexes [indexes .length ] = cgIndexes [ indexes . length - 1 ] + 1 ;
203+ cgIndexes [indexes .length ] = numberOfGroups + 1 ;
205204 return cgIndexes ;
206205 }
207206}
0 commit comments