1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-08 08:45:44 +02:00

[277911] cached results of remote file query need to be sorted

This commit is contained in:
David McKnight 2009-05-29 14:12:25 +00:00
parent 837b060804
commit 2f85b3ea6e

View file

@ -20,12 +20,14 @@
* Martin Oberhuber (Wind River) - [220020][api][breaking] SystemFileTransferModeRegistry should be internal * Martin Oberhuber (Wind River) - [220020][api][breaking] SystemFileTransferModeRegistry should be internal
* Martin Oberhuber (Wind River) - [219975] Fix implementations of clone() * Martin Oberhuber (Wind River) - [219975] Fix implementations of clone()
* David McKnight (IBM) - [231209] [api][breaking] IRemoteFile.getSystemConnection() should be changed to IRemoteFile.getHost() * David McKnight (IBM) - [231209] [api][breaking] IRemoteFile.getSystemConnection() should be changed to IRemoteFile.getHost()
* David McKnight (IBM) - [277911] cached results of remote file query need to be sorted
*******************************************************************************/ *******************************************************************************/
package org.eclipse.rse.subsystems.files.core.subsystems; package org.eclipse.rse.subsystems.files.core.subsystems;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
@ -678,7 +680,7 @@ public abstract class RemoteFile implements IRemoteFile, IAdaptable, Comparable
public Object[] getContents(ISystemContentsType contentsType, String filter) public Object[] getContents(ISystemContentsType contentsType, String filter)
{ {
HashMap filters = (HashMap)(_contents.get(contentsType)); HashMap filters = (HashMap)(_contents.get(contentsType));
Object[] results = null;
if (filters == null || filters.isEmpty()) if (filters == null || filters.isEmpty())
{ {
if (contentsType == RemoteChildrenContentsType.getInstance()) if (contentsType == RemoteChildrenContentsType.getInstance())
@ -715,66 +717,59 @@ public abstract class RemoteFile implements IRemoteFile, IAdaptable, Comparable
filter = "*"; //$NON-NLS-1$ filter = "*"; //$NON-NLS-1$
} }
if (filters.containsKey(filter)) if (filters.containsKey(filter)){
{
Object[] filterResults = (Object[])filters.get(filter); Object[] filterResults = (Object[])filters.get(filter);
if (contentsType == RemoteChildrenContentsType.getInstance() || results = filterResults;
contentsType == RemoteFileChildrenContentsType.getInstance() ||
contentsType == RemoteFolderChildrenContentsType.getInstance()
)
{
return filterResults;
}
else
{
return filterResults;
}
} }
else {
ArrayList calculatedResults = new ArrayList(); ArrayList calculatedResults = new ArrayList();
StringComparePatternMatcher fmatcher = new StringComparePatternMatcher(filter); StringComparePatternMatcher fmatcher = new StringComparePatternMatcher(filter);
// the filter may be a subset of existing filters // the filter may be a subset of existing filters
Object[] keySet = filters.keySet().toArray(); Object[] keySet = filters.keySet().toArray();
for (int i = 0; i < keySet.length; i++) { for (int i = 0; i < keySet.length; i++) {
String key = (String)keySet[i]; String key = (String)keySet[i];
// KM: we need to match with the key to ensure that the filter is a subset // KM: we need to match with the key to ensure that the filter is a subset
StringComparePatternMatcher matcher = new StringComparePatternMatcher(key); StringComparePatternMatcher matcher = new StringComparePatternMatcher(key);
if (matcher.stringMatches(filter)) { if (matcher.stringMatches(filter)) {
// get all children, i.e. the superset // get all children, i.e. the superset
Object[] all = (Object[]) filters.get(key); Object[] all = (Object[]) filters.get(key);
if (all != null) { if (all != null) {
for (int s = 0; s < all.length; s++) { for (int s = 0; s < all.length; s++) {
Object subContent = all[s]; Object subContent = all[s];
if (!calculatedResults.contains(subContent)) { if (!calculatedResults.contains(subContent)) {
if (subContent instanceof IRemoteFile) { if (subContent instanceof IRemoteFile) {
IRemoteFile temp = (IRemoteFile) subContent; IRemoteFile temp = (IRemoteFile) subContent;
if (temp.isFile()) { if (temp.isFile()) {
String compareTo = null; String compareTo = null;
boolean filterForFileTypes = isFilterForFileTypes(filter); boolean filterForFileTypes = isFilterForFileTypes(filter);
if (!filterForFileTypes) { if (!filterForFileTypes) {
compareTo = temp.getName(); compareTo = temp.getName();
}
else {
compareTo = temp.getExtension();
}
// match with the filter to take out those
// that do not match the filter
if (compareTo != null && fmatcher.stringMatches(compareTo)) {
calculatedResults.add(subContent);
}
} }
else { else {
compareTo = temp.getExtension();
}
// match with the filter to take out those
// that do not match the filter
if (compareTo != null && fmatcher.stringMatches(compareTo)) {
calculatedResults.add(subContent); calculatedResults.add(subContent);
} }
} }
@ -782,16 +777,15 @@ public abstract class RemoteFile implements IRemoteFile, IAdaptable, Comparable
calculatedResults.add(subContent); calculatedResults.add(subContent);
} }
} }
else {
calculatedResults.add(subContent);
}
} }
} }
} }
} }
results = calculatedResults.toArray();
} }
return calculatedResults.toArray(); Arrays.sort(results);
return results;
} }
/** /**