jdk/src/share/classes/java/util/regex/MatchResult.java
author alanb
Mon, 10 Jun 2013 12:58:32 +0100
changeset 18156 edb590d448c5
parent 5506 202f599c92aa
child 18787 8a57ff107238
permissions -rw-r--r--
8016217: More javadoc warnings Reviewed-by: lancea, chegar, psandoz
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.util.regex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * The result of a match operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * <p>This interface contains query methods used to determine the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * results of a match against a regular expression. The match boundaries,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * groups and group boundaries can be seen but not modified through
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * a <code>MatchResult</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * @author  Michael McCloskey
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * @see Matcher
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
public interface MatchResult {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
     * Returns the start index of the match.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
     * @return  The index of the first character matched
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     * @throws  IllegalStateException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     *          If no match has yet been attempted,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     *          or if the previous match operation failed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    public int start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     * Returns the start index of the subsequence captured by the given group
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * during this match.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * <p> <a href="Pattern.html#cg">Capturing groups</a> are indexed from left
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * to right, starting at one.  Group zero denotes the entire pattern, so
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * the expression <i>m.</i><tt>start(0)</tt> is equivalent to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * <i>m.</i><tt>start()</tt>.  </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * @param  group
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     *         The index of a capturing group in this matcher's pattern
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * @return  The index of the first character captured by the group,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     *          or <tt>-1</tt> if the match was successful but the group
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     *          itself did not match anything
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * @throws  IllegalStateException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     *          If no match has yet been attempted,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     *          or if the previous match operation failed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * @throws  IndexOutOfBoundsException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     *          If there is no capturing group in the pattern
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     *          with the given index
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    public int start(int group);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * Returns the offset after the last character matched.  </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     *
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 5506
diff changeset
    82
     * @return  The offset after the last character matched
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * @throws  IllegalStateException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     *          If no match has yet been attempted,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     *          or if the previous match operation failed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    public int end();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * Returns the offset after the last character of the subsequence
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * captured by the given group during this match.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * <p> <a href="Pattern.html#cg">Capturing groups</a> are indexed from left
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * to right, starting at one.  Group zero denotes the entire pattern, so
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * the expression <i>m.</i><tt>end(0)</tt> is equivalent to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * <i>m.</i><tt>end()</tt>.  </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * @param  group
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     *         The index of a capturing group in this matcher's pattern
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * @return  The offset after the last character captured by the group,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     *          or <tt>-1</tt> if the match was successful
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     *          but the group itself did not match anything
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * @throws  IllegalStateException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     *          If no match has yet been attempted,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     *          or if the previous match operation failed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * @throws  IndexOutOfBoundsException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     *          If there is no capturing group in the pattern
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     *          with the given index
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    public int end(int group);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * Returns the input subsequence matched by the previous match.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * <p> For a matcher <i>m</i> with input sequence <i>s</i>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * the expressions <i>m.</i><tt>group()</tt> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * <i>s.</i><tt>substring(</tt><i>m.</i><tt>start(),</tt>&nbsp;<i>m.</i><tt>end())</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * are equivalent.  </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * <p> Note that some patterns, for example <tt>a*</tt>, match the empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * string.  This method will return the empty string when the pattern
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * successfully matches the empty string in the input.  </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * @return The (possibly empty) subsequence matched by the previous match,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     *         in string form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * @throws  IllegalStateException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     *          If no match has yet been attempted,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     *          or if the previous match operation failed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    public String group();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * Returns the input subsequence captured by the given group during the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * previous match operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * <p> For a matcher <i>m</i>, input sequence <i>s</i>, and group index
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * <i>g</i>, the expressions <i>m.</i><tt>group(</tt><i>g</i><tt>)</tt> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * <i>s.</i><tt>substring(</tt><i>m.</i><tt>start(</tt><i>g</i><tt>),</tt>&nbsp;<i>m.</i><tt>end(</tt><i>g</i><tt>))</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * are equivalent.  </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * <p> <a href="Pattern.html#cg">Capturing groups</a> are indexed from left
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * to right, starting at one.  Group zero denotes the entire pattern, so
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * the expression <tt>m.group(0)</tt> is equivalent to <tt>m.group()</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * <p> If the match was successful but the group specified failed to match
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * any part of the input sequence, then <tt>null</tt> is returned. Note
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * that some groups, for example <tt>(a*)</tt>, match the empty string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * This method will return the empty string when such a group successfully
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * matches the empty string in the input.  </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * @param  group
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     *         The index of a capturing group in this matcher's pattern
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * @return  The (possibly empty) subsequence captured by the group
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     *          during the previous match, or <tt>null</tt> if the group
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     *          failed to match part of the input
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * @throws  IllegalStateException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     *          If no match has yet been attempted,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     *          or if the previous match operation failed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * @throws  IndexOutOfBoundsException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     *          If there is no capturing group in the pattern
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     *          with the given index
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    public String group(int group);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * Returns the number of capturing groups in this match result's pattern.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * <p> Group zero denotes the entire pattern by convention. It is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * included in this count.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * <p> Any non-negative integer smaller than or equal to the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * returned by this method is guaranteed to be a valid group index for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * this matcher.  </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * @return The number of capturing groups in this matcher's pattern
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    public int groupCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
}