Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/acmsl/regexpplugin/gnuregexp/MatchResultGNUAdapter.java


1   /*
2                   Java Regular Expressions Plugin API
3   
4       Copyright (C) 2002  Jose San Leandro Armendáriz
5                           jsanleandro@yahoo.es
6                           chousz@yahoo.com
7   
8       This library is free software; you can redistribute it and/or
9       modify it under the terms of the GNU Lesser General Public
10      License as published by the Free Software Foundation; either
11      version 2.1 of the License, or (at your option) any later version.
12  
13      This library is distributed in the hope that it will be useful,
14      but WITHOUT ANY WARRANTY; without even the implied warranty of
15      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16      Lesser General Public License for more details.
17  
18      You should have received a copy of the GNU Lesser General Public
19      License along with this library; if not, write to the Free Software
20      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  
22      Thanks to ACM S.L. for distributing this library under the LGPL license.
23      Contact info: jsr000@terra.es
24      Postal Address: c/Playa de Lagoa, 1
25                      Urb. Valdecabañas
26                      Boadilla del monte
27                      28660 Madrid
28                      Spain
29  
30      This library uses some external APIs. So far I haven't released such
31      APIs as projects themselves, but you should be able
32      to download them from the web page where you got this source code.
33  
34   ******************************************************************************
35   *
36   * Filename: $RCSfile: MatchResultGNUAdapter.java,v $
37   *
38   * Author: Jose San Leandro Armendáriz
39   *
40   * Description: Represents the result of match in a regexp parsing
41   *              process using GNU Regexp 1.1.4 package.
42   *
43   * Last modified by: $Author: dev $ at $Date: 2002/09/27 08:27:14 $
44   *
45   * File version: $Revision: 1.4 $
46   *
47   * Project version: $Name:  $
48   *                  ("Name" means no concrete version has been checked out)
49   *
50   * $Id: MatchResultGNUAdapter.java,v 1.4 2002/09/27 08:27:14 dev Exp $
51   *
52   */
53  package org.acmsl.regexpplugin.gnuregexp;
54  
55  /*
56   * Importing some project-specific classes.
57   */
58  import org.acmsl.regexpplugin.MatchResult;
59  
60  /*
61   * Importing some ACM classes.
62   */
63  import org.acmsl.version.Version;
64  import org.acmsl.version.VersionFactory;
65  
66  /*
67   * Importing some GNU Regexp 1.1.4 classes.
68   */
69  import gnu.regexp.REMatch;
70  
71  /**
72   * Represents the result of match in a regexp parsing process using
73   * GNU Regexp 1.1.4 package.
74   * @author <a href="mailto:jsanleandro@yahoo.es"
75             >Jose San Leandro Armendáriz</a>
76   * @version $Revision: 1.4 $
77   */
78  public class MatchResultGNUAdapter
79      implements  MatchResult
80  {
81      /**
82       * Adapted object.
83       */
84      private REMatch m__Adaptee;
85  
86      /**
87       * Group count.
88       */
89      private int m__iGroups = 0;
90  
91      /**
92       * Constructs a MatchResultGNUAdapter from given GNU Regexp 1.1.4
93       * REMatch instance.
94       * @param adaptee GNU Regexp 1.1.4 REMatch object to adapt.
95       * @param groups the group count.
96       */
97      public MatchResultGNUAdapter(REMatch adaptee, int groups)
98      {
99          setAdaptee(adaptee);
100 
101         setGroups(groups);
102     }
103 
104     /**
105      * Sets the adaptee.
106      * @param adaptee the instance to adapt.
107      */
108     protected void setAdaptee(REMatch adaptee)
109     {
110         m__Adaptee = adaptee;
111     }
112 
113     /**
114      * Retrieves the adaptee.
115      * @return the instance to adapt.
116      */
117     protected REMatch getAdaptee()
118     {
119         return m__Adaptee;
120     }
121 
122     /**
123      * Taken from JDK1.4 javadoc:
124      * <i>Returns the string matching the given subexpression. The
125      * subexpressions are indexed starting with one, not zero.
126      * That is, the subexpression identified by the first set of
127      * parentheses in a regular expression could be retrieved from an
128      * REMatch by calling match.toString(1).
129      * @param group Index of the subexpression.
130      * @return the group matched at given position.
131      */
132     public String group(int group)
133     {
134         return
135             (getAdaptee() == null)
136             ?  ""
137             :  (group < 1)
138                ?  getAdaptee().toString()
139                :  getAdaptee().toString(group);
140     }
141 
142     /**
143      * Taken from GNU Regexp 1.4 javadoc:
144      * <i>Returns the maximum number of subexpressions in this regular
145      * expression</i>.
146      * @return such value.
147      */
148     public int groups()
149     {
150         return m__iGroups;
151     }
152 
153     /**
154      * Sets the group count.
155      * @param groups the number of groups.
156      */
157     protected void setGroups(int groups)
158     {
159         m__iGroups = groups;
160     }
161 
162     /**
163      * Concrete version object updated everytime it's checked-in in a CVS
164      * repository.
165      */
166     public static final Version VERSION =
167         VersionFactory.createVersion("$Revision: 1.4 $");
168 
169     /**
170      * Retrieves the current version of this object.
171      * @return the version object with such information.
172      */
173     public Version getVersion()
174     {
175         return VERSION;
176     }
177 
178     /**
179      * Retrieves the current version of this class.
180      * @return the object with class version information.
181      */
182     public static Version getClassVersion()
183     {
184         return VERSION;
185     }
186 }