Home > Back-end >  Turn to the great god code to solve!!!!!!
Turn to the great god code to solve!!!!!!

Time:01-30

1) department of company division
{{L1: 'HR', L2: 'staffing'},
{L1: 'HR', L2: 'training'},
{L1: 'HR', L2: 'motivation'},
{L1: 'Finance', L2: 'Banking'},
{L1: 'Finance', L2: 'Insurance'},
{L1: 'Finance', L2: 'Investment'},
{L1: 'Technology', L2: 'Development'},
{L1: 'Technology', L2: 'Testing'},
{L1: 'Technology', L2: 'Business'}
. }

2) employee information
{{' id ':' 1 ', name: 'name1' L1: 'Finance', L2: 'Insurance'},
. ,
{' id ':' 1000 ', name: 'name1000, L1:' Technology ', L2: 'Business'}}
Topic: if for some department has no staff, from the 1) removed, generate the latest department division,

Pray god to write

CodePudding user response:

1 into listThe 2 into listTraverse 1 for each department, determine whether in the absence of repeating unit exists in the collection,

CodePudding user response:

You the design department of a table and a staff table, the table of the departments with parent-child relationships, staff table: id, name, department_id

CodePudding user response:

Make key12=L1 + L2;
The employee information read the map
The Map Map=new HashMap ();
For {...
The map. The put (key12, person);//person for employee information
.
}
//to read in deptMap department information;
Traverse deptMap - & gt; KeyEle {
If the map. The get (keyEle. Key)==null
{
DeptMap. Remove (keyEle. Key);
}
}
//to output deptMap

//pseudo code generally true,

CodePudding user response:

 

The import lombok. AllArgsConstructor;
The import lombok. Data;
The import lombok. NoArgsConstructor;

Import the Java. Util. Objects;

/* *
* @ author zhaojinhui
* @ date 2021/1/29 16:06
* @ apiNote
*/

@ Data
@ NoArgsConstructor
@ AllArgsConstructor
Public class Dept {

Private String l1.

Private String l2;


@ Override
Public Boolean equals (Object o) {
If (this==o) return true;
If (o==null | | getClass ()!=o.g etClass ()); return false
Dept Dept=(Dept) o;
Return Objects. Equals (l1, dept. L1) & amp; &
Objects. The equals (l2, dept. L2);
}

@ Override
Public int hashCode () {
Return l1. HashCode () & lt; <5-1 - l2. HashCode ();
}
}



The import lombok. AllArgsConstructor;
The import lombok. Data;
The import lombok. NoArgsConstructor;

/* *
* @ author zhaojinhui
* @ date 2021/1/29 16:06
* @ apiNote
*/
@ Data
@ NoArgsConstructor
@ AllArgsConstructor
Public class Emp {
private Integer id;

private String name;

Private String l1.

Private String l2;

}


import java.util.ArrayList;
Import the Java. Util. Collections;
import java.util.List;
Import the Java. Util. Set;
Import the Java. Util. Stream. Collectors;

/* *
* @ author zhaojinhui
* @ date 2021/1/29 16:05
* @ apiNote
*/
Public class Test {
Public static void main (String [] args) {
List Depts=new ArrayList<> (a);
The Collections. AddAll (depts,
New Dept (" HR ", "staffing"),
New Dept (" HR ", "training"),
New Dept (" HR ", "motivation"),
New Dept (" Finance ", "Backing"),
New Dept (" Finance ", "Insurance"),
New Dept (" Finance ", "Investment"),
New Dept (" Technology ", "Development"),
New Dept (" Technology ", "Testing"),
New Dept (" Technology ", "Business")
);

List Emps=new ArrayList<> (a);
The Collections. AddAll (emps,
New Emp (1, "name", "Finance", "Backing"),
New Emp (2, "name", "HR", "training"),
New Emp (3, "name", "Technology", "Testing")
);

Calculate according to the L1 and L2//hashCode
Set DeptHashCodeSet=emps. Stream (). The map (m - & gt; M.g etL1 (). The hashCode () & lt; <5-1 - m.g etL2 (). The hashCode ()). Collect (Collectors. ToSet ());

List Collect=depts. Stream (). The map (emp - & gt; DeptHashCodeSet. The contains (emp) hashCode ())? Emp: null). Collect (Collectors. ToList ());
Collect. RemoveAll (Collections. The singleton (null));
Collect. ForEach (System. Out: : println);


}
}





  • Related