EMMA Coverage Report (generated Wed Aug 29 00:03:59 CDT 2007)
[all classes][org.fuwjax.jon.type]

COVERAGE SUMMARY FOR SOURCE FILE [MapType.java]

nameclass, %method, %block, %line, %
MapType.java100% (1/1)100% (12/12)100% (109/109)100% (34/34)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class MapType100% (1/1)100% (12/12)100% (109/109)100% (34/34)
MapType (Class): void 100% (1/1)100% (4/4)100% (2/2)
createContainer (Object): Object 100% (1/1)100% (11/11)100% (4/4)
createInstance (Object, Object): Object 100% (1/1)100% (2/2)100% (1/1)
getClassCastStrategy (): ClassCastStrategy 100% (1/1)100% (2/2)100% (1/1)
getReferenceStrategy (): ReferenceStrategy 100% (1/1)100% (2/2)100% (1/1)
getSymbolSpec (): Symbol 100% (1/1)100% (2/2)100% (1/1)
init (): void 100% (1/1)100% (11/11)100% (3/3)
readEntries (KeyValueReader, Object): void 100% (1/1)100% (11/11)100% (4/4)
readEntry (KeyValueReader, Map): boolean 100% (1/1)100% (27/27)100% (8/8)
readPartitions (ListReader, Object): void 100% (1/1)100% (6/6)100% (2/2)
writeEntries (KeyValueWriter, Object): void 100% (1/1)100% (26/26)100% (5/5)
writePartitions (ListWriter, Object): void 100% (1/1)100% (5/5)100% (2/2)

1/*
2 * This file is part of JON.
3 *
4 * JON is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * JON is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 * 
17 * Copyright 2007 Michael Doberenz
18 */
19package org.fuwjax.jon.type;
20 
21import java.util.Map;
22 
23import org.fuwjax.jon.ClassCastStrategy;
24import org.fuwjax.jon.IndirectType;
25import org.fuwjax.jon.ObjectAccessException;
26import org.fuwjax.jon.Reference;
27import org.fuwjax.jon.ReferenceStrategy;
28import org.fuwjax.jon.SerialFormatException;
29import org.fuwjax.jon.accessor.EntriesAccessor;
30import org.fuwjax.jon.accessor.KeyValueReader;
31import org.fuwjax.jon.accessor.KeyValueWriter;
32import org.fuwjax.jon.accessor.ListReader;
33import org.fuwjax.jon.accessor.ListWriter;
34import org.fuwjax.jon.accessor.ObjectAccessor;
35import org.fuwjax.jon.accessor.Symbol;
36 
37/**
38 * An abstraction over {@link Map} subclasses.
39 * @author michaeldoberenz
40 */
41public class MapType extends AbstractIndirectType implements EntriesAccessor, ObjectAccessor{
42        private IndirectType keyType;
43        private IndirectType valueType;
44 
45        /**
46         * Creates a new instance.
47         * @param cls the {@link Map} subtype
48         */
49        public MapType(final Class<?> cls){
50                super(cls);
51        }
52 
53        @Override
54        protected void init(){
55                keyType = getIndirectType(null);
56                valueType = getIndirectType(null);
57        }
58 
59        public ClassCastStrategy getClassCastStrategy(){
60                return ClassCastStrategy.AlwaysCast;
61        }
62 
63        public ReferenceStrategy getReferenceStrategy(){
64                return ReferenceStrategy.AssignedReference;
65        }
66 
67        public Symbol getSymbolSpec(){
68                return Symbol.Object;
69        }
70 
71        public void writeEntries(final KeyValueWriter writer, final Object container) throws ObjectAccessException,
72              SerialFormatException{
73                for(Map.Entry<?, ?> entry: ((Map<?, ?>)container).entrySet()){
74                        writer.writeKey(entry.getKey(), keyType);
75                        writer.writeValue(entry.getValue(), valueType);
76                }
77        }
78 
79        public void writePartitions(final ListWriter writer, final Object object) throws ObjectAccessException,
80              SerialFormatException{
81                writer.write(object, this);
82        }
83 
84        public Object createContainer(final Object object) throws ObjectAccessException{
85                if(object != null){
86                        ((Map<?, ?>)object).clear();
87                        return object;
88                }
89                return NaiveInstantiator.create(getType());
90        }
91 
92        public Object createInstance(final Object container, final Object object){
93                return container;
94        }
95 
96        public void readPartitions(final ListReader reader, final Object container) throws ObjectAccessException,
97              SerialFormatException{
98                reader.read(container, this);
99        }
100 
101        /* SW unchecked from generic collection cast */
102        @SuppressWarnings("unchecked")
103        public void readEntries(final KeyValueReader reader, final Object container) throws ObjectAccessException,
104              SerialFormatException{
105                final Map<Object, Object> map = (Map<Object, Object>)container;
106                boolean entryFound;
107                do{
108                        entryFound = readEntry(reader, map);
109                }while(entryFound);
110        }
111 
112        private boolean readEntry(final KeyValueReader reader, final Map<Object, Object> map) throws ObjectAccessException,
113              SerialFormatException{
114                final int pos = reader.getPosition();
115                try{
116                        final Object key = reader.readKey(null, keyType);
117                        final Object value = reader.readValue(null, valueType);
118                        Reference.putTo(map, key, value);
119                        return true;
120                }catch(SerialFormatException e){
121                        e.assertPosition(pos);
122                        return false;
123                }
124        }
125}

[all classes][org.fuwjax.jon.type]
EMMA 2.0.5312 (C) Vladimir Roubtsov