Guest User

Untitled

a guest
Feb 22nd, 2018
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.26 KB | None | 0 0
  1. public final class Employee {
  2.   public static void main(String[] args) {
  3.     // Employee e = new Employee("Lex", 24, 250);
  4.     // e = Employee.setName(e, "Vasili");
  5.     // e = Employee.setAge(e, 12);
  6.     // e = Employee.setSalary(e, 2500);
  7.     // Employee.log(e);
  8.     Stream
  9.       .of(new Employee())
  10.       .map((e, "Vasili") -> Employee::setName)
  11.       .findFirst()
  12.       .get();
  13.   }
  14.  
  15.   public final String name;
  16.   public final Integer age;
  17.   public final Integer salary;
  18.  
  19.   public Employee(final String nameArg,
  20.                   final Integer ageArg,
  21.                   final Integer salaryArg) {
  22.     this.name   = nameArg;
  23.     this.age    = ageArg;
  24.     this.salary = salaryArg;
  25.   }
  26.  
  27.   public static Employee setName(final Employee e, final String n) {
  28.     return new Employee(n, e.age, e.salary);
  29.   }
  30.  
  31.   public static Employee setAge(final Employee e, final Integer a) {
  32.     return new Employee(e.name, a, e.salary);
  33.   }
  34.  
  35.   public static Employee setSalary(final Employee e, final Integer s) {
  36.     return new Employee(e.name, e.age, s);
  37.   }
  38.  
  39.   public static void log(final Employee e) {
  40.     System.out.println("Name: " + e.name + ", " +
  41.                        "age: " + e.age + ", " +
  42.                        "salary: " + e.salary + ".");
  43.   }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment