public static void main(String[] args) { // Create a default instance of Employee Employee emp = new Employee(); System.out.println(emp.toString() + "\n"); // Note how set methods are used - passing new object instances of Name and Date emp.setName(new Name("Joe", "Bloggs")); emp.setStartDate(new Date(10, 11, 2013)); emp.setSalary(12500); System.out.println(emp.toString() + "\n"); // Note how methods of the Name or Date class can be called by first // retrieving the object and then calling the method using dot notation System.out.println("Full name is " + emp.getName().getFullName()); System.out.println("Start date is " + emp.getStartDate().getDateString()); System.out.println("Annual salary is " + emp.getSalary()); System.out.println("\nCreating another employee..."); // Create a custom instance of Employee by providing Name and Date objects Employee emp1 = new Employee(new Name("Tom", "Ford"), new Date(1, 3, 2009), 15500.50); // Note how first name can be updated by retrieving Name object and then calling its method emp1.getName().setFirstName("George"); System.out.println(emp1.toString()); // ADD MORE CODE HERE // emp1.getSalary().setSalaray(25000.50); System.out.println("Salary is: " + emp1.getSalary()); // Changing the first name and month Employee emp2 = new Employee(); System.out.println("\nCreating another employee"); emp2.setName(new Name("Ryan", "Morris")); emp2.setStartDate(new Date(12, 11, 13)); emp2.setSalary(25000.00); System.out.println(emp2.getName()); System.out.println(emp2.getStartDate()); // Using the new methods System.out.println("Full name is: " + emp2.getName().getFullName()); System.out.println("Start date is: " + emp2.getStartDate().getDateString()); System.out.println("Salary is: " + emp2.getSalary()); }
public static void main(String[] args) { int i = 10; int j = 10; if (i == j) { System.out.println("Equals"); } Employee e1 = new Employee(10); Employee e2 = new Employee(10); e1 = e2; if (e1 == e2) { System.out.println("Equals"); } System.out.println(e1.hashCode()); System.out.println(e2.hashCode()); if (e1.equals(e2)) { System.out.println("Employee Equals"); } String s1 = new String("ABC"); String s2 = "ABC"; if (s1.equals(s2)) { System.out.println("String Equals"); } System.out.println(e1.toString()); }
public void execute() throws InvalidOperation { List<Employee> employees = _entity.getListOfEmployees(); Collections.sort(employees, new SortEmployeesByKey()); for (Employee e : employees) { IO.println(e.toString()); } }
/** @param args */ public static void main(String[] args) { // TODO Auto-generated method stub ApplicationContext bf = SpringApplicationContext.getContext(); System.out.println("isSingleton? " + bf.isSingleton("employee")); Employee employee = (Employee) bf.getBean("employee"); employee.setFirstName("Amit"); System.out.println(employee.toString()); employee.sayHello(); }
public static void main(String[] args) { // kreiramo objekte, testiramo funkcije Person osoba = new Person("Neko"); Student student = new Student("Student"); Employee zaposlenik = new Employee("Zaposlen"); Faculty profesor = new Faculty("Profesor"); Staff staff = new Staff("staff"); // to string System.out.println(osoba.toString()); System.out.println(student.toString()); System.out.println(zaposlenik.toString()); System.out.println(profesor.toString()); System.out.println(staff.toString()); }
public static void createWorker() { String name = "John Smith"; String employeeNumber = "123"; String hireDate = "11-15-2009"; int shift = 1; double payRate = -99.00; try { Employee emp = new ProductionWorker(name, employeeNumber, hireDate, shift, payRate); System.out.println(emp.toString()); } catch (InvalidShift | InvalidPayRate | InvalidEmployeeNumber e) { System.out.println(e.getMessage()); } }
public static Employee findEmployeeID(ArrayList<Employee> emp) { int theEmployeeID; try { System.out.println("Please enter the employee ID you are searching: "); theEmployeeID = keyboard.nextInt(); for (Employee e : emp) { System.out.println(e.getEmployeeID()); if (e.getEmployeeID() == theEmployeeID) { System.out.println(e.toString()); return e; } } System.out.println("There is no such employee ID in use"); } catch (Exception g) { } return null; }
public static void main(String[] args) { // List<Employee> emp = new ArrayList(4); // // emp.add(0,new Employee(1, "Jobs", "Steve", "111-11-1111")); // emp.add(1,new Employee(1, "Jobs", "Steve", "111-11-1111")); // emp.add(2,new Employee(1, "Rogers", "Aaron", "222-22-2222")); // emp.add(3,new Employee(1, "Gates", "Bill", "333-33-3333")); // System.out.println(emp.size()); // // key will be ssn HashMap<String, Employee> emp = new HashMap(); Employee e1 = new Employee(1, "Jobs", "Steve", "111-11-1111"); Employee e2 = new Employee(2, "Jobs", "Steve", "111-11-1111"); Employee e3 = new Employee(3, "Rogers", "Aaron", "222-22-2222"); Employee e4 = new Employee(4, "Gates", "Bill", "333-33-3333"); // add emplyees to hashmap emp.put(e1.getSsn(), e1); emp.put(e2.getSsn(), e2); emp.put(e3.getSsn(), e3); emp.put(e4.getSsn(), e4); // check how many values are in the map Set mapKeys = emp.keySet(); // should print 3 System.out.println(mapKeys.size()); // create an array of the ketSe Object[] keys = mapKeys.toArray(); // iterate through the array of keys and use them to retrieve objects from the map for (Object o : keys) { System.out.println(o.toString()); String key = o.toString(); Employee temp = emp.get(key); System.out.println(temp.toString()); } }
public void test() { // clear cache getSession().getIdentityMapAccessor().initializeAllIdentityMaps(); // create batch read query, set its selectionCriteria ReadAllQuery query = new ReadAllQuery(Employee.class); setSelectionCriteria(query); // before adding batch read attributes clone the query to create control query ReadAllQuery controlQuery = (ReadAllQuery) query.clone(); // add batch read attributes Expression managedEmployees = query.getExpressionBuilder().get("managedEmployees"); Expression managedEmployeesPhoneNumbers = managedEmployees.get("phoneNumbers"); query.addBatchReadAttribute(managedEmployeesPhoneNumbers); // execute the query List employees = (List) getSession().executeQuery(query); if (employees.isEmpty()) { throw new TestProblemException("No Employees were read"); } // need to instantiate only a single Phone on a single managed Employee to trigger sql that // reads data from the db for all. // still need to trigger all the indirections - but (except the first one) they are not // accessing the db // (the data is already cached in the value holders). printDebug("Trigger batch reading results"); boolean isConnected = true; for (int i = 0; i < employees.size(); i++) { Employee manager = (Employee) employees.get(i); if (!manager.getManagedEmployees().isEmpty()) { printDebug("Manager = " + manager); for (int j = 0; j < manager.getManagedEmployees().size(); j++) { Employee emp = (Employee) manager.getManagedEmployees().get(j); printDebug(" " + emp); for (int k = 0; k < emp.getPhoneNumbers().size(); k++) { if (isConnected) { // need to instantiate only a single Phone on a single managed Employee to trigger // sql that reads data from the db for all. // to ensure that no other sql is issued close connection. ((AbstractSession) getSession()).getAccessor().closeConnection(); isConnected = false; } PhoneNumber phone = (PhoneNumber) emp.getPhoneNumbers().get(k); printDebug(" " + phone); } } } else { printDebug(manager.toString()); } } if (!isConnected) { // reconnect connection ((AbstractSession) getSession()) .getAccessor() .reestablishConnection((AbstractSession) getSession()); } printDebug(""); // obtain control results // clear cache getSession().getIdentityMapAccessor().initializeAllIdentityMaps(); // execute control query List controlEmployees = (List) getSession().executeQuery(controlQuery); // instantiate all value holders that the batch query expected to instantiate printDebug("Trigger control results"); for (int i = 0; i < controlEmployees.size(); i++) { Employee manager = (Employee) controlEmployees.get(i); if (!manager.getManagedEmployees().isEmpty()) { printDebug("Manager = " + manager); for (int j = 0; j < manager.getManagedEmployees().size(); j++) { Employee emp = (Employee) manager.getManagedEmployees().get(j); printDebug(" " + emp); for (int k = 0; k < emp.getPhoneNumbers().size(); k++) { PhoneNumber phone = (PhoneNumber) emp.getPhoneNumbers().get(k); printDebug(" " + phone); } } } else { printDebug(manager.toString()); } } // compare results String errorMsg = JoinedAttributeTestHelper.compareCollections( employees, controlEmployees, getSession().getClassDescriptor(Employee.class), ((AbstractSession) getSession())); if (errorMsg.length() > 0) { throw new TestErrorException(errorMsg); } }