-1

first List

remoteDeviceAndPort===>List(
  (1,891w.yourdomain.com,wlan-ap0), 
   (13,ap,GigabitEthernet0), 
    (11,Router-3900,GigabitEthernet0/0)
   )

second List

interfacesList===>List(
  (1,UP,,0,0,0,0,UP,4294,other,VoIP-Null0,0,0),
  (13,DOWN,,0,0,0,0,UP,100,Ethernet,FastEthernet6,0,0),
  (11,UP,,0,0,0,0,UP,100,vlan,Vlan11,4558687845,1249542878), 
  (2,UP,,0,0,972,1327,UP,0,Tunnel,Virtual-Access1,0,0), 
  (4,DOWN,,0,0,0,0,UP,100,Ethernet,FastEthernet2,0,0),
  (6,DOWN,,0,0,0,0,UP,100,Ethernet,FastEthernet2,0,0)
  )

The above are my two lists now i have to combine these two lists like below.

Expected OutPut =>

 combineList = List(
   (1,UP,,0,0,0,0,UP,4294,other,VoIP-Null0,0,0,891w.yourdomain.com,wlan-ap0),        
   (13,DOWN,,0,0,0,0,UP,100,Ethernet,FastEthernet6,0,0,ap,GigabitEthernet0),
  (11,UP,,0,0,0,0,UP,100,vlan,Vlan11,4558687845,1249542878,Router-3900,GigabitEthernet0/0),
   (2,UP,,0,0,972,1327,UP,0,Tunnel,Virtual-Access1,0,0,empty,empty), 
  (4,DOWN,,0,0,0,0,UP,100,Ethernet,FastEthernet2,0,0,empty,empty),
  (6,DOWN,,0,0,0,0,UP,100,Ethernet,FastEthernet2,0,0,empty,empty)

)

1 Answers1

0

The similar question here

case class NetworkDeviceInterfaces(index: Int, params: String*)

val remoteDeviceAndPort = List(
  (1,"891w.yourdomain.com","wlan-ap0"),
  (13,"ap","GigabitEthernet0"),
  (11,"Router-3900","GigabitEthernet0/0")
)

val rdapMap = remoteDeviceAndPort map {case (k, v1, v2) => k -> (v1, v2) } toMap

val interfacesList = List(NetworkDeviceInterfaces(1,"UP","","0","0","0","0","UP","4294","other","VoIP-Null0","0","0"))

val result = interfacesList map {
  interface => {
    val (first, second) = rdapMap.getOrElse(interface.index, ("empty", "empty"))
    NetworkDeviceInterfaces(interface.index, (interface.params ++ Seq(first, second)):_*)
  }
}
Community
  • 1
  • 1
hellraiser
  • 1,451
  • 12
  • 19
  • case class NetworkDeviceInterfaces( ifIndex: Int, ifOperStatus: String, ifDescr: String, ifOutErrors: Int, ifInErrors: Int, ifInOctets: Long, ifOutOctets: Long, ifAdminStatus: String, ifSpeedMbps: Long, ifType: String, ifName: String, ifHCOutOctets: Long, ifHCInOctets: Long) – user3825542 Oct 13 '14 at 10:59
  • case class InterfaceRemoteDeviceAndPort(ifIndex: Int, remoteDevice: String, remotePort: String) – user3825542 Oct 13 '14 at 10:59
  • case class NetworkDeviceInterfaces( ifIndex: Int, ifOperStatus: String, ifDescr: String, ifOutErrors: Int, ifInErrors: Int, ifInOctets: Long, ifOutOctets: Long, ifAdminStatus: String, ifSpeedMbps: Long, ifType: String, ifName: String, ifHCOutOctets: Long, ifHCInOctets: Long) – user3825542 Oct 13 '14 at 11:06
  • It doesn't matter how your entities look like. I showed you decision of more abstract problem. You have two collections: base objects with key field and additional objects with the identifier. You need to enrich objects from base collection with data from additional collection by key equality. – hellraiser Oct 13 '14 at 11:32
  • val listVlanAndIpAddress = interfacesList map { case (index, v1, v2) => (index, v1, v2, remoteDeviceAndPort.toMap.getOrElse(index, "")) } – user3825542 Oct 13 '14 at 11:50
  • descrList==>List((12,VoIP-Null0,1), (8,FastEthernet6,6),(19,Vlan11,53), (4,FastEthernet2,6), (15,Vlan1,53), (11,GigabitEthernet0,6), (9,FastEthernet7,6), (22,Vlan20,53), (13,Wlan-GigabitEthernet0,6), (16,Async1,1), (5,FastEthernet3,6), (10,FastEthernet8,6), (21,Vlan12,53), (6,FastEthernet4,6), (1,wlan-ap0,24), (17,Virtual-Template1,131), (14,Null0,1), (20,Vlan10,53), (2,FastEthernet0,6), (18,NVI0,1), (7,FastEthernet5,6), (29,Virtual-Access7,131), (3,FastEthernet1,6), (28,Virtual-Access6,131)) – user3825542 Oct 13 '14 at 11:59
  • ipAddressList==>List((21,192.168.12.1), (19,192.168.11.1), (11,104.36.252.115), (20,192.168.10.1), (22,192.168.20.1)) – user3825542 Oct 13 '14 at 11:59
  • val listVlanAndIpAddress = descrList.filter(_._3.equalsIgnoreCase("vlan")) map { case (index, v1, v2) => (index, v1, v2, ipAddressList.toMap.getOrElse(index, "")) } with the above code i got the output like below remoteDeviceAndPort===>List((1,891w.yourdomain.com,wlan-ap0), (13,ap,GigabitEthernet0), (11,Router-3900,GigabitEthernet0/0), (11,FRE RESO,ether4), (2,sky,GigabitEthernet0/1)) – user3825542 Oct 13 '14 at 11:59
  • same thing i have to do with my two lists which are posted in my question..look out them – user3825542 Oct 13 '14 at 12:00
  • hello hellraiser i think last day you only sent me the solution – user3825542 Oct 13 '14 at 12:12