You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

WrongObjectTypeException.java 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Copyright (C) 2021, Thomas Wolf <thomas.wolf@paranor.ch> 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.api.errors;
  11. import java.text.MessageFormat;
  12. import org.eclipse.jgit.internal.JGitText;
  13. import org.eclipse.jgit.lib.Constants;
  14. import org.eclipse.jgit.lib.ObjectId;
  15. /**
  16. * A given object is not of an expected object type.
  17. *
  18. * @since 5.11
  19. */
  20. public class WrongObjectTypeException extends GitAPIException {
  21. private static final long serialVersionUID = 1L;
  22. private String name;
  23. private int type;
  24. /**
  25. * Construct a {@link WrongObjectTypeException} for the specified object id,
  26. * giving the expected type.
  27. *
  28. * @param id
  29. * {@link ObjectId} of the object with the unexpected type
  30. * @param type
  31. * expected object type code; see
  32. * {@link Constants}{@code .OBJ_*}.
  33. */
  34. public WrongObjectTypeException(ObjectId id, int type) {
  35. super(MessageFormat.format(JGitText.get().objectIsNotA, id.name(),
  36. Constants.typeString(type)));
  37. this.name = id.name();
  38. this.type = type;
  39. }
  40. /**
  41. * Retrieves the name (SHA-1) of the object.
  42. *
  43. * @return the name
  44. */
  45. public String getObjectId() {
  46. return name;
  47. }
  48. /**
  49. * Retrieves the expected type code. See {@link Constants}{@code .OBJ_*}.
  50. *
  51. * @return the type code
  52. */
  53. public int getExpectedType() {
  54. return type;
  55. }
  56. }