Skip to content

Files

Latest commit

44d1918 · Feb 22, 2020

History

History
103 lines (80 loc) · 2.02 KB

common.md

File metadata and controls

103 lines (80 loc) · 2.02 KB

simple java type helpers

Is

This class provides some helper functions for making boolean expressions more easily for some basic conditions.

instead of

  String value = .....
  if((value != null) && (!"".equals(value))) {...}

you can use

  String value = .....
  if(!Is.empty(value)) {...}

instead of

  List list = .....
  if((list != null) && (!list.isEmpty())) {...}

you can use

  List list = .....
  if(!Is.empty(list)) {...}

instead of

  Boolean bool = .....
  if((bool != null) && (bool)) {...}

you can use

  Boolean bool = .....
  if(Is.truth(bool)) {...}

Get

This class helps with unboxing primitives and accessins collection information.

instead of

  Integer integer = .....
  int i = (integer == null) ? 0 : integer;

you can use

  Integer integer = .....
  int i = Get.safeInt(integer);

instead of

  List<String> list = .....
  int size = (list == null) ? 0 : list.size();
  String firstElem = (list == null) ? null : list.get(0);

you can use

  List<String> list = .....
  int size = Get.size(list);
  String firstElem = Get.first(list);

Replace

This class helps with string substitution. It provide basic text ti text substitution.

  String text = "The Mickey is mouse ";
  text = Replace.all(text, "mouse", "the Mouse");

Split

Splits strings and text files.

Strings are split by specifying one or more substring delimiters. Exact match is used (no regexp, ..) and all divided parts are returned (no ignoring empty parts, ...).

It returns all substring delimited by delimiter including empty one and also first and last id delimiter is on begin or end of provided string.

Following code

  List<String> list = Split.string(", the text,, is separated, by comma,").bySubstringToList(",");

return "", " the text", "", " is separated", " by comma", ""

Text files are split to lines.

  List<String> list = Split.file("input.dat", "utf-8").byLinesToList();