FileDocCategorySizeDatePackage
PropertiesVocabSource.javaAPI DocApache Struts 2.0.9 Apps2455Mon Jul 23 13:43:26 BST 2007org.apache.struts2.showcase.hangman

PropertiesVocabSource

public class PropertiesVocabSource extends Object implements VocabSource

Fields Summary
private Properties
prop
private List
vocabs
Constructors Summary
public PropertiesVocabSource()

    
public PropertiesVocabSource(Properties prop)

        assert(prop != null);
        this.prop = prop;
        vocabs = readVocab(prop);
    
Methods Summary
public VocabgetRandomVocab()

        if (vocabs == null) {
            throw new HangmanException(HangmanException.Type.valueOf("NO_VOCAB_SOURCE"), "No vocab source");
        }
        if (vocabs.size() <= 0) {
            throw new HangmanException(HangmanException.Type.valueOf("NO_VOCAB"), "No vocab");
        }
        long vocabIndex = Math.round((Math.random() * (double)prop.size()));
        vocabIndex = vocabIndex == vocabs.size() ? vocabs.size() - 1 : vocabIndex;
        return vocabs.get((int)vocabIndex);
    
protected java.util.ListreadVocab(java.util.Properties prop)

        List<Vocab> vocabList = new ArrayList<Vocab>();

        for (Map.Entry e : prop.entrySet()) {
            String vocab = (String) e.getKey();
            String hint = (String) e.getValue();

            vocabList.add(new Vocab(vocab, hint));
        }
        return vocabList;
    
public voidsetVocabProperties(java.util.Properties prop)

        assert(prop != null);
        this.prop = prop;
        vocabs = readVocab(prop);