Skip to content
Snippets Groups Projects
Commit d38ef320 authored by Gregor Maier's avatar Gregor Maier
Browse files

Restructure code. Put all the constructors together! No other changes.

parent dbe6f9ec
No related branches found
No related tags found
No related merge requests found
...@@ -95,6 +95,61 @@ public class Device implements IDevice { ...@@ -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() { private Map<Long, AttachmentPoint> getAPMap() {
if (attachmentPoints == null) return null; if (attachmentPoints == null) return null;
...@@ -274,60 +329,7 @@ public class Device implements IDevice { ...@@ -274,60 +329,7 @@ public class Device implements IDevice {
return sp.toArray(new SwitchPort[sp.size()]); 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 // IDevice
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment