From 8628ce0e971584a1249b243fa76d99d465fa6b21 Mon Sep 17 00:00:00 2001 From: Piotr Gawron <piotr.gawron@uni.lu> Date: Tue, 13 Feb 2018 18:31:22 +0100 Subject: [PATCH] optimization: model.getBioEntities is computed per call - changing order increase speed by 2 --- .../mapviewer/commands/ColorModelCommand.java | 7 +++-- .../commands/ColorModelCommandTest.java | 29 +++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/model-command/src/main/java/lcsb/mapviewer/commands/ColorModelCommand.java b/model-command/src/main/java/lcsb/mapviewer/commands/ColorModelCommand.java index 07d2e6faed..bda5fc3e61 100644 --- a/model-command/src/main/java/lcsb/mapviewer/commands/ColorModelCommand.java +++ b/model-command/src/main/java/lcsb/mapviewer/commands/ColorModelCommand.java @@ -4,8 +4,10 @@ import java.awt.Color; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; import org.apache.log4j.Logger; @@ -289,9 +291,10 @@ public class ColorModelCommand extends ModelCommand { List<Model> models = new ArrayList<>(); models.add(getModel()); models.addAll(getModel().getSubmodels()); + for (Model model : models) { - for (ColorSchema schema : schemas) { - for (BioEntity element : model.getBioEntities()) { + for (BioEntity element : model.getBioEntities()) { + for (ColorSchema schema : schemas) { if (match(element, schema)) { if (result.get(element) != null && !colorExtractor.getNormalizedColor(result.get(element)).equals(Color.WHITE)) { diff --git a/model-command/src/test/java/lcsb/mapviewer/commands/ColorModelCommandTest.java b/model-command/src/test/java/lcsb/mapviewer/commands/ColorModelCommandTest.java index 59fe3d09bf..4f6be19fe0 100644 --- a/model-command/src/test/java/lcsb/mapviewer/commands/ColorModelCommandTest.java +++ b/model-command/src/test/java/lcsb/mapviewer/commands/ColorModelCommandTest.java @@ -2,6 +2,7 @@ package lcsb.mapviewer.commands; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import java.awt.Color; @@ -537,4 +538,32 @@ public class ColorModelCommandTest extends CommandTestFunctions { } } + @Test + public void testGetModifiedElements() throws Exception { + try { + Reaction reaction = new Reaction(); + reaction.addMiriamData(new MiriamData(MiriamType.PUBMED, "1234")); + + Model model = new ModelFullIndexed(null); + model.addReaction(reaction); + + GenericColorSchema colorSchema = new GenericColorSchema(); + colorSchema.addMiriamData(new MiriamData(MiriamType.PUBMED,"1234")); + + List<ColorSchema> schemas = new ArrayList<>(); + schemas.add(colorSchema); + + ColorModelCommand factory = new ColorModelCommand(model, schemas, colorExtractor); + + assertNotNull(factory.getModifiedElements().get(reaction)); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + + } + + + } -- GitLab