public static void main(String[] args) { Book book1 = new JavaTitleBook(new ProgrammingBook()); System.out.println(book1.getName()); Book book2 = new PHPTitleBook(new ProgrammingBook()); System.out.println(book2.getName()); }
// 도서 등록 public int InsertData(Book bean) { System.out.println(bean.toString()); String sql = "insert into books(bookcode, name, volume, writer, publisher, pubdate, genre, image, bookstat, bookstory) "; sql += " values(bookseq.nextval, ?, ?, ?, ?, to_date(?, 'yyyy/MM/dd'), ?, ?, default, ?) "; PreparedStatement pstmt = null; int cnt = -99999; try { if (conn == null) { super.conn = super.getConn(); } conn.setAutoCommit(false); pstmt = super.conn.prepareStatement(sql); pstmt.setString(1, bean.getName()); pstmt.setInt(2, bean.getVolume()); pstmt.setString(3, bean.getWriter()); pstmt.setString(4, bean.getPublisher()); pstmt.setString(5, bean.getPubdate()); pstmt.setString(6, bean.getGenre()); // 책 이미지 이름은 책 제목과 책 볼륨의 문자열 조합이다. String image = bean.getName() + " " + bean.getVolume() + ".jpg"; pstmt.setString(7, image); // pstmt.setString(8, bean.getBookstat()); pstmt.setString(8, bean.getBookstory()); cnt = pstmt.executeUpdate(); conn.commit(); } catch (Exception e) { SQLException err = (SQLException) e; cnt = -err.getErrorCode(); e.printStackTrace(); try { conn.rollback(); } catch (Exception e2) { e2.printStackTrace(); } } finally { try { if (pstmt != null) { pstmt.close(); } super.closeConn(); } catch (Exception e2) { e2.printStackTrace(); } } return cnt; }
public static String XMLContent(List<Book> books, Writer writer) { XmlSerializer serializer = Xml.newSerializer(); try { serializer.setOutput(writer); serializer.startDocument("UTF-8", true); serializer.startTag("", "books"); for (Book book : books) { serializer.startTag("", "book"); serializer.attribute("", "id", String.valueOf(book.getId())); serializer.startTag("", "name"); serializer.text(book.getName()); serializer.endTag("", "name"); serializer.startTag("", "price"); serializer.text(String.valueOf(book.getPrice())); serializer.endTag("", "price"); serializer.endTag("", "book"); } serializer.endTag("", "books"); serializer.endDocument(); return writer.toString(); } catch (Exception e) { e.printStackTrace(); } return null; }
@Test public void testSetorGetName() { String name = "Book"; Book test = new Book(null); test.setName(name); assertEquals(name, test.getName()); }
public List<Book> findAllBooksByName(String name) { List<Book> results = new ArrayList<Book>(); for (Book k : BookList) { if (k.getName().equals(name)) { results.add(k); } } return results; }
public synchronized boolean equals(java.lang.Object obj) { if (!(obj instanceof Book)) return false; Book other = (Book) obj; if (obj == null) return false; if (this == obj) return true; if (__equalsCalc != null) { return (__equalsCalc == obj); } __equalsCalc = obj; boolean _equals; _equals = true && this.id == other.getId() && ((this.name == null && other.getName() == null) || (this.name != null && this.name.equals(other.getName()))); __equalsCalc = null; return _equals; }
public static void main(String args[]) { Author schildt = new Author("Herbert Schildt", "*****@*****.**"); System.out.println(schildt.getName() + " at " + schildt.getEmail()); Author bjarne = new Author("Bjarne Stroustrup"); bjarne.setEmail("*****@*****.**"); bjarne.print(); Book b1 = new Book("Teach Yourself C++", schildt); b1.setPrice(150.5); b1.setStock(50); System.out.println( "Author: " + b1.getAuthorName() + " Name: " + b1.getName() + " Price: " + b1.getPrice() + " Stock: " + b1.getStock()); b1.borrowBook(20); b1.returnBook(10); System.out.println( "Author: " + b1.getAuthorName() + " Name: " + b1.getName() + " Price: " + b1.getPrice() + " Stock: " + b1.getStock()); Book b2 = new Book("The C++ Programming Language", bjarne, 200, 20); b2.print(); b2.returnBook(10); b2.borrowBook(50); b2.print(); b1.getAuthor().print(); b2.getAuthor().print(); }
public static void main(String[] args) { BookShelf bookShelf = new BookShelf(4); bookShelf.appendBook(new Book("Around the World in 80 Days")); bookShelf.appendBook(new Book("Bible")); bookShelf.appendBook(new Book("Cinderella")); bookShelf.appendBook(new Book("Daddy-Long-Legs")); Iterator it = bookShelf.iterator(); while (it.hasNext()) { Book book = (Book) it.next(); System.out.println(book.getName()); } }
public static void main(String[] args) { System.setProperty("fr.umlv.jbucks.factory", BuckFactoryImpl.class.getName()); BuckFactory factory = BuckFactory.getFactory(); Book book = factory.createBook("test"); System.out.println(book.getName()); book.setUserData("hello-UID", "12345"); System.out.println("hello-UID " + book.getUserDataValue("hello-UID")); EventManager manager = factory.getEventManager(); manager.addListener( Book.class, "accounts", PropertyEvent.TYPE_PROPERTY_ADDED | PropertyEvent.TYPE_PROPERTY_REMOVED, new PropertyListener() { public void propertyChanged(PropertyEvent event) { System.out.println(event); } }); Account account = factory.createAccount(book, "remi"); factory.createAccount(book, "gilles"); List list = book.getAccounts(); System.out.println(list); SortedSet transactions = account.getTransactions(); manager.addListener( Account.class, "transactions", PropertyEvent.TYPE_PROPERTY_ADDED | PropertyEvent.TYPE_PROPERTY_REMOVED, new PropertyListener() { public void propertyChanged(PropertyEvent event) { System.out.println("transaction " + event); } }); Transaction transaction = factory.createTransaction(new Date().getTime(), Collections.EMPTY_LIST); transactions.add(transaction); SortedSet tailSet = transactions.tailSet(transaction); System.out.println(tailSet); tailSet.add(factory.createTransaction(transaction.getDate() + 1, Collections.EMPTY_LIST)); }
public OwnedBook(Book book) { super( book.getId(), book.getGoodreadsId(), book.getAuthorName(), book.getGoodreadsAuthorId(), book.getName(), book.getIsbn(), book.getIsbn13(), book.getPublishedYear(), book.getDescription(), book.getPublisher(), book.getNumberOfPages(), book.getImageUrl()); setBookType(book.getBookType()); }
// 책 한건의 정보를 편집하기 위함 public int UpdateData(Book bean) { // System.out.println( "업뎃" + bean.toString() ); String sql = "update books set "; sql += " name=?, volume=?, writer=?, publisher=?, pubdate=to_date(?, 'yyyy/MM/dd'), "; sql += " genre=?, bookstory=? "; sql += " where bookcode = ? "; PreparedStatement pstmt = null; int cnt = -99999; try { if (conn == null) { super.conn = super.getConn(); } conn.setAutoCommit(false); pstmt = super.conn.prepareStatement(sql); pstmt.setString(1, bean.getName()); pstmt.setInt(2, bean.getVolume()); pstmt.setString(3, bean.getWriter()); pstmt.setString(4, bean.getPublisher()); pstmt.setString(5, bean.getPubdate()); pstmt.setString(6, bean.getGenre()); pstmt.setString(7, bean.getBookstory()); pstmt.setInt(8, bean.getBookcode()); cnt = pstmt.executeUpdate(); conn.commit(); } catch (Exception e) { SQLException err = (SQLException) e; cnt = -err.getErrorCode(); e.printStackTrace(); try { conn.rollback(); } catch (Exception e2) { e2.printStackTrace(); } } finally { try { if (pstmt != null) { pstmt.close(); } super.closeConn(); } catch (Exception e2) { e2.printStackTrace(); } } return cnt; }
@Override public LibraryProtos.Book convert( final EClass sourceType, final Book source, final Descriptor targetType) { final LibraryProtos.Book.Builder result = LibraryProtos.Book.newBuilder(); result.setId(pool.getId(source)); if (source.eIsSet(LibraryPackage.Literals.BOOK__NAME)) { result.setName(source.getName()); } if (source.eIsSet(LibraryPackage.Literals.BOOK__AUTHOR)) { final Author curAuthor = source.getAuthor(); if (curAuthor.eClass() == LibraryPackage.Literals.AUTHOR) { result .getAuthorBuilder() .setExtension( LibraryProtos.Author.authorAuthor, LibraryProtos.Author.newBuilder().setId(pool.getId(curAuthor)).build()); } else { // TODO: lookup in converter registry... throw new UnsupportedOperationException(); } } if (source.eIsSet(LibraryPackage.Literals.BOOK__RATING)) { switch (source.getRating()) { case NO_RATING: result.setRating(LibraryProtos.Rating.NO_RATING); break; case GOOD: result.setRating(LibraryProtos.Rating.GOOD); break; case MEDIUM: result.setRating(LibraryProtos.Rating.MEDIUM); break; case BAD: result.setRating(LibraryProtos.Rating.BAD); break; } ; } return result.build(); }
private Entry createBookEntry(int id, String name) throws Exception { Book b = new Book(); b.setId(id); b.setName(name); Factory factory = Abdera.getNewFactory(); JAXBContext jc = JAXBContext.newInstance(Book.class); Entry e = factory.getAbdera().newEntry(); e.setTitle(b.getName()); e.setId(Long.toString(b.getId())); StringWriter writer = new StringWriter(); jc.createMarshaller().marshal(b, writer); Content ct = factory.newContent(Content.Type.XML); ct.setValue(writer.toString()); e.setContentElement(ct); return e; }
@Test public void testBookShouldHaveName() throws Exception { Book book = new Book("TDD", 22341); assertEquals("TDD", book.getName()); }
@Override public int compareTo(Book book) { return this.getName().compareTo(book.getName()); }
@Test public void testBook() { String name = "Book"; Book test = new Book(name); assertEquals(name, test.getName()); }
private Book searchBook(String bookName) { for (Book book : books) { if (bookName.toLowerCase().equals(book.getName().toLowerCase())) return book; } return null; }