Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Mail Systems
Eclipse Documentation

How To Guides
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Problem Solutions
Privacy Policy




EMF Model Query Developer Guide
Previous Page Home Next Page

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.

Value Adapters API
[ 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.

  Published under the terms of the Eclipse Public License Version 1.0 ("EPL") Design by Interspire