1 16 17 package org.apache.commons.betwixt; 18 19 26 public class LoopBean 27 { 28 private static int count = 0; 29 30 private static final int max_count = 100; 31 32 private LoopBean friend; 33 34 private String name; 35 36 public static final LoopBean createNoLoopExampleBean() 37 { 38 LoopBean root = new LoopBean("Root"); 39 LoopBean levelOne = new LoopBean("level1"); 40 LoopBean levelTwo = new LoopBean("level2"); 41 LoopBean levelThree = new LoopBean("level3"); 42 LoopBean levelFour = new LoopBean("level4"); 43 LoopBean levelFive = new LoopBean("level5"); 44 45 root.setFriend(levelOne); 46 levelOne.setFriend(levelTwo); 47 levelTwo.setFriend(levelThree); 48 levelThree.setFriend(levelFour); 49 levelFour.setFriend(levelFive); 50 51 return root; 52 } 53 54 public static final LoopBean createLoopExampleBean() 55 { 56 LoopBean root = new LoopBean("Root"); 57 LoopBean levelOne = new LoopBean("level1"); 58 LoopBean levelTwo = new LoopBean("level2"); 59 LoopBean levelThree = new LoopBean("level3"); 60 LoopBean levelFour = new LoopBean("level4"); 61 LoopBean levelFive = new LoopBean("level5"); 62 63 root.setFriend(levelOne); 64 levelOne.setFriend(levelTwo); 65 levelTwo.setFriend(levelThree); 66 levelThree.setFriend(levelFour); 67 levelFour.setFriend(levelFive); 68 levelFive.setFriend(root); 69 70 return root; 71 } 72 73 74 public static final LoopBean createNotEmptyNoLoopExampleBean() 75 { 76 LoopBean root = new LoopBean(""); 77 LoopBean levelOne = new LoopBean(""); 78 LoopBean levelTwo = new LoopBean(""); 79 LoopBean levelThree = new LoopBean(""); 80 LoopBean levelFour = new LoopBean(""); 81 LoopBean levelFive = new LoopBean("Not Empty"); 82 83 root.setFriend(levelOne); 84 levelOne.setFriend(levelTwo); 85 levelTwo.setFriend(levelThree); 86 levelThree.setFriend(levelFour); 87 levelFour.setFriend(levelFive); 88 89 return root; 90 } 91 92 public static final LoopBean createEmptyLoopExampleBean() 93 { 94 LoopBean root = new LoopBean(""); 95 LoopBean levelOne = new LoopBean(""); 96 LoopBean levelTwo = new LoopBean(""); 97 LoopBean levelThree = new LoopBean(""); 98 LoopBean levelFour = new LoopBean(""); 99 LoopBean levelFive = new LoopBean(""); 100 101 root.setFriend(levelOne); 102 levelOne.setFriend(levelTwo); 103 levelTwo.setFriend(levelThree); 104 levelThree.setFriend(levelFour); 105 levelFour.setFriend(levelFive); 106 levelFive.setFriend(root); 107 108 return root; 109 } 110 111 public static final LoopBean createIdOnlyLoopExampleBean() 112 { 113 LoopBean root = new LoopBean("Root"); 114 LoopBean levelOne = new LoopBean("level1"); 115 LoopBean levelTwo = new LoopBean("level2"); 116 LoopBean levelThree = new LoopBean("level3"); 117 LoopBean levelFour = new LoopBean("level4"); 118 LoopBean levelFive = new LoopBean("level5"); 119 LoopBean notRoot = new LoopBean("Root"); 120 121 root.setFriend(levelOne); 122 levelOne.setFriend(levelTwo); 123 levelTwo.setFriend(levelThree); 124 levelThree.setFriend(levelFour); 125 levelFour.setFriend(levelFive); 126 levelFive.setFriend(notRoot); 127 128 return root; 129 } 130 131 public LoopBean(String name) 132 { 133 this.name = name; 134 } 135 136 public LoopBean getFriend() 137 { 138 if (++count > max_count) 139 { 140 throw new RuntimeException ("Looping!"); 141 } 142 return friend; 143 } 144 145 public void setFriend(LoopBean friend) 146 { 147 this.friend = friend; 148 } 149 150 public String getName() 151 { 152 return name; 153 } 154 155 public String toString() 156 { 157 return "[LoopBean] name=" + name; 158 } 159 } 160 | Popular Tags |