diff --git a/src/bacter/ConversionGraph.java b/src/bacter/ConversionGraph.java index 8ab16fe..52f82da 100644 --- a/src/bacter/ConversionGraph.java +++ b/src/bacter/ConversionGraph.java @@ -72,6 +72,7 @@ public class ConversionGraph extends Tree { */ protected Map> convs; protected Map> storedConvs; + protected final static List emptyConvList = new ArrayList<>(); /** * Event and region lists. @@ -114,7 +115,7 @@ public void initAndValidate() { } regionLists = new HashMap<>(); - for (Locus locus : convertibleLoci) + for (Locus locus : loci) regionLists.put(locus, new RegionList(this, locus)); cfEventList = new CFEventList(this); @@ -175,6 +176,9 @@ public void addConversion(Conversion conv) { Locus locus = conv.getLocus(); + if (!locus.conversionsAllowed()) + throw new IllegalStateException("Tried to add a conversion to a conversion-free locus."); + int i; for (i=0; iconv.startSite) @@ -190,7 +194,10 @@ public void addConversion(Conversion conv) { */ public void deleteConversion(Conversion conv) { startEditing(null); - + + if (!conv.getLocus().conversionsAllowed()) + throw new IllegalStateException("Tried to remove a conversion from a conversion-free locus."); + convs.get(conv.getLocus()).remove(conv); } @@ -201,7 +208,10 @@ public void deleteConversion(Conversion conv) { * @return List of conversions. */ public List getConversions(Locus locus) { - return convs.get(locus); + if (locus.conversionsAllowed()) + return convs.get(locus); + else + return emptyConvList; } /** @@ -211,7 +221,10 @@ public List getConversions(Locus locus) { * @return Number of conversions. */ public int getConvCount(Locus locus) { - return convs.get(locus).size(); + if (locus.conversionsAllowed()) + return convs.get(locus).size(); + else + return 0; } /** @@ -523,7 +536,7 @@ private void generalAssignFrom(StateNode other, boolean fragileAssignment) { cfEventList = new CFEventList(this); regionLists.clear(); - for (Locus locus : convertibleLoci) { + for (Locus locus : loci) { regionLists.put(locus, new RegionList(this, locus)); } } @@ -999,7 +1012,7 @@ public void restore() { convs = tmp; cfEventList.makeDirty(); - for (Locus locus : convertibleLoci) + for (Locus locus : loci) regionLists.get(locus).makeDirty(); } diff --git a/src/bacter/RegionList.java b/src/bacter/RegionList.java index efdd646..7a0b4b8 100644 --- a/src/bacter/RegionList.java +++ b/src/bacter/RegionList.java @@ -20,10 +20,7 @@ import com.google.common.collect.Lists; import com.google.common.collect.Sets; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import java.util.*; import java.util.function.Consumer; /** @@ -110,11 +107,11 @@ public void updateRegionList() { if (affectedSiteList.affectedSiteCount.get(conversion)>0) convOrderedByStart.add(conversion.getCopy()); }); - convOrderedByStart.sort((Conversion o1, Conversion o2) -> o1.startSite - o2.startSite); + convOrderedByStart.sort(Comparator.comparingInt((Conversion o) -> o.startSite)); List convOrderedByEnd = new ArrayList<>(); convOrderedByEnd.addAll(convOrderedByStart); - convOrderedByEnd.sort((Conversion o1, Conversion o2) -> o1.endSite - o2.endSite); + convOrderedByEnd.sort(Comparator.comparingInt((Conversion o) -> o.endSite)); Set activeConversions = Sets.newHashSet();