1*** Settings ***
2Documentation  This module contains keywords for list manipulation.
3Library  Collections
4
5*** Keywords ***
6Intersect Lists
7    [Documentation]  Intersects the two lists passed in. Returns a list of
8    ...  values common to both lists with no duplicates.
9    [Arguments]  ${list1}  ${list2}
10
11    # list1      The first list to intersect.
12    # list2      The second list to intersect.
13
14    ${length1}=  Get Length  ${list1}
15    ${length2}=  Get Length  ${list2}
16
17    @{intersected_list}  Create List
18
19    @{larger_list}=  Set Variable If  ${length1} >= ${length2}  ${list1}
20    ...                               ${length1} < ${length2}  ${list2}
21    @{smaller_list}=  Set Variable If  ${length1} >= ${length2}  ${list2}
22    ...                                ${length1} < ${length2}  ${list1}
23
24    :FOR  ${element}  IN  @{larger_list}
25    \  ${rc}=  Run Keyword and Return Status  List Should Contain Value  ${smaller_list}
26    ...  ${element}
27    \  Run Keyword If  '${rc}' == 'True'  Append to List  ${intersected_list}
28    ...  ${element}
29
30    @{intersected_list}=  Remove Duplicates  ${intersected_list}
31
32    [Return]  @{intersected_list}
33
34
35Subtract Lists
36    [Documentation]  Subtract list 2 from list 1 and return the result.
37    #  Return list contain items from the list 1 which are not present
38    #  in the list 2.
39    [Arguments]  ${list1}  ${list2}
40    # Description of argument(s):
41    # list1      The base list which is to be subtracted from.
42    # list2      The list which is to be subtracted from list1.
43
44    ${diff_list}=  Create List
45    :FOR  ${item}  IN  @{list1}
46    \  ${status}=  Run Keyword And Return Status
47    ...  Should Contain  ${list2}  ${item}
48    \  Run Keyword If  '${status}' == '${False}'
49    ...  Append To List  ${diff_list}  ${item}
50
51    [Return]  ${diff_list}
52