| <?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> > <a href="index.source.html" class="el_package">org.apache.shiro.samples.aspectj.bank</a> > <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 |
| * "License"); 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 |
| * "AS IS" 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<AccountTransaction> _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<AccountTransaction>();</span> |
| <span class="fc" id="L54"> _createdBy = "unknown";</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<AccountTransaction> 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("Unable to apply " + aTransaction.getType() + " of amount " + aTransaction.getAmount() + " to account " + _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 < aTransaction.getAmount()) {</span> |
| <span class="fc" id="L133"> throw new NotEnoughFundsException("Unable to withdraw " + aTransaction.getAmount() + "$ from account " + _id + " - current balance is " + _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("The transaction passed in has an invalid type: " + 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("id", _id).</span> |
| <span class="fc" id="L178"> append("ownerName", _ownerName).</span> |
| <span class="fc" id="L179"> append("isActive", _isActive).</span> |
| <span class="fc" id="L180"> append("balance", _balance).</span> |
| <span class="fc" id="L181"> append("tx.count", _transactions.size()).</span> |
| <span class="fc" id="L182"> append("createdBy", _createdBy).</span> |
| <span class="fc" id="L183"> append("creationDate", 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> |