View Javadoc
1   /*
2    * Copyright (C) 2016, Google Inc. and others
3    *
4    * This program and the accompanying materials are made available under the
5    * terms of the Eclipse Distribution License v. 1.0 which is available at
6    * https://www.eclipse.org/org/documents/edl-v10.php.
7    *
8    * SPDX-License-Identifier: BSD-3-Clause
9    */
10  
11  package org.eclipse.jgit.transport;
12  
13  import org.eclipse.jgit.lib.Constants;
14  
15  /**
16   * Statistics about {@link org.eclipse.jgit.transport.PackParser}.
17   *
18   * @since 4.6
19   */
20  public class ReceivedPackStatistics {
21  	private long numBytesRead;
22  
23  	private long numWholeCommit;
24  	private long numWholeTree;
25  	private long numWholeBlob;
26  	private long numWholeTag;
27  	private long numOfsDelta;
28  	private long numRefDelta;
29  
30  	private long numDeltaCommit;
31  	private long numDeltaTree;
32  	private long numDeltaBlob;
33  	private long numDeltaTag;
34  
35  	/**
36  	 * Get number of bytes read from the input stream
37  	 *
38  	 * @return number of bytes read from the input stream
39  	 */
40  	public long getNumBytesRead() {
41  		return numBytesRead;
42  	}
43  
44  	/**
45  	 * Get number of whole commit objects in the pack
46  	 *
47  	 * @return number of whole commit objects in the pack
48  	 */
49  	public long getNumWholeCommit() {
50  		return numWholeCommit;
51  	}
52  
53  	/**
54  	 * Get number of whole tree objects in the pack
55  	 *
56  	 * @return number of whole tree objects in the pack
57  	 */
58  	public long getNumWholeTree() {
59  		return numWholeTree;
60  	}
61  
62  	/**
63  	 * Get number of whole blob objects in the pack
64  	 *
65  	 * @return number of whole blob objects in the pack
66  	 */
67  	public long getNumWholeBlob() {
68  		return numWholeBlob;
69  	}
70  
71  	/**
72  	 * Get number of whole tag objects in the pack
73  	 *
74  	 * @return number of whole tag objects in the pack
75  	 */
76  	public long getNumWholeTag() {
77  		return numWholeTag;
78  	}
79  
80  	/**
81  	 * Get number of offset delta objects in the pack
82  	 *
83  	 * @return number of offset delta objects in the pack
84  	 */
85  	public long getNumOfsDelta() {
86  		return numOfsDelta;
87  	}
88  
89  	/**
90  	 * Get number of ref delta objects in the pack
91  	 *
92  	 * @return number of ref delta objects in the pack
93  	 */
94  	public long getNumRefDelta() {
95  		return numRefDelta;
96  	}
97  
98  	/**
99  	 * Get number of delta commit objects in the pack
100 	 *
101 	 * @return number of delta commit objects in the pack
102 	 */
103 	public long getNumDeltaCommit() {
104 		return numDeltaCommit;
105 	}
106 
107 	/**
108 	 * Get number of delta tree objects in the pack
109 	 *
110 	 * @return number of delta tree objects in the pack
111 	 */
112 	public long getNumDeltaTree() {
113 		return numDeltaTree;
114 	}
115 
116 	/**
117 	 * Get number of delta blob objects in the pack
118 	 *
119 	 * @return number of delta blob objects in the pack
120 	 */
121 	public long getNumDeltaBlob() {
122 		return numDeltaBlob;
123 	}
124 
125 	/**
126 	 * Get number of delta tag objects in the pack
127 	 *
128 	 * @return number of delta tag objects in the pack
129 	 */
130 	public long getNumDeltaTag() {
131 		return numDeltaTag;
132 	}
133 
134 	/** A builder for {@link ReceivedPackStatistics}. */
135 	public static class Builder {
136 		private long numBytesRead;
137 
138 		private long numWholeCommit;
139 		private long numWholeTree;
140 		private long numWholeBlob;
141 		private long numWholeTag;
142 		private long numOfsDelta;
143 		private long numRefDelta;
144 
145 		private long numDeltaCommit;
146 		private long numDeltaTree;
147 		private long numDeltaBlob;
148 		private long numDeltaTag;
149 
150 		/**
151 		 * @param numBytesRead number of bytes read from the input stream
152 		 * @return this
153 		 */
154 		public Builder setNumBytesRead(long numBytesRead) {
155 			this.numBytesRead = numBytesRead;
156 			return this;
157 		}
158 
159 		/**
160 		 * Increment a whole object count.
161 		 *
162 		 * @param type OBJ_COMMIT, OBJ_TREE, OBJ_BLOB, or OBJ_TAG
163 		 * @return this
164 		 */
165 		public Builder addWholeObject(int type) {
166 			switch (type) {
167 				case Constants.OBJ_COMMIT:
168 					numWholeCommit++;
169 					break;
170 				case Constants.OBJ_TREE:
171 					numWholeTree++;
172 					break;
173 				case Constants.OBJ_BLOB:
174 					numWholeBlob++;
175 					break;
176 				case Constants.OBJ_TAG:
177 					numWholeTag++;
178 					break;
179 				default:
180 					throw new IllegalArgumentException(
181 							type + " cannot be a whole object"); //$NON-NLS-1$
182 			}
183 			return this;
184 		}
185 
186 		/** @return this */
187 		public Builder addOffsetDelta() {
188 			numOfsDelta++;
189 			return this;
190 		}
191 
192 		/** @return this */
193 		public Builder addRefDelta() {
194 			numRefDelta++;
195 			return this;
196 		}
197 
198 		/**
199 		 * Increment a delta object count.
200 		 *
201 		 * @param type OBJ_COMMIT, OBJ_TREE, OBJ_BLOB, or OBJ_TAG
202 		 * @return this
203 		 */
204 		public Builder addDeltaObject(int type) {
205 			switch (type) {
206 				case Constants.OBJ_COMMIT:
207 					numDeltaCommit++;
208 					break;
209 				case Constants.OBJ_TREE:
210 					numDeltaTree++;
211 					break;
212 				case Constants.OBJ_BLOB:
213 					numDeltaBlob++;
214 					break;
215 				case Constants.OBJ_TAG:
216 					numDeltaTag++;
217 					break;
218 				default:
219 					throw new IllegalArgumentException(
220 							"delta should be a delta to a whole object. " + //$NON-NLS-1$
221 							type + " cannot be a whole object"); //$NON-NLS-1$
222 			}
223 			return this;
224 		}
225 
226 		ReceivedPackStatistics build() {
227 			ReceivedPackStatistics s = new ReceivedPackStatistics();
228 			s.numBytesRead = numBytesRead;
229 			s.numWholeCommit = numWholeCommit;
230 			s.numWholeTree = numWholeTree;
231 			s.numWholeBlob = numWholeBlob;
232 			s.numWholeTag = numWholeTag;
233 			s.numOfsDelta = numOfsDelta;
234 			s.numRefDelta = numRefDelta;
235 			s.numDeltaCommit = numDeltaCommit;
236 			s.numDeltaTree = numDeltaTree;
237 			s.numDeltaBlob = numDeltaBlob;
238 			s.numDeltaTag = numDeltaTag;
239 			return s;
240 		}
241 	}
242 }