From d38ef3209875dd01fab1bdf792f355788ba9f34e Mon Sep 17 00:00:00 2001 From: Gregor Maier <gregor.maier@bigswitch.com> Date: Fri, 10 Aug 2012 15:47:51 -0700 Subject: [PATCH] Restructure code. Put all the constructors together! No other changes. --- .../devicemanager/internal/Device.java | 110 +++++++++--------- 1 file changed, 56 insertions(+), 54 deletions(-) diff --git a/src/main/java/net/floodlightcontroller/devicemanager/internal/Device.java b/src/main/java/net/floodlightcontroller/devicemanager/internal/Device.java index 780e56f3e..9caaa9779 100755 --- a/src/main/java/net/floodlightcontroller/devicemanager/internal/Device.java +++ b/src/main/java/net/floodlightcontroller/devicemanager/internal/Device.java @@ -95,6 +95,61 @@ public class Device implements IDevice { } } + /** + * Create a device from a set of entities + * @param deviceManager the device manager for this device + * @param deviceKey the unique identifier for this device object + * @param entities the initial entities for the device + * @param entityClass the entity class associated with the entities + */ + public Device(DeviceManagerImpl deviceManager, + Long deviceKey, + Collection<AttachmentPoint> attachmentPoints, + Collection<Entity> entities, + IEntityClass entityClass) { + this.deviceManager = deviceManager; + this.deviceKey = deviceKey; + this.entities = entities.toArray(new Entity[entities.size()]); + if (attachmentPoints == null) { + this.attachmentPoints = null; + } else { + this.attachmentPoints = + new ArrayList<AttachmentPoint>(attachmentPoints); + } + this.macAddressString = + HexString.toHexString(this.entities[0].getMacAddress(), 6); + this.entityClass = entityClass; + Arrays.sort(this.entities); + } + + /** + * Construct a new device consisting of the entities from the old device + * plus an additional entity + * @param device the old device object + * @param newEntity the entity to add. newEntity must be have the same + * entity class as device + */ + public Device(Device device, + Entity newEntity) { + this.deviceManager = device.deviceManager; + this.deviceKey = device.deviceKey; + this.entities = Arrays.<Entity>copyOf(device.entities, + device.entities.length + 1); + this.entities[this.entities.length - 1] = newEntity; + Arrays.sort(this.entities); + + if (device.attachmentPoints != null) { + this.attachmentPoints = + new ArrayList<AttachmentPoint>(device.attachmentPoints); + } else + this.attachmentPoints = null; + + this.macAddressString = + HexString.toHexString(this.entities[0].getMacAddress(), 6); + + this.entityClass = device.entityClass; + } + private Map<Long, AttachmentPoint> getAPMap() { if (attachmentPoints == null) return null; @@ -274,60 +329,7 @@ public class Device implements IDevice { return sp.toArray(new SwitchPort[sp.size()]); } - /** - * Create a device from a set of entities - * @param deviceManager the device manager for this device - * @param deviceKey the unique identifier for this device object - * @param entities the initial entities for the device - * @param entityClass the entity class associated with the entities - */ - public Device(DeviceManagerImpl deviceManager, - Long deviceKey, - Collection<AttachmentPoint> attachmentPoints, - Collection<Entity> entities, - IEntityClass entityClass) { - this.deviceManager = deviceManager; - this.deviceKey = deviceKey; - this.entities = entities.toArray(new Entity[entities.size()]); - if (attachmentPoints == null) { - this.attachmentPoints = null; - } else { - this.attachmentPoints = - new ArrayList<AttachmentPoint>(attachmentPoints); - } - this.macAddressString = - HexString.toHexString(this.entities[0].getMacAddress(), 6); - this.entityClass = entityClass; - Arrays.sort(this.entities); - } - - /** - * Construct a new device consisting of the entities from the old device - * plus an additional entity - * @param device the old device object - * @param newEntity the entity to add. newEntity must be have the same - * entity class as device - */ - public Device(Device device, - Entity newEntity) { - this.deviceManager = device.deviceManager; - this.deviceKey = device.deviceKey; - this.entities = Arrays.<Entity>copyOf(device.entities, - device.entities.length + 1); - this.entities[this.entities.length - 1] = newEntity; - Arrays.sort(this.entities); - - if (device.attachmentPoints != null) { - this.attachmentPoints = - new ArrayList<AttachmentPoint>(device.attachmentPoints); - } else - this.attachmentPoints = null; - - this.macAddressString = - HexString.toHexString(this.entities[0].getMacAddress(), 6); - - this.entityClass = device.entityClass; - } + // ******* // IDevice -- GitLab