001: /*
002: * Copyright (c) 2000-2001 Sosnoski Software Solutions, Inc.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
019: * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
020: * IN THE SOFTWARE.
021: */
022:
023: package com.sosnoski.xmlbench;
024:
025: /**
026: * Document summary information. This includes several count values
027: * characteristic of a document, allowing simple consistency checks across
028: * different representations of the document.
029: *
030: * @author Dennis M. Sosnoski
031: * @version 1.2
032: */
033:
034: public class DocumentSummary {
035: /** Number of elements. */
036: private int m_elementCount;
037:
038: /** Number of content text segments. */
039: private int m_contentCount;
040:
041: /** Number of attributes. */
042: private int m_attributeCount;
043:
044: /** Number of characters of content text. */
045: private int m_textCharCount;
046:
047: /** Number of characters of attribute data. */
048: private int m_attrCharCount;
049:
050: /**
051: * Reset count values.
052: */
053:
054: public void reset() {
055: m_elementCount = 0;
056: m_contentCount = 0;
057: m_attributeCount = 0;
058: m_textCharCount = 0;
059: m_attrCharCount = 0;
060: }
061:
062: /**
063: * Get element count.
064: *
065: * @return number of elements
066: */
067:
068: public int getElementCount() {
069: return m_elementCount;
070: }
071:
072: /**
073: * Get content segment count.
074: *
075: * @return number of content segments
076: */
077:
078: public int getContentCount() {
079: return m_contentCount;
080: }
081:
082: /**
083: * Get attribute count.
084: *
085: * @return number of attributes
086: */
087:
088: public int getAttributeCount() {
089: return m_attributeCount;
090: }
091:
092: /**
093: * Get text content character count.
094: *
095: * @return number of text characters
096: */
097:
098: public int getTextCharCount() {
099: return m_textCharCount;
100: }
101:
102: /**
103: * Get attribute value character count.
104: *
105: * @return number of attribute value characters
106: */
107:
108: public int getAttrCharCount() {
109: return m_attrCharCount;
110: }
111:
112: /**
113: * Add to element count.
114: *
115: * @param count value to be added to element count
116: */
117:
118: public void addElements(int count) {
119: m_elementCount += count;
120: }
121:
122: /**
123: * Count attribute. Increments the attribute count by one and adds the
124: * supplied character count to the attribute data length.
125: *
126: * @param length attribute value text length
127: */
128:
129: public void addAttribute(int length) {
130: m_attributeCount++;
131: m_attrCharCount += length;
132: }
133:
134: /**
135: * Count content text segment. Increments the content segment count by one
136: * and adds the supplied character count to the content text length.
137: *
138: * @param length attribute value text length
139: */
140:
141: public void addContent(int length) {
142: m_contentCount++;
143: m_textCharCount += length;
144: }
145:
146: /**
147: * Check if object is equal to this one.
148: *
149: * @param obj object to be compared
150: * @return <code>true</code> if the values match, <code>false</code>
151: * if not
152: */
153:
154: public boolean equals(Object obj) {
155: if (obj instanceof DocumentSummary) {
156: DocumentSummary comp = (DocumentSummary) obj;
157: return m_elementCount == comp.m_elementCount
158: && m_contentCount == comp.m_contentCount
159: && m_attributeCount == comp.m_attributeCount
160: && m_textCharCount == comp.m_textCharCount
161: && m_attrCharCount == comp.m_attrCharCount;
162: } else {
163: return false;
164: }
165: }
166:
167: /**
168: * Check if object structure is equal to this one. This comparison ignores
169: * the text content segment count and total character length, since that
170: * can be changed by output formatting.
171: *
172: * @param obj object to be compared
173: * @return <code>true</code> if the values match, <code>false</code>
174: * if not
175: */
176:
177: public boolean structureEquals(Object obj) {
178: if (obj instanceof DocumentSummary) {
179: DocumentSummary comp = (DocumentSummary) obj;
180: return m_elementCount == comp.m_elementCount
181: && m_attributeCount == comp.m_attributeCount
182: && m_attrCharCount == comp.m_attrCharCount;
183: } else {
184: return false;
185: }
186: }
187: }
|