wm: java

ref: c38e733d9de9f416af3f1e629bc351c4723e2425
dir: /Bookproj/Book.java/

View raw version
package Bookproj;

import java.util.TreeMap;

public class Book {
    protected String Abstract;
    protected String Author;
    protected String Name;
    protected String ISBN;
    protected int AgeGroup;
    /* book is untaken by default */
    private boolean Status = false;
    private String Owner = ""; /* Username of user who reserved it */

    Book(String isbn, String name, String author, int age, String abs)
    {
        /* joy of joys willy */
        this.ISBN = isbn;
        this.Name = name;
        this.Author = author;
        this.AgeGroup = age;
        this.Abstract = abs;
    }

    boolean AgeOk(int age) {
        if (this.AgeGroup <= age)
            return true;
        else
            return false;
    }

    boolean setOwner(String u) {
        if (!this.Owner.isEmpty())
            return false;

        this.Owner = u;
        return true;
    }

    void setStatus(boolean b) {
        if (this.Status == b)
            throw new IllegalStateException("Status already set!");

        this.Status = b;
    }

    boolean getStatus() {
        return Status;
    }

    String getAbstract() {
        return this.Abstract;
    }

    String getAuthor() {
        return this.Author;
    }

    String getName() {
        return this.Name;
    }

    String getISBN() {
        return this.ISBN;
    }

    int getAgeGroup() {
        return this.AgeGroup;
    }

    String getOwner() {
        return this.Owner;
    }

    TreeMap<BookAttr, String> toMap() {
        TreeMap<BookAttr, String> temp = new TreeMap<BookAttr, String>();

        temp.put(BookAttr.ISBN, this.ISBN);
        temp.put(BookAttr.Status, Boolean.toString(this.Status));
        temp.put(BookAttr.Name, this.Name);
        temp.put(BookAttr.Author, this.Author);

        temp.put(BookAttr.AgeGroup, Integer.toString(this.AgeGroup));
        temp.put(BookAttr.Abstract, this.Abstract);
        temp.put(BookAttr.Owner, this.Owner);
        return temp;
    }
}