ListIterator<Book> iter = books.listIterator(); while(iter.hasNext()){ if(iter.next().getIsbn().equals(isbn)){ iter.add(new Book(...)); } }
@RequestMapping("/book/**") @Controller public class BookController { @RequestMapping(value = "/book", method = RequestMethod.POST) public String create( @ModelAttribute("bookCommand") final BookCommand bookCommand) { Book book = createBookFromBookCommand(bookCommand); return "redirect:/book/" + book.getId(); } @RequestMapping(value = "/book/form", method = RequestMethod.GET) public String createForm(final ModelMap modelMap) { modelMap.addAttribute("all", "what you need"); return "book/create"; //book/create.jsp } }
//convert string to JSONArray jsonArray = new JSONArray(bufferString); //parse an Object from a random index in the JSONArray JSONObject anObject = jsonArray.getJSONObject(randomNum); Book aBook = new Book(); aBook.setTitle((String) anObject.get("title")); //you can continue to set the different attributes of the Book object using key/value pairs from the Book class (e.g. setPageNum, setChapter, etc).
@Override public String toString() { return getCreator() + " - " + getTitle(); } }
protected void doPrint(boolean useBook) { RectangleThingy rectangleThingy = new RectangleThingy(); System.out.println("doPrint("+useBook+")"); try { PrinterJob printJob = PrinterJob.getPrinterJob(); if (useBook) { Book book = new Book(); book.append(rectangleThingy, getMinimumMarginPageFormat(printJob)); printJob.setPageable(book); } else { printJob.setPrintable(rectangleThingy); } if (printJob.printDialog()) printJob.print(); } catch(PrinterException pe) { System.out.println("Error printing: " + pe); } }
var book = new Book ("t", "a", "i", 10, 10); var json = book.toJson (); alert (json); //prints: {"title":"t","author":"a","isbn":"i","price":10,"stock":10} var book = Book.fromJson (json); alert (book.title); //prints: t
Observable .from(books) .map(new Func1<Book, Book>() { @Override public Book call(Book b) { if (book.getId().equals(b.getId())) return book; return b; } }) .toList() .subscribe();
Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create(); String json = gson.toJson(new Book());
book = new Book(); books = service.list();
HashMap<String, Book> books = new HashMap<String, Book>(); // String is the type of the index (the key) // and Book is the type of the elements (the values) // Like with an arraylist: ArrayList<Book> books = ...; // Now you have to store the elements with a string key: books.put("Harry Potter III", new Book("JK Rownling", 456, "Harry Potter")); // Now you can access the elements by using a String index Book book = books.get("Harry Potter III");
@XmlRootElement @XmlSeeAlso({Book.class}) public class Books extends ArrayList<Book> { public Books() { this.add(new Book("The Sign of the Four")); } @XmlElement(name = "book") public List<Book> getBooks() { return this; } }
@Path("/books") @Produces({"application/xml", "application/json"}) public class Bookstore { @AddLinks @LinkResource(value = Book.class) @GET @Formatted public Collection<Book> getBooks() { List<Book> books = new ArrayList<>(); books.add(new Book("Book", "Author")); return books; } }
Book book = new Book("Book One", "Author One"); booksDB.put(idCounter.incrementAndGet(), book); book = new Book("Book Two", "Author Two"); booksDB.put(idCounter.incrementAndGet(), book); book = new Book("Book Three", "Author Three"); booksDB.put(idCounter.incrementAndGet(), book); book = new Book("Book Four", "Author Four"); booksDB.put(idCounter.incrementAndGet(), book); book = new Book("Book Five", "Author Five"); booksDB.put(idCounter.incrementAndGet(), book);
public class BookCollection { public static final int MAX_COUNT = 20; private int count = 0; private Book[] books = new Book[MAX_COUNT]; public Book createBook(String nameP, String authorP, String genreP, int ratingP, int iDP, Boolean onLoanP) { books[count] = new Book(nameP, authorP, genreP, ratingP, iDP, onLoanP); return books[count++]; } public Book[] getBooks() { return books; } }
Book book = new Book(); book.Chapters = 50; book.OneBasedBookID = 1; book.Long = "Bahai"; book.Short = "ba"; book.Color = c; book.BookType = b; this.add(book);
Book myBooks0, myBooks1, myBooks2; myBooks0 = new Book(); myBooks1 = new Book(); myBooks2 = new Book(); myBooks0.title = "Example title xx"; myBooks1.title = "Example title cc"; myBooks2.title = "Example title yy"; myBooks0.author = "Example author xx"; myBooks1.author = "Example author cc"; myBooks2.author = "Example author yy";
ICsvBeanReader mockedBeanReader = mock(CsvBeanReader.class); Book book1 = new Book(); Book book2 = new Book(); Book book3 = new Book(); when(mockedBeanReader.getHeader(true)) .thenReturn(new String[]{"here", "is", "header"}); when(mockedBeanReader.read(Book.class, header, processors)) .thenReturn(book1) .thenReturn(book2) .thenReturn(book3);