类 Transaction
- java.lang.Object
-
- edu.princeton.cs.algs4.Transaction
-
- 所有已实现的接口:
java.lang.Comparable<Transaction>
public class Transaction extends java.lang.Object implements java.lang.Comparable<Transaction>
TheTransaction
class is an immutable data type to encapsulate a commercial transaction with a customer name, date, and amount.For additional documentation, see Section 1.2 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.
-
-
嵌套类概要
嵌套类 修饰符和类型 类 说明 static class
Transaction.HowMuchOrder
Compares two transactions by amount.static class
Transaction.WhenOrder
Compares two transactions by date.static class
Transaction.WhoOrder
Compares two transactions by customer name.
-
构造器概要
构造器 构造器 说明 Transaction(java.lang.String transaction)
Initializes a new transaction by parsing a string of the form NAME DATE AMOUNT.Transaction(java.lang.String who, Date when, double amount)
Initializes a new transaction from the given arguments.
-
方法概要
修饰符和类型 方法 说明 double
amount()
Returns the amount of this transaction.int
compareTo(Transaction that)
Compares two transactions by amount.boolean
equals(java.lang.Object other)
Compares this transaction to the specified object.int
hashCode()
Returns a hash code for this transaction.static void
main(java.lang.String[] args)
Unit tests theTransaction
data type.java.lang.String
toString()
Returns a string representation of this transaction.Date
when()
Returns the date of this transaction.java.lang.String
who()
Returns the name of the customer involved in this transaction.
-
-
-
构造器详细资料
-
Transaction
public Transaction(java.lang.String who, Date when, double amount)
Initializes a new transaction from the given arguments.- 参数:
who
- the person involved in this transactionwhen
- the date of this transactionamount
- the amount of this transaction- 抛出:
java.lang.IllegalArgumentException
- ifamount
isDouble.NaN
,Double.POSITIVE_INFINITY
, orDouble.NEGATIVE_INFINITY
-
Transaction
public Transaction(java.lang.String transaction)
Initializes a new transaction by parsing a string of the form NAME DATE AMOUNT.- 参数:
transaction
- the string to parse- 抛出:
java.lang.IllegalArgumentException
- ifamount
isDouble.NaN
,Double.POSITIVE_INFINITY
, orDouble.NEGATIVE_INFINITY
-
-
方法详细资料
-
who
public java.lang.String who()
Returns the name of the customer involved in this transaction.- 返回:
- the name of the customer involved in this transaction
-
when
public Date when()
Returns the date of this transaction.- 返回:
- the date of this transaction
-
amount
public double amount()
Returns the amount of this transaction.- 返回:
- the amount of this transaction
-
toString
public java.lang.String toString()
Returns a string representation of this transaction.- 覆盖:
toString
在类中java.lang.Object
- 返回:
- a string representation of this transaction
-
compareTo
public int compareTo(Transaction that)
Compares two transactions by amount.- 指定者:
compareTo
在接口中java.lang.Comparable<Transaction>
- 参数:
that
- the other transaction- 返回:
- { a negative integer, zero, a positive integer}, depending on whether the amount of this transaction is { less than, equal to, or greater than } the amount of that transaction
-
equals
public boolean equals(java.lang.Object other)
Compares this transaction to the specified object.- 覆盖:
equals
在类中java.lang.Object
- 参数:
other
- the other transaction- 返回:
- true if this transaction is equal to
other
; false otherwise
-
hashCode
public int hashCode()
Returns a hash code for this transaction.- 覆盖:
hashCode
在类中java.lang.Object
- 返回:
- a hash code for this transaction
-
main
public static void main(java.lang.String[] args)
Unit tests theTransaction
data type.- 参数:
args
- the command-line arguments
-
-