//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).
@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 } }
@GET public Collection<Book> getBooks() { List<Book> outBooks = new ArrayList<>(); for (Book book : bookRepo.getBooks()) { Book outBook = new Book(); outBook.setId(book.getId()); outBook.setTitle(book.getTitle()); outBook.setCreator(book.getCreator()); outBooks.add(outBook); } return outBooks; }
if (cursor.moveToFirst()) { do { Book book = new Book();//here book.setId(cursor.getString(cursor.getColumnIndex("id"))); book.setTitle(cursor.getString(cursor.getColumnIndex("title"))); book.setDescription(cursor.getString(cursor.getColumnIndex("description"))); bookList.add(book); } while (cursor.moveToNext()); }
public Book parse(Document doc) throws XPathExpressionException, URISyntaxException { Book book = new Book(); String id = xpath.evaluate("//pgterms:ebook/@rdf:about", doc); book.setId(id); book.setTitle(xpath.evaluate("//dcterms:title/text()", doc)); book.setCreator(xpath.evaluate("//dcterms:creator//pgterms:name/text()", doc)); NodeList files = (NodeList)xpath.evaluate("//pgterms:file", doc, XPathConstants.NODESET); //NodeList subjects = (NodeList)xpath.evaluate("//dcterms:subject/rdf:Description/rdf:value", doc, XPathConstants.NODESET); for (int c = 0; c < files.getLength(); c++) { Format format = parseFormat((Element)files.item(c)); if (format.getMediaType().startsWith("image")) { book.setCover(format.getFile()); } book.getFormats().add(format); } /* for (int c = 0; c < subjects.getLength(); c++) { Element subjectEl = (Element)subjects.item(c); book.getSubjects().add(new Subject(subjectEl.getTextContent())); } */ return book; }
Book book = new Book(); book.setId(1); book.setDescription("Mastering the Behavior Driven Development with " + "Ruby on Rails"); book.setTitle("Mastering the BDD"); book.setPrice(25.9f); book.setNumberofpage(1029); assertNotNull("ID should not be null", book.getId());
ListIterator<Book> iter = books.listIterator(); while(iter.hasNext()){ if(iter.next().getIsbn().equals(isbn)){ iter.add(new Book(...)); } }
@Override public void execute(Realm realm) { Book book = new Book(); book.setId(1); book.setAuthor("Reto Meier"); book.setTitle("Android 4 Application Development"); book.setImageUrl("http://api.androidhive.info/images/realm/1.png"); realm.insertOrUpdate(book); book.setId(2); book.setAuthor("Itzik Ben-Gan"); book.setTitle("Microsoft SQL Server 2012 T-SQL Fundamentals"); book.setImageUrl("http://api.androidhive.info/images/realm/2.png"); realm.insertOrUpdate(book); book.setId(3); book.setAuthor("Magnus Lie Hetland"); book.setTitle("Beginning Python: From Novice To Professional Paperback"); book.setImageUrl("http://api.androidhive.info/images/realm/3.png"); realm.insertOrUpdate(book); book.setId(4); book.setAuthor("Chad Fowler"); book.setTitle("The Passionate Programmer: Creating a Remarkable Career in Software Development"); book.setImageUrl("http://api.androidhive.info/images/realm/4.png"); realm.insertOrUpdate(book); book.setId(5); book.setAuthor("Yashavant Kanetkar");
List<Book> list = new ArrayList<Book>(); // populate list with the results got from database while(this.results.next()) { Book book = new Book(); book.setBookID(this.results.getInt("bookID")); book.setTitle(this.results.getString("title")); book.setAuthor(this.results.getString("author")); book.setPages(this.results.getInt("pages")); list.add(book); } // set the List of Book as request attribute request.setAttribute("list",list); // forward the request to the JSP page RequestDispatcher view = request.getRequestDispatcher("view.jsp"); view.forward(request, response);
@Override public Book deserialize(final JsonElement json, final Type typeOfT, final JsonDeserializationContext context) throws JsonParseException { final JsonObject jsonObject = json.getAsJsonObject(); final JsonElement jsonTitle = jsonObject.get("title"); final String title = jsonTitle.getAsString(); final String isbn10 = jsonObject.get("isbn-10").getAsString(); final String isbn13 = jsonObject.get("isbn-13").getAsString(); final JsonArray jsonAuthorsArray = jsonObject.get("authors").getAsJsonArray(); final String[] authors = new String[jsonAuthorsArray.size()]; for (int i = 0; i < authors.length; i++) { final JsonElement jsonAuthor = jsonAuthorsArray.get(i); authors[i] = jsonAuthor.getAsString(); } final Book book = new Book(); book.setTitle(title); book.setIsbn10(isbn10); book.setIsbn13(isbn13); book.setAuthors(authors); return book; } }
public class Book implements Comparable<Book> { public int compareTo(Book otherBook) { return title.compareTo(otherBook.getTitle()); } }
byte[] bin = some binary data... Book b = new Book(); b.setAuthor("John"); b.setTitle("wild stuff"); b.setYear(2012); MultiPart multiPart = new MultiPart(); multiPart.bodyPart(new BodyPart(b, MediaType.APPLICATION_XML_TYPE)); multiPart.bodyPart(new BodyPart(bin, MediaType.APPLICATION_OCTET_STREAM_TYPE)); response = service.path("rest").path("multipart"). type(MultiPartMediaTypes.MULTIPART_MIXED). post(ClientResponse.class, multiPart);
Book book = new Book(); book.setId(bookRecord.getId()); book.setFirstname(bookRecord.getFirstname());
// create manager and two example books SimpleBookManager manager = new SimpleBookManager(); Book harryPotter1 = manager.createBook(); Book harryPotter2 = manager.createBook(); harryPotter1.setAuthor("JK Rowling"); harryPotter1.setCourse("Harry Potter Kunskap"); harryPotter1.setPrice(199); harryPotter1.setTitle("Harry Potter and the philosifer Stone"); harryPotter1.setIsbn("9780590353403"); harryPotter2.setAuthor("JK Rowling"); harryPotter2.setCourse("Harry Potter Kunskap"); harryPotter2.setPrice(299); harryPotter2.setTitle("Harry Potter and snake"); harryPotter2.setIsbn("0439064872"); // let's use an intent to parcel the manager to Intent intent = new Intent(); intent.putExtra("extra_book_manager", manager); // read the parcelled manager back from the intent SimpleBookManager parcelledManager = intent.getParcelableExtra("extra_book_manager");
public class BookService { @Inject private NumberGenerator numberGenerator; private Date instanciationDate; @PostConstruct private void setInstanciationDate() { instanciationDate = new Date(); } public Book createBook(String title, String description, double price) { Book book = new Book(title, description, price); book.setId(numberGenerator.generateNumber()); book.setDate(instanciationDate); return book; } }