View Javadoc

1   /*
2    * Copyright (C) 2003-2006 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 program is free software; you can redistribute it and/or modify
8    * it under the terms of the GNU General Public License as published by
9    * the Free Software Foundation; either version 2 of the License, or
10   * (at your option) any later version.
11   *
12   * This program 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
15   * GNU General Public License for more details.
16   *
17   * You should have received a copy of the GNU General Public License
18   * along with this program; if not, visit
19   * http://www.gnu.org/licenses/gpl.html or write to the Free Software
20   * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21   */
22  package de.fu_berlin.ties.context;
23  
24  import org.apache.commons.lang.builder.ToStringBuilder;
25  
26  /***
27   * A small immutable wrapper class that bundles the position of an element
28   * within a parent element and the number of children of the parent.
29   *
30   * @author Christian Siefkes
31   * @version $Revision: 1.4 $, $Date: 2006/10/21 16:04:03 $, $Author: siefkes $
32   */
33  public class ElementPosition {
34  
35      /***
36       * The number of all children elements in the parent element.
37       */
38      private final int allChildren;
39  
40      /***
41       * The position of the represented element in the parent element,
42       * counting all children.
43       */
44      private final int overallPosition;
45  
46      /***
47       * The number of children elements in the parent element with the type
48       * (qualified name) of the represented element.
49       */
50      private final int typedChildren;
51  
52      /***
53       * The position of the represented element in the parent element,
54       * counting only children with the same type (qualified name).
55       */
56      private final int typedPosition;
57  
58      /***
59       * The number of preceding siblings that were processed by the context
60       * representation.
61       */
62      private final int processedPreceding;
63  
64      /***
65       * The number of following siblings that were processed by the context
66       * representation.
67       */
68      private final int processedFollowing;
69  
70      /***
71       * Creates a new instance.
72       *
73       * @param allChildElements the number of all children elements in the
74       * parent element
75       * @param overallPos the position of the represented element in the
76       * parent element, counting all children
77       * @param typedChildElements the number of children elements in the
78       * parent element with the type (qualified name) of the represented
79       * element
80       * @param typedPos the position of the represented element in the
81       * parent element, counting only children with the same type
82       * (qualified name)
83       * @param processedPrecedingSiblings the number of following siblings that
84       * were processed by the context representation
85       * @param processedFollowingSiblings the number of preceding siblings that
86       * were processed by the context representation
87       */
88      public ElementPosition(final int allChildElements,
89              final int overallPos, final int typedChildElements,
90              final int typedPos, final int processedPrecedingSiblings,
91              final int processedFollowingSiblings) {
92          allChildren = allChildElements;
93          overallPosition = overallPos;
94          typedChildren = typedChildElements;
95          typedPosition = typedPos;
96          processedPreceding = processedPrecedingSiblings;
97          processedFollowing = processedFollowingSiblings;
98      }
99  
100     /***
101      * Returns the number of all children elements in the parent element.
102      *
103      * @return the number
104      */
105     public int getAllChildren() {
106         return allChildren;
107     }
108 
109     /***
110      * Returns the position of the represented element in the parent
111      * element, counting all children.
112      *
113      * @return the position
114      */
115     public int getOverallPosition() {
116         return overallPosition;
117     }
118 
119     /***
120      * Returns the number of preceding siblings that were processed by the
121      * context representation.
122      *
123      * @return the number
124      */
125     public int getProcessedFollowing() {
126         return processedFollowing;
127     }
128 
129     /***
130      * Returns the number of following siblings that were processed by the
131      * context representation.
132      *
133      * @return the number
134      */
135     public int getProcessedPreceding() {
136         return processedPreceding;
137     }
138 
139     /***
140      * Returns the number of children elements in the parent element with
141      * the type (qualified name) of the represented element.
142      *
143      * @return the number
144      */
145     public int getTypedChildren() {
146         return typedChildren;
147     }
148 
149     /***
150      * Returns the position of the represented element in the parent
151      * element, counting only children with the same type (qualified name).
152      *
153      * @return the position
154      */
155     public int getTypedPosition() {
156         return typedPosition;
157     }
158 
159     /***
160      * Returns a string representation of this object.
161      *
162      * @return a textual representation
163      */
164     public String toString() {
165         return new ToStringBuilder(this)
166             .append("all child elements", allChildren)
167             .append("overall position", overallPosition)
168             .append("typed child elements", typedChildren)
169             .append("typed position", typedPosition)
170             .append("processed preceding siblings", processedPreceding)
171             .append("processed following siblings", processedFollowing)
172             .toString();
173     }
174 
175 }