View Javadoc
1   /*
2    * Copyright (C) 2013, 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.internal.storage.pack;
12  
13  /**
14   * A pack file extension.
15   */
16  public enum PackExt {
17  	/** A pack file extension. */
18  	PACK("pack"), //$NON-NLS-1$
19  
20  	/** A pack index file extension. */
21  	INDEX("idx"), //$NON-NLS-1$
22  
23  	/** A keep pack file extension. */
24  	KEEP("keep"), //$NON-NLS-1$
25  
26  	/** A pack bitmap index file extension. */
27  	BITMAP_INDEX("bitmap"), //$NON-NLS-1$
28  
29  	/** A reftable file. */
30  	REFTABLE("ref"); //$NON-NLS-1$
31  
32  	private final String ext;
33  
34  	private PackExt(String ext) {
35  		this.ext = ext;
36  	}
37  
38  	/**
39  	 * Get the file extension.
40  	 *
41  	 * @return the file extension.
42  	 */
43  	public String getExtension() {
44  		return ext;
45  	}
46  
47  	/**
48  	 * Get the position of the extension in the enum declaration.
49  	 *
50  	 * @return the position of the extension in the enum declaration.
51  	 */
52  	public int getPosition() {
53  		return ordinal();
54  	}
55  
56  	/**
57  	 * Get the bit mask of the extension e.g {@code 1 << getPosition()}.
58  	 *
59  	 * @return the bit mask of the extension e.g {@code 1 << getPosition()}.
60  	 */
61  	public int getBit() {
62  		return 1 << getPosition();
63  	}
64  
65  	/** {@inheritDoc} */
66  	@Override
67  	public String toString() {
68  		return String.format("PackExt[%s, bit=0x%s]", getExtension(), //$NON-NLS-1$
69  				Integer.toHexString(getBit()));
70  	}
71  }