예제 #1
0
파일: XBeeNode.java 프로젝트: KenC57/JMRI
 public void connectPortController(Class<jmri.jmrix.AbstractStreamPortController> T) {
   try {
     java.lang.reflect.Constructor<?> ctor =
         T.getConstructor(
             java.io.DataInputStream.class, java.io.DataOutputStream.class, String.class);
     connectedController =
         (jmri.jmrix.AbstractStreamPortController)
             ctor.newInstance(
                 getIOStream().getInputStream(),
                 getIOStream().getOutputStream(),
                 "XBee Node " + getPreferedName());
     connectedController.configure();
   } catch (java.lang.InstantiationException ie) {
     log.error("Unable to construct Stream Port Controller for node.");
     ie.printStackTrace();
   } catch (java.lang.NoSuchMethodException nsm) {
     log.error("Unable to construct Stream Port Controller for node.");
     nsm.printStackTrace();
   } catch (java.lang.IllegalAccessException iae) {
     log.error("Unable to construct Stream Port Controller for node.");
     iae.printStackTrace();
   } catch (java.lang.reflect.InvocationTargetException ite) {
     log.error("Unable to construct Stream Port Controller for node.");
     ite.printStackTrace();
   }
 }
예제 #2
0
 public Object getClone() {
   if (hasCloneMethod) {
     try {
       return method.invoke(object);
     } catch (java.lang.IllegalAccessException e) {
       e.printStackTrace();
     } catch (java.lang.reflect.InvocationTargetException e) {
       e.printStackTrace();
     }
     return null;
   } else {
     Object copy = Constructor.construct(object.getClass());
     for (Field field : fields) {
       try {
         field.set(copy, field.get(object));
       } catch (java.lang.IllegalAccessException e) {
         e.printStackTrace();
       }
     }
     return copy;
   }
 }
예제 #3
0
 private void callPut(
     java.lang.Object object,
     com.beust.jcommander.Parameterized parameterized,
     java.lang.String key,
     java.lang.String value) {
   try {
     java.lang.reflect.Method m;
     m = findPut(parameterized.getType());
     m.invoke(parameterized.get(object), key, value);
   } catch (java.lang.SecurityException e) {
     e.printStackTrace();
   } catch (java.lang.IllegalAccessException e) {
     e.printStackTrace();
   } catch (java.lang.reflect.InvocationTargetException e) {
     e.printStackTrace();
   } catch (java.lang.NoSuchMethodException e) {
     e.printStackTrace();
   }
 }
예제 #4
0
  public Atm() // constructor
        // sets the customer array to that found in the file if the file exists
      {
    try {
      // Set cross-platform Java L&F (also called "Metal")
      UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
    } catch (UnsupportedLookAndFeelException e) {
      e.printStackTrace();
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
    } catch (InstantiationException e) {
      e.printStackTrace();
    } catch (IllegalAccessException e) {
      e.printStackTrace();
    }

    if (logFile.exists()) {
      try {
        adminLogs = returnLog("p2.log");
        if (!adminLogs.isEmpty()) {
          // there may be customer data but perhaps no transactions yet.
          ArrayList<Integer> allTransactions = new ArrayList<>(100);
          for (AdminLog a : adminLogs) {

            int transaction = a.getTransactionID();
            ;
            allTransactions.add(transaction);
          }
          transaction_counter = Collections.max(allTransactions) + 1;
        }
      } catch (ClassNotFoundException | IOException e) {
        e.printStackTrace();
      }
    }

    if (DBfile.exists()) {
      try {

        cust = returnSavedData("p2.dat");

        // sets the starting ID to the max of all the IDs stored in the file.
        allIDs = new ArrayList<Integer>(100);
        ArrayList<Integer> allAccounts = new ArrayList<>();
        for (Customer customer : cust) {
          String idString = customer.returnID();
          int id = Integer.parseInt(idString);
          allIDs.add(id);
          int accountNumber = customer.returnMaxAccount();
          allAccounts.add(accountNumber);
        }
        // checks to see if the customer has even made any accounts, if not, max accounts will be
        // set at 1001
        if (starting_account_number != 1) {
          starting_account_number = Collections.max(allAccounts) + 1;
        }
        starting_customer_number = Collections.max(allIDs) + 1;

      } catch (ClassNotFoundException | IOException e) {
        e.printStackTrace();
      }
    } else {
      cust = new ArrayList<>(100);
      // creates the file if it does not exist
      try {
        saveFile(cust, DBfile);
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
    interest_rate = 5;
  }