extract comparator
import org.terasology.entitySystem.metadata.ComponentMetadata;
import org.terasology.entitySystem.prefab.Prefab;
import org.terasology.entitySystem.prefab.PrefabManager;
-import org.terasology.entitySystem.prefab.internal.PojoPrefab;
import org.terasology.entitySystem.systems.BaseComponentSystem;
import org.terasology.entitySystem.systems.RegisterSystem;
import org.terasology.logic.behavior.core.BehaviorNode;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
-import java.util.*;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
import java.util.stream.Collectors;
/**
public class BehaviorNodeFactory extends BaseComponentSystem {
private static final Logger logger = LoggerFactory.getLogger(BehaviorNodeFactory.class);
+ private static final Comparator<BehaviorNodeComponent> COMPARE_BY_NAME = Comparator.comparing(o -> o.name);
+
private List<BehaviorNodeComponent> nodeComponents = Lists.newArrayList();
private Map<String, List<BehaviorNodeComponent>> categoryComponents = Maps.newHashMap();
private List<String> categories;
@@ -99,8 +105,7 @@ public void refreshLibrary() {
public String getString(ResourceUrn value) {
return value.getResourceName().toString();
}
- }
- );
+ });
providerFactory.register("music", new ReadOnlyBinding<List<ResourceUrn>>() {
@Override
public List<ResourceUrn> get() {
@@ -111,16 +116,14 @@ public String getString(ResourceUrn value) {
public String getString(ResourceUrn value) {
return value.getResourceName().toString();
}
- }
- );
+ });
providerFactory.register("animations", new AnimationPoolUriBinding(),
new StringTextRenderer<ComponentFieldUri>() {
@Override
public String getString(ComponentFieldUri value) {
return value.toString();
}
- }
- );
+ });
refreshPrefabs();
sortLibrary();
}
@@ -153,7 +156,7 @@ private void sortLibrary() {
categories = Lists.newArrayList(categoryComponents.keySet());
Collections.sort(categories);
for (String category : categories) {
- Collections.sort(categoryComponents.get(category), Comparator.comparing(o -> o.name));
+ Collections.sort(categoryComponents.get(category), COMPARE_BY_NAME);
}
}
@@ -163,8 +166,7 @@ private void refreshPrefabs() {
// called from main menu
List<String> nodes = Arrays.asList(
"counter", "timer", "loop", "lookup", "dynselector",
- "fail", "parallel", "playMusic", "playSound", "running", "selector", "setAnimation", "sequence", "succeed"
- );
+ "fail", "parallel", "playMusic", "playSound", "running", "selector", "setAnimation", "sequence", "succeed");
prefabs = Lists.newArrayList();
for (String node : nodes) {
prefabs.add(Assets.get(new ResourceUrn("engine:" + node), Prefab.class).orElse(null));
