/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
public class TaskEmployee {
public static void main
(String[] args
) { DataBase dataBase = new DataBase();
for (Employee em : dataBase.findByString("ge")) {
System.
out.
println("FindByString \n" + em.
toString()); }
dataBase.setDateNow("2015 1");
for (Employee em : dataBase.findByYears(2)) {
System.
out.
println("findByYears\n" + em.
toString()); }
}
}
class Employee {
this.lastName = lastName;
this.firstName = firstName;
this.midName = midName;
this.address = address;
this.date = date;
}
this.lastName = lastName;
this.firstName = firstName;
this.address = address;
this.date = date;
}
return lastName;
}
public void setLastName
(String lastName
) { this.lastName = lastName;
}
public String getFirstName
() { return firstName;
}
public void setFirstName
(String firstName
) { this.firstName = firstName;
}
return midName;
}
public void setMidName
(String midName
) { this.midName = midName;
}
return address;
}
public void setAddress
(String address
) { this.address = address;
}
return date;
}
public void setDate
(String date
) { this.date = date;
}
public int getYear
(String now
) { int year
= Integer.
parseInt(now.
split(" ")[0]); int month
= Integer.
parseInt(now.
split(" ")[1]); int y
= Integer.
parseInt(date.
split(" ")[0]); int m
= Integer.
parseInt(date.
split(" ")[1]); y = year - y;
if (month < m) {
y--;
}
return y;
}
@Override
return "Employee : " +
"lastName='" + lastName + '\'' +
", firstName='" + firstName + '\'' +
", midName='" + midName + '\'' +
", address='" + address + '\'' +
", date='" + date + '\'';
}
}
class DataBase {
private List<Employee> employeeList;
public DataBase() {
this.employeeList = new ArrayList<Employee>();
employeeList.add(new Employee("Vihrev", "Petr", "Petrovich", "Ivanovo", "2010 5"));
employeeList.add(new Employee("Petrov", "Vasiliy", "Ivanovich", "Kazan", "2011 3"));
employeeList.add(new Employee("Gareev", "Evgeniy", "Ufa", "2015 5"));
employeeList.add(new Employee("Plotnikov", "Georgiy", "Omsk", "2012 1"));
employeeList.add(new Employee("Grishakov", "Roman", "Mihaylovich", "Moscow", "2014 8"));
}
return dateNow;
}
public void setDateNow
(String dateNow
) { this.dateNow = dateNow;
}
public List<Employee> getEmployeeList() {
return employeeList;
}
public List<Employee> findByYears(int year) {
List<Employee> res = new ArrayList<>();
for (Employee emp : getEmployeeList()) {
if (emp.getYear(getDateNow()) >= year) {
res.add(emp);
}
}
return res;
}
public List
<Employee
> findByString
(String ex
) { List<Employee> res = new ArrayList<>();
String reg
= ex.
toLowerCase(); for (Employee emp : getEmployeeList()) {
String sum
= (emp.
getFirstName() + " " + emp.
getLastName() + " " + emp.
getMidName()).
toLowerCase(); if (sum.contains(reg)) {
res.add(emp);
}
}
return res;
}
}
LyogcGFja2FnZSB3aGF0ZXZlcjsgLy8gZG9uJ3QgcGxhY2UgcGFja2FnZSBuYW1lISAqLwoKaW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5nLio7CmltcG9ydCBqYXZhLmlvLio7CgpwdWJsaWMgY2xhc3MgVGFza0VtcGxveWVlIHsKICAgIHB1YmxpYyBzdGF0aWMgdm9pZCBtYWluKFN0cmluZ1tdIGFyZ3MpIHsKICAgICAgICBEYXRhQmFzZSBkYXRhQmFzZSA9IG5ldyBEYXRhQmFzZSgpOwogICAgICAgIGZvciAoRW1wbG95ZWUgZW0gOiBkYXRhQmFzZS5maW5kQnlTdHJpbmcoImdlIikpIHsKICAgICAgICAgICAgU3lzdGVtLm91dC5wcmludGxuKCJGaW5kQnlTdHJpbmcgXG4iICsgZW0udG9TdHJpbmcoKSk7CiAgICAgICAgfQogICAgICAgIGRhdGFCYXNlLnNldERhdGVOb3coIjIwMTUgMSIpOwogICAgICAgIGZvciAoRW1wbG95ZWUgZW0gOiBkYXRhQmFzZS5maW5kQnlZZWFycygyKSkgewogICAgICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oImZpbmRCeVllYXJzXG4iICsgZW0udG9TdHJpbmcoKSk7CiAgICAgICAgfQogICAgfQp9CiAKY2xhc3MgRW1wbG95ZWUgewogICAgcHJpdmF0ZSBTdHJpbmcgbGFzdE5hbWU7CiAgICBwcml2YXRlIFN0cmluZyBmaXJzdE5hbWU7CiAgICBwcml2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SkgewogICAgICAgICAgICB5LS07CiAgICAgICAgfQogICAgICAgIHJldHVybiB5OwogICAgfQogCiAgICBAT3ZlcnJpZGUKICAgIHB1YmxpYyBTdHJpbmcgdG9TdHJpbmcoKSB7CiAgICAgICAgcmV0dXJuICJFbXBsb3llZSA6ICIgKwogICAgICAgICAgICAgICAgImxhc3ROYW1lPSciICsgbGFzdE5hbWUgKyAnXCcnICsKICAgICAgICAgICAgICAgICIsIGZpcnN0TmFtZT0nIiArIGZpcnN0TmFtZSArICdcJycgKwogICAgICAgICAgICAgICAgIiwgbWlkTmFtZT0nIiArIG1pZE5hbWUgKyAnXCcnICsKICAgICAgICAgICAgICAgICIsIGFkZHJlc3M9JyIgKyBhZGRyZXNzICsgJ1wnJyArCiAgICAgICAgICAgICAgICAiLCBkYXRlPSciICsgZGF0ZSArICdcJyc7CiAgICB9Cn0KIApjbGFzcyBEYXRhQmFzZSB7CiAKICAgIHByaXZhdGUgTGlzdDxFbXBsb3llZT4gZW1wbG95ZWVMaXN0OwogICAgcHJpdmF0ZSBTdHJpbmcgZGF0ZU5vdzsKIAogICAgcHVibGljIERhdGFCYXNlKCkgewogICAgICAgIHRoaXMuZW1wbG95ZWVMaXN0ID0gbmV3IEFycmF5TGlzdDxFbXBsb3llZT4oKTsKICAgICAgICBlbXBsb3llZUxpc3QuYWRkKG5ldyBFbXBsb3llZSgiVmlocmV2IiwgIlBldHIiLCAiUGV0cm92aWNoIiwgIkl2YW5vdm8iLCAiMjAxMCA1IikpOwogICAgICAgIGVtcGxveWVlTGlzdC5hZGQobmV3IEVtcGxveWVlKCJQZXRyb3YiLCAiVmFzaWxpeSIsICJJdmFub3ZpY2giLCAiS2F6YW4iLCAiMjAxMSAzIikpOwogICAgICAgIGVtcGxveWVlTGlzdC5hZGQobmV3IEVtcGxveWVlKCJHYXJlZXYiLCAiRXZnZW5peSIsICJVZmEiLCAiMjAxNSA1IikpOwogICAgICAgIGVtcGxveWVlTGlzdC5hZGQobmV3IEVtcGxveW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dldEVtcGxveWVlTGlzdCgpKSB7CiAgICAgICAgICAgIFN0cmluZyBzdW0gPSAoZW1wLmdldEZpcnN0TmFtZSgpICsgIiAiICsgZW1wLmdldExhc3ROYW1lKCkgKyAiICIgKyBlbXAuZ2V0TWlkTmFtZSgpKS50b0xvd2VyQ2FzZSgpOwogICAgICAgICAgICBpZiAoc3VtLmNvbnRhaW5zKHJlZykpIHsKICAgICAgICAgICAgICAgIHJlcy5hZGQoZW1wKTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gcmVzOwogICAgfQp9