Coverage Report

##### Coverage Report - org.webmacro.util.SelectList

Classes in this File | Line Coverage | Branch Coverage | Complexity
SelectList |
0% | 0/18
0% | 0/8
| 2.0;2

1 |  |
     /*
2 |  |
      * Copyright (C) 1998-2000 Semiotek Inc.  All Rights Reserved.
3 |  |
      *
4 |  |
      * Redistribution and use in source and binary forms, with or without
5 |  |
      * modification, are permitted under the terms of either of the following
6 |  |
      * Open Source licenses:
7 |  |
      *
8 |  |
      * The GNU General Public License, version 2, or any later version, as
9 |  |
      * published by the Free Software Foundation
10 |  |
      * (http://www.fsf.org/copyleft/gpl.html);
11 |  |
      *
12 |  |
      *  or
13 |  |
      *
14 |  |
      * The Semiotek Public License (http://webmacro.org/LICENSE.)
15 |  |
      *
16 |  |
      * This software is provided "as is", with NO WARRANTY, not even the
17 |  |
      * implied warranties of fitness to purpose, or merchantability. You
18 |  |
      * assume all risks and liabilities associated with its use.
19 |  |
      *
20 |  |
      * See www.webmacro.org for more information on the WebMacro project.
21 |  |
      */
22 |  |
23 |  |
24 |  |
     package org.webmacro.util;
25 |  |
26 |  |
     import java.util.Enumeration;
27 |  |
     import java.util.NoSuchElementException;
28 |  |
29 |  |
     /**
30 |  |
      * Selects from a list of things as an enumerator.
31 |  |
      */
32 |  |
     public class SelectList implements Enumeration
33 |  |
     {
34 |  |
35 |  |
         Object[] _values;
36 |  |
         int _current;
37 |  |
         int _selected;
38 |  |
39 |  |
         public SelectList (Object[] elements, int selected)
40 | 0 |
         {
41 | 0 |
             _current = -1;
42 | 0 |
             _selected = selected;
43 | 0 |
             _values = elements;
44 | 0 |
         }
45 |  |
46 |  |
         public boolean hasMoreElements ()
47 |  |
         {
48 | 0 |
             return ((_current + 1) < _values.length);
49 |  |
         }
50 |  |
51 |  |
         public Object nextElement ()
52 |  |
         {
53 | 0 |
             _current++;
54 | 0 |
             if (_current >= _values.length)
55 |  |
             {
56 | 0 |
                 throw new NoSuchElementException("List only has "
57 |  |
                         + _values.length + " elements");
58 |  |
             }
59 | 0 |
             return this;
60 |  |
         }
61 |  |
62 |  |
         public boolean isSelected ()
63 |  |
         {
64 | 0 |
             return (_current == _selected);
65 |  |
         }
66 |  |
67 |  |
         public String getSelected ()
68 |  |
         {
69 | 0 |
             return isSelected() ? "SELECTED" : "";
70 |  |
         }
71 |  |
72 |  |
         public Object getValue ()
73 |  |
         {
74 |  |
             try
75 |  |
             {
76 | 0 |
                 return _values[_current];
77 |  |
             }
78 | 0 |
             catch (Exception e)
79 |  |
             {
80 | 0 |
                 return null;
81 |  |
             }
82 |  |
         }
83 |  |
84 |  |
         public String toString ()
85 |  |
         {
86 |  |
             try
87 |  |
             {
88 | 0 |
                 return _values[_current].toString();
89 |  |
             }
90 | 0 |
             catch (Exception e)
91 |  |
             {
92 | 0 |
                 return null;
93 |  |
             }
94 |  |
         }
95 |  |
96 |  |
     }