Check out the new USENIX Web site. next up previous
Next: Subscription Patterns Up: Conditions Previous: Basic conditions


JAVA inherently defines three basic comparison mechanisms, which can be considered as candidates for B:

Is object o1 identical to object o2?

The comparison of two objects with the == operator yields true iff the two arguments are references to the same object. This comparison is less useful in our context, since two compared objects usually originate from different VMs. By default two such objects are never identical.

Is object o1 equal to object o2?

Every object can also be compared to any other object by means of the equals() method, which is inherent to all JAVA objects and can be overwritten by application-defined classes.

How does object o1 compare to object o2?

This is for objects implementing the java.lang.Comparable interface,[*] providing a method compareTo(). The return value is an integer, indicating the order of the object o1 with respect to o2. Such objects manifest a natural ordering, e.g., class java.lang.Integer, and can thus be matched against a range of values. Comparisons can be moved out of the compared objects by using java.util.Comparator objects, which are binary predicates.

In general, B is represented in JAVA by a method, and can also be viewed as Mk+1. Inversely, methods Mj...Mk (j >= 1) can be seen as part of the comparison. In that sense, we provide several shortcuts for common methods, e.g., to compare the type of an object to a predefined one. This reflects the method isInstance() (the dynamic counterpart to the instanceof operator) in java.lang.Class.

In our condition classes, like the Equals class given in Figure 8 (representing an equality test in the sense of II), we have added constructors which alleviate their use. The third constructor in the figure for instance enables the expression of nested method calls by providing a URL-like string denoting the names of the methods. The accessor is in that case created implicitly. Figure 9 shows the links between our JAVA implementation of accessors and conditions, illustrated through the Equals and Invoke classes.

public final class Equals
  implements Condition,
  /* compare the message object as a whole */
  public Equals(Object to) {...}
  /* compare return value of accessor */
  public Equals(Accessor acc, Object to) {...}
  /* implicit accessor creation */
  public Equals(String names, Object[][] args, 
                Object to) {...}
  public boolean conforms(Object m) {...}

Figure 8: Equals Class (Excerpt)

Figure 9: Class Diagram


next up previous
Next: Subscription Patterns Up: Conditions Previous: Basic conditions
Patrick Eugster