View Javadoc
1   /*
2    * Copyright (c) 2020, Google LLC 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    * http://www.eclipse.org/org/documents/edl-v10.php.
7    *
8    * SPDX-License-Identifier: BSD-3-Clause
9    */
10  package org.eclipse.jgit.internal.storage.pack;
11  
12  import org.eclipse.jgit.lib.AnyObjectId;
13  import org.eclipse.jgit.lib.ObjectId;
14  
15  /**
16   * A commit object for which a bitmap index should be built.
17   */
18  public final class BitmapCommit extends ObjectId {
19  
20  	private final boolean reuseWalker;
21  
22  	private final int flags;
23  
24  	private final boolean addToIndex;
25  
26  	BitmapCommit(AnyObjectId objectId, boolean reuseWalker, int flags) {
27  		super(objectId);
28  		this.reuseWalker = reuseWalker;
29  		this.flags = flags;
30  		this.addToIndex = false;
31  	}
32  
33  	BitmapCommit(AnyObjectId objectId, boolean reuseWalker, int flags,
34  				 boolean addToIndex) {
35  		super(objectId);
36  		this.reuseWalker = reuseWalker;
37  		this.flags = flags;
38  		this.addToIndex = addToIndex;
39  	}
40  
41  	boolean isReuseWalker() {
42  		return reuseWalker;
43  	}
44  
45  	int getFlags() {
46  		return flags;
47  	}
48  
49  	/**
50  	 * Whether corresponding bitmap should be added to PackBitmapIndexBuilder.
51  	 *
52  	 * @return true if the corresponding bitmap should be added to
53  	 *         PackBitmapIndexBuilder.
54  	 */
55  	public boolean isAddToIndex() {
56  		return addToIndex;
57  	}
58  
59  	/**
60  	 * Get a builder of BitmapCommit whose object id is {@code objId}.
61  	 *
62  	 * @param objId
63  	 *            the object id of the BitmapCommit
64  	 * @return a BitmapCommit builder with object id set.
65  	 */
66  	public static Builder newBuilder(AnyObjectId objId) {
67  		return new Builder().setId(objId);
68  	}
69  
70  	/**
71  	 * Get a builder of BitmapCommit whose fields are copied from
72  	 * {@code commit}.
73  	 *
74  	 * @param commit
75  	 *            the bitmap commit the builder is copying from
76  	 * @return a BitmapCommit build with fields copied from an existing bitmap
77  	 *         commit.
78  	 */
79  	public static Builder copyFrom(BitmapCommit commit) {
80  		return new Builder().setId(commit)
81  				.setReuseWalker(commit.isReuseWalker())
82  				.setFlags(commit.getFlags())
83  				.setAddToIndex(commit.isAddToIndex());
84  	}
85  
86  	/**
87  	 * Builder of BitmapCommit.
88  	 */
89  	public static class Builder {
90  		private AnyObjectId objectId;
91  
92  		private boolean reuseWalker;
93  
94  		private int flags;
95  
96  		private boolean addToIndex;
97  
98  		// Prevent default constructor.
99  		private Builder() {
100 		}
101 
102 		/**
103 		 * Set objectId of the builder.
104 		 *
105 		 * @param objectId
106 		 *            the object id of the BitmapCommit
107 		 * @return the builder itself
108 		 */
109 		public Builder setId(AnyObjectId objectId) {
110 			this.objectId = objectId;
111 			return this;
112 		}
113 
114 		/**
115 		 * Set reuseWalker of the builder.
116 		 *
117 		 * @param reuseWalker
118 		 *            whether the BitmapCommit should reuse bitmap walker when
119 		 *            walking objects
120 		 * @return the builder itself
121 		 */
122 		public Builder setReuseWalker(boolean reuseWalker) {
123 			this.reuseWalker = reuseWalker;
124 			return this;
125 		}
126 
127 		/**
128 		 * Set flags of the builder.
129 		 *
130 		 * @param flags
131 		 *            the flags of the BitmapCommit
132 		 * @return the builder itself
133 		 */
134 		public Builder setFlags(int flags) {
135 			this.flags = flags;
136 			return this;
137 		}
138 
139 		/**
140 		 * Set whether whether the bitmap of the BitmapCommit should be added to
141 		 * PackBitmapIndexBuilder when building bitmap index file.
142 		 *
143 		 * @param addToIndex
144 		 *            whether the bitmap of the BitmapCommit should be added to
145 		 *            PackBitmapIndexBuilder when building bitmap index file
146 		 * @return the builder itself
147 		 */
148 		public Builder setAddToIndex(boolean addToIndex) {
149 			this.addToIndex = addToIndex;
150 			return this;
151 		}
152 
153 		/**
154 		 * Builds BitmapCommit from the builder.
155 		 *
156 		 * @return the new BitmapCommit.
157 		 */
158 		public BitmapCommit build() {
159 			return new BitmapCommit(objectId, reuseWalker, flags,
160 					addToIndex);
161 		}
162 	}
163 }