Package com.dtrules.samples.bookpreview.datamodel

Examples of com.dtrules.samples.bookpreview.datamodel.Book


    boolean chance(int percent){
        return randint(100)<=percent;
    }
   
    private Book newBook(){
        Book book = new Book();
        book.setPublisher(publishers[randint(publishers.length)]);
        int pages = randint(200)+200;
        book.setPages(pages);
        int start = 1;
        boolean excluded = false;
        while(start < pages){
            int end = randint(20)+20+start;            // Chapters are 20 to 40 pages
            if(pages-end < 10 || end >= pages) end = pages; // Okay, we fit in the last chapter
            Chapter c = new Chapter();                 // Set up the chapter
            c.setBegin_page(start);
            c.setEnd_page(end);
           
            book.getChapters().add(c);                 // Add the chapter, and
            start = end+1;                             //  set the start of the next chapter
     
            if(excluded){                              // We exclude the ending chapters randomly.
                book.getExcluded_chapters().add(c);
            }else{
               excluded = randint(100)>70;             // Once we start excluding, we exclude the rest.
            }
        }
       
        if(flip()||flip()){                            // Half the books get a day limit.
            book.setDay_limit((randint(5)+1)*30);      // Limit to 30, 60, 90, 120, or 180 days.
        }else{
            book.setDay_limit(0);
        }
        return book;
    }
View Full Code Here


        customer.getOpen_books().get(index).setBook(request.getBook()); // Make one of the open books match
                                                                        //   the request.
       
        for(int i=0; i<num_openbooks; i++){
            Open_Book  ob          = customer.getOpen_books().get(i);
            Book       b           = ob.getBook();
            int        pages_read  = randint(60);
            int        this_page   = randint(5)+1;
            Chapter    c           = b.getChapters().get(0);
           
            while(this_page < pages_read){
                if(b.getExcluded_chapters().contains(c)) break;
                if(this_page > pages_read)break;
                if(this_page <= c.getEnd_page()){
                    if(!ob.getChapters_viewed().contains(c)){
                        ob.getChapters_viewed().add(c);
                    }
                    Page page = new Page();
                    page.setNumber(this_page);
                    this_page += 1;
                    ob.getPages().add(page);
                }
                if(this_page > c.getEnd_page()){
                    for(Chapter n : b.getChapters()){
                        if(n.getBegin_page()<this_page && n.getEnd_page()>= this_page){
                            c = n;
                            break;
                        }
                    }
View Full Code Here

  boolean chance(int percent){
    return randint(100)<=percent;
  }
 
  private Book newBook(){
      Book book = new Book();
      book.setPublisher(publishers[randint(publishers.length)]);
      int pages = randint(200)+200;
      book.setPages(pages);
      int start = 1;
      boolean excluded = false;
      while(start < pages){
          int end = randint(20)+20+start;            // Chapters are 20 to 40 pages
          if(pages-end < 10 || end >= pages) end = pages; // Okay, we fit in the last chapter
          Chapter c = new Chapter();                 // Set up the chapter
          c.setBegin_page(start);
          c.setEnd_page(end);
         
          book.getChapters().add(c);                 // Add the chapter, and
          start = end+1;                             //  set the start of the next chapter
   
          if(excluded){                              // We exclude the ending chapters randomly.
              book.getExcluded_chapters().add(c);
          }else{
             excluded = randint(100)>70;             // Once we start excluding, we exclude the rest.
          }
      }
     
      if(flip()||flip()){                            // Half the books get a day limit.
          book.setDay_limit((randint(5)+1)*30);      // Limit to 30, 60, 90, 120, or 180 days.
      }else{
          book.setDay_limit(0);
      }
      return book;
  }
View Full Code Here

      customer.getOpen_books().get(index).setBook(request.getBook()); // Make one of the open books match
                                                                      //   the request.
     
      for(int i=0; i<num_openbooks; i++){
          Open_Book  ob          = customer.getOpen_books().get(i);
          Book       b           = ob.getBook();
          int        pages_read  = randint(60);
          int        this_page   = randint(5)+1;
          Chapter    c           = b.getChapters().get(0);
         
          while(this_page < pages_read){
              if(b.getExcluded_chapters().contains(c)) break;
              if(this_page > pages_read)break;
              if(this_page <= c.getEnd_page()){
                  if(!ob.getChapters_viewed().contains(c)){
                      ob.getChapters_viewed().add(c);
                  }
                  Page page = new Page();
                  page.setNumber(this_page);
                  this_page += 1;
                  ob.getPages().add(page);
              }
              if(this_page > c.getEnd_page()){
                  for(Chapter n : b.getChapters()){
                      if(n.getBegin_page()<this_page && n.getEnd_page()>= this_page){
                          c = n;
                          break;
                      }
                  }
View Full Code Here

  boolean chance(int percent){
    return randint(100)<=percent;
  }
 
  private Book newBook(){
      Book book = new Book();
      book.setPublisher(publishers[randint(publishers.length)]);
      int pages = randint(200)+200;
      book.setPages(pages);
      int start = 1;
      boolean excluded = false;
      while(start < pages){
          int end = randint(20)+20+start;            // Chapters are 20 to 40 pages
          if(pages-end < 10 || end >= pages) end = pages; // Okay, we fit in the last chapter
          Chapter c = new Chapter();                 // Set up the chapter
          c.setBegin_page(start);
          c.setEnd_page(end);
         
          book.getChapters().add(c);                 // Add the chapter, and
          start = end+1;                             //  set the start of the next chapter
   
          if(excluded){                              // We exclude the ending chapters randomly.
              book.getExcluded_chapters().add(c);
          }else{
             excluded = randint(100)>70;             // Once we start excluding, we exclude the rest.
          }
      }
     
      if(flip()||flip()){                            // Half the books get a day limit.
          book.setDay_limit((randint(5)+1)*30);      // Limit to 30, 60, 90, 120, or 180 days.
      }else{
          book.setDay_limit(0);
      }
      return book;
  }
View Full Code Here

      customer.getOpen_books().get(index).setBook(request.getBook()); // Make one of the open books match
                                                                      //   the request.
     
      for(int i=0; i<num_openbooks; i++){
          Open_Book  ob          = customer.getOpen_books().get(i);
          Book       b           = ob.getBook();
          int        pages_read  = randint(60);
          int        this_page   = randint(5)+1;
          Chapter    c           = b.getChapters().get(0);
         
          while(this_page < pages_read){
              if(b.getExcluded_chapters().contains(c)) break;
              if(this_page > pages_read)break;
              if(this_page <= c.getEnd_page()){
                  if(!ob.getChapters_viewed().contains(c)){
                      ob.getChapters_viewed().add(c);
                  }
                  Page page = new Page();
                  page.setNumber(this_page);
                  this_page += 1;
                  ob.getPages().add(page);
              }
              if(this_page > c.getEnd_page()){
                  for(Chapter n : b.getChapters()){
                      if(n.getBegin_page()<this_page && n.getEnd_page()>= this_page){
                          c = n;
                          break;
                      }
                  }
View Full Code Here

TOP

Related Classes of com.dtrules.samples.bookpreview.datamodel.Book

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.