Clover coverage report - Maven Clover report
Coverage timestamp: Thu Oct 11 2007 08:41:48 CEST
file stats: LOC: 246   Methods: 22
NCLOC: 190   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
DefaultBusinessObject.java 95.8% 98.4% 100% 98.1%
coverage coverage
 1    /*
 2    * Copyright (C) 2007 Eric MIGNOT - mignots.eric@free.fr
 3    *
 4    * This library is free software; you can redistribute it and/or
 5    * modify it under the terms of the GNU Lesser General Public
 6    * License as published by the Free Software Foundation; either
 7    * version 2.1 of the License, or (at your option) any later version.
 8    *
 9    * This library 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 GNU
 12    * Lesser General Public License for more details.
 13    *
 14    * You should have received a copy of the GNU Lesser General Public
 15    * License along with this library; if not, write to the Free Software
 16    * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 17    */
 18    package org.ericmignot.modeler.helpers.data;
 19   
 20    import java.awt.Dimension;
 21    import java.awt.Point;
 22    import java.util.ArrayList;
 23    import java.util.HashMap;
 24    import java.util.List;
 25    import java.util.Map;
 26   
 27    import org.ericmignot.modeler.data.BusinessObject;
 28    import org.ericmignot.modeler.data.BusinessObjectListener;
 29   
 30    public class DefaultBusinessObject implements BusinessObject
 31    {
 32    protected static int NEXT_ID = -1;
 33   
 34    public static final String FIELD_ID = "Id";
 35    public static final String FIELD_X = "X";
 36    public static final String FIELD_Y = "Y";
 37    public static final String FIELD_HALFWIDTH = "HalfWidth";
 38    public static final String FIELD_HALFHEIGHT = "HalfHeight";
 39   
 40    private Map references;
 41   
 42    private long id;
 43    private Point center;
 44    private Dimension halfSize;
 45   
 46    private List listeners;
 47   
 48  639 public DefaultBusinessObject()
 49    {
 50  639 this.references = new HashMap();
 51  639 this.listeners = new ArrayList();
 52  639 this.setId(DefaultBusinessObject.NEXT_ID--);
 53  639 this.setCenter(new Point(0, 0));
 54  639 this.setHalfSize(new Dimension(0, 0));
 55    }
 56   
 57  1 public String[] getFieldNames()
 58    {
 59  1 return new String[]
 60    {
 61    FIELD_ID,
 62    FIELD_X,
 63    FIELD_Y,
 64    FIELD_HALFWIDTH,
 65    FIELD_HALFHEIGHT
 66    };
 67    }
 68   
 69    /**
 70    * Manages Id, X, Y, Width, Height field names
 71    * @param fieldName
 72    * @param fieldValue
 73    * @return true if the field was set, false otherwise
 74    */
 75  392 public boolean setFieldValue(String fieldName, String fieldValue)
 76    {
 77  392 if (FIELD_ID.equalsIgnoreCase(fieldName))
 78    {
 79  77 this.setId(Integer.parseInt(fieldValue));
 80  77 return true;
 81    }
 82  315 if (FIELD_X.equalsIgnoreCase(fieldName))
 83    {
 84  68 this.setCenter(new Point(Integer.parseInt(fieldValue), this.getCenter().y));
 85  68 return true;
 86    }
 87  247 if (FIELD_Y.equalsIgnoreCase(fieldName))
 88    {
 89  68 this.setCenter(new Point(this.getCenter().x, Integer.parseInt(fieldValue)));
 90  68 return true;
 91    }
 92  179 if (FIELD_HALFWIDTH.equalsIgnoreCase(fieldName))
 93    {
 94  17 this.setHalfSize(new Dimension(Integer.parseInt(fieldValue), this.getHalfSize().height));
 95  17 return true;
 96    }
 97  162 if (FIELD_HALFHEIGHT.equalsIgnoreCase(fieldName))
 98    {
 99  17 this.setHalfSize(new Dimension(this.getHalfSize().width, Integer.parseInt(fieldValue)));
 100  17 return true;
 101    }
 102  145 return false;
 103    }
 104   
 105  16 public String getFieldValue(String fieldName)
 106    {
 107  16 if (FIELD_ID.equalsIgnoreCase(fieldName))
 108    {
 109  4 return "" + this.getId();
 110    }
 111  12 if (FIELD_X.equalsIgnoreCase(fieldName))
 112    {
 113  4 return ""+this.getCenter().x;
 114    }
 115  8 if (FIELD_Y.equalsIgnoreCase(fieldName))
 116    {
 117  4 return ""+this.getCenter().y;
 118    }
 119  4 if (FIELD_HALFWIDTH.equalsIgnoreCase(fieldName))
 120    {
 121  2 return ""+this.getHalfSize().width;
 122    }
 123  2 if (FIELD_HALFHEIGHT.equalsIgnoreCase(fieldName))
 124    {
 125  2 return ""+this.getHalfSize().height;
 126    }
 127  0 return null;
 128    }
 129   
 130  3 public void copyFieldValuesFrom(BusinessObject source)
 131    {
 132  3 String[] names = this.getFieldNames();
 133  3 for (int i=0; i<names.length; i++)
 134    {
 135  9 this.setFieldValue(names[i], source.getFieldValue(names[i]));
 136    }
 137    }
 138   
 139    /**
 140    *
 141    * @param referenceName
 142    * @param referenceValue
 143    * @return true if the reference was set, false otherwise
 144    */
 145  775 public boolean setReference(String referenceName, BusinessObject referenceValue)
 146    {
 147  775 this.references.put(referenceName, referenceValue);
 148  775 return true;
 149    }
 150  275 public boolean hasReference(BusinessObject referenceValue)
 151    {
 152  275 return this.references.containsValue(referenceValue);
 153    }
 154  1310 public BusinessObject getReference(String referenceName)
 155    {
 156  1310 return (BusinessObject) this.references.get(referenceName);
 157    }
 158   
 159  10 public List getReferences()
 160    {
 161  10 return new ArrayList(this.references.values());
 162    }
 163   
 164   
 165   
 166  139 public long getId()
 167    {
 168  139 return id;
 169    }
 170  978 public void setId(long id)
 171    {
 172  978 this.id = id;
 173  978 this.fireUpdated();
 174    }
 175   
 176  3404 public Point getCenter()
 177    {
 178  3404 return this.center;
 179    }
 180  77 public void setCenter(int x, int y)
 181    {
 182  77 this.center.setLocation(x, y);
 183  77 this.fireUpdated();
 184    }
 185  968 public void setCenter(Point location)
 186    {
 187  968 this.center = location;
 188  968 this.fireUpdated();
 189    }
 190  4109 public Dimension getHalfSize()
 191    {
 192  4109 return this.halfSize;
 193    }
 194  868 public void setHalfSize(Dimension size)
 195    {
 196  868 this.halfSize = size;
 197  868 this.fireUpdated();
 198    }
 199   
 200  10 public String getXML()
 201    {
 202  10 String toReturn =
 203    "<BusinessObject class='" + this.getClass().getName() +"'>" +
 204    this.getParamsXML() +
 205    this.getReferencesXML() +
 206    "</BusinessObject>";
 207  10 return toReturn;
 208    }
 209   
 210  4 protected String getParamsXML()
 211    {
 212  4 String toReturn =
 213    "<Param Name='Id' Value='" + this.getId() + "' />" +
 214    "<Param Name='X' Value='" + this.getCenter().x + "' />" +
 215    "<Param Name='Y' Value='" + this.getCenter().y + "' />" +
 216    "<Param Name='HalfWidth' Value='" + this.getHalfSize().width + "' />" +
 217    "<Param Name='HalfHeight' Value='" + this.getHalfSize().height + "' />";
 218  4 return toReturn;
 219    }
 220   
 221  5 protected String getReferencesXML()
 222    {
 223  5 return "";
 224    }
 225   
 226  790 public void addListener(BusinessObjectListener listener)
 227    {
 228  790 this.listeners.add(listener);
 229    }
 230  28 public void removeListener(BusinessObjectListener listener)
 231    {
 232  28 this.listeners.remove(listener);
 233    }
 234   
 235  3780 protected void fireUpdated()
 236    {
 237  3780 for (int i = 0; i < this.listeners.size() ; i++)
 238    {
 239  199 ((BusinessObjectListener) this.listeners.get(i)).businessObjectUpdated(this);
 240    }
 241    }
 242   
 243   
 244   
 245   
 246    }