AmbiguousObjectException.java

  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. package org.eclipse.jgit.errors;

  11. import java.io.IOException;
  12. import java.text.MessageFormat;
  13. import java.util.Collection;

  14. import org.eclipse.jgit.internal.JGitText;
  15. import org.eclipse.jgit.lib.AbbreviatedObjectId;
  16. import org.eclipse.jgit.lib.ObjectId;

  17. /**
  18.  * An {@link org.eclipse.jgit.lib.AbbreviatedObjectId} cannot be extended.
  19.  */
  20. public class AmbiguousObjectException extends IOException {
  21.     private static final long serialVersionUID = 1L;

  22.     private final AbbreviatedObjectId missing;

  23.     private final Collection<ObjectId> candidates;

  24.     /**
  25.      * Construct a MissingObjectException for the specified object id. Expected
  26.      * type is reported to simplify tracking down the problem.
  27.      *
  28.      * @param id
  29.      *            SHA-1
  30.      * @param candidates
  31.      *            the candidate matches returned by the ObjectReader.
  32.      */
  33.     public AmbiguousObjectException(final AbbreviatedObjectId id,
  34.             final Collection<ObjectId> candidates) {
  35.         super(MessageFormat.format(JGitText.get().ambiguousObjectAbbreviation,
  36.                 id.name()));
  37.         this.missing = id;
  38.         this.candidates = candidates;
  39.     }

  40.     /**
  41.      * Get the {@code AbbreviatedObjectId} that has more than one result
  42.      *
  43.      * @return the {@code AbbreviatedObjectId} that has more than one result
  44.      */
  45.     public AbbreviatedObjectId getAbbreviatedObjectId() {
  46.         return missing;
  47.     }

  48.     /**
  49.      * Get the matching candidates (or at least a subset of them)
  50.      *
  51.      * @return the matching candidates (or at least a subset of them)
  52.      */
  53.     public Collection<ObjectId> getCandidates() {
  54.         return candidates;
  55.     }
  56. }