Last active
August 29, 2015 14:19
-
-
Save wbars/dbbd1c9ae7262391deba to your computer and use it in GitHub Desktop.
Company
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.helloworld; | |
import java.util.Date; | |
/** | |
* Created by wannabe on 18.04.15. | |
*/ | |
public abstract class BasicEmployee { | |
protected int id; | |
protected String name; | |
protected float salary; | |
protected Date hiringDate; | |
/** | |
* @param id | |
* @param name | |
* @param salary | |
* @param hiringDate | |
*/ | |
public BasicEmployee(int id, String name, float salary, Date hiringDate) { | |
this.id = id; | |
this.name = name; | |
this.salary = salary; | |
this.hiringDate = hiringDate; | |
} | |
public String name() { | |
return this.name; | |
} | |
public float salary() { | |
return this.salary; | |
} | |
public BasicEmployee salary(float salary) { | |
this.salary = salary; | |
return this; | |
} | |
public int id() { | |
return this.id; | |
} | |
public Date hiringDate() { | |
return this.hiringDate; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.helloworld; | |
import java.util.HashMap; | |
/** | |
* Created by wannabe on 18.04.15. | |
*/ | |
public class Company { | |
protected HashMap<Integer, BasicEmployee> employees; | |
protected String name; | |
public Company(String name) { | |
this.name = name; | |
this.employees = new HashMap<>(); | |
} | |
public Company(String name, HashMap<Integer, BasicEmployee> employees) { | |
this.name = name; | |
this.employees = employees; | |
} | |
public String name() { | |
return this.name; | |
} | |
public HashMap<Integer, BasicEmployee> employees() { | |
return this.employees; | |
} | |
public Company employees(HashMap<Integer, BasicEmployee> employees) { | |
this.employees = employees; | |
return this; | |
} | |
public Company addEmployee(BasicEmployee employee) { | |
this.employees.put(employee.id(), employee); | |
return this; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.helloworld; | |
import java.util.Date; | |
/** | |
* Created by wannabe on 18.04.15. | |
*/ | |
public class Employee extends BasicEmployee { | |
protected Head head; | |
/** | |
* @param id | |
* @param name | |
* @param salary | |
* @param hiringDate | |
*/ | |
public Employee(int id, String name, float salary, Date hiringDate) { | |
super(id, name, salary, hiringDate); | |
} | |
/** | |
* @param id | |
* @param name | |
* @param salary | |
* @param hiringDate | |
* @param head | |
*/ | |
public Employee(int id, String name, float salary, Date hiringDate, Head head) { | |
super(id, name, salary, hiringDate); | |
this.head = head; | |
} | |
public Head head() { | |
return this.head; | |
} | |
public BasicEmployee head(Head head) { | |
this.head = head; | |
return this; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.helloworld; | |
import java.lang.reflect.Array; | |
import java.util.ArrayList; | |
import java.util.Date; | |
import java.util.HashMap; | |
/** | |
* Created by wannabe on 18.04.15. | |
*/ | |
public class Head extends BasicEmployee { | |
HashMap<Integer, BasicEmployee> subordinates; | |
public static Head build(BasicEmployee employee) { | |
return new Head(employee.id(), employee.name(), employee.salary(), employee.hiringDate()); | |
} | |
public static Head build(BasicEmployee employee, HashMap<Integer, BasicEmployee> subordinates) { | |
return new Head(employee.id(), employee.name(), employee.salary(), employee.hiringDate(), subordinates); | |
} | |
/** | |
* @param id | |
* @param name | |
* @param salary | |
* @param hiringDate | |
*/ | |
public Head(int id, String name, float salary, Date hiringDate, HashMap<Integer, BasicEmployee> subordinates) { | |
super(id, name, salary, hiringDate); | |
this.subordinates = subordinates; | |
} | |
/** | |
* @param id | |
* @param name | |
* @param salary | |
* @param hiringDate | |
*/ | |
public Head(int id, String name, float salary, Date hiringDate) { | |
super(id, name, salary, hiringDate); | |
this.subordinates = new HashMap<>(); | |
} | |
public HashMap<Integer, BasicEmployee> subordinates() { | |
return this.subordinates; | |
} | |
public Head subordinates(HashMap<Integer, BasicEmployee> subordinates) { | |
this.subordinates = subordinates; | |
return this; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.helloworld; | |
import java.text.DateFormat; | |
import java.text.ParseException; | |
import java.text.SimpleDateFormat; | |
import java.util.*; | |
/** | |
* Created by wannabe on 12.04.15. | |
*/ | |
public class Main | |
{ | |
public static void main(String[] args) throws ParseException | |
{ | |
Company company = new Company("Google"); | |
DateFormat formatter = new SimpleDateFormat("dd-MM-yyyy"); | |
Employee worker1 = new Employee(1, "Программист Вася", 15.55f, formatter.parse("11-11-2015")); | |
HashMap<Integer, BasicEmployee> workerList = new HashMap<>(); | |
workerList.put(worker1.id(), worker1); | |
Head head = new Head(2, "Сергей Брин", 500f, formatter.parse("11-11-2015"), workerList); | |
company.addEmployee(worker1).addEmployee(head); | |
for (Map.Entry<Integer, BasicEmployee> employee : company.employees().entrySet()) { | |
System.out.println(employee.getValue().id()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment