View Javadoc

1   /*
2    * This file is a part of CAST project.
3    * (c) Copyright 2007, AGH University of Science & Technology
4    * https://caribou.iisg.agh.edu.pl/trac/cast
5    *
6    * Licensed under the Eclipse Public License, Version 1.0 (the "License").
7    * You may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    * http://www.eclipse.org/legal/epl-v10.html
10   */
11  /*
12   * File: DefaultStatisticsProvider.java
13   * Created: 2007-00-00
14   * Author: apohllo
15   * $Id: DefaultStatisticsProvider.java 2770 2009-04-21 19:17:34Z kpietak $
16   */
17  
18  package pl.edu.agh.cast.model;
19  
20  import java.util.ArrayList;
21  import java.util.List;
22  
23  import org.eclipse.core.runtime.IProgressMonitor;
24  
25  import pl.edu.agh.cast.model.base.IDataProvider;
26  import pl.edu.agh.cast.model.base.IDataSet;
27  import pl.edu.agh.cast.model.base.IEntity;
28  import pl.edu.agh.cast.model.visual.backward.IDiagram;
29  import pl.edu.agh.cast.model.visual.backward.Node;
30  import pl.edu.agh.cast.model.visual.backward.Statistic;
31  import pl.edu.agh.cast.util.Messages;
32  
33  /**
34   * The default implementation of the statistics provider counts only the number of source and target relations, not
35   * taking into account any domain model data associated with them.
36   *
37   * @author AGH CAST Team
38   */
39  public class DefaultStatisticsProvider implements IStatisticsProvider {
40  
41  	private List<Statistic> statistics(IDiagram dataProvider, IProgressMonitor monitor) {
42  		monitor.beginTask(Messages.Diagram_3, dataProvider.getNodes().size());
43  		ArrayList<Statistic> result = new ArrayList<Statistic>();
44  		for (Node node : dataProvider.getNodes()) {
45  			String label = node.getLabel();
46  			result.add(new Statistic(label, node.getTotalSourceConnectionsCount(), node
47  			        .getTotalTargetConnectionsCount()));
48  			monitor.worked(1);
49  		}
50  		monitor.done();
51  		return result;
52  	}
53  
54  	private List<Statistic> statistics(IDataSet dataProvider, IProgressMonitor monitor) {
55  		monitor.beginTask(Messages.DefaultStatisticsProvider_0, 2 * dataProvider.getRelations().size()
56  		        + dataProvider.getEntities().size());
57  		ArrayList<Statistic> result = new ArrayList<Statistic>();
58  		for (IEntity e : dataProvider.getEntities()) {
59  			result.add(new Statistic(e.getId(), e.getSourceRelations().size(), e.getTargetRelations().size()));
60  			monitor.worked(1);
61  		}
62  		monitor.done();
63  		return result;
64  	}
65  
66  	/**
67  	 * {@inheritDoc}
68  	 *
69  	 * @see pl.edu.agh.cast.model.IStatisticsProvider#statistics(pl.edu.agh.cast.model.base.IDataProvider,
70  	 *      org.eclipse.core.runtime.IProgressMonitor)
71  	 */
72  	public List<Statistic> statistics(IDataProvider dataProvider, IProgressMonitor monitor) {
73  		if (dataProvider instanceof IDiagram) {
74  			return statistics((IDiagram)dataProvider, monitor);
75  		} else if (dataProvider instanceof IDataSet) {
76  			return statistics((IDataSet)dataProvider, monitor);
77  		}
78  		return null;
79  	}
80  
81  }