Skip to content

Issue-606. replace String list with TreeSet #616

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public class AssetBrowser extends javax.swing.JPanel implements PreviewInteracti

private int lastGridColumns = 0;
private int lastGridRows = 0;
private String lastFilter;
private String lastFilter = "";

private int sizeX = Constants.sizeX;
private int sizeY = Constants.sizeY;
Expand Down Expand Up @@ -155,7 +155,7 @@ private void loadAssets(String filter) {
Dimension size = previewsPanel.getSize();

int rows = Math.min(size.height, getHeight() - 30) / sizeY;

final var textures = Arrays.stream(assetManager.getTextures()).filter(s -> filter.isEmpty() || s.toLowerCase().contains(filter)).collect(Collectors.toList());
final var materials = Arrays.stream(assetManager.getMaterials()).filter(s -> filter.isEmpty() || s.toLowerCase().contains(filter)).collect(Collectors.toList());
final var models = Arrays.stream(assetManager.getModels()).filter(s -> filter.isEmpty() || s.toLowerCase().contains(filter)).collect(Collectors.toList());
Expand Down
88 changes: 44 additions & 44 deletions jme3-core/src/com/jme3/gde/core/assets/ProjectAssetManager.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2009-2010 jMonkeyEngine
* Copyright (c) 2009-2024 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -50,6 +50,7 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.netbeans.api.java.classpath.ClassPath;
Expand Down Expand Up @@ -215,9 +216,7 @@
runtimeFiles = sourceSet.getRuntimeClassPath();
}
}
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
} catch (IllegalArgumentException ex) {
} catch (IOException | IllegalArgumentException ex) {
Exceptions.printStackTrace(ex);
}

Expand All @@ -243,25 +242,31 @@
}

FileChangeListener listener = new FileChangeListener() {
@Override
public void fileFolderCreated(FileEvent fe) {
fireChange(fe);
}

@Override
public void fileDataCreated(FileEvent fe) {
fireChange(fe);
}

@Override
public void fileChanged(FileEvent fe) {
fireChange(fe);
}

@Override
public void fileDeleted(FileEvent fe) {
}

@Override
public void fileRenamed(FileRenameEvent fe) {
fireChange(fe);
}

@Override
public void fileAttributeChanged(FileAttributeEvent fae) {
}

Expand All @@ -271,26 +276,22 @@
}
};

