// Collection of code snippets by Arne Vajhøj 
// (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) 
package jcademo.raoutbound.multcp_cci;

import java.util.AbstractList;

import javax.resource.cci.IndexedRecord;

@SuppressWarnings("rawtypes")
public class CCI_AB_IndexedRecord extends AbstractList implements IndexedRecord {
	private static final long serialVersionUID = 1L;
	private int a;
	private int b;
	// record name and description
	@Override
	public String getRecordName() {
		return "AB";
	}
	@Override
	public void setRecordName(String name) {
		// name is fixed
	}
	@Override
	public String getRecordShortDescription() {
		return "A and B (input)";
	}
	@Override
	public void setRecordShortDescription(String description) {
		// description is fixed
	}
	// core methods
	@Override
	public Object get(int index) {
		switch(index) {
			case 0:
				return a;
			case 1:
				return b;
			default:
				throw new IndexOutOfBoundsException(Integer.toString(index));
		}
	}
	@Override
	public Object set(int index, Object element) {
		switch(index) {
			case 0:
				int olda = a;
				a = (Integer)element;
				return olda;
			case 1:
				int oldb = b;
				b = (Integer)element;
				return oldb;
			default:
				throw new IndexOutOfBoundsException(Integer.toString(index));
		}
	}
	@Override
	public int size() {
		return 2;
	}
	// required
	@Override
	public Object clone() throws CloneNotSupportedException {
		return super.clone();
	}
}
