// 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.AbstractMap;
import java.util.HashSet;
import java.util.Set;

import javax.resource.cci.MappedRecord;

@SuppressWarnings("rawtypes")
public class CCI_AB_MappedRecord extends AbstractMap implements MappedRecord {
	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 Set entrySet() {
		Set res = new HashSet();
		res.add(new AbstractMap.SimpleEntry("A", (Integer)a));
		res.add(new AbstractMap.SimpleEntry("B", (Integer)b));
		return res;
	}
	@Override
	public Object put(Object key, Object value) {
		if(key.equals("A")) {
			int olda = a;
			a = (Integer) value;
			return olda;
		} else if(key.equals("B")) {
			int oldb = b;
			b = (Integer) value;
			return oldb;
		} else {
			throw new IllegalArgumentException("Bad key: " + key);
		}
	}
	// required
	@Override
	public Object clone() throws CloneNotSupportedException {
		return super.clone();
	}
}
