MergeChunk.java

  1. /*
  2.  * Copyright (C) 2009, Christian Halstrick <christian.halstrick@sap.com>
  3.  * Copyright (C) 2010, Google Inc. and others
  4.  *
  5.  * This program and the accompanying materials are made available under the
  6.  * terms of the Eclipse Distribution License v. 1.0 which is available at
  7.  * https://www.eclipse.org/org/documents/edl-v10.php.
  8.  *
  9.  * SPDX-License-Identifier: BSD-3-Clause
  10.  */

  11. package org.eclipse.jgit.merge;

  12. /**
  13.  * One chunk from a merge result. Each chunk contains a range from a
  14.  * single sequence. In case of conflicts multiple chunks are reported for one
  15.  * conflict. The conflictState tells when conflicts start and end.
  16.  */
  17. public class MergeChunk {
  18.     /**
  19.      * A state telling whether a MergeChunk belongs to a conflict or not. The
  20.      * first chunk of a conflict is reported with a special state to be able to
  21.      * distinguish the border between two consecutive conflicts
  22.      */
  23.     public enum ConflictState {
  24.         /**
  25.          * This chunk does not belong to a conflict
  26.          */
  27.         NO_CONFLICT,

  28.         /**
  29.          * This chunk does belong to a conflict and is the first one of the
  30.          * conflicting chunks
  31.          */
  32.         FIRST_CONFLICTING_RANGE,

  33.         /**
  34.          * This chunk does belong to a conflict but is not the first one of the
  35.          * conflicting chunks. It's a subsequent one.
  36.          */
  37.         NEXT_CONFLICTING_RANGE
  38.     }

  39.     private final int sequenceIndex;

  40.     private final int begin;

  41.     private final int end;

  42.     private final ConflictState conflictState;

  43.     /**
  44.      * Creates a new empty MergeChunk
  45.      *
  46.      * @param sequenceIndex
  47.      *            determines to which sequence this chunks belongs to. Same as
  48.      *            in {@link org.eclipse.jgit.merge.MergeResult#add}
  49.      * @param begin
  50.      *            the first element from the specified sequence which should be
  51.      *            included in the merge result. Indexes start with 0.
  52.      * @param end
  53.      *            specifies the end of the range to be added. The element this
  54.      *            index points to is the first element which not added to the
  55.      *            merge result. All elements between begin (including begin) and
  56.      *            this element are added.
  57.      * @param conflictState
  58.      *            the state of this chunk. See
  59.      *            {@link org.eclipse.jgit.merge.MergeChunk.ConflictState}
  60.      */
  61.     protected MergeChunk(int sequenceIndex, int begin, int end,
  62.             ConflictState conflictState) {
  63.         this.sequenceIndex = sequenceIndex;
  64.         this.begin = begin;
  65.         this.end = end;
  66.         this.conflictState = conflictState;
  67.     }

  68.     /**
  69.      * Get the index of the sequence to which this sequence chunks belongs to.
  70.      *
  71.      * @return the index of the sequence to which this sequence chunks belongs
  72.      *         to. Same as in {@link org.eclipse.jgit.merge.MergeResult#add}
  73.      */
  74.     public int getSequenceIndex() {
  75.         return sequenceIndex;
  76.     }

  77.     /**
  78.      * Get the first element from the specified sequence which should be
  79.      * included in the merge result.
  80.      *
  81.      * @return the first element from the specified sequence which should be
  82.      *         included in the merge result. Indexes start with 0.
  83.      */
  84.     public int getBegin() {
  85.         return begin;
  86.     }

  87.     /**
  88.      * Get the end of the range of this chunk.
  89.      *
  90.      * @return the end of the range of this chunk. The element this index points
  91.      *         to is the first element which not added to the merge result. All
  92.      *         elements between begin (including begin) and this element are
  93.      *         added.
  94.      */
  95.     public int getEnd() {
  96.         return end;
  97.     }

  98.     /**
  99.      * Get the state of this chunk.
  100.      *
  101.      * @return the state of this chunk. See
  102.      *         {@link org.eclipse.jgit.merge.MergeChunk.ConflictState}
  103.      */
  104.     public ConflictState getConflictState() {
  105.         return conflictState;
  106.     }
  107. }