RefLeaseSpec.java

  1. /*
  2.  * Copyright (C) 2017 Two Sigma Open Source 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.transport;

  11. import java.io.Serializable;

  12. /**
  13.  * Describes the expected value for a ref being pushed.
  14.  *
  15.  * @since 4.7
  16.  */
  17. public class RefLeaseSpec implements Serializable {
  18.     private static final long serialVersionUID = 1L;

  19.     /** Name of the ref whose value we want to check. */
  20.     private final String ref;

  21.     /** Local commitish to get expected value from. */
  22.     private final String expected;

  23.     /**
  24.      * <p>Constructor for RefLeaseSpec.</p>
  25.      *
  26.      * @param ref
  27.      *            ref being pushed
  28.      * @param expected
  29.      *            the expected value of the ref
  30.      */
  31.     public RefLeaseSpec(String ref, String expected) {
  32.         this.ref = ref;
  33.         this.expected = expected;
  34.     }

  35.     /**
  36.      * Get the ref to protect.
  37.      *
  38.      * @return name of ref to check.
  39.      */
  40.     public String getRef() {
  41.         return ref;
  42.     }

  43.     /**
  44.      * Get the expected value of the ref, in the form
  45.      * of a local committish
  46.      *
  47.      * @return expected ref value.
  48.      */
  49.     public String getExpected() {
  50.         return expected;
  51.     }

  52.     /** {@inheritDoc} */
  53.     @Override
  54.     public String toString() {
  55.         final StringBuilder r = new StringBuilder();
  56.         r.append(getRef());
  57.         r.append(':');
  58.         r.append(getExpected());
  59.         return r.toString();
  60.     }
  61. }