From f037bbfdff8e278df0a22d59078b36d988ed4714 Mon Sep 17 00:00:00 2001 From: teddybear02 Date: Fri, 7 Oct 2016 06:29:24 -0400 Subject: [PATCH 01/21] Modified setPeer to set the peer's peer as well --- scala/src/edu/cwru/eecs293/ttf10/uxb/Connector.scala | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/scala/src/edu/cwru/eecs293/ttf10/uxb/Connector.scala b/scala/src/edu/cwru/eecs293/ttf10/uxb/Connector.scala index 1cd5be7..bfa78a3 100644 --- a/scala/src/edu/cwru/eecs293/ttf10/uxb/Connector.scala +++ b/scala/src/edu/cwru/eecs293/ttf10/uxb/Connector.scala @@ -55,13 +55,18 @@ final class Connector(private val device: Device, private val index: Int, privat if (this.peer.nonEmpty) throw new ConnectionException(this, ConnectionException.ErrorCode.CONNECTOR_BUSY) - if (peer.getType == getType) + if (peer.`type` == `type`) throw new ConnectionException(this, ConnectionException.ErrorCode.CONNECTOR_MISMATCH) - if (peer.isReachable(getDevice)) + if (peer.isReachable(device)) throw new ConnectionException(this, ConnectionException.ErrorCode.CONNECTION_CYCLE) + if (peer.peer.nonEmpty) + throw new ConnectionException(peer, ConnectionException.ErrorCode.CONNECTOR_BUSY) + // TODO: ^ or `this`? + this.peer = Option(peer) + peer.peer = Option(this) } /** From cf0ff2523ba07aa2882dad4c47353eda10b0d97b Mon Sep 17 00:00:00 2001 From: teddybear02 Date: Fri, 7 Oct 2016 06:49:33 -0400 Subject: [PATCH 02/21] Merged primary and auxiliary constructors --- .../edu/cwru/eecs293/ttf10/uxb/BinaryMessage.scala | 12 ++---------- .../edu/cwru/eecs293/ttf10/uxb/StringMessage.scala | 12 ++---------- 2 files changed, 4 insertions(+), 20 deletions(-) diff --git a/scala/src/edu/cwru/eecs293/ttf10/uxb/BinaryMessage.scala b/scala/src/edu/cwru/eecs293/ttf10/uxb/BinaryMessage.scala index ab0826b..6c84a03 100644 --- a/scala/src/edu/cwru/eecs293/ttf10/uxb/BinaryMessage.scala +++ b/scala/src/edu/cwru/eecs293/ttf10/uxb/BinaryMessage.scala @@ -12,19 +12,11 @@ package edu.cwru.eecs293.ttf10.uxb *
2016 Fall Semester * @author Ted Frohlich < ttf10@case.edu > */ -final case class BinaryMessage() extends Message { - - private var value: BigInt = 0 - +final case class BinaryMessage(private var value: BigInt) extends Message { /** * Initialize this message with a copy of the given value. If the value is null, the message should contain zero. - * - * @param value the underlying value */ - def this(value: BigInt) { - this - if (value != null) this.value = value - } + value = Option(value).getOrElse(0) def getValue: BigInt = value diff --git a/scala/src/edu/cwru/eecs293/ttf10/uxb/StringMessage.scala b/scala/src/edu/cwru/eecs293/ttf10/uxb/StringMessage.scala index d52f123..0ec64f7 100644 --- a/scala/src/edu/cwru/eecs293/ttf10/uxb/StringMessage.scala +++ b/scala/src/edu/cwru/eecs293/ttf10/uxb/StringMessage.scala @@ -11,19 +11,11 @@ package edu.cwru.eecs293.ttf10.uxb *
2016 Fall Semester * @author Ted Frohlich < ttf10@case.edu > */ -final case class StringMessage() extends Message { - - private var string: String = "" - +final case class StringMessage(private var string: String) extends Message { /** * Initialize this message with the given string. If the string is null, the message should contain an empty non-null string. - * - * @param string the underlying string */ - def this(string: String) { - this - if (string != null) this.string = string - } + string = Option(string).getOrElse("") /** * Returns the underlying string. From 6ede00b85fabafe9120966f7430d46c50c6d8a4d Mon Sep 17 00:00:00 2001 From: teddybear02 Date: Fri, 7 Oct 2016 07:00:22 -0400 Subject: [PATCH 03/21] Modified to respond to binary messages by sending on the binary message 293 --- scala/src/edu/cwru/eecs293/ttf10/uxb/GoAmateur.scala | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scala/src/edu/cwru/eecs293/ttf10/uxb/GoAmateur.scala b/scala/src/edu/cwru/eecs293/ttf10/uxb/GoAmateur.scala index d6c4367..6a80546 100644 --- a/scala/src/edu/cwru/eecs293/ttf10/uxb/GoAmateur.scala +++ b/scala/src/edu/cwru/eecs293/ttf10/uxb/GoAmateur.scala @@ -43,7 +43,10 @@ class GoAmateur[T <: AbstractVideo.Builder[T]](private val builder: GoAmateur.Bu @throws[IllegalArgumentException] override def recv(message: BinaryMessage, connector: Connector) { validateRecv(message, connector) - println("[Log] >> " + "GoAmateur is not yet active: " + message.getValue) + // Respond by sending on all of this device's connectors the binary message 293. + connectors.foreach(con => con.recv(BinaryMessage(293))) + println("[Log] >> " + "GoAmateur has responded to the binary message: " + message.getValue) + println(" " + "by sending on all of its connectors the binary message: 293") } } From 05675eef4618df22d6874b511b10730fe2c9fa22 Mon Sep 17 00:00:00 2001 From: teddybear02 Date: Fri, 7 Oct 2016 07:37:45 -0400 Subject: [PATCH 04/21] Omitted `override` modifier and inherited method docs --- .../eecs293/ttf10/uxb/BinaryMessage.scala | 2 +- .../eecs293/ttf10/uxb/CannonPrinter.scala | 22 +++---------------- .../cwru/eecs293/ttf10/uxb/GoAmateur.scala | 22 +++---------------- .../eecs293/ttf10/uxb/SisterPrinter.scala | 22 +++---------------- .../eecs293/ttf10/uxb/StringMessage.scala | 2 +- 5 files changed, 11 insertions(+), 59 deletions(-) diff --git a/scala/src/edu/cwru/eecs293/ttf10/uxb/BinaryMessage.scala b/scala/src/edu/cwru/eecs293/ttf10/uxb/BinaryMessage.scala index 6c84a03..39356e2 100644 --- a/scala/src/edu/cwru/eecs293/ttf10/uxb/BinaryMessage.scala +++ b/scala/src/edu/cwru/eecs293/ttf10/uxb/BinaryMessage.scala @@ -30,7 +30,7 @@ final case class BinaryMessage(private var value: BigInt) extends Message { @throws[NullPointerException] @throws[IllegalArgumentException] @deprecated("Method chain Connector.recv >> Message.reach >> Device.recv no longer requires middleman", "hw4") - override def reach(device: Device, connector: Connector) { + def reach(device: Device, connector: Connector) { device.recv(this, connector) } diff --git a/scala/src/edu/cwru/eecs293/ttf10/uxb/CannonPrinter.scala b/scala/src/edu/cwru/eecs293/ttf10/uxb/CannonPrinter.scala index 58a993f..f8cf744 100644 --- a/scala/src/edu/cwru/eecs293/ttf10/uxb/CannonPrinter.scala +++ b/scala/src/edu/cwru/eecs293/ttf10/uxb/CannonPrinter.scala @@ -14,33 +14,17 @@ package edu.cwru.eecs293.ttf10.uxb class CannonPrinter[T <: AbstractPrinter.Builder[T]](private val builder: CannonPrinter.Builder[T]) extends AbstractPrinter(builder) { - /** - * Signifies the arrival of a message at the given connector in the device. - * - * @param message the string message being received - * @param connector the connector at which the message arrived - * @throws NullPointerException if either argument is null - * @throws IllegalArgumentException if the connector does not belong to this device - */ @throws[NullPointerException] @throws[IllegalArgumentException] - override def recv(message: StringMessage, connector: Connector) { + def recv(message: StringMessage, connector: Connector) { validateRecv(message, connector) println("[Log] >> " + "Cannon printer has printed the string: \"" + message.getString + "\"") println(" " + " -> UXB version number: " + version) } - /** - * Signifies the arrival of a message at the given connector in the device. - * - * @param message the binary message being received - * @param connector the connector at which the message arrived - * @throws NullPointerException if either argument is null - * @throws IllegalArgumentException if the connector does not belong to this device - */ @throws[NullPointerException] @throws[IllegalArgumentException] - override def recv(message: BinaryMessage, connector: Connector) { + def recv(message: BinaryMessage, connector: Connector) { validateRecv(message, connector) val result: BigInt = message.getValue * serialNumber.getOrElse(1) println("[Log] >> " + "Cannon printer has printed the binary message: " + result) @@ -59,7 +43,7 @@ object CannonPrinter { class Builder[T <: AbstractPrinter.Builder[T]](override protected val version: Int) extends AbstractPrinter.Builder[Builder[T]](version) { - override protected def getThis = this + protected def getThis = this /** * Initializes the cannon printer with the builder’s version, product code, serial number, and connector list. diff --git a/scala/src/edu/cwru/eecs293/ttf10/uxb/GoAmateur.scala b/scala/src/edu/cwru/eecs293/ttf10/uxb/GoAmateur.scala index 6a80546..c3ecb95 100644 --- a/scala/src/edu/cwru/eecs293/ttf10/uxb/GoAmateur.scala +++ b/scala/src/edu/cwru/eecs293/ttf10/uxb/GoAmateur.scala @@ -15,33 +15,17 @@ package edu.cwru.eecs293.ttf10.uxb class GoAmateur[T <: AbstractVideo.Builder[T]](private val builder: GoAmateur.Builder[T]) extends AbstractVideo[GoAmateur.Builder[T]](builder) { - /** - * Signifies the arrival of a message at the given connector in the device. - * - * @param message the string message being received - * @param connector the connector at which the message arrived - * @throws NullPointerException if either argument is null - * @throws IllegalArgumentException if the connector does not belong to this device - */ @throws[NullPointerException] @throws[IllegalArgumentException] - override def recv(message: StringMessage, connector: Connector) { + def recv(message: StringMessage, connector: Connector) { validateRecv(message, connector) println("[Log] >> " + "GoAmateur does not understand string messages: \"" + message.getString + "\"") println(" " + " -> connector index: " + connector.getIndex) } - /** - * Signifies the arrival of a message at the given connector in the device. - * - * @param message the binary message being received - * @param connector the connector at which the message arrived - * @throws NullPointerException if either argument is null - * @throws IllegalArgumentException if the connector does not belong to this device - */ @throws[NullPointerException] @throws[IllegalArgumentException] - override def recv(message: BinaryMessage, connector: Connector) { + def recv(message: BinaryMessage, connector: Connector) { validateRecv(message, connector) // Respond by sending on all of this device's connectors the binary message 293. connectors.foreach(con => con.recv(BinaryMessage(293))) @@ -62,7 +46,7 @@ object GoAmateur { class Builder[T <: AbstractVideo.Builder[T]](override protected val version: Int) extends AbstractVideo.Builder[Builder[T]](version) { - override protected def getThis = this + protected def getThis = this /** * Initializes the GoAmateur with the builder’s version, product code, serial number, and connector list. diff --git a/scala/src/edu/cwru/eecs293/ttf10/uxb/SisterPrinter.scala b/scala/src/edu/cwru/eecs293/ttf10/uxb/SisterPrinter.scala index f0fd354..0dd09d8 100644 --- a/scala/src/edu/cwru/eecs293/ttf10/uxb/SisterPrinter.scala +++ b/scala/src/edu/cwru/eecs293/ttf10/uxb/SisterPrinter.scala @@ -14,33 +14,17 @@ package edu.cwru.eecs293.ttf10.uxb class SisterPrinter[T <: AbstractPrinter.Builder[T]](private val builder: SisterPrinter.Builder[T]) extends AbstractPrinter(builder) { - /** - * Signifies the arrival of a message at the given connector in the device. - * - * @param message the string message being received - * @param connector the connector at which the message arrived - * @throws NullPointerException if either argument is null - * @throws IllegalArgumentException if the connector does not belong to this device - */ @throws[NullPointerException] @throws[IllegalArgumentException] - override def recv(message: StringMessage, connector: Connector) { + def recv(message: StringMessage, connector: Connector) { validateRecv(message, connector) println("[Log] >> " + "Sister printer has printed the string: \"" + message.getString + "\"") println(" " + " -> printer serial number: " + serialNumber.get) } - /** - * Signifies the arrival of a message at the given connector in the device. - * - * @param message the binary message being received - * @param connector the connector at which the message arrived - * @throws NullPointerException if either argument is null - * @throws IllegalArgumentException if the connector does not belong to this device - */ @throws[NullPointerException] @throws[IllegalArgumentException] - override def recv(message: BinaryMessage, connector: Connector) { + def recv(message: BinaryMessage, connector: Connector) { validateRecv(message, connector) val result: BigInt = message.getValue + productCode.getOrElse[Int](0) println("[Log] >> " + "Sister printer has printed the binary message: " + result) @@ -59,7 +43,7 @@ object SisterPrinter { class Builder[T <: AbstractPrinter.Builder[T]](override protected val version: Int) extends AbstractPrinter.Builder[Builder[T]](version) { - override protected def getThis = this + protected def getThis = this /** * Initializes the sister printer with the builder’s version, product code, serial number, and connector list. diff --git a/scala/src/edu/cwru/eecs293/ttf10/uxb/StringMessage.scala b/scala/src/edu/cwru/eecs293/ttf10/uxb/StringMessage.scala index 0ec64f7..3df2cb0 100644 --- a/scala/src/edu/cwru/eecs293/ttf10/uxb/StringMessage.scala +++ b/scala/src/edu/cwru/eecs293/ttf10/uxb/StringMessage.scala @@ -34,7 +34,7 @@ final case class StringMessage(private var string: String) extends Message { @throws[NullPointerException] @throws[IllegalArgumentException] @deprecated("Method chain Connector.recv >> Message.reach >> Device.recv no longer requires middleman", "hw4") - override def reach(device: Device, connector: Connector) { + def reach(device: Device, connector: Connector) { device.recv(this, connector) } From 573c81efe15298b2a1c3b4ea281ec6e613893013 Mon Sep 17 00:00:00 2001 From: teddybear02 Date: Fri, 7 Oct 2016 07:38:32 -0400 Subject: [PATCH 05/21] Modified to forward messages to other connectors --- .../src/edu/cwru/eecs293/ttf10/uxb/Hub.scala | 40 +++++++++---------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/scala/src/edu/cwru/eecs293/ttf10/uxb/Hub.scala b/scala/src/edu/cwru/eecs293/ttf10/uxb/Hub.scala index 0f43b8b..ac51fe3 100644 --- a/scala/src/edu/cwru/eecs293/ttf10/uxb/Hub.scala +++ b/scala/src/edu/cwru/eecs293/ttf10/uxb/Hub.scala @@ -18,34 +18,32 @@ class Hub[T <: AbstractDevice.Builder[T]](private val builder: Hub.Builder[T]) e override def getDeviceClass: DeviceClass = DeviceClass.HUB - /** - * Signifies the arrival of a message at the given connector in the device. - * - * @param message the string message being received - * @param connector the connector at which the message arrived - * @throws NullPointerException if either argument is null - * @throws IllegalArgumentException if the connector does not belong to this device - */ @throws[NullPointerException] @throws[IllegalArgumentException] - override def recv(message: StringMessage, connector: Connector) { + def recv(message: StringMessage, connector: Connector) { validateRecv(message, connector) - println("[Log] >> " + "recv not yet supported") + send(message, connector) + println("[Log] >> " + "Hub has forwarded on the string message: " + message.getString) } - /** - * Signifies the arrival of a message at the given connector in the device. - * - * @param message the binary message being received - * @param connector the connector at which the message arrived - * @throws NullPointerException if either argument is null - * @throws IllegalArgumentException if the connector does not belong to this device - */ @throws[NullPointerException] @throws[IllegalArgumentException] - override def recv(message: BinaryMessage, connector: Connector) { + def recv(message: BinaryMessage, connector: Connector) { validateRecv(message, connector) - println("[Log] >> " + "recv not yet supported") + send(message, connector) + println("[Log] >> " + "Hub has forwarded on the binary message: " + message.getValue) + } + // TODO: recv methods too similar? --write hubRecv helper method? + + /** + * Forwards the received message on all its connectors except the one from which the message was received. + * + * @param message the received message + * @param connector the connector from which the message was received + */ + private def send(message: Message, connector: Connector) { + (connectors.toSet - connector) + .foreach(con => con.recv(message)) } } @@ -61,7 +59,7 @@ object Hub { class Builder[T <: AbstractDevice.Builder[T]](override protected val version: Int) extends AbstractDevice.Builder[Builder[T]](version) { - override protected def getThis = this + protected def getThis = this /** * Initializes the hub with the builder’s version, product code, serial number, and connector list. From 5de3f4ed5b4a91d79637ad35114e3ee3a7532d84 Mon Sep 17 00:00:00 2001 From: teddybear02 Date: Fri, 7 Oct 2016 13:51:30 -0400 Subject: [PATCH 06/21] Renamed parameters of nextReachableDevices method for clarity (cherry picked from commit 4695e4e) --- scala/src/edu/cwru/eecs293/ttf10/uxb/Device.scala | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scala/src/edu/cwru/eecs293/ttf10/uxb/Device.scala b/scala/src/edu/cwru/eecs293/ttf10/uxb/Device.scala index 92bbcf5..60df81d 100644 --- a/scala/src/edu/cwru/eecs293/ttf10/uxb/Device.scala +++ b/scala/src/edu/cwru/eecs293/ttf10/uxb/Device.scala @@ -77,12 +77,12 @@ trait Device { /** * Maps the next level of reachable devices in the device tree from the previously mapped level, given a set of all reachable devices mapped hitherto. * - * @param previousReachableDevices a set of devices from the previous level in the device tree - * @param hithertoReachableDevices a set of all devices in the device tree so far + * @param lastLevelVisited a set of devices from the last-visited level in the device tree + * @param allLevelsVisited a set of devices from all levels of the device tree visited so far * @return a set of devices in the next level of the device tree */ - protected def nextReachableDevices(previousReachableDevices: Set[Device], - hithertoReachableDevices: Set[Device]): Set[Device] + protected def nextReachableDevices(lastLevelVisited: Set[Device], + allLevelsVisited: Set[Device]): Set[Device] /** * Maps a set of all devices reachable from this device until the target device is found. From 47d2dde64ae7e1b793e378ee5db722b67fcb63af Mon Sep 17 00:00:00 2001 From: teddybear02 Date: Fri, 7 Oct 2016 13:53:12 -0400 Subject: [PATCH 07/21] Revised reachableDevicesUntil method according to Andrew's comments (cherry picked from commit 7f061bc) --- .../eecs293/ttf10/uxb/AbstractDevice.scala | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/scala/src/edu/cwru/eecs293/ttf10/uxb/AbstractDevice.scala b/scala/src/edu/cwru/eecs293/ttf10/uxb/AbstractDevice.scala index 8eed266..40ba10d 100644 --- a/scala/src/edu/cwru/eecs293/ttf10/uxb/AbstractDevice.scala +++ b/scala/src/edu/cwru/eecs293/ttf10/uxb/AbstractDevice.scala @@ -44,30 +44,30 @@ abstract class AbstractDevice[T <: AbstractDevice.Builder[T]](private val builde def getConnector(index: Int): Connector = connectors(index) def peerDevices: Set[Device] = { - connectors.map(connector => connector.getDevice).toSet + connectors.map(_.getDevice).toSet } - protected def nextReachableDevices(previousReachableDevices: Set[Device], - hithertoReachableDevices: Set[Device]): Set[Device] = { - previousReachableDevices.flatMap(prev => prev.peerDevices -- hithertoReachableDevices) + protected def nextReachableDevices(lastLevelVisited: Set[Device], + allLevelsVisited: Set[Device]): Set[Device] = { + lastLevelVisited.flatMap(_.peerDevices -- allLevelsVisited) } protected def reachableDevicesUntil(target: Device = null): Set[Device] = { - var previous: Set[Device] = Set(this) - var hitherto: Set[Device] = Set.empty - var next: Set[Device] = Set.empty + var lastLevelVisited: Set[Device] = Set(this) + var allLevelsVisited: Set[Device] = lastLevelVisited + var nextLevelToVisit: Set[Device] = Set.empty do { - next = nextReachableDevices(previous, hitherto) - if (next.contains(target)) return null // return null set to indicate that the target was found - hitherto ++= previous - previous = next - } while (next.nonEmpty) - hitherto + nextLevelToVisit = nextReachableDevices(lastLevelVisited, allLevelsVisited) + allLevelsVisited ++= nextLevelToVisit + if (nextLevelToVisit.contains(target)) return allLevelsVisited // return set early if the target was found + lastLevelVisited = nextLevelToVisit + } while (nextLevelToVisit.nonEmpty) + allLevelsVisited } def reachableDevices: Set[Device] = reachableDevicesUntil() - def isReachable(device: Device): Boolean = reachableDevicesUntil(device) == null + def isReachable(device: Device): Boolean = reachableDevicesUntil(device).contains(device) /** * Signifies the arrival of a message at the given connector in the device. From 350b6deaf166a83c4b28c53723fffb3926e975ff Mon Sep 17 00:00:00 2001 From: teddybear02 Date: Fri, 7 Oct 2016 14:04:20 -0400 Subject: [PATCH 08/21] Attempted removal of type parameters for concrete devices --and to great avail! (cherry picked from commit e8ac9b9) --- .../src/edu/cwru/eecs293/ttf10/uxb/CannonPrinter.scala | 8 +++----- scala/src/edu/cwru/eecs293/ttf10/uxb/GoAmateur.scala | 10 ++++------ scala/src/edu/cwru/eecs293/ttf10/uxb/Hub.scala | 7 +++---- .../src/edu/cwru/eecs293/ttf10/uxb/SisterPrinter.scala | 8 +++----- .../cwru/eecs293/ttf10/uxb/AbstractDeviceTest.scala | 4 ++-- 5 files changed, 15 insertions(+), 22 deletions(-) diff --git a/scala/src/edu/cwru/eecs293/ttf10/uxb/CannonPrinter.scala b/scala/src/edu/cwru/eecs293/ttf10/uxb/CannonPrinter.scala index f8cf744..774d27f 100644 --- a/scala/src/edu/cwru/eecs293/ttf10/uxb/CannonPrinter.scala +++ b/scala/src/edu/cwru/eecs293/ttf10/uxb/CannonPrinter.scala @@ -11,8 +11,7 @@ package edu.cwru.eecs293.ttf10.uxb *
2016 Fall Semester * @author Ted Frohlich < ttf10@case.edu > */ -class CannonPrinter[T <: AbstractPrinter.Builder[T]](private val builder: CannonPrinter.Builder[T]) - extends AbstractPrinter(builder) { +class CannonPrinter(private val builder: CannonPrinter.Builder) extends AbstractPrinter(builder) { @throws[NullPointerException] @throws[IllegalArgumentException] @@ -40,8 +39,7 @@ object CannonPrinter { * * @param version the UXB version that this device supports */ - class Builder[T <: AbstractPrinter.Builder[T]](override protected val version: Int) - extends AbstractPrinter.Builder[Builder[T]](version) { + class Builder(override protected val version: Int) extends AbstractPrinter.Builder[Builder](version) { protected def getThis = this @@ -52,7 +50,7 @@ object CannonPrinter { * @throws IllegalStateException if the version number is null, or if one of the connectors is not of type peripheral */ @throws[IllegalStateException] - def build(): CannonPrinter[T] = { + def build(): CannonPrinter = { validate() new CannonPrinter(this) } diff --git a/scala/src/edu/cwru/eecs293/ttf10/uxb/GoAmateur.scala b/scala/src/edu/cwru/eecs293/ttf10/uxb/GoAmateur.scala index c3ecb95..7a41f40 100644 --- a/scala/src/edu/cwru/eecs293/ttf10/uxb/GoAmateur.scala +++ b/scala/src/edu/cwru/eecs293/ttf10/uxb/GoAmateur.scala @@ -12,8 +12,7 @@ package edu.cwru.eecs293.ttf10.uxb *
2016 Fall Semester * @author Ted Frohlich < ttf10@case.edu > */ -class GoAmateur[T <: AbstractVideo.Builder[T]](private val builder: GoAmateur.Builder[T]) - extends AbstractVideo[GoAmateur.Builder[T]](builder) { +class GoAmateur(private val builder: GoAmateur.Builder) extends AbstractVideo[GoAmateur.Builder](builder) { @throws[NullPointerException] @throws[IllegalArgumentException] @@ -43,8 +42,7 @@ object GoAmateur { * * @param version the UXB version that this device supports */ - class Builder[T <: AbstractVideo.Builder[T]](override protected val version: Int) - extends AbstractVideo.Builder[Builder[T]](version) { + class Builder(override protected val version: Int) extends AbstractVideo.Builder[Builder](version) { protected def getThis = this @@ -55,9 +53,9 @@ object GoAmateur { * @throws IllegalStateException if the version number is null, or if one of the connectors is not of type peripheral */ @throws[IllegalStateException] - def build(): GoAmateur[T] = { + def build(): GoAmateur = { validate() - new GoAmateur[T](this) + new GoAmateur(this) } } diff --git a/scala/src/edu/cwru/eecs293/ttf10/uxb/Hub.scala b/scala/src/edu/cwru/eecs293/ttf10/uxb/Hub.scala index ac51fe3..5015867 100644 --- a/scala/src/edu/cwru/eecs293/ttf10/uxb/Hub.scala +++ b/scala/src/edu/cwru/eecs293/ttf10/uxb/Hub.scala @@ -14,7 +14,7 @@ import DeviceClass._ *
2016 Fall Semester * @author Ted Frohlich < ttf10@case.edu > */ -class Hub[T <: AbstractDevice.Builder[T]](private val builder: Hub.Builder[T]) extends AbstractDevice(builder) { +class Hub(private val builder: Hub.Builder) extends AbstractDevice(builder) { override def getDeviceClass: DeviceClass = DeviceClass.HUB @@ -56,8 +56,7 @@ object Hub { * * @param version the UXB version that this device supports */ - class Builder[T <: AbstractDevice.Builder[T]](override protected val version: Int) - extends AbstractDevice.Builder[Builder[T]](version) { + class Builder(override protected val version: Int) extends AbstractDevice.Builder[Builder](version) { protected def getThis = this @@ -68,7 +67,7 @@ object Hub { * @throws IllegalStateException if the version is null, or the hub has no computer connector, or the hub has no peripheral connector. */ @throws[IllegalStateException] - def build(): Hub[T] = { + def build(): Hub = { validate() new Hub(this) } diff --git a/scala/src/edu/cwru/eecs293/ttf10/uxb/SisterPrinter.scala b/scala/src/edu/cwru/eecs293/ttf10/uxb/SisterPrinter.scala index 0dd09d8..c911a14 100644 --- a/scala/src/edu/cwru/eecs293/ttf10/uxb/SisterPrinter.scala +++ b/scala/src/edu/cwru/eecs293/ttf10/uxb/SisterPrinter.scala @@ -11,8 +11,7 @@ package edu.cwru.eecs293.ttf10.uxb *
2016 Fall Semester * @author Ted Frohlich < ttf10@case.edu > */ -class SisterPrinter[T <: AbstractPrinter.Builder[T]](private val builder: SisterPrinter.Builder[T]) - extends AbstractPrinter(builder) { +class SisterPrinter(private val builder: SisterPrinter.Builder) extends AbstractPrinter(builder) { @throws[NullPointerException] @throws[IllegalArgumentException] @@ -40,8 +39,7 @@ object SisterPrinter { * * @param version the UXB version that this device supports */ - class Builder[T <: AbstractPrinter.Builder[T]](override protected val version: Int) - extends AbstractPrinter.Builder[Builder[T]](version) { + class Builder(override protected val version: Int) extends AbstractPrinter.Builder[Builder](version) { protected def getThis = this @@ -52,7 +50,7 @@ object SisterPrinter { * @throws IllegalStateException if the version number is null, or if one of the connectors is not of type peripheral */ @throws[IllegalStateException] - def build(): SisterPrinter[T] = { + def build(): SisterPrinter = { validate() new SisterPrinter(this) } diff --git a/scala/test/edu/cwru/eecs293/ttf10/uxb/AbstractDeviceTest.scala b/scala/test/edu/cwru/eecs293/ttf10/uxb/AbstractDeviceTest.scala index 7f26d23..e6c072c 100644 --- a/scala/test/edu/cwru/eecs293/ttf10/uxb/AbstractDeviceTest.scala +++ b/scala/test/edu/cwru/eecs293/ttf10/uxb/AbstractDeviceTest.scala @@ -15,11 +15,11 @@ import org.junit.{Before, Test} */ class AbstractDeviceTest { - private var validBuilder: Hub.Builder[Nothing] = _ + private var validBuilder: Hub.Builder = _ private var validVersion: Int = _ private var validConnectors: List[Connector.Type] = _ - private var invalidBuilder: Hub.Builder[Nothing] = _ + private var invalidBuilder: Hub.Builder = _ @Before def setUp() { From 4fbf21f12d4d33496bb2f4c299273dc55fb084bd Mon Sep 17 00:00:00 2001 From: teddybear02 Date: Fri, 7 Oct 2016 15:56:56 -0400 Subject: [PATCH 09/21] Used `getPeer` instead of `this.peer`, as field should be reserved for reassignments (cherry picked from commit 46dc30b) --- scala/src/edu/cwru/eecs293/ttf10/uxb/Connector.scala | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/scala/src/edu/cwru/eecs293/ttf10/uxb/Connector.scala b/scala/src/edu/cwru/eecs293/ttf10/uxb/Connector.scala index bfa78a3..dc75e67 100644 --- a/scala/src/edu/cwru/eecs293/ttf10/uxb/Connector.scala +++ b/scala/src/edu/cwru/eecs293/ttf10/uxb/Connector.scala @@ -19,29 +19,21 @@ final class Connector(private val device: Device, private val index: Int, privat private var peer: Option[Connector] = Option.empty /** - * Returns the device to which this connector belongs. - * * @return the device to which this connector belongs */ def getDevice: Device = device /** - * Returns the index of this connector. - * * @return the plug number in the connector's device */ def getIndex: Int = index /** - * Returns the type of this connector. - * * @return the type of this connector */ def getType: Connector.Type = `type` /** - * Returns the peer of this connector. - * * @return the other connector if any to which this connector is plugged */ def getPeer: Option[Connector] = peer @@ -52,7 +44,7 @@ final class Connector(private val device: Device, private val index: Int, privat if (peer == null) throw new NullPointerException("Couldn't connect to peer: peer is null.") - if (this.peer.nonEmpty) + if (getPeer.nonEmpty) throw new ConnectionException(this, ConnectionException.ErrorCode.CONNECTOR_BUSY) if (peer.`type` == `type`) From 256087295f86c27b58c12083d5a94883047cad80 Mon Sep 17 00:00:00 2001 From: teddybear02 Date: Fri, 7 Oct 2016 18:45:03 -0400 Subject: [PATCH 10/21] Revised setter docs --- scala/src/edu/cwru/eecs293/ttf10/uxb/AbstractDevice.scala | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scala/src/edu/cwru/eecs293/ttf10/uxb/AbstractDevice.scala b/scala/src/edu/cwru/eecs293/ttf10/uxb/AbstractDevice.scala index 40ba10d..94e7215 100644 --- a/scala/src/edu/cwru/eecs293/ttf10/uxb/AbstractDevice.scala +++ b/scala/src/edu/cwru/eecs293/ttf10/uxb/AbstractDevice.scala @@ -116,7 +116,7 @@ object AbstractDevice { * Sets the product code to the given value. If the productCode is null, set it to an empty optional. * * @param productCode the product code of this device - * @return [[getThis]] + * @return this device */ def productCode(productCode: Int): T = { this.productCode = // Must perform null check since Int is not a nullable type @@ -128,7 +128,7 @@ object AbstractDevice { * Sets the serial number to the given value. If the serial number is null, set it to an empty optional. * * @param serialNumber the serial number of this device - * @return [[getThis()]] + * @return this device */ def serialNumber(serialNumber: BigInt): T = { this.serialNumber = Option(serialNumber) // BigInt is a nullable type (see counterexample above) @@ -139,7 +139,7 @@ object AbstractDevice { * Sets the connector types to a copy of the given value. If the argument is null, the device will have no connectors. * * @param connectors the type of each connector in this device - * @return [[getThis()]] + * @return this device */ def connectors(connectors: List[Connector.Type]): T = { this.connectors = if (connectors != null) connectors else List.empty From 3920f002f095b7c94dccdcb93a3302190c55827c Mon Sep 17 00:00:00 2001 From: teddybear02 Date: Fri, 7 Oct 2016 18:53:56 -0400 Subject: [PATCH 11/21] Simplified foreach statement --- scala/src/edu/cwru/eecs293/ttf10/uxb/GoAmateur.scala | 2 +- scala/src/edu/cwru/eecs293/ttf10/uxb/Hub.scala | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scala/src/edu/cwru/eecs293/ttf10/uxb/GoAmateur.scala b/scala/src/edu/cwru/eecs293/ttf10/uxb/GoAmateur.scala index 7a41f40..ddc94e1 100644 --- a/scala/src/edu/cwru/eecs293/ttf10/uxb/GoAmateur.scala +++ b/scala/src/edu/cwru/eecs293/ttf10/uxb/GoAmateur.scala @@ -27,7 +27,7 @@ class GoAmateur(private val builder: GoAmateur.Builder) extends AbstractVideo[Go def recv(message: BinaryMessage, connector: Connector) { validateRecv(message, connector) // Respond by sending on all of this device's connectors the binary message 293. - connectors.foreach(con => con.recv(BinaryMessage(293))) + connectors.foreach(_.recv(BinaryMessage(293))) println("[Log] >> " + "GoAmateur has responded to the binary message: " + message.getValue) println(" " + "by sending on all of its connectors the binary message: 293") } diff --git a/scala/src/edu/cwru/eecs293/ttf10/uxb/Hub.scala b/scala/src/edu/cwru/eecs293/ttf10/uxb/Hub.scala index 5015867..1df5ca3 100644 --- a/scala/src/edu/cwru/eecs293/ttf10/uxb/Hub.scala +++ b/scala/src/edu/cwru/eecs293/ttf10/uxb/Hub.scala @@ -43,7 +43,7 @@ class Hub(private val builder: Hub.Builder) extends AbstractDevice(builder) { */ private def send(message: Message, connector: Connector) { (connectors.toSet - connector) - .foreach(con => con.recv(message)) + .foreach(_.recv(message)) } } From fa0089b27466fcde6140ab1f44bd7b8f41e08506 Mon Sep 17 00:00:00 2001 From: teddybear02 Date: Sat, 8 Oct 2016 13:21:19 -0400 Subject: [PATCH 12/21] Revised to reflect fixes in message class signatures --- scala/test/edu/cwru/eecs293/ttf10/uxb/Broadcast.scala | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scala/test/edu/cwru/eecs293/ttf10/uxb/Broadcast.scala b/scala/test/edu/cwru/eecs293/ttf10/uxb/Broadcast.scala index d74ba5f..170f993 100644 --- a/scala/test/edu/cwru/eecs293/ttf10/uxb/Broadcast.scala +++ b/scala/test/edu/cwru/eecs293/ttf10/uxb/Broadcast.scala @@ -44,11 +44,11 @@ class Broadcast { // Create message list messages = List( - new StringMessage("Hello, world!"), - new StringMessage("My name is Ted."), - new StringMessage(""), - new BinaryMessage(0), - new BinaryMessage(1) + StringMessage("Hello, world!"), + StringMessage("My name is Ted."), + StringMessage(""), + BinaryMessage(0), + BinaryMessage(1) ) } From b9c55ad8ce949bc63c0b6e2e5995a3e083e2be9d Mon Sep 17 00:00:00 2001 From: teddybear02 Date: Sat, 8 Oct 2016 14:37:05 -0400 Subject: [PATCH 13/21] Made more use of getters in `setPeer` --- scala/src/edu/cwru/eecs293/ttf10/uxb/Connector.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scala/src/edu/cwru/eecs293/ttf10/uxb/Connector.scala b/scala/src/edu/cwru/eecs293/ttf10/uxb/Connector.scala index dc75e67..35969da 100644 --- a/scala/src/edu/cwru/eecs293/ttf10/uxb/Connector.scala +++ b/scala/src/edu/cwru/eecs293/ttf10/uxb/Connector.scala @@ -47,13 +47,13 @@ final class Connector(private val device: Device, private val index: Int, privat if (getPeer.nonEmpty) throw new ConnectionException(this, ConnectionException.ErrorCode.CONNECTOR_BUSY) - if (peer.`type` == `type`) + if (peer.getType == `type`) throw new ConnectionException(this, ConnectionException.ErrorCode.CONNECTOR_MISMATCH) if (peer.isReachable(device)) throw new ConnectionException(this, ConnectionException.ErrorCode.CONNECTION_CYCLE) - if (peer.peer.nonEmpty) + if (peer.getPeer.nonEmpty) throw new ConnectionException(peer, ConnectionException.ErrorCode.CONNECTOR_BUSY) // TODO: ^ or `this`? From 6d868c2c0f568417869fc2a3f9c76a0889212a6c Mon Sep 17 00:00:00 2001 From: teddybear02 Date: Sat, 8 Oct 2016 16:12:57 -0400 Subject: [PATCH 14/21] Added `send` method --- .../edu/cwru/eecs293/ttf10/uxb/AbstractDevice.scala | 11 +++++++++++ scala/src/edu/cwru/eecs293/ttf10/uxb/Device.scala | 12 ++++++++++++ 2 files changed, 23 insertions(+) diff --git a/scala/src/edu/cwru/eecs293/ttf10/uxb/AbstractDevice.scala b/scala/src/edu/cwru/eecs293/ttf10/uxb/AbstractDevice.scala index 94e7215..aa46833 100644 --- a/scala/src/edu/cwru/eecs293/ttf10/uxb/AbstractDevice.scala +++ b/scala/src/edu/cwru/eecs293/ttf10/uxb/AbstractDevice.scala @@ -86,6 +86,17 @@ abstract class AbstractDevice[T <: AbstractDevice.Builder[T]](private val builde throw new IllegalArgumentException("Message not received: connector does not belong to this device.") } + @throws[NullPointerException] + @throws[IllegalArgumentException] + protected def send(message: Message, connectors: List[Connector]) { + if (message == null || connectors == null || connectors.contains(null)) + throw new NullPointerException("Message not sent: null argument") + if (connectors.exists(_.getDevice != this)) + throw new IllegalArgumentException("Message not sent: connector does not belong to this device") + connectors.foreach(_.getPeer + .foreach(_.recv(message))) // `foreach` passes over an undefined optional value + } + } diff --git a/scala/src/edu/cwru/eecs293/ttf10/uxb/Device.scala b/scala/src/edu/cwru/eecs293/ttf10/uxb/Device.scala index 60df81d..ebb4a9c 100644 --- a/scala/src/edu/cwru/eecs293/ttf10/uxb/Device.scala +++ b/scala/src/edu/cwru/eecs293/ttf10/uxb/Device.scala @@ -131,4 +131,16 @@ trait Device { @throws[IllegalArgumentException] def recv(message: BinaryMessage, connector: Connector) + /** + * Sends a message on the specified (sub)list of connectors belonging to this device. + * + * @param message the message + * @param connectors the connectors on which the message will be sent + * @throws NullPointerException if either argument is null, or if connectors contains a null connector + * @throws IllegalArgumentException if any of the connectors do not belong to this device + */ + @throws[NullPointerException] + @throws[IllegalArgumentException] + protected def send(message: Message, connectors: List[Connector]) + } From 2e7c1f5d8e19655947de053aed29e397e53a06fa Mon Sep 17 00:00:00 2001 From: teddybear02 Date: Sat, 8 Oct 2016 16:16:55 -0400 Subject: [PATCH 15/21] Revised `recv` to actually broadcast the message (using newly added `send` method) --- scala/src/edu/cwru/eecs293/ttf10/uxb/GoAmateur.scala | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scala/src/edu/cwru/eecs293/ttf10/uxb/GoAmateur.scala b/scala/src/edu/cwru/eecs293/ttf10/uxb/GoAmateur.scala index ddc94e1..ad32e6f 100644 --- a/scala/src/edu/cwru/eecs293/ttf10/uxb/GoAmateur.scala +++ b/scala/src/edu/cwru/eecs293/ttf10/uxb/GoAmateur.scala @@ -26,8 +26,7 @@ class GoAmateur(private val builder: GoAmateur.Builder) extends AbstractVideo[Go @throws[IllegalArgumentException] def recv(message: BinaryMessage, connector: Connector) { validateRecv(message, connector) - // Respond by sending on all of this device's connectors the binary message 293. - connectors.foreach(_.recv(BinaryMessage(293))) + send(BinaryMessage(293), connectors) // respond by broadcasting the binary message: 293 println("[Log] >> " + "GoAmateur has responded to the binary message: " + message.getValue) println(" " + "by sending on all of its connectors the binary message: 293") } From 7997734b16105a2043cd8d04c3e4533133a1d33d Mon Sep 17 00:00:00 2001 From: teddybear02 Date: Sat, 8 Oct 2016 16:52:28 -0400 Subject: [PATCH 16/21] Delegated `send` functionality to parent class --- scala/src/edu/cwru/eecs293/ttf10/uxb/Hub.scala | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/scala/src/edu/cwru/eecs293/ttf10/uxb/Hub.scala b/scala/src/edu/cwru/eecs293/ttf10/uxb/Hub.scala index 1df5ca3..60c9303 100644 --- a/scala/src/edu/cwru/eecs293/ttf10/uxb/Hub.scala +++ b/scala/src/edu/cwru/eecs293/ttf10/uxb/Hub.scala @@ -33,7 +33,6 @@ class Hub(private val builder: Hub.Builder) extends AbstractDevice(builder) { send(message, connector) println("[Log] >> " + "Hub has forwarded on the binary message: " + message.getValue) } - // TODO: recv methods too similar? --write hubRecv helper method? /** * Forwards the received message on all its connectors except the one from which the message was received. @@ -41,9 +40,8 @@ class Hub(private val builder: Hub.Builder) extends AbstractDevice(builder) { * @param message the received message * @param connector the connector from which the message was received */ - private def send(message: Message, connector: Connector) { - (connectors.toSet - connector) - .foreach(_.recv(message)) + protected def send(message: Message, connector: Connector) { + send(message, connectors diff List(connector)) } } From 30daf270675e9bdb6841119917949671dbad7ba0 Mon Sep 17 00:00:00 2001 From: teddybear02 Date: Sat, 8 Oct 2016 16:54:26 -0400 Subject: [PATCH 17/21] Redefined device list as a set, and other stylistic changes --- .../cwru/eecs293/ttf10/uxb/Broadcast.scala | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/scala/test/edu/cwru/eecs293/ttf10/uxb/Broadcast.scala b/scala/test/edu/cwru/eecs293/ttf10/uxb/Broadcast.scala index 170f993..2a28748 100644 --- a/scala/test/edu/cwru/eecs293/ttf10/uxb/Broadcast.scala +++ b/scala/test/edu/cwru/eecs293/ttf10/uxb/Broadcast.scala @@ -15,34 +15,33 @@ string message. */ class Broadcast { - private var devices: List[Device] = _ + private var devices: Set[Device] = _ private var messages: List[Message] = _ @Before def setUp() { - // Create peripheral connector doubleton list to add to each device - val cons = List(Connector.Type.PERIPHERAL, Connector.Type.PERIPHERAL) - - // Initialize device list - devices = List( + + // Instantiate device set + val conList = List(Connector.Type.PERIPHERAL) + devices = Set( new Hub.Builder(2016) - .connectors(Connector.Type.COMPUTER :: cons) + .connectors(Connector.Type.COMPUTER :: conList) .build(), new SisterPrinter.Builder(2016) .serialNumber(13579) .productCode(293) - .connectors(cons) + .connectors(conList) .build(), new CannonPrinter.Builder(2016) .serialNumber(24680) - .connectors(cons) + .connectors(conList) .build(), new GoAmateur.Builder(2016) - .connectors(cons) + .connectors(conList) .build() ) - // Create message list + // Initialize message list messages = List( StringMessage("Hello, world!"), StringMessage("My name is Ted."), From 1c79e4a78c29c3fe0768b48986c11ccad1fd8901 Mon Sep 17 00:00:00 2001 From: teddybear02 Date: Sat, 8 Oct 2016 16:55:22 -0400 Subject: [PATCH 18/21] Created `SystemTest` test class --- .../cwru/eecs293/ttf10/uxb/SystemTest.scala | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 scala/test/edu/cwru/eecs293/ttf10/uxb/SystemTest.scala diff --git a/scala/test/edu/cwru/eecs293/ttf10/uxb/SystemTest.scala b/scala/test/edu/cwru/eecs293/ttf10/uxb/SystemTest.scala new file mode 100644 index 0000000..bbb88b7 --- /dev/null +++ b/scala/test/edu/cwru/eecs293/ttf10/uxb/SystemTest.scala @@ -0,0 +1,74 @@ +package edu.cwru.eecs293.ttf10.uxb + +import org.junit.{Before, Test} + +/**

+ * This test creates a UXB system containing two hubs, three printers (not all of the same type), and a Webcam. These UXB devices will all be connected with each other, directly or indirectly. Then, the following scenarios will be explored: + *

    + *
  • A string message is broadcast from a hub. + *
  • A binary message is sent from a hub along a connector that links the hub to a Webcam. + *
  • A binary message is broadcast from a hub. + *
+ * @since Programming Assignment 5 + *
+ *
Case Western Reserve University + *
EECS 293: Software Craftsmanship + *
2016 Fall Semester + * @author Ted Frohlich < ttf10@case.edu > + */ +class SystemTest { + + private var hub1, hub2 : Hub = _ + private var printer1, printer2 : SisterPrinter = _ + private var printer3 : CannonPrinter = _ + private var webcam: GoAmateur = _ + + @Before + def setUp { + webcam = new GoAmateur.Builder(2) + .connectors(List( + Connector.Type.PERIPHERAL)) // to hub1 + .build() + hub1 = new Hub.Builder(1) + .connectors(List( + Connector.Type.COMPUTER, // to webcam + Connector.Type.COMPUTER, // to printer3 + Connector.Type.COMPUTER, // to hub2 + Connector.Type.PERIPHERAL)) // hub needs both types of connectors + .build() + printer3 = new CannonPrinter.Builder(2) + .connectors(List( + Connector.Type.PERIPHERAL)) // to hub1 + .build() + hub2 = new Hub.Builder(2) + .connectors(List( + Connector.Type.PERIPHERAL, // to hub1 + Connector.Type.COMPUTER, // to printer1 + Connector.Type.COMPUTER)) // to printer2 + .build() + val sisterPrinterBuilder = new SisterPrinter.Builder(3) + .connectors(List( + Connector.Type.PERIPHERAL)) // to hub2 + printer1 = sisterPrinterBuilder.build() + printer2 = sisterPrinterBuilder.build() + } + + @Test + @throws[Exception] + def broadcastStringMessage { + + } + + @Test + @throws[Exception] + def sendBinaryMessage { + + } + + @Test + @throws[Exception] + def broadcastBinaryMessage { + + } + +} From 2a52978dfd3782041ebda4dd6ec1a1c3e963d4b2 Mon Sep 17 00:00:00 2001 From: teddybear02 Date: Sun, 9 Oct 2016 21:38:04 -0400 Subject: [PATCH 19/21] Overhauled header format --- .../eecs293/ttf10/uxb/AbstractDevice.scala | 14 +++++++++----- .../ttf10/uxb/AbstractPeripheral.scala | 16 ++++++++++------ .../eecs293/ttf10/uxb/AbstractPrinter.scala | 16 ++++++++++------ .../eecs293/ttf10/uxb/AbstractVideo.scala | 16 ++++++++++------ .../eecs293/ttf10/uxb/BinaryMessage.scala | 14 +++++++++----- .../eecs293/ttf10/uxb/CannonPrinter.scala | 16 ++++++++++------ .../ttf10/uxb/ConnectionException.scala | 16 ++++++++++------ .../cwru/eecs293/ttf10/uxb/Connector.scala | 19 ++++++++++++------- .../edu/cwru/eecs293/ttf10/uxb/Device.scala | 16 ++++++++++------ .../cwru/eecs293/ttf10/uxb/DeviceClass.scala | 17 +++++++++++------ .../cwru/eecs293/ttf10/uxb/GoAmateur.scala | 19 ++++++++++++------- .../src/edu/cwru/eecs293/ttf10/uxb/Hub.scala | 16 ++++++++++------ .../edu/cwru/eecs293/ttf10/uxb/Message.scala | 16 ++++++++++------ .../eecs293/ttf10/uxb/SisterPrinter.scala | 16 ++++++++++------ .../eecs293/ttf10/uxb/StringMessage.scala | 16 ++++++++++------ 15 files changed, 153 insertions(+), 90 deletions(-) diff --git a/scala/src/edu/cwru/eecs293/ttf10/uxb/AbstractDevice.scala b/scala/src/edu/cwru/eecs293/ttf10/uxb/AbstractDevice.scala index aa46833..5b3e57e 100644 --- a/scala/src/edu/cwru/eecs293/ttf10/uxb/AbstractDevice.scala +++ b/scala/src/edu/cwru/eecs293/ttf10/uxb/AbstractDevice.scala @@ -1,3 +1,11 @@ +/* *\ +** Case Western Reserve University ** +** ** +** EECS 293 ** +** Software Craftsmanship ** +** 2016 Fall Semester ** +\* */ + package edu.cwru.eecs293.ttf10.uxb import edu.cwru.eecs293.ttf10.uxb.DeviceClass._ @@ -8,11 +16,7 @@ import edu.cwru.eecs293.ttf10.uxb.DeviceClass._ * @see [[https://blackboard.case.edu/bbcswebdav/pid-1381847-dt-content-rid-4318401_1/xid-4318401_1 Hw3.pdf]] *
[[https://blackboard.case.edu/bbcswebdav/pid-1379538-dt-content-rid-4287477_1/xid-4287477_1 Hw2.pdf]] * @since Programming Assignment 2 - *
- *
Case Western Reserve University - *
EECS 293: Software Craftsmanship - *
2016 Fall Semester - * @author Ted Frohlich < ttf10@case.edu > + * @author Ted Frohlich */ abstract class AbstractDevice[T <: AbstractDevice.Builder[T]](private val builder: AbstractDevice.Builder[T]) extends Device { diff --git a/scala/src/edu/cwru/eecs293/ttf10/uxb/AbstractPeripheral.scala b/scala/src/edu/cwru/eecs293/ttf10/uxb/AbstractPeripheral.scala index 44a447d..6a36d38 100644 --- a/scala/src/edu/cwru/eecs293/ttf10/uxb/AbstractPeripheral.scala +++ b/scala/src/edu/cwru/eecs293/ttf10/uxb/AbstractPeripheral.scala @@ -1,15 +1,19 @@ +/* *\ +** Case Western Reserve University ** +** ** +** EECS 293 ** +** Software Craftsmanship ** +** 2016 Fall Semester ** +\* */ + package edu.cwru.eecs293.ttf10.uxb /** - *

Represents a prototypical UXB peripheral. + * Represents a prototypical UXB peripheral. * * @see [[https://blackboard.case.edu/bbcswebdav/pid-1381847-dt-content-rid-4318401_1/xid-4318401_1 Hw3.pdf]] * @since Programming Assignment 3 - *
- *
Case Western Reserve University - *
EECS 293: Software Craftsmanship - *
2016 Fall Semester - * @author Ted Frohlich < ttf10@case.edu > + * @author Ted Frohlich */ abstract class AbstractPeripheral[T <: AbstractPeripheral.Builder[T]](private val builder: AbstractPeripheral.Builder[T]) extends AbstractDevice(builder) diff --git a/scala/src/edu/cwru/eecs293/ttf10/uxb/AbstractPrinter.scala b/scala/src/edu/cwru/eecs293/ttf10/uxb/AbstractPrinter.scala index de27d09..d4ca67e 100644 --- a/scala/src/edu/cwru/eecs293/ttf10/uxb/AbstractPrinter.scala +++ b/scala/src/edu/cwru/eecs293/ttf10/uxb/AbstractPrinter.scala @@ -1,17 +1,21 @@ +/* *\ +** Case Western Reserve University ** +** ** +** EECS 293 ** +** Software Craftsmanship ** +** 2016 Fall Semester ** +\* */ + package edu.cwru.eecs293.ttf10.uxb import DeviceClass._ /** - *

Represents a prototypical UXB printer. + * Represents a prototypical UXB printer. * * @see [[https://blackboard.case.edu/bbcswebdav/pid-1381847-dt-content-rid-4318401_1/xid-4318401_1 Hw3.pdf]] * @since Programming Assignment 3 - *
- *
Case Western Reserve University - *
EECS 293: Software Craftsmanship - *
2016 Fall Semester - * @author Ted Frohlich < ttf10@case.edu > + * @author Ted Frohlich */ abstract class AbstractPrinter[T <: AbstractPrinter.Builder[T]](private val builder: AbstractPrinter.Builder[T]) extends AbstractPeripheral(builder) { diff --git a/scala/src/edu/cwru/eecs293/ttf10/uxb/AbstractVideo.scala b/scala/src/edu/cwru/eecs293/ttf10/uxb/AbstractVideo.scala index ca4fe7c..2bf25bc 100644 --- a/scala/src/edu/cwru/eecs293/ttf10/uxb/AbstractVideo.scala +++ b/scala/src/edu/cwru/eecs293/ttf10/uxb/AbstractVideo.scala @@ -1,17 +1,21 @@ +/* *\ +** Case Western Reserve University ** +** ** +** EECS 293 ** +** Software Craftsmanship ** +** 2016 Fall Semester ** +\* */ + package edu.cwru.eecs293.ttf10.uxb import DeviceClass._ /** - *

Represents a prototypical UXB video peripheral device. + * Represents a prototypical UXB video peripheral device. * * @see [[https://blackboard.case.edu/bbcswebdav/pid-1381847-dt-content-rid-4318401_1/xid-4318401_1 Hw3.pdf]] * @since Programming Assignment 3 - *
- *
Case Western Reserve University - *
EECS 293: Software Craftsmanship - *
2016 Fall Semester - * @author Ted Frohlich < ttf10@case.edu > + * @author Ted Frohlich */ abstract class AbstractVideo[T <: AbstractVideo.Builder[T]](private val builder: AbstractVideo.Builder[T]) extends AbstractPeripheral(builder) { diff --git a/scala/src/edu/cwru/eecs293/ttf10/uxb/BinaryMessage.scala b/scala/src/edu/cwru/eecs293/ttf10/uxb/BinaryMessage.scala index 39356e2..548dc2d 100644 --- a/scala/src/edu/cwru/eecs293/ttf10/uxb/BinaryMessage.scala +++ b/scala/src/edu/cwru/eecs293/ttf10/uxb/BinaryMessage.scala @@ -1,3 +1,11 @@ +/* *\ +** Case Western Reserve University ** +** ** +** EECS 293 ** +** Software Craftsmanship ** +** 2016 Fall Semester ** +\* */ + package edu.cwru.eecs293.ttf10.uxb /** @@ -6,11 +14,7 @@ package edu.cwru.eecs293.ttf10.uxb * @see [[https://blackboard.case.edu/bbcswebdav/pid-1381847-dt-content-rid-4318401_1/xid-4318401_1 Hw3.pdf]] *
[[https://blackboard.case.edu/bbcswebdav/pid-1379538-dt-content-rid-4287477_1/xid-4287477_1 Hw2.pdf]] * @since Programming Assignment 2 - *
- *
Case Western Reserve University - *
EECS 293: Software Craftsmanship - *
2016 Fall Semester - * @author Ted Frohlich < ttf10@case.edu > + * @author Ted Frohlich */ final case class BinaryMessage(private var value: BigInt) extends Message { /** diff --git a/scala/src/edu/cwru/eecs293/ttf10/uxb/CannonPrinter.scala b/scala/src/edu/cwru/eecs293/ttf10/uxb/CannonPrinter.scala index 774d27f..a0f0655 100644 --- a/scala/src/edu/cwru/eecs293/ttf10/uxb/CannonPrinter.scala +++ b/scala/src/edu/cwru/eecs293/ttf10/uxb/CannonPrinter.scala @@ -1,15 +1,19 @@ +/* *\ +** Case Western Reserve University ** +** ** +** EECS 293 ** +** Software Craftsmanship ** +** 2016 Fall Semester ** +\* */ + package edu.cwru.eecs293.ttf10.uxb /** - *

Represents a concrete UXB cannon printer (with two n's!) + * Represents a concrete UXB cannon printer (with two n's!) * * @see [[https://blackboard.case.edu/bbcswebdav/pid-1381847-dt-content-rid-4318401_1/xid-4318401_1 Hw3.pdf]] * @since Programming Assignment 3 - *
- *
Case Western Reserve University - *
EECS 293: Software Craftsmanship - *
2016 Fall Semester - * @author Ted Frohlich < ttf10@case.edu > + * @author Ted Frohlich */ class CannonPrinter(private val builder: CannonPrinter.Builder) extends AbstractPrinter(builder) { diff --git a/scala/src/edu/cwru/eecs293/ttf10/uxb/ConnectionException.scala b/scala/src/edu/cwru/eecs293/ttf10/uxb/ConnectionException.scala index 8a0aa4e..65601fd 100644 --- a/scala/src/edu/cwru/eecs293/ttf10/uxb/ConnectionException.scala +++ b/scala/src/edu/cwru/eecs293/ttf10/uxb/ConnectionException.scala @@ -1,15 +1,19 @@ +/* *\ +** Case Western Reserve University ** +** ** +** EECS 293 ** +** Software Craftsmanship ** +** 2016 Fall Semester ** +\* */ + package edu.cwru.eecs293.ttf10.uxb /** - *

A ConnectionException will be used to signal problems when attempting to interconnect device. + * A `ConnectionException` will be used to signal problems when attempting to interconnect device. * * @see [[https://blackboard.case.edu/bbcswebdav/pid-1385161-dt-content-rid-4331066_1/courses/eecs293_vxl11/Hw4.pdf Hw4.pdf]] * @since Programming Assignment 4 - *
- *
Case Western Reserve University - *
EECS 293: Software Craftsmanship - *
2016 Fall Semester - * @author Ted Frohlich < ttf10@case.edu > + * @author Ted Frohlich */ @SerialVersionUID(293) class ConnectionException(private val connector: Connector, diff --git a/scala/src/edu/cwru/eecs293/ttf10/uxb/Connector.scala b/scala/src/edu/cwru/eecs293/ttf10/uxb/Connector.scala index 35969da..8888edb 100644 --- a/scala/src/edu/cwru/eecs293/ttf10/uxb/Connector.scala +++ b/scala/src/edu/cwru/eecs293/ttf10/uxb/Connector.scala @@ -1,18 +1,23 @@ +/* *\ +** Case Western Reserve University ** +** ** +** EECS 293 ** +** Software Craftsmanship ** +** 2016 Fall Semester ** +\* */ + package edu.cwru.eecs293.ttf10.uxb /** - *

Represents one of multiple connectors belonging to a UXB device. - *

Each connector is a physical plug that enables the user to insert a cable for connecting the device to a computer or to a UXB hub. Connectors are of two types: computer-side and peripheral-side. A computer-side connector is an outlet that is installed in a computer and a peripheral-side connector is a plug that is installed in a peripheral device. A UXB cable always runs from a peripheral to a computer but never from a computer to a computer or from a peripheral to a peripheral. A computer can have multiple computer-side connectors so that multiple peripherals can be added. A peripheral can have multiple peripheral-side connectors so that the peripheral can be added to multiple computers. A UXB hub can have multiple computer-side and peripheral-side connectors. + * Represents one of multiple connectors belonging to a UXB device. + *

+ * Each connector is a physical plug that enables the user to insert a cable for connecting the device to a computer or to a UXB hub. Connectors are of two types: computer-side and peripheral-side. A computer-side connector is an outlet that is installed in a computer and a peripheral-side connector is a plug that is installed in a peripheral device. A UXB cable always runs from a peripheral to a computer but never from a computer to a computer or from a peripheral to a peripheral. A computer can have multiple computer-side connectors so that multiple peripherals can be added. A peripheral can have multiple peripheral-side connectors so that the peripheral can be added to multiple computers. A UXB hub can have multiple computer-side and peripheral-side connectors. * * @see [[https://blackboard.case.edu/bbcswebdav/pid-1385161-dt-content-rid-4331066_1/courses/eecs293_vxl11/Hw4.pdf Hw4.pdf]] *
[[https://blackboard.case.edu/bbcswebdav/pid-1381847-dt-content-rid-4318401_1/xid-4318401_1 Hw3.pdf]] *
[[https://blackboard.case.edu/bbcswebdav/pid-1379538-dt-content-rid-4287477_1/xid-4287477_1 Hw2.pdf]] * @since Programming Assignment 2 - *
- *
Case Western Reserve University - *
EECS 293: Software Craftsmanship - *
2016 Fall Semester - * @author Ted Frohlich < ttf10@case.edu > + * @author Ted Frohlich */ final class Connector(private val device: Device, private val index: Int, private val `type`: Connector.Type) { diff --git a/scala/src/edu/cwru/eecs293/ttf10/uxb/Device.scala b/scala/src/edu/cwru/eecs293/ttf10/uxb/Device.scala index ebb4a9c..4287c9c 100644 --- a/scala/src/edu/cwru/eecs293/ttf10/uxb/Device.scala +++ b/scala/src/edu/cwru/eecs293/ttf10/uxb/Device.scala @@ -1,19 +1,23 @@ +/* *\ +** Case Western Reserve University ** +** ** +** EECS 293 ** +** Software Craftsmanship ** +** 2016 Fall Semester ** +\* */ + package edu.cwru.eecs293.ttf10.uxb import edu.cwru.eecs293.ttf10.uxb.DeviceClass._ /** - *

Represents a UXB device, which is a UXB-enabled computer, peripheral, or hub. + * Represents a UXB device, which is a UXB-enabled computer, peripheral, or hub. * * @see [[https://blackboard.case.edu/bbcswebdav/pid-1385161-dt-content-rid-4331066_1/courses/eecs293_vxl11/Hw4.pdf Hw4.pdf]] *
[[https://blackboard.case.edu/bbcswebdav/pid-1381847-dt-content-rid-4318401_1/xid-4318401_1 Hw3.pdf]] *
[[https://blackboard.case.edu/bbcswebdav/pid-1379538-dt-content-rid-4287477_1/xid-4287477_1 Hw2.pdf]] * @since Programming Assignment 2 - *
- *
Case Western Reserve University - *
EECS 293: Software Craftsmanship - *
2016 Fall Semester - * @author Ted Frohlich < ttf10@case.edu > + * @author Ted Frohlich */ trait Device { diff --git a/scala/src/edu/cwru/eecs293/ttf10/uxb/DeviceClass.scala b/scala/src/edu/cwru/eecs293/ttf10/uxb/DeviceClass.scala index 8f0b4a8..3514e1f 100644 --- a/scala/src/edu/cwru/eecs293/ttf10/uxb/DeviceClass.scala +++ b/scala/src/edu/cwru/eecs293/ttf10/uxb/DeviceClass.scala @@ -1,16 +1,21 @@ +/* *\ +** Case Western Reserve University ** +** ** +** EECS 293 ** +** Software Craftsmanship ** +** 2016 Fall Semester ** +\* */ + package edu.cwru.eecs293.ttf10.uxb /** * Represents one of many classes in which UXB devices are grouped. - *

The concept of device class similar in traditional USB. UXB classes are: audio, communication, human-interface, physical-interface (e.g., force feedback joysticks), image, printer, mass storage, video, audio-video, virtual reality, and hub. + *

+ * The concept of device class similar in traditional USB. UXB classes are: audio, communication, human-interface, physical-interface (e.g., force feedback joysticks), image, printer, mass storage, video, audio-video, virtual reality, and hub. * * @see [[https://blackboard.case.edu/bbcswebdav/pid-1379538-dt-content-rid-4287477_1/xid-4287477_1 Hw2.pdf]] * @since Programming Assignment 2 - *
- *
Case Western Reserve University - *
EECS 293: Software Craftsmanship - *
2016 Fall Semester - * @author Ted Frohlich < ttf10@case.edu > + * @author Ted Frohlich */ case object DeviceClass extends Enumeration { diff --git a/scala/src/edu/cwru/eecs293/ttf10/uxb/GoAmateur.scala b/scala/src/edu/cwru/eecs293/ttf10/uxb/GoAmateur.scala index ad32e6f..1cc7882 100644 --- a/scala/src/edu/cwru/eecs293/ttf10/uxb/GoAmateur.scala +++ b/scala/src/edu/cwru/eecs293/ttf10/uxb/GoAmateur.scala @@ -1,16 +1,21 @@ +/* *\ +** Case Western Reserve University ** +** ** +** EECS 293 ** +** Software Craftsmanship ** +** 2016 Fall Semester ** +\* */ + package edu.cwru.eecs293.ttf10.uxb /** - *

Represents a concrete UXB video peripheral device. - *

This just might be better than the [[http://www.ufunk.net/en/gadgets/goamateur/ GoAmateur]]! + * Represents a concrete UXB video peripheral device. + *

+ * This just might be better than the [[http://www.ufunk.net/en/gadgets/goamateur/ GoAmateur]]! * * @see [[https://blackboard.case.edu/bbcswebdav/pid-1381847-dt-content-rid-4318401_1/xid-4318401_1 Hw3.pdf]] * @since Programming Assignment 3 - *
- *
Case Western Reserve University - *
EECS 293: Software Craftsmanship - *
2016 Fall Semester - * @author Ted Frohlich < ttf10@case.edu > + * @author Ted Frohlich */ class GoAmateur(private val builder: GoAmateur.Builder) extends AbstractVideo[GoAmateur.Builder](builder) { diff --git a/scala/src/edu/cwru/eecs293/ttf10/uxb/Hub.scala b/scala/src/edu/cwru/eecs293/ttf10/uxb/Hub.scala index 60c9303..e87d9d0 100644 --- a/scala/src/edu/cwru/eecs293/ttf10/uxb/Hub.scala +++ b/scala/src/edu/cwru/eecs293/ttf10/uxb/Hub.scala @@ -1,18 +1,22 @@ +/* *\ +** Case Western Reserve University ** +** ** +** EECS 293 ** +** Software Craftsmanship ** +** 2016 Fall Semester ** +\* */ + package edu.cwru.eecs293.ttf10.uxb import DeviceClass._ /** - *

Represents a UXB hub, which can have multiple computer-side and peripheral-side connectors. + * Represents a UXB hub, which can have multiple computer-side and peripheral-side connectors. * * @see [[https://blackboard.case.edu/bbcswebdav/pid-1381847-dt-content-rid-4318401_1/xid-4318401_1 Hw3.pdf]] *
[[https://blackboard.case.edu/bbcswebdav/pid-1379538-dt-content-rid-4287477_1/xid-4287477_1 Hw2.pdf]] * @since Programming Assignment 2 - *
- *
Case Western Reserve University - *
EECS 293: Software Craftsmanship - *
2016 Fall Semester - * @author Ted Frohlich < ttf10@case.edu > + * @author Ted Frohlich */ class Hub(private val builder: Hub.Builder) extends AbstractDevice(builder) { diff --git a/scala/src/edu/cwru/eecs293/ttf10/uxb/Message.scala b/scala/src/edu/cwru/eecs293/ttf10/uxb/Message.scala index 844b414..65153dc 100644 --- a/scala/src/edu/cwru/eecs293/ttf10/uxb/Message.scala +++ b/scala/src/edu/cwru/eecs293/ttf10/uxb/Message.scala @@ -1,16 +1,20 @@ +/* *\ +** Case Western Reserve University ** +** ** +** EECS 293 ** +** Software Craftsmanship ** +** 2016 Fall Semester ** +\* */ + package edu.cwru.eecs293.ttf10.uxb /** - *

Represents a message carried between devices via UXB cable. + * Represents a message carried between devices via UXB cable. * * @see [[https://blackboard.case.edu/bbcswebdav/pid-1381847-dt-content-rid-4318401_1/xid-4318401_1 Hw3.pdf]] *
[[https://blackboard.case.edu/bbcswebdav/pid-1379538-dt-content-rid-4287477_1/xid-4287477_1 Hw2.pdf]] * @since Programming Assignment 2 - *
- *
Case Western Reserve University - *
EECS 293: Software Craftsmanship - *
2016 Fall Semester - * @author Ted Frohlich < ttf10@case.edu > + * @author Ted Frohlich */ trait Message { diff --git a/scala/src/edu/cwru/eecs293/ttf10/uxb/SisterPrinter.scala b/scala/src/edu/cwru/eecs293/ttf10/uxb/SisterPrinter.scala index c911a14..66ae30c 100644 --- a/scala/src/edu/cwru/eecs293/ttf10/uxb/SisterPrinter.scala +++ b/scala/src/edu/cwru/eecs293/ttf10/uxb/SisterPrinter.scala @@ -1,15 +1,19 @@ +/* *\ +** Case Western Reserve University ** +** ** +** EECS 293 ** +** Software Craftsmanship ** +** 2016 Fall Semester ** +\* */ + package edu.cwru.eecs293.ttf10.uxb /** - *

Represents a concrete UXB printer. + * Represents a concrete UXB printer. * * @see [[https://blackboard.case.edu/bbcswebdav/pid-1381847-dt-content-rid-4318401_1/xid-4318401_1 Hw3.pdf]] * @since Programming Assignment 3 - *
- *
Case Western Reserve University - *
EECS 293: Software Craftsmanship - *
2016 Fall Semester - * @author Ted Frohlich < ttf10@case.edu > + * @author Ted Frohlich */ class SisterPrinter(private val builder: SisterPrinter.Builder) extends AbstractPrinter(builder) { diff --git a/scala/src/edu/cwru/eecs293/ttf10/uxb/StringMessage.scala b/scala/src/edu/cwru/eecs293/ttf10/uxb/StringMessage.scala index 3df2cb0..0117b92 100644 --- a/scala/src/edu/cwru/eecs293/ttf10/uxb/StringMessage.scala +++ b/scala/src/edu/cwru/eecs293/ttf10/uxb/StringMessage.scala @@ -1,15 +1,19 @@ +/* *\ +** Case Western Reserve University ** +** ** +** EECS 293 ** +** Software Craftsmanship ** +** 2016 Fall Semester ** +\* */ + package edu.cwru.eecs293.ttf10.uxb /** - *

Represents a string message carried between devices via UXB cable. + * Represents a string message carried between devices via UXB cable. * * @see [[https://blackboard.case.edu/bbcswebdav/pid-1381847-dt-content-rid-4318401_1/xid-4318401_1 Hw3.pdf]] * @since Programming Assignment 3 - *
- *
Case Western Reserve University - *
EECS 293: Software Craftsmanship - *
2016 Fall Semester - * @author Ted Frohlich < ttf10@case.edu > + * @author Ted Frohlich */ final case class StringMessage(private var string: String) extends Message { /** From 96250b61f4fe389f1c9b43b9361907eb7ba732af Mon Sep 17 00:00:00 2001 From: teddybear02 Date: Sun, 9 Oct 2016 22:14:28 -0400 Subject: [PATCH 20/21] Overhauled header format --- .../ttf10/uxb/AbstractDeviceTest.scala | 20 ++++++++----- .../cwru/eecs293/ttf10/uxb/Broadcast.scala | 29 +++++++++---------- .../cwru/eecs293/ttf10/uxb/Connections.scala | 14 +++++---- .../cwru/eecs293/ttf10/uxb/SystemTest.scala | 24 ++++++++------- 4 files changed, 49 insertions(+), 38 deletions(-) diff --git a/scala/test/edu/cwru/eecs293/ttf10/uxb/AbstractDeviceTest.scala b/scala/test/edu/cwru/eecs293/ttf10/uxb/AbstractDeviceTest.scala index e6c072c..d9a19ce 100644 --- a/scala/test/edu/cwru/eecs293/ttf10/uxb/AbstractDeviceTest.scala +++ b/scala/test/edu/cwru/eecs293/ttf10/uxb/AbstractDeviceTest.scala @@ -1,17 +1,21 @@ +/* *\ +** Case Western Reserve University ** +** ** +** EECS 293 ** +** Software Craftsmanship ** +** 2016 Fall Semester ** +\* */ + package edu.cwru.eecs293.ttf10.uxb import org.junit.Assert._ import org.junit.{Before, Test} -/**

- * Class for testing methods in [[edu.cwru.eecs293.ttf10.uxb.AbstractDevice AbstractDevice]] and other underlying functionality thereof. Since the AbstractDevice class is obviously abstract, test cases employ concrete subclass [[edu.cwru.eecs293.ttf10.uxb.Hub Hub]] to allow for actualization and access of the superceding functionality in question. - *

+/** + * Class for testing methods in [[edu.cwru.eecs293.ttf10.uxb.AbstractDevice AbstractDevice]] and other underlying functionality thereof. Since the `AbstractDevice` class is obviously abstract, test cases employ concrete subclass [[edu.cwru.eecs293.ttf10.uxb.Hub Hub]] to allow for actualization and access of the superceding functionality in question. + * * @since Programming Assignment 2 - *
- *
Case Western Reserve University - *
EECS 293: Software Craftsmanship - *
2016 Fall Semester - * @author Ted Frohlich < ttf10@case.edu > + * @author Ted Frohlich */ class AbstractDeviceTest { diff --git a/scala/test/edu/cwru/eecs293/ttf10/uxb/Broadcast.scala b/scala/test/edu/cwru/eecs293/ttf10/uxb/Broadcast.scala index 2a28748..8c11006 100644 --- a/scala/test/edu/cwru/eecs293/ttf10/uxb/Broadcast.scala +++ b/scala/test/edu/cwru/eecs293/ttf10/uxb/Broadcast.scala @@ -1,17 +1,20 @@ +/* *\ +** Case Western Reserve University ** +** ** +** EECS 293 ** +** Software Craftsmanship ** +** 2016 Fall Semester ** +\* */ + package edu.cwru.eecs293.ttf10.uxb import org.junit.{Before, Test} -/**

- * A test that, given a List[Device] and a List[Message], delivers all messages to all devices on their zero connector (if any). The device list should contain at least one device of each type, and the message list should contain at least one binary and at least one -string message. +/** + * A test that, given a List[Device] and a List[Message], delivers all messages to all devices on their zero connector (if any). The device list should contain at least one device of each type, and the message list should contain at least one binary and at least one string message. * * @since Programming Assignment 2 - *
- *
Case Western Reserve University - *
EECS 293: Software Craftsmanship - *
2016 Fall Semester - * @author Ted Frohlich < ttf10@case.edu > + * @author Ted Frohlich */ class Broadcast { @@ -20,7 +23,6 @@ class Broadcast { @Before def setUp() { - // Instantiate device set val conList = List(Connector.Type.PERIPHERAL) devices = Set( @@ -40,7 +42,6 @@ class Broadcast { .connectors(conList) .build() ) - // Initialize message list messages = List( StringMessage("Hello, world!"), @@ -54,11 +55,9 @@ class Broadcast { @Test @throws[Exception] def broadcast() { - for (device <- devices) { - for (message <- messages) { - device.getConnector(0).recv(message) - } - } + devices.foreach(device => + messages.foreach(message => + device.getConnector(0).recv(message))) } } diff --git a/scala/test/edu/cwru/eecs293/ttf10/uxb/Connections.scala b/scala/test/edu/cwru/eecs293/ttf10/uxb/Connections.scala index 3b513d0..0bf0f9a 100644 --- a/scala/test/edu/cwru/eecs293/ttf10/uxb/Connections.scala +++ b/scala/test/edu/cwru/eecs293/ttf10/uxb/Connections.scala @@ -1,3 +1,11 @@ +/* *\ +** Case Western Reserve University ** +** ** +** EECS 293 ** +** Software Craftsmanship ** +** 2016 Fall Semester ** +\* */ + package edu.cwru.eecs293.ttf10.uxb import org.junit.{Before, Test} @@ -7,11 +15,7 @@ import org.junit.{Before, Test} * * @see [[https://blackboard.case.edu/bbcswebdav/pid-1385161-dt-content-rid-4331066_1/courses/eecs293_vxl11/Hw4.pdf Hw4.pdf]] * @since Programming Assignment 4 - *
- *
Case Western Reserve University - *
EECS 293: Software Craftsmanship - *
2016 Fall Semester - * @author Ted Frohlich < ttf10@case.edu > + * @author Ted Frohlich */ class Connections { diff --git a/scala/test/edu/cwru/eecs293/ttf10/uxb/SystemTest.scala b/scala/test/edu/cwru/eecs293/ttf10/uxb/SystemTest.scala index bbb88b7..05af816 100644 --- a/scala/test/edu/cwru/eecs293/ttf10/uxb/SystemTest.scala +++ b/scala/test/edu/cwru/eecs293/ttf10/uxb/SystemTest.scala @@ -1,8 +1,16 @@ +/* *\ +** Case Western Reserve University ** +** ** +** EECS 293 ** +** Software Craftsmanship ** +** 2016 Fall Semester ** +\* */ + package edu.cwru.eecs293.ttf10.uxb import org.junit.{Before, Test} -/**

+/** * This test creates a UXB system containing two hubs, three printers (not all of the same type), and a Webcam. These UXB devices will all be connected with each other, directly or indirectly. Then, the following scenarios will be explored: *

    *
  • A string message is broadcast from a hub. @@ -10,11 +18,7 @@ import org.junit.{Before, Test} *
  • A binary message is broadcast from a hub. *
* @since Programming Assignment 5 - *
- *
Case Western Reserve University - *
EECS 293: Software Craftsmanship - *
2016 Fall Semester - * @author Ted Frohlich < ttf10@case.edu > + * @author Ted Frohlich */ class SystemTest { @@ -24,7 +28,7 @@ class SystemTest { private var webcam: GoAmateur = _ @Before - def setUp { + def setUp() { webcam = new GoAmateur.Builder(2) .connectors(List( Connector.Type.PERIPHERAL)) // to hub1 @@ -55,19 +59,19 @@ class SystemTest { @Test @throws[Exception] - def broadcastStringMessage { + def broadcastStringMessage() { } @Test @throws[Exception] - def sendBinaryMessage { + def sendBinaryMessage() { } @Test @throws[Exception] - def broadcastBinaryMessage { + def broadcastBinaryMessage() { } From e467e36009792a048d2f75ebc6b3b12182cdb6b3 Mon Sep 17 00:00:00 2001 From: teddybear02 Date: Mon, 10 Oct 2016 04:14:24 -0400 Subject: [PATCH 21/21] Updated system communication and tests --- .../eecs293/ttf10/uxb/AbstractDevice.scala | 16 +++------- .../edu/cwru/eecs293/ttf10/uxb/Device.scala | 31 ++++++++++++++++--- .../src/edu/cwru/eecs293/ttf10/uxb/Hub.scala | 26 +++++++++++----- .../cwru/eecs293/ttf10/uxb/SystemTest.scala | 21 +++++++++++-- 4 files changed, 67 insertions(+), 27 deletions(-) diff --git a/scala/src/edu/cwru/eecs293/ttf10/uxb/AbstractDevice.scala b/scala/src/edu/cwru/eecs293/ttf10/uxb/AbstractDevice.scala index 5b3e57e..7763542 100644 --- a/scala/src/edu/cwru/eecs293/ttf10/uxb/AbstractDevice.scala +++ b/scala/src/edu/cwru/eecs293/ttf10/uxb/AbstractDevice.scala @@ -73,16 +73,6 @@ abstract class AbstractDevice[T <: AbstractDevice.Builder[T]](private val builde def isReachable(device: Device): Boolean = reachableDevicesUntil(device).contains(device) - /** - * Signifies the arrival of a message at the given connector in the device. - * - * @param message the message being received - * @param connector the connector at which the message arrived - * @throws NullPointerException if either argument is null - * @throws IllegalArgumentException if the connector does not belong to this device - */ - @throws[NullPointerException] - @throws[IllegalArgumentException] protected def validateRecv(message: Message, connector: Connector) { if (message == null || connector == null) throw new NullPointerException("Message not received: null argument.") @@ -90,8 +80,6 @@ abstract class AbstractDevice[T <: AbstractDevice.Builder[T]](private val builde throw new IllegalArgumentException("Message not received: connector does not belong to this device.") } - @throws[NullPointerException] - @throws[IllegalArgumentException] protected def send(message: Message, connectors: List[Connector]) { if (message == null || connectors == null || connectors.contains(null)) throw new NullPointerException("Message not sent: null argument") @@ -101,6 +89,10 @@ abstract class AbstractDevice[T <: AbstractDevice.Builder[T]](private val builde .foreach(_.recv(message))) // `foreach` passes over an undefined optional value } + def broadcast(message: Message) { + send(message, connectors) + } + } diff --git a/scala/src/edu/cwru/eecs293/ttf10/uxb/Device.scala b/scala/src/edu/cwru/eecs293/ttf10/uxb/Device.scala index 4287c9c..6ff9a51 100644 --- a/scala/src/edu/cwru/eecs293/ttf10/uxb/Device.scala +++ b/scala/src/edu/cwru/eecs293/ttf10/uxb/Device.scala @@ -92,14 +92,14 @@ trait Device { * Maps a set of all devices reachable from this device until the target device is found. * * @param target an optional device parameter that terminates this function when found - * @return a set of all devices reachable from this device, or null if the target was found + * @return a set of all devices reachable from this device, or `null` if the target was found */ protected def reachableDevicesUntil(target: Device = null): Set[Device] /** * Maps a set of all devices reachable from this device. * - * @return all devices that are reachable either directly (the peerDevices) or indirectly from this device + * @return all devices that are reachable either directly (the `peerDevices`) or indirectly from this device */ def reachableDevices: Set[Device] @@ -107,9 +107,21 @@ trait Device { * Determines whether the given device is reachable from this device. * * @param device the device in question - * @return true if the argument is connected directly or indirectly to this device, false otherwise + * @return `true` if the argument is connected directly or indirectly to this device, `false` otherwise */ def isReachable(device: Device): Boolean + + /** + * Signifies the arrival of a message at the given connector in the device. + * + * @param message the message being received + * @param connector the connector at which the message arrived + * @throws NullPointerException if either argument is null + * @throws IllegalArgumentException if the connector does not belong to this device + */ + @throws[NullPointerException] + @throws[IllegalArgumentException] + protected def validateRecv(message: Message, connector: Connector) /** * Signifies the arrival of a message at the given connector in the device. @@ -140,11 +152,22 @@ trait Device { * * @param message the message * @param connectors the connectors on which the message will be sent - * @throws NullPointerException if either argument is null, or if connectors contains a null connector + * @throws NullPointerException if either argument is null, or if `connectors` contains a null connector * @throws IllegalArgumentException if any of the connectors do not belong to this device */ @throws[NullPointerException] @throws[IllegalArgumentException] protected def send(message: Message, connectors: List[Connector]) + /** + * Broadcasts a message on all connectors belonging to this hub. + * + * @param message the message to send + * @throws NullPointerException if the message is null + * @throws IllegalArgumentException if any of the connectors employed in this broadcast do not belong to this device + */ + @throws[NullPointerException] + @throws[IllegalArgumentException] + def broadcast(message: Message) + } diff --git a/scala/src/edu/cwru/eecs293/ttf10/uxb/Hub.scala b/scala/src/edu/cwru/eecs293/ttf10/uxb/Hub.scala index e87d9d0..7a92e65 100644 --- a/scala/src/edu/cwru/eecs293/ttf10/uxb/Hub.scala +++ b/scala/src/edu/cwru/eecs293/ttf10/uxb/Hub.scala @@ -22,32 +22,42 @@ class Hub(private val builder: Hub.Builder) extends AbstractDevice(builder) { override def getDeviceClass: DeviceClass = DeviceClass.HUB - @throws[NullPointerException] - @throws[IllegalArgumentException] def recv(message: StringMessage, connector: Connector) { validateRecv(message, connector) - send(message, connector) + sendFrom(message, connector) println("[Log] >> " + "Hub has forwarded on the string message: " + message.getString) } - @throws[NullPointerException] - @throws[IllegalArgumentException] def recv(message: BinaryMessage, connector: Connector) { validateRecv(message, connector) - send(message, connector) + sendFrom(message, connector) println("[Log] >> " + "Hub has forwarded on the binary message: " + message.getValue) } /** - * Forwards the received message on all its connectors except the one from which the message was received. + * Forwards the received message on all connectors except the one from which the message was received. * * @param message the received message * @param connector the connector from which the message was received */ - protected def send(message: Message, connector: Connector) { + @throws[NullPointerException] + @throws[IllegalArgumentException] + private def sendFrom(message: Message, connector: Connector) { send(message, connectors diff List(connector)) } + /** + * Sends a message from this hub along one of its connectors. + * + * @param message the message to send + * @param connector the connector to which the message is being sent + */ + @throws[NullPointerException] + @throws[IllegalArgumentException] + def sendTo(message: Message, connector: Connector) { + send(message, List(connector)) + } + } diff --git a/scala/test/edu/cwru/eecs293/ttf10/uxb/SystemTest.scala b/scala/test/edu/cwru/eecs293/ttf10/uxb/SystemTest.scala index 05af816..4d0f95f 100644 --- a/scala/test/edu/cwru/eecs293/ttf10/uxb/SystemTest.scala +++ b/scala/test/edu/cwru/eecs293/ttf10/uxb/SystemTest.scala @@ -57,22 +57,37 @@ class SystemTest { printer2 = sisterPrinterBuilder.build() } + /** + * Tests the scenario in which a string message is broadcast from a hub. + * + * @throws Exception if the test fails + */ @Test @throws[Exception] def broadcastStringMessage() { - + hub1.broadcast(StringMessage("A string message is broadcast from a hub.")) } + /** + * Tests the scenario in which a binary message is sent from a hub along a connector that links the hub to a Webcam. + * + * @throws Exception if the test fails + */ @Test @throws[Exception] def sendBinaryMessage() { - + hub1.sendTo(BinaryMessage(132), hub1.getConnector(0)) } + /** + * Tests the scenario in which a binary message is broadcast from a hub. + * + * @throws Exception if the test fails + */ @Test @throws[Exception] def broadcastBinaryMessage() { - + hub2.broadcast(BinaryMessage(132465798)) } }