你的意思是这样的吗?
public class Lexicon {
class State {
public long count = 0;
public long stateNo;
public Set<Arc> arcs;
}
class Arc {
public char character;
public State destState;
public Set<String> letters;
}
Set<State> states = new HashSet<State>();
public void update(long stateNo, char character, String letter) {
for (State state : states) {
if(state.stateNo == stateNo) {
for (Arc arc : state.arcs) {
if (arc.character == character) {
arc.letters.add(letter);
break;
}
}
break;
}
}
}
}
如果是这样,您最好使用地图集合重写它:
public class Lexicon {
class State {
public long count = 0;
public long stateNo;
public Map<Character, Arc> arcs;
public void updateArc(char character, String letter) {
Arc arc = arcs.get(character);
if (arc != null) {
arc.letters.add(letter);
}
}
}
class Arc {
public char character;
public State destState;
public Set<String> letters;
}
Map<Long, State> states = new HashMap<Long, State>();
public void update(long stateNo, char character, String letter) {
State state = states.get(stateNo);
if (state != null) {
state.updateArc(character, letter);
}
}
}
Of course this is draft only and you heave to initialize all collections.
Also all fields are declared as public only for clarity of example.