Javaがハッシュマップからgetメソッドを呼び出すと、Javaはequals()比較を実行しますか?
私はそれを読んだことがありますが、私が得ているエラーでは、== 比較を行っているようです。
public class UniversalFiniteStateAutomaton {
State currentState;
State initialState;
State trapState;
public UniversalFiniteStateAutomaton(ArrayList<String> finalStates,
ArrayList<String> transitions) {
String statesAndTransitions[];
Map<Symbol<E>, State> createdStates = new HashMap<Symbol<E>, State>();
for (String s : transitions) {
// Replace the stuff that doesn't matter
s = s.replaceAll("[()]", "");
// Split the transition into states and transitions
statesAndTransitions = s.split("\\s+");
// Create the state if its not already created
if (finalStates.contains(new Symbol(statesAndTransitions[0]))) {
if (!createdStates.containsKey((new Symbol(statesAndTransitions[0])))) {
createdStates.put(new Symbol(statesAndTransitions[0]),
new FinalState(this));
System.out.println("Created one symb " + new Symbol(statesAndTransitions));
}
} else {
if (!createdStates.containsKey(new Symbol(statesAndTransitions[0]))) {
createdStates.put(new Symbol(statesAndTransitions[0]),
new NormalState(this));
System.out.println("Created one symb " + new Symbol(statesAndTransitions[0]));
}
}
// Make sure that the next state is created
if (finalStates.contains(new Symbol(statesAndTransitions[2]))) {
if (!createdStates.containsKey(new Symbol(statesAndTransitions[2]))) {
createdStates.put(new Symbol(statesAndTransitions[2]),
new FinalState(this));
}
} else {
if (!createdStates.containsKey(new Symbol(statesAndTransitions[2]))) {
createdStates.put(new Symbol(statesAndTransitions[2]),
new NormalState(this));
}
}
System.out.println(createdStates);
// Define the transition
createdStates.get(new Symbol(statesAndTransitions[0])).addTransition(
new Symbol(statesAndTransitions[1]),
createdStates.get(new Symbol(statesAndTransitions[2])));
}
this.currentState = createdStates.get(new Symbol("0"));
}
public String analyzeInput(String input) {
String splitInput[] = input.split("\\s+");
for(String s: splitInput)
try {
currentState.transition(new Symbol(s));
} catch (TrapException e) {
return("Reject");
}
if(currentState.type()==0)
return "Accept";
return "Reject";
}
public void setState(State currentState) {
this.currentState = currentState;
}
}
public class Symbol<E> {
private E symbol;
public Symbol(E symbol){
this.symbol = symbol;
}
public E getSymbol() {
return symbol;
}
public void setSymbol(E symbol) {
this.symbol = symbol;
}
public String toString(){ return "" +symbol;}
}