Jsolve - Projects in Maven Central

23 May 2015 on java, sweetener, oven, type-converter, maven

Jsolve - Projects in Maven Central! From now Sweetener, Oven and Type-converter are in Maven Cetral.
Current versions of our libraries are: sweetener: 1.0.0, oven: 1.0.1, type-converter: 1.0.1. In order to use it in maven project just add the below dependency to your pom file.

Sweetener - Collection Restrictions - Part III - Custom restrictions

21 May 2015 on java, sweetener, restrictions, collections, criteria

Sweetener contains many pre-defined restrictions, but we cannot predict all use-cases of our mechanism. For this reason we have prepared CustomRestriction. If none of the restrictions prepared by us is what you are looking for, you can create your own restriction. Preparing CustomRestriction is simple and intuitive. To create your own Restriction you need to create new class which extends CustomRestriction class. Let’s assume that we want to create restriction which checks whether string starts with some substring. The example restriction might look as follows:

Sweetener - Collection Restrictions - Part II - Filtering by date

20 May 2015 on java, sweetener, restrictions, collections, criteria

Filtering objects by using Date class is a very common problem. There are times when we want find objects, for which one of the field is in some time range. Such an example may be find all people who were born before the year 1988. However, there is problem with dates in Java, namely the lack of a uniform approach. There are still applications which use java.util.Date or java.util.Calendar. In addition to the java.util.Date there is also java.sql.Date. Modern applications written in Java < SE 8 use JodaTime library to represent date. It has introduced several new classes of date: DateTime, LocalDate, LocalTime, LocalDateTime. All of these classes are located in org.joda.time package. In the SE8 these classes have been integrated into the standard SE8 and have been placed in java.time. As you can see there is a very large number representation of a date in Java. For this reason, it is hard to create a generic restriction which could operate on all of these date types. To solve this problem, we have prepared a special mechanism that allows comparison of the dates of any type, we’ve create DateExtractor interface. For each type of date used during filtering you should register appropriate extractor:

Sweetener - Collection Restrictions - Part I

18 May 2015 on java, sweetener, restrictions, collections, criteria

Search through the collection has always been a problem for developers and simple search enforced on the programmer writing many lines of code (Countless foreach, if-else constructions). Fortunately, class Collections solves this problem. The integral part of this class is Criteria and Restriction mechanism, which allows for complex query conditions. The restrictions can be joined in chain by add method. Example criteria is shown below:

Criteria.newCriteria().add(Restrictions.isNotNull("company.name"))
        .add(Restrictions.contains("categoriesOfDrivingLicense", "B","D"))
        .add(Restrictions.greaterOrEquals("age", 24))
        .add(Restrictions.equals("name", "marry", true));


Criteria object created in this way can be used in filter method on Collections

Previous Page: 3 of 3