JDK-4655198 : RFE: java.lang.Boolean should implement java.lang.Comparable
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 1.4.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2002-03-20
  • Updated: 2002-03-20
  • Resolved: 2002-03-20
Related Reports
Duplicate :  
Description

Name: rmT116609			Date: 03/19/2002


FULL PRODUCT VERSION :
java version "1.4.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)

FULL OPERATING SYSTEM VERSION :
Microsoft Windows 2000 [Version 5.00.2195]

A DESCRIPTION OF THE PROBLEM :
For consistency of wrapping primitive types (int,float,...) to their object-counterparts (java.lang.Integer,java.lang.Float,...) java.lang.Boolean
should implement the java.lang.Comparable interface.

I'm working on a object-database completly stored in memory, backed by a JDBC-connected database. For easy and fast queries, i use java.util.TreeMap to provide field- based sorted lists of the stored records in memory, using
the key's natural order. Works fine with most (important) JDBC-Types (all numbers, strings, dates) but not with booleans.

// suggestion, analogous to java.lang.Integer

public int compareTo(Boolean anotherBoolean) {
boolean thisValue=this.value;
boolean thatValue=anotherBoolean.value;
return (int) thisValue ? (thatValue ? (int)0 : (int)-1) :
(thatValue ? (int)1 : (int)0);
}

public int compareTo(Object anotherObject) {
return compareTo((Boolean)anotherObject);
}


(Review ID: 144362) 
======================================================================

Comments
EVALUATION Possibly a duplicate of 4329937. -- iag@sfbay 2002-03-19 Yes, closing as duplicate of 4329937; see that bug for a full rationale. Essentially, the compareTo methods in the other wrapper classes mirror the natural ordering of the underlying primitive type and primitive booleans have no such ordering (Float and Double using a different ordering than float and double for technical reasons). ###@###.### 2002-03-19
19-03-2002