progress of 7/1

This commit is contained in:
Walcher 2024-01-07 17:50:17 +01:00
parent 0c0dd043ec
commit 84fa1cf9d7
2 changed files with 29 additions and 26 deletions

View file

@ -3,6 +3,7 @@ package ab1.impl.GRUPPE;
import ab1.FinalizedStateException;
import ab1.NFA;
import ab1.Transition;
import lombok.Getter;
import java.util.Collection;
import java.util.HashSet;
@ -11,16 +12,24 @@ import java.util.Set;
public class NFAImpl implements NFA {
private Set<String> states;
private Set<Transition> transitions;
private String initialState;
private Set<String> acceptingStates;
@Getter
private Set<Character> alphabet;
private boolean isFinalized;
public NFAImpl(String startState) {
this.initialState = startState;
this.states = new HashSet<>();
this.states.add(startState);
this.transitions = new HashSet<>();
this.acceptingStates = new HashSet<>();
this.alphabet = new HashSet<>();
this.isFinalized = false;
}
@Override
@ -34,7 +43,6 @@ public class NFAImpl implements NFA {
@Override
public Set<String> getAcceptingStates() {
return this.acceptingStates;
}
@ -48,6 +56,8 @@ public class NFAImpl implements NFA {
if (this.isFinalized) {
throw new FinalizedStateException();
} else if (!this.transitions.contains(transition)) {
// add symbol to alphabet. If it is already in the alphabet, nothing happens
this.alphabet.add(transition.readSymbol());
this.transitions.add(transition);
}
}
@ -57,29 +67,11 @@ public class NFAImpl implements NFA {
if (this.isFinalized) {
throw new FinalizedStateException();
} else if (!this.states.contains(state)) {
this.states.add(state);
this.acceptingStates.add(state);
}
}
// warum gabs die methode nicht schon vorher? weil i a idiot bin und man die direct adden kann.
/*
public void addAllStates(Set<String> states) throws FinalizedStateException {
if (this.isFinalized) {
throw new FinalizedStateException();
} else {
this.states.addAll(states);
}
}
public void addAllTransitions(Set<Transition> transitions) throws FinalizedStateException {
if (this.isFinalized) {
throw new FinalizedStateException();
} else {
this.transitions.addAll(transitions);
}
}
*/
// #TODO
@Override
public NFA union(NFA other) throws FinalizedStateException {
@ -155,14 +147,23 @@ public class NFAImpl implements NFA {
// #TODO
@Override
public NFA complement() throws FinalizedStateException {
if(!this.isFinalized){
throw new FinalizedStateException();
}
NFAImpl complementNFA = new NFAImpl(this.initialState);
complementNFA.states.addAll(this.states);
complementNFA.transitions.addAll(this.transitions);
/*
for(String state : this.states){
}
*/
return null;
}
public void turnNFAIntoDFA(NFAImpl nfa) {
// #TODO
}
@Override
public boolean isFinalized() {
return isFinalized;
@ -176,7 +177,9 @@ public class NFAImpl implements NFA {
// #TODO
@Override
public boolean isFinite() {
//check if finite
//transitions={fromState==toState}
//states={A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z}
//obergrenze = anzahl der states (26)
return false;
}