View Javadoc

1   /*
2    * Copyright (C) 2004 Christian Siefkes <christian@siefkes.net>.
3    * Development of this software is supported by the German Research Society,
4    * Berlin-Brandenburg Graduate School in Distributed Information Systems
5    * (DFG grant no. GRK 316).
6    *
7    * This library is free software; you can redistribute it and/or
8    * modify it under the terms of the GNU Lesser General Public
9    * License as published by the Free Software Foundation; either
10   * version 2.1 of the License, or (at your option) any later version.
11   *
12   * This library is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this library; if not, visit
19   * http://www.gnu.org/licenses/lgpl.html or write to the Free Software
20   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
21   */
22  package de.fu_berlin.ties.text;
23  
24  import org.apache.commons.lang.builder.ToStringBuilder;
25  
26  /***
27   * Stores details on a token in a document. Instances of this class are
28   * immutable and thus thread-safe.
29   *
30   * @author Christian Siefkes
31   * @version $Revision: 1.3 $, $Date: 2004/11/17 15:25:11 $, $Author: siefkes $
32   */
33  public class TokenDetails {
34  
35      /***
36       * The token itself.
37       */
38      private final String token;
39  
40      /***
41       * The repetition of the token in the original text (counting starts with 0,
42       * as the first occurrence is the "0th repetition").
43       */
44      private final int rep;
45  
46      /***
47       * The index of the token in the original text (indexing starts with 0).
48       */
49      private final int index;
50  
51      /***
52       * Whether there is whitespace before the token.
53       */
54      private final boolean whitespaceBefore;
55  
56      /***
57       * Creates a new instance.
58       *
59       * @param theToken the token to represent
60       * @param tokenRep the repetition of the token in the document (counting
61       * starts with 0, as the first occurrence is the "0th repetition")
62       * @param tokenIndex the index of the token in the document (counting
63       * starts with 0 for the very first token)
64       * @param wsBefore whether there is whitespace before the main
65       * <code>token</code> (either at the end of <code>left</code> or in the
66       * preceding element)
67       */
68      public TokenDetails(final String theToken, final int tokenRep,
69              final int tokenIndex, final boolean wsBefore) {
70          super();
71          token = theToken;
72          rep = tokenRep;
73          index = tokenIndex;
74          whitespaceBefore = wsBefore;
75      }
76  
77      /***
78       * Returns the index of the token in the original text (indexing starts
79       * with 0).
80       *
81       * @return the value of the attribute
82       */
83      public int getIndex() {
84          return index;
85      }
86  
87      /***
88       * Returns the repetition of the token in the original text (counting starts
89       * with 0, as the first occurrence is the "0th repetition").
90       *
91       * @return the value of the attribute
92       */
93      public int getRep() {
94          return rep;
95      }
96  
97      /***
98       * Returns the token itself.
99       * @return the value of the attribute
100      */
101     public String getToken() {
102         return token;
103     }
104 
105     /***
106      * Whether there is whitespace before the token.
107      * @return the value of the attribute
108      */
109     public boolean isWhitespaceBefore() {
110         return whitespaceBefore;
111     }
112 
113     /***
114      * Returns a string representation of this object.
115      *
116      * @return a textual representation
117      */
118     public String toString() {
119         return new ToStringBuilder(this)
120             .append("token", token)
121             .append("repetition", rep)
122             .append("index", index)
123             .append("whitespace before", whitespaceBefore)
124             .toString();
125     }
126 
127 }