Skip to content

Commit

Permalink
Performance improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
marcphilipp committed Feb 4, 2015
1 parent 2e9661f commit 155dec3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,19 @@ public List<IPath> getAllSourceFolders() {
return allSourceFolders;
}

public void updateSourceFolders( List<IPath> allSourceFolders ) {
public boolean updateSourceFolders( List<IPath> allSourceFolders ) {
if( this.allSourceFolders.equals( allSourceFolders ) ) {
return false;
}
this.visibleSourceFolders.retainAll( allSourceFolders );
this.visibleSourceFolders.addAll( addedSourceFolders( allSourceFolders ) );
this.allSourceFolders = new LinkedList<IPath>( allSourceFolders );
this.allSourceFolders = new ArrayList<IPath>( allSourceFolders );
return true;
}

private LinkedList<IPath> addedSourceFolders( List<IPath> newSourceFolders ) {
private List<IPath> addedSourceFolders( List<IPath> newSourceFolders ) {
List<IPath> oldSourceFolders = this.allSourceFolders;
LinkedList<IPath> result = new LinkedList<IPath>( newSourceFolders );
List<IPath> result = new LinkedList<IPath>( newSourceFolders );
result.removeAll( oldSourceFolders );
return result;
}
Expand All @@ -51,6 +55,10 @@ public String getDescription() {

@Override
protected boolean select( GraphNode node, Set<GraphNode> others ) {
return !isFiltering() || isContainedByVisibleSourceFolder( node );
}

private boolean isContainedByVisibleSourceFolder( GraphNode node ) {
IJavaElement javaElement = JavaCore.create( node.getFile() );
IJavaElement packageFragmentRoot = javaElement.getAncestor( IJavaElement.PACKAGE_FRAGMENT_ROOT );
IJavaProject javaProject = packageFragmentRoot.getJavaProject();
Expand All @@ -63,6 +71,6 @@ protected boolean select( GraphNode node, Set<GraphNode> others ) {
}

public boolean isFiltering() {
return getAllSourceFolders().size() > getVisibleSourceFolders().size();
return allSourceFolders.size() > visibleSourceFolders.size();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static org.projectusus.core.statistics.UsusModelProvider.ususModel;
import static org.projectusus.ui.dependencygraph.sourcefolder.SourceFolderChangeDetector.detectSourceFolderChange;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -77,9 +78,11 @@ private void recomputeSourceFolders() {
IJavaProject[] ususJavaProjects = convertToJavaProjects( ususProjects );
Set<IPath> allSourceFolders = scanForSourceFolders( ususJavaProjects );

filter.updateSourceFolders( new LinkedList<IPath>( allSourceFolders ) );
action.updateState();
refreshable.refresh();
boolean changed = filter.updateSourceFolders( new ArrayList<IPath>( allSourceFolders ) );
if( changed ) {
action.updateState();
refreshable.refresh();
}
}

private Set<IPath> scanForSourceFolders( IJavaProject[] ususJavaProjects ) {
Expand Down

0 comments on commit 155dec3

Please sign in to comment.