package org.jscience.economics.money;
import org.jscience.economics.Organization;
import org.jscience.measure.Identification;
import org.jscience.measure.Identified;
import java.util.Date;
/**
* A class representing an exchange of money and goods or services between two
* parties. Each transaction emits a receipt for each party.
*
* @author Silvere Martin-Michiellot
* @version 1.0
*/
//final modifier used to secure the access
public final class Transaction extends Object implements Identified {
/**
* DOCUMENT ME!
*/
private Organization seller;
/**
* DOCUMENT ME!
*/
private Organization buyer;
/**
* DOCUMENT ME!
*/
private Date date;
/**
* DOCUMENT ME!
*/
private Identification identification;
/**
* DOCUMENT ME!
*/
private String description;
/**
* DOCUMENT ME!
*/
private Money money;
/**
* DOCUMENT ME!
*/
private Share share;
/**
* DOCUMENT ME!
*/
private int quantity;
//money is transfered from the buyer to the seller
//while goods or services are transfered the opposite way
public Transaction(Organization seller, Organization buyer, Date date,
Identification identification, String description, Money money) {
if ((seller != null) && (buyer != null) && (date != null) &&
(identification != null) && (description != null) &&
(description.length() > 0) && (money != null)) {
this.seller = seller;
this.buyer = buyer;
this.date = date;
this.identification = identification;
this.description = description;
this.money = money;
this.share = null;
this.quantity = 0;
} else {
throw new IllegalArgumentException(
"Transaction doesn't accept null arguments and description can't be empty.");
}
}
//money is transfered from the buyer to the seller
//while shares are transfered the opposite way
public Transaction(Organization seller, Organization buyer, Date date,
Identification identification, String description, Share share,
int quantity) {
if ((seller != null) && (buyer != null) && (date != null) &&
(identification != null) && (description != null) &&
(description.length() > 0) && (share != null)) {
if (quantity > 0) {
this.seller = seller;
this.buyer = buyer;
this.date = date;
this.identification = identification;
this.description = description;
this.money = new Money(0, Currencies.US_DOLLAR);
this.share = share;
this.quantity = quantity;
} else {
throw new IllegalArgumentException(
"The quantity must be positive.");
}
} else {
throw new IllegalArgumentException(
"Transaction doesn't accept null arguments and description can't be empty.");
}
}
/**
* DOCUMENT ME!
*
* @return DOCUMENT ME!
*/
public final Organization getSeller() {
return seller;
}
/**
* DOCUMENT ME!
*
* @return DOCUMENT ME!
*/
public final Organization getBuyer() {
return buyer;
}
/**
* DOCUMENT ME!
*
* @return DOCUMENT ME!
*/
public final Date getDate() {
return date;
}
/**
* DOCUMENT ME!
*
* @return DOCUMENT ME!
*/
public final Identification getIdentification() {
return identification;
}
/**
* DOCUMENT ME!
*
* @return DOCUMENT ME!
*/
public final String getDescription() {
return description;
}
/**
* DOCUMENT ME!
*
* @return DOCUMENT ME!
*/
public final Money getMoney() {
return money;
}
/**
* DOCUMENT ME!
*
* @return DOCUMENT ME!
*/
public final Share getShare() {
return share;
}
/**
* DOCUMENT ME!
*
* @return DOCUMENT ME!
*/
public final int getQuantity() {
return quantity;
}
//otherwise you traded shares
public boolean isMoneyTransaction() {
return quantity == 0;
}
/**
* DOCUMENT ME!
*
* @return DOCUMENT ME!
*/
public final Receipt getReceipt() {
if (isMoneyTransaction()) {
return new Receipt(seller, buyer, date, identification,
description, money);
} else {
return new Receipt(seller, buyer, date, identification,
description, share, quantity);
}
}
}
কোন মন্তব্য নেই:
একটি মন্তব্য পোস্ট করুন
Thankyou!