|
5 | 5 | <!-- toc --> |
6 | 6 | ## Contents |
7 | 7 |
|
8 | | - * [Why use logs?](#why-use-logs) |
9 | | - * [Capturing logs in test](#capturing-logs-in-test) |
10 | | - * [See also](#see-also)<!-- endToc --> |
| 8 | + * [The problem](#the-problem) |
| 9 | + * [Single Element array solution](#single-element-array-solution) |
| 10 | + * [Mutable<T> solution](#mutablet-solution)<!-- endToc --> |
11 | 11 |
|
12 | 12 |
|
13 | 13 | ## The problem |
@@ -35,17 +35,44 @@ The most common solution to this is to use a single element array. While this wo |
35 | 35 |
|
36 | 36 | For example: |
37 | 37 |
|
38 | | -snippet: single_element_array |
| 38 | +<!-- snippet: single_element_array --> |
| 39 | +<a id='snippet-single_element_array'></a> |
| 40 | +```java |
| 41 | +final int[] i = {1}; |
| 42 | +Function0<Integer> counter = () -> i[0]++; |
| 43 | +``` |
| 44 | +<sup><a href='/approvaltests-util-tests/src/test/java/org/lambda/utils/MutableTest.java#L12-L15' title='Snippet source file'>snippet source</a> | <a href='#snippet-single_element_array' title='Start of snippet'>anchor</a></sup> |
| 45 | +<!-- endSnippet --> |
39 | 46 |
|
40 | 47 | ## Mutable<T> solution |
41 | 48 |
|
42 | 49 | Mutable allows for easy getting/setting/updating. |
43 | 50 |
|
44 | 51 | For example: |
45 | 52 |
|
46 | | -snippet: mutable_example |
| 53 | +<!-- snippet: mutable_example --> |
| 54 | +<a id='snippet-mutable_example'></a> |
| 55 | +```java |
| 56 | +Mutable<String> i = new Mutable<>("Brian"); |
| 57 | +Scheduler scheduler = new Scheduler(() -> i.get()); |
| 58 | +scheduler.addEvent(); |
| 59 | +i.update(n -> "Mr. " + n); |
| 60 | +scheduler.rsvp(); |
| 61 | +i.set("Steve"); |
| 62 | +scheduler.bookHotel(); |
| 63 | +``` |
| 64 | +<sup><a href='/approvaltests-util-tests/src/test/java/org/lambda/utils/MutableTest.java#L20-L28' title='Snippet source file'>snippet source</a> | <a href='#snippet-mutable_example' title='Start of snippet'>anchor</a></sup> |
| 65 | +<!-- endSnippet --> |
47 | 66 |
|
48 | 67 | Will produce the following: |
49 | 68 |
|
50 | | -snippet: MutableTest.exampleOfMutable.approved.txt |
| 69 | +<!-- snippet: MutableTest.exampleOfMutable.approved.txt --> |
| 70 | +<a id='snippet-MutableTest.exampleOfMutable.approved.txt'></a> |
| 71 | +```txt |
| 72 | +adding event as Brian |
| 73 | +rsvping as Mr. Brian |
| 74 | +booking hotel as Steve |
| 75 | +``` |
| 76 | +<sup><a href='/approvaltests-util-tests/src/test/java/org/lambda/utils/MutableTest.exampleOfMutable.approved.txt#L1-L3' title='Snippet source file'>snippet source</a> | <a href='#snippet-MutableTest.exampleOfMutable.approved.txt' title='Start of snippet'>anchor</a></sup> |
| 77 | +<!-- endSnippet --> |
51 | 78 |
|
0 commit comments