Debian Codegraph @

src/test/java/org/fest/reflect/Jedi.java

raw
1 /*
2 * Created on May 18, 2007
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
5 * License. You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS"
10 * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language
11 * governing permissions and limitations under the License.
12 *
13 * Copyright @2007-2009 the original author or authors.
14 */
15 package org.fest.reflect;
16
17 import java.util.ArrayList;
18 import java.util.List;
19
20 /**
21 * Understands a Jedi.
22 *
23 * @author Alex Ruiz
24 */
25 public class Jedi extends Person {
26
27 private static List<String> commonPowers = new ArrayList<String>();
28
29 private final List<String> powers = new ArrayList<String>();
30 private boolean master;
31
32 public Jedi(String name) {
33 super(name);
34 }
35
36 public void addPower(String power) {
37 powers.add(power);
38 }
39
40 public String powerAt(int index) {
41 return powers.get(index);
42 }
43
44 public int powerCount() {
45 return powers.size();
46 }
47
48 public void clearPowers() {
49 powers.clear();
50 }
51
52 public void makeMaster() {
53 master = true;
54 }
55
56 public List<String> powers() {
57 return getPowers();
58 }
59
60 public List<String> getPowers() {
61 return new ArrayList<String>(powers);
62 }
63
64 public void setPowers(List<String> newPowers) {
65 powers.clear();
66 powers.addAll(newPowers);
67 }
68
69 public List<String> powersThatStartWith(String prefix) {
70 List<String> sub = new ArrayList<String>();
71 for (String power : powers)
72 if (power != null && power.startsWith(prefix)) sub.add(power);
73 return sub;
74 }
75
76 public boolean isMaster() {
77 return master;
78 }
79
80 public void throwRuntimeException() {
81 throw new IllegalStateException("Somehow I got in an illegal state");
82 }
83
84 public void throwCheckedException() throws Exception {
85 throw new Exception("I don't know what's wrong");
86 }
87
88 public static void addCommonPower(String power) {
89 commonPowers.add(power);
90 }
91
92 public static String commonPowerAt(int index) {
93 return commonPowers.get(index);
94 }
95
96 public static int commonPowerCount() {
97 return commonPowers.size();
98 }
99
100 public static void clearCommonPowers() {
101 commonPowers.clear();
102 }
103
104 public static List<String> commonPowers() {
105 return new ArrayList<String>(commonPowers);
106 }
107
108 public static List<String> commonPowersThatStartWith(String prefix) {
109 List<String> sub = new ArrayList<String>();
110 for (String power : commonPowers)
111 if (power != null && power.startsWith(prefix)) sub.add(power);
112 return sub;
113 }
114 }