KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > compare > internal > DocumentManager


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.compare.internal;
12
13 import java.util.ArrayList JavaDoc;
14
15 import org.eclipse.jface.text.IDocument;
16
17 /**
18  * No API yet.
19  */

20 public class DocumentManager {
21     
22     private static final boolean DEBUG= false;
23     
24     private static ArrayList JavaDoc fgKeys= new ArrayList JavaDoc();
25     private static ArrayList JavaDoc fgValues= new ArrayList JavaDoc();
26     
27     public static IDocument get(Object JavaDoc o) {
28         
29         for (int i= 0; i < fgKeys.size(); i++) {
30             if (fgKeys.get(i) == o)
31                 return (IDocument) fgValues.get(i);
32         }
33         return null;
34     }
35     
36     public static void put(Object JavaDoc o, IDocument document) {
37         if (DEBUG) System.out.println("DocumentManager.put: " + document); //$NON-NLS-1$
38
for (int i= 0; i < fgKeys.size(); i++) {
39             if (fgKeys.get(i) == o) {
40                 fgValues.set(i, document);
41                 return;
42             }
43         }
44         fgKeys.add(o);
45         fgValues.add(document);
46     }
47     
48     public static void remove(IDocument document) {
49         if (document != null) {
50             if (DEBUG) System.out.println("DocumentManager.remove: " + document); //$NON-NLS-1$
51
for (int i= 0; i < fgValues.size(); i++) {
52                 if (fgValues.get(i) == document) {
53                     fgKeys.remove(i);
54                     fgValues.remove(i);
55                     return;
56                 }
57             }
58             if (DEBUG) System.out.println("DocumentManager.remove: not found"); //$NON-NLS-1$
59
}
60     }
61     
62     public static void dump() {
63         if (DEBUG) System.out.println("DocumentManager: managed docs:" + fgValues.size()); //$NON-NLS-1$
64
}
65 }
66
Popular Tags