Skip to content
This repository was archived by the owner on May 28, 2018. It is now read-only.

Commit 4726653

Browse files
author
Michal Gajdos
committed
JERSEY-2486: Clarify Javadoc of PatternWithGroups.getGroupIndexes()
- updated javadoc - UriTemplateParser.getGroupIndexes now returns non-empty array in case no nested capturing groups are used in a template - test Change-Id: Ie09b1da069b3dfcb2f7dc1a66b844fb8c1519019 Signed-off-by: Michal Gajdos <[email protected]>
1 parent 7860d26 commit 4726653

File tree

3 files changed

+42
-10
lines changed

3 files changed

+42
-10
lines changed

core-common/src/main/java/org/glassfish/jersey/uri/PatternWithGroups.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,13 @@ public final String getRegex() {
147147
}
148148

149149
/**
150-
* Get the group indexes.
150+
* Get the group indexes to capturing groups.
151+
* <p>
152+
* Any nested capturing groups will be ignored and the
153+
* the group index will refer to the top-level capturing
154+
* groups associated with the templates variables.
151155
*
152-
* @return the group indexes.
156+
* @return the group indexes to capturing groups.
153157
*/
154158
public final int[] getGroupIndexes() {
155159
return groupIndexes.clone();

core-common/src/main/java/org/glassfish/jersey/uri/internal/UriTemplateParser.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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
@@ -190,12 +190,7 @@ public final int[] getGroupIndexes() {
190190
for (int i = 1; i < indexes.length; i++) {
191191
indexes[i] = indexes[i - 1] + groupCounts.get(i - 1);
192192
}
193-
for (int i = 0; i < indexes.length; i++) {
194-
if (indexes[i] != i + 1) {
195-
return indexes;
196-
}
197-
}
198-
return EMPTY_INT_ARRAY;
193+
return indexes;
199194
}
200195

201196
/**

core-common/src/test/java/org/glassfish/jersey/uri/UriTemplateTest.java

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
/**
5959
* Taken from Jersey 1: jersey-tests: com.sun.jersey.impl.uri.UriTemplateTest
6060
*
61-
* @author Paul.Sandoz at Sun.Com
61+
* @author Paul Sandoz
6262
*/
6363
public class UriTemplateTest {
6464

@@ -398,6 +398,39 @@ public void testSubstitutionArray() {
398398
"fred", "barney", "joe");
399399
}
400400

401+
@Test
402+
public void testGroupIndexes() throws Exception {
403+
UriTemplate template = new UriTemplate("/a");
404+
assertThat(template.getPattern().getGroupIndexes(), equalTo(new int[0]));
405+
406+
template = new UriTemplate("/{a}");
407+
assertThat(template.getPattern().getGroupIndexes(), equalTo(new int[] {1, 2}));
408+
409+
template = new UriTemplate("/{a}/b");
410+
assertThat(template.getPattern().getGroupIndexes(), equalTo(new int[] {1, 2}));
411+
412+
template = new UriTemplate("/{a}/{b}");
413+
assertThat(template.getPattern().getGroupIndexes(), equalTo(new int[] {1, 2, 3}));
414+
415+
template = new UriTemplate("/{a}/{b}");
416+
assertThat(template.getPattern().getGroupIndexes(), equalTo(new int[] {1, 2, 3}));
417+
418+
template = new UriTemplate("/{a}/b/{c}");
419+
assertThat(template.getPattern().getGroupIndexes(), equalTo(new int[] {1, 2, 3}));
420+
421+
template = new UriTemplate("/{a: (abc)+}");
422+
assertThat(template.getPattern().getGroupIndexes(), equalTo(new int[] {1, 3}));
423+
424+
template = new UriTemplate("/{a: (abc)+}/b");
425+
assertThat(template.getPattern().getGroupIndexes(), equalTo(new int[] {1, 3}));
426+
427+
template = new UriTemplate("/{a: (abc)+}/{b}");
428+
assertThat(template.getPattern().getGroupIndexes(), equalTo(new int[] {1, 3, 4}));
429+
430+
template = new UriTemplate("/{a: (abc)+}/b/{c}");
431+
assertThat(template.getPattern().getGroupIndexes(), equalTo(new int[] {1, 3, 4}));
432+
}
433+
401434
void _testSubstitutionArray(String template, String uri, String... values) {
402435
UriTemplate t = new UriTemplate(template);
403436

0 commit comments

Comments
 (0)