diff --git a/.idea/misc.xml b/.idea/misc.xml
index ecfa09c..9902dc5 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -8,7 +8,7 @@
-
+
\ No newline at end of file
diff --git a/.idea/theorethische-informatik-gruppe-10.iml b/.idea/theorethische-informatik-gruppe-10.iml
new file mode 100644
index 0000000..d6ebd48
--- /dev/null
+++ b/.idea/theorethische-informatik-gruppe-10.iml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 4fde15a..8ee1354 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -5,14 +5,13 @@
-
-
+
+
+
-
-
-
+
@@ -42,36 +41,6 @@
"second": "e0c4ebfe-e254-4a34-93d3-a6ee2cb18f94"
}
}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -134,6 +103,13 @@
+
+
+
+
+
+
+
diff --git a/src/main/java/ab1/impl/GRUPPE/NFAImpl.java b/src/main/java/ab1/impl/GRUPPE/NFAImpl.java
index 8fd9b1e..69ac215 100644
--- a/src/main/java/ab1/impl/GRUPPE/NFAImpl.java
+++ b/src/main/java/ab1/impl/GRUPPE/NFAImpl.java
@@ -101,6 +101,39 @@ public class NFAImpl implements NFA {
if (!this.isFinalized || !other.isFinalized()) {
throw new FinalizedStateException();
}
+ // new initialState with epsilon to initialState of this and other.
+ // Problem: what if states are called the same in this and other + what do we use as initialState?
+ Set unionStates = new HashSet<>();
+ unionStates.addAll(this.states);
+
+ //do the union:
+ String start = changeIfNecessary(changeIfNecessary("START", unionStates), other.getStates());
+
+
+
+
+ for(String state : other.getStates()){
+ if(!unionStates.contains(state)){
+ unionStates.add(state);
+ }else{
+ // a state of other has the same name as one in this.
+ //change name of state and every Transitions it is a part of in other
+ String newstate = state;
+ while (unionStates.contains(newstate)){
+ //change the state slightly and save the different version
+ newstate = newstate+"|";
+ }
+ for(Transition transition : other.getTransitions()){
+ if(transition.fromState().equals(state)){
+ Transition changedTransition = new Transition(newstate, transition.readSymbol(), transition.toState());
+ }
+ if(transition.toState().equals(state)){
+ Transition changedTransition = new Transition(transition.fromState(), transition.readSymbol(), newstate);
+ }
+ }
+ unionStates.add(newstate);
+ }
+ }
NFAImpl unionNFA = new NFAImpl(this.initialState);
unionNFA.states.addAll(this.states);
@@ -392,4 +425,11 @@ public class NFAImpl implements NFA {
return Integer.toString(dfaStates.indexOf(set));
}
+ private String changeIfNecessary(String str, Set toCheck){
+ while(toCheck.contains(str)){
+ str = str+"|";
+ }
+ return str;
+ }
+
}