Home > Back-end >  The data processing
The data processing

Time:04-03



, as shown in the above left in an Excel file, can't read the first line, the second line in the header of the 'level' indefinite number, the possibility of 3/4/5/... Corresponding 3/4/5 column/... Level, behind the number/name/specifications/quantity/unit five columns fixed,

Requirements: similar to the manufacturing BOM, separate the data according to the level as shown in figure in the right,
Difficulty (1) parsing file 'level' number has settled through (access to the largest number of columns - 5);
Difficult (2) in the order read from top down, below the level 1 only with own below level 2 and greater than level 2 skip, if appear again behind, level 1, then the second time appear behind the level 1 level 2 as the second level 1 (usually a file only a level 1).
Level 2 below only with their the level 3 below, the skip of larger than level 3, if appear again later, level 2, then the second time behind the level 2 level 3 as the second level 2;
Level 3 below only with their the level 4 below, the skip of larger than level 4, if appear again behind, level 3, then the second time in level 3 at the back of the level 4 as the second level 3;
So on,
Difficulty (3) the last hope to List List=new ArrayList (a); Type of storage, will split the independence of each group,

Himself wrote a two days this logic... Feel how write all cannot solve the level 3 only to appear in the last 2, meet next 2 jump out, and then continue to split a
Everybody a great god help see can solve, thank you thank you!

CodePudding user response:

CodePudding user response:

You can't read while the output, should complete the data read into memory first.
In the memory, can use Map Way of recording data, the key is level, List Is the level of the index value of the collection order (from top to bottom),
After reading, you save your map global information. Can recursively, incoming call recursive method two parameters: the level=1, level 1 index=0, + 1=2, then the key take 2 have to judge the following list, if any, traverse the level 2, and then call the recursive method is introduced to level 2, level 2 instead of the index, the recursive until decision condition is level 5, this time at level 5, the participation in do you know how much is the index of level 4, with the index of level 4, to find his next index. You'll get the table row index of the scope of level 5. Can split out the lowest table.

CodePudding user response:

refer to the second floor of the Yangtze river water to write diary response:
you can't read while the output, should complete the data read into memory first.
In the memory, can use Map Way of recording data, the key is level, List Is the level of the index value of the collection order (from top to bottom),
After reading, you save your map global information. Can recursively, incoming call recursive method two parameters: the level=1, level 1 index=0, + 1=2, then the key take 2 have to judge the following list, if any, traverse the level 2, and then call the recursive method is introduced to level 2, level 2 instead of the index, the recursive until decision condition is level 5, this time at level 5, the participation in do you know how much is the index of level 4, with the index of level 4, to find his next index. You'll get the table row index of the scope of level 5. Can split out the lowest table.


I am directly at the time of reading Excel will take out all the data at once, use List List=new ArrayList (a); The type, the List. The get (0) is the first article of the Excel data, get (1) is the second, and so on,

The key is how this batch of data down behind a group of a group of List This logic, has been written, and it can code for a demonstration?

CodePudding user response:

You need to process the Map< first. Integer, List This to just go, you this List Just bring out each line of data, where each level is a line not clear

CodePudding user response:

//data processing in the first place in the map key=& gt; Level value=https://bbs.csdn.net/topics/> table row index 
Private static Map ALL_DATA=https://bbs.csdn.net/topics/null;
//your data
Private static List Lists=new ArrayList (a);

Private static void recursion (Integer level, Integer rowIndex) {
Integer nextLevel=level + 1;
If (CollectionUtils. IsNotEmpty (ALL_DATA. Get (nextLevel))) {
List LevleList=ALL_DATA. Get (level);
If (levleList. The size () - 1==levleList. IndexOf (rowIndex)) {
//todo to get him under the level of the next level, the output
} else {
Integer nextRowIndex=levleList.get(levleList.indexOf(rowIndex) + 1);
List NewLevleList=ALL_DATA. Get (nextLevel);
//select the level of the next level of the index of rows in the table
List Collect=newLevleList. Stream (). The filter (a - & gt; a> RowIndex & amp; & A. & lt; NextRowIndex). Collect (Collectors. ToList ());
//todo o
}
for (int i=0; I & lt; ALL_DATA. Get (nextLevel). The size (); I++) {
Recursion (nextLevel, I);
}
}
}

CodePudding user response:

The
cited the fifth floor of the Yangtze river water to write diary reply:
//data processing in the first place in the map key=& gt; Level value=https://bbs.csdn.net/topics/> table row index 
Private static Map ALL_DATA=https://bbs.csdn.net/topics/null;
//your data
Private static List Lists=new ArrayList (a);

Private static void recursion (Integer level, Integer rowIndex) {
Integer nextLevel=level + 1;
If (CollectionUtils. IsNotEmpty (ALL_DATA. Get (nextLevel))) {
List LevleList=ALL_DATA. Get (level);
If (levleList. The size () - 1==levleList. IndexOf (rowIndex)) {
//todo to get him under the level of the next level, the output
} else {
Integer nextRowIndex=levleList.get(levleList.indexOf(rowIndex) + 1);
List NewLevleList=ALL_DATA. Get (nextLevel);
//select the level of the next level of the index of rows in the table
List Collect=newLevleList. Stream (). The filter (a - & gt; a> RowIndex & amp; & A. & lt; NextRowIndex). Collect (Collectors. ToList ());
//todo o
}
for (int i=0; I & lt; ALL_DATA. Get (nextLevel). The size (); I++) {
Recursion (nextLevel, I);
}
}
}


I consider the first thank you!
  • Related