View Javadoc
1   /*
2    * Copyright (C) 2010, 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.errors;
12  
13  import java.io.IOException;
14  import java.text.MessageFormat;
15  import java.util.Collection;
16  
17  import org.eclipse.jgit.internal.JGitText;
18  import org.eclipse.jgit.lib.AbbreviatedObjectId;
19  import org.eclipse.jgit.lib.ObjectId;
20  
21  /**
22   * An {@link org.eclipse.jgit.lib.AbbreviatedObjectId} cannot be extended.
23   */
24  public class AmbiguousObjectException extends IOException {
25  	private static final long serialVersionUID = 1L;
26  
27  	private final AbbreviatedObjectId missing;
28  
29  	private final Collection<ObjectId> candidates;
30  
31  	/**
32  	 * Construct a MissingObjectException for the specified object id. Expected
33  	 * type is reported to simplify tracking down the problem.
34  	 *
35  	 * @param id
36  	 *            SHA-1
37  	 * @param candidates
38  	 *            the candidate matches returned by the ObjectReader.
39  	 */
40  	public AmbiguousObjectException(final AbbreviatedObjectId id,
41  			final Collection<ObjectId> candidates) {
42  		super(MessageFormat.format(JGitText.get().ambiguousObjectAbbreviation,
43  				id.name()));
44  		this.missing = id;
45  		this.candidates = candidates;
46  	}
47  
48  	/**
49  	 * Get the {@code AbbreviatedObjectId} that has more than one result
50  	 *
51  	 * @return the {@code AbbreviatedObjectId} that has more than one result
52  	 */
53  	public AbbreviatedObjectId getAbbreviatedObjectId() {
54  		return missing;
55  	}
56  
57  	/**
58  	 * Get the matching candidates (or at least a subset of them)
59  	 *
60  	 * @return the matching candidates (or at least a subset of them)
61  	 */
62  	public Collection<ObjectId> getCandidates() {
63  		return candidates;
64  	}
65  }