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

com.rivescript.session.History Maven / Gradle / Ivy

There is a newer version: 0.11.0
Show newest version
/*
 * Copyright (c) 2016 the original author or authors.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

package com.rivescript.session;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import static com.rivescript.RiveScript.UNDEFINED;
import static com.rivescript.session.SessionManager.HISTORY_SIZE;

/**
 * Container to keep track of recent input and reply history.
 *
 * @author Noah Petherbridge
 * @author Marcel Overdijk
 */
public class History implements Serializable {

	private static final long serialVersionUID = 3383496053211557826L;

	private List input;
	private List reply;

	public History() {
		this.input = new ArrayList<>(HISTORY_SIZE);
		this.reply = new ArrayList<>(HISTORY_SIZE);
		for (int i = 0; i < HISTORY_SIZE; i++) {
			this.input.add(UNDEFINED);
			this.reply.add(UNDEFINED);
		}
	}

	public List getInput() {
		return input;
	}

	public String getInput(int index) {
		return input.get(index);
	}

	public List getReply() {
		return reply;
	}

	public String getReply(int index) {
		return reply.get(index);
	}

	@Override
	public boolean equals(Object o) {
		if (this == o) {
			return true;
		}
		if (o == null || getClass() != o.getClass()) {
			return false;
		}
		History that = (History) o;
		if (input != null ? !input.equals(that.input) : that.input != null) {
			return false;
		}
		return reply != null ? reply.equals(that.reply) : that.reply == null;
	}

	@Override
	public int hashCode() {
		int result = input != null ? input.hashCode() : 0;
		result = 31 * result + (reply != null ? reply.hashCode() : 0);
		return result;
	}

	@Override
	public String toString() {
		return "History{" +
				"input=" + input +
				", reply=" + reply +
				'}';
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy