private boolean iterateForGrammarProductions(Production production) {
	Set<Terminal> firstSet = firstGrammar.get(production.getName());
	int startLength = firstSet.size();
	if (production.isEmpty()) {
	    /* rule 3 */
	    firstSet.add(EmptyTerminal.getInstance());
	} else {
	    /* rule 2 */
	    for (Construction construction : production.getConstructions()) {
		if (construction.isTerminal()) {
		    firstSet.add((Terminal) construction);
		    // terminal is found and there is nothing to proceed...
		    break;
		}
		Set<Terminal> terminals = firstGrammar.get(construction.getName());
		if (terminals == null) {
		    continue;
		}
		firstSet.addAll(terminals);
		if (!terminals.contains(EmptyTerminal.getInstance())) {
		    break;
		}
	    }
	}
	return (startLength != firstSet.size());
    }
private boolean iterateForGrammarProductions ( Production production ) { Set < Terminal > firstSet = firstGrammar . get ( production . getName ( ) ) ; int startLength = firstSet . size ( ) ; if ( production . isEmpty ( ) ) { firstSet . add ( EmptyTerminal . getInstance ( ) ) ; } else { for ( Construction construction : production . getConstructions ( ) ) { if ( construction . isTerminal ( ) ) { firstSet . add ( ( Terminal ) construction ) ; break ; } Set < Terminal > terminals = firstGrammar . get ( construction . getName ( ) ) ; if ( terminals == null ) { continue ; } firstSet . addAll ( terminals ) ; if ( ! terminals . contains ( EmptyTerminal . getInstance ( ) ) ) { break ; } } } return ( startLength != firstSet . size ( ) ) ; }
This is rule 2 from Dragon Book: