|
2 | 2 | <a href="https://www.codefactor.io/repository/github/alexbolot/codingutils"><img src="https://www.codefactor.io/repository/github/alexbolot/codingutils/badge" /></a>
|
3 | 3 | </h1>
|
4 | 4 |
|
5 |
| -<h3>1. AssertUtils</h3> |
| 5 | +<h3>1. ArrayList8 (extends java.util.ArrayList)</h3> |
| 6 | + |
| 7 | +This class extends java.util.ArrayList. <br> |
| 8 | +Its name is due to the methods it add : suiting Java8 <br> |
| 9 | +It allows easier list management using Predicates and Comparators (replacing .filter and .collect) <br> |
| 10 | +The main goal here is to make the code clearer by replacing heavy lines like <br> |
| 11 | +`myList.stream().filter(...).collect(...)` <br> |
| 12 | +by <br> |
| 13 | +`myList.subList(...)` |
| 14 | + |
| 15 | +<b>Exemple :</b> |
| 16 | +``` |
| 17 | +public E min (Comparator‹E› comparator) |
| 18 | +public E max (Comparator‹E› comparator) |
| 19 | +public E findFirst (Predicate‹E› filter) |
| 20 | +public int countIf (Predicate‹E› filter) |
| 21 | +public ArrayList8 subList (Predicate‹E› filter) |
| 22 | +public boolean addIf (E value, Predicate‹E› filter) |
| 23 | +``` |
| 24 | +<hr> |
| 25 | +<br> |
| 26 | + |
| 27 | +<h3>2. AssertUtils</h3> |
6 | 28 |
|
7 | 29 | This class contains methods used to test values.<br>
|
8 | 30 | When calling those asserting methods :<br>
|
9 | 31 | - if assertion is true, nothing happens, process goes on.
|
10 | 32 | - if assertion is false, throws <b>IllegalArgumentException</b> with a custom message.<br>
|
11 |
| -It can be usefull as feedback for the user (ex : "Name is empty"). |
| 33 | +Note : it can be usefull as feedback for the user (ex : "Name is empty"). |
12 | 34 |
|
13 |
| -Exemple : |
14 |
| -<pre> |
| 35 | +<b>Exemple :</b> |
| 36 | +``` |
15 | 37 | public void assertNotEmpty (List list)
|
16 | 38 | public void assertNotEmpty (String string)
|
17 | 39 | public void assertNotNull (Object... objects)
|
18 |
| -</pre> |
| 40 | +public void assertStrictlyPositive (double value) |
| 41 | +``` |
19 | 42 |
|
20 | 43 | <hr>
|
| 44 | +<br> |
21 | 45 |
|
22 |
| -<h3>2. FormatUtils</h3> |
| 46 | +<h3>3. FormatUtils</h3> |
23 | 47 |
|
24 |
| -This class contains mehtods used to format or print things.<br> |
25 |
| - |
26 |
| -Exemple : |
27 |
| -<pre> |
28 |
| -public int tryParseInt (String string) |
29 |
| -public boolean isInteger (String string) |
| 48 | +<b>Exemple :</b> |
| 49 | +``` |
30 | 50 | public String toFirstUpperCase (String string)
|
31 |
| -</pre> |
| 51 | +public ‹T› void printArrayFancy (T[] array, String start, String separator, String end) |
| 52 | +public ‹T› void printListFancy (List‹T› list, String start, String separator, String end) |
| 53 | + |
| 54 | + exemple : list = {a, b, c} |
| 55 | + start = "((" |
| 56 | + separator = " - " |
| 57 | + end = "))" |
| 58 | + |
| 59 | + result : ((a - b - c)) |
| 60 | +
|
| 61 | +``` |
| 62 | + |
| 63 | +<hr> |
| 64 | +<br> |
| 65 | + |
| 66 | +<h3>4. NumberUtils</h3> |
| 67 | + |
| 68 | +This class contains mehtods used to parse strings or get min/max from Collections.<br> |
| 69 | + |
| 70 | +<b>Find if value is parseable or directly parse it</b> |
| 71 | +``` |
| 72 | +public int tryParseInt (String string) //Also exists for float and double |
| 73 | +public boolean isInteger (String string) //Also exists for float and double |
| 74 | +``` |
| 75 | + |
| 76 | +<b>Find if a value is between a min and a max</b> (both excluded) |
| 77 | +``` |
| 78 | +public boolean isInBounds (double min, double value, double max) |
| 79 | +public boolean isInBounds (T min, T value, T max) //with ‹T extends Comparator‹T›› |
| 80 | +public boolean isInBounds (T min, T value, T max, Comparator‹T› comparator) |
| 81 | +``` |
| 82 | + |
| 83 | +<b>Find min value of an Array or Collection</b> |
| 84 | +``` |
| 85 | +public int min (int[] array) //Also exists for float and double |
| 86 | +public T min (T[] array) //with ‹T extends Comparator‹T›› |
| 87 | +public T min (T[] array, Comparator‹T› comparator) |
| 88 | +public T min (Collection‹T› collection) //with ‹T extends Comparator‹T›› |
| 89 | +public T min (Collection‹T› collection, Comparator‹T› comparator) |
| 90 | +``` |
| 91 | + |
| 92 | +<b>Find max value of an Array or Collection</b> |
| 93 | +``` |
| 94 | +public int max (int[] array) // Also exists for float and double |
| 95 | +public T max (T[] array) // with ‹T extends Comparator‹T›› |
| 96 | +public T max (T[] array, Comparator‹T› comparator) |
| 97 | +public T max (Collection‹T› collection) // with ‹T extends Comparator‹T›› |
| 98 | +public T max (Collection‹T› collection, Comparator‹T› comparator) |
| 99 | +``` |
0 commit comments