You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
1.9 KiB
71 lines
1.9 KiB
package network.MessageEncoders;
|
|
|
|
|
|
import network.Exceptions.InvalidMessageTypeException;
|
|
import network.Messages.Enums.MessageType;
|
|
|
|
/**
|
|
* Factory to create the appropriate encoder for a given message.
|
|
*/
|
|
public class EncoderFactory {
|
|
|
|
|
|
/**
|
|
* Private constructor. Currently doesn't need to be constructed.
|
|
*/
|
|
private EncoderFactory(){
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* Creates the correct type of encoder for a given message type.
|
|
* @param type Type of message you want an encoder for.
|
|
* @return The encoder.
|
|
* @throws InvalidMessageTypeException If you pass in a {@link MessageType} that isn't recognised.
|
|
*/
|
|
public static MessageEncoder create(MessageType type) throws InvalidMessageTypeException {
|
|
|
|
|
|
switch (type) {
|
|
|
|
case HEARTBEAT: return new HeartBeatEncoder();
|
|
|
|
case RACESTATUS: return new RaceStatusEncoder();
|
|
|
|
//case DISPLAYTEXTMESSAGE: return new DisplayTextMessageEncoder();//TODO
|
|
|
|
case XMLMESSAGE: return new XMLMessageEncoder();
|
|
|
|
case RACESTARTSTATUS: return new RaceStartStatusEncoder();
|
|
|
|
case YACHTEVENTCODE: return new YachtEventCodeEncoder();
|
|
|
|
//case YACHTACTIONCODE: return new YachtActionCodeEncoder();//TODO
|
|
|
|
//case CHATTERTEXT: return new ChatterTextEncoder();//TODO
|
|
|
|
case BOATLOCATION: return new BoatLocationEncoder();
|
|
|
|
case MARKROUNDING: return new MarkRoundingEncoder();
|
|
|
|
case COURSEWIND: return new CourseWindsEncoder();
|
|
|
|
case AVGWIND: return new AverageWindEncoder();
|
|
|
|
case REQUEST_TO_JOIN: return new RequestToJoinEncoder();
|
|
|
|
case JOIN_ACCEPTANCE: return new JoinAcceptanceEncoder();
|
|
|
|
case BOATACTION: return new BoatActionEncoder();
|
|
|
|
|
|
default: throw new InvalidMessageTypeException("Unrecognised message type: " + type);
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|