-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
434bbc2
commit 1754c3f
Showing
5 changed files
with
55 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package Entities.Equipment; | ||
|
||
import Entities.Packages.Packet; | ||
import Entities.Packages.PacketType; | ||
import Exceptions.AssociateEquipmentError; | ||
|
||
public abstract class NetEquipment extends Equipment{ | ||
|
||
protected int connectionsNumber; | ||
|
||
public int getConnectionsNumber() { | ||
return connectionsNumber; | ||
} | ||
|
||
public void setConnectionsNumber(int connectionsNumber) { | ||
this.connectionsNumber = connectionsNumber; | ||
} | ||
|
||
public abstract void sendPacket(Packet<PacketType> packet); | ||
|
||
public abstract void receivePacket(Packet<PacketType> packet); | ||
|
||
@Override | ||
public void associateEquipment(Equipment equipment) throws AssociateEquipmentError{ | ||
|
||
if(this.isConnNumberExceeded()) | ||
{ | ||
throw new AssociateEquipmentError(); | ||
}else{ | ||
this.equipments.add(equipment); | ||
equipment.associateEquipment(this); | ||
} | ||
|
||
} | ||
|
||
private boolean isConnNumberExceeded(){ | ||
return this.equipments.size() > this.connectionsNumber; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package Exceptions; | ||
|
||
public class AssociateEquipmentError extends Exception { | ||
|
||
public AssociateEquipmentError(){ | ||
super("Can not associate equipment, connections numbers exceeded"); | ||
} | ||
} |