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

COVERAGE SUMMARY FOR SOURCE FILE [ListType.java]

nameclass, %method, %block, %line, %
ListType.java100% (1/1)100% (10/10)100% (88/88)100% (32/32)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ListType100% (1/1)100% (10/10)100% (88/88)100% (32/32)
ListType (Class): void 100% (1/1)100% (4/4)100% (2/2)
addToList (Collection, Object): void 100% (1/1)100% (13/13)100% (5/5)
createContainer (Object): Object 100% (1/1)100% (12/12)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% (6/6)100% (2/2)
readElements (ListReader, Object): void 100% (1/1)100% (28/28)100% (11/11)
writeElements (ListWriter, Object): void 100% (1/1)100% (17/17)100% (4/4)

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.Collection;
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.ListAccessor;
30import org.fuwjax.jon.accessor.ListReader;
31import org.fuwjax.jon.accessor.ListWriter;
32import org.fuwjax.jon.accessor.Symbol;
33 
34/**
35 * An abstraction over {@link Collection} subclasses.
36 * @author michaeldoberenz
37 */
38public class ListType extends AbstractIndirectType implements ListAccessor{
39        private IndirectType component;
40 
41        /**
42         * Creates a new instance.
43         * @param cls the {@link Collection} subtype
44         */
45        public ListType(final Class<?> cls){
46                super(cls);
47        }
48 
49        @Override
50        protected void init(){
51                component = getIndirectType(null);
52        }
53 
54        public ClassCastStrategy getClassCastStrategy(){
55                return ClassCastStrategy.AlwaysCast;
56        }
57 
58        public ReferenceStrategy getReferenceStrategy(){
59                return ReferenceStrategy.AssignedReference;
60        }
61 
62        public Symbol getSymbolSpec(){
63                return Symbol.List;
64        }
65 
66        public void writeElements(final ListWriter writer, final Object container) throws ObjectAccessException,
67              SerialFormatException{
68                for(Object member: (Collection<?>)container){
69                        writer.write(member, component);
70                }
71        }
72 
73        public Object createContainer(final Object object) throws ObjectAccessException{
74                if(object instanceof Collection){
75                        ((Collection<?>)object).clear();
76                        return object;
77                }
78                return NaiveInstantiator.create(getType());
79        }
80 
81        public Object createInstance(final Object container, final Object object){
82                return container;
83        }
84 
85        /* SW unchecked for generic collection cast */
86        @SuppressWarnings("unchecked")
87        public void readElements(final ListReader reader, final Object object) throws ObjectAccessException,
88              SerialFormatException{
89                final Collection<Object> list = (Collection<Object>)object;
90                boolean foundElement = true;
91                do{
92                        final int pos = reader.getPosition();
93                        try{
94                                final Object value = reader.read(null, component);
95                                addToList(list, value);
96                        }catch(SerialFormatException e){
97                                e.assertPosition(pos);
98                                foundElement = false;
99                        }
100                }while(foundElement);
101        }
102 
103        private void addToList(final Collection<Object> list, final Object value) throws ObjectAccessException{
104                if(value instanceof Reference){
105                        ((Reference)value).addTo(list);
106                }else{
107                        list.add(value);
108                }
109        }
110}

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