Ignat Commons is Core Java common code that I've found myself reusing many times over the years.
The latest release is 2.0.0, available in the Maven Central artifact repository, retrievable via all Java dependency managers.
See Versions for a release history.
Currently the only dependencies are on Google Guava and Apache Commons Lang3, both implementation
-scoped. These two libraries are ubiquitous, and most projects likely already use them. Ignat Commons has been tested against both recent and the earliest versions of these two libraries, and has left their version ranges wide open, so as to defer version resolution to client projects per their specific needs.
Care has been taken to avoid other dependencies, such as Spring, as not all client projects may want them on their classpath.
Throw this in situations that would be code defects, or use it to wrap checked exceptions that are fatal and/or you cannot meaningfully handle.
try
{
myInputStream.read(myByteArray);
}
catch (IOException e)
{
throw new UnexpectedException(e);
}
Throw these from else
and default
statements to give your conditionals useful default behavior. This makes them
fail-fast if you forget to update them after their universe of values grows.
if (value == 1)
{
...
}
else if (value == 2)
{
...
}
else
{
throw new UnexpectedCaseException(value);
}
switch (value)
{
case 1:
...
break;
case 2:
...
break;
default:
throw new UnexpectedCaseException(value);
}
if (shape instanceof Circle)
{
...
}
else if (shape instanceof Rectangle)
{
...
}
else
{
throw new UnexpectedTypeException(shape);
}
General utilities, as well as some enhancements to utilities in the JDK, Google Guava, and Apache Commons.
<T> T getFirst(@Nonnull List<T> list)
<T> T getLast(@Nonnull List<T> list)
FileOutputStream openNewOutputFile(File file)
FileOutputStream openNewOutputFile(File file, boolean safely)
InputStream getResource(String resourcePath)
File getResourceFile(String resourcePath)
String getResourceText(String resourcePath)
<T> T[] of(T... values)
BigDecimal normalizeCurrency(BigDecimal bigDecimal)
BigDecimal normalize(BigDecimal bigDecimal, int scale)
String toSimpleString(BigDecimal bigDecimal)
String toCompactString(double d)
<E extends Enum<E>> boolean equalsAny(String name, E... candidates)
String toCompactString(float f)
<T> boolean equalsAny(T object, T... candidates)
<T> String toLinesString(Iterable<T> objects)
boolean containsAnyIgnoreCase(CharSequence string, CharSequence... candidates)
List<String> findAllMatches(String patternString, CharSequence input)
List<String> findAllMatches(Pattern pattern, CharSequence input)