Clover coverage report - brownies library - 1.0-beta-1 Coverage timestamp: 月 8 16 2004 17:14:42 GMT+09:00 FRAMES NO FRAMES |
file stats: | LOC: | 122 |  | Methods: | 15
| NCLOC: | 88 |  | Classes: | 2
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
Source file | Conditionals | Statements | Methods | TOTAL
EnumSet.java | 90% | 91.9% | 86.7% | 90.3% |

1 |  |
     /*
2 |  |
      * Joey and its relative products are published under the terms
3 |  |
      * of the Apache Software License.
4 |  |
      */
5 |  |
     /*
6 |  |
      * Created on 2004/03/01
7 |  |
      */
8 |  |
     package org.asyrinx.brownie.core.lang.enum;
9 |  |
10 |  |
     import java.util.ArrayList;
11 |  |
     import java.util.Collections;
12 |  |
     import java.util.HashSet;
13 |  |
     import java.util.Iterator;
14 |  |
     import java.util.List;
15 |  |
     import java.util.Set;
16 |  |
17 |  |
     import org.apache.commons.collections.Predicate;
18 |  |
     import org.apache.commons.lang.enum.Enum;
19 |  |
     import org.apache.commons.lang.enum.EnumUtils;
20 |  |
21 |  |
     /**
22 |  |
      * @author akima
23 |  |
      */
24 |  |
     public class EnumSet {
25 |  |
26 |  |
         /**
27 |  |
          *
28 |  |
          */
29 | 1 |
         public EnumSet(Class enumClass) {
30 | 1 |
             super();
31 | 1 |
             this.enumClass = enumClass;
32 | 1 |
             this.entries = createEntries();
33 |  |
         }
34 |  |
35 |  |
         protected final Class enumClass;
36 |  |
37 |  |
         protected final List entries;
38 |  |
39 | 1 |
         protected List createEntries() {
40 | 1 |
             final List enums = EnumUtils.getEnumList(this.enumClass);
41 | 1 |
             final List result = new ArrayList(enums.size());
42 | 1 |
             final Iterator iterator = enums.iterator();
43 | 1 |
             while (iterator.hasNext()) {
44 | 4 |
                 final Enum enum = (ValuedEnum) iterator.next();
45 | 4 |
                 result.add(toEntry(enum));
46 |  |
             }
47 | 1 |
             return Collections.unmodifiableList(result);
48 |  |
         }
49 |  |
50 | 0 |
         protected EnumSetEntry toEntry(Enum enum) {
51 | 0 |
             return new EnumSetEntry(enum);
52 |  |
         }
53 |  |
54 | 3 |
         public Set getSelectedEnums() {
55 | 3 |
             return toEnumSet(new SelectedPredicate(true));
56 |  |
         }
57 |  |
58 | 0 |
         public Set getUnselectedEnums() {
59 | 0 |
             return toEnumSet(new SelectedPredicate(false));
60 |  |
         }
61 |  |
62 |  |
         protected static class SelectedPredicate implements Predicate {
63 | 6 |
             public SelectedPredicate(boolean selected) {
64 | 6 |
                 this.selected = selected;
65 |  |
             }
66 |  |
67 |  |
             final boolean selected;
68 |  |
69 | 24 |
             public boolean evaluate(Object input) {
70 | 24 |
                 final EnumSetEntry entry = (EnumSetEntry) input;
71 | 24 |
                 return entry.isSelected() == selected;
72 |  |
             }
73 |  |
         }
74 |  |
75 | 3 |
         protected final Set toEnumSet(Predicate predicate) {
76 | 3 |
             final Set result = new HashSet();
77 | 3 |
             final Iterator iterator = this.iterator();
78 | 3 |
             while (iterator.hasNext()) {
79 | 12 |
                 final EnumSetEntry entry = (EnumSetEntry) iterator.next();
80 | 12 |
                 if (predicate.evaluate(entry))
81 | 3 |
                     result.add(entry.getEnum());
82 |  |
             }
83 | 3 |
             return result;
84 |  |
         }
85 |  |
86 | 11 |
         protected final EnumSetEntry findEntry(Predicate predicate) {
87 | 11 |
             final Iterator iterator = this.iterator();
88 | 26 |
             while (iterator.hasNext()) {
89 | 26 |
                 final EnumSetEntry entry = (EnumSetEntry) iterator.next();
90 | 26 |
                 if (predicate.evaluate(entry))
91 | 11 |
                     return entry;
92 |  |
             }
93 | 0 |
             return null;
94 |  |
         }
95 |  |
96 | 4 |
         public EnumSetEntry getEntryByName(final String enumName) {
97 | 4 |
             return findEntry(new Predicate() {
98 | 10 |
                 public boolean evaluate(Object input) {
99 | 10 |
                     final EnumSetEntry entry = (EnumSetEntry) input;
100 | 10 |
                     return enumName.equals(entry.getName());
101 |  |
                 }
102 |  |
             });
103 |  |
         }
104 |  |
105 | 3 |
         public EnumSetEntry getEntry(final Enum enum) {
106 | 3 |
             return findEntry(new Predicate() {
107 | 6 |
                 public boolean evaluate(Object input) {
108 | 6 |
                     final EnumSetEntry entry = (EnumSetEntry) input;
109 | 6 |
                     return enum == entry.getEnum();
110 |  |
                 }
111 |  |
             });
112 |  |
         }
113 |  |
114 | 1 |
         public int size() {
115 | 1 |
             return entries.size();
116 |  |
         }
117 |  |
118 | 17 |
         public Iterator iterator() {
119 | 17 |
             return entries.iterator();
120 |  |
         }
121 |  |
122 |  |
     }