EMMA Coverage Report (generated Wed Feb 13 07:49:24 ICT 2008)
[all classes][net.sourceforge.hiveboard.view]

COVERAGE SUMMARY FOR SOURCE FILE [AccountListModel.java]

nameclass, %method, %block, %line, %
AccountListModel.java100% (6/6)100% (15/15)97%  (222/230)96%  (44/46)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class AccountListModel$AccountComparator100% (1/1)100% (3/3)73%  (16/22)80%  (4/5)
compare (Account, Account): int 100% (1/1)62%  (10/16)75%  (3/4)
AccountListModel$AccountComparator (): void 100% (1/1)100% (3/3)100% (1/1)
AccountListModel$AccountComparator (AccountListModel$1): void 100% (1/1)100% (3/3)100% (1/1)
     
class AccountListModel100% (1/1)100% (4/4)99%  (144/146)96%  (27/28)
findAccount (int): int 100% (1/1)91%  (21/23)86%  (6/7)
AccountListModel (AccountRepository, Channel): void 100% (1/1)100% (114/114)100% (20/20)
access$100 (AccountListModel, int): int 100% (1/1)100% (4/4)100% (1/1)
access$200 (AccountListModel, int, int): void 100% (1/1)100% (5/5)100% (1/1)
     
class AccountListModel$1100% (1/1)100% (2/2)100% (12/12)100% (3/3)
AccountListModel$1 (AccountListModel): void 100% (1/1)100% (6/6)100% (1/1)
pushEvent (Event): void 100% (1/1)100% (6/6)100% (2/2)
     
class AccountListModel$2100% (1/1)100% (2/2)100% (17/17)100% (3/3)
AccountListModel$2 (AccountListModel): void 100% (1/1)100% (6/6)100% (1/1)
pushEvent (Event): void 100% (1/1)100% (11/11)100% (2/2)
     
class AccountListModel$3100% (1/1)100% (2/2)100% (18/18)100% (4/4)
AccountListModel$3 (AccountListModel): void 100% (1/1)100% (6/6)100% (1/1)
pushEvent (Event): void 100% (1/1)100% (12/12)100% (3/3)
     
class AccountListModel$4100% (1/1)100% (2/2)100% (15/15)100% (3/3)
AccountListModel$4 (AccountListModel): void 100% (1/1)100% (6/6)100% (1/1)
pushEvent (Event): void 100% (1/1)100% (9/9)100% (2/2)

1//  Copyright 2004-2007 Jean-Francois Poilpret
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14 
15package net.sourceforge.hiveboard.view;
16 
17import java.util.Comparator;
18 
19import net.sourceforge.hiveboard.Account;
20import net.sourceforge.hiveboard.Event;
21import net.sourceforge.hiveboard.EventType;
22import net.sourceforge.hiveboard.event.ConstraintEventFilter;
23import net.sourceforge.hiveboard.event.Constraints;
24import net.sourceforge.hiveboard.event.EventsPriorities;
25import net.sourceforge.hiveboard.event.PersistentDeferredConsumer;
26import net.sourceforge.hiveboard.model.AccountRepository;
27import net.sourceforge.hiveevents.Channel;
28import net.sourceforge.hiveevents.Filter;
29import net.sourceforge.hivegui.table.DefaultDataListModel;
30 
31public class AccountListModel extends DefaultDataListModel<Account>
32{
33        public AccountListModel(AccountRepository repository, Channel<Event> eventChannel)
34        {
35                super(Account.class, new AccountComparator());
36                setRows(repository.getAccounts());
37 
38                // Add events listeners
39                int priority = EventsPriorities.ACCOUNT_LIST_UPDATE;
40                String constraint;
41                constraint = Constraints.eventType(EventType.EVT_CREATE_ACCOUNT);
42                Filter<Event> filter = new ConstraintEventFilter(constraint);
43                PersistentDeferredConsumer consumer = new PersistentDeferredConsumer()
44                {
45                        @Override protected void pushEvent(Event event)
46                        {
47                                addRow(event.getAccount());
48                        }
49                };
50                eventChannel.registerPushConsumer(priority, filter, consumer);
51 
52                constraint = Constraints.eventType(EventType.EVT_MODIFY_ACCOUNT);
53                filter = new ConstraintEventFilter(constraint);
54                consumer = new PersistentDeferredConsumer()
55                {
56                        @Override protected void pushEvent(Event event)
57                        {
58                                setRow(findAccount(event.getWho()), event.getAccount());
59                        }
60                };
61                eventChannel.registerPushConsumer(priority, filter, consumer);
62 
63                constraint = Constraints.eventType(EventType.EVT_LOGIN, EventType.EVT_LOGOUT);
64                filter = new ConstraintEventFilter(constraint);
65                consumer = new PersistentDeferredConsumer()
66                {
67                        @Override protected void pushEvent(Event event)
68                        {
69                                int index = findAccount(event.getWho());
70                                fireRowsModified(index, index);
71                        }
72                };
73                eventChannel.registerPushConsumer(priority, filter, consumer);
74 
75                constraint = Constraints.eventType(EventType.EVT_DESTROY_ACCOUNT);
76                filter = new ConstraintEventFilter(constraint);
77                consumer = new PersistentDeferredConsumer()
78                {
79                        @Override protected void pushEvent(Event event)
80                        {
81                                removeRow(findAccount(event.getWho()));
82                        }
83                };
84                eventChannel.registerPushConsumer(priority, filter, consumer);
85        }
86        
87        private int        findAccount(int id)
88        {
89                int index = 0;
90                for (Account account: _items)
91                {
92                        if (account.getId() == id)
93                        {
94                                return index;
95                        }
96                        index++;
97                }
98                return -1;
99        }
100        
101        static private class AccountComparator implements Comparator<Account>
102        {
103                public int        compare(Account a1, Account a2)
104                {
105                        int diff = a1.getVisa().compareTo(a2.getVisa());
106                        if (diff != 0)
107                        {
108                                return diff;
109                        }
110                        return a1.getId() - a2.getId();
111                }
112        }
113}

[all classes][net.sourceforge.hiveboard.view]
EMMA 2.0.5312 (C) Vladimir Roubtsov