private PropertyChangeListener classPathListener = new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent evt) {
logger.log(Level.FINE, "Classpath event: {0}", evt);
if (null != evt.getPropertyName()) switch (evt.getPropertyName()) {
case ClassPath.PROP_ROOTS -> updateClassLoader();
case ClassPath.PROP_ENTRIES -> updateClassLoader();
case ClassPath.PROP_INCLUDES -> updateClassLoader();
default -> {
}
private PropertyChangeListener classPathListener = (PropertyChangeEvent evt) -> {

Check notice on line 279 in jme3-core/src/com/jme3/gde/core/assets/ProjectAssetManager.java

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

jme3-core/src/com/jme3/gde/core/assets/ProjectAssetManager.java#L279

Fields should be declared at the top of the class, before any method declarations, constructors, initializers or inner classes.
logger.log(Level.FINE, "Classpath event: {0}", evt);
if (null != evt.getPropertyName()) switch (evt.getPropertyName()) {
case ClassPath.PROP_ROOTS -> updateClassLoader();
case ClassPath.PROP_ENTRIES -> updateClassLoader();
case ClassPath.PROP_INCLUDES -> updateClassLoader();
default -> {
}
}
};

public void updateClassLoader() {
ProjectManager.mutex().postWriteRequest(new Runnable() {
public void run() {
synchronized (classPathItems) {
clearClassLoader();
loadClassLoader();
}
ProjectManager.mutex().postWriteRequest(() -> {
synchronized (classPathItems) {
clearClassLoader();
loadClassLoader();
}
});
notifyClassPathListeners();
Expand All @@ -303,6 +304,7 @@

private void prepAssetEventListeners() {
super.setAssetEventListener(new AssetEventListener() {
@Override
public void assetLoaded(AssetKey ak) {
synchronized (assetEventListeners) {
for (AssetEventListener assetEventListener : assetEventListeners) {
Expand All @@ -311,6 +313,7 @@
}
}

@Override
public void assetRequested(AssetKey ak) {
synchronized (assetEventListeners) {
for (AssetEventListener assetEventListener : assetEventListeners) {
Expand All @@ -319,6 +322,7 @@
}
}

@Override
public void assetDependencyNotFound(AssetKey ak, AssetKey ak1) {
synchronized (assetEventListeners) {
for (AssetEventListener assetEventListener : assetEventListeners) {
Expand Down Expand Up @@ -425,6 +429,7 @@

/**
* Adds a locator to a folder within the main project directory
* @param relativePath
*/
public void addFolderLocator(String relativePath) {
String string = project.getProjectDirectory().getPath() + "/" + relativePath + "/";
Expand Down Expand Up @@ -506,12 +511,12 @@
return filesWithSuffix("j3md", includeDependencies);
}

public List<String> getProjectShaderNodeDefs() {
return collectProjectFilesWithSuffix("j3sn", new LinkedList<>());
public Set<String> getProjectShaderNodeDefs() {
return collectProjectFilesWithSuffix("j3sn", new TreeSet<>());
}

public List<String> getDependenciesShaderNodeDefs() {
return collectDependenciesFilesWithSuffix("j3sn", new LinkedList<>());
public Set<String> getDependenciesShaderNodeDefs() {
return collectDependenciesFilesWithSuffix("j3sn", new TreeSet<>());
}

public String[] getAssetsWithSuffix(String string) {
Expand All @@ -523,20 +528,20 @@
}

private String[] filesWithSuffix(String string, boolean includeDependencies) {
List<String> list = collectFilesWithSuffix(string, includeDependencies);
Set<String> list = collectFilesWithSuffix(string, includeDependencies);
return list.toArray(String[]::new);
}

private List<String> collectFilesWithSuffix(String suffix, boolean includeDependencies) {
List<String> list = new LinkedList<>();
private Set<String> collectFilesWithSuffix(String suffix, boolean includeDependencies) {
Set<String> list = new TreeSet<>();
collectProjectFilesWithSuffix(suffix, list);
if(includeDependencies) {
collectDependenciesFilesWithSuffix(suffix, list);
}
return list;
}

private List<String> collectProjectFilesWithSuffix(String suffix, List<String> list) {
private Set<String> collectProjectFilesWithSuffix(String suffix, Set<String> list) {
FileObject assetsFolder = getAssetFolder();
if (assetsFolder != null) {
Enumeration<FileObject> assets = (Enumeration<FileObject>) assetsFolder.getChildren(true);
Expand All @@ -550,12 +555,9 @@
return list;
}

private List<String> collectDependenciesFilesWithSuffix(String suffix, List<String> list) {
private Set<String> collectDependenciesFilesWithSuffix(String suffix, Set<String> list) {
synchronized (classPathItems) {
// TODO I need to find out if classPathItems contains all jars added to a project
Iterator<ClassPathItem> classPathItemsIter = classPathItems.iterator();
while (classPathItemsIter.hasNext()) {
ClassPathItem classPathItem = classPathItemsIter.next();
for (ClassPathItem classPathItem : classPathItems) {
FileObject jarFile = classPathItem.object;

// Gradle projects don't know that the dependency is a Jar file
Expand All @@ -572,19 +574,18 @@
}
}
}

}
return list;
// TODO I need to find out if classPathItems contains all jars added to a project
return list;
}
}

public InputStream getResourceAsStream(String name) {
InputStream in = null;//JmeSystem.getResourceAsStream(name);
synchronized (classPathItems) {
// TODO I need to find out if classPathItems contains all jars added to a project
Iterator<ClassPathItem> classPathItemsIter = classPathItems.iterator();
while (classPathItemsIter.hasNext()) {
ClassPathItem classPathItem = classPathItemsIter.next();

for (ClassPathItem classPathItem : classPathItems) {
FileObject jarFile = classPathItem.object;

Enumeration<FileObject> jarEntry;
Expand Down Expand Up @@ -692,12 +693,10 @@

private void notifyClassPathListeners() {
final ProjectAssetManager pm = this;
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
synchronized (classPathListeners) {
for (ClassPathChangeListener classPathChangeListener : classPathListeners) {
classPathChangeListener.classPathChanged(pm);
}
java.awt.EventQueue.invokeLater(() -> {
synchronized (classPathListeners) {
for (ClassPathChangeListener classPathChangeListener : classPathListeners) {
classPathChangeListener.classPathChanged(pm);
}
}
});
Expand Down Expand Up @@ -729,10 +728,12 @@
this.pm = pm;
}

@Override
public Lookup getLookup() {
return Lookups.fixed(this, pm);
}

@Override
public FileObject getProjectDirectory() {
if (folder != null) {
return folder;
Expand All @@ -743,7 +744,6 @@

private static class ClassPathItem {

ClassPath path;
FileObject object;
FileChangeListener listener;

Expand Down
Loading