Skip to content

Project containing utils methods, that we use all the time, to avoid rewriting all the time the same code

License

Notifications You must be signed in to change notification settings

AlexBolot/CodingUtils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Coding Utils :

1. ArrayList8 (extends java.util.ArrayList)

This class extends java.util.ArrayList.
Its name is due to the methods it add : suiting Java8
It allows easier list management using Predicates and Comparators (replacing .filter and .collect)
The main goal here is to make the code clearer by replacing heavy lines like
myList.stream().filter(...).collect(...)
by
myList.subList(...)

Exemple :

public E min (Comparator‹E› comparator)
public E max (Comparator‹E› comparator)
public E findFirst (Predicate‹E› filter)
public int countIf (Predicate‹E› filter)
public ArrayList8 subList (Predicate‹E› filter)
public boolean addIf (E value, Predicate‹E› filter)


2. AssertUtils

This class contains methods used to test values.
When calling those asserting methods :

  • if assertion is true, nothing happens, process goes on.
  • if assertion is false, throws IllegalArgumentException with a custom message.
    Note : it can be usefull as feedback for the user (ex : "Name is empty").

Exemple :

public void assertNotEmpty (List list)
public void assertNotEmpty (String string)
public void assertNotNull (Object... objects)
public void assertStrictlyPositive (double value)


3. FormatUtils

This class contains methods used to format test or print with special format.

Exemple :

public String toFirstUpperCase (String string)
public ‹T› void printArrayFancy (T[] array, String start, String separator, String end)
public ‹T› void printListFancy (List‹T› list, String start, String separator, String end)
    
    exemple : list       = {a, b, c}
              start      = "(("
              separator  = " - "
              end        = "))"
                
    result :  ((a - b - c))



4. NumberUtils

This class contains mehtods used to parse strings or get min/max from Collections.

Find if value is parseable or directly parse it

public int tryParseInt (String string)      //Also exists for float and double
public boolean isInteger (String string)    //Also exists for float and double

Find if a value is between a min and a max (both excluded)

public boolean isInBounds (double min, double value, double max)
public boolean isInBounds (T min, T value, T max)   //with ‹T extends Comparator‹T››
public boolean isInBounds (T min, T value, T max, Comparator‹T› comparator)

Find min value of an Array or Collection

public int min (int[] array)    //Also exists for float and double
public T min (T[] array)        //with ‹T extends Comparator‹T››
public T min (T[] array, Comparator‹T› comparator)
public T min (Collection‹T› collection) //with ‹T extends Comparator‹T››
public T min (Collection‹T› collection, Comparator‹T› comparator)

Find max value of an Array or Collection

public int max (int[] array)    // Also exists for float and double
public T max (T[] array)        // with ‹T extends Comparator‹T››
public T max (T[] array, Comparator‹T› comparator)
public T max (Collection‹T› collection) // with ‹T extends Comparator‹T››
public T max (Collection‹T› collection, Comparator‹T› comparator)

About

Project containing utils methods, that we use all the time, to avoid rewriting all the time the same code

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages