KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > corext > refactoring > nls > NLSLine


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.jdt.internal.corext.refactoring.nls;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.Iterator JavaDoc;
15 import java.util.List JavaDoc;
16
17 import org.eclipse.core.runtime.Assert;
18
19
20 public class NLSLine {
21
22     private int fLineNumber;
23     private List JavaDoc fElements;
24
25     public NLSLine(int lineNumber) {
26         fLineNumber= lineNumber;
27         Assert.isTrue(fLineNumber >= 0);
28         fElements= new ArrayList JavaDoc();
29     }
30     
31     public int getLineNumber() {
32         return fLineNumber;
33     }
34     
35     /**
36      * Adds a NLS element to this line.
37      */

38     public void add(NLSElement element) {
39         Assert.isNotNull(element);
40         fElements.add(element);
41     }
42     
43     public NLSElement[] getElements() {
44         return (NLSElement[]) fElements.toArray(new NLSElement[fElements.size()]);
45     }
46     
47     public NLSElement get(int index) {
48         return (NLSElement)fElements.get(index);
49     }
50     
51     public boolean exists(int index) {
52         return index >= 0 && index < fElements.size();
53     }
54     
55     public int size(){
56         return fElements.size();
57     }
58     
59     /* non javaDoc
60      * only for debugging
61      * @see Object#toString()
62      */

63     public String JavaDoc toString() {
64         StringBuffer JavaDoc result= new StringBuffer JavaDoc();
65         result.append("Line: " + fLineNumber + "\n"); //$NON-NLS-2$ //$NON-NLS-1$
66
for (Iterator JavaDoc iter= fElements.iterator(); iter.hasNext(); ) {
67             result.append("\t"); //$NON-NLS-1$
68
result.append(iter.next().toString());
69             result.append("\n"); //$NON-NLS-1$
70
}
71         return result.toString();
72     }
73 }
74
75
Popular Tags