java: fixes ListTemplate and MapTemplate

This commit is contained in:
frsyuki 2010-10-24 20:11:39 +09:00
parent e3bf8a404b
commit 19ff0dd17f
3 changed files with 36 additions and 2 deletions

View file

@ -34,10 +34,11 @@ public class ListTemplate implements Template {
}
public void pack(Packer pk, Object target) throws IOException {
if(target instanceof List) {
if(!(target instanceof List)) {
throw new MessageTypeException();
}
List<Object> list = (List<Object>)target;
pk.packArray(list.size());
for(Object element : list) {
elementTemplate.pack(pk, element);
}

View file

@ -40,10 +40,11 @@ public class MapTemplate implements Template {
}
public void pack(Packer pk, Object target) throws IOException {
if(target instanceof Map) {
if(!(target instanceof Map)) {
throw new MessageTypeException();
}
Map<Object,Object> map = (Map<Object,Object>)target;
pk.packMap(map.size());
for(Map.Entry<Object,Object> pair : map.entrySet()) {
keyTemplate.pack(pk, pair.getKey());
valueTemplate.pack(pk, pair.getValue());