66
77import java .util .ArrayList ;
88import java .util .Collections ;
9+ import java .util .HashMap ;
10+ import java .util .LinkedHashMap ;
911import java .util .List ;
12+ import java .util .Map ;
1013import java .util .function .BiConsumer ;
1114import java .util .function .Consumer ;
15+ import java .util .function .Predicate ;
1216
1317/**
1418 * A mapping (in the math sense) from a list of vertices to another list of
2024public class Mapping {
2125
2226
27+ private final Map <Vertex , Vertex > fixedParentRestrictions ;
2328 private final BiMap <Vertex , Vertex > fixedMappings ;
2429 private final List <Vertex > fixedSourceList ;
2530 private final List <Vertex > fixedTargetList ;
@@ -28,12 +33,14 @@ public class Mapping {
2833 private final List <Vertex > sourceList ;
2934 private final List <Vertex > targetList ;
3035
31- private Mapping (BiMap <Vertex , Vertex > fixedMappings ,
36+ private Mapping (Map <Vertex , Vertex > fixedParentRestrictions ,
37+ BiMap <Vertex , Vertex > fixedMappings ,
3238 List <Vertex > fixedSourceList ,
3339 List <Vertex > fixedTargetList ,
3440 BiMap <Vertex , Vertex > map ,
3541 List <Vertex > sourceList ,
3642 List <Vertex > targetList ) {
43+ this .fixedParentRestrictions = fixedParentRestrictions ;
3744 this .fixedMappings = fixedMappings ;
3845 this .fixedSourceList = fixedSourceList ;
3946 this .fixedTargetList = fixedTargetList ;
@@ -42,9 +49,26 @@ private Mapping(BiMap<Vertex, Vertex> fixedMappings,
4249 this .targetList = targetList ;
4350 }
4451
45- public static Mapping newMapping (BiMap <Vertex , Vertex > fixedMappings , List <Vertex > fixedSourceList , List <Vertex > fixedTargetList ) {
46- return new Mapping (fixedMappings , fixedSourceList , fixedTargetList , HashBiMap .create (), Collections .emptyList (), Collections .emptyList ());
52+ public static Mapping newMapping (Map <Vertex , Vertex > fixedParentRestrictions ,
53+ BiMap <Vertex , Vertex > fixedMappings ,
54+ List <Vertex > fixedSourceList ,
55+ List <Vertex > fixedTargetList ) {
56+ return new Mapping (
57+ fixedParentRestrictions ,
58+ fixedMappings ,
59+ fixedSourceList ,
60+ fixedTargetList ,
61+ HashBiMap .create (),
62+ Collections .emptyList (),
63+ Collections .emptyList ());
64+ }
65+
66+ public boolean hasParentRestriction (Vertex v ) {
67+ return fixedParentRestrictions .containsKey (v );
68+ }
4769
70+ public Vertex getParentRestriction (Vertex v ) {
71+ return fixedParentRestrictions .get (v );
4872 }
4973
5074 public Vertex getSource (Vertex target ) {
@@ -118,14 +142,14 @@ public Mapping copyMappingWithLastElementRemoved() {
118142 newMap .remove (this .sourceList .get (this .sourceList .size () - 1 ));
119143 List <Vertex > newSourceList = new ArrayList <>(this .sourceList .subList (0 , this .sourceList .size () - 1 ));
120144 List <Vertex > newTargetList = new ArrayList <>(this .targetList .subList (0 , this .targetList .size () - 1 ));
121- return new Mapping (fixedMappings , fixedSourceList , fixedTargetList , newMap , newSourceList , newTargetList );
145+ return new Mapping (fixedParentRestrictions , fixedMappings , fixedSourceList , fixedTargetList , newMap , newSourceList , newTargetList );
122146 }
123147
124148 public Mapping copy () {
125149 HashBiMap <Vertex , Vertex > newMap = HashBiMap .create (map );
126150 List <Vertex > newSourceList = new ArrayList <>(this .sourceList );
127151 List <Vertex > newTargetList = new ArrayList <>(this .targetList );
128- return new Mapping (fixedMappings , fixedSourceList , fixedTargetList , newMap , newSourceList , newTargetList );
152+ return new Mapping (fixedParentRestrictions , fixedMappings , fixedSourceList , fixedTargetList , newMap , newSourceList , newTargetList );
129153 }
130154
131155 public Mapping extendMapping (Vertex source , Vertex target ) {
@@ -135,7 +159,7 @@ public Mapping extendMapping(Vertex source, Vertex target) {
135159 newSourceList .add (source );
136160 List <Vertex > newTargetList = new ArrayList <>(this .targetList );
137161 newTargetList .add (target );
138- return new Mapping (fixedMappings , fixedSourceList , fixedTargetList , newMap , newSourceList , newTargetList );
162+ return new Mapping (fixedParentRestrictions , fixedMappings , fixedSourceList , fixedTargetList , newMap , newSourceList , newTargetList );
139163 }
140164
141165 public void forEachTarget (Consumer <? super Vertex > action ) {
@@ -168,6 +192,6 @@ public Mapping invert() {
168192 Vertex t = map .get (s );
169193 invertedMap .put (t , s );
170194 }
171- return new Mapping (invertedFixedMappings , fixedTargetList , fixedSourceList , invertedMap , targetList , sourceList );
195+ return new Mapping (fixedParentRestrictions , invertedFixedMappings , fixedTargetList , fixedSourceList , invertedMap , targetList , sourceList );
172196 }
173197}
0 commit comments