1 package db; 8 9 import java.util.*; 10 11 import org.ozoneDB.OzoneInterface; 12 import org.ozoneDB.OzoneObject; 13 14 15 public class FortuneGeneratorImpl extends OzoneObject implements FortuneGenerator { 16 17 public static final long serialVersionUID = 1L; 18 private List fortunes; 19 Random randomizer; 20 21 public static FortuneGenerator create(OzoneInterface db) { 22 return (FortuneGenerator) db.createObject(FortuneGeneratorImpl.class, 23 OzoneInterface.Public, 24 FortuneGenerator.class.getName()); 25 } 26 27 public FortuneGeneratorImpl() { 28 init(); 29 } 30 31 public String getFortune() { 32 System.out.println("[FortuneGeneratorImpl] getting fortune"); 33 return (String ) fortunes.get(randomizer.nextInt(fortunes.size())); 34 } 35 36 public void addFortune(String fortune) { 37 System.out.println("[FortuneGeneratorImpl] adding fortune"); 38 fortunes.add(fortune); 39 } 40 41 public void removeFortunes() { 42 System.out.println("[FortuneGeneratorImpl] removing fortunes"); 43 init(); 44 } 45 46 public List getAllFortunes() { 47 System.out.println("[FortuneGeneratorImpl] getting all fortunes"); 48 return fortunes; 49 } 50 51 private void init() { 52 fortunes = new ArrayList(); 53 randomizer = new Random(); 54 fortunes.add("I like work ... I can sit and watch it for hours."); 55 fortunes.add("Nihilism should commence with oneself."); 56 fortunes.add("Ah say, son, you're about as sharp as a bowlin' ball."); 57 fortunes.add("Yield to Temptation ... it may not pass your way again."); 58 } 59 } 60 | Popular Tags |