转载需说明出处:http://blog.csdn.net/minimicall, http://cloudtrade.top
不论什么可交易的都能够称之为Assert,资产。其类代码例如以下:
package org.cryptocoinpartners.schema; import javax.persistence.Basic; import javax.persistence.Cacheable; import javax.persistence.Entity; import javax.persistence.Transient; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * Represents anything valuable and tradable, like currency or stock *不论什么有价值的而且可交易的物体,比方现金、股票 * @author Tim Olson */ @Entity //实体,说明在数据库中会建立对应的表格。因为没有使用name參数。说明类名就是表明。
@Cacheable //可缓存 public abstract class Asset extends EntityBase { public static Asset forSymbol(String symbol) { // only Currency is supported return Currency.forSymbol(symbol); } @Basic(optional = false) public String getSymbol() { return symbol; } @Basic(optional = false) public double getBasis() { return basis; } @Transient public int getScale() { int length = (int) (Math.log10(Math.round(1 / basis))); return length; } @Override public String toString() { return symbol; } protected Asset(String symbol, double basis) { this.symbol = symbol; this.basis = basis; } // JPA protected Asset() { } protected void setSymbol(String symbol) { this.symbol = symbol; } protected void setBasis(double basis) { this.basis = basis; } private String symbol;//符号 private double basis;//值 private static Logger log = LoggerFactory.getLogger(Asset.class); }