77import java .util .ArrayList ;
88import java .util .Collections ;
99import java .util .List ;
10+ import java .util .Map ;
1011import java .util .function .BiConsumer ;
1112import java .util .function .Consumer ;
1213
2021public class Mapping {
2122
2223
24+ private final Map <Vertex , Vertex > fixedParentRestrictions ;
2325 private final BiMap <Vertex , Vertex > fixedMappings ;
2426 private final List <Vertex > fixedSourceList ;
2527 private final List <Vertex > fixedTargetList ;
@@ -28,12 +30,14 @@ public class Mapping {
2830 private final List <Vertex > sourceList ;
2931 private final List <Vertex > targetList ;
3032
31- private Mapping (BiMap <Vertex , Vertex > fixedMappings ,
33+ private Mapping (Map <Vertex , Vertex > fixedParentRestrictions ,
34+ BiMap <Vertex , Vertex > fixedMappings ,
3235 List <Vertex > fixedSourceList ,
3336 List <Vertex > fixedTargetList ,
3437 BiMap <Vertex , Vertex > map ,
3538 List <Vertex > sourceList ,
3639 List <Vertex > targetList ) {
40+ this .fixedParentRestrictions = fixedParentRestrictions ;
3741 this .fixedMappings = fixedMappings ;
3842 this .fixedSourceList = fixedSourceList ;
3943 this .fixedTargetList = fixedTargetList ;
@@ -42,9 +46,26 @@ private Mapping(BiMap<Vertex, Vertex> fixedMappings,
4246 this .targetList = targetList ;
4347 }
4448
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 ());
49+ public static Mapping newMapping (Map <Vertex , Vertex > fixedParentRestrictions ,
50+ BiMap <Vertex , Vertex > fixedMappings ,
51+ List <Vertex > fixedSourceList ,
52+ List <Vertex > fixedTargetList ) {
53+ return new Mapping (
54+ fixedParentRestrictions ,
55+ fixedMappings ,
56+ fixedSourceList ,
57+ fixedTargetList ,
58+ HashBiMap .create (),
59+ Collections .emptyList (),
60+ Collections .emptyList ());
61+ }
62+
63+ public boolean hasParentRestriction (Vertex v ) {
64+ return fixedParentRestrictions .containsKey (v );
65+ }
4766
67+ public Vertex getParentRestriction (Vertex v ) {
68+ return fixedParentRestrictions .get (v );
4869 }
4970
5071 public Vertex getSource (Vertex target ) {
@@ -118,14 +139,14 @@ public Mapping copyMappingWithLastElementRemoved() {
118139 newMap .remove (this .sourceList .get (this .sourceList .size () - 1 ));
119140 List <Vertex > newSourceList = new ArrayList <>(this .sourceList .subList (0 , this .sourceList .size () - 1 ));
120141 List <Vertex > newTargetList = new ArrayList <>(this .targetList .subList (0 , this .targetList .size () - 1 ));
121- return new Mapping (fixedMappings , fixedSourceList , fixedTargetList , newMap , newSourceList , newTargetList );
142+ return new Mapping (fixedParentRestrictions , fixedMappings , fixedSourceList , fixedTargetList , newMap , newSourceList , newTargetList );
122143 }
123144
124145 public Mapping copy () {
125146 HashBiMap <Vertex , Vertex > newMap = HashBiMap .create (map );
126147 List <Vertex > newSourceList = new ArrayList <>(this .sourceList );
127148 List <Vertex > newTargetList = new ArrayList <>(this .targetList );
128- return new Mapping (fixedMappings , fixedSourceList , fixedTargetList , newMap , newSourceList , newTargetList );
149+ return new Mapping (fixedParentRestrictions , fixedMappings , fixedSourceList , fixedTargetList , newMap , newSourceList , newTargetList );
129150 }
130151
131152 public Mapping extendMapping (Vertex source , Vertex target ) {
@@ -135,7 +156,7 @@ public Mapping extendMapping(Vertex source, Vertex target) {
135156 newSourceList .add (source );
136157 List <Vertex > newTargetList = new ArrayList <>(this .targetList );
137158 newTargetList .add (target );
138- return new Mapping (fixedMappings , fixedSourceList , fixedTargetList , newMap , newSourceList , newTargetList );
159+ return new Mapping (fixedParentRestrictions , fixedMappings , fixedSourceList , fixedTargetList , newMap , newSourceList , newTargetList );
139160 }
140161
141162 public void forEachTarget (Consumer <? super Vertex > action ) {
@@ -168,6 +189,6 @@ public Mapping invert() {
168189 Vertex t = map .get (s );
169190 invertedMap .put (t , s );
170191 }
171- return new Mapping (invertedFixedMappings , fixedTargetList , fixedSourceList , invertedMap , targetList , sourceList );
192+ return new Mapping (fixedParentRestrictions , invertedFixedMappings , fixedTargetList , fixedSourceList , invertedMap , targetList , sourceList );
172193 }
173194}
0 commit comments