Meaning of initializing the Big Decimal to -99 in the below code

I know hashtable doesnt allow null keys ...but how is the below code working.

And what does initializing the Big Decimal to -99 in the below code do.

private static final BigDecimal NO_REGION = new BigDecimal (-99);

public List getAllParameters (BigDecimal region, String key) {
    List values = null;
    if (region==null) {
        region = NO_REGION;
    }
    Hashtable paramCache = (Hashtable)CacheManager.getInstance().get(ParameterCodeConstants.PARAMETER_CACHE);
    if (paramCache.containsKey(region)) {
        values = (List) ((Hashtable)paramCache.get(region)).get(key); 
    }

    return values;
}

Am struggling for a long time and dont understand it.

Answers


This is an implementation of the null object pattern: a special object, BigDecimal(-99), is designated to play the role of null in a situation where "real" nulls are not allowed.

The only requirement is that the null object must be different from all "regular" objects. This way, the next time the program needs to find entries with no region, all it needs to do is a lookup by the NO_REGION key.


Need Your Help

WADL applications?

http web-applications rest wadl

I have read the book "Restful Web services". In that book it described WADL and it's purpose to describe RESTful web applications.

Using an Excel macro to query a spreadsheet

sql excel excel-2003

So I have some data in some spreadsheets and I've found that for all the macros and filtering and forumlas I've written to simplify it and narrow it down to what I want, it would have been much eas...