aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src/org/eclipse/jgit/lib/AbbreviatedObjectId.java
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/lib/AbbreviatedObjectId.java')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/AbbreviatedObjectId.java103
1 files changed, 46 insertions, 57 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/AbbreviatedObjectId.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/AbbreviatedObjectId.java
index 29a379e4a6..a13136b9f1 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/AbbreviatedObjectId.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/AbbreviatedObjectId.java
@@ -1,44 +1,11 @@
/*
- * Copyright (C) 2008-2009, Google Inc.
- * and other copyright owners as documented in the project's IP log.
+ * Copyright (C) 2008-2009, Google Inc. and others
*
- * This program and the accompanying materials are made available
- * under the terms of the Eclipse Distribution License v1.0 which
- * accompanies this distribution, is reproduced below, and is
- * available at http://www.eclipse.org/org/documents/edl-v10.php
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Distribution License v. 1.0 which is available at
+ * https://www.eclipse.org/org/documents/edl-v10.php.
*
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or
- * without modification, are permitted provided that the following
- * conditions are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following
- * disclaimer in the documentation and/or other materials provided
- * with the distribution.
- *
- * - Neither the name of the Eclipse Foundation, Inc. nor the
- * names of its contributors may be used to endorse or promote
- * products derived from this software without specific prior
- * written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
- * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * SPDX-License-Identifier: BSD-3-Clause
*/
package org.eclipse.jgit.lib;
@@ -52,7 +19,7 @@ import org.eclipse.jgit.util.NB;
import org.eclipse.jgit.util.RawParseUtils;
/**
- * A prefix abbreviation of an {@link ObjectId}.
+ * A prefix abbreviation of an {@link org.eclipse.jgit.lib.ObjectId}.
* <p>
* Sometimes Git produces abbreviated SHA-1 strings, using sufficient leading
* digits from the ObjectId name to still be unique within the repository the
@@ -74,7 +41,7 @@ public final class AbbreviatedObjectId implements Serializable {
* the string to test.
* @return true if the string can converted into an AbbreviatedObjectId.
*/
- public static final boolean isId(final String id) {
+ public static final boolean isId(String id) {
if (id.length() < 2 || Constants.OBJECT_ID_STRING_LENGTH < id.length())
return false;
try {
@@ -109,13 +76,14 @@ public final class AbbreviatedObjectId implements Serializable {
}
/**
- * Convert an AbbreviatedObjectId from an {@link AnyObjectId}.
+ * Convert an AbbreviatedObjectId from an
+ * {@link org.eclipse.jgit.lib.AnyObjectId}.
* <p>
* This method copies over all bits of the Id, and is therefore complete
* (see {@link #isComplete()}).
*
* @param id
- * the {@link ObjectId} to convert from.
+ * the {@link org.eclipse.jgit.lib.ObjectId} to convert from.
* @return the converted object id.
*/
public static final AbbreviatedObjectId fromObjectId(AnyObjectId id) {
@@ -130,7 +98,7 @@ public final class AbbreviatedObjectId implements Serializable {
* the string to read from. Must be &lt;= 40 characters.
* @return the converted object id.
*/
- public static final AbbreviatedObjectId fromString(final String str) {
+ public static final AbbreviatedObjectId fromString(String str) {
if (str.length() > Constants.OBJECT_ID_STRING_LENGTH)
throw new IllegalArgumentException(MessageFormat.format(JGitText.get().invalidId, str));
final byte[] b = Constants.encodeASCII(str);
@@ -146,8 +114,11 @@ public final class AbbreviatedObjectId implements Serializable {
final int d = hexUInt32(bs, ptr + 24, end);
final int e = hexUInt32(bs, ptr + 32, end);
return new AbbreviatedObjectId(end - ptr, a, b, c, d, e);
- } catch (ArrayIndexOutOfBoundsException e1) {
- throw new InvalidObjectIdException(bs, ptr, end - ptr);
+ } catch (ArrayIndexOutOfBoundsException e) {
+ InvalidObjectIdException e1 = new InvalidObjectIdException(bs, ptr,
+ end - ptr);
+ e1.initCause(e);
+ throw e1;
}
}
@@ -161,10 +132,10 @@ public final class AbbreviatedObjectId implements Serializable {
r |= RawParseUtils.parseHexInt4(bs[p++]);
n++;
}
- return r << (8 - n) * 4;
+ return r << ((8 - n) * 4);
}
- static int mask(final int nibbles, final int word, final int v) {
+ static int mask(int nibbles, int word, int v) {
final int b = (word - 1) * 8;
if (b + 8 <= nibbles) {
// We have all of the bits required for this word.
@@ -205,17 +176,29 @@ public final class AbbreviatedObjectId implements Serializable {
w5 = new_5;
}
- /** @return number of hex digits appearing in this id */
+ /**
+ * Get number of hex digits appearing in this id.
+ *
+ * @return number of hex digits appearing in this id.
+ */
public int length() {
return nibbles;
}
- /** @return true if this ObjectId is actually a complete id. */
+ /**
+ * Whether this ObjectId is actually a complete id.
+ *
+ * @return true if this ObjectId is actually a complete id.
+ */
public boolean isComplete() {
return length() == Constants.OBJECT_ID_STRING_LENGTH;
}
- /** @return a complete ObjectId; null if {@link #isComplete()} is false */
+ /**
+ * A complete ObjectId; null if {@link #isComplete()} is false
+ *
+ * @return a complete ObjectId; null if {@link #isComplete()} is false
+ */
public ObjectId toObjectId() {
return isComplete() ? new ObjectId(w1, w2, w3, w4, w5) : null;
}
@@ -231,7 +214,7 @@ public final class AbbreviatedObjectId implements Serializable {
* &gt;0 if this abbreviation names an object that is after
* <code>other</code>.
*/
- public final int prefixCompare(final AnyObjectId other) {
+ public final int prefixCompare(AnyObjectId other) {
int cmp;
cmp = NB.compareUInt32(w1, mask(1, other.w1));
@@ -267,7 +250,7 @@ public final class AbbreviatedObjectId implements Serializable {
* &gt;0 if this abbreviation names an object that is after
* <code>other</code>.
*/
- public final int prefixCompare(final byte[] bs, final int p) {
+ public final int prefixCompare(byte[] bs, int p) {
int cmp;
cmp = NB.compareUInt32(w1, mask(1, NB.decodeInt32(bs, p)));
@@ -303,7 +286,7 @@ public final class AbbreviatedObjectId implements Serializable {
* &gt;0 if this abbreviation names an object that is after
* <code>other</code>.
*/
- public final int prefixCompare(final int[] bs, final int p) {
+ public final int prefixCompare(int[] bs, int p) {
int cmp;
cmp = NB.compareUInt32(w1, mask(1, bs[p]));
@@ -325,22 +308,26 @@ public final class AbbreviatedObjectId implements Serializable {
return NB.compareUInt32(w5, mask(5, bs[p + 4]));
}
- /** @return value for a fan-out style map, only valid of length &gt;= 2. */
+ /**
+ * Get value for a fan-out style map, only valid of length &gt;= 2.
+ *
+ * @return value for a fan-out style map, only valid of length &gt;= 2.
+ */
public final int getFirstByte() {
return w1 >>> 24;
}
- private int mask(final int word, final int v) {
+ private int mask(int word, int v) {
return mask(nibbles, word, v);
}
@Override
public int hashCode() {
- return w2;
+ return w1;
}
@Override
- public boolean equals(final Object o) {
+ public boolean equals(Object o) {
if (o instanceof AbbreviatedObjectId) {
final AbbreviatedObjectId b = (AbbreviatedObjectId) o;
return nibbles == b.nibbles && w1 == b.w1 && w2 == b.w2
@@ -350,6 +337,8 @@ public final class AbbreviatedObjectId implements Serializable {
}
/**
+ * Get string form of the abbreviation, in lower case hexadecimal.
+ *
* @return string form of the abbreviation, in lower case hexadecimal.
*/
public final String name() {