commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 30911] New: - Map that returns a defaul value if key is not present
Date Sat, 28 Aug 2004 02:28:20 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=30911>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=30911

Map that returns a defaul value if key is not present

           Summary: Map that returns a defaul value if key is not present
           Product: Commons
           Version: 3.2
          Platform: Other
        OS/Version: Other
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: Collections
        AssignedTo: commons-dev@jakarta.apache.org
        ReportedBy: r.u.c.afonso@uol.com.br


By definition if a map does not contain a determined key it returns null. But 
sometimes may be desirable that it returns a not-null value for not present 
keys. My propose is create a Decorated Map that extends 
org.apache.commons.collections.map.AbstractMapDecorator class. In constructor 
it receives the original Map and a default value to be returned is for a 
inexistent key. This class will override get() method like this:

public Object get(Object key) {
	Object value = super.get(key);
	if(value == null) {
		value = this.defaultValue;
	}
	return value;
}

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message