Package tests.jfun.yan.xml

Source Code of tests.jfun.yan.xml.SingletonBankAccount

package tests.jfun.yan.xml;

import tests.jfun.models.BankAccount;

public class SingletonBankAccount extends BankAccount {
  private static int count = 0;
  private SingletonBankAccount(){
    if(count > 0)
      throw new IllegalStateException("should not have more than 1 instances");
    count++;
  }
  public static BankAccount create(String id, int balance){
    BankAccount acct = new SingletonBankAccount();
    acct.balance = balance;
    acct.setId(id);
    return acct;
  }
  private boolean invoked = false;
  public void run(){
    if(invoked){
      throw new IllegalStateException("should not be called twice!");
    }
    this.invoked = true;
  }
}
TOP

Related Classes of tests.jfun.yan.xml.SingletonBankAccount

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.