All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.lafaspot.pop.command.PopCommandResponse Maven / Gradle / Ivy

The newest version!
/**
 * 
 */
package com.lafaspot.pop.command;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Nonnull;

/**
 * Pop comamnd response object.
 * @author kraman
 *
 */
public class PopCommandResponse {

	/** Response type - ERR or OK. */
	private Type  type;
	/** Is parsing complete for response. */
	private boolean parseComplete = false;
	/** This response is for command. */
	private final PopCommand command;
	/** Response lines. */
	private final List lines = new ArrayList();

	/**
	 * Constructor.
	 * @param command this response is for
	 */
	public PopCommandResponse(@Nonnull final PopCommand command) {
		this.command = command;
		this.parseComplete = !command.getType().multiLine();
	}

	/**
	 * Return if parse is complete.
	 * @return parseComplete
	 */
	public boolean parseComplete() {
		return parseComplete;
	}

	/**
	 * Parse one line of response.
	 * @param line response line
	 */
	public void parse(@Nonnull final String line) {

		if (line.trim().startsWith("-ERR")) {
			parseComplete = true;
			type = Type.ERR;
		} else if (line.trim().startsWith("+OK")) {
			type = Type.OK;
		} else if (line.trim().equals(".")) {
			parseComplete = true;
		}
		lines.add(line);
	}

	/**
	 * Is this response OK?
	 * @return was the response OK
	 */
	public boolean isOk() {
		return Type.OK.equals(type);
	}

	/**
	 * Get response lines.
	 * @return response lines
	 */
	public List getLines() {
		return lines;
	}

	/**
	 * Return the command this response is for.
	 * @return command
	 */
	public PopCommand getCommand() {
		return command;
	}

	/**
	 * Response type, OK or ERR.
	 * @author kraman
	 *
	 */
	public enum Type {
		/** Response OK. */
		OK,
		/** Response ERR. */
		ERR
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy