| 1 | | (1) | |
| 2 | | | |
| 3 | | | |
| 4 | | | |
| 5 | | | |
| 6 | | | |
| 7 | | | |
| 8 | | | |
| 9 | | | |
| 10 | | | |
| 11 | | | |
| 12 | | | |
| 13 | | | |
| 14 | | | |
| 15 | | | |
| 16 | | | |
| 17 | | | |
| 18 | | | |
| 19 | | | |
| 20 | | | |
| 21 | | | |
| 22 | | | |
| 23 | | | |
| 24 | | | |
| 25 | | | |
| 26 | | | |
| 27 | | | |
| 28 | | | |
| 29 | | | |
| 30 | | | |
| 31 | | | |
| 32 | | | |
| 33 | | | |
| 34 | | | |
| 35 | | | package org.jcoderz.guidelines.snippets; |
| 36 | | | |
| 37 | | | |
| 38 | | | |
| 39 | | | import java.io.IOException; |
| 40 | | | import java.io.Serializable; |
| 41 | | | |
| 42 | | (2) | import java.util.ArrayList; |
| 43 | | (3) | import java.util.List; |
| 44 | | (4) | import java.util.EventObject; |
| 45 | | | |
| 46 | | | |
| 47 | | (5) | import java.util.*; |
| 48 | | | |
| 49 | | | import java.util.logging.Logger; |
| 50 | | | |
| 51 | | | |
| 52 | | | import javax.naming.Context; |
| 53 | | | import javax.servlet.http.HttpServletResponse; |
| 54 | | | |
| 55 | | | |
| 56 | | | |
| 57 | | | |
| 58 | | | |
| 59 | | | @author |
| 60 | | | |
| 61 | | (6) | public class SampleSnippets |
| 62 | | | implements Serializable |
| 63 | | | { |
| 64 | | | private static final int DEFAULT_SIZE = 30; |
| 65 | | | private static final int SIZE = 30; |
| 66 | | | |
| 67 | | | |
| 68 | | | private SampleSnippets () |
| 69 | 0 | | { |
| 70 | | | |
| 71 | 0 | | } |
| 72 | | | |
| 73 | | | |
| 74 | | | |
| 75 | | | |
| 76 | | | @author |
| 77 | | | @author |
| 78 | | | |
| 79 | 0 | (7) | public class ExampleClass |
| 80 | | | { |
| 81 | | | |
| 82 | | | } |
| 83 | | | |
| 84 | | | |
| 85 | | (8)(9) | private static int funtionCallReturn () |
| 86 | | | { |
| 87 | 0 | (10) | final java.util.ArrayList list = new java.util.ArrayList(); |
| 88 | 0 | (11) | int size = list.size(); |
| 89 | | | |
| 90 | 0 | | if (size > 0) |
| 91 | | | { |
| 92 | | | |
| 93 | 0 | | return list.size(); |
| 94 | | | |
| 95 | | | } |
| 96 | | | else |
| 97 | | | { |
| 98 | | | |
| 99 | | | |
| 100 | 0 | | return (size != 0 ? size : DEFAULT_SIZE); |
| 101 | | | |
| 102 | | | } |
| 103 | | | } |
| 104 | | | |
| 105 | | (12)(13)(14)(15) | private static void statements () |
| 106 | | | { |
| 107 | 0 | | int i = 0; |
| 108 | | | |
| 109 | | | |
| 110 | 0 | (16) | if (i > 0) |
| 111 | | | { |
| 112 | | | |
| 113 | | | } |
| 114 | | | |
| 115 | 0 | | if (i > 0) |
| 116 | | | { |
| 117 | | | |
| 118 | | | } |
| 119 | | | else |
| 120 | | | { |
| 121 | | | |
| 122 | | | } |
| 123 | | | |
| 124 | 0 | | if (i > 0) |
| 125 | | | { |
| 126 | | | |
| 127 | | | } |
| 128 | 0 | | else if (i == 0) |
| 129 | | | { |
| 130 | | | |
| 131 | | | } |
| 132 | | | else |
| 133 | | | { |
| 134 | | | |
| 135 | | | } |
| 136 | | | |
| 137 | | | |
| 138 | | | |
| 139 | 0 | | for (int j = 0; j < SIZE; j++) |
| 140 | | | { |
| 141 | | | |
| 142 | | | } |
| 143 | | | |
| 144 | | | |
| 145 | | | |
| 146 | 0 | (17) | while (i > 0) |
| 147 | | | { |
| 148 | | | |
| 149 | | | } |
| 150 | | | |
| 151 | | | |
| 152 | | (18) | |
| 153 | | | |
| 154 | 0 | (19)(20) | while (--i > 0); |
| 155 | | | |
| 156 | | | |
| 157 | | | |
| 158 | | | do |
| 159 | | | { |
| 160 | | | |
| 161 | | | } |
| 162 | 0 | (21) | while (i > 0); |
| 163 | | | |
| 164 | | | |
| 165 | | | |
| 166 | 0 | | switch (i) |
| 167 | | | { |
| 168 | | | case HttpServletResponse.SC_ACCEPTED: |
| 169 | | | |
| 170 | | | |
| 171 | | | case HttpServletResponse.SC_BAD_REQUEST: |
| 172 | | | |
| 173 | 0 | (22) | break; |
| 174 | | | case HttpServletResponse.SC_CONTINUE: |
| 175 | | | |
| 176 | 0 | | break; |
| 177 | | | default: |
| 178 | 0 | | throw new RuntimeException("Unexpected condition."); |
| 179 | | | |
| 180 | | | } |
| 181 | | | |
| 182 | | | |
| 183 | | | |
| 184 | | | try |
| 185 | | | { |
| 186 | | | |
| 187 | | | } |
| 188 | | | catch (IllegalArgumentException ex) |
| 189 | | | { |
| 190 | | | |
| 191 | 0 | | } |
| 192 | | | |
| 193 | | | try |
| 194 | | | { |
| 195 | | | |
| 196 | | | } |
| 197 | | | catch (IllegalArgumentException ex) |
| 198 | | | { |
| 199 | | | |
| 200 | | | } |
| 201 | | | finally |
| 202 | 0 | | { |
| 203 | | | |
| 204 | 0 | | } |
| 205 | | | |
| 206 | | | try |
| 207 | | | { |
| 208 | | | |
| 209 | | | } |
| 210 | | | finally |
| 211 | 0 | | { |
| 212 | | | |
| 213 | 0 | | } |
| 214 | | | |
| 215 | 0 | | } |
| 216 | | | |
| 217 | | | private static boolean aMethod (byte a, Object b) |
| 218 | | | { |
| 219 | 0 | | return true; |
| 220 | | | } |
| 221 | | | |
| 222 | | | |
| 223 | | | private static void anotherMethod (int a, int b) |
| 224 | | | { |
| 225 | | | |
| 226 | 0 | | } |
| 227 | | | |
| 228 | | | |
| 229 | | (23) | private static void whitespace () |
| 230 | | | { |
| 231 | 0 | (24) | int a = 0; |
| 232 | 0 | | int b = 1; |
| 233 | 0 | (25) | int c = -1; |
| 234 | | | |
| 235 | 0 | | int d = 1; |
| 236 | 0 | | b = (a + b) / (c * ++d); |
| 237 | 0 | (26) | System.out.println("c=" + c + "\n"); |
| 238 | | | |
| 239 | | | |
| 240 | 0 | | final Integer x = new Integer(b); |
| 241 | | | |
| 242 | 0 | (27) | final boolean result = aMethod((byte) a, (Object) x); |
| 243 | 0 | (28)(29) | anotherMethod((int) (a + 1), ((int) (b + MAX_LOOPS)) + 1); |
| 244 | | | |
| 245 | 0 | | } |
| 246 | | | |
| 247 | | | |
| 248 | | (30)(31) | static final int MIN_WIDTH = 4; |
| 249 | | (32)(33) | static final int MAX_WIDTH = 999; |
| 250 | | (34)(35) | static final int GET_THE_CPU = 1; |
| 251 | | (36)(37) | static final long serialVersionUID = -7064645359225861305L; |
| 252 | 0 | (38)(39) | static final Logger logger |
| 253 | | | = Logger.getLogger(SampleSnippets.class.getName()); |
| 254 | | | |
| 255 | | | |
| 256 | | (40) | private static void naming () |
| 257 | | | { |
| 258 | | | |
| 259 | | (41) | int i; |
| 260 | | (42) | char c; |
| 261 | | (43) | float myWidth; |
| 262 | | | |
| 263 | 0 | | } |
| 264 | | | |
| 265 | | | |
| 266 | | | void yetAnotherMethod () |
| 267 | | | { |
| 268 | 0 | (44) | int int1 = 0; |
| 269 | | | |
| 270 | 0 | | if (int1 == 0) |
| 271 | | | { |
| 272 | 0 | (45) | int int2 = 0; |
| 273 | | | |
| 274 | | | |
| 275 | | | } |
| 276 | 0 | | } |
| 277 | | | |
| 278 | | | |
| 279 | | (46) | private static final int MAX_LOOPS = 100; |
| 280 | | | |
| 281 | | (47) | private static void practices () |
| 282 | | | { |
| 283 | | | |
| 284 | 0 | | for (int i = 0; i < MAX_LOOPS; i++) |
| 285 | | | { |
| 286 | | | |
| 287 | | | } |
| 288 | | | |
| 289 | 0 | | } |
| 290 | | | |
| 291 | | | |
| 292 | | (48)(49)(50)(51) | int count; |
| 293 | | | |
| 294 | | | void counter () |
| 295 | | | { |
| 296 | 0 | (52)(53) | if (count > 0) |
| 297 | | | { |
| 298 | | (54)(55) | int count; |
| 299 | | | |
| 300 | | | |
| 301 | | | } |
| 302 | | | |
| 303 | | | |
| 304 | 0 | | } |
| 305 | | | |
| 306 | | | |
| 307 | | | |
| 308 | | (56) | public interface ActionListener |
| 309 | | | { |
| 310 | | (57) | void actionPerformed (EventObject event); |
| 311 | | | } |
| 312 | | | |
| 313 | | | |
| 314 | | | |
| 315 | | (58) | public interface Runnable |
| 316 | | | { |
| 317 | | (59) | void run (); |
| 318 | | | } |
| 319 | | | |
| 320 | | (60) | public interface Accessible |
| 321 | | | { |
| 322 | | (61) | Context getContext (); |
| 323 | | | } |
| 324 | | | |
| 325 | | | |
| 326 | | (62)(63)(64) | public static final int MAX_CUSTOMERS = 100; |
| 327 | | | |
| 328 | | | |
| 329 | 0 | (65) | private Object[] mCustomers = new Object[MAX_CUSTOMERS]; |
| 330 | | | |
| 331 | | | void addCustomer (int index, Object customer) |
| 332 | | | { |
| 333 | 0 | | mCustomers[index] = customer; |
| 334 | 0 | | } |
| 335 | | | |
| 336 | | | |
| 337 | | | |
| 338 | 0 | (66)(67)(68)(69)(70)(71)(72) | public class IndentionSample |
| 339 | | | extends SampleSnippets |
| 340 | | | implements Serializable, Cloneable, Comparable |
| 341 | | | { |
| 342 | | | |
| 343 | | | |
| 344 | | | |
| 345 | | (73) | public void doSomething (int length) |
| 346 | | (74) | throws IOException |
| 347 | | | |
| 348 | | | |
| 349 | | | { |
| 350 | 0 | (75) | final List servers = new ArrayList(); |
| 351 | | | |
| 352 | | | |
| 353 | | | |
| 354 | | | |
| 355 | | | |
| 356 | | | |
| 357 | | | |
| 358 | 0 | | } |
| 359 | | | |
| 360 | | | {@inheritDoc} |
| 361 | | | public int compareTo (Object o) |
| 362 | | | { |
| 363 | | (76) | |
| 364 | 0 | (77)(78) | return 0; |
| 365 | | | } |
| 366 | | | } |
| 367 | | | |
| 368 | | | } |