public class Reply {
/** The source of the reply. */
- private final Optional<String> source;
+ private final Optional<Source> source;
/** The command of the reply (may be numeric). */
private final String command;
* @param parameters
* The parameters of the reply
*/
- private Reply(Optional<String> source, String command, List<String> parameters) {
+ private Reply(Optional<Source> source, String command, List<String> parameters) {
this.source = source;
this.command = command;
this.parameters = parameters;
*
* @return The source of the reply, or {@link Optional#absent()}
*/
- public Optional<String> source() {
+ public Optional<Source> source() {
return source;
}
}
//
+ // OBJECT METHODS
+ //
+
+ @Override
+ public String toString() {
+ StringBuilder string = new StringBuilder();
+ if (source.isPresent()) {
+ string.append(':').append(source.get()).append(' ');
+ }
+ string.append(command);
+ for (int parameterIndex = 0; parameterIndex < parameters.size(); ++parameterIndex) {
+ string.append(' ');
+ String parameter = parameters.get(parameterIndex);
+ if (parameterIndex == (parameters.size() - 1) && parameter.contains(" ")) {
+ string.append(':');
+ }
+ string.append(parameter);
+ }
+ return string.toString();
+ }
+
+ //
// STATIC METHODS
//
String remainingLine = line;
/* parse source. */
- Optional<String> source = Optional.absent();
+ Optional<Source> source = Optional.absent();
if (remainingLine.startsWith(":")) {
- source = Optional.of(getFirstWord(remainingLine).substring(1));
+ source = Optional.of(Source.parseSource(getFirstWord(remainingLine).substring(1)));
remainingLine = removeFirstWord(remainingLine);
}