[jboss-cvs] JBossAS SVN: r66596 - projects/microcontainer/trunk/docs/examples/User_Guide/humanResourcesService/src/main/java/org/jboss/example/service.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Oct 31 04:44:23 EDT 2007
Author: newtonm
Date: 2007-10-31 04:44:23 -0400 (Wed, 31 Oct 2007)
New Revision: 66596
Added:
projects/microcontainer/trunk/docs/examples/User_Guide/humanResourcesService/src/main/java/org/jboss/example/service/Address.java
projects/microcontainer/trunk/docs/examples/User_Guide/humanResourcesService/src/main/java/org/jboss/example/service/AgeBasedSalaryStrategy.java
projects/microcontainer/trunk/docs/examples/User_Guide/humanResourcesService/src/main/java/org/jboss/example/service/Employee.java
projects/microcontainer/trunk/docs/examples/User_Guide/humanResourcesService/src/main/java/org/jboss/example/service/LocationBasedSalaryStrategy.java
projects/microcontainer/trunk/docs/examples/User_Guide/humanResourcesService/src/main/java/org/jboss/example/service/SalaryStrategy.java
Modified:
projects/microcontainer/trunk/docs/examples/User_Guide/humanResourcesService/src/main/java/org/jboss/example/service/Manager.java
Log:
Added more classes.
Added: projects/microcontainer/trunk/docs/examples/User_Guide/humanResourcesService/src/main/java/org/jboss/example/service/Address.java
===================================================================
--- projects/microcontainer/trunk/docs/examples/User_Guide/humanResourcesService/src/main/java/org/jboss/example/service/Address.java (rev 0)
+++ projects/microcontainer/trunk/docs/examples/User_Guide/humanResourcesService/src/main/java/org/jboss/example/service/Address.java 2007-10-31 08:44:23 UTC (rev 66596)
@@ -0,0 +1,27 @@
+package org.jboss.example.service;
+
+public class Address {
+
+ private int number;
+ private String street;
+ private String city;
+
+ public int getNumber() {
+ return number;
+ }
+ public void setNumber(int number) {
+ this.number = number;
+ }
+ public String getStreet() {
+ return street;
+ }
+ public void setStreet(String street) {
+ this.street = street;
+ }
+ public String getCity() {
+ return city;
+ }
+ public void setCity(String city) {
+ this.city = city;
+ }
+}
Added: projects/microcontainer/trunk/docs/examples/User_Guide/humanResourcesService/src/main/java/org/jboss/example/service/AgeBasedSalaryStrategy.java
===================================================================
--- projects/microcontainer/trunk/docs/examples/User_Guide/humanResourcesService/src/main/java/org/jboss/example/service/AgeBasedSalaryStrategy.java (rev 0)
+++ projects/microcontainer/trunk/docs/examples/User_Guide/humanResourcesService/src/main/java/org/jboss/example/service/AgeBasedSalaryStrategy.java 2007-10-31 08:44:23 UTC (rev 66596)
@@ -0,0 +1,63 @@
+package org.jboss.example.service;
+
+import java.util.Calendar;
+
+/**
+ * Check that the salary is relative to the employee's age in years.
+ */
+public class AgeBasedSalaryStrategy implements SalaryStrategy {
+
+ private int minSalary = 5000;
+ private int maxSalary = 100000;
+
+ public Integer checkSalary(Employee employee, Integer salary) {
+
+ Calendar dateOfBirth = Calendar.getInstance();
+ dateOfBirth.setTime(employee.getDateOfBirth());
+
+ Calendar now = Calendar.getInstance();
+
+ if (now.before(dateOfBirth)) {
+ throw new IllegalArgumentException("Employee is not born yet!");
+ }
+
+ int age = now.get(Calendar.YEAR) - dateOfBirth.get(Calendar.YEAR);
+
+ // Check if the employee has already had their birthday this year
+ if (age > 0) {
+ if (now.get(Calendar.MONTH) - dateOfBirth.get(Calendar.MONTH) > 0) {
+ age--;
+ } else if (now.get(Calendar.MONTH) - dateOfBirth.get(Calendar.MONTH) == 0) {
+ if (now.get(Calendar.DAY_OF_MONTH) - dateOfBirth.get(Calendar.DAY_OF_MONTH) > 0 ) {
+ age--;
+ }
+ }
+ }
+
+ // Set minimum salaries depending on the age of the employee
+ if (age >= 21 && age < 30 && salary < 25000) {
+ salary = 25000;
+ }
+
+ if (age >= 30 && age < 50 && salary < 50000) {
+ salary = 50000;
+ }
+
+ // Apply company-wide ranges
+ if (salary < minSalary) {
+ salary = minSalary;
+ } else if (salary > maxSalary) {
+ salary = maxSalary;
+ }
+
+ return salary;
+ }
+
+ public void setMinSalary(int minSalary) {
+ this.minSalary = minSalary;
+ }
+
+ public void setMaxSalary(int maxSalary) {
+ this.maxSalary = maxSalary;
+ }
+}
Added: projects/microcontainer/trunk/docs/examples/User_Guide/humanResourcesService/src/main/java/org/jboss/example/service/Employee.java
===================================================================
--- projects/microcontainer/trunk/docs/examples/User_Guide/humanResourcesService/src/main/java/org/jboss/example/service/Employee.java (rev 0)
+++ projects/microcontainer/trunk/docs/examples/User_Guide/humanResourcesService/src/main/java/org/jboss/example/service/Employee.java 2007-10-31 08:44:23 UTC (rev 66596)
@@ -0,0 +1,74 @@
+package org.jboss.example.service;
+
+import java.util.Date;
+
+public class Employee {
+
+ private String firstName;
+ private String lastName;
+ private Date dateOfBirth;
+ private Address address;
+
+ public Employee(String firstName, String lastName) {
+ this.firstName = firstName;
+ this.lastName = lastName;
+ }
+
+ public String getFirstName() {
+ return firstName;
+ }
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+ public String getLastName() {
+ return lastName;
+ }
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
+ public Date getDateOfBirth() {
+ return dateOfBirth;
+ }
+ public void setDateOfBirth(Date dateOfBirth) {
+ this.dateOfBirth = dateOfBirth;
+ }
+ public Address getAddress() {
+ return address;
+ }
+ public void setAddress(Address address) {
+ this.address = address;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result
+ + ((firstName == null) ? 0 : firstName.hashCode());
+ result = prime * result
+ + ((lastName == null) ? 0 : lastName.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ final Employee other = (Employee) obj;
+ if (firstName == null) {
+ if (other.firstName != null)
+ return false;
+ } else if (!firstName.equals(other.firstName))
+ return false;
+ if (lastName == null) {
+ if (other.lastName != null)
+ return false;
+ } else if (!lastName.equals(other.lastName))
+ return false;
+ return true;
+ }
+}
Added: projects/microcontainer/trunk/docs/examples/User_Guide/humanResourcesService/src/main/java/org/jboss/example/service/LocationBasedSalaryStrategy.java
===================================================================
--- projects/microcontainer/trunk/docs/examples/User_Guide/humanResourcesService/src/main/java/org/jboss/example/service/LocationBasedSalaryStrategy.java (rev 0)
+++ projects/microcontainer/trunk/docs/examples/User_Guide/humanResourcesService/src/main/java/org/jboss/example/service/LocationBasedSalaryStrategy.java 2007-10-31 08:44:23 UTC (rev 66596)
@@ -0,0 +1,48 @@
+package org.jboss.example.service;
+
+/**
+ * Check that the salary is relative to the employee's location.
+ */
+public class LocationBasedSalaryStrategy implements SalaryStrategy {
+
+ private int minSalary = 5000;
+ private int maxSalary = 100000;
+
+ private static final int LONDON_MIN_SALARY = 50000;
+ private static final int MANCHESTER_MIN_SALARY = 40000;
+ private static final int GLASGOW_MIN_SALARY = 30000;
+ private static final int BELFAST_MIN_SALARY = 20000;
+
+ public Integer checkSalary(Employee employee, Integer salary) {
+
+ String city = employee.getAddress().getCity();
+
+ // Set minimum salaries depending on the location of the employee
+ if (city.equals("London") && salary < LONDON_MIN_SALARY) {
+ salary = LONDON_MIN_SALARY;
+ } else if (city.equals("Manchester") && salary < MANCHESTER_MIN_SALARY) {
+ salary = MANCHESTER_MIN_SALARY;
+ } else if (city.equals("Glasgow") && salary < GLASGOW_MIN_SALARY) {
+ salary = GLASGOW_MIN_SALARY;
+ } else if (city.equals("Belfast") & salary < BELFAST_MIN_SALARY) {
+ salary = BELFAST_MIN_SALARY;
+ }
+
+ // Apply company-wide ranges
+ if (salary < minSalary) {
+ salary = minSalary;
+ } else if (salary > maxSalary) {
+ salary = maxSalary;
+ }
+
+ return salary;
+ }
+
+ public void setMinSalary(int minSalary) {
+ this.minSalary = minSalary;
+ }
+
+ public void setMaxSalary(int maxSalary) {
+ this.maxSalary = maxSalary;
+ }
+}
Modified: projects/microcontainer/trunk/docs/examples/User_Guide/humanResourcesService/src/main/java/org/jboss/example/service/Manager.java
===================================================================
--- projects/microcontainer/trunk/docs/examples/User_Guide/humanResourcesService/src/main/java/org/jboss/example/service/Manager.java 2007-10-31 07:23:35 UTC (rev 66595)
+++ projects/microcontainer/trunk/docs/examples/User_Guide/humanResourcesService/src/main/java/org/jboss/example/service/Manager.java 2007-10-31 08:44:23 UTC (rev 66596)
@@ -1,11 +1,78 @@
package org.jboss.example.service;
-/**
- * @author <a href="mailto:mark.newton at jboss.org">Mark Newton</a>
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * An Manager keeps track of a set of employees and their associated salaries.
*/
public class Manager {
+ private static final Integer STANDARD_SALARY = 10000;
+
+ private Map<Employee, Integer> employees;
+
+ private boolean hiringFreeze = false;
+
+ private SalaryStrategy salaryStrategy = null;
+
public Manager() {
System.out.println("Hello from the manager...");
+ employees = new ConcurrentHashMap<Employee, Integer>();
}
+
+ public boolean addEmployee(Employee employee) {
+ if (hiringFreeze == false) {
+ employees.put(employee, STANDARD_SALARY);
+ }
+
+ return (hiringFreeze == false);
+ }
+
+ public Set<Employee> getEmployees() {
+ return employees.keySet();
+ }
+
+ public Employee getEmployee(String firstName, String lastName) {
+ Set<Employee> employees = getEmployees();
+ for (Employee employee : employees) {
+ if (employee.getFirstName().equals(firstName)
+ && employee.getLastName().equals(lastName)) {
+ return employee;
+ }
+ }
+
+ return null;
+ }
+
+ public void removeEmployee(Employee employee) {
+ employees.remove(employee);
+ }
+
+ public Integer getSalary(Employee employee) {
+ return employees.get(employee);
+ }
+
+ public void setSalary(Employee employee, Integer salary) {
+
+ int adjustedSalary = salary;
+
+ if (salaryStrategy != null) {
+ adjustedSalary = salaryStrategy.checkSalary(employee, salary);
+ }
+ employees.put(employee, adjustedSalary);
+ }
+
+ public boolean isHiringFreeze() {
+ return hiringFreeze;
+ }
+
+ public void setHiringFreeze(boolean hiringFreeze) {
+ this.hiringFreeze = hiringFreeze;
+ }
+
+ public void setSalaryStrategy(SalaryStrategy salaryStrategy) {
+ this.salaryStrategy = salaryStrategy;
+ }
}
Added: projects/microcontainer/trunk/docs/examples/User_Guide/humanResourcesService/src/main/java/org/jboss/example/service/SalaryStrategy.java
===================================================================
--- projects/microcontainer/trunk/docs/examples/User_Guide/humanResourcesService/src/main/java/org/jboss/example/service/SalaryStrategy.java (rev 0)
+++ projects/microcontainer/trunk/docs/examples/User_Guide/humanResourcesService/src/main/java/org/jboss/example/service/SalaryStrategy.java 2007-10-31 08:44:23 UTC (rev 66596)
@@ -0,0 +1,6 @@
+package org.jboss.example.service;
+
+public interface SalaryStrategy {
+
+ public Integer checkSalary(Employee employee, Integer salary);
+}
More information about the jboss-cvs-commits
mailing list