Ordering is Guava’s fluent Comparator class and implements Comparator interface. It can be used to build complex comparators and apply them to collections of objects.
Okay, so let’s getting started. Firstly, we declared a String type List:
1 | private List<String> locations = Lists.newArrayList( |
We will use this locations variable later.
Custom Tag is a user-defined JSP language element. When it is contained in JSP page and it will translate into a servlet, the custom tag is converted to opertions on an object called a tag handler. The web container then invokes those operations when the JSP page’s servlet is executed.
If we want to create a custom tag, what we need to do is simply extend SimpleTagSupport class and override the doTag() method, where you can place your code to generate content for the tag.
Let’s getting started to create a custom tag now.
As you can see below, consider we want to create two tag, one is user tag with name and isMale attribute, another is system tag with size attribute.
1 | <custom:user name="user1" isMale="true"/> |
Guava provides a number of precondition checking utilities. It’s Preconditions class. You can use it into your project.
Usage
checkArgument(boolean)
Checks that the boolean is true. Use for validating arguments to methods.
checkNotNull(T)
Checks that the value is not null. Returns the value directly, so you can use checkNotNull(value) inline.
Optional<T> is a way of replacing a nullable T reference with a non-null value. An Optional may either contain a non-null T reference (in which case we say the reference is “present”), or it may contain nothing (in which case we say the reference is “absent”). It is never said to “contain null.”