1 7 package com.inversoft.verge.examples.madlib; 8 9 10 import java.util.ArrayList ; 11 import java.util.List ; 12 import java.util.SortedSet ; 13 import java.util.TreeSet ; 14 15 16 24 public class MadLib { 25 26 private String rawText; 27 private List fillins; 28 private MadLibFillin[] display; 29 private int numberOfWords; 30 private int numberOfNumbers; 31 32 33 40 public MadLib(String rawText, List fillins) { 41 this.rawText = rawText; 42 this.fillins = fillins; 43 44 SortedSet set = new TreeSet (fillins); 45 this.display = (MadLibFillin []) set.toArray(new MadLibFillin[set.size()]); 46 47 this.numberOfNumbers = 0; 49 this.numberOfWords = 0; 50 for (int i = 0; i < display.length; i++) { 51 if (display[i].isWord()) { 52 numberOfWords++; 53 } else { 54 numberOfNumbers++; 55 } 56 } 57 } 58 59 60 65 public String getRawText() { 66 return rawText; 67 } 68 69 74 public int getNumberOfNumbers() { 75 return numberOfNumbers; 76 } 77 78 83 public int getNumberOfWords() { 84 return numberOfWords; 85 } 86 87 93 public MadLibFillin getMadLibFillin(int index) { 94 if (index < 0 || index > fillins.size()) { 95 return null; 96 } 97 98 return (MadLibFillin) fillins.get(index); 99 } 100 101 107 public List getRawMadLibFillins() { 108 return new ArrayList (fillins); 109 } 110 111 117 public MadLibFillin [] getDisplayMadLibFillins() { 118 return display; 119 } 120 121 128 public MadLibFillin getMadLibFillin(int index, boolean word) { 129 MadLibFillin fillin = null; 130 for (int i = 0; i < display.length; i++) { 131 if (display[i].getIndex() == index && display[i].isWord() == word) { 132 fillin = display[i]; 133 } 134 } 135 136 return fillin; 137 } 138 } | Popular Tags |