KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ltk > core > refactoring > RefactoringDescriptorProxy


1 /*******************************************************************************
2  * Copyright (c) 2005, 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.ltk.core.refactoring;
12
13 import org.eclipse.core.runtime.IProgressMonitor;
14 import org.eclipse.core.runtime.PlatformObject;
15
16 import org.eclipse.ltk.core.refactoring.history.IRefactoringHistoryService;
17 import org.eclipse.ltk.core.refactoring.history.RefactoringHistory;
18
19 import org.eclipse.ltk.internal.core.refactoring.history.RefactoringHistoryService;
20
21 /**
22  * Proxy of a refactoring descriptor.
23  * <p>
24  * Refactoring descriptors are exposed by the refactoring history service as
25  * lightweight proxy objects. Refactoring descriptor proxies have an efficient
26  * memory representation and are therefore suited to model huge refactoring
27  * histories which may be displayed in the user interface. The refactoring
28  * history service may hand out any number of proxies for a given descriptor.
29  * Proxies only offer direct access to the time stamp {@link #getTimeStamp()},
30  * the related project {@link #getProject()} and description
31  * {@link #getDescription()}. In order to access other information such as
32  * arguments and comments, clients have to call
33  * {@link #requestDescriptor(IProgressMonitor)} in order to obtain the actual
34  * refactoring descriptor.
35  * </p>
36  * <p>
37  * Refactoring descriptors are potentially heavy weight objects which should not
38  * be held on to. Proxies which are retrieved from external sources (e.g. not
39  * from the local refactoring history service) may encapsulate refactoring
40  * descriptors and should not be held in memory as well.
41  * </p>
42  * <p>
43  * All time stamps are measured as the milliseconds since January 1, 1970,
44  * 00:00:00 GMT.
45  * </p>
46  * <p>
47  * Note: this class is not intended to be subclassed by clients.
48  * </p>
49  *
50  * @see IRefactoringHistoryService
51  * @see RefactoringHistory
52  *
53  * @since 3.2
54  */

55 public abstract class RefactoringDescriptorProxy extends PlatformObject implements Comparable JavaDoc {
56
57     /**
58      * {@inheritDoc}
59      */

60     public int compareTo(final Object JavaDoc object) {
61         if (object instanceof RefactoringDescriptorProxy) {
62             final RefactoringDescriptorProxy proxy= (RefactoringDescriptorProxy) object;
63             final long delta= getTimeStamp() - proxy.getTimeStamp();
64             if (delta > 0)
65                 return 1;
66             else if (delta < 0)
67                 return -1;
68             return 0;
69         }
70         return 0;
71     }
72
73     /**
74      * {@inheritDoc}
75      */

76     public final boolean equals(final Object JavaDoc object) {
77         if (object instanceof RefactoringDescriptorProxy) {
78             final RefactoringDescriptorProxy proxy= (RefactoringDescriptorProxy) object;
79             return getTimeStamp() == proxy.getTimeStamp() && getDescription().equals(proxy.getDescription());
80         }
81         return false;
82     }
83
84     /**
85      * Returns a human-readable description of refactoring.
86      *
87      * @return a description of the refactoring
88      */

89     public abstract String JavaDoc getDescription();
90
91     /**
92      * Returns the name of the associated project.
93      *
94      * @return the non-empty name of the project, or <code>null</code>
95      */

96     public abstract String JavaDoc getProject();
97
98     /**
99      * Returns the time stamp of this refactoring.
100      *
101      * @return the time stamp, or <code>-1</code> if no time information is
102      * available
103      */

104     public abstract long getTimeStamp();
105
106     /**
107      * {@inheritDoc}
108      */

109     public final int hashCode() {
110         int code= getDescription().hashCode();
111         final long stamp= getTimeStamp();
112         if (stamp >= 0)
113             code+= (17 * stamp);
114         return code;
115     }
116
117     /**
118      * Resolves this proxy and returns the associated refactoring descriptor.
119      * <p>
120      * Clients must connect to the refactoring history service first before
121      * calling this method.
122      * </p>
123      *
124      * @param monitor
125      * the progress monitor to use, or <code>null</code>
126      *
127      * @return the refactoring descriptor, or <code>null</code>
128      */

129     public RefactoringDescriptor requestDescriptor(final IProgressMonitor monitor) {
130         return RefactoringHistoryService.getInstance().requestDescriptor(this, monitor);
131     }
132 }
133
Popular Tags