blob: 1d29590e85c3e93607bf7c432e7299f9dde8eeeb [file] [log] [blame]
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>Account.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">Apache Shiro :: Samples :: AspectJ</a> &gt; <a href="index.source.html" class="el_package">org.apache.shiro.samples.aspectj.bank</a> &gt; <span class="el_source">Account.java</span></div><h1>Account.java</h1><pre class="source lang-java linenums">/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* &quot;License&quot;); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* &quot;AS IS&quot; BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.shiro.samples.aspectj.bank;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class Account {
private static long _SEQUENCE;
private long _id;
private String _ownerName;
private volatile boolean _isActive;
private double _balance;
private final List&lt;AccountTransaction&gt; _transactions;
private String _createdBy;
private Date _creationDate;
<span class="fc" id="L48"> public Account(String anOwnerName) {</span>
<span class="fc" id="L49"> _id = ++_SEQUENCE;</span>
<span class="fc" id="L50"> _ownerName = anOwnerName;</span>
<span class="fc" id="L51"> _isActive = true;</span>
<span class="fc" id="L52"> _balance = 0.0d;</span>
<span class="fc" id="L53"> _transactions = new ArrayList&lt;AccountTransaction&gt;();</span>
<span class="fc" id="L54"> _createdBy = &quot;unknown&quot;;</span>
<span class="fc" id="L55"> _creationDate = new Date();</span>
<span class="fc" id="L56"> }</span>
/**
* Returns the id attribute.
*
* @return The id value.
*/
public long getId() {
<span class="fc" id="L64"> return _id;</span>
}
/**
* Returns the ownerName attribute.
*
* @return The ownerName value.
*/
public String getOwnerName() {
<span class="fc" id="L73"> return _ownerName;</span>
}
/**
* Returns the isActive attribute.
*
* @return The isActive value.
*/
public boolean isActive() {
<span class="fc" id="L82"> return _isActive;</span>
}
/**
* Changes the value of the attributes isActive.
*
* @param aIsActive The new value of the isActive attribute.
*/
public void setActive(boolean aIsActive) {
<span class="fc" id="L91"> _isActive = aIsActive;</span>
<span class="fc" id="L92"> }</span>
/**
* Changes the value of the attributes ownerName.
*
* @param aOwnerName The new value of the ownerName attribute.
*/
public void setOwnerName(String aOwnerName) {
<span class="nc" id="L100"> _ownerName = aOwnerName;</span>
<span class="nc" id="L101"> }</span>
/**
* Returns the balance attribute.
*
* @return The balance value.
*/
public double getBalance() {
<span class="fc" id="L109"> return _balance;</span>
}
/**
* Returns the transactions attribute.
*
* @return The transactions value.
*/
public List&lt;AccountTransaction&gt; getTransactions() {
<span class="fc" id="L118"> return _transactions;</span>
}
protected void applyTransaction(AccountTransaction aTransaction) throws NotEnoughFundsException, InactiveAccountException {
<span class="pc bpc" id="L122" title="1 of 2 branches missed."> if (!_isActive) {</span>
<span class="nc" id="L123"> throw new InactiveAccountException(&quot;Unable to apply &quot; + aTransaction.getType() + &quot; of amount &quot; + aTransaction.getAmount() + &quot; to account &quot; + _id);</span>
}
<span class="fc" id="L126"> synchronized (_transactions) {</span>
<span class="fc bfc" id="L127" title="All 2 branches covered."> if (AccountTransaction.TransactionType.DEPOSIT == aTransaction.getType()) {</span>
<span class="fc" id="L128"> _transactions.add(aTransaction);</span>
<span class="fc" id="L129"> _balance += aTransaction.getAmount();</span>
<span class="pc bpc" id="L131" title="1 of 2 branches missed."> } else if (AccountTransaction.TransactionType.WITHDRAWAL == aTransaction.getType()) {</span>
<span class="fc bfc" id="L132" title="All 2 branches covered."> if (_balance &lt; aTransaction.getAmount()) {</span>
<span class="fc" id="L133"> throw new NotEnoughFundsException(&quot;Unable to withdraw &quot; + aTransaction.getAmount() + &quot;$ from account &quot; + _id + &quot; - current balance is &quot; + _balance);</span>
}
<span class="fc" id="L135"> _transactions.add(aTransaction);</span>
<span class="fc" id="L136"> _balance -= aTransaction.getAmount();</span>
<span class="fc" id="L138"> } else {</span>
<span class="nc" id="L139"> throw new IllegalArgumentException(&quot;The transaction passed in has an invalid type: &quot; + aTransaction.getType());</span>
}
}
<span class="fc" id="L142"> }</span>
/**
* Changes the value of the attributes createdBy.
*
* @param aCreatedBy The new value of the createdBy attribute.
*/
protected void setCreatedBy(String aCreatedBy) {
<span class="fc" id="L150"> _createdBy = aCreatedBy;</span>
<span class="fc" id="L151"> }</span>
/**
* Returns the createdBy attribute.
*
* @return The createdBy value.
*/
public String getCreatedBy() {
<span class="nc" id="L159"> return _createdBy;</span>
}
/**
* Returns the creationDate attribute.
*
* @return The creationDate value.
*/
public Date getCreationDate() {
<span class="nc" id="L168"> return _creationDate;</span>
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
public String toString() {
<span class="fc" id="L176"> return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).</span>
<span class="fc" id="L177"> append(&quot;id&quot;, _id).</span>
<span class="fc" id="L178"> append(&quot;ownerName&quot;, _ownerName).</span>
<span class="fc" id="L179"> append(&quot;isActive&quot;, _isActive).</span>
<span class="fc" id="L180"> append(&quot;balance&quot;, _balance).</span>
<span class="fc" id="L181"> append(&quot;tx.count&quot;, _transactions.size()).</span>
<span class="fc" id="L182"> append(&quot;createdBy&quot;, _createdBy).</span>
<span class="fc" id="L183"> append(&quot;creationDate&quot;, new Timestamp(_creationDate.getTime())).</span>
<span class="fc" id="L184"> toString();</span>
}
}
</pre><div class="footer"><span class="right">Created with <a href="http://www.eclemma.org/jacoco">JaCoCo</a> 0.7.7.201606060606</span></div></body></html>