Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: f9384de9f6dcab9de07467b4cf6d7eb5263efc6e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*******************************************************************************
 * Copyright (c) 2000, 2006 IBM Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.team.internal.ccvs.core;

import org.eclipse.osgi.util.NLS;

/**
 * Model for a CVS Annotate block.
 */
public class CVSAnnotateBlock {

	String revision = ""; //$NON-NLS-1$
	String user = ""; //$NON-NLS-1$
	int startLine = 0;
	int endLine = 0;
	int sourceOffset = 0;
	boolean valid = false;

	/**
	 * @return
	 */
	public boolean isValid() {
		return valid;
	}

	/**
	 * @return index of line where source starts.
	 */
	public int getSourceOffset() {
		return sourceOffset;
	}

	/**
	 * @return int the last source line of the receiver
	 */
	public int getEndLine() {
		return endLine;
	}

	/**
	 * @param line
	 */
	public void setEndLine(int line) {
		endLine = line;
	}

	/**
	 * @return the revision the receiver occured in.
	 */
	public String getRevision() {
		return revision;
	}

	/**
	 * @return the first source line number of the receiver
	 */
	public int getStartLine() {
		return startLine;
	}


	/**
	 * Parase a CVS Annotate output line and instantiate the receiver
	 * @param line a CVS Annotate output line
	 */
	public CVSAnnotateBlock(String line, int lineNumber) {
		super();
		
		startLine = lineNumber;
		endLine = lineNumber;
		
		int index = line.indexOf(' ');
		if (index == -1) {
			return;
		}
		revision = line.substring(0, index);
		
		index = line.indexOf("(", index); //$NON-NLS-1$
		if (index == -1) {
			return;
		}
		
		int index2 = line.indexOf(' ', index);
		if (index2 == -1) {
			return;
		}
		
		user = line.substring(index + 1, index2);
		
		index = line.indexOf(":", index2); //$NON-NLS-1$
		if (index == -1) {
			return;
		}
		
		sourceOffset = index + 2;
		valid = true;
	}

	/**
	 * Used by the default LabelProvider to display objects in a List View
	 */
	public String toString() {
		int delta = endLine - startLine + 1;
		String line = CVSMessages.CVSAnnotateBlock_4; 
		if (delta == 1) {
			line = CVSMessages.CVSAnnotateBlock_5; 
		}
		return NLS.bind(CVSMessages.CVSAnnotateBlock_6, (new Object[] { 
			user,
			revision,
			String.valueOf(delta),
			line
		}));
	}

	/**
	 * Answer true if the receiver contains the given line number, false otherwse.
	 * @param i a line number
	 * @return true if receiver contains a line number.
	 */
	public boolean contains(int i) {
		return (i >= startLine && i <= endLine);
	}
}

Back to the top