Skip to content

Commit b9f87cd

Browse files
author
rcartwright
committed
In classes where structural equality is unnecessary, this revision
replaces structural definitions of equals by default identity definitions. These classes are used primarily in the implementation of FindResultsPanel. This goal of this revision is to lower the overhead associated with operation on FindResultsPanel and other region list/tree displays. The following files were modified: M src/edu/rice/cs/drjava/DrJavaRoot.java M src/edu/rice/cs/drjava/ui/MainFrame.java M src/edu/rice/cs/drjava/ui/NewVersionPopup.java M src/edu/rice/cs/drjava/ui/BrowserHistoryPanel.java M src/edu/rice/cs/drjava/ui/RegionsListPanel.java M src/edu/rice/cs/drjava/ui/ClipboardHistoryFrame.java M src/edu/rice/cs/util/FileOps.java M src/edu/rice/cs/util/OrderedHashSet.java M src/edu/rice/cs/util/NullFile.java git-svn-id: file:///tmp/test-svn/trunk@4600 fe72c1cf-3628-48e9-8b72-1c46755d3cff
1 parent 4699abd commit b9f87cd

File tree

9 files changed

+57
-71
lines changed

9 files changed

+57
-71
lines changed

drjava/src/edu/rice/cs/drjava/DrJavaRoot.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -164,18 +164,18 @@ public static void main(final String[] args) {
164164
// false means "do not jump to the line number that may be specified, just open the file"
165165
_openCommandLineFiles(_mainFrame, filesToOpen, numFiles, false);
166166

167-
/* This call on invokeLater only runs in the main thread, so we use EventQueue rather than Utilities.
168-
* We use invokeLater here ensure all files have finished loading and added to the fileview before the MainFrame
169-
* is set visible. When this was not done, we occasionally encountered a NullPointerException on start up when
170-
* specifying a file (ex: java -jar drjava.jar somefile.java)
167+
/* We use EventQueue.invokeLater rather than Utilities.invokeLater to ensure all files have been loaded and
168+
* added to the fileview before the MainFrame is set visible. When this was not done, we occasionally encountered
169+
* a NullPointerException on start up when specifying a file (ex: java -jar drjava.jar somefile.java)
171170
*/
172-
EventQueue.invokeLater(new Runnable(){ public void run(){
173-
_mainFrame.start();
174-
if (anyLineNumbersSpecified) {
175-
// this time, we do want to jump to the line number
176-
_openCommandLineFiles(_mainFrame, filesToOpen, numFiles, true);
177-
}
178-
} });
171+
EventQueue.invokeLater(new Runnable(){
172+
public void run(){
173+
_mainFrame.start();
174+
if (anyLineNumbersSpecified) { // this time, we do want to jump to the line number
175+
_openCommandLineFiles(_mainFrame, filesToOpen, numFiles, true);
176+
}
177+
}
178+
});
179179

180180
// redirect stdout to DrJava's console
181181
System.setOut(new PrintStream(new OutputStreamRedirector() {
@@ -198,8 +198,6 @@ public static void main(final String[] args) {
198198
System.out.println("error thrown");
199199
new DrJavaErrorHandler().handle(t);
200200
}
201-
// }
202-
// });
203201
}
204202

205203
/** Handle the list of files specified on the command line. Feature request #509701.

drjava/src/edu/rice/cs/drjava/ui/BrowserHistoryPanel.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -280,14 +280,14 @@ public String toString() {
280280
// finally { _region.getDocument().releaseReadLock(); }
281281
return sb.toString();
282282
}
283-
public boolean equals(Object other) {
284-
if (other == null || other.getClass() != this.getClass()) return false;
285-
@SuppressWarnings("unchecked") BrowserHistoryListUserObj o = (BrowserHistoryListUserObj)other;
286-
return (o.region().getDocument().equals(region().getDocument())) &&
287-
(o.region().getStartOffset()==region().getStartOffset()) &&
288-
(o.region().getEndOffset()==region().getEndOffset());
289-
}
290-
public int hashCode() { return (_region != null ? _region.hashCode() : 0); }
283+
// public boolean equals(Object other) {
284+
// if (other == null || other.getClass() != this.getClass()) return false;
285+
// @SuppressWarnings("unchecked") BrowserHistoryListUserObj o = (BrowserHistoryListUserObj)other;
286+
// return (o.region().getDocument().equals(region().getDocument())) &&
287+
// (o.region().getStartOffset()==region().getStartOffset()) &&
288+
// (o.region().getEndOffset()==region().getEndOffset());
289+
// }
290+
// public int hashCode() { return (_region != null ? _region.hashCode() : 0); }
291291
}
292292
}
293293

drjava/src/edu/rice/cs/drjava/ui/ClipboardHistoryFrame.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -411,10 +411,10 @@ public ListItem(String s) {
411411
}
412412
public String getFull() { return full; }
413413
public String toString() { return display; }
414-
public boolean equals(Object o) {
415-
if (o == null || getClass() != o.getClass()) return false;
416-
return full.equals(((ListItem)o).full);
417-
}
418-
public int hashCode() { return (full != null ? full.hashCode() : 0); }
414+
// public boolean equals(Object o) {
415+
// if (o == null || getClass() != o.getClass()) return false;
416+
// return full.equals(((ListItem)o).full);
417+
// }
418+
// public int hashCode() { return (full != null ? full.hashCode() : 0); }
419419
}
420420
}

drjava/src/edu/rice/cs/drjava/ui/MainFrame.java

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,15 +1161,15 @@ private static abstract class ClassNameAndPackageEntry implements Comparable<Cla
11611161

11621162
public int compareTo(ClassNameAndPackageEntry other) {
11631163
int res = getClassName().toLowerCase().compareTo(other.getClassName().toLowerCase());
1164-
if (res!=0) { return res; }
1164+
if (res != 0) { return res; }
11651165
return getFullPackage().toLowerCase().compareTo(other.getFullPackage().toLowerCase());
11661166
}
1167+
// WARNING: this relation is finer grained that the equivalance relation induced by compareTo above
11671168
public boolean equals(Object other) {
1168-
if (other==null) { return false; }
1169+
if (other == null) { return false; }
11691170
if (! (other instanceof ClassNameAndPackageEntry)) return false;
11701171
ClassNameAndPackageEntry o = (ClassNameAndPackageEntry)other;
1171-
return ((getClassName().equals(o.getClassName())) &&
1172-
(getFullPackage().equals(o.getFullPackage())));
1172+
return (getClassName().equals(o.getClassName()) && getFullPackage().equals(o.getFullPackage()));
11731173
}
11741174
public int hashCode() { return hash(getClassName().hashCode(), getFullPackage().hashCode()); }
11751175
}
@@ -1187,12 +1187,12 @@ public GoToFileListEntry(OpenDefinitionsDocument d, String s) {
11871187
str = s;
11881188
}
11891189
public String getFullPackage() {
1190-
if (fullPackage!=null) { return fullPackage; }
1190+
if (fullPackage != null) { return fullPackage; }
11911191
fullPackage = "";
11921192
if (doc!=null) {
11931193
try {
11941194
fullPackage = doc.getPackageName();
1195-
if (fullPackage.length()>0) { fullPackage += '.'; }
1195+
if (fullPackage.length() > 0) { fullPackage += '.'; }
11961196
}
11971197
catch(Exception e) { fullPackage = ""; }
11981198
}
@@ -4817,12 +4817,10 @@ private void _printDefDocPreview() {
48174817
_showFileMovedError(fme);
48184818
}
48194819
catch (BadLocationException e) {
4820-
_showError(e, "Print Error",
4821-
"An error occured while preparing the print preview.");
4820+
_showError(e, "Print Error", "An error occured while preparing the print preview.");
48224821
}
48234822
catch (IllegalStateException e) {
4824-
_showError(e, "Print Error",
4825-
"An error occured while preparing the print preview.");
4823+
_showError(e, "Print Error", "An error occured while preparing the print preview.");
48264824
}
48274825
}
48284826

@@ -4832,8 +4830,7 @@ private void _printConsolePreview() {
48324830
new PreviewConsoleFrame(_model, this, false);
48334831
}
48344832
catch (IllegalStateException e) {
4835-
_showError(e, "Print Error",
4836-
"An error occured while preparing the print preview.");
4833+
_showError(e, "Print Error", "An error occured while preparing the print preview.");
48374834
}
48384835
}
48394836

@@ -4843,8 +4840,7 @@ private void _printInteractionsPreview() {
48434840
new PreviewConsoleFrame(_model, this, true);
48444841
}
48454842
catch (IllegalStateException e) {
4846-
_showError(e, "Print Error",
4847-
"An error occured while preparing the print preview.");
4843+
_showError(e, "Print Error", "An error occured while preparing the print preview.");
48484844
}
48494845
}
48504846

@@ -4858,8 +4854,7 @@ private void _pageSetup() {
48584854

48594855
private void _closeAll() {
48604856
updateStatusField("Closing All Files");
4861-
if (!_model.isProjectActive() || _model.isProjectActive() && _closeProject())
4862-
_model.closeAllFiles();
4857+
if (!_model.isProjectActive() || _model.isProjectActive() && _closeProject()) _model.closeAllFiles();
48634858
}
48644859

48654860
private boolean _save() {
@@ -4898,8 +4893,7 @@ private boolean _saveAs() {
48984893
updateStatusField("Saving File Under New Name");
48994894
try {
49004895
boolean toReturn = _model.getActiveDocument().saveFileAs(_saveAsSelector);
4901-
/** this highlights the document in the navigator */
4902-
_model.setActiveDocument(_model.getActiveDocument());
4896+
_model.setActiveDocument(_model.getActiveDocument()); // highlights the document in the navigator
49034897
return toReturn;
49044898
}
49054899
catch (IOException ioe) {
@@ -4913,9 +4907,7 @@ private boolean _rename() {
49134907
if (!_model.getActiveDocument().fileExists()) return _saveAs();
49144908
else {
49154909
File fileToDelete;
4916-
try {
4917-
fileToDelete = _model.getActiveDocument().getFile();
4918-
}
4910+
try { fileToDelete = _model.getActiveDocument().getFile(); }
49194911
catch (FileMovedException fme) { return _saveAs(); }
49204912
boolean toReturn = _model.getActiveDocument().saveFileAs(_saveAsSelector);
49214913
/** Delete the old file if save was successful. */

drjava/src/edu/rice/cs/drjava/ui/NewVersionPopup.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ private void updateText() {
148148
cp.add(_bottomPanel, BorderLayout.SOUTH);
149149
getRootPane().setDefaultButton(_closeButton);
150150
pack();
151-
Utilities.clearEventQueue();
151+
Utilities.clearEventQueue(); // Why? In principle, its inclusion does not change the semantics of the program
152152

153153
EventQueue.invokeLater(new Runnable() {
154154
public void run() {

drjava/src/edu/rice/cs/drjava/ui/RegionsListPanel.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,6 @@ protected static class RegionListUserObj<R extends IDocumentRegion> {
363363
public RegionListUserObj(R r) { _region = r; }
364364
public String toString() {
365365
final StringBuilder sb = new StringBuilder();
366-
// _region.getDocument().acquireReadLock();
367-
// try {
368366
sb.append(_region.getDocument().toString());
369367
sb.append(':');
370368
sb.append(lineNumber());
@@ -373,18 +371,16 @@ public String toString() {
373371
int length = Math.min(120, _region.getEndOffset()-_region.getStartOffset());
374372
sb.append(_region.getDocument().getText(_region.getStartOffset(), length).trim());
375373
} catch(BadLocationException bpe) { /* ignore, just don't display line */ }
376-
// }
377-
// finally { _region.getDocument().releaseReadLock(); }
378374
return sb.toString();
379375
}
380-
public boolean equals(Object other) {
381-
if ((other == null) || !(other instanceof RegionListUserObj)) { return false; }
382-
@SuppressWarnings("unchecked") RegionListUserObj<R> o = (RegionListUserObj<R>)other;
383-
return (o.region().getDocument().equals(region().getDocument())) &&
384-
(o.region().getStartOffset()==region().getStartOffset()) &&
385-
(o.region().getEndOffset()==region().getEndOffset());
386-
}
387-
public int hashCode() { return (_region != null ? _region.hashCode() : 0); }
376+
// public boolean equals(Object other) {
377+
// if ((other == null) || ! (other instanceof RegionListUserObj)) { return false; }
378+
// @SuppressWarnings("unchecked") RegionListUserObj<R> o = (RegionListUserObj<R>)other;
379+
// return (o.region().getDocument().equals(region().getDocument())) &&
380+
// (o.region().getStartOffset()==region().getStartOffset()) &&
381+
// (o.region().getEndOffset()==region().getEndOffset());
382+
// }
383+
// public int hashCode() { return (_region != null ? _region.hashCode() : 0); }
388384
}
389385

390386

drjava/src/edu/rice/cs/util/FileOps.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,21 @@ public abstract class FileOps {
5959

6060
private static Log _log = new Log("FileOpsTest.txt", false);
6161

62-
static public abstract class NoFile extends File {
63-
public NoFile(String name) { super(name); }
62+
/** A singleton null file class. */
63+
static public class NullFile extends File {
64+
65+
public static NullFile ONLY = new NullFile();
66+
67+
private NullFile() { super(""); }
6468
public boolean canRead() { return false; }
6569
public boolean canWrite() { return false; }
6670
public int compareTo(File f) { return (f == this) ? 0 : -1; }
6771
public boolean createNewFile() { return false; }
6872
public boolean delete() { return false; }
6973
public void deleteOnExit() {}
7074
public boolean equals(Object o) { return o == this; }
75+
public boolean exists() { return false; }
76+
public int hashCode() { return getClass().hashCode(); }
7177
public File getAbsoluteFile() { return this; }
7278
public String getAbsolutePath() { return ""; }
7379
public File getCanonicalFile() { return this; }
@@ -76,7 +82,6 @@ public void deleteOnExit() {}
7682
public String getParent() { return null; }
7783
public File getParentFile() { return null; }
7884
public String getPath() { return ""; }
79-
public int hashCode() { return getClass().hashCode(); }
8085
public boolean isAbsolute() { return false; }
8186
public boolean isDirectory() { return false; }
8287
public boolean isFile() { return false; }
@@ -99,10 +104,7 @@ public void deleteOnExit() {}
99104
};
100105

101106
/** Special sentinal file used in FileOption and test classes among others. */
102-
public static final File NULL_FILE = new NoFile("") { public boolean exists() { return false; } };
103-
104-
// /** Special File object corresponding to a dummy file. Simliar to NULL_FILE but exists() returns false. */
105-
// public static final File NULL_FILE = new NoFile("") { public boolean exists() { return false; } };
107+
public static final File NULL_FILE = NullFile.ONLY;
106108

107109
/** @deprecated For a best-attempt canonical file, use {@link edu.rice.cs.plt.io.IOUtil#attemptCanonicalFile} instead.
108110
* (for example, {@code IOUtil.attemptCanonicalFile(new File(path))})

drjava/src/edu/rice/cs/util/NullFile.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
public class NullFile extends File implements Serializable {
4545

4646
private static volatile int ct = 0;
47-
4847
private final String _lexiName;
4948

5049
public NullFile() {
@@ -68,6 +67,5 @@ private NullFile(String lexiName) {
6867
public boolean equals(Object o) {
6968
if (o == null || o.getClass() != getClass()) return false;
7069
return o == this;
71-
}
72-
70+
}
7371
}

drjava/src/edu/rice/cs/util/OrderedHashSet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public boolean containsAll(Collection<?> c) {
6868
}
6969

7070
public boolean equals(Object o) {
71-
if ((o == null) || o.getClass() != getClass()) return false;
71+
if (o == null || o.getClass() != getClass()) return false;
7272
return order.equals(elements());
7373
}
7474

0 commit comments

Comments
 (0)