View Javadoc
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  
12  package org.eclipse.jgit.merge;
13  
14  /**
15   * One chunk from a merge result. Each chunk contains a range from a
16   * single sequence. In case of conflicts multiple chunks are reported for one
17   * conflict. The conflictState tells when conflicts start and end.
18   */
19  public class MergeChunk {
20  	/**
21  	 * A state telling whether a MergeChunk belongs to a conflict or not. The
22  	 * first chunk of a conflict is reported with a special state to be able to
23  	 * distinguish the border between two consecutive conflicts
24  	 */
25  	public enum ConflictState {
26  		/**
27  		 * This chunk does not belong to a conflict
28  		 */
29  		NO_CONFLICT,
30  
31  		/**
32  		 * This chunk does belong to a conflict and is the first one of the
33  		 * conflicting chunks
34  		 */
35  		FIRST_CONFLICTING_RANGE,
36  
37  		/**
38  		 * This chunk does belong to a conflict but is not the first one of the
39  		 * conflicting chunks. It's a subsequent one.
40  		 */
41  		NEXT_CONFLICTING_RANGE
42  	}
43  
44  	private final int sequenceIndex;
45  
46  	private final int begin;
47  
48  	private final int end;
49  
50  	private final ConflictState conflictState;
51  
52  	/**
53  	 * Creates a new empty MergeChunk
54  	 *
55  	 * @param sequenceIndex
56  	 *            determines to which sequence this chunks belongs to. Same as
57  	 *            in {@link org.eclipse.jgit.merge.MergeResult#add}
58  	 * @param begin
59  	 *            the first element from the specified sequence which should be
60  	 *            included in the merge result. Indexes start with 0.
61  	 * @param end
62  	 *            specifies the end of the range to be added. The element this
63  	 *            index points to is the first element which not added to the
64  	 *            merge result. All elements between begin (including begin) and
65  	 *            this element are added.
66  	 * @param conflictState
67  	 *            the state of this chunk. See
68  	 *            {@link org.eclipse.jgit.merge.MergeChunk.ConflictState}
69  	 */
70  	protected MergeChunk(int sequenceIndex, int begin, int end,
71  			ConflictState conflictState) {
72  		this.sequenceIndex = sequenceIndex;
73  		this.begin = begin;
74  		this.end = end;
75  		this.conflictState = conflictState;
76  	}
77  
78  	/**
79  	 * Get the index of the sequence to which this sequence chunks belongs to.
80  	 *
81  	 * @return the index of the sequence to which this sequence chunks belongs
82  	 *         to. Same as in {@link org.eclipse.jgit.merge.MergeResult#add}
83  	 */
84  	public int getSequenceIndex() {
85  		return sequenceIndex;
86  	}
87  
88  	/**
89  	 * Get the first element from the specified sequence which should be
90  	 * included in the merge result.
91  	 *
92  	 * @return the first element from the specified sequence which should be
93  	 *         included in the merge result. Indexes start with 0.
94  	 */
95  	public int getBegin() {
96  		return begin;
97  	}
98  
99  	/**
100 	 * Get the end of the range of this chunk.
101 	 *
102 	 * @return the end of the range of this chunk. The element this index points
103 	 *         to is the first element which not added to the merge result. All
104 	 *         elements between begin (including begin) and this element are
105 	 *         added.
106 	 */
107 	public int getEnd() {
108 		return end;
109 	}
110 
111 	/**
112 	 * Get the state of this chunk.
113 	 *
114 	 * @return the state of this chunk. See
115 	 *         {@link org.eclipse.jgit.merge.MergeChunk.ConflictState}
116 	 */
117 	public ConflictState getConflictState() {
118 		return conflictState;
119 	}
120 }