66using System ;
77using System . Collections . Concurrent ;
88using System . Collections . Generic ;
9+ using System . Diagnostics . Contracts ;
910using System . Linq ;
1011
1112namespace Kveer . XBeeApi
1213{
13- /**
14- * This class represents an XBee Network.
15- *
16- * <p>The network allows the discovery of remote devices in the same network
17- * as the local one and stores them.</p>
18- */
14+ /// <summary>
15+ /// This class represents an XBee Network.
16+ /// </summary>
17+ /// <remarks>The network allows the discovery of remote devices in the same network as the local one and stores them.</remarks>
1918 public class XBeeNetwork
2019 {
21-
2220 // Variables.
23-
2421 private XBeeDevice localDevice ;
2522
2623 private ConcurrentDictionary < XBee64BitAddress , RemoteXBeeDevice > remotesBy64BitAddr ;
@@ -79,15 +76,12 @@ public XBeeNetwork(XBeeDevice device)
7976 * @see #getDevice(String)
8077 * @see RemoteXBeeDevice
8178 */
82- public RemoteXBeeDevice discoverDevice ( String id ) /*throws XBeeException */ {
83- if ( id == null )
84- throw new ArgumentNullException ( "Device identifier cannot be null." ) ;
85- if ( id . Length == 0 )
86- throw new ArgumentException ( "Device identifier cannot be an empty string." ) ;
79+ public RemoteXBeeDevice DiscoverDevice ( string id ) /*throws XBeeException */ {
80+ Contract . Requires < ArgumentNullException > ( ! string . IsNullOrEmpty ( id ) , "Device identifier cannot be null or empty." ) ;
8781
8882 logger . DebugFormat ( "{0}Discovering '{1}' device." , localDevice . ToString ( ) , id ) ;
8983
90- return nodeDiscovery . discoverDevice ( id ) ;
84+ return nodeDiscovery . DiscoverDevice ( id ) ;
9185 }
9286
9387 /**
@@ -115,7 +109,7 @@ public RemoteXBeeDevice discoverDevice(String id)/*throws XBeeException */{
115109 * @see #discoverDevice(String)
116110 * @see RemoteXBeeDevice
117111 */
118- public List < RemoteXBeeDevice > discoverDevices ( IList < String > ids ) /*throws XBeeException */ {
112+ public List < RemoteXBeeDevice > discoverDevices ( IList < string > ids ) /*throws XBeeException */ {
119113 if ( ids == null )
120114 throw new ArgumentNullException ( "List of device identifiers cannot be null." ) ;
121115 if ( ids . Count == 0 )
@@ -411,7 +405,10 @@ public RemoteXBeeDevice GetDevice(XBee64BitAddress address)
411405
412406 logger . DebugFormat ( "{0}Getting device '{1}' from network." , localDevice . ToString ( ) , address ) ;
413407
414- return remotesBy64BitAddr [ address ] ;
408+ RemoteXBeeDevice result ;
409+ remotesBy64BitAddr . TryGetValue ( address , out result ) ;
410+
411+ return result ;
415412 }
416413
417414 /**
@@ -510,8 +507,7 @@ public RemoteXBeeDevice addRemoteDevice(RemoteXBeeDevice remoteDevice)
510507 if ( addr64 != null && ! addr64 . Equals ( XBee64BitAddress . UNKNOWN_ADDRESS ) )
511508 {
512509 // The device has 64-bit address, so look in the 64-bit map.
513- devInNetwork = remotesBy64BitAddr [ addr64 ] ;
514- if ( devInNetwork != null )
510+ if ( remotesBy64BitAddr . TryGetValue ( addr64 , out devInNetwork ) )
515511 {
516512 // The device exists in the 64-bit map, so update the reference and return it.
517513 logger . DebugFormat ( "{0}Existing device '{1}' in network." , localDevice . ToString ( ) , devInNetwork . ToString ( ) ) ;
@@ -524,8 +520,7 @@ public RemoteXBeeDevice addRemoteDevice(RemoteXBeeDevice remoteDevice)
524520 if ( addr16 != null && ! addr16 . Equals ( XBee16BitAddress . UNKNOWN_ADDRESS ) )
525521 {
526522 // The device has 16-bit address, so look in the 16-bit map.
527- devInNetwork = remotesBy16BitAddr [ addr16 ] ;
528- if ( devInNetwork != null )
523+ if ( remotesBy16BitAddr . TryGetValue ( addr16 , out devInNetwork ) )
529524 {
530525 // The device exists in the 16-bit map, so remove it and add it to the 64-bit map.
531526 logger . DebugFormat ( "{0}Existing device '{1}' in network." , localDevice . ToString ( ) , devInNetwork . ToString ( ) ) ;
0 commit comments