001 package com.mockrunner.mock.connector.cci; 002 003 import java.util.Collection; 004 import java.util.HashMap; 005 import java.util.Map; 006 import java.util.Set; 007 008 import javax.resource.cci.MappedRecord; 009 010 import com.mockrunner.base.NestedApplicationException; 011 012 /** 013 * Mock implementation of <code>MappedRecord</code>. 014 */ 015 public class MockMappedRecord extends MockRecord implements MappedRecord 016 { 017 private Map backingMap; 018 019 public MockMappedRecord() 020 { 021 this("MockrunnerGenericMappedRecord"); 022 } 023 024 public MockMappedRecord(String name) 025 { 026 this(name, name); 027 } 028 029 public MockMappedRecord(String name, String description) 030 { 031 super(name, description); 032 backingMap = new HashMap(); 033 } 034 035 public int size() 036 { 037 return backingMap.size(); 038 } 039 040 public boolean isEmpty() 041 { 042 return backingMap.isEmpty(); 043 } 044 045 public boolean containsKey(Object key) 046 { 047 return backingMap.containsKey(key); 048 } 049 050 public boolean containsValue(Object value) 051 { 052 return backingMap.containsValue(value); 053 } 054 055 public Object get(Object key) 056 { 057 return backingMap.get(key); 058 } 059 060 public Object put(Object key, Object value) 061 { 062 return backingMap.put(key, value); 063 } 064 065 public Object remove(Object key) 066 { 067 return backingMap.remove(key); 068 } 069 070 public void putAll(Map map) 071 { 072 backingMap.putAll(map); 073 } 074 075 public void clear() 076 { 077 backingMap.clear(); 078 } 079 080 public Set keySet() 081 { 082 return backingMap.keySet(); 083 } 084 085 public Collection values() 086 { 087 return backingMap.values(); 088 } 089 090 public Set entrySet() 091 { 092 return backingMap.entrySet(); 093 } 094 095 public boolean equals(Object object) 096 { 097 if(!super.equals(object)) return false; 098 MockMappedRecord other = (MockMappedRecord)object; 099 return backingMap.equals(other.backingMap); 100 } 101 102 public int hashCode() 103 { 104 return super.hashCode() * 31 + backingMap.hashCode(); 105 } 106 107 public String toString() 108 { 109 return super.toString() + "\n" + backingMap.toString(); 110 } 111 112 public Object clone() 113 { 114 try 115 { 116 MockMappedRecord clone = (MockMappedRecord)super.clone(); 117 clone.backingMap = new HashMap(this.backingMap); 118 return clone; 119 } 120 catch(Exception exc) 121 { 122 throw new NestedApplicationException(exc); 123 } 124 } 125 }