1 /*
2 * Copyright 2012-2025 CodeLibs Project and the Others.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13 * either express or implied. See the License for the specific language
14 * governing permissions and limitations under the License.
15 */
16 package org.codelibs.fess.util;
17
18 import java.util.ArrayList;
19 import java.util.Arrays;
20 import java.util.Map;
21
22 /**
23 * A specialized ArrayList for storing document data with additional metadata.
24 * This class extends ArrayList to hold document maps while tracking content size
25 * and processing time metrics. It's used throughout the Fess search system to
26 * manage collections of search results and crawled documents.
27 *
28 */
29 public class DocList extends ArrayList<Map<String, Object>> {
30
31 /** Serial version UID for serialization */
32 private static final long serialVersionUID = 1L;
33
34 /** Total content size of all documents in this list */
35 private long contentSize = 0;
36
37 /** Total processing time for all documents in this list */
38 private long processingTime = 0;
39
40 /**
41 * Default constructor for DocList.
42 * Creates a new empty document list with zero content size and processing time.
43 */
44 public DocList() {
45 super();
46 }
47
48 /**
49 * Clears all documents from the list and resets metrics.
50 * Removes all documents and resets content size and processing time to zero.
51 */
52 @Override
53 public void clear() {
54 super.clear();
55 contentSize = 0;
56 processingTime = 0;
57 }
58
59 /**
60 * Gets the total content size of all documents in this list.
61 *
62 * @return the total content size in bytes
63 */
64 public long getContentSize() {
65 return contentSize;
66 }
67
68 /**
69 * Adds to the total content size of this document list.
70 *
71 * @param contentSize the content size to add in bytes
72 */
73 public void addContentSize(final long contentSize) {
74 this.contentSize += contentSize;
75 }
76
77 /**
78 * Gets the total processing time for all documents in this list.
79 *
80 * @return the total processing time in milliseconds
81 */
82 public long getProcessingTime() {
83 return processingTime;
84 }
85
86 /**
87 * Adds to the total processing time of this document list.
88 *
89 * @param processingTime the processing time to add in milliseconds
90 */
91 public void addProcessingTime(final long processingTime) {
92 this.processingTime += processingTime;
93 }
94
95 /**
96 * Returns a string representation of this DocList including metrics and content.
97 *
98 * @return a string representation including content size, processing time, and elements
99 */
100 @Override
101 public String toString() {
102 return "DocList [contentSize=" + contentSize + ", processingTime=" + processingTime + ", elementData="
103 + Arrays.toString(toArray(new Map[size()])) + "]";
104 }
105
106 }