307 lines
		
	
	
		
			7.8 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
			
		
		
	
	
			307 lines
		
	
	
		
			7.8 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
package at.reisinger;
 | 
						|
 | 
						|
import com.fasterxml.jackson.annotation.*;
 | 
						|
 | 
						|
import java.util.ArrayList;
 | 
						|
 | 
						|
/**
 | 
						|
 * at.reisinger.User & at.reisinger.Store Logik
 | 
						|
 */
 | 
						|
@JsonAutoDetect
 | 
						|
public class User{
 | 
						|
    @JsonProperty
 | 
						|
    private String name, nachname, email, bio, image;
 | 
						|
    /*
 | 
						|
    @JsonProperty
 | 
						|
    private Stack stack;
 | 
						|
    */
 | 
						|
    //private DBConnection db;
 | 
						|
    @JsonProperty
 | 
						|
    private Credentials credentials;
 | 
						|
    @JsonProperty
 | 
						|
    private Coins coins;
 | 
						|
 | 
						|
    /*
 | 
						|
     * Erstellt einen neuen at.reisinger.User
 | 
						|
     * @param credentials Zugangsdaten des Users
 | 
						|
     * @param name Name des Users
 | 
						|
     * @param nachname Nachname des Users
 | 
						|
     * @param email Email des Users
 | 
						|
     * @param stack Alle Karten des Users
 | 
						|
     * @param coins Alle Münzen des Users
 | 
						|
 | 
						|
    @JsonCreator
 | 
						|
    public User(@JsonProperty Credentials credentials,@JsonProperty String name,@JsonProperty String nachname,@JsonProperty String email,@JsonProperty Stack stack,@JsonProperty Coins coins) {
 | 
						|
        this.credentials = credentials;
 | 
						|
        this.name = name;
 | 
						|
        this.nachname = nachname;
 | 
						|
        this.email = email;
 | 
						|
        this.stack = stack;
 | 
						|
        this.coins = coins;
 | 
						|
        //this.db = new at.reisinger.DBConnection();
 | 
						|
    }
 | 
						|
*/
 | 
						|
    @JsonCreator
 | 
						|
    public User(@JsonProperty Credentials credentials,@JsonProperty String name,@JsonProperty String nachname,@JsonProperty String email,@JsonProperty Coins coins, @JsonProperty String bio, @JsonProperty String image) {
 | 
						|
        this.credentials = credentials;
 | 
						|
        this.name = name;
 | 
						|
        this.nachname = nachname;
 | 
						|
        this.email = email;
 | 
						|
        //this.stack = null;
 | 
						|
        this.coins = coins;
 | 
						|
        this.bio = bio;
 | 
						|
        this.image = image;
 | 
						|
        //this.db = new at.reisinger.DBConnection();
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * Holt die Bio vom User
 | 
						|
     * @return Bio des Users
 | 
						|
     */
 | 
						|
    @JsonGetter
 | 
						|
    public String getBio() {
 | 
						|
        return bio;
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * Setzt die Bio vom User
 | 
						|
     * @param bio Bio des Users
 | 
						|
     */
 | 
						|
    @JsonSetter
 | 
						|
    public void setBio(String bio) {
 | 
						|
        this.bio = bio;
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * Holt das image vom user
 | 
						|
     * @return Image vom user
 | 
						|
     */
 | 
						|
    @JsonGetter
 | 
						|
    public String getImage() {
 | 
						|
        return image;
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * Setzt das image vom user
 | 
						|
     * @param image Image vom user
 | 
						|
     */
 | 
						|
    @JsonSetter
 | 
						|
    public void setImage(String image) {
 | 
						|
        this.image = image;
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * Holt den at.reisinger.Stack des Users
 | 
						|
     * @return at.reisinger.Stack des Users
 | 
						|
 | 
						|
    @JsonGetter
 | 
						|
    public Stack getStack() {
 | 
						|
        return stack;
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * Setzt den at.reisinger.Stack eines Users
 | 
						|
     * @param stack Der neue at.reisinger.Stack des Users
 | 
						|
 | 
						|
    @JsonSetter
 | 
						|
    public void setStack(Stack stack) {
 | 
						|
        this.stack = stack;
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * Holt das DB Obj
 | 
						|
     * @return Das DB Obj
 | 
						|
 | 
						|
    @JsonGetter
 | 
						|
    public DBConnection getDb() {
 | 
						|
        return new DBConnection();
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * Setzt ein neues DB Obj
 | 
						|
     * @param db Das neue DB Obj
 | 
						|
 | 
						|
 | 
						|
    @JsonSetter
 | 
						|
    public void setDb(DBConnection db) {
 | 
						|
        this.db = db;
 | 
						|
    }
 | 
						|
 | 
						|
    */
 | 
						|
 | 
						|
    /**
 | 
						|
     * Holt die eindeutigen Logindaten des Users
 | 
						|
     * @return Eindeutige Logindaten
 | 
						|
     */
 | 
						|
    @JsonGetter
 | 
						|
    public Credentials getCredentials() {
 | 
						|
        return credentials;
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * Setzt die eindeutigen Logindaten
 | 
						|
     * @param credentials Die neuen at.reisinger.Credentials des Users
 | 
						|
     */
 | 
						|
    @JsonSetter
 | 
						|
    public void setCredentials(Credentials credentials) {
 | 
						|
        this.credentials = credentials;
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * Holt alle at.reisinger.Coins des Users
 | 
						|
     * @return at.reisinger.Coins des Users
 | 
						|
     */
 | 
						|
    @JsonGetter
 | 
						|
    public Coins getCoins() {
 | 
						|
        return coins;
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * Setzt alle at.reisinger.Coins des Users
 | 
						|
     * @param coins Neue at.reisinger.Coins des Users
 | 
						|
     */
 | 
						|
    @JsonSetter
 | 
						|
    public void setCoins(Coins coins) {
 | 
						|
        this.coins = coins;
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * Get Name of at.reisinger.User
 | 
						|
     * @return Name of at.reisinger.User
 | 
						|
     */
 | 
						|
    @JsonGetter
 | 
						|
    public String getName() {
 | 
						|
        return this.name;
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * Get Nachname of at.reisinger.User
 | 
						|
     * @return Nachname of at.reisinger.User
 | 
						|
     */
 | 
						|
    @JsonGetter
 | 
						|
    public String getNachname() {
 | 
						|
        return this.nachname;
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * Email of at.reisinger.User
 | 
						|
     * @return Email of at.reisinger.User
 | 
						|
     */
 | 
						|
    @JsonGetter
 | 
						|
    public String getEmail() {
 | 
						|
        return this.email;
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * Setzt den Namen des Users
 | 
						|
     * @param name Neuer Name des Users
 | 
						|
     */
 | 
						|
    @JsonSetter
 | 
						|
    public void setName(String name) {
 | 
						|
        this.name = name;
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * Setzt den Nachnamen
 | 
						|
     * @param nachname Neuer Nachname
 | 
						|
     */
 | 
						|
    @JsonSetter
 | 
						|
    public void setNachname(String nachname) {
 | 
						|
        this.nachname = nachname;
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * Setzt die Email des Users
 | 
						|
     * @param email Neue Email des Users
 | 
						|
     */
 | 
						|
    @JsonSetter
 | 
						|
    public void setEmail(String email) {
 | 
						|
        this.email = email;
 | 
						|
    }
 | 
						|
 | 
						|
    //at.reisinger.Store Methoden
 | 
						|
 | 
						|
    /**
 | 
						|
     * Kauft ein at.reisinger.Package
 | 
						|
     * @param mypackage at.reisinger.Package welches gekauft werden soll
 | 
						|
     * @return Alle Karten des neuen at.reisinger.Package
 | 
						|
     * @throws NegativAmountException Wenn ein negativer Preis im at.reisinger.Package gesetzt wird.
 | 
						|
     */
 | 
						|
    public ArrayList<Card> buyPackage(Package mypackage) throws NegativAmountException {
 | 
						|
        //ArrayList<Package> availablePackages = new DBConnection().getAllPackages();
 | 
						|
        //availablePackages.removeIf(obj -> obj.equals(mypackage));
 | 
						|
        this.coins.removeCoin(mypackage.getPrice());
 | 
						|
        return mypackage.getCards();
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * Fügt dem at.reisinger.Store einen neuen Tradingdeal hinzu
 | 
						|
     * @param tradingDeal Der neue Tradingdeal
 | 
						|
     *
 | 
						|
    public void addTradingDeal(TradingDeal tradingDeal) {
 | 
						|
        new DBConnection().addTradingDeal(tradingDeal);
 | 
						|
    }
 | 
						|
 | 
						|
 | 
						|
    /**
 | 
						|
     * Holt alle verfügbaren Tradingdeals
 | 
						|
     * @return Alle verfügbaren Deals
 | 
						|
     *
 | 
						|
    public ArrayList<TradingDeal> getTradingDeals() {
 | 
						|
        return new DBConnection().getAllTradingDeals();
 | 
						|
    }
 | 
						|
 | 
						|
    @Override
 | 
						|
    public boolean doTrading(TradingDeal tradingDeal1, TradingDeal tradingDeal2) {
 | 
						|
        return false;
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * Startet ein Trading zw 2 TradingDeals
 | 
						|
     * @param myTradingDeal Wenn der Deal passt, wird diese Karte aus dem at.reisinger.Stack entfernt
 | 
						|
     * @param storeTradingDeal Wenn der Deal passt, wird diese Karte dem at.reisinger.Stack hinzugefügt
 | 
						|
     * @return True wenn erfolgreich, False wenn die Deals nicht zusammenpassen
 | 
						|
 | 
						|
    public boolean doTrading(TradingDeal myTradingDeal, TradingDeal storeTradingDeal) {
 | 
						|
        if (storeTradingDeal.dealOk(myTradingDeal)){
 | 
						|
            stack.delCard(myTradingDeal.getCardToTrade());
 | 
						|
            stack.addCard(storeTradingDeal.getCardToTrade());
 | 
						|
            return true;
 | 
						|
        }
 | 
						|
        return false;
 | 
						|
    }
 | 
						|
    */
 | 
						|
 | 
						|
    /**
 | 
						|
     * Gibt alle Möglichen Trading Deals zurück
 | 
						|
     * @param toTrade Prüft nach diesem Deal
 | 
						|
     * @return
 | 
						|
     *
 | 
						|
    @Override
 | 
						|
    public ArrayList<TradingDeal> getPossibleTradingDeals(Card toTrade) {
 | 
						|
        ArrayList<TradingDeal> storeList = new DBConnection().getAllTradingDeals();
 | 
						|
        ArrayList<TradingDeal> possible = new ArrayList<TradingDeal>();
 | 
						|
        storeList.forEach(item -> {
 | 
						|
            if(item.cardOk(toTrade)){
 | 
						|
                System.out.println("ADDED ein item");
 | 
						|
                possible.add(item);
 | 
						|
            }
 | 
						|
        });
 | 
						|
        return possible;
 | 
						|
    }
 | 
						|
 | 
						|
    */
 | 
						|
    /**
 | 
						|
     * Checkt ob es sich um den selben at.reisinger.User handelt
 | 
						|
     * @param toCheck Mit diesem at.reisinger.User wird verglichen
 | 
						|
     * @return True wenn es der selbe at.reisinger.User ist
 | 
						|
     */
 | 
						|
    public boolean equals(User toCheck){
 | 
						|
        if (toCheck.getCredentials().getUsername() == this.credentials.getUsername() && toCheck.getCredentials().getPasswort() == this.credentials.getPasswort()){
 | 
						|
            return true;
 | 
						|
        }else {
 | 
						|
            return false;
 | 
						|
        }
 | 
						|
    }
 | 
						|
}
 |