KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > core > CVSAnnotateBlock


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.team.internal.ccvs.core;
12
13 import org.eclipse.osgi.util.NLS;
14
15 /**
16  * Model for a CVS Annotate block.
17  */

18 public class CVSAnnotateBlock {
19
20     String JavaDoc revision = ""; //$NON-NLS-1$
21
String JavaDoc user = ""; //$NON-NLS-1$
22
int startLine = 0;
23     int endLine = 0;
24     int sourceOffset = 0;
25     boolean valid = false;
26
27     /**
28      * @return
29      */

30     public boolean isValid() {
31         return valid;
32     }
33
34     /**
35      * @return index of line where source starts.
36      */

37     public int getSourceOffset() {
38         return sourceOffset;
39     }
40
41     /**
42      * @return int the last source line of the receiver
43      */

44     public int getEndLine() {
45         return endLine;
46     }
47
48     /**
49      * @param line
50      */

51     public void setEndLine(int line) {
52         endLine = line;
53     }
54
55     /**
56      * @return the revision the receiver occured in.
57      */

58     public String JavaDoc getRevision() {
59         return revision;
60     }
61
62     /**
63      * @return the first source line number of the receiver
64      */

65     public int getStartLine() {
66         return startLine;
67     }
68
69
70     /**
71      * Parase a CVS Annotate output line and instantiate the receiver
72      * @param line a CVS Annotate output line
73      */

74     public CVSAnnotateBlock(String JavaDoc line, int lineNumber) {
75         super();
76         
77         startLine = lineNumber;
78         endLine = lineNumber;
79         
80         int index = line.indexOf(' ');
81         if (index == -1) {
82             return;
83         }
84         revision = line.substring(0, index);
85         
86         index = line.indexOf("(", index); //$NON-NLS-1$
87
if (index == -1) {
88             return;
89         }
90         
91         int index2 = line.indexOf(' ', index);
92         if (index2 == -1) {
93             return;
94         }
95         
96         user = line.substring(index + 1, index2);
97         
98         index = line.indexOf(":", index2); //$NON-NLS-1$
99
if (index == -1) {
100             return;
101         }
102         
103         sourceOffset = index + 2;
104         valid = true;
105     }
106
107     /**
108      * Used by the default LabelProvider to display objects in a List View
109      */

110     public String JavaDoc toString() {
111         int delta = endLine - startLine + 1;
112         String JavaDoc line = CVSMessages.CVSAnnotateBlock_4;
113         if (delta == 1) {
114             line = CVSMessages.CVSAnnotateBlock_5;
115         }
116         return NLS.bind(CVSMessages.CVSAnnotateBlock_6, (new Object JavaDoc[] {
117             user,
118             revision,
119             String.valueOf(delta),
120             line
121         }));
122     }
123
124     /**
125      * Answer true if the receiver contains the given line number, false otherwse.
126      * @param i a line number
127      * @return true if receiver contains a line number.
128      */

129     public boolean contains(int i) {
130         return (i >= startLine && i <= endLine);
131     }
132 }
133
Popular Tags