Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.xlrit.gears.common.test_domain.Library Maven / Gradle / Ivy
package com.xlrit.gears.common.test_domain;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import lombok.RequiredArgsConstructor;
@RequiredArgsConstructor
public class Library {
private final Consumer callback;
public final List authors = new ArrayList<>();
public final Author danielDefoe;
public final Author williamGolding;
public final Author lewisCarroll;
public final Author hermanMelville;
public final Author johnMilton;
public final Author margaretMitchell;
public final Author brentUnderwood;
public final Author johnUpdike;
public final List books = new ArrayList<>();
public final Book robinsonCrusoe;
public final Book captainSingleton;
public final Book lordOfTheFlies;
public final Book aliceAdventures;
public final Book mobyDick;
public final Book paradiseLost;
public final Book goneWithTheWind;
public final Book lotsOfNights;
public final Book rabbitIsRich;
public Library(Consumer callback) {
this.callback = callback;
danielDefoe = createAuthor("01", "Daniel", "Defoe", LocalDate.of(1900, 1,2), true);
williamGolding = createAuthor("02", "William", "Golding", null, true);
lewisCarroll = createAuthor("03", "Lewis", "Carroll", LocalDate.of(1900, 3,4), true);
hermanMelville = createAuthor("04", "Herman", "Melville", LocalDate.of(1900, 5,6), true);
johnMilton = createAuthor("05", "John", "Milton", LocalDate.of(2900, 7,8), true);
margaretMitchell = createAuthor("06", "Margaret", "Mitchell", LocalDate.of(2022, 8,4), false);
brentUnderwood = createAuthor("07", "Brent", "Underwood", LocalDate.of(1988, 5,13), true);
johnUpdike = createAuthor("08", "John", "Updike", LocalDate.of(1932, 3,18), true);
// books (titles and (fake) ISBNs generated using https://www.onlinedatagenerator.com/)
robinsonCrusoe = createBook("01", "Robinson Crusoe", "615-51-08028-21-3", 1719L, new BigDecimal("199912.33"), danielDefoe);
captainSingleton = createBook("02", "Captain Singleton", "978-15-54813-41-4", 1720L, new BigDecimal("199912.35"), danielDefoe);
lordOfTheFlies = createBook("03", "Lord of the Flies", "582-42-58056-15-4", 1954L, new BigDecimal("199945.64"), williamGolding);
aliceAdventures = createBook("04", "Alice Adventures in Wonderland","562-13-05820-71-4", 1865L, new BigDecimal("199978.95"), lewisCarroll);
mobyDick = createBook("05", "Moby Dick", "106-86-45341-14-3", 1851L, new BigDecimal("199910.16"), hermanMelville);
paradiseLost = createBook("06", "Paradise Lost", "583-54-73461-72-5", 1667L, new BigDecimal("199923.47"), johnMilton);
goneWithTheWind = createBook("07", "Gone With the Wind", "715-01-78482-70-4", 1936L, new BigDecimal("199956.78"), margaretMitchell);
lotsOfNights = createBook("08", "One Thousand and One Nights", "978-03-85771-51-2", 1721L, new BigDecimal("199999.99"), null);
rabbitIsRich = createBook("09", "Rabbit Is Rich", "978-03-94520-87-2", 1981L, new BigDecimal("199933.42"), johnUpdike);
}
private Author createAuthor(String id, String firstName, String lastName, LocalDate born, boolean isMale) {
Author author = new Author(id);
author.setFirstName(firstName);
author.setLastName(lastName);
author.setBorn(born);
author.setIsMale(isMale);
authors.add(author);
callback.accept(author);
return author;
}
private Book createBook(String id, String title, String isbn, long year, BigDecimal score, Author author) {
Book book = new Book(id);
book.setTitle(title);
book.setIsbn(isbn);
book.setYear(year);
book.setScore(score);
book.setAuthorBidi(author);
books.add(book);
callback.accept(book);
return book;
}
@Override
public String toString() {
return "Library[%d authors, %d books]".formatted(authors.size(), books.size());
}
}