Clover coverage report - Ledge Components - SNAPSHOT
Coverage timestamp: Fri Nov 17 2006 05:13:20 CET
file stats: LOC: 728   Methods: 58
NCLOC: 441   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
CompoundParameters.java 0% 0% 0% 0%
coverage
 1    //
 2    //Copyright (c) 2003, Caltha - Gajda, Krzewski, Mach, Potempski Sp.J.
 3    //All rights reserved.
 4    //
 5    //Redistribution and use in source and binary forms, with or without modification,
 6    //are permitted provided that the following conditions are met:
 7    //
 8    //* Redistributions of source code must retain the above copyright notice,
 9    //this list of conditions and the following disclaimer.
 10    //* Redistributions in binary form must reproduce the above copyright notice,
 11    //this list of conditions and the following disclaimer in the documentation
 12    //and/or other materials provided with the distribution.
 13    //* Neither the name of the Caltha - Gajda, Krzewski, Mach, Potempski Sp.J.
 14    //nor the names of its contributors may be used to endorse or promote products
 15    //derived from this software without specific prior written permission.
 16    //
 17    //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 18    //AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 19    //WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 20    //IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 21    //INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 22    //BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
 23    //OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 24    //WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 25    //ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 26    //POSSIBILITY OF SUCH DAMAGE.
 27    //
 28   
 29    package org.objectledge.parameters;
 30   
 31    import java.util.ArrayList;
 32    import java.util.Arrays;
 33    import java.util.Date;
 34    import java.util.Iterator;
 35    import java.util.List;
 36    import java.util.Set;
 37    import java.util.SortedSet;
 38    import java.util.TreeSet;
 39   
 40    /**
 41    * A compound implementation of parameters.
 42    *
 43    * @author <a href="mailto:pablo@caltha.com">Pawel Potempski</a>
 44    * @author <a href="mailto:rafal@caltha.com">Rafal Krzewski</a>
 45    * @version $Id: CompoundParameters.java,v 1.8 2006/01/12 15:51:01 rafal Exp $
 46    */
 47    public class CompoundParameters implements Parameters
 48    {
 49    /** The underylying containers. */
 50    private List<Parameters> containers;
 51   
 52    /**
 53    * Constructs a copound parameter container.
 54    *
 55    * <p>The contatiners with lesser indexes will have precedence over the
 56    * conainer with greater indexes.</p>
 57    *
 58    * @param containers the containers.
 59    */
 60  0 public CompoundParameters(Parameters... containers)
 61    {
 62  0 this.containers = Arrays.asList(containers);
 63    }
 64   
 65    /**
 66    * Constructs a copound parameter container.
 67    *
 68    * <p>The contatiners with lesser indexes will have precenence over the
 69    * conainer with greater indexes.</p>
 70    *
 71    * @param list the containers.
 72    */
 73  0 public CompoundParameters(List<Parameters> list)
 74    {
 75  0 containers = list;
 76  0 Iterator i = list.iterator();
 77  0 while(i.hasNext())
 78    {
 79  0 Object obj = i.next();
 80  0 if(!(obj instanceof Parameters))
 81    {
 82  0 throw new ClassCastException(obj.getClass().getName());
 83    }
 84    }
 85    }
 86   
 87   
 88    /**
 89    * {@inheritDoc}
 90    */
 91  0 public boolean isDefined(String name)
 92    {
 93  0 Iterator i = containers.iterator();
 94  0 while(i.hasNext())
 95    {
 96  0 Parameters c = (Parameters)i.next();
 97  0 if(c.isDefined(name))
 98    {
 99  0 return true;
 100    }
 101    }
 102  0 return false;
 103    }
 104   
 105    /**
 106    * {@inheritDoc}
 107    */
 108  0 public String[] getParameterNames()
 109    {
 110  0 SortedSet<String> keys = new TreeSet<String>();
 111  0 Iterator i = containers.iterator();
 112  0 while(i.hasNext())
 113    {
 114  0 Parameters c = (Parameters)i.next();
 115  0 keys.addAll(Arrays.asList(c.getParameterNames()));
 116    }
 117  0 String[] result = new String[keys.size()];
 118  0 keys.toArray(result);
 119  0 return result;
 120    }
 121   
 122    /**
 123    * {@inheritDoc}
 124    */
 125  0 public String get(String name)
 126    {
 127  0 Iterator i = containers.iterator();
 128  0 while(i.hasNext())
 129    {
 130  0 Parameters c = (Parameters)i.next();
 131  0 if(c.isDefined(name))
 132    {
 133  0 return c.get(name);
 134    }
 135    }
 136  0 throw new UndefinedParameterException("Parameter '" + name + "'is undefined");
 137    }
 138   
 139    /**
 140    * {@inheritDoc}
 141    */
 142  0 public String get(String name, String defaultValue)
 143    {
 144  0 Iterator i = containers.iterator();
 145  0 while(i.hasNext())
 146    {
 147  0 Parameters c = (Parameters)i.next();
 148  0 if(c.isDefined(name))
 149    {
 150  0 return c.get(name);
 151    }
 152    }
 153  0 return defaultValue;
 154    }
 155   
 156    /**
 157    * {@inheritDoc}
 158    */
 159  0 public String[] getStrings(String name)
 160    {
 161  0 Iterator i = containers.iterator();
 162  0 while(i.hasNext())
 163    {
 164  0 Parameters c = (Parameters)i.next();
 165  0 if(c.isDefined(name))
 166    {
 167  0 return c.getStrings(name);
 168    }
 169    }
 170  0 return new String[0];
 171    }
 172   
 173    /**
 174    * {@inheritDoc}
 175    */
 176  0 public boolean getBoolean(String name)
 177    {
 178  0 Iterator i = containers.iterator();
 179  0 while(i.hasNext())
 180    {
 181  0 Parameters c = (Parameters)i.next();
 182  0 if(c.isDefined(name))
 183    {
 184  0 return c.getBoolean(name);
 185    }
 186    }
 187  0 throw new UndefinedParameterException("Parameter '" + name + "'is undefined");
 188    }
 189   
 190    /**
 191    * {@inheritDoc}
 192    */
 193  0 public boolean getBoolean(String name, boolean defaultValue)
 194    {
 195  0 Iterator i = containers.iterator();
 196  0 while(i.hasNext())
 197    {
 198  0 Parameters c = (Parameters)i.next();
 199  0 if(c.isDefined(name))
 200    {
 201  0 return c.getBoolean(name);
 202    }
 203    }
 204  0 return defaultValue;
 205    }
 206   
 207    /**
 208    * {@inheritDoc}
 209    */
 210  0 public boolean[] getBooleans(String name)
 211    {
 212  0 Iterator i = containers.iterator();
 213  0 while(i.hasNext())
 214    {
 215  0 Parameters c = (Parameters)i.next();
 216  0 if(c.isDefined(name))
 217    {
 218  0 return c.getBooleans(name);
 219    }
 220    }
 221  0 return new boolean[0];
 222    }
 223   
 224    /**
 225    * {@inheritDoc}
 226    */
 227  0 public Date getDate(String name)
 228    {
 229  0 Iterator i = containers.iterator();
 230  0 while(i.hasNext())
 231    {
 232  0 Parameters c = (Parameters)i.next();
 233  0 if(c.isDefined(name))
 234    {
 235  0 return c.getDate(name);
 236    }
 237    }
 238  0 throw new UndefinedParameterException("Parameter '" + name + "'is undefined");
 239    }
 240   
 241    /**
 242    * {@inheritDoc}
 243    */
 244  0 public Date getDate(String name, Date defaultValue)
 245    {
 246  0 Iterator i = containers.iterator();
 247  0 while(i.hasNext())
 248    {
 249  0 Parameters c = (Parameters)i.next();
 250  0 if(c.isDefined(name))
 251    {
 252  0 return c.getDate(name, defaultValue);
 253    }
 254    }
 255  0 return defaultValue;
 256    }
 257   
 258    /**
 259    * {@inheritDoc}
 260    */
 261  0 public Date[] getDates(String name)
 262    {
 263  0 Iterator i = containers.iterator();
 264  0 while(i.hasNext())
 265    {
 266  0 Parameters c = (Parameters)i.next();
 267  0 if(c.isDefined(name))
 268    {
 269  0 return c.getDates(name);
 270    }
 271    }
 272  0 return new Date[0];
 273    }
 274   
 275    /**
 276    * {@inheritDoc}
 277    */
 278  0 public int getInt(String name)
 279    {
 280  0 Iterator i = containers.iterator();
 281  0 while(i.hasNext())
 282    {
 283  0 Parameters c = (Parameters)i.next();
 284  0 if(c.isDefined(name))
 285    {
 286  0 return c.getInt(name);
 287    }
 288    }
 289  0 throw new UndefinedParameterException("Parameter '" + name + "'is undefined");
 290    }
 291   
 292    /**
 293    * {@inheritDoc}
 294    */
 295  0 public int getInt(String name, int defaultValue)
 296    {
 297  0 Iterator i = containers.iterator();
 298  0 while(i.hasNext())
 299    {
 300  0 Parameters c = (Parameters)i.next();
 301  0 if(c.isDefined(name))
 302    {
 303  0 return c.getInt(name, defaultValue);
 304    }
 305    }
 306  0 return defaultValue;
 307    }
 308   
 309    /**
 310    * {@inheritDoc}
 311    */
 312  0 public int[] getInts(String name)
 313    {
 314  0 Iterator i = containers.iterator();
 315  0 while(i.hasNext())
 316    {
 317  0 Parameters c = (Parameters)i.next();
 318  0 if(c.isDefined(name))
 319    {
 320  0 return c.getInts(name);
 321    }
 322    }
 323  0 return new int[0];
 324    }
 325   
 326    /**
 327    * {@inheritDoc}
 328    */
 329  0 public long getLong(String name)
 330    {
 331  0 Iterator i = containers.iterator();
 332  0 while(i.hasNext())
 333    {
 334  0 Parameters c = (Parameters)i.next();
 335  0 if(c.isDefined(name))
 336    {
 337  0 return c.getLong(name);
 338    }
 339    }
 340  0 throw new UndefinedParameterException("Parameter '" + name + "'is undefined");
 341    }
 342   
 343    /**
 344    * {@inheritDoc}
 345    */
 346  0 public long getLong(String name, long defaultValue)
 347    {
 348  0 Iterator i = containers.iterator();
 349  0 while(i.hasNext())
 350    {
 351  0 Parameters c = (Parameters)i.next();
 352  0 if(c.isDefined(name))
 353    {
 354  0 return c.getLong(name, defaultValue);
 355    }
 356    }
 357  0 return defaultValue;
 358    }
 359   
 360    /**
 361    * {@inheritDoc}
 362    */
 363  0 public long[] getLongs(String name)
 364    {
 365  0 Iterator i = containers.iterator();
 366  0 while(i.hasNext())
 367    {
 368  0 Parameters c = (Parameters)i.next();
 369  0 if(c.isDefined(name))
 370    {
 371  0 return c.getLongs(name);
 372    }
 373    }
 374  0 return new long[0];
 375    }
 376   
 377    /**
 378    * {@inheritDoc}
 379    */
 380  0 public float getFloat(String name)
 381    {
 382  0 Iterator i = containers.iterator();
 383  0 while(i.hasNext())
 384    {
 385  0 Parameters c = (Parameters)i.next();
 386  0 if(c.isDefined(name))
 387    {
 388  0 return c.getFloat(name);
 389    }
 390    }
 391  0 throw new UndefinedParameterException("Parameter '" + name + "'is undefined");
 392    }
 393   
 394    /**
 395    * {@inheritDoc}
 396    */
 397  0 public float getFloat(String name, float defaultValue)
 398    {
 399  0 Iterator i = containers.iterator();
 400  0 while(i.hasNext())
 401    {
 402  0 Parameters c = (Parameters)i.next();
 403  0 if(c.isDefined(name))
 404    {
 405  0 return c.getFloat(name, defaultValue);
 406    }
 407    }
 408  0 return defaultValue;
 409    }
 410   
 411    /**
 412    * {@inheritDoc}
 413    */
 414  0 public float[] getFloats(String name)
 415    {
 416  0 Iterator i = containers.iterator();
 417  0 while(i.hasNext())
 418    {
 419  0 Parameters c = (Parameters)i.next();
 420  0 if(c.isDefined(name))
 421    {
 422  0 return c.getFloats(name);
 423    }
 424    }
 425  0 return new float[0];
 426    }
 427   
 428    /**
 429    * {@inheritDoc}
 430    */
 431  0 public Parameters getChild(String prefix)
 432    {
 433  0 List<Parameters> list = new ArrayList<Parameters>();
 434  0 Iterator i = containers.iterator();
 435  0 while(i.hasNext())
 436    {
 437  0 Parameters c = (Parameters)i.next();
 438  0 list.add(c.getChild(prefix));
 439    }
 440  0 return new CompoundParameters(list);
 441    }
 442   
 443    //// ---------------------------------
 444   
 445    /**
 446    * {@inheritDoc}
 447    */
 448  0 public void remove()
 449    {
 450  0 throw new UnsupportedOperationException();
 451    }
 452   
 453    /**
 454    * {@inheritDoc}
 455    */
 456  0 public void remove(String name)
 457    {
 458  0 throw new UnsupportedOperationException();
 459    }
 460   
 461    /**
 462    * {@inheritDoc}
 463    */
 464  0 public void remove(String name, String value)
 465    {
 466  0 throw new UnsupportedOperationException();
 467    }
 468   
 469    /**
 470    * {@inheritDoc}
 471    */
 472  0 public void remove(String name, Date value)
 473    {
 474  0 throw new UnsupportedOperationException();
 475    }
 476   
 477    /**
 478    * {@inheritDoc}
 479    */
 480  0 public void remove(String name, float value)
 481    {
 482  0 throw new UnsupportedOperationException();
 483    }
 484   
 485    /**
 486