JDK-4850973 : MidiMesssage and subclasses: .equals() not implemented
  • Type: Enhancement
  • Component: client-libs
  • Sub-Component: javax.sound
  • Affected Version: 1.4.2
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2003-04-18
  • Updated: 2003-04-22
  • Resolved: 2003-04-22
Related Reports
Duplicate :  
Description

Name: gm110360			Date: 04/18/2003


A DESCRIPTION OF THE REQUEST :
The class MidiMessage and it's subclasses doesn't override
the .equals() method of Object.
.equals should check for the same *contents* of an object.
So it's needed to override it at least for such important
containers.

JUSTIFICATION :
Everywhere in the API's there are .equals() methods for comparing
the content (Point, Color etc.etc.)
But the entire sound-API is missing it, so you can't compare
Messages (Short and Sysex-Messages) without implementing own methods.


EXPECTED VERSUS ACTUAL BEHAVIOR :
Correct implementation of .equals() method - comparing the
contents and not the pointer to the object.
.equals compares only the reference (the default behav. of Object.equals())

---------- BEGIN SOURCE ----------
/*
 * EqualTest.java
 *
 * Created on 12. April 2003, 14:13
 */
import javax.sound.midi.*;
/**
 *
 * @author  Gerrit Gehnen
 */
public class EqualTest {
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        ShortMessage msg1,msg2;
        msg1=new ShortMessage();
        
        try{
        msg1.setMessage(ShortMessage.NOTE_ON,1,64,64);

        // Duplicate the original Message
        msg2=(ShortMessage)msg1.clone();
        
        if (msg1.equals(msg2))
            {
            System.out.println("OK: Is equal!");
            System.exit(0);
        }
        else
        {
            System.out.println("ERROR: Is not equal!");
            System.exit(1);
        }
                }catch (Exception e){e.printStackTrace();}
    }
    
}

---------- END SOURCE ----------
(Review ID: 184030) 
======================================================================

Comments
EVALUATION ###@###.### 2003-04-21 General problem in the Java Sound API. Will be targeted with RFE 4663506: RFE: override equals() method in info classes.
21-04-2003