27
27
import javax .annotation .Nullable ;
28
28
29
29
/**
30
- * <strong>This class shouldn't be used in any public API or library.</strong> It is designed to be used for in-house development
31
- * of end user applications which will report Bugs in standardized error pages or post them to issue tracker.
32
- * <p/>
30
+ * <p>
31
+ * <strong>This class shouldn't be used in any public API or library.</strong> It is designed to be used for in-house
32
+ * development of end user applications which will report Bugs in standardized error pages or post them to issue
33
+ * tracker.
34
+ * <p>
33
35
* Static convenience methods that help a method or constructor check whether it was invoked correctly (whether its
34
- * <i>preconditions</i>
35
- * have been met). These methods generally accept a {@code boolean} expression which is expected to be {@code true} (or in the
36
- * case of {@code
37
- * checkNotNull}, an object reference which is expected to be non-null). When {@code false} (or {@code null}) is passed instead,
38
- * the {@code EidPreconditions} method throws an unchecked exception, which helps the calling method communicate to <i>its</i>
39
- * caller that
40
- * <i>that</i> caller has made a mistake.
41
- * <p/>
42
- * Each method accepts a EID String or {@link Eid} object, which is designed to ease of use and provide strict ID for given
43
- * Exception usage. This approach speed up development of large application and helps support teams to by giving the both static
44
- * and random ID for each possible unpredicted bug.
45
- * <p/>
36
+ * <i>preconditions</i> have been met). These methods generally accept a {@code boolean} expression which is expected
37
+ * to be {@code true} (or in the case of {@link #checkNotNull(Object, String)}, an object reference which is expected
38
+ * to be non-null). When {@code false} (or {@code null}) is passed instead, the {@link EidPreconditions} method throws
39
+ * an unchecked exception, which helps the calling method communicate to <i>its</i> caller <i>that</i> caller has made
40
+ * a mistake.
41
+ * <p>
42
+ * Each method accepts a EID String or {@link Eid} object, which is designed to ease of use and provide strict ID for
43
+ * given Exception usage. This approach speed up development of large application and helps support teams to by giving
44
+ * the both static and random ID for each possible unpredicted bug.
45
+ * <p>
46
46
* This is best to use with tools and plugins like
47
47
* <a href="http://plugins.netbeans.org/plugin/53137/exception-id-eid-generator">EidGenerator for Netbeans IDE</a>
48
- * <p/ >
48
+ * <p>
49
49
* Example:
50
- * <pre> {@code
51
- *
52
- * /**
53
- * * Returns the positive square root of the given value.
54
- * *
55
- * * @throws EidIllegalArgumentException if the value is negative
56
- * *}{@code /
57
- * public static double sqrt(double value) {
58
- * EidPreconditions.checkArgument(value >= 0.0, "20150718:012333");
50
+ * <pre>
51
+ * /**
52
+ * * Returns the positive square root of the given value.
53
+ * *
54
+ * * @throws EidIllegalArgumentException if the value is negative
55
+ * */
56
+ * public static double sqrt(double value) {
57
+ * EidPreconditions.checkArgument(value >= 0.0, "20150718:012333");
59
58
* // calculate the square root
60
- * }
59
+ * }
61
60
*
62
- * void exampleBadCaller() {
61
+ * void exampleBadCaller() {
63
62
* double d = sqrt(-1.0);
64
- * }
65
- * }</pre>
66
- * <p/>
67
- * In this example, {@code checkArgument} throws an {@code EidIllegalArgumentException} to indicate that {@code exampleBadCaller}
68
- * made an error in <i>its</i> call to {@code sqrt}. Exception, when it will be printed will contain user given Eid and also
69
- * Randomly generated ID. Those fields can be displayed to user on error page on posted directly to issue tracker.
70
- * <p/>
63
+ * }
64
+ * </pre>
65
+ * <p>
66
+ * In this example, {@link #checkArgument(boolean, String)} throws an {@link EidIllegalArgumentException} to indicate
67
+ * that {@code exampleBadCaller} made an error in <i>its</i> call to {@code sqrt}. Exception, when it will be printed
68
+ * will contain user given Eid and also randomly generated ID. Those fields can be displayed to user on error page on
69
+ * posted directly to issue tracker.
70
+ * <p>
71
71
* Example:
72
- * <p/>
73
72
* <pre>
74
- *
75
- * {@code
76
- * // Main application class for ex.: http servlet
77
- * try {
78
- * performRequest(request, response);
79
- * } catch (EidRuntimeException ex) {
80
- * issuesTracker.put(ex);
81
- * throw ex;
82
- * }
83
- * }</pre>
84
- * <p/>
85
- * <p/>
73
+ * // Main application class for ex.: http servlet
74
+ * try {
75
+ * performRequest(request, response);
76
+ * } catch (EidRuntimeException ex) {
77
+ * issuesTracker.put(ex);
78
+ * throw ex;
79
+ * }
80
+ * </pre>
86
81
* <h3>Functional try to execute blocks</h3>
87
- * <p/>
88
- * <p/>
89
82
* Using functional blocks to handle operations, that are intended to operate properly, simplify the code and makes it more
90
83
* readable. It's also good way to deal with untested, uncovered {@code catch} blocks. It's easy and gives developers nice way of
91
84
* dealing with countless operations that suppose to work as intended.
92
- * <p/>
93
- * <p/>
85
+ * <p>
94
86
* Example:
95
- * <pre><code>
96
- *
97
- * InputStream is = EidPreconditions.tryToExecute({@code new UnsafeSupplier<InputStream>}() {
98
- * {@literal @}Override
99
- * public InputStream get() throws IOException {
100
- * return this.getClass().getClassLoader()
101
- * .getResourceAsStream("project.properties");
102
- * }
103
- * }, "20150718:121521");
104
- * </code></pre>
87
+ * <pre>
88
+ * InputStream is = EidPreconditions.tryToExecute(new UnsafeSupplier<InputStream>() {
89
+ * @Override
90
+ * public InputStream get() throws IOException {
91
+ * return this.getClass().getClassLoader()
92
+ * .getResourceAsStream("project.properties");
93
+ * }
94
+ * }, "20150718:121521");
95
+ * </pre>
105
96
*
106
97
* @author <a href="mailto:[email protected] ">Krzysztof Suszynski</a>
107
98
* @since 0.1.0 (idea imported from Guava Library and COI code)
@@ -450,18 +441,17 @@ public static void tryToExecute(final UnsafeProcedure procedure, final String ei
450
441
/**
451
442
* Tries to execute code in given unsafe supplier code block, and if exception is thrown, it will gets rethrown as a
452
443
* {@link EidRuntimeException} with eid given as a argument. This is because this exception is threaded as a software bug!
453
- * <p/ >
444
+ * <p>
454
445
* Example:
455
- * <pre><code>
456
- *
457
- * Document doc = EidPreconditions.tryToExecute({@code new UnsafeSupplier<Document>}() {
458
- * {@literal @}Override
446
+ * <pre>
447
+ * Document doc = EidPreconditions.tryToExecute(new UnsafeSupplier<Document>}() {
448
+ * @Override
459
449
* public Document get() throws SAXException, IOException {
460
- * DocumentBuilder docBuilder = ...
461
- * return docBuilder.parse(new InputSource(reader));
450
+ * DocumentBuilder docBuilder = ...
451
+ * return docBuilder.parse(new InputSource(reader));
462
452
* }
463
453
* }, new Eid("20150718:121521"));
464
- * </code></ pre>
454
+ * </pre>
465
455
*
466
456
* @param <R> return type
467
457
* @param supplier unsafe supplier code to be executed within a try-catch block
@@ -480,17 +470,16 @@ public static <R> R tryToExecute(final UnsafeSupplier<R> supplier, final Eid eid
480
470
/**
481
471
* Tries to execute code in given unsafe procedure code block, and if exception is thrown, it will gets rethrown as a
482
472
* {@link EidRuntimeException} with eid given as a argument. This is because this exception is threaded as a software bug!
483
- * <p/ >
473
+ * <p>
484
474
* Example:
485
- * <pre><code>
486
- *
487
- * EidPreconditions.tryToExecute({@code new UnsafeProcedure}() {
488
- * {@literal @}Override
475
+ * <pre>
476
+ * EidPreconditions.tryToExecute(new UnsafeProcedure() {
477
+ * @Override
489
478
* public void execute() throws EJBException {
490
- * em.persist(user);
479
+ * em.persist(user);
491
480
* }
492
481
* }, new Eid("20151117:184627"));
493
- * </code></ pre>
482
+ * </pre>
494
483
*
495
484
* @param procedure unsafe procedure code to be executed within a try-catch block
496
485
* @param eid unique developer identifier from date for ex.: "20150716:123200"
0 commit comments