mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-11 01:32:08 +10:00
copy-paste performance improvement
This commit is contained in:
+10
-5
@@ -3,6 +3,7 @@ package org.diylc.presenter;
|
|||||||
import java.awt.Point;
|
import java.awt.Point;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
@@ -172,15 +173,19 @@ public class InstantiationManager {
|
|||||||
public String createUniqueName(ComponentType componentType, Project currentProject) {
|
public String createUniqueName(ComponentType componentType, Project currentProject) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
boolean exists = true;
|
boolean exists = true;
|
||||||
|
List<IDIYComponent<?>> components = currentProject.getComponents();
|
||||||
|
String[] takenNames = new String[components.size()];
|
||||||
|
for (int j = 0; j < currentProject.getComponents().size(); j++) {
|
||||||
|
takenNames[j] = components.get(i).getName();
|
||||||
|
}
|
||||||
|
Arrays.sort(takenNames);
|
||||||
while (exists) {
|
while (exists) {
|
||||||
i++;
|
i++;
|
||||||
String name = componentType.getNamePrefix() + i;
|
String name = componentType.getNamePrefix() + i;
|
||||||
exists = false;
|
exists = false;
|
||||||
for (IDIYComponent<?> c : currentProject.getComponents()) {
|
if (Arrays.binarySearch(takenNames, name) >= 0) {
|
||||||
if (c.getName().equals(name)) {
|
exists = true;
|
||||||
exists = true;
|
break;
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return componentType.getNamePrefix() + i;
|
return componentType.getNamePrefix() + i;
|
||||||
|
|||||||
Reference in New Issue
Block a user