# Value Adapters

The primitive value conditions work well with inputs that match their respective types. But what about models that use, for example, string attributes to represent numeric data? Enter the value adapter.

> [as SVG]

Each adapter type has a shared default instance that simply assumes that the input value is of the expected type, and casts it. The abstract NumberAdapter has concrete inner subclasses to parallel the NumberConditions.

As an example, consider a query that would look for books published in 1990 or later. It might be just as easy to create a custom date condition type, but it could make use of a condition like this:

    // get the long representation of midnight, Jan. 1, 1990
    Calendar midnightJan1_1990 = Calendar.getInstance();
    midnightJan1_1990.set(1990, Calendar.JANUARY, 1, 0, 0, 0);
    long time = midnightJan1_1990.getTimeInMillis();

    NumberAdapter dateAdapter = new NumberAdapter.LongAdapter() {
        public long longValue(Object object) {
            return ((Date) object).getTime();
        }};

    Object subject = new Date();

    // match dates on or after midnight, Jan. 1, 1990
    Condition cond = new NumberCondition.LongValue(time, Long.MAX_VALUE, dateAdapter);

    System.out.println("Test: ", cond.isSatisfied(subject));

Copyright (c) 2000, 2007 IBM Corporation and others. All Rights Reserved.